]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbcreaMaracasVisuManualPaint_Model.cxx
2a64b94278b5d122d0180a0ac6c7663b13ac0ab2
[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 //-- 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;
29         
30         double distMin,dist2Min;
31         if (bbGetInputTool()==0) 
32         { 
33                 distMin=bbGetInputBrushSize(); 
34         } else {
35                 distMin=bbGetInputDistanceFill();
36         }
37         dist2Min=distMin*distMin*1.2;
38
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++)
43         {
44                 lst1.push_back(i1);
45         } // for i1
46
47 // B. if list1 es not empty do..
48         int i2,i3,size2;
49         double dist2,dx,dy,dz;
50         while (lst1.size()!=0)
51         {
52 // B.1. Create copy of lst1 to lst2
53                 size1=lst1.size();
54                 std::vector<int> lst2;
55                 for (i1=0;i1<size1;i1++)
56                 {
57                         lst2.push_back( lst1[i1] );
58                 } // for i1
59                 
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++)
62                 {
63                         size2=lst2.size();
64                         for ( i3=size2-1 ; i3>i2 ; i3-- )
65                         {
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 ;
70                                 if (dist2<dist2Min)
71                                 {
72                                         lst2.erase( lst2.begin()+i3 );
73                                 }                       } // for i3
74                 } // for i2
75
76 // B.3. openmp sobre la La lst2 que queda (PaintImage)
77                 size2=lst2.size();
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)  size=%ld\n",size2);
85 #pragma omp parallel for 
86                 for (i2=0;i2<size2;i2++)
87                 {
88 if ( (k1omp==i2) || (k2omp==i2) || (k3omp==i2) || 
89      (k4omp==i2) || (k5omp==i2) || (k6omp==i2) ) 
90
91         if (size2==1) 
92         { 
93                 printf("  100% (just one element)\n"); 
94         } else {
95                 printf("  %d%\n", (int)(((double)i2/(double)(size2-1))*100 )); 
96         } 
97 }// if K#omp
98                         manualpaintmodel->PaintImage(   bbGetInputByLstPointsX()[ lst2[i2] ] , 
99                                                                                         bbGetInputByLstPointsY()[ lst2[i2] ] , 
100                                                                                         bbGetInputByLstPointsZ()[ lst2[i2] ] );
101                 } // for i2
102
103 // B.4. Quitar los elementos de lst2 en lst1 y recomenzar desde el punto B;
104                 for (i2=0;i2<size2;i2++)
105                 {
106                         size1=lst1.size();
107                         for (i1=0;i1<size1;i1++)
108                         {
109                                 if (lst2[i2]==lst1[i1])
110                                 {
111                                         lst1.erase( lst1.begin()+i1 );
112                                         i1=size1;       
113                                 } // if
114                         } // for i1
115                 } // for i2
116
117         } // while
118
119 }
120
121
122 void ManualPaint_Model::Process()
123 {
124
125 /* Notas
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
135 */ 
136         if (bbGetInputActive()==true)
137         {
138                 if (bbGetInputImage()!=NULL)
139                 {  
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)
153                         {
154                                 manualpaintmodel->PaintImage( bbGetInputPoint()[0] , bbGetInputPoint()[1] , bbGetInputPoint()[2] );
155                                 manualpaintmodel->SetUndoImage();
156                         } // if Points
157                         if ( bbGetInputByLstPointsX().size()!=0 )
158                         {
159                                 //-- Alternativa con openmp --
160                                 LstPointOMPAnalice();
161
162   /* -- Original ByLstPoints sin openmp --
163                                 int i,size = bbGetInputByLstPointsX().size();
164                                 for (i=0;i<size;i++)
165                                 {
166                                         manualpaintmodel->PaintImage(   bbGetInputByLstPointsX()[i] , 
167                                                                                                         bbGetInputByLstPointsY()[i] , 
168                                                                                                         bbGetInputByLstPointsZ()[i] );
169                                         //_manualPaintModel->SetUndoImage();     // Probably needed.   Here is ok.
170                                 } // for
171  -- Original ByLstPoints sin openmp --*/
172
173                         }// if ByLstPointsX
174                         if ((bbGetInputByImagePoints()!=NULL) && (bbGetInputImage2()!=NULL) )
175                         {
176                                 // -- Alternativa con openmp --
177                                 // Calcular numero de cuadrantes
178                                 // Recorrer el primer cuadrante
179                                 //   Sacar la lista de todos los cuadrantes con el iElement Listo para analizar
180                                 // Recorrer la lista con openmp y ejecutar PaintImage
181                         
182 ///*  -------------------- Original ByImagePoints sin openmp----------------------------
183         //                      int ia,ja,ka;
184         //                      int ii,jj,kk;
185                                 int ext[6];
186         //EED 2017-01-01 Migration VTK7
187         #if VTK_MAJOR_VERSION <= 5
188                                 bbGetInputByImagePoints()->GetWholeExtent(ext);
189         #else
190                                 bbGetInputByImagePoints()->GetExtent(ext);
191         #endif
192                                 int dimX=ext[1]-ext[0]+1;
193                                 int dimY=ext[3]-ext[2]+1;
194                                 int dimZ=ext[5]-ext[4]+1;
195                                 DEF_POINTER_IMAGE_VTK_CREA(vBIP,sSBIP,pBIP,sTBIP,bbGetInputByImagePoints());
196                                 DEF_POINTER_IMAGE_VTK_CREA(vI2,sSI2,pI2,sTI2,bbGetInputImage2());
197                                 int i,j,k;
198         //#pragma omp parallel for
199                                 for (k=0;k<dimZ;k++) 
200                                 {
201                                         if (k%50==0)
202                                         {
203                                                 printf("ManualPaint_Model %d%\n", (int)(k*100.0/dimZ) );
204                                         }
205                                         for (j=0;j<dimY;j++) 
206                                         {
207                                                 for (i=0;i<dimX;i++) 
208                                                 {
209                                                         GETVALUE_VTK_CREA(vBIP,pBIP,sTBIP)
210                                                         if (vBIP>0)
211                                                         {
212                                                                 GETVALUE_VTK_CREA(vI2,pI2,sTI2)
213                                                                 if (vI2==0)
214                                                                 {
215                                                                         manualpaintmodel->PaintImage(i,j,k);
216         //                                                              manualpaintmodel->SetUndoImage();     // Probably needed.   Here is ok.
217                                                                 } // vI2                
218                                                         } // vBIP 
219                                                         pBIP = pBIP + sSBIP;                            
220                                                         pI2  = pI2  + sSI2;                             
221                                                 }// for i
222                                         }// for j
223                                 }// for k
224                                 printf("ManualPaint_Model %d%\n", 100 );
225 //-------  Original ByImagePoints sin openmp--------  */
226                         } // if ByImagePoints
227
228                  } else {
229                         printf("EED Warning!!  creaMaracasVisu::ManualPaint_Model (BBTK)   bbInputImage not set.  \n");
230                 } // if (bbGetInputImage()!=NULL)
231         } // if active
232
233         if (bbGetInputImage2()!=NULL)
234         { 
235                 bbSetOutputOut( bbGetInputImage2() );
236         } else if (bbGetInputImage()!=NULL) { 
237                 bbSetOutputOut( bbGetInputImage() );
238         } else { 
239                 bbSetOutputOut( NULL );
240         } 
241         bbSetOutputManualpaintmodel( manualpaintmodel );
242 }
243 //===== 
244 // 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)
245 //===== 
246 void ManualPaint_Model::bbUserSetDefaultValues()
247 {
248
249 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
250 //    Here we initialize the input 'In' to 0
251
252         bbSetInputActive(true);
253         bbSetInputTool(1);              // Paint
254         bbSetInput2D3D(1);              // 3D
255         bbSetInputImage(NULL);
256         bbSetInputImage2(NULL);
257         bbSetInputGrayLevel(100);
258         bbSetInputDirection(2);         // XY
259         bbSetInputBrushSize(3);
260         bbSetInputBrushForm(1);         // sphere
261         bbSetInputToleranceFill(50);
262         bbSetInputDistanceFill(25);
263         std::vector<int> point;
264         point.push_back(0);
265         point.push_back(0);
266         point.push_back(0);
267         bbSetInputPoint(point);
268         std::vector<double> range;
269         range.push_back(0);
270         range.push_back(200);
271         bbSetInputRange(range);
272         bbSetInputByImagePoints(NULL);
273 }
274 //===== 
275 // 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)
276 //===== 
277 void ManualPaint_Model::bbUserInitializeProcessing()
278 {
279
280 //  THE INITIALIZATION METHOD BODY :
281 //    Here does nothing 
282 //    but this is where you should allocate the internal/output pointers 
283 //    if any 
284         manualpaintmodel=new ManualPaintModel();  
285 }
286 //===== 
287 // 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)
288 //===== 
289 void ManualPaint_Model::bbUserFinalizeProcessing()
290 {
291
292 //  THE FINALIZATION METHOD BODY :
293 //    Here does nothing 
294 //    but this is where you should desallocate the internal/output pointers 
295 //    if any
296         delete manualpaintmodel;
297   
298 }
299
300 }
301 // EO namespace bbcreaMaracasVisu
302
303