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