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"
12 namespace bbcreaMaracasVisu
15 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ManualPaint_Model)
16 BBTK_BLACK_BOX_IMPLEMENTATION(ManualPaint_Model,bbtk::AtomicBlackBox);
18 // 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)
21 //-- Alternativa con openmp --
22 void ManualPaint_Model::LstPointOMPAnalice()
25 printf("EED ManualPaint_Model::LstPointOMPAnalice\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");
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");
32 printf("EED ManualPaint_Model::LstPointOMPAnalice Start \n");
33 //-- Alternativa con openmp --
34 // A. Create copie of index original list => lst1
35 // B. if list1 es not empty do..
36 // B.1. Create copy of lst1 to lst2
37 // B.2. For each element of lst2 (incrimental) check the distance of the rest of the list (decremental) and take it out
38 // B.3. openmp sobre la La lst2 que queda (PaintImage)
39 // B.4. Quitar los elementos de lst2 en lst1 y recomenzar desde el punto B;
41 double distMin,dist2Min;
42 if (bbGetInputTool()==0)
44 distMin=bbGetInputBrushSize();
46 distMin=bbGetInputDistanceFill();
48 dist2Min=distMin*distMin*1.2;
50 // A. Create copie of index original list => lst1
51 std::vector<int> lst1;
52 int i1,size1 = bbGetInputByLstPointsX().size();
53 for (i1=0;i1<size1;i1++)
58 // B. if list1 es not empty do..
60 double dist2,dx,dy,dz;
61 while (lst1.size()!=0)
63 // B.1. Create copy of lst1 to lst2
65 std::vector<int> lst2;
66 for (i1=0;i1<size1;i1++)
68 lst2.push_back( lst1[i1] );
71 // B.2. For each element of lst2 (incrimental) check the distance of the rest of the list (decremental) and take it out
72 for (i2=0;i2<lst2.size();i2++)
75 for ( i3=size2-1 ; i3>i2 ; i3-- )
77 dx = bbGetInputByLstPointsX()[ lst2[i2] ]-bbGetInputByLstPointsX()[ lst2[i3] ];
78 dy = bbGetInputByLstPointsY()[ lst2[i2] ]-bbGetInputByLstPointsY()[ lst2[i3] ];
79 dz = bbGetInputByLstPointsZ()[ lst2[i2] ]-bbGetInputByLstPointsZ()[ lst2[i3] ];
80 dist2 = dx*dx +dy*dy + dz*dz ;
83 lst2.erase( lst2.begin()+i3 );
87 // B.3. openmp sobre la La lst2 que queda (PaintImage)
89 long int k1omp=(double)(size2-1)*0.0;
90 long int k2omp=(double)(size2-1)*0.2;
91 long int k3omp=(double)(size2-1)*0.4;
92 long int k4omp=(double)(size2-1)*0.6;
93 long int k5omp=(double)(size2-1)*0.8;
94 long int k6omp=(double)(size2-1)*1.0;
95 printf("EED ManualPaint_Model::LstPointOMPAnalice (with openmp) size=%d\n",size2);
96 #pragma omp parallel for
97 for (i2=0;i2<size2;i2++)
99 if ( (k1omp==i2) || (k2omp==i2) || (k3omp==i2) ||
100 (k4omp==i2) || (k5omp==i2) || (k6omp==i2) )
104 printf(" 100% (just one element)\n");
106 printf(" %d% \n", (int)(((double)i2/(double)(size2-1))*100 ));
109 manualpaintmodel->PaintImage( bbGetInputByLstPointsX()[ lst2[i2] ] ,
110 bbGetInputByLstPointsY()[ lst2[i2] ] ,
111 bbGetInputByLstPointsZ()[ lst2[i2] ] );
114 // B.4. Quitar los elementos de lst2 en lst1 y recomenzar desde el punto B;
115 for (i2=0;i2<size2;i2++)
118 for (i1=0;i1<size1;i1++)
120 if (lst2[i2]==lst1[i1])
122 lst1.erase( lst1.begin()+i1 );
129 printf("EED ManualPaint_Model::LstPointOMPAnalice End\n");
134 void ManualPaint_Model::Process()
137 0. Quitar comentarion ByLstPoints openmp
138 1. Falta openmp ByImagePoints
139 2. Desligar cada PaintImage de la mascara
140 -pequeno bloque de memoria para cada PaintImage
141 -el resultado volverlo a colocar en la image2 original
142 -Si no existe image2 original y hay que colocarlo en la imagen de origien
143 hay que crear una imagen2 temporal y luego bajar la imagen
144 3. Verificar el mecanismo de undo con ByLstPoints
145 4. Verificar el mecanismo de undo con ByImagePoints
147 if (bbGetInputActive()==true)
149 if (bbGetInputImage()!=NULL)
151 manualpaintmodel->SetActive( bbGetInputActive() );
152 manualpaintmodel->SetTool( bbGetInputTool() );
153 manualpaintmodel->Set2D3D( bbGetInput2D3D() );
154 manualpaintmodel->SetImages( bbGetInputImage(),bbGetInputImage2() );
155 manualpaintmodel->SetGrayLevel( bbGetInputGrayLevel() );
156 manualpaintmodel->SetDirection( bbGetInputDirection() );
157 manualpaintmodel->SetBrushSize( bbGetInputBrushSize() );
158 manualpaintmodel->SetBrushForm( bbGetInputBrushForm() );
159 manualpaintmodel->SetToleranceFill( bbGetInputToleranceFill() );
160 manualpaintmodel->SetDistanceFill( bbGetInputDistanceFill() );
161 manualpaintmodel->SetRangeMin( bbGetInputRange()[0] );
162 manualpaintmodel->SetRangeMax( bbGetInputRange()[1] );
163 if (bbGetInputPoint().size()==3)
165 manualpaintmodel->PaintImage( bbGetInputPoint()[0] , bbGetInputPoint()[1] , bbGetInputPoint()[2] );
166 manualpaintmodel->SetUndoImage();
167 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
169 if ( bbGetInputByLstPointsX().size()!=0 )
171 //-- Alternativa con openmp --
172 // LstPointOMPAnalice();
174 // /* -- Original ByLstPoints sin openmp --
175 int i,size = bbGetInputByLstPointsX().size();
176 long int k1omp=(double)(size-1)*0.0;
177 long int k2omp=(double)(size-1)*0.2;
178 long int k3omp=(double)(size-1)*0.4;
179 long int k4omp=(double)(size-1)*0.6;
180 long int k5omp=(double)(size-1)*0.8;
181 long int k6omp=(double)(size-1)*1.0;
182 printf("EED ManualPaint_Model::Process list of points (with openmp) size=%d\n",size);
183 #pragma omp parallel for
186 if ( (k1omp==i) || (k2omp==i) || (k3omp==i) ||
187 (k4omp==i) || (k5omp==i) || (k6omp==i) )
191 printf(" 100% (just one element)\n");
193 printf(" %d% \n", (int)(((double)i/(double)(size-1))*100 ));
196 manualpaintmodel->PaintImage( bbGetInputByLstPointsX()[i] ,
197 bbGetInputByLstPointsY()[i] ,
198 bbGetInputByLstPointsZ()[i] );
199 //_manualPaintModel->SetUndoImage(); // Probably needed. Here is ok.
201 // -- Original ByLstPoints sin openmp --*/
203 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
206 if ((bbGetInputByImagePoints()!=NULL) && (bbGetInputImage2()!=NULL) )
208 // -- Alternativa con openmp --
209 // Calcular numero de cuadrantes
210 // Recorrer el primer cuadrante
211 // Sacar la lista de todos los cuadrantes con el iElement Listo para analizar
212 // Recorrer la lista con openmp y ejecutar PaintImage
214 ///* -------------------- Original ByImagePoints sin openmp----------------------------
218 //EED 2017-01-01 Migration VTK7
219 #if VTK_MAJOR_VERSION <= 5
220 bbGetInputByImagePoints()->GetWholeExtent(ext);
222 bbGetInputByImagePoints()->GetExtent(ext);
224 int dimX=ext[1]-ext[0]+1;
225 int dimY=ext[3]-ext[2]+1;
226 int dimZ=ext[5]-ext[4]+1;
227 DEF_POINTER_IMAGE_VTK_CREA(vBIP,sSBIP,pBIP,sTBIP,bbGetInputByImagePoints());
228 DEF_POINTER_IMAGE_VTK_CREA(vI2,sSI2,pI2,sTI2,bbGetInputImage2());
230 long int index, size=dimX*dimY*dimZ;
232 printf("EED ManualPaint_Model::Process A.start\n");
233 std::vector<int> lstX;
234 std::vector<int> lstY;
235 std::vector<int> lstZ;
239 for (index=0; index<size; index++)
241 GETVALUE2_VTK_CREA(value1,pBIP,sTBIP,index)
244 GETVALUE2_VTK_CREA(value2,pI2,sTI2,index)
248 j = (index % (dimX*dimY)) / dimX;
249 k = index / (dimX*dimY);
256 printf("EED ManualPaint_Model::Process B.end\n");
259 long int k1omp=(double)(size-1)*0.0;
260 long int k2omp=(double)(size-1)*0.2;
261 long int k3omp=(double)(size-1)*0.4;
262 long int k4omp=(double)(size-1)*0.6;
263 long int k5omp=(double)(size-1)*0.8;
264 long int k6omp=(double)(size-1)*1.0;
265 printf("EED ManualPaint_Model::Process ByImagePoints (with openmp) size=%d GrayLevel=%f this=%p\n",size,(double)bbGetInputGrayLevel(),this);
266 //omp_set_num_threads( omp_get_max_threads()-1 );
267 #pragma omp parallel for
268 for (index=0; index<size; index++)
270 if ( (k1omp==index) || (k2omp==index) || (k3omp==index) ||
271 (k4omp==index) || (k5omp==index) || (k6omp==index) )
275 printf(" 100% (just one element)\n");
277 printf(" %d%% omp_get_num_threads=%d\n", (int)(((double)index/(double)(size-1))*100 ), omp_get_num_threads() );
281 // GETVALUE2_VTK_CREA(value1,pBIP,sTBIP,index)
285 // GETVALUE2_VTK_CREA(value2,pI2,sTI2,index)
288 // int i = index % dimX;
289 // int j = (index % (dimX*dimY)) / dimX;
290 // int k = index / (dimX*dimY);
291 manualpaintmodel->PaintImage(lstX[index],lstY[index],lstZ[index]);
292 // // manualpaintmodel->SetUndoImage(); // Probably needed. Here is ok.
295 } // for index END openmp
296 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
305 long int k1omp=(double)(size-1)*0.0;
306 long int k2omp=(double)(size-1)*0.2;
307 long int k3omp=(double)(size-1)*0.4;
308 long int k4omp=(double)(size-1)*0.6;
309 long int k5omp=(double)(size-1)*0.8;
310 long int k6omp=(double)(size-1)*1.0;
311 printf("EED ManualPaint_Model::Process ByImagePoints (with openmp) size=%d GrayLevel=%f this=%p\n",size,(double)bbGetInputGrayLevel(),this);
312 omp_set_num_threads( omp_get_max_threads()-1 );
313 #pragma omp parallel for
314 for (index=0; index<size; index++)
316 if ( (k1omp==index) || (k2omp==index) || (k3omp==index) ||
317 (k4omp==index) || (k5omp==index) || (k6omp==index) )
321 printf(" 100% (just one element)\n");
323 printf(" %d%% omp_get_num_threads=%d\n", (int)(((double)index/(double)(size-1))*100 ), omp_get_num_threads() );
327 GETVALUE2_VTK_CREA(value1,pBIP,sTBIP,index)
331 GETVALUE2_VTK_CREA(value2,pI2,sTI2,index)
334 int i = index % dimX;
335 int j = (index % (dimX*dimY)) / dimX;
336 int k = index / (dimX*dimY);
337 manualpaintmodel->PaintImage(i,j,k);
338 // manualpaintmodel->SetUndoImage(); // Probably needed. Here is ok.
341 } // for index END openmp
342 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
347 //#pragma omp parallel for
354 GETVALUE_VTK_CREA(vBIP,pBIP,sTBIP)
357 GETVALUE_VTK_CREA(vI2,pI2,sTI2)
360 manualpaintmodel->PaintImage(i,j,k);
361 // manualpaintmodel->SetUndoImage(); // Probably needed. Here is ok.
369 //------- Original ByImagePoints sin openmp-------- */
372 } // if ByImagePoints
375 printf("EED Warning!! creaMaracasVisu::ManualPaint_Model (BBTK) bbInputImage not set. \n");
376 } // if (bbGetInputImage()!=NULL)
379 if (bbGetInputImage2()!=NULL)
381 bbSetOutputOut( bbGetInputImage2() );
382 } else if (bbGetInputImage()!=NULL) {
383 bbSetOutputOut( bbGetInputImage() );
385 bbSetOutputOut( NULL );
387 bbSetOutputManualpaintmodel( manualpaintmodel );
390 // 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)
392 void ManualPaint_Model::bbUserSetDefaultValues()
395 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
396 // Here we initialize the input 'In' to 0
398 bbSetInputActive(true);
399 bbSetInputTool(1); // Paint
400 bbSetInput2D3D(1); // 3D
401 bbSetInputImage(NULL);
402 bbSetInputImage2(NULL);
403 bbSetInputGrayLevel(100);
404 bbSetInputDirection(2); // XY
405 bbSetInputBrushSize(3);
406 bbSetInputBrushForm(1); // sphere
407 bbSetInputToleranceFill(50);
408 bbSetInputDistanceFill(25);
409 std::vector<int> point;
410 // point.push_back(0);
411 // point.push_back(0);
412 // point.push_back(0);
413 // bbSetInputPoint(point);
414 std::vector<double> range;
416 range.push_back(200);
417 bbSetInputRange(range);
418 bbSetInputByImagePoints(NULL);
421 // 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)
423 void ManualPaint_Model::bbUserInitializeProcessing()
426 // THE INITIALIZATION METHOD BODY :
428 // but this is where you should allocate the internal/output pointers
430 manualpaintmodel=new ManualPaintModel();
433 // 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)
435 void ManualPaint_Model::bbUserFinalizeProcessing()
438 // THE FINALIZATION METHOD BODY :
440 // but this is where you should desallocate the internal/output pointers
442 delete manualpaintmodel;
447 // EO namespace bbcreaMaracasVisu