]> Creatis software - creaVtk.git/blobdiff - bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.cxx
#3281 creaVtk Feature New Normal - FindAxisEED
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkDistanceMap.cxx
index 787c1efa5e3d9033935458369b5534768066adec..fae5840f0958a5319805039e279f9dd58e35c5c2 100644 (file)
@@ -3,6 +3,9 @@
 //===== 
 #include "bbcreaVtkDistanceMap.h"
 #include "bbcreaVtkPackage.h"
+
+#include "creaVtk_MACROS.h"
+
 namespace bbcreaVtk
 {
 
@@ -29,14 +32,17 @@ void DistanceMap::Process()
        if ( (bbGetInputIn()!=NULL) && (bbGetInputPoint1().size()==3) )
        {
 
-               int     ext[6];
-               int     dim[3];
+               int             ext[6];
+               int             dim[3];
+               long int        dimX,dimXY;
                double  spc[3];
                bbGetInputIn()->GetSpacing(spc);
                bbGetInputIn()->GetExtent(ext);
-               dim[0]= ext[1]-ext[0]+1;
-               dim[1]= ext[3]-ext[2]+1;
-               dim[2]= ext[5]-ext[4]+1;
+               dim[0]  = ext[1]-ext[0]+1;
+               dim[1]  = ext[3]-ext[2]+1;
+               dim[2]  = ext[5]-ext[4]+1;
+               dimX    = dim[0];
+               dimXY   = dim[0]*dim[1];
                if (imageoutput!=NULL) 
                {
                        imageoutput->Delete();
@@ -74,16 +80,11 @@ void DistanceMap::Process()
                double depth=0;
                int px,py,pz;           
                int pxOut,pyOut,pzOut;  
+               double tmpValue;
 
 
-printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
-printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
-printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
-printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
-printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
-printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
-printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
-printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
+               DEF_POINTER_IMAGE_VTK_CREA(vIn,ssIn,pIn,stIn,bbGetInputIn())
+               DEF_POINTER_IMAGE_VTK_CREA(vOut,ssOut,pOut,stOut,imageoutput)
 
                while (lst1X.size()>0)
                {
@@ -91,13 +92,18 @@ printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
                        size=lst1X.size();
                        for (i=0;i<size;i++)
                        {
-                               glIn=bbGetInputIn()->GetScalarComponentAsDouble( lst1X[i], lst1Y[i], lst1Z[i], 0);
+                               GETVALUE2_VTK_CREA(glIn,pIn,stIn, lst1X[i] + lst1Y[i]*dimX + lst1Z[i]*dimXY )
+
+//                             glIn=bbGetInputIn()->GetScalarComponentAsDouble( lst1X[i], lst1Y[i], lst1Z[i], 0);
                                if (glIn!=0)
                                {
-                                       glOut=imageoutput->GetScalarComponentAsDouble( lst1X[i], lst1Y[i], lst1Z[i], 0);
+                                       GETVALUE2_VTK_CREA(glOut,pOut,stOut, lst1X[i] + lst1Y[i]*dimX + lst1Z[i]*dimXY )
+//                                     glOut=imageoutput->GetScalarComponentAsDouble( lst1X[i], lst1Y[i], lst1Z[i], 0);
                                        if (glOut==0)
                                        {
-                                               imageoutput->SetScalarComponentFromDouble( lst1X[i], lst1Y[i], lst1Z[i], 0, depth+(255-glIn));
+                                               tmpValue        =       depth  +  (255-glIn)*bbGetInputAverageRadius()*2;
+                                               SETVALUE2_VTK_CREA(tmpValue,pOut,stOut,  lst1X[i] + lst1Y[i]*dimX + lst1Z[i]*dimXY )
+//                                             imageoutput->SetScalarComponentFromDouble( lst1X[i], lst1Y[i], lst1Z[i], 0, depth+(255-glIn)*bbGetInputAverageRadius()*2);
                                                pxOut=lst1X[i]; pyOut=lst1Y[i]; pzOut=lst1Z[i];
 
 
@@ -110,7 +116,12 @@ printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
                                                                        if (!( (px==lst1X[i]) && (py==lst1Y[i]) && (pz==lst1Z[i]) )) 
                                                                        {
                                                                                if ((px>=0) && (px<dim[0]) && (py>=0) && (py<dim[1]) &&  (pz>=0) && (pz<dim[2]) )
-                                                                                       { glOut=imageoutput->GetScalarComponentAsDouble( px,py,pz , 0); } else { glOut=-1; }
+                                                                               { 
+                                                                                       GETVALUE2_VTK_CREA(glOut,pOut,stOut, px + py*dimX + pz*dimXY )
+//                                                                                     glOut=imageoutput->GetScalarComponentAsDouble( px,py,pz , 0); 
+                                                                               } else { 
+                                                                                       glOut=-1; 
+                                                                               } // if px py pz  inside the image
                                                                                if (glOut==0) { lst2X.push_back(px); lst2Y.push_back(  py ); lst2Z.push_back(  pz ); }
                                                                        } // if 
                                                                } // for kk
@@ -173,7 +184,6 @@ printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
                int pxOutBack;
                int pyOutBack;
                int pzOutBack;
-               int length=0;
                while (ok==true)
                {       
                        ok2=false;
@@ -185,7 +195,8 @@ printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
                                        {
                                                if ((px>=0) && (px<dim[0]) && (py>=0) && (py<dim[1]) && (pz>=0) && (pz<dim[2]) )
                                                { 
-                                                               glOut=imageoutput->GetScalarComponentAsDouble( px,py,pz , 0); 
+                                                               GETVALUE2_VTK_CREA(glOut,pOut,stOut, px + py*dimX + pz*dimXY )
+//                                                             glOut=imageoutput->GetScalarComponentAsDouble( px,py,pz , 0); 
                                                                if ( (glOut<min) && (glOut!=0) )
                                                                {
                                                                        min                     = glOut;
@@ -207,7 +218,6 @@ printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
                                lstPathXOut.push_back( pxOut );
                                lstPathYOut.push_back( pyOut );
                                lstPathZOut.push_back( pzOut );
-                               length++;
                        } else {
                                ok=false;
                        }
@@ -215,7 +225,19 @@ printf("EED Warnning!  DistanceMap::Process    Clean Ponter Image......\n");
 
                bbSetOutputOut( imageoutput );
                bbSetOutputFinalPoint( lstPointOut );
-               bbSetOutputLength( length );
+               bbSetOutputLengthPixels( lstPathXOut.size() );
+
+               // invert list of points
+               size=lstPathXOut.size();
+               long int size2=size/2;
+               int tmp;        
+               for (i=0; i<size2;i++)
+               {
+                       tmp= lstPathXOut[i]; lstPathXOut[i]=lstPathXOut[size-1-i]; lstPathXOut[size-1-i]=tmp;
+                       tmp= lstPathYOut[i]; lstPathYOut[i]=lstPathYOut[size-1-i]; lstPathYOut[size-1-i]=tmp;
+                       tmp= lstPathZOut[i]; lstPathZOut[i]=lstPathZOut[size-1-i]; lstPathZOut[size-1-i]=tmp;
+               } // for invert list            
+
                bbSetOutputLstPathXOut( lstPathXOut );
                bbSetOutputLstPathYOut( lstPathYOut );
                bbSetOutputLstPathZOut( lstPathZOut );
@@ -233,6 +255,7 @@ void DistanceMap::bbUserSetDefaultValues()
 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
 //    Here we initialize the input 'In' to 0
        bbSetInputIn(NULL);
+       bbSetInputAverageRadius(10);
        bbSetInputSlope(10);
        imageoutput=NULL;