]> Creatis software - creaMaracasVisu.git/blobdiff - bbtk/src/bbcreaMaracasVisuManualPaint_Model.cxx
#3413 creaMaracasVisu Feature New Normal - openmp and Transparent mechanism in...
[creaMaracasVisu.git] / bbtk / src / bbcreaMaracasVisuManualPaint_Model.cxx
index 58df16c3523c4da7bea3f11f4ab15842e33051f4..7167f6cbff873cc17cbff82fe8ac9cde70301e3f 100644 (file)
@@ -16,24 +16,123 @@ BBTK_BLACK_BOX_IMPLEMENTATION(ManualPaint_Model,bbtk::AtomicBlackBox);
 // 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)
 //===== 
 
+//-- Alternativa con openmp --
+void ManualPaint_Model::LstPointOMPAnalice()
+{
+//-- Alternativa con openmp --
+// A. Create copie of index original list => lst1
+// B. if list1 es not empty do..
+// B.1. Create copy of lst1 to lst2
+// B.2. For each element of lst2 (incrimental) check the distance of the rest of the list (decremental) and take it out
+// B.3. openmp sobre la La lst2 que queda (PaintImage)
+// B.4. Quitar los elementos de lst2 en lst1 y recomenzar desde el punto B;
+       
+       double distMin,dist2Min;
+       if (bbGetInputTool()==0) 
+       { 
+               distMin=bbGetInputBrushSize(); 
+       } else {
+               distMin=bbGetInputDistanceFill();
+       }
+       dist2Min=distMin*distMin*1.2;
+
+// A. Create copie of index original list => lst1
+       std::vector<int> lst1;
+       int i1,size1 = bbGetInputByLstPointsX().size();
+       for (i1=0;i1<size1;i1++)
+       {
+               lst1.push_back(i1);
+       } // for i1
+
+// B. if list1 es not empty do..
+       int i2,i3,size2;
+       double dist2,dx,dy,dz;
+       while (lst1.size()!=0)
+       {
+// B.1. Create copy of lst1 to lst2
+               size1=lst1.size();
+               std::vector<int> lst2;
+               for (i1=0;i1<size1;i1++)
+               {
+                       lst2.push_back( lst1[i1] );
+               } // for i1
+               
+// B.2. For each element of lst2 (incrimental) check the distance of the rest of the list (decremental) and take it out
+               for (i2=0;i2<lst2.size();i2++)
+               {
+                       size2=lst2.size();
+                       for ( i3=size2-1 ; i3>i2 ; i3-- )
+                       {
+                               dx              = bbGetInputByLstPointsX()[ lst2[i2] ]-bbGetInputByLstPointsX()[ lst2[i3] ];
+                               dy              = bbGetInputByLstPointsY()[ lst2[i2] ]-bbGetInputByLstPointsY()[ lst2[i3] ];
+                               dz              = bbGetInputByLstPointsZ()[ lst2[i2] ]-bbGetInputByLstPointsZ()[ lst2[i3] ];
+                               dist2   = dx*dx +dy*dy + dz*dz ;
+                               if (dist2<dist2Min)
+                               {
+                                       lst2.erase( lst2.begin()+i3 );
+                               }                       } // for i3
+               } // for i2
+
+// B.3. openmp sobre la La lst2 que queda (PaintImage)
+               size2=lst2.size();
+long int k1omp=(double)(size2-1)*0.0;
+long int k2omp=(double)(size2-1)*0.2;
+long int k3omp=(double)(size2-1)*0.4;
+long int k4omp=(double)(size2-1)*0.6;
+long int k5omp=(double)(size2-1)*0.8;
+long int k6omp=(double)(size2-1)*1.0;
+printf("EED ManualPaint_Model::LstPointOMPAnalice (with openmp)\n");
+#pragma omp parallel for 
+               for (i2=0;i2<size2;i2++)
+               {
+if ( (k1omp==i2) || (k2omp==i2) || (k3omp==i2) || 
+     (k4omp==i2) || (k5omp==i2) || (k6omp==i2) ) 
+{ 
+       if (size2==1) 
+       { 
+               printf("  100% (just one element)\n"); 
+       } else {
+               printf("  %d%\n", (int)(((double)i2/(double)(size2-1))*100 )); 
+       } 
+}// if K#omp
+                       manualpaintmodel->PaintImage(   bbGetInputByLstPointsX()[ lst2[i2] ] , 
+                                                                                       bbGetInputByLstPointsY()[ lst2[i2] ] , 
+                                                                                       bbGetInputByLstPointsZ()[ lst2[i2] ] );
+               } // for i2
+
+// B.4. Quitar los elementos de lst2 en lst1 y recomenzar desde el punto B;
+               for (i2=0;i2<size2;i2++)
+               {
+                       size1=lst1.size();
+                       for (i1=0;i1<size1;i1++)
+                       {
+                               if (lst2[i2]==lst1[i1])
+                               {
+                                       lst1.erase( lst1.begin()+i1 );
+                                       i1=size1;       
+                               } // if
+                       } // for i1
+               } // for i2
+
+       } // while
+
+}
+
 
 void ManualPaint_Model::Process()
 {
 
-// THE MAIN PROCESSING METHOD BODY
-//   Here we simply set the input 'In' value to the output 'Out'
-//   And print out the output value
-// INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
-//    void bbSet{Input|Output}NAME(const TYPE&)
-//    const TYPE& bbGet{Input|Output}NAME() const 
-//    Where :
-//    * NAME is the name of the input/output
-//      (the one provided in the attribute 'name' of the tag 'input')
-//    * TYPE is the C++ type of the input/output
-//      (the one provided in the attribute 'type' of the tag 'input')
-//    bbSetOutputOut( bbGetInputIn() );
-//    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
-
+/* Notas
+0. Quitar comentarion ByLstPoints openmp
+1. Falta openmp ByImagePoints
+2. Desligar cada PaintImage de la mascara
+    -pequeno bloque de memoria para cada PaintImage
+       -el resultado volverlo a colocar en la image2 original
+       -Si no existe image2 original y hay que colocarlo en la imagen de origien 
+        hay que crear una imagen2 temporal y luego bajar la imagen 
+3. Verificar el mecanismo de undo con ByLstPoints
+4. Verificar el mecanismo de undo con ByImagePoints
+*/ 
        if (bbGetInputActive()==true)
        {
                if (bbGetInputImage()!=NULL)
@@ -57,15 +156,28 @@ void ManualPaint_Model::Process()
                        } // if Points
                        if ( bbGetInputByLstPointsX().size()!=0 )
                        {
+                               //-- Alternativa con openmp --
+                               LstPointOMPAnalice();
+
+/* -- Original ByLstPoints sin openmp --
                                int i,size = bbGetInputByLstPointsX().size();
                                for (i=0;i<size;i++)
                                {
                                        manualpaintmodel->PaintImage( bbGetInputByLstPointsX()[i] , bbGetInputByLstPointsY()[i] , bbGetInputByLstPointsZ()[i] );
-       //                      _manualPaintModel->SetUndoImage();     // Probably needed.   Here is ok.
+                                       //_manualPaintModel->SetUndoImage();     // Probably needed.   Here is ok.
                                } // for
+ -- Original ByLstPoints sin openmp --*/
+
                        }// if ByLstPointsX
                        if ((bbGetInputByImagePoints()!=NULL) && (bbGetInputImage2()!=NULL) )
                        {
+                               // -- Alternativa con openmp --
+                               // Calcular numero de cuadrantes
+                               // Recorrer el primer cuadrante
+                               //   Sacar la lista de todos los cuadrantes con el iElement Listo para analizar
+                               // Recorrer la lista con openmp y ejecutar PaintImage
+                       
+///*  -------------------- Original ByImagePoints sin openmp----------------------------
        //                      int ia,ja,ka;
        //                      int ii,jj,kk;
                                int ext[6];
@@ -80,8 +192,8 @@ void ManualPaint_Model::Process()
                                int dimZ=ext[5]-ext[4]+1;
                                DEF_POINTER_IMAGE_VTK_CREA(vBIP,sSBIP,pBIP,sTBIP,bbGetInputByImagePoints());
                                DEF_POINTER_IMAGE_VTK_CREA(vI2,sSI2,pI2,sTI2,bbGetInputImage2());
-       //#pragma omp parallel for
                                int i,j,k;
+       //#pragma omp parallel for
                                for (k=0;k<dimZ;k++) 
                                {
                                        if (k%50==0)
@@ -108,10 +220,12 @@ void ManualPaint_Model::Process()
                                        }// for j
                                }// for k
                                printf("ManualPaint_Model %d%\n", 100 );
+//-------  Original ByImagePoints sin openmp--------  */
                        } // if ByImagePoints
+
                 } else {
-                       printf("EED Warning: ByImagePoints or Image2 not set.  Box creaMaracasVisu::ManualPaint_Model (BBTK) \n");
-               } // if ((bbGetInputByImagePoints()!=NULL) && (bbGetInputImage2()!=NULL) )
+                       printf("EED Warning!!  creaMaracasVisu::ManualPaint_Model (BBTK)   bbInputImage not set.  \n");
+               } // if (bbGetInputImage()!=NULL)
        } // if active
 
        if (bbGetInputImage2()!=NULL)