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)
5 #include "creaVtk_MACROS.h"
6 #include "bbcreaMaracasVisuManualPaint_Model.h"
7 #include "bbcreaMaracasVisuPackage.h"
10 namespace bbcreaMaracasVisu
13 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ManualPaint_Model)
14 BBTK_BLACK_BOX_IMPLEMENTATION(ManualPaint_Model,bbtk::AtomicBlackBox);
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)
19 //-- Alternativa con openmp --
20 void ManualPaint_Model::LstPointOMPAnalice()
23 printf("EED ManualPaint_Model::LstPointOMPAnalice\n" );
24 printf("EED FillFilter::Run ojo toca limpiar bien el codigo _px px ...... \n");
25 printf("EED FillFilter::Run ojo toca limpiar bien el codigo _px px ...... \n");
26 printf("EED FillFilter::Run ojo toca limpiar bien el codigo _px px ...... \n");
27 printf("EED FillFilter::Run ojo toca limpiar bien el codigo _px px ...... \n");
30 printf("EED ManualPaint_Model::LstPointOMPAnalice Start \n");
31 //-- Alternativa con openmp --
32 // A. Create copie of index original list => lst1
33 // B. if list1 es not empty do..
34 // B.1. Create copy of lst1 to lst2
35 // B.2. For each element of lst2 (incrimental) check the distance of the rest of the list (decremental) and take it out
36 // B.3. openmp sobre la La lst2 que queda (PaintImage)
37 // B.4. Quitar los elementos de lst2 en lst1 y recomenzar desde el punto B;
39 double distMin,dist2Min;
40 if (bbGetInputTool()==0)
42 distMin=bbGetInputBrushSize();
44 distMin=bbGetInputDistanceFill();
46 dist2Min=distMin*distMin*1.2;
48 // A. Create copie of index original list => lst1
49 std::vector<int> lst1;
50 int i1,size1 = bbGetInputByLstPointsX().size();
51 for (i1=0;i1<size1;i1++)
56 // B. if list1 es not empty do..
58 double dist2,dx,dy,dz;
59 while (lst1.size()!=0)
61 // B.1. Create copy of lst1 to lst2
63 std::vector<int> lst2;
64 for (i1=0;i1<size1;i1++)
66 lst2.push_back( lst1[i1] );
69 // B.2. For each element of lst2 (incrimental) check the distance of the rest of the list (decremental) and take it out
70 for (i2=0;i2<lst2.size();i2++)
73 for ( i3=size2-1 ; i3>i2 ; i3-- )
75 dx = bbGetInputByLstPointsX()[ lst2[i2] ]-bbGetInputByLstPointsX()[ lst2[i3] ];
76 dy = bbGetInputByLstPointsY()[ lst2[i2] ]-bbGetInputByLstPointsY()[ lst2[i3] ];
77 dz = bbGetInputByLstPointsZ()[ lst2[i2] ]-bbGetInputByLstPointsZ()[ lst2[i3] ];
78 dist2 = dx*dx +dy*dy + dz*dz ;
81 lst2.erase( lst2.begin()+i3 );
85 // B.3. openmp sobre la La lst2 que queda (PaintImage)
87 long int k1omp=(double)(size2-1)*0.0;
88 long int k2omp=(double)(size2-1)*0.2;
89 long int k3omp=(double)(size2-1)*0.4;
90 long int k4omp=(double)(size2-1)*0.6;
91 long int k5omp=(double)(size2-1)*0.8;
92 long int k6omp=(double)(size2-1)*1.0;
93 printf("EED ManualPaint_Model::LstPointOMPAnalice (with openmp) size=%d\n",size2);
94 #pragma omp parallel for
95 for (i2=0;i2<size2;i2++)
97 if ( (k1omp==i2) || (k2omp==i2) || (k3omp==i2) ||
98 (k4omp==i2) || (k5omp==i2) || (k6omp==i2) )
102 printf(" 100% (just one element)\n");
104 printf(" %d% \n", (int)(((double)i2/(double)(size2-1))*100 ));
107 manualpaintmodel->PaintImage( bbGetInputByLstPointsX()[ lst2[i2] ] ,
108 bbGetInputByLstPointsY()[ lst2[i2] ] ,
109 bbGetInputByLstPointsZ()[ lst2[i2] ] );
112 // B.4. Quitar los elementos de lst2 en lst1 y recomenzar desde el punto B;
113 for (i2=0;i2<size2;i2++)
116 for (i1=0;i1<size1;i1++)
118 if (lst2[i2]==lst1[i1])
120 lst1.erase( lst1.begin()+i1 );
127 printf("EED ManualPaint_Model::LstPointOMPAnalice End\n");
132 void ManualPaint_Model::Process()
135 0. Quitar comentarion ByLstPoints openmp
136 1. Falta openmp ByImagePoints
137 2. Desligar cada PaintImage de la mascara
138 -pequeno bloque de memoria para cada PaintImage
139 -el resultado volverlo a colocar en la image2 original
140 -Si no existe image2 original y hay que colocarlo en la imagen de origien
141 hay que crear una imagen2 temporal y luego bajar la imagen
142 3. Verificar el mecanismo de undo con ByLstPoints
143 4. Verificar el mecanismo de undo con ByImagePoints
145 if (bbGetInputActive()==true)
147 if (bbGetInputImage()!=NULL)
149 manualpaintmodel->SetActive( bbGetInputActive() );
150 manualpaintmodel->SetTool( bbGetInputTool() );
151 manualpaintmodel->Set2D3D( bbGetInput2D3D() );
152 manualpaintmodel->SetImages( bbGetInputImage(),bbGetInputImage2() );
153 manualpaintmodel->SetGrayLevel( bbGetInputGrayLevel() );
154 manualpaintmodel->SetDirection( bbGetInputDirection() );
155 manualpaintmodel->SetBrushSize( bbGetInputBrushSize() );
156 manualpaintmodel->SetBrushForm( bbGetInputBrushForm() );
157 manualpaintmodel->SetToleranceFill( bbGetInputToleranceFill() );
158 manualpaintmodel->SetDistanceFill( bbGetInputDistanceFill() );
159 manualpaintmodel->SetRangeMin( bbGetInputRange()[0] );
160 manualpaintmodel->SetRangeMax( bbGetInputRange()[1] );
161 if (bbGetInputPoint().size()==3)
163 manualpaintmodel->PaintImage( bbGetInputPoint()[0] , bbGetInputPoint()[1] , bbGetInputPoint()[2] );
164 manualpaintmodel->SetUndoImage();
165 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
167 if ( bbGetInputByLstPointsX().size()!=0 )
169 //-- Alternativa con openmp --
170 // LstPointOMPAnalice();
172 // /* -- Original ByLstPoints sin openmp --
173 int i,size = bbGetInputByLstPointsX().size();
174 long int k1omp=(double)(size-1)*0.0;
175 long int k2omp=(double)(size-1)*0.2;
176 long int k3omp=(double)(size-1)*0.4;
177 long int k4omp=(double)(size-1)*0.6;
178 long int k5omp=(double)(size-1)*0.8;
179 long int k6omp=(double)(size-1)*1.0;
180 printf("EED ManualPaint_Model::Process list of points (with openmp) size=%d\n",size);
181 #pragma omp parallel for
184 if ( (k1omp==i) || (k2omp==i) || (k3omp==i) ||
185 (k4omp==i) || (k5omp==i) || (k6omp==i) )
189 printf(" 100% (just one element)\n");
191 printf(" %d% \n", (int)(((double)i/(double)(size-1))*100 ));
194 manualpaintmodel->PaintImage( bbGetInputByLstPointsX()[i] ,
195 bbGetInputByLstPointsY()[i] ,
196 bbGetInputByLstPointsZ()[i] );
197 //_manualPaintModel->SetUndoImage(); // Probably needed. Here is ok.
199 // -- Original ByLstPoints sin openmp --*/
201 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
204 if ((bbGetInputByImagePoints()!=NULL) && (bbGetInputImage2()!=NULL) )
206 // -- Alternativa con openmp --
207 // Calcular numero de cuadrantes
208 // Recorrer el primer cuadrante
209 // Sacar la lista de todos los cuadrantes con el iElement Listo para analizar
210 // Recorrer la lista con openmp y ejecutar PaintImage
212 ///* -------------------- Original ByImagePoints sin openmp----------------------------
216 //EED 2017-01-01 Migration VTK7
217 #if VTK_MAJOR_VERSION <= 5
218 bbGetInputByImagePoints()->GetWholeExtent(ext);
220 bbGetInputByImagePoints()->GetExtent(ext);
222 int dimX=ext[1]-ext[0]+1;
223 int dimY=ext[3]-ext[2]+1;
224 int dimZ=ext[5]-ext[4]+1;
225 DEF_POINTER_IMAGE_VTK_CREA(vBIP,sSBIP,pBIP,sTBIP,bbGetInputByImagePoints());
226 DEF_POINTER_IMAGE_VTK_CREA(vI2,sSI2,pI2,sTI2,bbGetInputImage2());
228 long int index, size=dimX*dimY*dimZ;
230 long int k1omp=(double)(size-1)*0.0;
231 long int k2omp=(double)(size-1)*0.2;
232 long int k3omp=(double)(size-1)*0.4;
233 long int k4omp=(double)(size-1)*0.6;
234 long int k5omp=(double)(size-1)*0.8;
235 long int k6omp=(double)(size-1)*1.0;
236 printf("EED ManualPaint_Model::Process ByImagePoints (with openmp) size=%d GrayLevel=%f\n",size,(double)bbGetInputGrayLevel());
237 #pragma omp parallel for
238 for (index=0; index<size; index++)
240 if ( (k1omp==index) || (k2omp==index) || (k3omp==index) ||
241 (k4omp==index) || (k5omp==index) || (k6omp==index) )
245 printf(" 100% (just one element)\n");
247 printf(" %d% \n", (int)(((double)index/(double)(size-1))*100 ));
251 GETVALUE2_VTK_CREA(value1,pBIP,sTBIP,index)
255 GETVALUE2_VTK_CREA(value2,pI2,sTI2,index)
258 int i = index % dimX;
259 int j = (index % (dimX*dimY)) / dimX;
260 int k = index / (dimX*dimY);
261 manualpaintmodel->PaintImage(i,j,k);
262 // manualpaintmodel->SetUndoImage(); // Probably needed. Here is ok.
266 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
270 //#pragma omp parallel for
277 GETVALUE_VTK_CREA(vBIP,pBIP,sTBIP)
280 GETVALUE_VTK_CREA(vI2,pI2,sTI2)
283 manualpaintmodel->PaintImage(i,j,k);
284 // manualpaintmodel->SetUndoImage(); // Probably needed. Here is ok.
292 //------- Original ByImagePoints sin openmp-------- */
295 } // if ByImagePoints
298 printf("EED Warning!! creaMaracasVisu::ManualPaint_Model (BBTK) bbInputImage not set. \n");
299 } // if (bbGetInputImage()!=NULL)
302 if (bbGetInputImage2()!=NULL)
304 bbSetOutputOut( bbGetInputImage2() );
305 } else if (bbGetInputImage()!=NULL) {
306 bbSetOutputOut( bbGetInputImage() );
308 bbSetOutputOut( NULL );
310 bbSetOutputManualpaintmodel( manualpaintmodel );
312 printf("EED ManualPaint_Model::Process End\n");
315 // 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)
317 void ManualPaint_Model::bbUserSetDefaultValues()
320 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
321 // Here we initialize the input 'In' to 0
323 bbSetInputActive(true);
324 bbSetInputTool(1); // Paint
325 bbSetInput2D3D(1); // 3D
326 bbSetInputImage(NULL);
327 bbSetInputImage2(NULL);
328 bbSetInputGrayLevel(100);
329 bbSetInputDirection(2); // XY
330 bbSetInputBrushSize(3);
331 bbSetInputBrushForm(1); // sphere
332 bbSetInputToleranceFill(50);
333 bbSetInputDistanceFill(25);
334 std::vector<int> point;
335 // point.push_back(0);
336 // point.push_back(0);
337 // point.push_back(0);
338 // bbSetInputPoint(point);
339 std::vector<double> range;
341 range.push_back(200);
342 bbSetInputRange(range);
343 bbSetInputByImagePoints(NULL);
346 // 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)
348 void ManualPaint_Model::bbUserInitializeProcessing()
351 // THE INITIALIZATION METHOD BODY :
353 // but this is where you should allocate the internal/output pointers
355 manualpaintmodel=new ManualPaintModel();
358 // 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)
360 void ManualPaint_Model::bbUserFinalizeProcessing()
363 // THE FINALIZATION METHOD BODY :
365 // but this is where you should desallocate the internal/output pointers
367 delete manualpaintmodel;
372 // EO namespace bbcreaMaracasVisu