]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkVoiMPR.cxx
#spc.push_back(1);
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkVoiMPR.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 "bbcreaVtkVoiMPR.h"
5 #include "bbcreaVtkPackage.h"
6
7 namespace bbcreaVtk
8 {
9
10 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,VoiMPR)
11 BBTK_BLACK_BOX_IMPLEMENTATION(VoiMPR,bbtk::AtomicBlackBox);
12 //===== 
13 // 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)
14 //===== 
15 void VoiMPR::Process()
16 {
17
18 // THE MAIN PROCESSING METHOD BODY
19 //   Here we simply set the input 'In' value to the output 'Out'
20 //   And print out the output value
21 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
22 //    void bbSet{Input|Output}NAME(const TYPE&)
23 //    const TYPE& bbGet{Input|Output}NAME() const 
24 //    Where :
25 //    * NAME is the name of the input/output
26 //      (the one provided in the attribute 'name' of the tag 'input')
27 //    * TYPE is the C++ type of the input/output
28 //      (the one provided in the attribute 'type' of the tag 'input')
29 //    bbSetOutputOut( bbGetInputIn() );
30 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
31   
32         if (bbGetInputIn().size()!=6)
33         {
34                 printf("EED Warning box not defined.\n");
35         } else {
36                 bool showActorXY;
37                 bool showActorYZ;
38                 bool showActorXZ;
39
40                 std::vector<int> vecVOI = bbGetInputIn();
41                 std::vector<double> spc = bbGetInputSpacing();
42                 vecVOI[0] = vecVOI[0]*spc[0];
43                 vecVOI[1] = vecVOI[1]*spc[0];
44                 vecVOI[2] = vecVOI[2]*spc[1];
45                 vecVOI[3] = vecVOI[3]*spc[1];
46                 vecVOI[4] = vecVOI[4]*spc[2];
47                 vecVOI[5] = vecVOI[5]*spc[2];
48                 int dep;
49                 std::vector<int> vecPoint = bbGetInputActualPoint();
50                 vecPoint[0] = vecPoint[0]*spc[0];
51                 vecPoint[1] = vecPoint[1]*spc[1];
52                 vecPoint[2] = vecPoint[2]*spc[2];
53
54                 if (vecPoint.size()==3)
55                 {
56                         if ((vecPoint[0]>=vecVOI[0]) && (vecPoint[0]<=vecVOI[1]) ) 
57                         {       
58                                 showActorYZ=bbGetInputActive() && true; 
59                         } else {
60                                 showActorYZ=bbGetInputActive() && false;        
61                         }
62                         if ((vecPoint[1]>=vecVOI[2]) && (vecPoint[1]<=vecVOI[3]) ) 
63                         {       
64                                 showActorXZ=bbGetInputActive() && true; 
65                         } else {
66                                 showActorXZ=bbGetInputActive() && false;        
67                         }
68                         if ((vecPoint[2]>=vecVOI[4]) && (vecPoint[2]<=vecVOI[5]) ) 
69                         {       
70                                 showActorXY=bbGetInputActive() && true; 
71                         } else {
72                                 showActorXY=bbGetInputActive() && false;        
73                         }
74                 
75                 } else {
76                         showActorXY=bbGetInputActive();
77                         showActorYZ=bbGetInputActive();
78                         showActorXZ=bbGetInputActive();
79                 }
80
81                 if (bbGetInputXYrender()!=NULL)
82                 {
83                         dep=-900;
84                         pointsXY->SetPoint(0, vecVOI[0], vecVOI[2], dep);
85                         pointsXY->SetPoint(1, vecVOI[0], vecVOI[3], dep);
86                         pointsXY->SetPoint(2, vecVOI[1], vecVOI[3], dep);
87                         pointsXY->SetPoint(3, vecVOI[1], vecVOI[2], dep);
88                         pointsXY-> Modified();
89                         if ( showActorXY==true )
90                         {
91                                 if (actorAddedXY==false)
92                                 {
93                                         bbGetInputXYrender()->AddActor(polygonActorXY);
94                                         actorAddedXY=true;
95                                 } // 
96                         } else {
97                                 if (actorAddedXY==true)
98                                 {
99                                         bbGetInputXYrender()->RemoveActor(polygonActorXY);
100                                         actorAddedXY=false;
101                                 } // 
102                         }// Active
103                 } // if XYrender
104                 if (bbGetInputYZrender()!=NULL)
105                 {
106                         dep=900;
107                         pointsYZ->SetPoint(0, dep,vecVOI[2], vecVOI[4] );
108                         pointsYZ->SetPoint(1, dep,vecVOI[2], vecVOI[5] );
109                         pointsYZ->SetPoint(2, dep,vecVOI[3], vecVOI[5] );
110                         pointsYZ->SetPoint(3, dep,vecVOI[3], vecVOI[4] );
111                         pointsYZ-> Modified();
112                         if ( showActorYZ==true )
113                         {
114                                 if (actorAddedYZ==false)
115                                 {
116                                         bbGetInputYZrender()->AddActor(polygonActorYZ);
117                                         actorAddedYZ=true;
118                                 } // 
119                         } else {
120                                 if (actorAddedYZ==true)
121                                 {
122                                         bbGetInputYZrender()->RemoveActor(polygonActorYZ);
123                                         actorAddedYZ=false;
124                                 } // 
125                         }// Active
126                 } // if XYrender
127                 if (bbGetInputXZrender()!=NULL)
128                 {
129                         dep=-900;
130                         pointsXZ->SetPoint(0, vecVOI[0],dep, vecVOI[4] );
131                         pointsXZ->SetPoint(1, vecVOI[0],dep, vecVOI[5] );
132                         pointsXZ->SetPoint(2, vecVOI[1],dep, vecVOI[5] );
133                         pointsXZ->SetPoint(3, vecVOI[1],dep, vecVOI[4] );
134                         pointsXZ-> Modified();
135                         if ( showActorXZ==true )
136                         {
137                                 if (actorAddedXZ==false)
138                                 {
139                                         bbGetInputXZrender()->AddActor(polygonActorXZ);
140                                         actorAddedXZ=true;
141                                 } // 
142                         } else {
143                                 if (actorAddedXZ==true)
144                                 {
145                                         bbGetInputXZrender()->RemoveActor(polygonActorXZ);
146                                         actorAddedXZ=false;
147                                 } // 
148                         }// Active
149                 } // if XYrender
150         } // In size
151 }
152 //===== 
153 // 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)
154 //===== 
155 void VoiMPR::bbUserSetDefaultValues()
156 {
157
158 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
159 //    Here we initialize the input 'In' to 0
160         actorAddedXY            = false;
161         actorAddedXZ            = false;
162         actorAddedYZ            = false;
163         bbSetInputActive(true);
164         bbSetInputXYrender(NULL);
165         bbSetInputYZrender(NULL);
166         bbSetInputXZrender(NULL);
167
168         std::vector<double> spc;
169         spc.push_back(1);
170         spc.push_back(1);
171         spc.push_back(1);
172         bbSetInputSpacing(spc);
173 }
174 //===== 
175 // 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)
176 //===== 
177 void VoiMPR::bbUserInitializeProcessing()
178 {
179
180 //  THE INITIALIZATION METHOD BODY :
181 //    Here does nothing 
182 //    but this is where you should allocate the internal/output pointers 
183 //    if any 
184
185
186         pointsXY                = vtkPoints                     ::New();
187         linesXY                 = vtkCellArray          ::New();
188         polygonXY               = vtkPolyData           ::New();
189         polygonMapperXY = vtkPolyDataMapper     ::New();
190         polygonActorXY  = vtkActor                      ::New();
191         pointsXY                -> SetNumberOfPoints(4);
192         pointsXY                -> SetPoint(0, 0, 0, 0);
193         pointsXY                -> SetPoint(1, 0, 0, 0);
194         pointsXY                -> SetPoint(2, 0, 0, 0);
195         pointsXY                -> SetPoint(3, 0, 0, 0);
196         linesXY                 -> InsertNextCell(5);
197         linesXY                 -> InsertCellPoint(0);
198         linesXY                 -> InsertCellPoint(1);
199         linesXY                 -> InsertCellPoint(2);
200         linesXY                 -> InsertCellPoint(3);
201         linesXY                 -> InsertCellPoint(0);
202         polygonXY               -> SetPoints(pointsXY);
203         polygonXY               -> SetLines(linesXY);
204         polygonMapperXY -> SetInputData(polygonXY);
205         polygonMapperXY -> Update();
206         polygonActorXY  -> SetMapper(polygonMapperXY);
207
208
209         pointsXZ                = vtkPoints                     ::New();
210         linesXZ                 = vtkCellArray          ::New();
211         polygonXZ               = vtkPolyData           ::New();
212         polygonMapperXZ = vtkPolyDataMapper     ::New();
213         polygonActorXZ  = vtkActor                      ::New();
214         pointsXZ                -> SetNumberOfPoints(4);
215         pointsXZ                -> SetPoint(0, 0, 0, 0);
216         pointsXZ                -> SetPoint(1, 0, 0, 0);
217         pointsXZ                -> SetPoint(2, 0, 0, 0);
218         pointsXZ                -> SetPoint(3, 0, 0, 0);
219         linesXZ                 -> InsertNextCell(5);
220         linesXZ                 -> InsertCellPoint(0);
221         linesXZ                 -> InsertCellPoint(1);
222         linesXZ                 -> InsertCellPoint(2);
223         linesXZ                 -> InsertCellPoint(3);
224         linesXZ                 -> InsertCellPoint(0);
225         polygonXZ               -> SetPoints(pointsXZ);
226         polygonXZ               -> SetLines(linesXZ);
227         polygonMapperXZ -> SetInputData(polygonXZ);
228         polygonMapperXZ -> Update();
229         polygonActorXZ  -> SetMapper(polygonMapperXZ);
230
231         pointsYZ                = vtkPoints                     ::New();
232         linesYZ                 = vtkCellArray          ::New();
233         polygonYZ               = vtkPolyData           ::New();
234         polygonMapperYZ = vtkPolyDataMapper     ::New();
235         polygonActorYZ  = vtkActor                      ::New();
236         pointsYZ                ->SetNumberOfPoints(4);
237         pointsYZ                ->SetPoint(0, 0, 0, 0);
238         pointsYZ                ->SetPoint(1, 0, 0, 0);
239         pointsYZ                ->SetPoint(2, 0, 0, 0);
240         pointsYZ                ->SetPoint(3, 0, 0, 0);
241         linesYZ                 ->InsertNextCell(5);
242         linesYZ                 ->InsertCellPoint(0);
243         linesYZ                 ->InsertCellPoint(1);
244         linesYZ                 ->InsertCellPoint(2);
245         linesYZ                 ->InsertCellPoint(3);
246         linesYZ                 ->InsertCellPoint(0);
247         polygonYZ               -> SetPoints(pointsYZ);
248         polygonYZ               -> SetLines(linesYZ);
249         polygonMapperYZ -> SetInputData(polygonYZ);
250         polygonMapperYZ -> Update();
251         polygonActorYZ  -> SetMapper(polygonMapperYZ);
252 }
253 //===== 
254 // 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)
255 //===== 
256 void VoiMPR::bbUserFinalizeProcessing()
257 {
258
259 //  THE FINALIZATION METHOD BODY :
260 //    Here does nothing 
261 //    but this is where you should desallocate the internal/output pointers 
262 //    if any
263   
264 }
265 }
266 // EO namespace bbcreaVtk
267
268