]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbcreaMaracasVisuManualPaint_Model.cxx
#3340 creaMaracasVisu Bug New Normal - ManualPaint_model Active option
[creaMaracasVisu.git] / bbtk / src / bbcreaMaracasVisuManualPaint_Model.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 "creaVtk_MACROS.h"
6 #include "bbcreaMaracasVisuManualPaint_Model.h"
7 #include "bbcreaMaracasVisuPackage.h"
8
9
10 namespace bbcreaMaracasVisu
11 {
12
13 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ManualPaint_Model)
14 BBTK_BLACK_BOX_IMPLEMENTATION(ManualPaint_Model,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
19
20 void ManualPaint_Model::Process()
21 {
22
23 // THE MAIN PROCESSING METHOD BODY
24 //   Here we simply set the input 'In' value to the output 'Out'
25 //   And print out the output value
26 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
27 //    void bbSet{Input|Output}NAME(const TYPE&)
28 //    const TYPE& bbGet{Input|Output}NAME() const 
29 //    Where :
30 //    * NAME is the name of the input/output
31 //      (the one provided in the attribute 'name' of the tag 'input')
32 //    * TYPE is the C++ type of the input/output
33 //      (the one provided in the attribute 'type' of the tag 'input')
34 //    bbSetOutputOut( bbGetInputIn() );
35 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
36
37         if (bbGetInputActive()==true)
38         {
39                 if (bbGetInputImage()!=NULL)
40                 {  
41                         manualpaintmodel->SetActive( bbGetInputActive() );
42                         manualpaintmodel->SetTool( bbGetInputTool() );
43                         manualpaintmodel->Set2D3D( bbGetInput2D3D() );
44                         manualpaintmodel->SetImages( bbGetInputImage(),bbGetInputImage2() );
45                         manualpaintmodel->SetGrayLevel( bbGetInputGrayLevel() );
46                         manualpaintmodel->SetDirection( bbGetInputDirection() );
47                         manualpaintmodel->SetBrushSize( bbGetInputBrushSize() );
48                         manualpaintmodel->SetBrushForm( bbGetInputBrushForm() );
49                         manualpaintmodel->SetToleranceFill( bbGetInputToleranceFill() );
50                         manualpaintmodel->SetDistanceFill( bbGetInputDistanceFill() );          
51                         manualpaintmodel->SetRangeMin( bbGetInputRange()[0] );
52                         manualpaintmodel->SetRangeMax( bbGetInputRange()[1] );
53                         if (bbGetInputPoint().size()==3)
54                         {
55                                 manualpaintmodel->PaintImage( bbGetInputPoint()[0] , bbGetInputPoint()[1] , bbGetInputPoint()[2] );
56                                 manualpaintmodel->SetUndoImage();
57                         } // if Points
58                         if ( bbGetInputByLstPointsX().size()!=0 )
59                         {
60                                 int i,size = bbGetInputByLstPointsX().size();
61                                 for (i=0;i<size;i++)
62                                 {
63                                         manualpaintmodel->PaintImage( bbGetInputByLstPointsX()[i] , bbGetInputByLstPointsY()[i] , bbGetInputByLstPointsZ()[i] );
64         //                      _manualPaintModel->SetUndoImage();     // Probably needed.   Here is ok.
65                                 } // for
66                         }// if ByLstPointsX
67                         if ((bbGetInputByImagePoints()!=NULL) && (bbGetInputImage2()!=NULL) )
68                         {
69         //                      int ia,ja,ka;
70         //                      int ii,jj,kk;
71                                 int ext[6];
72         //EED 2017-01-01 Migration VTK7
73         #if VTK_MAJOR_VERSION <= 5
74                                 bbGetInputByImagePoints()->GetWholeExtent(ext);
75         #else
76                                 bbGetInputByImagePoints()->GetExtent(ext);
77         #endif
78                                 int dimX=ext[1]-ext[0]+1;
79                                 int dimY=ext[3]-ext[2]+1;
80                                 int dimZ=ext[5]-ext[4]+1;
81                                 DEF_POINTER_IMAGE_VTK_CREA(vBIP,sSBIP,pBIP,sTBIP,bbGetInputByImagePoints());
82                                 DEF_POINTER_IMAGE_VTK_CREA(vI2,sSI2,pI2,sTI2,bbGetInputImage2());
83         //#pragma omp parallel for
84                                 int i,j,k;
85                                 for (k=0;k<dimZ;k++) 
86                                 {
87                                         if (k%50==0)
88                                         {
89                                                 printf("ManualPaint_Model %d%\n", (int)(k*100.0/dimZ) );
90                                         }
91                                         for (j=0;j<dimY;j++) 
92                                         {
93                                                 for (i=0;i<dimX;i++) 
94                                                 {
95                                                         GETVALUE_VTK_CREA(vBIP,pBIP,sTBIP)
96                                                         if (vBIP>0)
97                                                         {
98                                                                 GETVALUE_VTK_CREA(vI2,pI2,sTI2)
99                                                                 if (vI2==0)
100                                                                 {
101                                                                         manualpaintmodel->PaintImage(i,j,k);
102         //                                                              manualpaintmodel->SetUndoImage();     // Probably needed.   Here is ok.
103                                                                 } // vI2                
104                                                         } // vBIP 
105                                                         pBIP = pBIP + sSBIP;                            
106                                                         pI2  = pI2  + sSI2;                             
107                                                 }// for i
108                                         }// for j
109                                 }// for k
110                                 printf("ManualPaint_Model %d%\n", 100 );
111                         } // if ByImagePoints
112                  } else {
113                         printf("EED Warning: ByImagePoints or Image2 not set.  Box creaMaracasVisu::ManualPaint_Model (BBTK) \n");
114                 } // if ((bbGetInputByImagePoints()!=NULL) && (bbGetInputImage2()!=NULL) )
115         } // if active
116
117         if (bbGetInputImage2()!=NULL)
118         { 
119                 bbSetOutputOut( bbGetInputImage2() );
120         } else if (bbGetInputImage()!=NULL) { 
121                 bbSetOutputOut( bbGetInputImage() );
122         } else { 
123                 bbSetOutputOut( NULL );
124         } 
125         bbSetOutputManualpaintmodel( manualpaintmodel );
126 }
127 //===== 
128 // 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)
129 //===== 
130 void ManualPaint_Model::bbUserSetDefaultValues()
131 {
132
133 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
134 //    Here we initialize the input 'In' to 0
135
136         bbSetInputActive(true);
137         bbSetInputTool(1);              // Paint
138         bbSetInput2D3D(1);              // 3D
139         bbSetInputImage(NULL);
140         bbSetInputImage2(NULL);
141         bbSetInputGrayLevel(100);
142         bbSetInputDirection(2);         // XY
143         bbSetInputBrushSize(3);
144         bbSetInputBrushForm(1);         // sphere
145         bbSetInputToleranceFill(50);
146         bbSetInputDistanceFill(25);
147         std::vector<int> point;
148         point.push_back(0);
149         point.push_back(0);
150         point.push_back(0);
151         bbSetInputPoint(point);
152         std::vector<double> range;
153         range.push_back(0);
154         range.push_back(200);
155         bbSetInputRange(range);
156         bbSetInputByImagePoints(NULL);
157 }
158 //===== 
159 // 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)
160 //===== 
161 void ManualPaint_Model::bbUserInitializeProcessing()
162 {
163
164 //  THE INITIALIZATION METHOD BODY :
165 //    Here does nothing 
166 //    but this is where you should allocate the internal/output pointers 
167 //    if any 
168         manualpaintmodel=new ManualPaintModel();  
169 }
170 //===== 
171 // 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)
172 //===== 
173 void ManualPaint_Model::bbUserFinalizeProcessing()
174 {
175
176 //  THE FINALIZATION METHOD BODY :
177 //    Here does nothing 
178 //    but this is where you should desallocate the internal/output pointers 
179 //    if any
180         delete manualpaintmodel;
181   
182 }
183
184 }
185 // EO namespace bbcreaMaracasVisu
186
187