]> Creatis software - creaVtk.git/commitdiff
#3276 creaVtk Feature New Normal - DistanceMap Box
authorEduardo DAVILA <davila@ei-ed-606.creatis.insa-lyon.fr>
Fri, 12 Jul 2019 12:55:49 +0000 (14:55 +0200)
committerEduardo DAVILA <davila@ei-ed-606.creatis.insa-lyon.fr>
Fri, 12 Jul 2019 12:55:49 +0000 (14:55 +0200)
bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.cxx [new file with mode: 0644]
bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.h [new file with mode: 0644]

diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.cxx
new file mode 100644 (file)
index 0000000..1c50d0f
--- /dev/null
@@ -0,0 +1,256 @@
+//===== 
+// 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 "bbcreaVtkDistanceMap.h"
+#include "bbcreaVtkPackage.h"
+namespace bbcreaVtk
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,DistanceMap)
+BBTK_BLACK_BOX_IMPLEMENTATION(DistanceMap,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)
+//===== 
+void DistanceMap::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')
+
+       if ( (bbGetInputIn()!=NULL) && (bbGetInputPoint1().size()==3) )
+       {
+
+               int     ext[6];
+               int     dim[3];
+               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;
+               if (imageoutput!=NULL) 
+               {
+                       imageoutput->Delete();
+               }       
+               imageoutput = vtkImageData::New();
+               imageoutput->Initialize();
+               imageoutput->SetSpacing( spc );
+               imageoutput->SetDimensions(  dim[0], dim[1], dim[2] );
+
+       //EED 2017-01-01 Migration VTK7
+       #if (VTK_MAJOR_VERSION <= 5) 
+               imageoutput->SetScalarType( VTK_DOUBLE );       
+               imageoutput->AllocateScalars();
+       #endif
+       #if (VTK_MAJOR_VERSION >= 6) 
+               imageoutput->AllocateScalars( VTK_DOUBLE,1 );
+       #endif
+               imageoutput->Modified();
+
+               memset( imageoutput->GetScalarPointer() ,0, sizeof(double)*dim[0]*dim[1]*dim[2] );
+               std::vector<int> lst1X;         
+               std::vector<int> lst1Y;         
+               std::vector<int> lst1Z;         
+
+               std::vector<int> lst2X;         
+               std::vector<int> lst2Y;         
+               std::vector<int> lst2Z;         
+
+               lst1X.push_back( bbGetInputPoint1()[0] );
+               lst1Y.push_back( bbGetInputPoint1()[1]);
+               lst1Z.push_back( bbGetInputPoint1()[2]);
+
+               long int i,size;
+               double glIn,glOut;
+               double depth=0;
+               int px,py,pz;           
+               int pxOut,pyOut,pzOut;  
+
+               while (lst1X.size()>0)
+               {
+                       depth=depth+bbGetInputSlope();
+                       size=lst1X.size();
+                       for (i=0;i<size;i++)
+                       {
+                               glIn=bbGetInputIn()->GetScalarComponentAsDouble( lst1X[i], lst1Y[i], lst1Z[i], 0);
+                               if (glIn!=0)
+                               {
+                                       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));
+                                               pxOut=lst1X[i]; pyOut=lst1Y[i]; pzOut=lst1Z[i];
+
+
+                                               for (px=lst1X[i]-1;px<=lst1X[i]+1;px++)
+                                               {
+                                                       for (py=lst1Y[i]-1;py<=lst1Y[i]+1;py++)
+                                                       {
+                                                               for (pz=lst1Z[i]-1;pz<=lst1Z[i]+1;pz++)
+                                                               {
+                                                                       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; }
+                                                                               if (glOut==0) { lst2X.push_back(px); lst2Y.push_back(  py ); lst2Z.push_back(  pz ); }
+                                                                       } // if 
+                                                               } // for kk
+                                                       } // fo jj
+                                               } // for ii
+
+                                               if ( bbGetInputPoint2().size()==3)
+                                               {
+                                                       if ( (bbGetInputPoint2()[0]==lst1X[i]) && (bbGetInputPoint2()[1]==lst1Y[i]) && (bbGetInputPoint2()[2]==lst1Z[i]) )
+                                                       {
+                                                               i=size;  // out of for lst1
+                                                               lst2X.clear();
+                                                               lst2Y.clear();
+                                                               lst2Z.clear();
+                                                       } // if Arrive to Point2
+                                               } // Point size 3
+
+                                       }
+
+                               }// If glIn
+
+                       }  // for lst1
+
+                       lst1X.clear();
+                       lst1Y.clear();
+                       lst1Z.clear();
+
+                       size=lst2X.size();
+                       for (i=0;i<size;i++)
+                       {
+                               lst1X.push_back( lst2X[i] );
+                               lst1Y.push_back( lst2Y[i] );
+                               lst1Z.push_back( lst2Z[i] );
+                       } // for lst2
+
+                       lst2X.clear();
+                       lst2Y.clear();
+                       lst2Z.clear();
+
+               } // while lstX
+
+
+               std::vector<int> lstPointOut;
+               lstPointOut.push_back( pxOut );
+               lstPointOut.push_back( pyOut );
+               lstPointOut.push_back( pzOut );
+
+               std::vector<int> lstPathXOut;
+               std::vector<int> lstPathYOut;
+               std::vector<int> lstPathZOut;
+       
+               lstPathXOut.push_back( pxOut );
+               lstPathYOut.push_back( pyOut );
+               lstPathZOut.push_back( pzOut );
+
+               // find Path
+               bool    ok2;
+               bool    ok      = true;
+               double  min     = imageoutput->GetScalarComponentAsDouble( pxOut,pyOut,pzOut , 0);
+               int pxOutBack;
+               int pyOutBack;
+               int pzOutBack;
+               while (ok==true)
+               {       
+                       ok2=false;
+                       for (px=pxOut-1;px<=pxOut+1;px++)
+                       {
+                               for (py=pyOut-1;py<=pyOut+1;py++)
+                               {
+                                       for (pz=pzOut-1;pz<=pzOut+1;pz++)
+                                       {
+                                               if ((px>=0) && (px<dim[0]) && (py>=0) && (py<dim[1]) && (pz>=0) && (pz<dim[2]) )
+                                               { 
+                                                               glOut=imageoutput->GetScalarComponentAsDouble( px,py,pz , 0); 
+                                                               if ( (glOut<min) && (glOut!=0) )
+                                                               {
+                                                                       min                     = glOut;
+                                                                       pxOutBack       = px;
+                                                                       pyOutBack       = py;
+                                                                       pzOutBack       = pz;
+                                                                       ok2                     = true;
+                                                               } // if min
+                                               } // if 
+                                       } // for kk
+                               } // fo jj
+                       } // for ii
+
+                       if (ok2==true)
+                       {
+                               pxOut=pxOutBack;
+                               pyOut=pyOutBack;
+                               pzOut=pzOutBack;
+                               lstPathXOut.push_back( pxOut );
+                               lstPathYOut.push_back( pyOut );
+                               lstPathZOut.push_back( pzOut );
+                       } else {
+                               ok=false;
+                       }
+               }
+
+               bbSetOutputOut( imageoutput );
+               bbSetOutputFinalPoint( lstPointOut );
+
+               bbSetOutputLstPathXOut( lstPathXOut );
+               bbSetOutputLstPathYOut( lstPathYOut );
+               bbSetOutputLstPathZOut( lstPathZOut );
+       } else {
+               printf("EED Warnning! DistanceMap::Process  In or Point1 is EMPTY\n");
+       }  // if In Point1  
+
+}
+//===== 
+// 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)
+//===== 
+void DistanceMap::bbUserSetDefaultValues()
+{
+
+//  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
+//    Here we initialize the input 'In' to 0
+       bbSetInputIn(NULL);
+       bbSetInputSlope(10);
+       imageoutput=NULL;
+  
+}
+//===== 
+// 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)
+//===== 
+void DistanceMap::bbUserInitializeProcessing()
+{
+
+//  THE INITIALIZATION METHOD BODY :
+//    Here does nothing 
+//    but this is where you should allocate the internal/output pointers 
+//    if any 
+
+  
+}
+//===== 
+// 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)
+//===== 
+void DistanceMap::bbUserFinalizeProcessing()
+{
+
+//  THE FINALIZATION METHOD BODY :
+//    Here does nothing 
+//    but this is where you should desallocate the internal/output pointers 
+//    if any
+  
+}
+}
+// EO namespace bbcreaVtk
+
+
diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.h b/bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.h
new file mode 100644 (file)
index 0000000..a86d68e
--- /dev/null
@@ -0,0 +1,71 @@
+//===== 
+// 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)
+//===== 
+#ifndef __bbcreaVtkDistanceMap_h_INCLUDED__
+#define __bbcreaVtkDistanceMap_h_INCLUDED__
+
+#include "bbcreaVtk_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+
+#include "vtkImageData.h"
+
+namespace bbcreaVtk
+{
+
+class bbcreaVtk_EXPORT DistanceMap
+ : 
+   public bbtk::AtomicBlackBox
+{
+  BBTK_BLACK_BOX_INTERFACE(DistanceMap,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)
+//===== 
+
+  BBTK_DECLARE_INPUT(In,vtkImageData*);
+  BBTK_DECLARE_INPUT(Slope,double);
+  BBTK_DECLARE_INPUT(Point1, std::vector<int>);
+  BBTK_DECLARE_INPUT(Point2, std::vector<int>);
+
+  BBTK_DECLARE_OUTPUT(Out,vtkImageData*);
+  BBTK_DECLARE_OUTPUT(FinalPoint,std::vector<int>);
+  BBTK_DECLARE_OUTPUT(LstPathXOut,std::vector<int>);
+  BBTK_DECLARE_OUTPUT(LstPathYOut,std::vector<int>);
+  BBTK_DECLARE_OUTPUT(LstPathZOut,std::vector<int>);
+
+  BBTK_PROCESS(Process);
+  void Process();
+
+  vtkImageData* imageoutput;
+
+//===== 
+// 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)
+//===== 
+};
+
+BBTK_BEGIN_DESCRIBE_BLACK_BOX(DistanceMap,bbtk::AtomicBlackBox);
+  BBTK_NAME("DistanceMap");
+  BBTK_AUTHOR("InfoDev");
+  BBTK_DESCRIPTION("Normaly mask or mask[0 255] + gaussian[5]");
+  BBTK_CATEGORY("empty");
+
+    BBTK_INPUT(DistanceMap,In,"Input image",vtkImageData*,"");
+    BBTK_INPUT(DistanceMap,Slope,"(default 10) Slope",double,"");
+    BBTK_INPUT(DistanceMap,Point1,"Start point",std::vector<int>,"");
+    BBTK_INPUT(DistanceMap,Point2,"End point (There is no guarantee of reaching this point.)",std::vector<int>,"");
+
+    BBTK_OUTPUT(DistanceMap,Out,"Output image",vtkImageData*,"");
+    BBTK_OUTPUT(DistanceMap,FinalPoint,"Final Point",std::vector<int>,"");
+    BBTK_OUTPUT(DistanceMap,LstPathXOut,"Vector path X",std::vector<int>,"");
+    BBTK_OUTPUT(DistanceMap,LstPathYOut,"Vector path Y",std::vector<int>,"");
+    BBTK_OUTPUT(DistanceMap,LstPathZOut,"Vector path Z",std::vector<int>,"");
+
+BBTK_END_DESCRIBE_BLACK_BOX(DistanceMap);
+//===== 
+// 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)
+//===== 
+}
+// EO namespace bbcreaVtk
+
+#endif // __bbcreaVtkDistanceMap_h_INCLUDED__
+