]> Creatis software - bbtk.git/blobdiff - packages/vtk/src/bbvtkImageBoundaries.cxx
Clean code
[bbtk.git] / packages / vtk / src / bbvtkImageBoundaries.cxx
index 4f7056052562970fc3543792562c20af4ac0535a..c477aade336f12711fd8376ed00224843a8eca37 100644 (file)
@@ -1,8 +1,46 @@
-//===== 
+/*
+ # ---------------------------------------------------------------------
+ #
+ # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+ #                        pour la SantÈ)
+ # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+ # Previous Authors : Laurent Guigues, Jean-Pierre Roux
+ # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+ #
+ #  This software is governed by the CeCILL-B license under French law and
+ #  abiding by the rules of distribution of free software. You can  use,
+ #  modify and/ or redistribute the software under the terms of the CeCILL-B
+ #  license as circulated by CEA, CNRS and INRIA at the following URL
+ #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ #  or in the file LICENSE.txt.
+ #
+ #  As a counterpart to the access to the source code and  rights to copy,
+ #  modify and redistribute granted by the license, users are provided only
+ #  with a limited warranty  and the software's author,  the holder of the
+ #  economic rights,  and the successive licensors  have only  limited
+ #  liability.
+ #
+ #  The fact that you are presently reading this means that you have had
+ #  knowledge of the CeCILL-B license and that you accept its terms.
+ # ------------------------------------------------------------------------ */
+
+
+//=====
 // 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)
 //===== 
 #include "bbvtkImageBoundaries.h"
 #include "bbvtkPackage.h"
+#include "creaVtk_MACROS.h"
+
+
+/*
+
+#include <omp.h>
+
+*/
+
+
+
 namespace bbvtk
 {
 
@@ -13,17 +51,21 @@ BBTK_BLACK_BOX_IMPLEMENTATION(ImageBoundaries,bbtk::AtomicBlackBox);
 //===== 
 void ImageBoundaries::Process()
 {
-       printf("bbtk:vtk::ImageBoundaries::Process start\n");
        if (bbGetInputIn()!=NULL){
-               int i,j,k;      
                int ext[6];
                double value;
                
+//EED 2017-01-01 Migration VTK7
+#if (VTK_MAJOR_VERSION <= 5) 
                bbGetInputIn()->GetWholeExtent(ext);
+#endif
+#if (VTK_MAJOR_VERSION >= 6) 
+               bbGetInputIn()->GetExtent(ext);
+#endif
+
                int maxX        = ext[1]-ext[0]+1;
                int maxY        = ext[3]-ext[2]+1;
                int maxZ        = ext[5]-ext[4]+1;
-                               
                int bXMax       = 0;
                int bYMax       = 0;
                int bZMax       = 0;
@@ -31,29 +73,57 @@ void ImageBoundaries::Process()
                int bYMin       = maxY-1;
                int bZMin       = maxZ-1;
                
-               for (i=0 ; i<maxX ; i++)
+       
+               double lowervalue = bbGetInputLowerValue();
+               double uppervalue = bbGetInputUpperValue();
+               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");
+
+// http://jakascorner.com/blog/2016/05/omp-for.html
+//#pragma omp parallel shared(maxZ,bXMin,bYMin,bZMin,bXMax,bYMax,bZMax)
+//{ 
+               #pragma omp 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 )); }
+                       int i,j;
+                       double vItmpOMP;
                        for (j=0 ; j<maxY ; j++)
                        {
-                               for (k=0 ; k<maxZ ; k++)
+                               for (i=0 ; i<maxX ; i++)
                                {
-                                       value = bbGetInputIn()->GetScalarComponentAsDouble(i, j, k,0);
-                                       if ( (value>=bbGetInputLowerValue()) && (value<=bbGetInputUpperValue())  )
+//                                     double value = bbGetInputIn()->GetScalarComponentAsDouble(i, j, k,0);
+                                       GETVALUE2_VTK_CREA(vItmpOMP,pI,stI,index) 
+                                       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<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;
                                        }
                                } // for k
                        } // for j
                } // i
-                       
+// } // #pragma
+
                std::vector<int> tmpIndex;              
                std::vector<int> tmpSize;
-               
                if (bXMin>bXMax){
                        tmpIndex.push_back(0);
                        tmpIndex.push_back(0);
@@ -69,13 +139,11 @@ void ImageBoundaries::Process()
                        tmpSize.push_back(bYMax-bYMin+1);
                        tmpSize.push_back(bZMax-bZMin+1);
                }
-                       
                bbSetOutputIndex(tmpIndex);
                bbSetOutputSize(tmpSize);
        } else {
                printf("bbtk warnning: bbtk:vtk:ImageBoundaries box, Input image (In) not initialized..\n");
        }
-       printf("bbtk:vtk::ImageBoundaries::Process end\n");
 }
 //===== 
 // 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)