From fd579f268efe95807b8800d073ac4e9b8645aea2 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Thu, 30 Jun 2016 02:47:38 +0200 Subject: [PATCH] #2981 BBTK Feature New Normal - FormatOutput of filters in string --- packages/vtk/src/bbtkSimpleUtilities.h | 2 +- packages/vtk/src/bbtkStaticLecture.cxx | 33 ++++++++++++ packages/vtk/src/bbtkStaticLecture.h | 5 +- .../vtk/src/bbvtkRescaleSlopeIntercept.cxx | 17 ++----- packages/vtk/src/bbvtkRescaleSlopeIntercept.h | 3 +- .../vtk/src/bbvtkSegmentationConnectivity.cxx | 51 ++++++++++++++++--- .../vtk/src/bbvtkSegmentationConnectivity.h | 25 +++++---- 7 files changed, 101 insertions(+), 35 deletions(-) diff --git a/packages/vtk/src/bbtkSimpleUtilities.h b/packages/vtk/src/bbtkSimpleUtilities.h index 874c35c..067af42 100755 --- a/packages/vtk/src/bbtkSimpleUtilities.h +++ b/packages/vtk/src/bbtkSimpleUtilities.h @@ -366,4 +366,4 @@ class sorts } -#endif /* _DLL_H_ */ +#endif // _BBTKSIMPLEUTILITIES_H_ diff --git a/packages/vtk/src/bbtkStaticLecture.cxx b/packages/vtk/src/bbtkStaticLecture.cxx index e166919..fc1f9af 100755 --- a/packages/vtk/src/bbtkStaticLecture.cxx +++ b/packages/vtk/src/bbtkStaticLecture.cxx @@ -27,6 +27,39 @@ #include "bbtkStaticLecture.h" +#include + +int bbtkStaticLecture::GetTypeFormat( std::string formatStr , vtkImageData* image ) +{ + int outputformat = VTK_UNSIGNED_CHAR; + if (formatStr=="SAME") + { + if (image!=NULL) outputformat = image->GetScalarType(); + } + else if (formatStr=="VTK_BIT") outputformat = VTK_BIT; // 1 + else if (formatStr=="VTK_CHAR") outputformat = VTK_CHAR; // 2 + else if (formatStr=="VTK_SIGNED_CHAR") outputformat = VTK_SIGNED_CHAR; // 15 + else if (formatStr=="VTK_UNSIGNED_CHAR") outputformat = VTK_UNSIGNED_CHAR; // 3 + else if (formatStr=="VTK_SHORT") outputformat = VTK_SHORT; // 4 + else if (formatStr=="VTK_UNSIGNED_SHORT") outputformat = VTK_UNSIGNED_SHORT; // 5 + else if (formatStr=="VTK_INT") outputformat = VTK_INT; // 6 + else if (formatStr=="VTK_UNSIGNED_INT") outputformat = VTK_UNSIGNED_INT; // 7 + else if (formatStr=="VTK_LONG") outputformat = VTK_LONG; // 8 + else if (formatStr=="VTK_UNSIGNED_LONG") outputformat = VTK_UNSIGNED_LONG; // 9 + else if (formatStr=="VTK_FLOAT") outputformat = VTK_FLOAT; // 10 + else if (formatStr=="VTK_DOUBLE") outputformat = VTK_DOUBLE; // 11 + else if (formatStr=="MET_CHAR") outputformat = VTK_CHAR; // 2 + else if (formatStr=="MET_UCHAR") outputformat = VTK_UNSIGNED_CHAR; // 3 + else if (formatStr=="MET_SHORT") outputformat = VTK_SHORT; // 4 + else if (formatStr=="MET_USHORT") outputformat = VTK_UNSIGNED_SHORT; // 5 + else if (formatStr=="MET_SHORT") outputformat = VTK_SHORT; // 4 + else if (formatStr=="MET_FLOAT") outputformat = VTK_FLOAT; // 10 + else if (formatStr=="MET_DOUBLE") outputformat = VTK_DOUBLE; // 11 + + return outputformat; +} + + void bbtkStaticLecture::setPixelValue(int i, int j, int k, vtkImageData* img, double value) { diff --git a/packages/vtk/src/bbtkStaticLecture.h b/packages/vtk/src/bbtkStaticLecture.h index 9b214e7..35b0624 100755 --- a/packages/vtk/src/bbtkStaticLecture.h +++ b/packages/vtk/src/bbtkStaticLecture.h @@ -34,8 +34,9 @@ class bbtkStaticLecture { public: - void setPixelValue(int i, int j, int k, vtkImageData* img, double value); - double getPixelValue(int i, int j, int k, vtkImageData* img); + static int GetTypeFormat( std::string formatStr , vtkImageData* image ); + void setPixelValue(int i, int j, int k, vtkImageData* img, double value); + double getPixelValue(int i, int j, int k, vtkImageData* img); }; #endif diff --git a/packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx b/packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx index dc4e0af..117b979 100644 --- a/packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx +++ b/packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx @@ -31,6 +31,7 @@ #include "bbvtkRescaleSlopeIntercept.h" #include "bbvtkPackage.h" +#include "bbtkStaticLecture.h" namespace bbvtk { @@ -65,19 +66,9 @@ void RescaleSlopeIntercept::Process() if (bbGetInputIn()!=0) { - if (bbGetInputOutputFormat()=="SAME") outputformat = bbGetInputIn()->GetScalarType(); - else if (bbGetInputOutputFormat()=="VTK_BIT") outputformat = VTK_BIT; // 1 - else if (bbGetInputOutputFormat()=="VTK_CHAR") outputformat = VTK_CHAR; // 2 - else if (bbGetInputOutputFormat()=="VTK_SIGNED_CHAR") outputformat = VTK_SIGNED_CHAR; // 15 - else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_CHAR") outputformat = VTK_UNSIGNED_CHAR; // 3 - else if (bbGetInputOutputFormat()=="VTK_SHORT") outputformat = VTK_SHORT; // 4 - else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_SHORT") outputformat = VTK_UNSIGNED_SHORT; // 5 - else if (bbGetInputOutputFormat()=="VTK_INT") outputformat = VTK_INT; // 6 - else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_INT") outputformat = VTK_UNSIGNED_INT; // 7 - else if (bbGetInputOutputFormat()=="VTK_LONG") outputformat = VTK_LONG; // 8 - else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_LONG") outputformat = VTK_UNSIGNED_LONG; // 9 - else if (bbGetInputOutputFormat()=="VTK_FLOAT") outputformat = VTK_FLOAT; // 10 - else if (bbGetInputOutputFormat()=="VTK_DOUBLE") outputformat = VTK_DOUBLE; // 11 + + + int outputformat = bbtkStaticLecture::GetTypeFormat( bbGetInputOutputFormat() , bbGetInputIn() ); bbGetInputIn()->GetScalarRange(range); diff --git a/packages/vtk/src/bbvtkRescaleSlopeIntercept.h b/packages/vtk/src/bbvtkRescaleSlopeIntercept.h index 77ef177..10d67b9 100644 --- a/packages/vtk/src/bbvtkRescaleSlopeIntercept.h +++ b/packages/vtk/src/bbvtkRescaleSlopeIntercept.h @@ -59,8 +59,7 @@ class bbvtk_EXPORT RescaleSlopeIntercept BBTK_DECLARE_OUTPUT(Out,vtkImageData*); BBTK_PROCESS(Process); void Process(); - - int outputformat; + vtkImageShiftScale *filter1; vtkImageShiftScale *filter2; vtkImageChangeInformation *mchange; diff --git a/packages/vtk/src/bbvtkSegmentationConnectivity.cxx b/packages/vtk/src/bbvtkSegmentationConnectivity.cxx index 679e070..218c9db 100644 --- a/packages/vtk/src/bbvtkSegmentationConnectivity.cxx +++ b/packages/vtk/src/bbvtkSegmentationConnectivity.cxx @@ -43,6 +43,8 @@ #include "bbvtkSegmentationConnectivity.h" #include "bbvtkPackage.h" +#include "bbtkStaticLecture.h" + namespace bbvtk { BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SegmentationConnectivity); @@ -54,7 +56,7 @@ namespace bbvtk void SegmentationConnectivity::bbUserSetDefaultValues() { thresh2 = NULL; - cast2 = NULL; +// cast2 = NULL; connect2 = NULL; cast4 = NULL; @@ -69,12 +71,32 @@ namespace bbvtk threshold.push_back(0); bbSetInputThresholdMinMax(threshold); bbSetOutputOut(NULL); + + bbSetInputOutputFormat("SAME"); + bbSetInputValue(255); + + } // -------------------------------------------------------------- void SegmentationConnectivity::bbUserInitializeProcessing() { + + thresh2 = vtkImageThreshold::New(); + thresh2->SetInValue(255); + thresh2->SetOutputScalarTypeToUnsignedChar(); + connect2 = vtkImageSeedConnectivity::New(); + connect2->SetInput(thresh2->GetOutput()); + connect2->SetInputConnectValue(255); + connect2->SetOutputConnectedValue( 255 ); + connect2->SetOutputUnconnectedValue(0); + cast4 = vtkImageCast::New(); + cast4->SetInput(connect2->GetOutput()); + +// EED 2016 06 15 + +/* thresh2 = vtkImageThreshold::New(); thresh2->SetInValue(255); thresh2->SetOutputScalarTypeToUnsignedShort(); @@ -90,6 +112,8 @@ namespace bbvtk cast4 = vtkImageCast::New(); cast4->SetInput(connect2->GetOutput()); cast4->SetOutputScalarTypeToUnsignedShort(); +*/ + } // -------------------------------------------------------------- @@ -101,11 +125,11 @@ namespace bbvtk thresh2->Delete(); thresh2=NULL; } - if (cast2!=NULL) - { - cast2->Delete(); - cast2=NULL; - } +// if (cast2!=NULL) +// { +// cast2->Delete(); +// cast2=NULL; +// } if (connect2!=NULL) { connect2->Delete(); @@ -118,10 +142,17 @@ namespace bbvtk } } + + + // -------------------------------------------------------------- void SegmentationConnectivity::DoProcess() { + int outputformat = bbtkStaticLecture::GetTypeFormat( bbGetInputOutputFormat() , bbGetInputIn() ); + + + vtkImageData *imagedata = bbGetInputIn(); imagedata->UpdateInformation(); imagedata->SetUpdateExtent(imagedata->GetWholeExtent()); @@ -131,8 +162,9 @@ namespace bbvtk thresh2->ThresholdBetween(bbGetInputThresholdMinMax()[0], bbGetInputThresholdMinMax()[1]); thresh2->Modified(); thresh2->Update(); - cast2->Modified(); - cast2->Update(); +// EED 2016 06 15 +// cast2->Modified(); +// cast2->Update(); connect2->RemoveAllSeeds (); int x = bbGetInputPositionXYZ()[0]; @@ -153,6 +185,9 @@ namespace bbvtk if ( z>=maxz ) { printf("Warnnig bbtk::vtk::SegmentationConnectivity::DoProcess limites of the image out of range z: %d -> %d \n",y, maxz-1 ); z=maxz-1; } connect2->AddSeed( x,y,z ); + connect2->SetOutputConnectedValue( bbGetInputValue() ); + cast4->SetOutputScalarType( outputformat ); + connect2->Modified(); connect2->Update(); cast4->Update(); diff --git a/packages/vtk/src/bbvtkSegmentationConnectivity.h b/packages/vtk/src/bbvtkSegmentationConnectivity.h index 57399af..bd4b479 100644 --- a/packages/vtk/src/bbvtkSegmentationConnectivity.h +++ b/packages/vtk/src/bbvtkSegmentationConnectivity.h @@ -71,6 +71,8 @@ namespace bbvtk BBTK_DECLARE_INPUT(In,vtkImageData *); BBTK_DECLARE_INPUT(PositionXYZ,std::vector); BBTK_DECLARE_INPUT(ThresholdMinMax,std::vector); + BBTK_DECLARE_INPUT(Value,unsigned char); + BBTK_DECLARE_INPUT( OutputFormat , std::string ); BBTK_DECLARE_OUTPUT(Out,vtkImageData *); BBTK_PROCESS(DoProcess); void DoProcess(); @@ -78,7 +80,7 @@ namespace bbvtk protected: private: - vtkImageCast *cast2; +// vtkImageCast *cast2; vtkImageCast *cast4; // binary segmentation result vtkImageThreshold *thresh2; vtkImageSeedConnectivity *connect2; @@ -86,14 +88,19 @@ namespace bbvtk }; BBTK_BEGIN_DESCRIBE_BLACK_BOX(SegmentationConnectivity,bbtk::AtomicBlackBox); - BBTK_NAME("SegmentationConnectivity"); - BBTK_AUTHOR("eduardo.davila [at] creatis.insa-lyon.fr"); - BBTK_DESCRIPTION("Segmentation with min max threshold and connectivity"); - BBTK_INPUT(SegmentationConnectivity,In,"Input image",vtkImageData *,""); - BBTK_INPUT(SegmentationConnectivity,PositionXYZ,"vector with the Position [x y z]" , std::vector,""); - BBTK_INPUT(SegmentationConnectivity,ThresholdMinMax,"vector with the Threshold [min max]" , std::vector,""); - BBTK_OUTPUT(SegmentationConnectivity,Out,"Result image",vtkImageData *,""); - BBTK_END_DESCRIBE_BLACK_BOX(SegmentationConnectivity); + BBTK_NAME("SegmentationConnectivity"); + BBTK_AUTHOR("eduardo.davila [at] creatis.insa-lyon.fr"); + BBTK_DESCRIPTION("Segmentation with min max threshold and connectivity"); + + BBTK_INPUT(SegmentationConnectivity,In,"Input image",vtkImageData *,""); + BBTK_INPUT(SegmentationConnectivity,PositionXYZ,"vector with the Position [x y z]" , std::vector,""); + BBTK_INPUT(SegmentationConnectivity,ThresholdMinMax,"vector with the Threshold [min max]" , std::vector,""); + BBTK_INPUT(SegmentationConnectivity,Value,"(255 default) [0..255] Gey level of output image" , unsigned char,""); + BBTK_INPUT(SegmentationConnectivity,OutputFormat,"Image output format: SAME (default), VTK_BIT, VTK_CHAR, VTK_SIGNED_CHAR, VTK_UNSIGNED_CHAR, VTK_SHORT, VTK_UNSIGNED_SHORT, VTK_INT, VTK_UNSIGNED_INT, VTK_LONG, VTK_UNSIGNED_LONG, VTK_FLOAT, VTK_DOUBLE",std::string,""); + + BBTK_OUTPUT(SegmentationConnectivity,Out,"Result image",vtkImageData *,""); + + BBTK_END_DESCRIBE_BLACK_BOX(SegmentationConnectivity); } // EO namespace bbvtk -- 2.44.0