]> Creatis software - creaVtk.git/commitdiff
#3304 creaVtk Bug New Normal - GrayLevel box
authorEduardo DAVILA <davila@ei-ed-606.univ-lyon1.fr>
Thu, 12 Sep 2019 15:07:03 +0000 (17:07 +0200)
committerEduardo DAVILA <davila@ei-ed-606.univ-lyon1.fr>
Thu, 12 Sep 2019 15:07:03 +0000 (17:07 +0200)
bbtk_creaVtk_PKG/src/bbcreaVtkGrayLevel.cxx

index 4f8ca61e3747575e0783ff8d31ab43d245813d6b..11e6c3a76d438e34ea18262c3713cab495d19313 100644 (file)
@@ -14,6 +14,8 @@ BBTK_BLACK_BOX_IMPLEMENTATION(GrayLevel,bbtk::AtomicBlackBox);
 void GrayLevel::Process()
 {
 
+printf ("EED GrayLevel::Process Start\n");
+
 // THE MAIN PROCESSING METHOD BODY
 //   Here we simply set the input 'In' value to the output 'Out'
 //   And print out the output value
@@ -31,24 +33,44 @@ void GrayLevel::Process()
 
     double grayLevel                   = -9999;
     std::vector<double> coord  = bbGetInputCoordinate();
+
+       int ext[6];
+       int maxX,maxY,maxZ;
+
        double px,py,pz;
        if (bbGetInputImage()!=NULL)
        {
                double spc[3];
                bbGetInputImage()->GetSpacing(spc);
-               if (coord.size()>=2)
+               bbGetInputImage()->GetExtent(ext);
+               maxX = ext[1]-ext[0]+1;
+               maxY = ext[3]-ext[2]+1;
+               maxZ = ext[5]-ext[4]+1;
+
+               if (coord.size()==3)
                { 
                        if (bbGetInputWithSpacing()==true)
                        {
-                               px = round(coord[0]/spc[0]);
-                               py = round(coord[1]/spc[1]);
-                               pz = round(coord[2]/spc[2]);
+                               px = coord[0]/spc[0];
+                               py = coord[1]/spc[1];
+                               pz = coord[2]/spc[2];
                        } else {
-                               px = round(coord[0]);
-                               py = round(coord[1]);
-                               pz = round(coord[2]);
+                               px = coord[0];
+                               py = coord[1];
+                               pz = coord[2];
                        }// if
-                       grayLevel = bbGetInputImage()->GetScalarComponentAsDouble( px,py,pz,0);
+
+                       px=round(px);
+                       py=round(py);
+                       pz=round(pz);           
+                       if ( (px>=0) && (px<maxX) && (py>=0) && (py<maxY) &&(pz>=0) && (pz<maxZ)  )
+                       {
+                               grayLevel = bbGetInputImage()->GetScalarComponentAsDouble( px,py,pz,0);
+                       } else {
+                               grayLevel = -9991;
+                       } // if px py pz
+
+
                } // coord
                std::vector<double> lstGL;
                std::vector<double> lstX = bbGetInputLstPointsX();
@@ -61,20 +83,33 @@ void GrayLevel::Process()
                        {       
                                if (bbGetInputWithSpacing()==true)
                                {
-                                       px = round(lstX[i]/spc[0]);
-                                       py = round(lstY[i]/spc[1]);
-                                       pz = round(lstZ[i]/spc[2]);
+                                       px = lstX[i]/spc[0];
+                                       py = lstY[i]/spc[1];
+                                       pz = lstZ[i]/spc[2];
                                } else {
-                                       px = round(lstX[i]);
-                                       py = round(lstY[i]);
-                                       pz = round(lstZ[i]);                                    
+                                       px = lstX[i];
+                                       py = lstY[i];
+                                       pz = lstZ[i];                                   
                                }// if
-                               lstGL.push_back( bbGetInputImage()->GetScalarComponentAsDouble( px,py,pz,0) );
+
+                               px = round(px);
+                               py = round(py);
+                               pz = round(pz);
+                               if ( (px>=0) && (px<maxX) && (py>=0) && (py<maxY) &&(pz>=0) && (pz<maxZ)  )
+                               {
+                                       lstGL.push_back( bbGetInputImage()->GetScalarComponentAsDouble( px, py,pz,0) );
+                               } else {
+                                       lstGL.push_back( -9991 );
+                               }
+
                        }// for 
                        bbSetOutputLstGrayLevel(lstGL);
                } // if size of Lst
        } // InputImage
        bbSetOutputGrayLevel(grayLevel);
+
+printf ("EED GrayLevel::Process End\n");
+
 }
 
 //=====