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()
134 printf("EED ManualPaint_Model::Process Start\n");
136 0. Quitar comentarion ByLstPoints openmp
137 1. Falta openmp ByImagePoints
138 2. Desligar cada PaintImage de la mascara
139 -pequeno bloque de memoria para cada PaintImage
140 -el resultado volverlo a colocar en la image2 original
141 -Si no existe image2 original y hay que colocarlo en la imagen de origien
142 hay que crear una imagen2 temporal y luego bajar la imagen
143 3. Verificar el mecanismo de undo con ByLstPoints
144 4. Verificar el mecanismo de undo con ByImagePoints
146 if (bbGetInputActive()==true)
148 printf("EED ManualPaint_Model::Process 1\n");
149 if (bbGetInputImage()!=NULL)
151 printf("EED ManualPaint_Model::Process 2\n");
152 manualpaintmodel->SetActive( bbGetInputActive() );
153 manualpaintmodel->SetTool( bbGetInputTool() );
154 manualpaintmodel->Set2D3D( bbGetInput2D3D() );
155 printf("EED ManualPaint_Model::Process 2.1\n");
156 manualpaintmodel->SetImages( bbGetInputImage(),bbGetInputImage2() );
157 printf("EED ManualPaint_Model::Process 2.2\n");
158 manualpaintmodel->SetGrayLevel( bbGetInputGrayLevel() );
159 manualpaintmodel->SetDirection( bbGetInputDirection() );
160 manualpaintmodel->SetBrushSize( bbGetInputBrushSize() );
161 manualpaintmodel->SetBrushForm( bbGetInputBrushForm() );
162 manualpaintmodel->SetToleranceFill( bbGetInputToleranceFill() );
163 manualpaintmodel->SetDistanceFill( bbGetInputDistanceFill() );
164 manualpaintmodel->SetRangeMin( bbGetInputRange()[0] );
165 manualpaintmodel->SetRangeMax( bbGetInputRange()[1] );
166 if (bbGetInputPoint().size()==3)
168 printf("EED ManualPaint_Model::Process 3\n");
169 manualpaintmodel->PaintImage( bbGetInputPoint()[0] , bbGetInputPoint()[1] , bbGetInputPoint()[2] );
170 manualpaintmodel->SetUndoImage();
172 if ( bbGetInputByLstPointsX().size()!=0 )
174 printf("EED ManualPaint_Model::Process 4\n");
175 //-- Alternativa con openmp --
176 // LstPointOMPAnalice();
178 // /* -- Original ByLstPoints sin openmp --
179 int i,size = bbGetInputByLstPointsX().size();
180 long int k1omp=(double)(size-1)*0.0;
181 long int k2omp=(double)(size-1)*0.2;
182 long int k3omp=(double)(size-1)*0.4;
183 long int k4omp=(double)(size-1)*0.6;
184 long int k5omp=(double)(size-1)*0.8;
185 long int k6omp=(double)(size-1)*1.0;
186 printf("EED ManualPaint_Model::Process list of points (with openmp) size=%d\n",size);
187 #pragma omp parallel for
190 if ( (k1omp==i) || (k2omp==i) || (k3omp==i) ||
191 (k4omp==i) || (k5omp==i) || (k6omp==i) )
195 printf(" 100% (just one element)\n");
197 printf(" %d% \n", (int)(((double)i/(double)(size-1))*100 ));
200 manualpaintmodel->PaintImage( bbGetInputByLstPointsX()[i] ,
201 bbGetInputByLstPointsY()[i] ,
202 bbGetInputByLstPointsZ()[i] );
203 //_manualPaintModel->SetUndoImage(); // Probably needed. Here is ok.
205 // -- Original ByLstPoints sin openmp --*/
207 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
210 if ((bbGetInputByImagePoints()!=NULL) && (bbGetInputImage2()!=NULL) )
212 // -- Alternativa con openmp --
213 // Calcular numero de cuadrantes
214 // Recorrer el primer cuadrante
215 // Sacar la lista de todos los cuadrantes con el iElement Listo para analizar
216 // Recorrer la lista con openmp y ejecutar PaintImage
218 ///* -------------------- Original ByImagePoints sin openmp----------------------------
222 //EED 2017-01-01 Migration VTK7
223 #if VTK_MAJOR_VERSION <= 5
224 bbGetInputByImagePoints()->GetWholeExtent(ext);
226 bbGetInputByImagePoints()->GetExtent(ext);
228 int dimX=ext[1]-ext[0]+1;
229 int dimY=ext[3]-ext[2]+1;
230 int dimZ=ext[5]-ext[4]+1;
231 DEF_POINTER_IMAGE_VTK_CREA(vBIP,sSBIP,pBIP,sTBIP,bbGetInputByImagePoints());
232 DEF_POINTER_IMAGE_VTK_CREA(vI2,sSI2,pI2,sTI2,bbGetInputImage2());
234 long int index, size=dimX*dimY*dimZ;
236 long int k1omp=(double)(size-1)*0.0;
237 long int k2omp=(double)(size-1)*0.2;
238 long int k3omp=(double)(size-1)*0.4;
239 long int k4omp=(double)(size-1)*0.6;
240 long int k5omp=(double)(size-1)*0.8;
241 long int k6omp=(double)(size-1)*1.0;
242 printf("EED ManualPaint_Model::Process ByImagePoints (with openmp) size=%d\n",size);
243 #pragma omp parallel for
244 for (index=0; index<size; index++)
246 if ( (k1omp==index) || (k2omp==index) || (k3omp==index) ||
247 (k4omp==index) || (k5omp==index) || (k6omp==index) )
251 printf(" 100% (just one element)\n");
253 printf(" %d% \n", (int)(((double)index/(double)(size-1))*100 ));
257 GETVALUE2_VTK_CREA(value1,pBIP,sTBIP,index)
261 GETVALUE2_VTK_CREA(value2,pI2,sTI2,index)
264 int i = index % dimX;
265 int j = (index % (dimX*dimY)) / dimX;
266 int k = index / (dimX*dimY);
267 manualpaintmodel->PaintImage(i,j,k);
268 // manualpaintmodel->SetUndoImage(); // Probably needed. Here is ok.
272 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
276 //#pragma omp parallel for
283 GETVALUE_VTK_CREA(vBIP,pBIP,sTBIP)
286 GETVALUE_VTK_CREA(vI2,pI2,sTI2)
289 manualpaintmodel->PaintImage(i,j,k);
290 // manualpaintmodel->SetUndoImage(); // Probably needed. Here is ok.
298 //------- Original ByImagePoints sin openmp-------- */
301 } // if ByImagePoints
304 printf("EED Warning!! creaMaracasVisu::ManualPaint_Model (BBTK) bbInputImage not set. \n");
305 } // if (bbGetInputImage()!=NULL)
308 if (bbGetInputImage2()!=NULL)
310 bbSetOutputOut( bbGetInputImage2() );
311 } else if (bbGetInputImage()!=NULL) {
312 bbSetOutputOut( bbGetInputImage() );
314 bbSetOutputOut( NULL );
316 bbSetOutputManualpaintmodel( manualpaintmodel );
318 printf("EED ManualPaint_Model::Process End\n");
321 // 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)
323 void ManualPaint_Model::bbUserSetDefaultValues()
326 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
327 // Here we initialize the input 'In' to 0
329 bbSetInputActive(true);
330 bbSetInputTool(1); // Paint
331 bbSetInput2D3D(1); // 3D
332 bbSetInputImage(NULL);
333 bbSetInputImage2(NULL);
334 bbSetInputGrayLevel(100);
335 bbSetInputDirection(2); // XY
336 bbSetInputBrushSize(3);
337 bbSetInputBrushForm(1); // sphere
338 bbSetInputToleranceFill(50);
339 bbSetInputDistanceFill(25);
340 std::vector<int> point;
341 // point.push_back(0);
342 // point.push_back(0);
343 // point.push_back(0);
344 // bbSetInputPoint(point);
345 std::vector<double> range;
347 range.push_back(200);
348 bbSetInputRange(range);
349 bbSetInputByImagePoints(NULL);
352 // 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)
354 void ManualPaint_Model::bbUserInitializeProcessing()
357 // THE INITIALIZATION METHOD BODY :
359 // but this is where you should allocate the internal/output pointers
361 manualpaintmodel=new ManualPaintModel();
364 // 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)
366 void ManualPaint_Model::bbUserFinalizeProcessing()
369 // THE FINALIZATION METHOD BODY :
371 // but this is where you should desallocate the internal/output pointers
373 delete manualpaintmodel;
378 // EO namespace bbcreaMaracasVisu