]> Creatis software - creaMaracasVisu.git/commitdiff
#3413 creaMaracasVisu Feature New Normal - openmp and Transparent mechanism in...
authorEduardo DAVILA <davila@localhost.localdomain>
Mon, 27 Apr 2020 08:39:15 +0000 (10:39 +0200)
committerEduardo DAVILA <davila@localhost.localdomain>
Mon, 27 Apr 2020 08:39:15 +0000 (10:39 +0200)
bbtk/src/bbcreaMaracasVisuManualPaint_Model.cxx
bbtk/src/bbcreaMaracasVisuManualPaint_Model.h
bbtk/src/bbmaracasvisuAxeVolume.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk3DBaseView.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)
index 4e7e008abc6f60ebb1c636661320f62010843f97..d5cc1d44565041a74f53d591732506ac4a172ad2 100644 (file)
@@ -42,7 +42,7 @@ class bbcreaMaracasVisu_EXPORT ManualPaint_Model
   BBTK_PROCESS(Process);
   void Process();
 
-
+  void LstPointOMPAnalice();
   ManualPaintModel *manualpaintmodel;
 
 //===== 
index 1a72bb5e4a55e8daf80b77784cd5c8f716081092..b660b691d8f7b518960be41833eace21570a4d47 100644 (file)
@@ -26,6 +26,8 @@
 #include "bbmaracasvisuAxeVolume.h"
 #include "bbcreaMaracasVisuPackage.h"
 
+#include "creaVtk_MACROS.h"
+
 namespace bbcreaMaracasVisu
 {
 
@@ -66,116 +68,146 @@ int AxeVolume::GetTypeFormat( std::string formatStr , vtkImageData* image )
 
 void AxeVolume::Process()
 {
-       if ( mimage!=NULL )
-       {
-               mimage->Delete();
-       }
-
-       int ext[6];
-       bbGetInputIn()->GetExtent(ext);
-       int sizeX=ext[1]-ext[0]+1;
-       int sizeY=ext[3]-ext[2]+1;
-       int sizeZ=ext[5]-ext[4]+1;
-
-    double spc[3];
-       bbGetInputIn()->GetSpacing(spc);
-    double invSpc[3];
-    invSpc[0] = 1/spc[0];
-    invSpc[1] = 1/spc[1];
-    invSpc[2] = 1/spc[2];
-
-       int outputformat = GetTypeFormat( bbGetInputOutputFormat() , bbGetInputIn() );
-
-       mimage = vtkImageData::New();
-       mimage->SetSpacing(bbGetInputIn()->GetSpacing());
-       mimage->SetDimensions(bbGetInputIn()->GetDimensions());
-       mimage->SetExtent(bbGetInputIn()->GetExtent());
-       mimage->SetOrigin(bbGetInputIn()->GetOrigin());
-//EED 2017-01-01 Migration VTK7
-#if VTK_MAJOR_VERSION <= 5
-       mimage->SetScalarType( outputformat );
-       mimage->AllocateScalars();
-#else
-       mimage->AllocateScalars( outputformat , 1);
-#endif
-
-    int sizeLstPointR  = bbGetInputlstPointR().size();
-       int iAxe,sizeAxe        = bbGetInputlstPointX().size();
-       int ii;
-       int sizeImage           = sizeX*sizeY*sizeZ;
-       unsigned short *p;
-
-       // Clean image
-       p = (unsigned short*)mimage->GetScalarPointer (0, 0, 0);
-       for ( ii=0 ; ii<sizeImage ; ii++)
+       if (bbGetInputIn()!=NULL)
        {
-               *p = 0;
-               p++;
-       }
-
-
-#pragma omp parallel for 
-       for (iAxe=0 ; iAxe<sizeAxe; iAxe++)
-        {
-               int i,j,k;
-               double rx,ry,rz;
-               double r,rr;
-               double px,py,pz;
-               double px1,py1,pz1;
-               double px2,py2,pz2;
-               printf("AxeVolume %d/%d\n ",iAxe,sizeAxe);
-               if (iAxe<sizeLstPointR)
+               if ( mimage!=NULL )
                {
-                       r = bbGetInputlstPointR()[ iAxe ]* invSpc[0];
-               } else {
-                       if (bbGetInputlstPointR().size()>=1)
+                       mimage->Delete();
+               }
+
+               int ext[6];
+               bbGetInputIn()->GetExtent(ext);
+               int sizeX=ext[1]-ext[0]+1;
+               int sizeY=ext[3]-ext[2]+1;
+               int sizeZ=ext[5]-ext[4]+1;
+
+               double spc[3];
+               bbGetInputIn()->GetSpacing(spc);
+               double invSpc[3];
+               invSpc[0] = 1/spc[0];
+               invSpc[1] = 1/spc[1];
+               invSpc[2] = 1/spc[2];
+
+               int outputformat = GetTypeFormat( bbGetInputOutputFormat() , bbGetInputIn() );
+
+               mimage = vtkImageData::New();
+               mimage->SetSpacing(bbGetInputIn()->GetSpacing());
+               mimage->SetDimensions(bbGetInputIn()->GetDimensions());
+               mimage->SetExtent(bbGetInputIn()->GetExtent());
+               mimage->SetOrigin(bbGetInputIn()->GetOrigin());
+       //EED 2017-01-01 Migration VTK7
+       #if VTK_MAJOR_VERSION <= 5
+               mimage->SetScalarType( outputformat );
+               mimage->AllocateScalars();
+       #else
+               mimage->AllocateScalars( outputformat , 1);
+       #endif
+
+               int sizeLstPointR       = bbGetInputlstPointR().size();
+               int iAxe,sizeAxe        = bbGetInputlstPointX().size();
+               int ii;
+               int sizeImage           = sizeX*sizeY*sizeZ;
+       //      unsigned short *p;
+
+               // Clean image
+               memset( (char*)mimage->GetScalarPointer(0,0,0) , 0, sizeImage*(mimage->GetScalarSize()) );
+
+       //      p = (unsigned short*)mimage->GetScalarPointer (0, 0, 0);
+       //      for ( ii=0 ; ii<sizeImage ; ii++)
+       //      {
+       //              *p = 0;
+       //              p++;
+       //      }
+
+
+       DEF_POINTER_IMAGE_VTK_CREA(vI,ssI,pI,stI,mimage)
+
+
+       int k1omp=(double)(sizeAxe-1)*0.0;
+       int k2omp=(double)(sizeAxe-1)*0.2;
+       int k3omp=(double)(sizeAxe-1)*0.4;
+       int k4omp=(double)(sizeAxe-1)*0.6;
+       int k5omp=(double)(sizeAxe-1)*0.8;
+       int k6omp=(double)(sizeAxe-1)*1.0;
+
+       printf("EED AxeVolume::Process (with openmp)\n");
+
+       #pragma omp parallel for 
+               for (iAxe=0 ; iAxe<sizeAxe; iAxe++)
+                {
+       if ( (k1omp==iAxe) || (k2omp==iAxe) || (k3omp==iAxe) || 
+                (k4omp==iAxe) || (k5omp==iAxe) || (k6omp==iAxe) ) { printf("  %d%\n", (int)(((double)iAxe/(double)(sizeAxe-1))*100 )); }
+                       int i,j,k;
+                       double rx,ry,rz;
+                       double r,rr;
+                       double px,py,pz;
+                       double px1,py1,pz1;
+                       double px2,py2,pz2;
+                       double vItmpOMP;
+
+                       if (iAxe<sizeLstPointR)
                        {
-                               r = bbGetInputlstPointR()[ bbGetInputlstPointR().size()-1 ]    * invSpc[0];
+                               r = bbGetInputlstPointR()[ iAxe ]* invSpc[0];
                        } else {
-                               r = 1;
-                       }
-               }
-               px = bbGetInputlstPointX()[iAxe] * invSpc[0];
-               py = bbGetInputlstPointY()[iAxe] * invSpc[1];
-               pz = bbGetInputlstPointZ()[iAxe] * invSpc[2];
-               px1 = px - r;
-               py1 = py - r;
-               pz1 = pz - r;
-               px2 = px + r;
-               py2 = py + r;
-               pz2 = pz + r;
-               rr=r*r;
-
-               for ( i=px1 ; i<=px2 ; i++ )
-               {
-                       rx      =       i - px;
-                       rx      =       rx*rx;
-                       for ( j=py1 ; j<py2 ; j++ )
+                               if (bbGetInputlstPointR().size()>=1)
+                               {
+                                       r = bbGetInputlstPointR()[ bbGetInputlstPointR().size()-1 ]    * invSpc[0];
+                               } else {
+                                       r = 1;
+                               }
+                       } // if iAxe sizeLstPointR
+                       px = bbGetInputlstPointX()[iAxe] * invSpc[0];
+                       py = bbGetInputlstPointY()[iAxe] * invSpc[1];
+                       pz = bbGetInputlstPointZ()[iAxe] * invSpc[2];
+                       px1 = px - r;
+                       py1 = py - r;
+                       pz1 = pz - r;
+                       px2 = px + r;
+                       py2 = py + r;
+                       pz2 = pz + r;
+                       rr=r*r;
+
+                       long int index;
+                       for ( i=px1 ; i<=px2 ; i++ )
                        {
-                               ry      =       j - py;
-                               ry      =       ry*ry;
-                               for ( k=pz1 ; k<pz2 ; k++ )
+                               rx      =       i - px;
+                               rx      =       rx*rx;
+                               for ( j=py1 ; j<py2 ; j++ )
                                {
-                                       if ( (i>=0) && (i<sizeX) && (j>=0) && (j<sizeY) &&(k>=0) && (k<sizeZ) )
+                                       ry      =       j - py;
+                                       ry      =       ry*ry;
+                                       for ( k=pz1 ; k<pz2 ; k++ )
                                        {
-//                                             p = (unsigned short*)mimage->GetScalarPointer (i, j, k);
-//                                             if (*p==0)
-                                               if ( mimage->GetScalarComponentAsDouble(i,j,k,0)==0 )
+                                               if ( (i>=0) && (i<sizeX) && (j>=0) && (j<sizeY) &&(k>=0) && (k<sizeZ) )
                                                {
-                                                       rz      =       k - pz;
-                                                       rz      =       rz*rz;
-                                                       if ( rx + ry + rz <= rr )
+       //                                              p = (unsigned short*)mimage->GetScalarPointer (i, j, k);
+       //                                              if (*p==0)
+                                                       index=i+j*sizeX+k*sizeX*sizeY;
+                                                       GETVALUE2_VTK_CREA(vItmpOMP,pI,stI,index)
+       // EED2020-04-25                                                if ( mimage->GetScalarComponentAsDouble(i,j,k,0)==0 )
+                                                       if ( vI==0 )
                                                        {
-//                                                             *p=255;
-                                                               mimage->SetScalarComponentFromDouble (i,j,k,0, bbGetInputValue() );
-                                                       }
-                                               } // *p==0
-                                       } // if inside point
-                               } //for k
-                       } //for j
-               } //for i
-       } // for iAxe
-    bbSetOutputOut( mimage );
+                                                               rz      =       k - pz;
+                                                               rz      =       rz*rz;
+                                                               if ( rx + ry + rz <= rr )
+                                                               {
+       //                                                              *p=255;
+                                                                       vItmpOMP=bbGetInputValue();
+                                                                       SETVALUE2_VTK_CREA(vItmpOMP,pI,stI,index)
+       // EED2020-04-25                                                                mimage->SetScalarComponentFromDouble (i,j,k,0, bbGetInputValue() );
+                                                               }
+                                                       } // *p==0
+                                               } // if inside point
+                                       } //for k
+                               } //for j
+                       } //for i
+               } // for iAxe
+               bbSetOutputOut( mimage );
+       } else  {
+               printf("\n");
+               printf("EED Warnning!!  AxeVolume::Process  The Input In is not set.\n");
+               printf("\n");
+       }// if bbGetInputIn()
 }
 
 
index d9c33391a9cfa152c4fe8de4cbf2998dd762ed02..4bf3d9b73a7520f050ab99e131f2f6eaa642663b 100644 (file)
@@ -208,7 +208,14 @@ void wxVtk3DBaseView::Configure()
                GetCamera()->Yaw(180+30);
                GetCamera()->Pitch(-22);
                                
-       }
+               //https://stackoverflow.com/questions/47528086/problems-with-rendering-transparent-objects-in-vtk
+               //https://itk.org/Wiki/VTK/Depth_Peeling
+               _aRenderer->SetUseDepthPeeling(1);
+               _aRenderer->SetOcclusionRatio(0.1);
+               _aRenderer->SetMaximumNumberOfPeels(100);
+               _renWin->SetMultiSamples(0);
+               _renWin->SetAlphaBitPlanes(1);
+       } // if _configure
 }
 
 //-------------------------------------------------------------------