]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkImageExtractComponents.cxx
#3457 creaVtk Feature New Normal - new box VtkWriteLstImages
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkImageExtractComponents.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbcreaVtkImageExtractComponents.h"
5 #include "bbcreaVtkPackage.h"
6 namespace bbcreaVtk
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ImageExtractComponents)
10 BBTK_BLACK_BOX_IMPLEMENTATION(ImageExtractComponents,bbtk::AtomicBlackBox);
11 //===== 
12 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
13 //===== 
14 void ImageExtractComponents::Process()
15 {
16
17 // THE MAIN PROCESSING METHOD BODY
18 //   Here we simply set the input 'In' value to the output 'Out'
19 //   And print out the output value
20 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
21 //    void bbSet{Input|Output}NAME(const TYPE&)
22 //    const TYPE& bbGet{Input|Output}NAME() const 
23 //    Where :
24 //    * NAME is the name of the input/output
25 //      (the one provided in the attribute 'name' of the tag 'input')
26 //    * TYPE is the C++ type of the input/output
27 //      (the one provided in the attribute 'type' of the tag 'input')
28
29 //    bbSetOutputOut( bbGetInputIn() );
30 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
31   
32         bbSetOutputOut0( NULL ); 
33         bbSetOutputOut1( NULL ); 
34         bbSetOutputOut2( NULL ); 
35         bbSetOutputOut3( NULL ); 
36
37 // InputComponent 0..3
38         if (bbGetInputType()==0)   
39         {    
40         
41                         if (bbGetInputComponent0()!=-1)
42                         {
43                 //EED 2017-01-01 Migration VTK7
44                 #if VTK_MAJOR_VERSION <= 5
45                                 IEC0->SetInput( bbGetInputIn() );
46                 #else
47                                 IEC0->SetInputData( bbGetInputIn() );
48                 #endif
49                                 IEC0->SetComponents( bbGetInputComponent0() );
50                                 IEC0->Update();
51                                 bbSetOutputOut0( IEC0->GetOutput() ); 
52                         } 
53
54                         if (bbGetInputComponent1()!=-1)
55                         {
56                 //EED 2017-01-01 Migration VTK7
57                 #if VTK_MAJOR_VERSION <= 5
58                                 IEC1->SetInput( bbGetInputIn() );
59                 #else
60                                 IEC1->SetInputData( bbGetInputIn() );
61                 #endif
62                                 IEC1->SetComponents( bbGetInputComponent1() );
63                                 IEC1->Update();
64                                 bbSetOutputOut1( IEC1->GetOutput() ); 
65                         }
66
67                         if (bbGetInputComponent2()!=-1)
68                         {
69                 //EED 2017-01-01 Migration VTK7
70                 #if VTK_MAJOR_VERSION <= 5
71                                 IEC2->SetInput( bbGetInputIn() );
72                 #else
73                                 IEC2->SetInputData( bbGetInputIn() );
74                 #endif
75                                 IEC2->SetComponents( bbGetInputComponent2() );
76                                 IEC2->Update();
77                                 bbSetOutputOut2( IEC2->GetOutput() ); 
78                         }
79
80                         if (bbGetInputComponent3()!=-1)
81                         {
82                 //EED 2017-01-01 Migration VTK7
83                 #if VTK_MAJOR_VERSION <= 5
84                                 IEC3->SetInput( bbGetInputIn() );
85                 #else
86                                 IEC3->SetInputData( bbGetInputIn() );
87                 #endif
88                                 IEC3->SetComponents( bbGetInputComponent2() );
89                                 IEC3->Update();
90                                 bbSetOutputOut3( IEC3->GetOutput() ); 
91                         }
92         } // Type 0
93
94 // List of components
95         if (bbGetInputType()==1) 
96         {   
97                 int i,size=lstIEC.size();
98                 for (i=0; i<size; i++)
99                 {
100                         lstIEC[i]->Delete();
101                 } // for i
102                 lstIEC.clear();
103                 lstOut.clear();
104                 int nrCmp = bbGetInputIn()->GetNumberOfScalarComponents();
105                 for (i=0; i<nrCmp; i++)
106                 {
107                         vtkImageExtractComponents* IEC;
108                         IEC=vtkImageExtractComponents::New();  
109                         IEC->SetInputData( bbGetInputIn() );
110                         IEC->SetComponents( i );
111                         IEC->Update();
112                         lstIEC.push_back( IEC);
113                         lstOut.push_back( IEC->GetOutput() );
114                 } // for i
115                 bbSetOutputLstOut( lstOut ); 
116         } // Type 1
117 }
118
119 //===== 
120 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
121 //===== 
122 void ImageExtractComponents::bbUserSetDefaultValues()
123 {
124 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
125 //    Here we initialize the input 'In' to 0
126    bbSetInputIn(NULL);
127    bbSetInputComponent0(-1);
128    bbSetInputComponent1(-1);
129    bbSetInputComponent2(-1);
130    bbSetInputComponent3(-1);
131    bbSetInputType(0);
132 }
133
134 //===== 
135 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
136 //===== 
137 void ImageExtractComponents::bbUserInitializeProcessing()
138 {
139
140 //  THE INITIALIZATION METHOD BODY :
141 //    Here does nothing 
142 //    but this is where you should allocate the internal/output pointers 
143 //    if any 
144
145         IEC0=vtkImageExtractComponents::New();  
146         IEC1=vtkImageExtractComponents::New();  
147         IEC2=vtkImageExtractComponents::New();  
148         IEC3=vtkImageExtractComponents::New();  
149 }
150 //===== 
151 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
152 //===== 
153 void ImageExtractComponents::bbUserFinalizeProcessing()
154 {
155 //  THE FINALIZATION METHOD BODY :
156 //    Here does nothing 
157 //    but this is where you should desallocate the internal/output pointers 
158 //    if any
159         IEC0->Delete();  
160         IEC1->Delete();  
161         IEC2->Delete();  
162         IEC3->Delete();  
163         int i,size=lstIEC.size();
164         for (i=0; i<size; i++)
165         {
166                 lstIEC[i]->Delete();
167         } // for i
168         lstIEC.clear();
169 }
170
171 }
172 // EO namespace bbcreaVtk
173
174