From dce9dbecb71a7f84a827c550976eeec0eee2c6a8 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Fri, 12 Jul 2019 14:55:49 +0200 Subject: [PATCH] #3276 creaVtk Feature New Normal - DistanceMap Box --- bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.cxx | 256 ++++++++++++++++++ bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.h | 71 +++++ 2 files changed, 327 insertions(+) create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.cxx create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.h diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.cxx new file mode 100644 index 0000000..1c50d0f --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkDistanceMap.cxx @@ -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 lst1X; + std::vector lst1Y; + std::vector lst1Z; + + std::vector lst2X; + std::vector lst2Y; + std::vector 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;iGetScalarComponentAsDouble( 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=0) && (py=0) && (pzGetScalarComponentAsDouble( 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 lstPointOut; + lstPointOut.push_back( pxOut ); + lstPointOut.push_back( pyOut ); + lstPointOut.push_back( pzOut ); + + std::vector lstPathXOut; + std::vector lstPathYOut; + std::vector 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=0) && (py=0) && (pzGetScalarComponentAsDouble( px,py,pz , 0); + if ( (glOut); + BBTK_DECLARE_INPUT(Point2, std::vector); + + BBTK_DECLARE_OUTPUT(Out,vtkImageData*); + BBTK_DECLARE_OUTPUT(FinalPoint,std::vector); + BBTK_DECLARE_OUTPUT(LstPathXOut,std::vector); + BBTK_DECLARE_OUTPUT(LstPathYOut,std::vector); + BBTK_DECLARE_OUTPUT(LstPathZOut,std::vector); + + 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,""); + BBTK_INPUT(DistanceMap,Point2,"End point (There is no guarantee of reaching this point.)",std::vector,""); + + BBTK_OUTPUT(DistanceMap,Out,"Output image",vtkImageData*,""); + BBTK_OUTPUT(DistanceMap,FinalPoint,"Final Point",std::vector,""); + BBTK_OUTPUT(DistanceMap,LstPathXOut,"Vector path X",std::vector,""); + BBTK_OUTPUT(DistanceMap,LstPathYOut,"Vector path Y",std::vector,""); + BBTK_OUTPUT(DistanceMap,LstPathZOut,"Vector path Z",std::vector,""); + +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__ + -- 2.45.1