]> Creatis software - bbtk.git/commitdiff
#3523 openmp ImageBoundaries
authoreduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Thu, 17 Oct 2024 13:52:52 +0000 (15:52 +0200)
committereduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Thu, 17 Oct 2024 13:52:52 +0000 (15:52 +0200)
kernel/cmake/BBTKConfigurePackage.cmake
packages/itk/CMakeLists.txt
packages/itkvtk/CMakeLists.txt
packages/std/src/bbstdVectorFilterDouble.cxx
packages/std/src/bbstdVectorFilterDouble.h
packages/vtk/CMakeLists.txt
packages/vtk/src/bbvtkImageBoundaries.cxx

index cf1949eaa4996267ce0fc71231c65f818d499994..7e627cd7fe209188f1dcc64b162bd43123a56c47 100644 (file)
@@ -142,6 +142,16 @@ ENDIF(NOT ${BBTK_PACKAGE_NAME}_IN_DEPS)
 
 #---------------------------------------------------------------------------
 # Package dependencies
+
+IF(${BBTK_PACKAGE_NAME}_USE_OPENMP)
+  SET(USE_OPENMP ON CACHE BOOL "Use OPENMP" FORCE)
+  SET(${BBTK_PACKAGE_NAME}_LIBS
+    ${${BBTK_PACKAGE_NAME}_LIBS}
+    ${OpenMP_libomp_LIBRARY_crea}
+    )
+   LINK_DIRECTORIES( /opt/local/lib/libomp )
+ENDIF(${BBTK_PACKAGE_NAME}_USE_VTK)
+
 IF(${BBTK_PACKAGE_NAME}_USE_VTK)
   SET(USE_VTK ON CACHE BOOL "Use VTK" FORCE)
   SET(${BBTK_PACKAGE_NAME}_LIBS
index c1821170b0b43056d61f5ae479b8d860f0006365..c25db9390b3e2e6dea9acb88f3b13dd173cbf6a2 100644 (file)
@@ -45,6 +45,8 @@ SET(${BBTK_PACKAGE_NAME}_USE_ITK  ON)
 # SET(${BBTK_PACKAGE_NAME}_USE_GDCM2 ON)
 # SET(${BBTK_PACKAGE_NAME}_USE_GSMIS ON)
 # SET(${BBTK_PACKAGE_NAME}_USE_WXWIDGETS ON)
+SET(${BBTK_PACKAGE_NAME}_USE_OPENMP ON)
+
 #===========================================================================
 
 #===========================================================================
@@ -140,6 +142,9 @@ SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS
   ../std/src
   # The path to the build tree folder is needed to find bbstd_EXPORT.h
   ${PROJECT_BINARY_DIR}/packages/std/src
+  
+  /opt/local/include/libomp
+  
   )
 #===========================================================================
 
index 1b62a97e20929c2707b136fe844c81d16eb51247..594830be72b2a470190ba5685f97d202d8e6fa44 100644 (file)
@@ -138,6 +138,8 @@ SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS
   #  - automatically handled libraries or packages : wx, vtk... (see above)
   #  - the dirs automatically set by other libraries found by FIND_PACKAGE
  ../itk/src
+   /opt/local/include/libomp
+
   )
 #===========================================================================
 
index 16c90e1f876dac1f838f65946f79cc085318adb1..ff85b0b8550231993d0d791317d0f571ce96e4e0 100644 (file)
@@ -492,6 +492,24 @@ void VectorFilterDouble::Process()
         } // if In0.size   and  k1.size
      } // Type 15
 
+    if (bbGetInputType()==16)   // 16 switch In0 and In1 (k1=1 nothing, k0 swhich)
+    {
+        if (bbGetInputk1().size()==1)
+        {
+            if (bbGetInputk1()[0] == 0)
+            {
+                Out0 = In0;
+                Out1 = In1;
+            } // if k1 == 0
+            if (bbGetInputk1()[0] == 1)
+            {
+                Out0 = In1;
+                Out1 = In0;
+            } // if k1 == 1
+        } // if size k1 == 1
+    } // if Type 16
+    
+    
        bbSetOutputOut0( Out0 );
        bbSetOutputOut1( Out1 );
        bbSetOutputOut2( Out2 );
index 08b525fc8e408d0bd0b79f9ada91a2949c5da869..ee7976b9244647e3d6686c92367d79d3398faa82 100644 (file)
@@ -52,8 +52,8 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(VectorFilterDouble,bbtk::AtomicBlackBox);
   BBTK_AUTHOR("InfoDev");
   BBTK_DESCRIPTION("No Description.");
   BBTK_CATEGORY("empty");
-  BBTK_INPUT(VectorFilterDouble,Type,"default (0)  0=Erase duplicated lines, 1=Redimention Vectors, 2=Insert intermediat points,3=Adition k1, 4=Substraction k1, 5=Multilication k1, 6=Division k1, 7=Connect mesh X1,Y1,Z1,idxs1,X2,X2,X2,idx2, 8=Order All vectors with the logic of In0 , 9=Invert Vectors, 10=Nearest Point in the vector. In3PointXYZ In0LstX In1LstY In2LstZ  (Out0-index Out1-PointXYZ), 11=Mul Spacing (K1[spcX,spcY,spcZ]=Spacing), 12=Div Spacing (K1[spcX,spcY,spcZ]=Spacing), 13=Distance pointIn0 and pontIn1,  14=Select specific segments [k1] in In0=lstPx In1=lstPy In2=lstPz In3=lstIndex (if k1 empty all segments are selected) , 15 swhitch element in a point k1=0 yz, k1=1 nothing k2=2 xz",int,"");
-  BBTK_INPUT(VectorFilterDouble,k1,"(default [0])  nothing (Type0), k1[0]=new size vectors (Type 1) , nothing (Type2), k1[0] = Addition const. (Type 3), k1[0] = Substraction const. (Type 4), k1[0] = Multiplication const. (Type 5) , k1[0] = Division const. (Type 6)  , k1[spcX,spcY,spcZ] MulSpc In0_X,In1_Y,In2_Z (type 11),  k1[spcX,spcY,spcZ] DivSpc In0_X,In1_Y,In2_Z (type 12) , k1[segment1, segment2,..] (type 14) , direction (type 15) ",std::vector<double>,"");
+  BBTK_INPUT(VectorFilterDouble,Type,"default (0)  0=Erase duplicated lines, 1=Redimention Vectors, 2=Insert intermediat points,3=Adition k1, 4=Substraction k1, 5=Multilication k1, 6=Division k1, 7=Connect mesh X1,Y1,Z1,idxs1,X2,X2,X2,idx2, 8=Order All vectors with the logic of In0 , 9=Invert Vectors, 10=Nearest Point in the vector. In3PointXYZ In0LstX In1LstY In2LstZ  (Out0-index Out1-PointXYZ), 11=Mul Spacing (K1[spcX,spcY,spcZ]=Spacing), 12=Div Spacing (K1[spcX,spcY,spcZ]=Spacing), 13=Distance pointIn0 and pontIn1,  14=Select specific segments [k1] in In0=lstPx In1=lstPy In2=lstPz In3=lstIndex (if k1 empty all segments are selected) , 15 swhitch element in a point k1=0 yz, k1=1 nothing k2=2 xz , 16 switch In0 and In1 (k1=1 nothing k0 swhich)",int,"");
+  BBTK_INPUT(VectorFilterDouble,k1,"(default [0])  nothing (Type0), k1[0]=new size vectors (Type 1) , nothing (Type2), k1[0] = Addition const. (Type 3), k1[0] = Substraction const. (Type 4), k1[0] = Multiplication const. (Type 5) , k1[0] = Division const. (Type 6)  , k1[spcX,spcY,spcZ] MulSpc In0_X,In1_Y,In2_Z (type 11),  k1[spcX,spcY,spcZ] DivSpc In0_X,In1_Y,In2_Z (type 12) , k1[segment1, segment2,..] (type 14) , direction (type 15), direction (type 16) ",std::vector<double>,"");
   BBTK_INPUT(VectorFilterDouble,In0,"Input vector",std::vector<double>,"");
   BBTK_INPUT(VectorFilterDouble,In1,"Input vector",std::vector<double>,"");
   BBTK_INPUT(VectorFilterDouble,In2,"Input vector",std::vector<double>,"");
index 6689a6089c52f8a5bbe6e345d219eff9ea0db8aa..13ae68a820abced8d0a88b2742ebb2047fa15d6d 100644 (file)
@@ -67,6 +67,7 @@ SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION 0)
 # SET(${BBTK_PACKAGE_NAME}_USE_GDCM2 ON)
 # SET(${BBTK_PACKAGE_NAME}_USE_GSMIS ON)
 # SET(${BBTK_PACKAGE_NAME}_USE_WXWIDGETS ON)
+SET(${BBTK_PACKAGE_NAME}_USE_OPENMP ON)
 #===========================================================================
 
 #===========================================================================
index c477aade336f12711fd8376ed00224843a8eca37..ad8f1afd93a9b2b0009b49f2e6d483e49da37bef 100644 (file)
@@ -79,26 +79,41 @@ void ImageBoundaries::Process()
                DEF_POINTER_IMAGE_VTK_CREA(vI,ssI,pI,stI,bbGetInputIn())        
                long int index=0;
 
-               //int i,j;
-               int k;  
-
-int k1omp=(double)(maxZ-1)*0.0;
-int k2omp=(double)(maxZ-1)*0.2;
-int k3omp=(double)(maxZ-1)*0.4;
-int k4omp=(double)(maxZ-1)*0.6;
-int k5omp=(double)(maxZ-1)*0.8;
-int k6omp=(double)(maxZ-1)*1.0;
-
-//printf("EED ImageBoundaries::Process (with openmp)\n");
-
+        
+        int *vecXMin = (int*)malloc( maxZ*sizeof(int) );
+        int *vecYMin = (int*)malloc( maxZ*sizeof(int) );
+        int *vecZMin = (int*)malloc( maxZ*sizeof(int) );
+        int *vecXMax = (int*)malloc( maxZ*sizeof(int) );
+        int *vecYMax = (int*)malloc( maxZ*sizeof(int) );
+        int *vecZMax = (int*)malloc( maxZ*sizeof(int) );
+
+        //int i,j;
+        int k;
+
+        for ( k=0 ; k<maxZ ; k++)
+        {
+            vecXMax[k] = 0;
+            vecYMax[k] = 0;
+            vecZMax[k] = 0;
+            vecXMin[k] = maxX-1;
+            vecYMin[k] = maxY-1;
+            vecZMin[k] = maxZ-1;
+        } // for
+        
+        int k1omp = (double)(maxZ-1)*0.0;
+        int k2omp = (double)(maxZ-1)*0.2;
+        int k3omp = (double)(maxZ-1)*0.4;
+        int k4omp = (double)(maxZ-1)*0.6;
+        int k5omp = (double)(maxZ-1)*0.8;
+        int k6omp = (double)(maxZ-1)*1.0;
+
+printf("EED ImageBoundaries::Process (with openmp)\n");
 // http://jakascorner.com/blog/2016/05/omp-for.html
-//#pragma omp parallel shared(maxZ,bXMin,bYMin,bZMin,bXMax,bYMax,bZMax)
-//{ 
-               #pragma omp for
+        #pragma omp parallel for
                for ( k=0 ; k<maxZ ; k++)
                {
-//if ( (k1omp==k) || (k2omp==k) || (k3omp==k) || 
-//     (k4omp==k) || (k5omp==k) || (k6omp==k) ) { printf("  %d%\n", (int)(((double)k/(double)(maxZ-1))*100 )); }
+if ( (k1omp==k) || (k2omp==k) || (k3omp==k) ||
+     (k4omp==k) || (k5omp==k) || (k6omp==k) ) { printf("  %d%\n", (int)(((double)k/(double)(maxZ-1))*100 )); }
                        int i,j;
                        double vItmpOMP;
                        for (j=0 ; j<maxY ; j++)
@@ -110,19 +125,45 @@ int k6omp=(double)(maxZ-1)*1.0;
                                        index++;
                                        if ( (vItmpOMP>=lowervalue) && (vItmpOMP<=uppervalue)  )
                                        {
+                        /*
                                                if (i<bXMin) bXMin = i;
                                                if (j<bYMin) bYMin = j;
                                                if (k<bZMin) bZMin = k;
                                                if (i>bXMax) bXMax = i;
                                                if (j>bYMax) bYMax = j;
                                                if (k>bZMax) bZMax = k;
+                         */
+                        if (i<vecXMin[k]) vecXMin[k] = i;
+                        if (j<vecYMin[k]) vecYMin[k] = j;
+                        if (k<vecZMin[k]) vecZMin[k] = k;
+                        if (i>vecXMax[k]) vecXMax[k] = i;
+                        if (j>vecYMax[k]) vecYMax[k] = j;
+                        if (k>vecZMax[k]) vecZMax[k] = k;
+
                                        }
                                } // for k
                        } // for j
                } // i
-// } // #pragma
 
-               std::vector<int> tmpIndex;              
+        
+        for ( k=0 ; k<maxZ ; k++)
+        {
+            if (vecXMin[k]<bXMin) bXMin = vecXMin[k];
+            if (vecYMin[k]<bYMin) bYMin = vecYMin[k];
+            if (vecZMin[k]<bZMin) bZMin = vecZMin[k];
+            if (vecXMax[k]>bXMax) bXMax = vecXMax[k];
+            if (vecYMax[k]>bYMax) bYMax = vecYMax[k];
+            if (vecZMax[k]>bZMax) bZMax = vecZMax[k];
+        }
+                
+        delete vecXMin;
+        delete vecYMin;
+        delete vecZMin;
+        delete vecXMax;
+        delete vecYMax;
+        delete vecZMax;
+
+               std::vector<int> tmpIndex;
                std::vector<int> tmpSize;
                if (bXMin>bXMax){
                        tmpIndex.push_back(0);