lib/Panotools/Script.pm

filter: Statementstmt 60.5% 349 / 576 Branchbran 50.6% 81 / 160 Conditioncond 21.5% 22 / 102 MC/DCmcdc 15.2% 7 / 46 Subroutinesub 74.1% 43 / 58 Podpod 0.0% 0 / 35 totaltotal 51.3% 502 / 977 CC 159 SCAR 40.7
CC
159
Cov
54%
UnifyLenses
420.0
Stats
110.0
Centre
56.0
CRAP 58.6
↑ Summary lib/Panotools/Script/Line/Variable.pm »
1 package Panotools::Script;
2  
3 =head1 NAME
4  
5 Panotools::Script - Panorama Tools scripting
6  
7 =head1 SYNOPSIS
8  
9 Read, write and manipulate hugin script files.
10  
11 =head1 DESCRIPTION
12  
13 Library and utilities for manipulating project files created by the hugin photo
14 stitching software.
15  
16 This file format is shared with various other tools, in particular this module
17 is also capable of working with Panorama Tools script files.
18  
19 =cut
20  
21 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 10 ▶use Panotools::Script::Line::Mode;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 10 ▶use Panotools::Script::Line::Panorama;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 10 ▶use Panotools::Script::Line::Option;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 10 ▶use Panotools::Script::Line::Image;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 10 ▶use Panotools::Script::Line::ImageMetadata;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 10 ▶use Panotools::Script::Line::Output;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 10 ▶use Panotools::Script::Line::Control;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 10 ▶use Panotools::Script::Line::ControlMorph;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 10 ▶use Panotools::Script::Line::Variable;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 10 ▶use Panotools::Script::Line::Mask;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 10 ▶use Digest::MD5 'md5_hex';
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 10 ▶use File::Temp qw/ tempdir /;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 10 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 10 ▶use Math::Trig qw/:radial pi great_circle_distance/;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 10 ▶use Storable qw/ dclone /;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 10 our $VERSION = '0.29';
43  
44 10 our $CLEANUP = 1;
45 10 ▶$CLEANUP = 0 if defined $ENV{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"DEBUG"} 0 10 10
46  
47 =head1 USAGE
48  
49 my $p = new Panotools::Script;
50  
51 =cut
52  
53 sub new
54 10 ▶{
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
55 10 my $class = shift;
56 10 ▶ $class = ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0100
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
57 10 my $self = bless {}, $class;
58 10 $self->_defaults;
59 10 return $self;
60 }
61  
62 sub _defaults
63 16 ▶{
Subroutine _defaults: called CC=1 SCAR=0.0
64 16 my $self = shift;
65 16 $self->{mode} = new Panotools::Script::Line::Mode;
66 16 $self->{panorama} = new Panotools::Script::Line::Panorama;
67 16 $self->{option} = new Panotools::Script::Line::Option;
68 16 $self->{variable} = new Panotools::Script::Line::Variable;
69 16 $self->{image} = [];
70 16 $self->{imagemetadata} = [];
71 16 $self->{output} = [];
72 16 $self->{control} = [];
73 16 $self->{controlmorph} = [];
74 16 $self->{mask} = [];
75 }
76  
77 =pod
78  
79 $p->Read ('/path/to/script.txt');
80  
81 =cut
82  
83 sub Read
84 6 ▶{
Subroutine Read: called CC=15 SCAR=27.3
Pod undocumented
85 6 my $self = shift;
86 6 $self->_defaults;
87 6 ▶ my $path = shift || return 0;
Condition50%1/2
shift() || (return 0)
l!l
60
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
88 6 ▶ if ($path eq '-')
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq '-') { } 0 6 6
89 {
90 0 open FILE, '<-';
91 }
92 else
93 {
94 6 ▶ open FILE, "<", $path or die "cannot read-open $path";
Branch: 1 branch
BranchTrueFalseTotal
open FILE, "<", $path or die "cannot read-open $path" 6 0 6
95 }
96 6 my @raw = <FILE>;
97 6 close FILE;
98  
99 6 $self->{md5} = md5_hex (join '', @raw);
100  
101 6 my ($volume, $directories, $file) = File::Spec->splitpath ($path);
102  
103 6 for my $line (@raw)
104 {
105 367 $line =~ s/(\r|\n)//g;
106 367 ▶ $self->Mode->Parse ($line) if ($line =~ /^m /);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^m / 6 361 367
107 367 ▶ $self->Panorama->Parse ($line) if ($line =~ /^p /);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^p / 6 361 367
108 367 ▶ $self->Option->Parse ($line) if ($line =~ /^#hugin_/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#hugin_/ 5 362 367
109 367 ▶ $self->Variable->Parse ($line) if ($line =~ /^v /);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^v / 30 337 367
110 367 ▶ if ($line =~ /^i /)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^i /) 25 342 367
111 {
112 25 my $image = new Panotools::Script::Line::Image;
113 25 $image->Parse ($line);
114 25 push @{$self->Image}, $image;
115 }
116 367 ▶ if ($line =~ /^o /)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^o /) 5 362 367
117 {
118 5 my $output = new Panotools::Script::Line::Output;
119 5 $output->Parse ($line);
120 5 push @{$self->Output}, $output;
121 }
122 367 ▶ if ($line =~ /^c /)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^c /) 205 162 367
123 {
124 205 my $control = new Panotools::Script::Line::Control;
125 205 $control->Parse ($line);
126 205 push @{$self->Control}, $control;
127 }
128 367 ▶ if ($line =~ /^C /)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^C /) 0 367 367
129 {
130 0 my $controlmorph = new Panotools::Script::Line::ControlMorph;
131 0 $controlmorph->Parse ($line);
132 0 push @{$self->ControlMorph}, $controlmorph;
133 }
134 367 ▶ if ($line =~ /^#-hugin /)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^#-hugin /) 25 342 367
135 {
136 # per-image metadata
137 25 my $imagemeta = new Panotools::Script::Line::ImageMetadata;
138 25 $imagemeta->Parse ($line);
139 25 push @{$self->ImageMetadata}, $imagemeta;
140 }
141 367 ▶ if ($line =~ /^k /)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^k /) 4 363 367
142 {
143 4 my $mask = new Panotools::Script::Line::Mask;
144 4 $mask->Parse ($line);
145 4 push @{$self->Mask}, $mask;
146 }
147 }
148 6 $self->Output2Image;
149 6 return 1;
150 }
151  
152 =pod
153  
154 $p->Write ('/path/to/script.txt');
155  
156 File paths in a Panorama Tools script file are generally relative to the
157 directory containing the script. Modify this or otherwise prefix the filenames
158 by supplying an optional second argument:
159  
160 $p->Write ('/path/to/script.txt', '../path/to/prefix/tofiles');
161  
162 =cut
163  
164 sub Write
165 7 ▶{
Subroutine Write: called CC=13 SCAR=26.0
Pod undocumented
166 7 my $self = shift;
167 7 ▶ $self->Image2Output if scalar @{$self->Output};
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$self->Output;} 3 4 7
168 7 ▶ my $path = shift || return 0;
Condition50%1/2
shift() || (return 0)
l!l
70
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
169 7 ▶ my $vector = shift || '';
Condition50%1/2
shift() || ''
l!l
07
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
170 7 ▶ if ($path eq '-')
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq '-') { } 0 7 7
171 {
172 0 open FILE, '>-';
173 }
174 else
175 {
176 7 ▶ open FILE, ">", $path or die "cannot write-open $path";
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">", $path or die "cannot write-open $path" 7 0 7
177 }
178 7 print FILE "# Created by ". (ref $self) ." $VERSION\n\n";
179 7 print FILE $self->Panorama->Assemble;
180 7 print FILE $self->Mode->Assemble;
181 7 print FILE "\n# Image lines\n";
182 7 for my $index (0 .. (scalar (@{$self->Image}) - 1))
183 {
184 23 ▶ print FILE $self->ImageMetadata->[$index]->Assemble if defined ($self->ImageMetadata->[$index]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->ImageMetadata->[$index] 10 13 23
185 23 ▶ print FILE $self->Image->[$index]->Assemble if defined ($self->Image->[$index]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->Image->[$index] 23 0 23
186 }
187 7 print FILE "\n# Variable lines\n";
188 7 print FILE $self->Variable->Assemble;
189 7 print FILE "\n# Control point lines\n";
190 7 for my $control (@{$self->Control})
191 {
192 82 print FILE $control->Assemble;
193 }
194 7 for my $controlmorph (@{$self->ControlMorph})
195 {
196 0 print FILE $controlmorph->Assemble;
197 }
198 7 print FILE "\n# Mask lines\n";
199 7 for my $mask (@{$self->Mask})
200 {
201 1 print FILE $mask->Assemble;
202 }
203 7 print FILE "\n# option lines\n";
204 7 print FILE $self->Option->Assemble;
205 7 print FILE "\n*\n";
206 7 print FILE "\n# Output image lines\n";
207 7 for my $output (@{$self->Output})
208 {
209 15 print FILE $output->Assemble ($vector);
210 }
211 7 close FILE;
212 }
213  
214 =pod
215  
216 Clone a script object
217  
218 $clone = $p->Clone;
219  
220 =cut
221  
222 sub Clone
223 2 ▶{
Subroutine Clone: called CC=1 SCAR=0.0
Pod undocumented
224 2 my $self = shift;
225 2 dclone ($self);
226 }
227  
228 =pod
229  
230 Access various sections of the scriptfile:
231  
232 $p->Mode; # a L<Panotools::Script::Line::Mode> object
233 $p->Panorama; # a L<Panotools::Script::Line::Panorama> object
234 $p->Variable; # a L<Panotools::Script::Line::Variable> object
235  
236 =cut
237  
238 sub Mode
239 15 ▶{
Subroutine Mode: called CC=1 SCAR=0.0
Pod undocumented
240 15 my $self = shift;
241 15 $self->{mode};
242 }
243  
244 sub Panorama
245 27 ▶{
Subroutine Panorama: called CC=1 SCAR=0.0
Pod undocumented
246 27 my $self = shift;
247 27 $self->{panorama};
248 }
249  
250 sub Option
251 34 ▶{
Subroutine Option: called CC=1 SCAR=0.0
Pod undocumented
252 34 my $self = shift;
253 34 $self->{option};
254 }
255  
256 sub Variable
257 41 ▶{
Subroutine Variable: called CC=1 SCAR=0.0
Pod undocumented
258 41 my $self = shift;
259 41 $self->{variable};
260 }
261  
262 =pod
263  
264 $p->Image; # an array of L<Panotools::Script::Line::Image> objects
265 $p->Output; # an array of L<Panotools::Script::Line::Output> objects
266 $p->Control; # an array of L<Panotools::Script::Line::Control> objects
267 $p->ControlMorph; # an array of L<Panotools::Script::Line::ControlMorph> objects
268  
269 =cut
270  
271 sub Image
272 1869 ▶{
Subroutine Image: called CC=1 SCAR=0.0
Pod undocumented
273 1869 my $self = shift;
274 1869 $self->{image};
275 }
276  
277 sub ImageMetadata
278 64 ▶{
Subroutine ImageMetadata: called CC=1 SCAR=0.0
Pod undocumented
279 64 my $self = shift;
280 64 $self->{imagemetadata};
281 }
282  
283 sub Output
284 1206 ▶{
Subroutine Output: called CC=1 SCAR=0.0
Pod undocumented
285 1206 my $self = shift;
286 1206 $self->{output};
287 }
288  
289 sub Control
290 445 ▶{
Subroutine Control: called CC=2 SCAR=6.9
Pod undocumented
291 445 my $self = shift;
292 445 ▶ $self->{control} = shift if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 2 443 445
293 445 $self->{control};
294 }
295  
296 sub ControlMorph
297 7 ▶{
Subroutine ControlMorph: called CC=1 SCAR=0.0
Pod undocumented
298 7 my $self = shift;
299 7 $self->{controlmorph};
300 }
301  
302 sub Mask
303 17 ▶{
Subroutine Mask: called CC=1 SCAR=0.0
Pod undocumented
304 17 my $self = shift;
305 17 $self->{mask};
306 }
307  
308 =pod
309  
310 Rotate transform all the images in a project, angles in degrees:
311  
312 $p->Transform ($roll, $pitch, $yaw);
313  
314 =cut
315  
316 sub Transform
317 2 ▶{
Subroutine Transform: called CC=2 SCAR=6.9
Pod undocumented
318 2 my $self = shift;
319 2 my ($roll, $pitch, $yaw) = @_;
320 2 for my $image (@{$self->Image})
321 {
322 7 $image->Transform ($roll, $pitch, $yaw);
323 }
324 2 $self->Image2Output;
325 }
326  
327 =pod
328  
329 'o' output lines are generated by PTOptimizer and contain stitching parameters
330 for each input image.
331 'i' image lines provide parameters for optimisation as well as stitching.
332  
333 Update the 'image' lines based on 'output' lines and vice-versa like so:
334  
335 $p->Output2Image;
336 $p->Image2Output;
337  
338 =cut
339  
340 sub Output2Image
341 7 ▶{
Subroutine Output2Image: called CC=6 SCAR=17.9
Pod undocumented
342 7 my $self = shift;
343 7 for my $index (0 .. (@{$self->Output} - 1))
344 {
345 7 for my $entry (keys %{$self->Output->[$index]})
346 {
347 101 ▶ $self->Image->[$index] = new Panotools::Script::Line::Image unless (defined $self->Image->[$index]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->Image->[$index] 5 96 101
348 $self->Image->[$index]->{$entry} = $self->Output->[$index]->{$entry}
349 101 ▶ unless (defined $self->Image->[$index]->{$entry} and $self->Image->[$index]->{$entry} =~ /=/);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->Image->[$index]{$entry} and $self->Image->[$index]{$entry} =~ /=/ 100 1 101
Condition100%3/3
defined $self->Image->[$index]{$entry} and $self->Image->[$index]{$entry} =~ /=/
!ll&&!rl&&r
35651
MC/DC100%2/2
defined $self->Image->[$index]{$entry} and $self->Image->[$index]{$entry} =~ /=/
defined $self->Image->[$index]{$entry} $self->Image->[$index]{$entry} =~ /=/
Truth table100%3/3
A and B
A= defined $self->Image->[$index]{$entry}B= $self->Image->[$index]{$entry} =~ /=/
ABresult
0X0
100
111
350 }
351 }
352 }
353  
354 sub Image2Output
355 7 ▶{
Subroutine Image2Output: called CC=5 SCAR=16.1
Pod undocumented
356 7 my $self = shift;
357 7 for my $index (0 .. (@{$self->Image} - 1))
358 {
359 26 for my $entry (keys %{$self->Image->[$index]})
360 {
361 528 ▶ $self->Output->[$index] = new Panotools::Script::Line::Output unless (defined $self->Output->[$index]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->Output->[$index] 9 519 528
362 528 ▶ unless ($self->Image->[$index]->{$entry} =~ /=/)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Image->[$index]{$entry} =~ /=/) { } 114 414 528
363 {
364 414 $self->Output->[$index]->{$entry} = $self->Image->[$index]->{$entry};
365 }
366 else
367 {
368 114 my $base = $self->Image->[$index]->{$entry};
369 114 $base =~ s/=//;
370 114 $self->Output->[$index]->{$entry} = $self->Image->[$base]->{$entry};
371 }
372 }
373 }
374 }
375  
376 =pod
377  
378 Remove duplicate control points from the project, returns a list of deleted
379 points:
380  
381 my $deleted = $p->Duplicates;
382  
383 =cut
384  
385 sub Duplicates
386 2 ▶{
Subroutine Duplicates: called CC=3 SCAR=11.0
Pod undocumented
387 2 my $self = shift;
388 2 my $packed_seen = {};
389 2 my $points_uniq = [];
390 2 my $points_deleted = [];
391 2 for my $point (@{$self->Control})
392 {
393 81 my $packed = $point->Packed;
394 81 ▶ if (defined $packed_seen->{$packed})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $packed_seen->{$packed}) { } 1 80 81
395 {
396 1 push @{$points_deleted}, $point;
397 }
398 else
399 {
400 80 push @{$points_uniq}, $point;
401 }
402 81 $packed_seen->{$packed} = 'TRUE';
403 }
404  
405 2 $self->Control ($points_uniq);
406 2 return $points_deleted;
407 }
408  
409 =pod
410  
411 Remove all points with an error distance greater than a threshold measured in
412 pixels, returns a list of deleted points:
413  
414 my $pruned = $p->Prune (12.345);
415  
416 =cut
417  
418 sub Prune
419 0 ▶{
Subroutine Prune: not called CC=5 SCAR=34.0
Pod undocumented
420 0 my $self = shift;
421 0 my $threshold = shift;
422 0 ▶ return [] unless $threshold > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $threshold > 0 0 0 0
423 0 my $points_new = [];
424 0 my $points_pruned = [];
425  
426 0 for my $point (@{$self->Control})
427 {
428 0 ▶ if ($point->{t} > 0 or $point->Distance ($self) < $threshold)
Branch: 1 branch
BranchTrueFalseTotal
if ($point->{'t'} > 0 or $point->Distance($self) < $threshold) { } 0 0 0
Condition0%0/3
$point->{"t"} > 0 or $point->Distance($self) < $threshold
l!l&&r!l&&!r
000
MC/DC0%0/2
$point->{"t"} > 0 or $point->Distance($self) < $threshold
$point->{"t"} > 0 $point->Distance($self) < $threshold
Truth table0%0/3
A or B
A= $point->{"t"} > 0B= $point->Distance($self) < $threshold
ABresult
1X1
011
000
429 {
430 0 push @{$points_new}, $point;
431 }
432 else
433 {
434 0 push @{$points_pruned}, $point;
435 }
436 }
437  
438 0 $self->{control} = $points_new;
439 0 return $points_pruned;
440 }
441  
442 =pod
443  
444 Extract a new object consisting of just the requested images, related
445 control points and optimisation settings:
446  
447 my $subset = $p->Subset (1, 2, 34, 56);
448  
449 Images can be requested in any order, but they will be returned in the same
450 order as the 'parent' project.
451  
452 =cut
453  
454 sub Subset
455 2 ▶{
Subroutine Subset: called CC=19 SCAR=29.5
Pod undocumented
456 2 my $self = shift;
457 2 my @selection = sort {$a <=> $b} @_;
458  
459 2 my $mapping;
460 2 for my $index (0 .. scalar @selection -1)
461 {
462 7 ▶ return 0 unless $selection[$index] =~ /^[0-9]+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $selection[$index] =~ /^[0-9]+$/ 0 7 7
463 7 ▶ return 0 if $selection[$index] >= scalar @{$self->{image}};
Branch: 1 branch
BranchTrueFalseTotal
if $selection[$index] >= scalar @{$self->{"image"};} 0 7 7
464 7 $mapping->{$selection[$index]} = $index;
465 }
466 2 ▶ return 0 unless scalar keys %{$mapping} == scalar @selection;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %{$mapping;} == scalar @selection 0 2 2
467  
468 2 my $pto_out = $self->Clone;
469  
470 # only use selected images
471 2 $pto_out->{image} = [];
472 2 $pto_out->{imagemetadata} = [];
473 2 $pto_out->{variable} = new Panotools::Script::Line::Variable;
474  
475 2 for my $index (0 .. scalar @{$self->{image}} -1)
476 {
477 10 ▶ next unless defined $mapping->{$index};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mapping->{$index} 3 7 10
478  
479 # copy metadata for selected image
480 $pto_out->{imagemetadata}->[$mapping->{$index}]
481 = $self->{imagemetadata}->[$index]->Clone
482 7 ▶ if defined $self->{imagemetadata}->[$index];
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"imagemetadata"}[$index] 7 0 7
483  
484 # copy selected image but resolve '=0' style references
485 7 my $image = $self->{image}->[$index]->Clone;
486 7 for my $key (keys %{$image})
487 {
488 # resolve references as anchor image may be gone
489 210 ▶ if ($image->{$key} =~ /^=([0-9]+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($image->{$key} =~ /^=([0-9]+)$/) 84 126 210
490 {
491 84 $image->{$key} = $self->{image}->[$1]->{$key};
492 }
493 # rereference to image 0 if possible
494 210 ▶ if (scalar @{$pto_out->{image}} > 0
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$pto_out->{"image"};} > 0 and $image->{$key} eq $pto_out->{"image"}[0]{$key} and $key =~ /^([abcdev]|R[abcde]|V[abcdxy])$/) 85 125 210
Condition100%6/6
scalar @{$pto_out->{"image"};} > 0 and $image->{$key} eq $pto_out->{"image"}[0]{$key} and $key =~ /^([abcdev]|R[abcde]|V[abcdxy])$/
!ll&&!rl&&r
804585
scalar @{$pto_out->{"image"};} > 0 and $image->{$key} eq $pto_out->{"image"}[0]{$key}
!ll&&!rl&&r
6020130
MC/DC100%3/3
scalar @{$pto_out->{"image"};} > 0 and $image->{$key} eq $pto_out->{"image"}[0]{$key} and $key =~ /^([abcdev]|R[abcde]|V[abcdxy])$/
scalar @{$pto_out->{"image"};} > 0 $image->{$key} eq $pto_out->{"image"}[0]{$key} $key =~ /^([abcdev]|R[abcde]|V[abcdxy])$/
Truth table100%4/4
A and B and C
A= scalar @{$pto_out->{"image"};} > 0B= $image->{$key} eq $pto_out->{"image"}[0]{$key}C= $key =~ /^([abcdev]|R[abcde]|V[abcdxy])$/
ABCresult
0XX0
10X0
1100
1111
495 and $image->{$key} eq $pto_out->{image}->[0]->{$key}
496 and $key =~ /^([abcdev]|R[abcde]|V[abcdxy])$/)
497 {
498 85 $image->{$key} = '=0';
499 }
500 }
501 7 $pto_out->{image}->[$mapping->{$index}] = $image;
502  
503 # copy only optimisation parameters for selected image
504 $pto_out->{variable}->{$mapping->{$index}}
505 7 = {%{$self->{variable}->{$index}}}
506 7 ▶ if defined $self->{variable}->{$index};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"variable"}{$index} 7 0 7
507 }
508  
509 # copy only control points related to selected images
510 2 $pto_out->{control} = [];
511 2 for my $control (@{$self->{control}})
512 {
513 80 ▶ next unless defined $mapping->{$control->{n}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$mapping{$control->{"n"}} 33 47 80
514 47 ▶ next unless defined $mapping->{$control->{N}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$mapping{$control->{"N"}} 7 40 47
515 40 my $clone = $control->Clone;
516 40 $clone->{n} = $mapping->{$control->{n}};
517 40 $clone->{N} = $mapping->{$control->{N}};
518 40 push @{$pto_out->{control}}, $clone;
519 }
520  
521 # copy masks for selected images
522 2 $pto_out->{mask} = [];
523 2 for my $mask (@{$self->{mask}})
524 {
525 2 ▶ next unless defined $mapping->{$mask->{i}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$mapping{$mask->{"i"}} 1 1 2
526 1 my $clone = $mask->Clone;
527 1 $clone->{i} = $mapping->{$mask->{i}};
528 1 push @{$pto_out->{mask}}, $clone;
529 }
530  
531 2 return $pto_out;
532 }
533  
534 =pod
535  
536 Merge a project with another:
537  
538 $p->Merge ($newstuff);
539  
540 This adds extra images from $newstuff, skipping duplicates. All control points
541 except exact duplicates are imported regardless.
542  
543 =cut
544  
545 sub Merge
546 1 ▶{
Subroutine Merge: called CC=18 SCAR=32.1
Pod undocumented
547 1 my $self = shift;
548 1 ▶ my $b = shift || return 0;
Condition50%1/2
shift() || (return 0)
l!l
10
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
549  
550 # create lookup table relating filenames to index in final project
551 1 my $mapping = {};
552  
553 1 for my $index (0 .. scalar @{$self->Image} -1)
554 {
555 3 $mapping->{$self->Image->[$index]->{n}} = $index;
556 }
557  
558 1 my $index = scalar keys %{$mapping};
559 1 for my $image (@{$b->Image})
560 {
561 4 ▶ unless (defined $mapping->{$image->{n}})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$mapping{$image->{"n"}}) 2 2 4
562 {
563 2 $mapping->{$image->{n}} = $index;
564 2 $index++;
565 }
566 }
567  
568 # insert metadata, image and variable info if a new filename
569 1 for my $index (0 .. scalar @{$b->Image} -1)
570 {
571 4 my $filename = $b->Image->[$index]->{n};
572 4 ▶ next if defined $self->Image->[$mapping->{$filename}];
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->Image->[$mapping->{$filename}] 2 2 4
573  
574 2 ▶ $self->ImageMetadata->[$mapping->{$filename}] = $b->ImageMetadata->[$index]->Clone
Branch: 1 branch
BranchTrueFalseTotal
if defined $b->ImageMetadata->[$index] 2 0 2
575 if defined $b->ImageMetadata->[$index];
576  
577 2 my $image = $b->Image->[$index]->Clone;
578 2 for my $key (keys %{$image})
579 {
580 # update references
581 60 ▶ if ($image->{$key} =~ /^=([0-9]+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($image->{$key} =~ /^=([0-9]+)$/) 17 43 60
582 {
583 17 my $index_new = $mapping->{$b->Image->[$1]->{n}};
584 17 $image->{$key} = "=$index_new";
585 }
586 }
587 2 $self->Image->[$mapping->{$filename}] = $image;
588  
589 2 my $variable = $b->Variable->Clone;
590 2 $self->Variable->{$mapping->{$filename}} = $variable->{$index};
591 }
592  
593 # append control points
594 1 for my $control (@{$b->Control})
595 {
596 21 my $clone = $control->Clone;
597 21 $clone->{n} = $mapping->{$b->Image->[$clone->{n}]->{n}};
598 21 $clone->{N} = $mapping->{$b->Image->[$clone->{N}]->{n}};
599 21 push @{$self->Control}, $clone;
600 }
601  
602 # add masks
603 1 for my $mask (@{$b->Mask})
604 {
605 0 my $jump;
606 0 for my $self_mask (@{$self->Mask})
607 {
608 0 ▶ $jump = 1 if ($self_mask->{i} eq $mask->{i} and $self_mask->{p} eq $mask->{p});
Branch: 1 branch
BranchTrueFalseTotal
if $self_mask->{"i"} eq $mask->{"i"} and $self_mask->{"p"} eq $mask->{"p"} 0 0 0
Condition0%0/3
$self_mask->{"i"} eq $mask->{"i"} and $self_mask->{"p"} eq $mask->{"p"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self_mask->{"i"} eq $mask->{"i"} and $self_mask->{"p"} eq $mask->{"p"}
$self_mask->{"i"} eq $mask->{"i"} $self_mask->{"p"} eq $mask->{"p"}
Truth table0%0/3
A and B
A= $self_mask->{"i"} eq $mask->{"i"}B= $self_mask->{"p"} eq $mask->{"p"}
ABresult
0X0
100
111
609 }
610 0 ▶ next if $jump;
Branch: 1 branch
BranchTrueFalseTotal
if $jump 0 0 0
611 0 my $clone = $mask->Clone;
612 0 $clone->{i} = $mapping->{$b->Image->[$clone->{i}]->{n}};
613 0 push @{$self->Mask}, $clone;
614 }
615  
616 1 $self->Duplicates;
617  
618 1 for my $option (keys %{$b->Option})
619 {
620 21 ▶ $self->Option->{$option} = $b->Option->{$option} unless defined $self->Option->{$option};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->Option->{$option} 0 21 21
621 }
622  
623 1 return 1;
624 }
625  
626 =pod
627  
628 Get a summary of control point error distances in pixel units scaled to the
629 output panorama:
630  
631 my ($total, $min, $max, $average, $sigma) = $p->Stats;
632  
633 =cut
634  
635 sub Stats
636 0 ▶{
Subroutine Stats: not called CC=10 SCAR=47.0
Pod undocumented
637 0 my $self = shift;
638  
639 # get a list of all the distances
640 0 my @distances;
641 0 for my $point (@{$self->Control})
642 {
643 0 ▶ next unless $point->{t} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $point->{"t"} == 0 0 0 0
644 0 push @distances, $point->Distance ($self);
645 }
646  
647 0 my $total = scalar (@distances);
648  
649 0 ▶ return (0,0,0,0,0) unless $total;
Branch: 1 branch
BranchTrueFalseTotal
unless $total 0 0 0
650  
651 # calculate maximum and average distance
652 0 my $max = undef;
653 0 my $min = undef;
654 0 my $sum = 0;
655 0 for my $distance (@distances)
656 {
657 0 ▶ $min = $distance unless defined $min;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min 0 0 0
658 0 ▶ $min = $distance if ($min > $distance);
Branch: 1 branch
BranchTrueFalseTotal
if $min > $distance 0 0 0
659 0 ▶ $max = $distance unless defined $max;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max 0 0 0
660 0 ▶ $max = $distance if ($max < $distance);
Branch: 1 branch
BranchTrueFalseTotal
if $max < $distance 0 0 0
661 0 $sum += $distance;
662 }
663 0 my $average = $sum / $total;
664  
665 # calculate variation and standard deviation (sigma)
666 0 $sum = 0;
667 0 for my $distance (@distances)
668 {
669 0 my $variation = $distance - $average;
670 0 $sum += $variation * $variation;
671 }
672 0 my $variance = $sum / $total;
673 0 my $sigma = sqrt ($variance);
674  
675 0 return ($total, $min, $max, $average, $sigma);
676 }
677  
678 =pod
679  
680 Centre input images into the final panorama:
681  
682 $p->Centre ('y');
683 $p->Centre ('p');
684 $p->Centre ('r');
685  
686 =cut
687  
688 sub Centre
689 0 ▶{
Subroutine Centre: not called CC=7 SCAR=40.3
Pod undocumented
690 0 my $self = shift;
691 0 my $param = shift;
692  
693 0 for my $image (@{$self->Image})
694 {
695 0 my $sigma_old = $self->Sigma ($param);
696 0 $image->{$param} += 360;
697 0 ▶ next if $self->Sigma ($param) < $sigma_old;
Branch: 1 branch
BranchTrueFalseTotal
if $self->Sigma($param) < $sigma_old 0 0 0
698 0 $image->{$param} -= 720;
699 0 ▶ next if $self->Sigma ($param) < $sigma_old;
Branch: 1 branch
BranchTrueFalseTotal
if $self->Sigma($param) < $sigma_old 0 0 0
700 0 $image->{$param} += 360;
701 }
702  
703 0 my $average_r = $self->_average ('r');
704 0 my $average_p = $self->_average ('p');
705 0 my $average_y = $self->_average ('y');
706  
707 0 ▶ if ($param eq 'r')
Branch: 1 branch
BranchTrueFalseTotal
if ($param eq "r") 0 0 0
708 {
709 0 $self->Transform (0, 0, 0 - $average_y);
710 0 $self->Transform (0, 0 - $average_p, 0);
711 0 $self->Transform (0 - $average_r, 0, 0);
712 0 $self->Transform (0, $average_p, 0);
713 0 $self->Transform (0, 0, $average_y);
714 }
715 0 ▶ if ($param eq 'p')
Branch: 1 branch
BranchTrueFalseTotal
if ($param eq "p") 0 0 0
716 {
717 0 $self->Transform (0, 0, 0 - $average_y);
718 0 $self->Transform (0, 0 - $average_p, 0);
719 0 $self->Transform (0, 0, $average_y);
720 }
721 0 ▶ if ($param eq 'y')
Branch: 1 branch
BranchTrueFalseTotal
if ($param eq "y") 0 0 0
722 {
723 0 $self->Transform (0, 0, 0 - $average_y);
724 }
725 }
726  
727 sub _average
728 0 ▶{
Subroutine _average: not called CC=2 SCAR=17.9
729 0 my $self = shift;
730 0 my $param = shift;
731 0 my $sum = 0;
732 0 for my $image (@{$self->Image})
733 {
734 0 $sum += $image->{$param}
735 }
736 0 return $sum / scalar @{$self->Image};
737 }
738  
739 sub Sigma
740 0 ▶{
Subroutine Sigma: not called CC=2 SCAR=17.9
Pod undocumented
741 0 my $self = shift;
742 0 my $param = shift;
743 0 my $sum = 0;
744 0 my $average = $self->_average ($param);
745 0 for my $image (@{$self->Image})
746 {
747 0 my $variation = $image->{$param} - $average;
748 0 $sum += $variation * $variation;
749 }
750 0 my $variance = $sum / scalar @{$self->Image};
751 0 return sqrt ($variance);
752 }
753  
754 =pod
755  
756 Split the project into exposure stacks based in roll, pitch & yaw, or into
757 exposure layers based on EV values:
758  
759 $stacks = $pto->Stacks;
760 $layers = $pto->ExposureLayers;
761  
762 Returns a list of image number lists.
763  
764 e.g. extract the first stack as a new project:
765  
766 $pto_stack = $pto->Subset (@{$pto->Stacks->[0]});
767  
768 =cut
769  
770 sub Stacks
771 0 ▶{
Subroutine Stacks: not called CC=4 SCAR=30.0
Pod undocumented
772 0 my $self = shift->Clone;
773 0 my $stacks = [];
774 0 my $maxShift = $self->Image->[0]->{v} / 10.0;
775 0 my @images = (0 .. scalar @{$self->Image} -1);
776 0 ▶ while (@images)
Branch: 1 branch
BranchTrueFalseTotal
if (@images) 0 0 0
777 {
778 0 my $base_image = shift @images;
779 0 my $stack = [$base_image];
780 0 my @images_remaining = @images;
781 0 for my $image (@images)
782 {
783 0 ▶ if (_samestack ($self->{image}->[$base_image], $self->{image}->[$image], $maxShift))
Branch: 1 branch
BranchTrueFalseTotal
if (_samestack($self->{"image"}[$base_image], $self->{"image"}[$image], $maxShift)) 0 0 0
784 {
785 0 push @{$stack}, $image;
786 0 @images_remaining = grep !/^$image$/, @images_remaining;
787 }
788 }
789 0 @images = @images_remaining;
790 0 push @{$stacks}, $stack;
791 }
792 0 return $stacks;
793 }
794  
795 sub _samestack
796 0 ▶{
Subroutine _samestack: not called CC=4 SCAR=30.0
797 0 my ($image0, $image1, $maxShift) = @_;
798 0 my $minShift = 360.0 - $maxShift;
799 0 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if abs $image0->y - $image1->y < $maxShift || abs $image0->y - $image1->y > $minShift and abs $image0->p - $image1->p < $maxShift 0 0 0
Condition0%0/6
abs $image0->y - $image1->y < $maxShift || abs $image0->y - $image1->y > $minShift and abs $image0->p - $image1->p < $maxShift
!ll&&!rl&&r
000
abs $image0->y - $image1->y < $maxShift or abs $image0->y - $image1->y > $minShift
l!l&&r!l&&!r
000
MC/DC0%0/3
abs $image0->y - $image1->y < $maxShift || abs $image0->y - $image1->y > $minShift and abs $image0->p - $image1->p < $maxShift
abs $image0->y - $image1->y < $maxShift abs $image0->y - $image1->y > $minShift abs $image0->p - $image1->p < $maxShift
Truth table0%0/5
A or B and C
A= abs $image0->y - $image1->y < $maxShiftB= abs $image0->y - $image1->y > $minShiftC= abs $image0->p - $image1->p < $maxShift
ABCresult
00X0
1X00
0100
1X11
0111
800 if ( (abs ($image0->y - $image1->y) < $maxShift || abs ($image0->y - $image1->y) > $minShift)
801 && abs ($image0->p - $image1->p) < $maxShift );
802 0 return 0;
803 }
804  
805 =pod
806  
807 Split a project into exposure layers, returns a list of lists of image ids:
808  
809 my $layers = $pto->ExposureLayers (1.0);
810  
811 Deafults to 0.5EV difference threshold.
812  
813 =cut
814  
815 sub ExposureLayers
816 0 ▶{
Subroutine ExposureLayers: not called CC=5 SCAR=34.0
Pod undocumented
817 0 my $self = shift->Clone;
818 0 my $layers = [];
819 0 ▶ my $maxEVDiff = shift || 0.5;
Condition0%0/2
shift() || 0.5
l!l
00
MC/DC0%0/1
shift() || 0.5
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
820 0 my @images = (0 .. scalar @{$self->Image} -1);
821 0 ▶ while (@images)
Branch: 1 branch
BranchTrueFalseTotal
if (@images) 0 0 0
822 {
823 0 my $base_image = shift @images;
824 0 my $layer = [$base_image];
825 0 my @images_remaining = @images;
826 0 for my $image (@images)
827 {
828 0 ▶ if (_samelayer ($self->{image}->[$base_image], $self->{image}->[$image], $maxEVDiff))
Branch: 1 branch
BranchTrueFalseTotal
if (_samelayer($self->{"image"}[$base_image], $self->{"image"}[$image], $maxEVDiff)) 0 0 0
829 {
830 0 push @{$layer}, $image;
831 0 @images_remaining = grep !/^$image$/, @images_remaining;
832 }
833 }
834 0 @images = @images_remaining;
835 0 push @{$layers}, $layer;
836 }
837 0 return $layers;
838 }
839  
840 sub _samelayer
841 0 ▶{
Subroutine _samelayer: not called CC=2 SCAR=17.9
842 0 my ($image0, $image1, $maxEVDiff) = @_;
843 0 ▶ return 1 if (abs ($image0->{Eev} - $image1->{Eev}) < $maxEVDiff );
Branch: 1 branch
BranchTrueFalseTotal
if abs $image0->{"Eev"} - $image1->{"Eev"} < $maxEVDiff 0 0 0
844 0 return 0;
845 }
846  
847 =pod
848  
849 Get a list of unconnected groups, i.e. a list of image id lists:
850  
851 $groups = $pto->ConnectedGroups;
852  
853 warn 'just one group' if scalar @{$groups} == 1;
854  
855 =cut
856  
857 sub ConnectedGroups
858 12 ▶{
Subroutine ConnectedGroups: called CC=10 SCAR=23.0
Pod undocumented
859 12 my $self = shift;
860 12 ▶ return [[]] unless scalar @{$self->Image};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$self->Image;} 0 12 12
861 12 my $groups = [[0]];
862 12 my $group_id = 0;
863  
864 12 my @images = (1 .. scalar @{$self->Image} -1);
865 12 ▶ while (@images)
Branch: 1 branch
BranchTrueFalseTotal
if (@images) 65 12 77
866 {
867 65 my $match = 0;
868 65 for my $image (@images)
869 {
870 166 ▶ next if $match;
Branch: 1 branch
BranchTrueFalseTotal
if $match 94 72 166
871 72 ▶ next if grep /^$image$/, @{$groups->[$group_id]};
Branch: 1 branch
BranchTrueFalseTotal
if grep /^$image$/, @{$$groups[$group_id];} 0 72 72
872 72 for my $base_image (@{$groups->[$group_id]})
873 {
874 263 ▶ next if $match;
Branch: 1 branch
BranchTrueFalseTotal
if $match 87 176 263
875 176 ▶ if (scalar $self->Connections ($base_image, $image))
Branch: 1 branch
BranchTrueFalseTotal
if (scalar $self->Connections($base_image, $image)) 51 125 176
876 {
877 51 push @{$groups->[$group_id]}, $image;
878 51 $match = 1;
879 51 @images = grep !/^$image$/, @images;
880 }
881 }
882 }
883 65 ▶ unless ($match)
Branch: 1 branch
BranchTrueFalseTotal
unless ($match) 14 51 65
884 {
885 14 $group_id++;
886 14 $groups->[$group_id]->[0] = shift @images;
887 }
888 }
889 12 return $groups;
890 }
891  
892 =pod
893  
894 Count the connections between any two images:
895  
896 $points = $pto->Connections (3, 5);
897  
898 =cut
899  
900 sub Connections
901 191 ▶{
Subroutine Connections: called CC=6 SCAR=18.0
Pod undocumented
902 191 my $self = shift;
903 191 my ($a, $b) = @_;
904  
905 191 my $results = 0;
906 191 for my $control (@{$self->Control})
907 {
908 7885 my $N = $control->{N};
909 7885 my $n = $control->{n};
910 7885 ▶ $results++ if (($n == $a and $N == $b) or ($n == $b and $N == $a));
Branch: 1 branch
BranchTrueFalseTotal
if $n == $a and $N == $b or $n == $b and $N == $a 536 7349 7885
Condition77%7/9
$n == $a and $N == $b or $n == $b and $N == $a
l!l&&r!l&&!r
53607349
$n == $a and $N == $b
!ll&&!rl&&r
56551694536
$n == $b and $N == $a
!ll&&!rl&&r
68784710
MC/DC50%2/4
$n == $a and $N == $b or $n == $b and $N == $a
$n == $a $N == $b $n == $b $N == $a
Truth table71%5/7
A and B or C and D
A= $n == $aB= $N == $bC= $n == $bD= $N == $a
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
911 }
912 191 return $results;
913 }
914  
915 =pod
916  
917 Given a project with unlinked lens parameters, link them together with the same
918 lens number if all distortion, and photometric parameters match:
919  
920 $pto->UnifyLenses;
921  
922 =cut
923  
924 sub UnifyLenses
925 0 ▶{
Subroutine UnifyLenses: not called CC=20 SCAR=60.4
Pod undocumented
926 0 my $self = shift;
927 0 for my $id (1 .. scalar @{$self->Image} -1)
928 {
929 0 my $img = $self->Image->[$id];
930 0 for my $base_id (0 .. $id -1)
931 {
932 0 my $base_img = $self->Image->[$base_id];
933 0 ▶ if ($img->v ($self) eq $base_img->{v}
Branch: 1 branch
BranchTrueFalseTotal
if ($img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"} and $img->Ra($self) eq $base_img->{"Ra"} and $img->Rb($self) eq $base_img->{"Rb"} and $img->Rc($self) eq $base_img->{"Rc"} and $img->Rd($self) eq $base_img->{"Rd"} and $img->Re($self) eq $base_img->{"Re"} and $img->Va($self) eq $base_img->{"Va"} and $img->Vb($self) eq $base_img->{"Vb"} and $img->Vc($self) eq $base_img->{"Vc"} and $img->Vd($self) eq $base_img->{"Vd"} and $img->Vx($self) eq $base_img->{"Vx"} and $img->Vy($self) eq $base_img->{"Vy"}) 0 0 0
Condition0%0/48
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"} and $img->Ra($self) eq $base_img->{"Ra"} and $img->Rb($self) eq $base_img->{"Rb"} and $img->Rc($self) eq $base_img->{"Rc"} and $img->Rd($self) eq $base_img->{"Rd"} and $img->Re($self) eq $base_img->{"Re"} and $img->Va($self) eq $base_img->{"Va"} and $img->Vb($self) eq $base_img->{"Vb"} and $img->Vc($self) eq $base_img->{"Vc"} and $img->Vd($self) eq $base_img->{"Vd"} and $img->Vx($self) eq $base_img->{"Vx"} and $img->Vy($self) eq $base_img->{"Vy"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"} and $img->Ra($self) eq $base_img->{"Ra"} and $img->Rb($self) eq $base_img->{"Rb"} and $img->Rc($self) eq $base_img->{"Rc"} and $img->Rd($self) eq $base_img->{"Rd"} and $img->Re($self) eq $base_img->{"Re"} and $img->Va($self) eq $base_img->{"Va"} and $img->Vb($self) eq $base_img->{"Vb"} and $img->Vc($self) eq $base_img->{"Vc"} and $img->Vd($self) eq $base_img->{"Vd"} and $img->Vx($self) eq $base_img->{"Vx"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"} and $img->Ra($self) eq $base_img->{"Ra"} and $img->Rb($self) eq $base_img->{"Rb"} and $img->Rc($self) eq $base_img->{"Rc"} and $img->Rd($self) eq $base_img->{"Rd"} and $img->Re($self) eq $base_img->{"Re"} and $img->Va($self) eq $base_img->{"Va"} and $img->Vb($self) eq $base_img->{"Vb"} and $img->Vc($self) eq $base_img->{"Vc"} and $img->Vd($self) eq $base_img->{"Vd"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"} and $img->Ra($self) eq $base_img->{"Ra"} and $img->Rb($self) eq $base_img->{"Rb"} and $img->Rc($self) eq $base_img->{"Rc"} and $img->Rd($self) eq $base_img->{"Rd"} and $img->Re($self) eq $base_img->{"Re"} and $img->Va($self) eq $base_img->{"Va"} and $img->Vb($self) eq $base_img->{"Vb"} and $img->Vc($self) eq $base_img->{"Vc"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"} and $img->Ra($self) eq $base_img->{"Ra"} and $img->Rb($self) eq $base_img->{"Rb"} and $img->Rc($self) eq $base_img->{"Rc"} and $img->Rd($self) eq $base_img->{"Rd"} and $img->Re($self) eq $base_img->{"Re"} and $img->Va($self) eq $base_img->{"Va"} and $img->Vb($self) eq $base_img->{"Vb"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"} and $img->Ra($self) eq $base_img->{"Ra"} and $img->Rb($self) eq $base_img->{"Rb"} and $img->Rc($self) eq $base_img->{"Rc"} and $img->Rd($self) eq $base_img->{"Rd"} and $img->Re($self) eq $base_img->{"Re"} and $img->Va($self) eq $base_img->{"Va"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"} and $img->Ra($self) eq $base_img->{"Ra"} and $img->Rb($self) eq $base_img->{"Rb"} and $img->Rc($self) eq $base_img->{"Rc"} and $img->Rd($self) eq $base_img->{"Rd"} and $img->Re($self) eq $base_img->{"Re"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"} and $img->Ra($self) eq $base_img->{"Ra"} and $img->Rb($self) eq $base_img->{"Rb"} and $img->Rc($self) eq $base_img->{"Rc"} and $img->Rd($self) eq $base_img->{"Rd"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"} and $img->Ra($self) eq $base_img->{"Ra"} and $img->Rb($self) eq $base_img->{"Rb"} and $img->Rc($self) eq $base_img->{"Rc"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"} and $img->Ra($self) eq $base_img->{"Ra"} and $img->Rb($self) eq $base_img->{"Rb"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"} and $img->Ra($self) eq $base_img->{"Ra"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"}
!ll&&!rl&&r
000
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"}
!ll&&!rl&&r
000
MC/DC0%0/17
$img->v($self) eq $base_img->{"v"} and $img->a($self) eq $base_img->{"a"} and $img->b($self) eq $base_img->{"b"} and $img->c($self) eq $base_img->{"c"} and $img->d($self) eq $base_img->{"d"} and $img->e($self) eq $base_img->{"e"} and $img->Ra($self) eq $base_img->{"Ra"} and $img->Rb($self) eq $base_img->{"Rb"} and $img->Rc($self) eq $base_img->{"Rc"} and $img->Rd($self) eq $base_img->{"Rd"} and $img->Re($self) eq $base_img->{"Re"} and $img->Va($self) eq $base_img->{"Va"} and $img->Vb($self) eq $base_img->{"Vb"} and $img->Vc($self) eq $base_img->{"Vc"} and $img->Vd($self) eq $base_img->{"Vd"} and $img->Vx($self) eq $base_img->{"Vx"} and $img->Vy($self) eq $base_img->{"Vy"}
too many conditions
934 and $img->a ($self) eq $base_img->{a}
935 and $img->b ($self) eq $base_img->{b}
936 and $img->c ($self) eq $base_img->{c}
937 and $img->d ($self) eq $base_img->{d}
938 and $img->e ($self) eq $base_img->{e}
939 and $img->Ra ($self) eq $base_img->{Ra}
940 and $img->Rb ($self) eq $base_img->{Rb}
941 and $img->Rc ($self) eq $base_img->{Rc}
942 and $img->Rd ($self) eq $base_img->{Rd}
943 and $img->Re ($self) eq $base_img->{Re}
944 and $img->Va ($self) eq $base_img->{Va}
945 and $img->Vb ($self) eq $base_img->{Vb}
946 and $img->Vc ($self) eq $base_img->{Vc}
947 and $img->Vd ($self) eq $base_img->{Vd}
948 and $img->Vx ($self) eq $base_img->{Vx}
949 and $img->Vy ($self) eq $base_img->{Vy}
950 )
951 {
952 0 $img->{v} = "=$base_id";
953 0 $img->{a} = "=$base_id";
954 0 $img->{b} = "=$base_id";
955 0 $img->{c} = "=$base_id";
956 0 $img->{d} = "=$base_id";
957 0 $img->{e} = "=$base_id";
958 0 $img->{Ra} = "=$base_id";
959 0 $img->{Rb} = "=$base_id";
960 0 $img->{Rc} = "=$base_id";
961 0 $img->{Rd} = "=$base_id";
962 0 $img->{Re} = "=$base_id";
963 0 $img->{Va} = "=$base_id";
964 0 $img->{Vb} = "=$base_id";
965 0 $img->{Vc} = "=$base_id";
966 0 $img->{Vd} = "=$base_id";
967 0 $img->{Vx} = "=$base_id";
968 0 $img->{Vy} = "=$base_id";
969 0 next;
970 }
971 }
972 }
973 }
974  
975 =pod
976  
977 Given a project with stacks indicated by 'j' parameters, hard-link the
978 positions (only recognised by Hugin with layout mode code).
979  
980 $pto->LinkStacks;
981  
982 =cut
983  
984 sub LinkStacks
985 0 ▶{
Subroutine LinkStacks: not called CC=6 SCAR=37.4
Pod undocumented
986 0 my $self = shift;
987 0 for my $id (1 .. scalar @{$self->Image} -1)
988 {
989 0 my $img = $self->Image->[$id];
990 0 my $found;
991 0 for my $base_id (0 .. $id -1)
992 {
993 0 ▶ next if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 0 0
994 0 my $base_img = $self->Image->[$base_id];
995 0 ▶ next unless defined $img->{j};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $img->{"j"} 0 0 0
996 0 ▶ if ($img->{j} eq $base_img->{j})
Branch: 1 branch
BranchTrueFalseTotal
if ($img->{"j"} eq $base_img->{"j"}) 0 0 0
997 {
998 0 $img->{r} = "=$base_id";
999 0 $img->{p} = "=$base_id";
1000 0 $img->{y} = "=$base_id";
1001 0 $found = 1;
1002 0 next;
1003 }
1004 }
1005 }
1006 }
1007  
1008 =pod
1009  
1010 Return the angular distance in degrees between two images:
1011  
1012 $deg = $pto->AngularDistance (3, 5);
1013  
1014 =cut
1015  
1016 sub AngularDistance
1017 14 ▶{
Subroutine AngularDistance: called CC=3 SCAR=11.3
Pod undocumented
1018 14 my $self = shift;
1019 14 ▶ return undef unless ($_[0] =~ /^[0-9]+$/ and $_[1] =~ /^[0-9]+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^[0-9]+$/ and $_[1] =~ /^[0-9]+$/ 0 14 14
Condition33%1/3
$_[0] =~ /^[0-9]+$/ and $_[1] =~ /^[0-9]+$/
!ll&&!rl&&r
0014
MC/DC0%0/2
$_[0] =~ /^[0-9]+$/ and $_[1] =~ /^[0-9]+$/
$_[0] =~ /^[0-9]+$/ $_[1] =~ /^[0-9]+$/
Truth table33%1/3
A and B
A= $_[0] =~ /^[0-9]+$/B= $_[1] =~ /^[0-9]+$/
ABresult
0X0
100
111
1020 14 my $yaw_a = $self->Image->[$_[0]]->y ($self);
1021 14 my $pitch_a = $self->Image->[$_[0]]->p ($self);
1022 14 my $yaw_b = $self->Image->[$_[1]]->y ($self);
1023 14 my $pitch_b = $self->Image->[$_[1]]->p ($self);
1024 14 my $distance = great_circle_distance ($yaw_a * pi/180, pi/2 - ($pitch_a * pi/180),
1025 $yaw_b * pi/180, pi/2 - ($pitch_b * pi/180));
1026 14 return $distance * 180/pi;
1027 }
1028  
1029 =pod
1030  
1031 Look at all photos and calculate an optimal pixel width for this panorama,
1032 optionally supply a scaling factor:
1033  
1034 $width = $pto->OptimalWidth (0.7);
1035  
1036 This number is rounded up to the nearest multiple of 16 pixels.
1037  
1038 =cut
1039  
1040 sub OptimalWidth
1041 0 ▶{
Subroutine OptimalWidth: not called CC=7 SCAR=40.3
Pod undocumented
1042 0 my $self = shift;
1043 0 ▶ my $factor = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1044 0 my $pix_radius_max = 1;
1045 0 for (@{$self->Image})
1046 {
1047 0 my $pix_radius = $_->Radius ($self);
1048 0 ▶ $pix_radius_max = $pix_radius if $pix_radius > $pix_radius_max;
Branch: 1 branch
BranchTrueFalseTotal
if $pix_radius > $pix_radius_max 0 0 0
1049 }
1050 0 my $pix_width;
1051 0 my $rad_fov = Math::Trig::deg2rad ($self->Panorama->{v});
1052 0 ▶ $rad_fov = 2 * Math::Trig::pi() if $rad_fov == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rad_fov == 0 0 0 0
1053 0 ▶ if ($self->Panorama->{f} == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Panorama->{'f'} == 0) { } 0 0 0
1054 {
1055 0 ▶ return $self->Panorama->{w} if $self->Panorama->{v} >= 180;
Branch: 1 branch
BranchTrueFalseTotal
if $self->Panorama->{"v"} >= 180 0 0 0
1056 0 $pix_width = 2 * $pix_radius_max * Math::Trig::tan ($rad_fov/2);
1057 }
1058 else
1059 {
1060 0 $pix_width = $pix_radius_max * $rad_fov;
1061 }
1062 0 return int (($pix_width * $factor / 16) +1) * 16;
1063 }
1064  
1065 =pod
1066  
1067 Hugin ships with a tool called pano_trafo for querying the forward and reverse
1068 transform for pixel coordinates in a PTO project.
1069  
1070 Initialise this as a service, spawns two pano_trafo processes which are only
1071 killed when the perl process finishes:
1072  
1073 $pto->InitTrafo ('/path/to/project.pto');
1074  
1075 This is very unlikely to work on non-unixy systems.
1076  
1077 =cut
1078  
1079 sub InitTrafo
1080 0 ▶{
Subroutine InitTrafo: not called CC=6 SCAR=32.0
Pod undocumented
1081 0 my $self = shift;
1082 0 ▶ my $path_pto = shift || return 0;
Condition0%0/2
shift() || (return 0)
l!l
00
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1083 10 ▶ use IPC::Open2;
Subroutine BEGIN: called CC=1 SCAR=0.0
1084 10 ▶ use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
1085  
1086 0 ▶ my $pid_forward_old = $self->{trafo_forward}->{pid} || undef;
Condition0%0/2
$self->{'trafo_forward'}{'pid'} || undef
l!l
00
MC/DC0%0/1
$self->{'trafo_forward'}{'pid'} || undef
$self->{'trafo_forward'}{'pid'}
Truth table0%0/2
A
A= $self->{'trafo_forward'}{'pid'}
Aresult
11
00
1087 0 my $WTR_forward = gensym;
1088 0 my $RDR_forward = gensym;
1089 0 my $pid_forward = open2 ($RDR_forward, $WTR_forward, 'pano_trafo', $path_pto);
1090 0 $self->{trafo_forward} = {pid => $pid_forward, WTR => $WTR_forward, RDR => $RDR_forward};
1091  
1092 0 ▶ my $pid_reverse_old = $self->{trafo_reverse}->{pid} || undef;
Condition0%0/2
$self->{'trafo_reverse'}{'pid'} || undef
l!l
00
MC/DC0%0/1
$self->{'trafo_reverse'}{'pid'} || undef
$self->{'trafo_reverse'}{'pid'}
Truth table0%0/2
A
A= $self->{'trafo_reverse'}{'pid'}
Aresult
11
00
1093 0 my $WTR_reverse = gensym;
1094 0 my $RDR_reverse = gensym;
1095 0 my $pid_reverse = open2 ($RDR_reverse, $WTR_reverse, 'pano_trafo', '-r', $path_pto);
1096 0 $self->{trafo_reverse} = {pid => $pid_reverse, WTR => $WTR_reverse, RDR => $RDR_reverse};
1097  
1098 0 ▶ waitpid ($pid_forward_old, 0) if defined $pid_forward_old;
Branch: 1 branch
BranchTrueFalseTotal
if defined $pid_forward_old 0 0 0
1099 0 ▶ waitpid ($pid_reverse_old, 0) if defined $pid_reverse_old;
Branch: 1 branch
BranchTrueFalseTotal
if defined $pid_reverse_old 0 0 0
1100 }
1101  
1102 =pod
1103  
1104 Query the forward transform like so:
1105  
1106 ($X, $Y) = $pto->Trafo ($image_no, $x, $y);
1107  
1108 =cut
1109  
1110 sub Trafo
1111 0 ▶{
Subroutine Trafo: not called CC=1 SCAR=6.9
Pod undocumented
1112 0 my $self = shift;
1113 0 my ($image, $x, $y) = @_;
1114 0 my $WTX = $self->{trafo_forward}->{WTR};
1115 0 my $RDX = $self->{trafo_forward}->{RDR};
1116 0 print $WTX join (' ', $image, $x, $y) . "\n";
1117 0 my $result = <$RDX>;
1118 0 chomp $result;
1119 0 return split ' ', $result;
1120 }
1121  
1122 =pod
1123  
1124 Query the reverse transform like so:
1125  
1126 ($x, $y) = $pto->TrafoReverse ($image_no, $X, $Y);
1127  
1128 =cut
1129  
1130 sub TrafoReverse
1131 0 ▶{
Subroutine TrafoReverse: not called CC=1 SCAR=6.9
Pod undocumented
1132 0 my $self = shift;
1133 0 my ($image, $x, $y) = @_;
1134 0 my $WTX = $self->{trafo_reverse}->{WTR};
1135 0 my $RDX = $self->{trafo_reverse}->{RDR};
1136 0 print $WTX join (' ', $image, $x, $y) . "\n";
1137 0 my $result = <$RDX>;
1138 0 chomp $result;
1139 0 return split ' ', $result;
1140 }
1141  
1142 =head1 COPYRIGHT
1143  
1144 Copyright (c) 2001 Bruno Postle <bruno@postle.net>. All Rights Reserved.
1145  
1146 This program is free software; you can redistribute it and/or
1147 modify it under the terms of the GNU General Public
1148 License as published by the Free Software Foundation; either
1149 version 2 of the License, or (at your option) any later version.
1150  
1151 This software is distributed in the hope that it will be useful,
1152 but WITHOUT ANY WARRANTY; without even the implied warranty of
1153 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1154 General Public License for more details.
1155  
1156 You should have received a copy of the GNU General Public
1157 License along with this software; if not, write to the Free Software
1158 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1159  
1160 =cut
1161  
1162 10 1;
1163  
↑ Summary lib/Panotools/Script/Line/Variable.pm »