lib/PDL/IO/Dcm/Plugins/Primitive.pm

filter: Statementstmt 36.5% 15 / 41 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 37.2% 22 / 59 CC 5 SCAR 21.9
CC
5
Cov
31%
handle_duplicates
20.0
setup_dcm
6.0
populate_header
2.0
CRAP 8.9
« lib/PDL/IO/Dcm.pm ↑ Summary script/sort_dcms.pl »
1 #!/usr/bin/perl
2  
3 package PDL::IO::Dcm::Plugins::Primitive;
4 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use PDL;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use PDL::NiceSlice;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 #use 5.10.0;
9  
10  
11 2 our @ISA=qw/Exporter/;
12 2 our @EXPORT_OK=qw/populate_header setup_dcm/;
13  
14 0 ▶sub setup_dcm {
Subroutine setup_dcm: not called CC=2 SCAR=17.9
Pod documented
15 0 my $opt=shift;
16 0 ▶ $opt={} unless (ref($opt) eq 'HASH'); # ensure hash context
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opt eq "HASH" 0 0 0
17 # split on series number by default
18 0 $$opt{id}=\&PDL::IO::Dcm::sort_series;
19 0 $$opt{dim_order}=[0,1];
20 0 $$opt{parser}=\&populate_header;
21 0 $$opt{duplicates}=\&handle_duplicates;
22 0 $$opt{delete_raw}=1; # deletes the raw_dicom structure after parsing
23 0 $$opt{Dimensions}=[qw/x y InstanceNumber n/];
24 0 $opt;
25 }
26  
27 0 ▶sub populate_header {
Subroutine populate_header: not called CC=1 SCAR=6.9
Pod documented
28 0 my $dicom =shift;
29 0 my $piddle=shift;
30 0 my $in=$dicom->getValue('InstanceNumber');
31 0 $piddle->hdr->{dcm_key}=$piddle->hdr->{dicom}->{'SOP Instance UID'};
32 0 my $pos=pdl(ushort,$in-1,0);
33 0 $piddle->hdr->{dim_idx}=$pos;
34 0 return $in;
35 }
36  
37 0 ▶sub handle_duplicates {
Subroutine handle_duplicates: not called CC=4 SCAR=30.0
Pod documented
38 0 my $stack=shift;
39 0 my $dcm=shift;
40 #my $str=',,'.$dcm->hdr->{dim_idx}->(0);
41 #say "duplicate ",$dcm->hdr->{dim_idx}, $stack->info;
42 0 my $idx=$dcm->hdr->{dim_idx};
43 0 my $n=$idx(1);
44 #say "$n - idx: ",$idx->info;
45 # increase the second index until we find an empty space
46 # data flow should store
47 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$stack->slice(list($idx)) and do { do { ++$n; if (sclr($stack->shape->slice(-1) <= $n)) { $stack = $stack->mv(-1, 0)->append(0)->mv(0, -1); } ; barf("This is impossible $n, $idx, ", $stack->slice($idx->slice(0), "X")->reshape(-1)) if $n > 2 } } 0 0 0
48 #say "$idx ",$stack(list ($idx);-),"; ";
49 #print "$idx n $n exists? ",$stack(list($idx);-),"\n";
50 #say $n," >= shape ",$stack->shape->(-1);
51 0 $n++;
52 0 ▶ if (sclr $stack->shape->(-1) <= ($n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (sclr($stack->shape->slice(-1) <= $n)) 0 0 0
53 #say "growing $n",$stack->shape->(-1);
54 0 $stack=$stack->mv(-1,0)->append(0)->mv(0,-1);
55 }
56 0 ▶ barf "This is impossible $n, $idx, ",$stack($idx(0),;-) if $n>2;
Branch: 1 branch
BranchTrueFalseTotal
if $n > 2 0 0 0
57 } while ($stack(list ($idx)));
58 #say "new dim_dix ",$dcm->hdr->{dim_idx}, $stack->info;
59 #$dcm->hdr->{dim_idx}=
60 #$stack->(,,list($dcm->hdr->{dim_idx}),$n).=$dcm;
61 #"This entry (". $dcm->hdr->{dim_idx}->($order).
62 #max ($data{$pid}->(,,list $dcm->hdr->{dim_idx}->($order))).
63 #") is already set! This should not happen, please file a bug report!\n";
64 0 $stack;
65 }
66 =head1 General
67  
68 This module provides simple splitting based on intance number and should be used
69 as template when writing more specific plugin modules.
70  
71 The setup_dcm creates a template options hash.
72  
73 =head1 FUNCTIONS
74  
75 =head2 handle_duplicates
76  
77 If more data with the same series/instance number arrive -- can happen -- the second
78 index is incremented until a free slot is found. It is up to the user to sort the mess,
79 i.e. write/use a more sophisticated plugin.
80  
81 =head2 populate_header
82  
83 Here happens the vendor/modallity specific stuff like parsing private fields.
84 It is required to set the IcePos and dcm_key fields in the piddle header. dcm_key
85 serves mainly as a unique identifier, IcePos is an index piddle.
86  
87 =head2 setup_dcm
88  
89 sets useful options for this modality. Should accept a hash ref and return one.
90  
91 =head2 sort_protid
92  
93 alternative to split based on lProtID (matches raw data key)
94  
95 =cut
96  
97 2 1;
« lib/PDL/IO/Dcm.pm ↑ Summary script/sort_dcms.pl »