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"
9 /* EED 20210-09-13 Not compiling in MacOs
13 namespace bbcreaMaracasVisu
16 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ManualPaint_Model)
17 BBTK_BLACK_BOX_IMPLEMENTATION(ManualPaint_Model,bbtk::AtomicBlackBox);
19 // 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)
22 //-- Alternativa con openmp --
23 void ManualPaint_Model::LstPointOMPAnalice()
26 printf("EED ManualPaint_Model::LstPointOMPAnalice\n" );
27 printf("EED FillFilter::Run ojo toca limpiar bien el codigo _px px ...... \n");
28 printf("EED FillFilter::Run ojo toca limpiar bien el codigo _px px ...... \n");
29 printf("EED FillFilter::Run ojo toca limpiar bien el codigo _px px ...... \n");
30 printf("EED FillFilter::Run ojo toca limpiar bien el codigo _px px ...... \n");
33 printf("EED ManualPaint_Model::LstPointOMPAnalice Start \n");
34 //-- Alternativa con openmp --
35 // A. Create copie of index original list => lst1
36 // B. if list1 es not empty do..
37 // B.1. Create copy of lst1 to lst2
38 // B.2. For each element of lst2 (incrimental) check the distance of the rest of the list (decremental) and take it out
39 // B.3. openmp sobre la La lst2 que queda (PaintImage)
40 // B.4. Quitar los elementos de lst2 en lst1 y recomenzar desde el punto B;
42 double distMin,dist2Min;
43 if (bbGetInputTool()==0)
45 distMin=bbGetInputBrushSize();
47 distMin=bbGetInputDistanceFill();
49 dist2Min=distMin*distMin*1.2;
51 // A. Create copie of index original list => lst1
52 std::vector<int> lst1;
53 int i1,size1 = bbGetInputByLstPointsX().size();
54 for (i1=0;i1<size1;i1++)
59 // B. if list1 es not empty do..
61 double dist2,dx,dy,dz;
62 while (lst1.size()!=0)
64 // B.1. Create copy of lst1 to lst2
66 std::vector<int> lst2;
67 for (i1=0;i1<size1;i1++)
69 lst2.push_back( lst1[i1] );
72 // B.2. For each element of lst2 (incrimental) check the distance of the rest of the list (decremental) and take it out
73 for (i2=0;i2<lst2.size();i2++)
76 for ( i3=size2-1 ; i3>i2 ; i3-- )
78 dx = bbGetInputByLstPointsX()[ lst2[i2] ]-bbGetInputByLstPointsX()[ lst2[i3] ];
79 dy = bbGetInputByLstPointsY()[ lst2[i2] ]-bbGetInputByLstPointsY()[ lst2[i3] ];
80 dz = bbGetInputByLstPointsZ()[ lst2[i2] ]-bbGetInputByLstPointsZ()[ lst2[i3] ];
81 dist2 = dx*dx +dy*dy + dz*dz ;
84 lst2.erase( lst2.begin()+i3 );
88 // B.3. openmp sobre la La lst2 que queda (PaintImage)
90 long int k1omp=(double)(size2-1)*0.0;
91 long int k2omp=(double)(size2-1)*0.2;
92 long int k3omp=(double)(size2-1)*0.4;
93 long int k4omp=(double)(size2-1)*0.6;
94 long int k5omp=(double)(size2-1)*0.8;
95 long int k6omp=(double)(size2-1)*1.0;
96 printf("EED ManualPaint_Model::LstPointOMPAnalice (with openmp) size=%d\n",size2);
97 #pragma omp parallel for
98 for (i2=0;i2<size2;i2++)
100 if ( (k1omp==i2) || (k2omp==i2) || (k3omp==i2) ||
101 (k4omp==i2) || (k5omp==i2) || (k6omp==i2) )
105 printf(" 100% (just one element)\n");
107 printf(" %d% \n", (int)(((double)i2/(double)(size2-1))*100 ));
110 manualpaintmodel->PaintImage( bbGetInputByLstPointsX()[ lst2[i2] ] ,
111 bbGetInputByLstPointsY()[ lst2[i2] ] ,
112 bbGetInputByLstPointsZ()[ lst2[i2] ] );
115 // B.4. Quitar los elementos de lst2 en lst1 y recomenzar desde el punto B;
116 for (i2=0;i2<size2;i2++)
119 for (i1=0;i1<size1;i1++)
121 if (lst2[i2]==lst1[i1])
123 lst1.erase( lst1.begin()+i1 );
130 printf("EED ManualPaint_Model::LstPointOMPAnalice End\n");
135 void ManualPaint_Model::Process()
138 0. Quitar comentarion ByLstPoints openmp
139 1. Falta openmp ByImagePoints
140 2. Desligar cada PaintImage de la mascara
141 -pequeno bloque de memoria para cada PaintImage
142 -el resultado volverlo a colocar en la image2 original
143 -Si no existe image2 original y hay que colocarlo en la imagen de origien
144 hay que crear una imagen2 temporal y luego bajar la imagen
145 3. Verificar el mecanismo de undo con ByLstPoints
146 4. Verificar el mecanismo de undo con ByImagePoints
148 if (bbGetInputActive()==true)
150 if (bbGetInputImage()!=NULL)
152 manualpaintmodel->SetActive( bbGetInputActive() );
153 manualpaintmodel->SetTool( bbGetInputTool() );
154 manualpaintmodel->Set2D3D( bbGetInput2D3D() );
155 manualpaintmodel->SetImages( bbGetInputImage(),bbGetInputImage2() );
156 manualpaintmodel->SetGrayLevel( bbGetInputGrayLevel() );
157 manualpaintmodel->SetDirection( bbGetInputDirection() );
158 manualpaintmodel->SetBrushSize( bbGetInputBrushSize() );
159 manualpaintmodel->SetBrushForm( bbGetInputBrushForm() );
160 manualpaintmodel->SetToleranceFill( bbGetInputToleranceFill() );
161 manualpaintmodel->SetDistanceFill( bbGetInputDistanceFill() );
162 manualpaintmodel->SetRangeMin( bbGetInputRange()[0] );
163 manualpaintmodel->SetRangeMax( bbGetInputRange()[1] );
164 if (bbGetInputPoint().size()==3)
166 manualpaintmodel->PaintImage( bbGetInputPoint()[0] , bbGetInputPoint()[1] , bbGetInputPoint()[2] );
167 manualpaintmodel->SetUndoImage();
168 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
170 if ( bbGetInputByLstPointsX().size()!=0 )
172 //-- Alternativa con openmp --
173 // LstPointOMPAnalice();
175 // /* -- Original ByLstPoints sin openmp --
176 int i,size = bbGetInputByLstPointsX().size();
177 long int k1omp=(double)(size-1)*0.0;
178 long int k2omp=(double)(size-1)*0.2;
179 long int k3omp=(double)(size-1)*0.4;
180 long int k4omp=(double)(size-1)*0.6;
181 long int k5omp=(double)(size-1)*0.8;
182 long int k6omp=(double)(size-1)*1.0;
183 printf("EED ManualPaint_Model::Process list of points (with openmp) size=%d\n",size);
184 #pragma omp parallel for
187 if ( (k1omp==i) || (k2omp==i) || (k3omp==i) ||
188 (k4omp==i) || (k5omp==i) || (k6omp==i) )
192 printf(" 100% (just one element)\n");
194 printf(" %d% \n", (int)(((double)i/(double)(size-1))*100 ));
197 manualpaintmodel->PaintImage( bbGetInputByLstPointsX()[i] ,
198 bbGetInputByLstPointsY()[i] ,
199 bbGetInputByLstPointsZ()[i] );
200 //_manualPaintModel->SetUndoImage(); // Probably needed. Here is ok.
202 // -- Original ByLstPoints sin openmp --*/
204 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
207 if ((bbGetInputByImagePoints()!=NULL) && (bbGetInputImage2()!=NULL) )
209 // -- Alternativa con openmp --
210 // Calcular numero de cuadrantes
211 // Recorrer el primer cuadrante
212 // Sacar la lista de todos los cuadrantes con el iElement Listo para analizar
213 // Recorrer la lista con openmp y ejecutar PaintImage
215 ///* -------------------- Original ByImagePoints sin openmp----------------------------
219 //EED 2017-01-01 Migration VTK7
220 #if VTK_MAJOR_VERSION <= 5
221 bbGetInputByImagePoints()->GetWholeExtent(ext);
223 bbGetInputByImagePoints()->GetExtent(ext);
225 int dimX=ext[1]-ext[0]+1;
226 int dimY=ext[3]-ext[2]+1;
227 int dimZ=ext[5]-ext[4]+1;
228 DEF_POINTER_IMAGE_VTK_CREA(vBIP,sSBIP,pBIP,sTBIP,bbGetInputByImagePoints());
229 DEF_POINTER_IMAGE_VTK_CREA(vI2,sSI2,pI2,sTI2,bbGetInputImage2());
231 long int index, size=dimX*dimY*dimZ;
233 printf("EED ManualPaint_Model::Process A.start\n");
234 std::vector<int> lstX;
235 std::vector<int> lstY;
236 std::vector<int> lstZ;
240 for (index=0; index<size; index++)
242 GETVALUE2_VTK_CREA(value1,pBIP,sTBIP,index)
245 GETVALUE2_VTK_CREA(value2,pI2,sTI2,index)
249 j = (index % (dimX*dimY)) / dimX;
250 k = index / (dimX*dimY);
257 printf("EED ManualPaint_Model::Process B.end\n");
260 long int k1omp=(double)(size-1)*0.0;
261 long int k2omp=(double)(size-1)*0.2;
262 long int k3omp=(double)(size-1)*0.4;
263 long int k4omp=(double)(size-1)*0.6;
264 long int k5omp=(double)(size-1)*0.8;
265 long int k6omp=(double)(size-1)*1.0;
266 printf("EED ManualPaint_Model::Process ByImagePoints (with openmp) size=%d GrayLevel=%f this=%p\n",size,(double)bbGetInputGrayLevel(),this);
267 //omp_set_num_threads( omp_get_max_threads()-1 );
268 #pragma omp parallel for
269 for (index=0; index<size; index++)
271 if ( (k1omp==index) || (k2omp==index) || (k3omp==index) ||
272 (k4omp==index) || (k5omp==index) || (k6omp==index) )
273 { printf(" %d%\n", (int)(((double)index/(double)(size-1))*100 )); }
276 // GETVALUE2_VTK_CREA(value1,pBIP,sTBIP,index)
280 // GETVALUE2_VTK_CREA(value2,pI2,sTI2,index)
283 // int i = index % dimX;
284 // int j = (index % (dimX*dimY)) / dimX;
285 // int k = index / (dimX*dimY);
286 manualpaintmodel->PaintImage(lstX[index],lstY[index],lstZ[index]);
287 // // manualpaintmodel->SetUndoImage(); // Probably needed. Here is ok.
290 } // for index END openmp
291 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
300 long int k1omp=(double)(size-1)*0.0;
301 long int k2omp=(double)(size-1)*0.2;
302 long int k3omp=(double)(size-1)*0.4;
303 long int k4omp=(double)(size-1)*0.6;
304 long int k5omp=(double)(size-1)*0.8;
305 long int k6omp=(double)(size-1)*1.0;
306 printf("EED ManualPaint_Model::Process ByImagePoints (with openmp) size=%d GrayLevel=%f this=%p\n",size,(double)bbGetInputGrayLevel(),this);
307 omp_set_num_threads( omp_get_max_threads()-1 );
308 #pragma omp parallel for
309 for (index=0; index<size; index++)
311 if ( (k1omp==index) || (k2omp==index) || (k3omp==index) ||
312 (k4omp==index) || (k5omp==index) || (k6omp==index) )
316 printf(" 100% (just one element)\n");
318 printf(" %d%% omp_get_num_threads=%d\n", (int)(((double)index/(double)(size-1))*100 ), omp_get_num_threads() );
322 GETVALUE2_VTK_CREA(value1,pBIP,sTBIP,index)
326 GETVALUE2_VTK_CREA(value2,pI2,sTI2,index)
329 int i = index % dimX;
330 int j = (index % (dimX*dimY)) / dimX;
331 int k = index / (dimX*dimY);
332 manualpaintmodel->PaintImage(i,j,k);
333 // manualpaintmodel->SetUndoImage(); // Probably needed. Here is ok.
336 } // for index END openmp
337 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
342 //#pragma omp parallel for
349 GETVALUE_VTK_CREA(vBIP,pBIP,sTBIP)
352 GETVALUE_VTK_CREA(vI2,pI2,sTI2)
355 manualpaintmodel->PaintImage(i,j,k);
356 // manualpaintmodel->SetUndoImage(); // Probably needed. Here is ok.
364 //------- Original ByImagePoints sin openmp-------- */
367 } // if ByImagePoints
370 printf("EED Warning!! creaMaracasVisu::ManualPaint_Model (BBTK) bbInputImage not set. \n");
371 } // if (bbGetInputImage()!=NULL)
374 if (bbGetInputImage2()!=NULL)
376 bbSetOutputOut( bbGetInputImage2() );
377 } else if (bbGetInputImage()!=NULL) {
378 bbSetOutputOut( bbGetInputImage() );
380 bbSetOutputOut( NULL );
382 bbSetOutputManualpaintmodel( manualpaintmodel );
385 // 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)
387 void ManualPaint_Model::bbUserSetDefaultValues()
390 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
391 // Here we initialize the input 'In' to 0
393 bbSetInputActive(true);
394 bbSetInputTool(1); // Paint
395 bbSetInput2D3D(1); // 3D
396 bbSetInputImage(NULL);
397 bbSetInputImage2(NULL);
398 bbSetInputGrayLevel(100);
399 bbSetInputDirection(2); // XY
400 bbSetInputBrushSize(3);
401 bbSetInputBrushForm(1); // sphere
402 bbSetInputToleranceFill(50);
403 bbSetInputDistanceFill(25);
404 std::vector<int> point;
405 // point.push_back(0);
406 // point.push_back(0);
407 // point.push_back(0);
408 // bbSetInputPoint(point);
409 std::vector<double> range;
411 range.push_back(200);
412 bbSetInputRange(range);
413 bbSetInputByImagePoints(NULL);
416 // 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)
418 void ManualPaint_Model::bbUserInitializeProcessing()
421 // THE INITIALIZATION METHOD BODY :
423 // but this is where you should allocate the internal/output pointers
425 manualpaintmodel=new ManualPaintModel();
428 // 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)
430 void ManualPaint_Model::bbUserFinalizeProcessing()
433 // THE FINALIZATION METHOD BODY :
435 // but this is where you should desallocate the internal/output pointers
437 delete manualpaintmodel;
442 // EO namespace bbcreaMaracasVisu