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()
22 //-- Alternativa con openmp --
23 // A. Create copie of index original list => lst1
24 // B. if list1 es not empty do..
25 // B.1. Create copy of lst1 to lst2
26 // B.2. For each element of lst2 (incrimental) check the distance of the rest of the list (decremental) and take it out
27 // B.3. openmp sobre la La lst2 que queda (PaintImage)
28 // B.4. Quitar los elementos de lst2 en lst1 y recomenzar desde el punto B;
30 double distMin,dist2Min;
31 if (bbGetInputTool()==0)
33 distMin=bbGetInputBrushSize();
35 distMin=bbGetInputDistanceFill();
37 dist2Min=distMin*distMin*1.2;
39 // A. Create copie of index original list => lst1
40 std::vector<int> lst1;
41 int i1,size1 = bbGetInputByLstPointsX().size();
42 for (i1=0;i1<size1;i1++)
47 // B. if list1 es not empty do..
49 double dist2,dx,dy,dz;
50 while (lst1.size()!=0)
52 // B.1. Create copy of lst1 to lst2
54 std::vector<int> lst2;
55 for (i1=0;i1<size1;i1++)
57 lst2.push_back( lst1[i1] );
60 // B.2. For each element of lst2 (incrimental) check the distance of the rest of the list (decremental) and take it out
61 for (i2=0;i2<lst2.size();i2++)
64 for ( i3=size2-1 ; i3>i2 ; i3-- )
66 dx = bbGetInputByLstPointsX()[ lst2[i2] ]-bbGetInputByLstPointsX()[ lst2[i3] ];
67 dy = bbGetInputByLstPointsY()[ lst2[i2] ]-bbGetInputByLstPointsY()[ lst2[i3] ];
68 dz = bbGetInputByLstPointsZ()[ lst2[i2] ]-bbGetInputByLstPointsZ()[ lst2[i3] ];
69 dist2 = dx*dx +dy*dy + dz*dz ;
72 lst2.erase( lst2.begin()+i3 );
76 // B.3. openmp sobre la La lst2 que queda (PaintImage)
78 long int k1omp=(double)(size2-1)*0.0;
79 long int k2omp=(double)(size2-1)*0.2;
80 long int k3omp=(double)(size2-1)*0.4;
81 long int k4omp=(double)(size2-1)*0.6;
82 long int k5omp=(double)(size2-1)*0.8;
83 long int k6omp=(double)(size2-1)*1.0;
84 printf("EED ManualPaint_Model::LstPointOMPAnalice (with openmp)\n");
85 #pragma omp parallel for
86 for (i2=0;i2<size2;i2++)
88 if ( (k1omp==i2) || (k2omp==i2) || (k3omp==i2) ||
89 (k4omp==i2) || (k5omp==i2) || (k6omp==i2) )
93 printf(" 100% (just one element)\n");
95 printf(" %d%\n", (int)(((double)i2/(double)(size2-1))*100 ));
98 manualpaintmodel->PaintImage( bbGetInputByLstPointsX()[ lst2[i2] ] ,
99 bbGetInputByLstPointsY()[ lst2[i2] ] ,
100 bbGetInputByLstPointsZ()[ lst2[i2] ] );
103 // B.4. Quitar los elementos de lst2 en lst1 y recomenzar desde el punto B;
104 for (i2=0;i2<size2;i2++)
107 for (i1=0;i1<size1;i1++)
109 if (lst2[i2]==lst1[i1])
111 lst1.erase( lst1.begin()+i1 );
122 void ManualPaint_Model::Process()
126 0. Quitar comentarion ByLstPoints openmp
127 1. Falta openmp ByImagePoints
128 2. Desligar cada PaintImage de la mascara
129 -pequeno bloque de memoria para cada PaintImage
130 -el resultado volverlo a colocar en la image2 original
131 -Si no existe image2 original y hay que colocarlo en la imagen de origien
132 hay que crear una imagen2 temporal y luego bajar la imagen
133 3. Verificar el mecanismo de undo con ByLstPoints
134 4. Verificar el mecanismo de undo con ByImagePoints
136 if (bbGetInputActive()==true)
138 if (bbGetInputImage()!=NULL)
140 manualpaintmodel->SetActive( bbGetInputActive() );
141 manualpaintmodel->SetTool( bbGetInputTool() );
142 manualpaintmodel->Set2D3D( bbGetInput2D3D() );
143 manualpaintmodel->SetImages( bbGetInputImage(),bbGetInputImage2() );
144 manualpaintmodel->SetGrayLevel( bbGetInputGrayLevel() );
145 manualpaintmodel->SetDirection( bbGetInputDirection() );
146 manualpaintmodel->SetBrushSize( bbGetInputBrushSize() );
147 manualpaintmodel->SetBrushForm( bbGetInputBrushForm() );
148 manualpaintmodel->SetToleranceFill( bbGetInputToleranceFill() );
149 manualpaintmodel->SetDistanceFill( bbGetInputDistanceFill() );
150 manualpaintmodel->SetRangeMin( bbGetInputRange()[0] );
151 manualpaintmodel->SetRangeMax( bbGetInputRange()[1] );
152 if (bbGetInputPoint().size()==3)
154 manualpaintmodel->PaintImage( bbGetInputPoint()[0] , bbGetInputPoint()[1] , bbGetInputPoint()[2] );
155 manualpaintmodel->SetUndoImage();
157 if ( bbGetInputByLstPointsX().size()!=0 )
159 //-- Alternativa con openmp --
160 LstPointOMPAnalice();
162 /* -- Original ByLstPoints sin openmp --
163 int i,size = bbGetInputByLstPointsX().size();
166 manualpaintmodel->PaintImage( bbGetInputByLstPointsX()[i] , bbGetInputByLstPointsY()[i] , bbGetInputByLstPointsZ()[i] );
167 //_manualPaintModel->SetUndoImage(); // Probably needed. Here is ok.
169 -- Original ByLstPoints sin openmp --*/
172 if ((bbGetInputByImagePoints()!=NULL) && (bbGetInputImage2()!=NULL) )
174 // -- Alternativa con openmp --
175 // Calcular numero de cuadrantes
176 // Recorrer el primer cuadrante
177 // Sacar la lista de todos los cuadrantes con el iElement Listo para analizar
178 // Recorrer la lista con openmp y ejecutar PaintImage
180 ///* -------------------- Original ByImagePoints sin openmp----------------------------
184 //EED 2017-01-01 Migration VTK7
185 #if VTK_MAJOR_VERSION <= 5
186 bbGetInputByImagePoints()->GetWholeExtent(ext);
188 bbGetInputByImagePoints()->GetExtent(ext);
190 int dimX=ext[1]-ext[0]+1;
191 int dimY=ext[3]-ext[2]+1;
192 int dimZ=ext[5]-ext[4]+1;
193 DEF_POINTER_IMAGE_VTK_CREA(vBIP,sSBIP,pBIP,sTBIP,bbGetInputByImagePoints());
194 DEF_POINTER_IMAGE_VTK_CREA(vI2,sSI2,pI2,sTI2,bbGetInputImage2());
196 //#pragma omp parallel for
201 printf("ManualPaint_Model %d%\n", (int)(k*100.0/dimZ) );
207 GETVALUE_VTK_CREA(vBIP,pBIP,sTBIP)
210 GETVALUE_VTK_CREA(vI2,pI2,sTI2)
213 manualpaintmodel->PaintImage(i,j,k);
214 // manualpaintmodel->SetUndoImage(); // Probably needed. Here is ok.
222 printf("ManualPaint_Model %d%\n", 100 );
223 //------- Original ByImagePoints sin openmp-------- */
224 } // if ByImagePoints
227 printf("EED Warning!! creaMaracasVisu::ManualPaint_Model (BBTK) bbInputImage not set. \n");
228 } // if (bbGetInputImage()!=NULL)
231 if (bbGetInputImage2()!=NULL)
233 bbSetOutputOut( bbGetInputImage2() );
234 } else if (bbGetInputImage()!=NULL) {
235 bbSetOutputOut( bbGetInputImage() );
237 bbSetOutputOut( NULL );
239 bbSetOutputManualpaintmodel( manualpaintmodel );
242 // 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)
244 void ManualPaint_Model::bbUserSetDefaultValues()
247 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
248 // Here we initialize the input 'In' to 0
250 bbSetInputActive(true);
251 bbSetInputTool(1); // Paint
252 bbSetInput2D3D(1); // 3D
253 bbSetInputImage(NULL);
254 bbSetInputImage2(NULL);
255 bbSetInputGrayLevel(100);
256 bbSetInputDirection(2); // XY
257 bbSetInputBrushSize(3);
258 bbSetInputBrushForm(1); // sphere
259 bbSetInputToleranceFill(50);
260 bbSetInputDistanceFill(25);
261 std::vector<int> point;
265 bbSetInputPoint(point);
266 std::vector<double> range;
268 range.push_back(200);
269 bbSetInputRange(range);
270 bbSetInputByImagePoints(NULL);
273 // 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)
275 void ManualPaint_Model::bbUserInitializeProcessing()
278 // THE INITIALIZATION METHOD BODY :
280 // but this is where you should allocate the internal/output pointers
282 manualpaintmodel=new ManualPaintModel();
285 // 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)
287 void ManualPaint_Model::bbUserFinalizeProcessing()
290 // THE FINALIZATION METHOD BODY :
292 // but this is where you should desallocate the internal/output pointers
294 delete manualpaintmodel;
299 // EO namespace bbcreaMaracasVisu