]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbcreaMaracasVisuManualPaint_Model.cxx
19945fbdfae42f69833c6d9afb40ba3f5623b452
[creaMaracasVisu.git] / bbtk / src / bbcreaMaracasVisuManualPaint_Model.cxx
1 //===== 
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)
3 //===== 
4
5 #include "creaVtk_MACROS.h"
6 #include "bbcreaMaracasVisuManualPaint_Model.h"
7 #include "bbcreaMaracasVisuPackage.h"
8
9
10 namespace bbcreaMaracasVisu
11 {
12
13 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ManualPaint_Model)
14 BBTK_BLACK_BOX_IMPLEMENTATION(ManualPaint_Model,bbtk::AtomicBlackBox);
15 //===== 
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)
17 //===== 
18
19 //-- Alternativa con openmp --
20 void ManualPaint_Model::LstPointOMPAnalice()
21 {
22
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"); 
28
29
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;
38         
39         double distMin,dist2Min;
40         if (bbGetInputTool()==0) 
41         { 
42                 distMin=bbGetInputBrushSize(); 
43         } else {
44                 distMin=bbGetInputDistanceFill();
45         }
46         dist2Min=distMin*distMin*1.2;
47
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++)
52         {
53                 lst1.push_back(i1);
54         } // for i1
55
56 // B. if list1 es not empty do..
57         int i2,i3,size2;
58         double dist2,dx,dy,dz;
59         while (lst1.size()!=0)
60         {
61 // B.1. Create copy of lst1 to lst2
62                 size1=lst1.size();
63                 std::vector<int> lst2;
64                 for (i1=0;i1<size1;i1++)
65                 {
66                         lst2.push_back( lst1[i1] );
67                 } // for i1
68                 
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++)
71                 {
72                         size2=lst2.size();
73                         for ( i3=size2-1 ; i3>i2 ; i3-- )
74                         {
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 ;
79                                 if (dist2<dist2Min)
80                                 {
81                                         lst2.erase( lst2.begin()+i3 );
82                                 }                       } // for i3
83                 } // for i2
84
85 // B.3. openmp sobre la La lst2 que queda (PaintImage)
86                 size2=lst2.size();
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++)
96                 {
97                         if ( (k1omp==i2) || (k2omp==i2) || (k3omp==i2) || 
98                                  (k4omp==i2) || (k5omp==i2) || (k6omp==i2) ) 
99                         { 
100                                 if (size2==1) 
101                                 { 
102                                         printf("  100% (just one element)\n"); 
103                                 } else {
104                                         printf("  %d% \n", (int)(((double)i2/(double)(size2-1))*100 )); 
105                                 } 
106                         }// if K#omp
107                         manualpaintmodel->PaintImage(   bbGetInputByLstPointsX()[ lst2[i2] ] , 
108                                                                                         bbGetInputByLstPointsY()[ lst2[i2] ] , 
109                                                                                         bbGetInputByLstPointsZ()[ lst2[i2] ] );
110                 } // for i2
111
112 // B.4. Quitar los elementos de lst2 en lst1 y recomenzar desde el punto B;
113                 for (i2=0;i2<size2;i2++)
114                 {
115                         size1=lst1.size();
116                         for (i1=0;i1<size1;i1++)
117                         {
118                                 if (lst2[i2]==lst1[i1])
119                                 {
120                                         lst1.erase( lst1.begin()+i1 );
121                                         i1=size1;       
122                                 } // if
123                         } // for i1
124                 } // for i2
125
126         } // while
127 printf("EED ManualPaint_Model::LstPointOMPAnalice End\n");
128
129 }
130
131
132 void ManualPaint_Model::Process()
133 {
134 printf("EED ManualPaint_Model::Process Start\n");
135 /* Notas
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
145 */ 
146         if (bbGetInputActive()==true)
147         {
148 printf("EED ManualPaint_Model::Process 1\n");
149                 if (bbGetInputImage()!=NULL)
150                 {  
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)
167                         {
168 printf("EED ManualPaint_Model::Process 3\n");
169                                 manualpaintmodel->PaintImage( bbGetInputPoint()[0] , bbGetInputPoint()[1] , bbGetInputPoint()[2] );
170                                 manualpaintmodel->SetUndoImage();
171                         } // if Points
172                         if ( bbGetInputByLstPointsX().size()!=0 )
173                         {
174 printf("EED ManualPaint_Model::Process 4\n");
175                                 //-- Alternativa con openmp --
176 //                              LstPointOMPAnalice();
177
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 
188                                 for (i=0;i<size;i++)
189                                 {
190                                         if ( (k1omp==i) || (k2omp==i) || (k3omp==i) || 
191                                                  (k4omp==i) || (k5omp==i) || (k6omp==i) ) 
192                                         { 
193                                                 if (size==1) 
194                                                 { 
195                                                         printf("  100% (just one element)\n"); 
196                                                 } else {
197                                                         printf("  %d% \n", (int)(((double)i/(double)(size-1))*100 )); 
198                                                 } 
199                                         }// if K#omp
200                                         manualpaintmodel->PaintImage(   bbGetInputByLstPointsX()[i] , 
201                                                                                                         bbGetInputByLstPointsY()[i] , 
202                                                                                                         bbGetInputByLstPointsZ()[i] );
203                                         //_manualPaintModel->SetUndoImage();     // Probably needed.   Here is ok.
204                                 } // for
205 //  -- Original ByLstPoints sin openmp --*/
206
207                                 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
208
209                         }// if ByLstPointsX
210                         if ((bbGetInputByImagePoints()!=NULL) && (bbGetInputImage2()!=NULL) )
211                         {
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
217                         
218 ///*  -------------------- Original ByImagePoints sin openmp----------------------------
219         //                      int ia,ja,ka;
220         //                      int ii,jj,kk;
221                                 int ext[6];
222         //EED 2017-01-01 Migration VTK7
223         #if VTK_MAJOR_VERSION <= 5
224                                 bbGetInputByImagePoints()->GetWholeExtent(ext);
225         #else
226                                 bbGetInputByImagePoints()->GetExtent(ext);
227         #endif
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());
233
234                                 long int index, size=dimX*dimY*dimZ;
235
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++)
245                                 {
246                                         if ( (k1omp==index) || (k2omp==index) || (k3omp==index) || 
247                                                  (k4omp==index) || (k5omp==index) || (k6omp==index) ) 
248                                         { 
249                                                 if (size==1) 
250                                                 { 
251                                                         printf("  100% (just one element)\n"); 
252                                                 } else {
253                                                         printf("  %d% \n", (int)(((double)index/(double)(size-1))*100 )); 
254                                                 } 
255                                         }// if K#omp
256                                         double value1;
257                                         GETVALUE2_VTK_CREA(value1,pBIP,sTBIP,index)
258                                         if (value1>0)
259                                         {
260                                                 double value2;
261                                                 GETVALUE2_VTK_CREA(value2,pI2,sTI2,index)
262                                                 if (value2==0)
263                                                 {
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.
269                                                 } // vI2                
270                                         } // vBIP 
271                                 } // for index
272                                 manualpaintmodel->Copy_GeneralAuxFill_to_Results();
273
274 /*
275                                 int i,j,k;
276         //#pragma omp parallel for
277                                 for (k=0;k<dimZ;k++) 
278                                 {
279                                         for (j=0;j<dimY;j++) 
280                                         {
281                                                 for (i=0;i<dimX;i++) 
282                                                 {
283                                                         GETVALUE_VTK_CREA(vBIP,pBIP,sTBIP)
284                                                         if (vBIP>0)
285                                                         {
286                                                                 GETVALUE_VTK_CREA(vI2,pI2,sTI2)
287                                                                 if (vI2==0)
288                                                                 {
289                                                                         manualpaintmodel->PaintImage(i,j,k);
290         //                                                              manualpaintmodel->SetUndoImage();     // Probably needed.   Here is ok.
291                                                                 } // vI2                
292                                                         } // vBIP 
293                                                         pBIP = pBIP + sSBIP;                            
294                                                         pI2  = pI2  + sSI2;                             
295                                                 }// for i
296                                         }// for j
297                                 }// for k
298 //-------  Original ByImagePoints sin openmp--------  */
299
300
301                         } // if ByImagePoints
302
303                  } else {
304                         printf("EED Warning!!  creaMaracasVisu::ManualPaint_Model (BBTK)   bbInputImage not set.  \n");
305                 } // if (bbGetInputImage()!=NULL)
306         } // if active
307
308         if (bbGetInputImage2()!=NULL)
309         { 
310                 bbSetOutputOut( bbGetInputImage2() );
311         } else if (bbGetInputImage()!=NULL) { 
312                 bbSetOutputOut( bbGetInputImage() );
313         } else { 
314                 bbSetOutputOut( NULL );
315         } 
316         bbSetOutputManualpaintmodel( manualpaintmodel );
317
318 printf("EED ManualPaint_Model::Process End\n");
319 }
320 //===== 
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)
322 //===== 
323 void ManualPaint_Model::bbUserSetDefaultValues()
324 {
325
326 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
327 //    Here we initialize the input 'In' to 0
328
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;
346         range.push_back(0);
347         range.push_back(200);
348         bbSetInputRange(range);
349         bbSetInputByImagePoints(NULL);
350 }
351 //===== 
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)
353 //===== 
354 void ManualPaint_Model::bbUserInitializeProcessing()
355 {
356
357 //  THE INITIALIZATION METHOD BODY :
358 //    Here does nothing 
359 //    but this is where you should allocate the internal/output pointers 
360 //    if any 
361         manualpaintmodel=new ManualPaintModel();  
362 }
363 //===== 
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)
365 //===== 
366 void ManualPaint_Model::bbUserFinalizeProcessing()
367 {
368
369 //  THE FINALIZATION METHOD BODY :
370 //    Here does nothing 
371 //    but this is where you should desallocate the internal/output pointers 
372 //    if any
373         delete manualpaintmodel;
374   
375 }
376
377 }
378 // EO namespace bbcreaMaracasVisu
379
380