From f42abb6e844c616090c52099c000ff4ed8062b25 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Tue, 27 Dec 2022 16:46:56 +0100 Subject: [PATCH] #3498 Connectivity Filter Threshold --- .../src/bbcreaVtkImageConnectivityFilter.cxx | 46 ++++++++-- .../src/bbcreaVtkImageConnectivityFilter.h | 8 +- .../bbcreaVtkImageThresholdConnectivity.cxx | 90 +++++++++++++++---- .../src/bbcreaVtkImageThresholdConnectivity.h | 12 +++ 4 files changed, 130 insertions(+), 26 deletions(-) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.cxx index 2f5c9e9..d9c051c 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.cxx @@ -4,6 +4,10 @@ #include "bbcreaVtkImageConnectivityFilter.h" #include "bbcreaVtkPackage.h" +#include +#include +#include + namespace bbcreaVtk { @@ -26,12 +30,12 @@ void ImageConnectivityFilter::Process() // (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){ + + if (bbGetInputIn()!=NULL) + { if (imgConnfilter) {imgConnfilter->Delete();} imgConnfilter=vtkImageConnectivityFilter::New(); - imgConnfilter->SetInputData( bbGetInputIn() ); + imgConnfilter->SetInputData( bbGetInputIn() ); if (bbGetInputExtractionMode()==0) // LargestRegion { imgConnfilter->SetExtractionModeToLargestRegion(); @@ -41,21 +45,47 @@ void ImageConnectivityFilter::Process() { printf("EED Warning!!!! ImageConnectivityFilter - AllRegions Not Implemented\n "); } // ExtractionMode - if (bbGetInputExtractionMode()==2) // SeededRegions + if (bbGetInputExtractionMode()==2) // SeedRegions { - printf("EED Warning!!!! ImageConnectivityFilter - SeededRegions Not Implemented\n "); + std::vector lstX = bbGetInputLstX(); + std::vector lstY = bbGetInputLstY(); + std::vector lstZ = bbGetInputLstZ(); + int size = lstX.size(); + if ( (lstX.size()>0) && (lstX.size()==lstY.size()) && (lstX.size()==lstZ.size()) ) + { + int i; + double p[3]; + vtkPoints *points = vtkPoints::New(); + for (i=0; iInsertNextPoint(p); + } // for i + vtkPolyData *seedData = vtkPolyData::New(); + seedData->SetPoints( points ); +// vtkUnsignedCharArray *seedScalars = vtkUnsignedCharArray::New(); +// seedScalars->InsertNextValue(100); +// seedData->GetPointData()->SetScalars(seedScalars); + seedData->GetPointData()->SetScalars(nullptr); + + imgConnfilter->SetExtractionModeToSeededRegions(); + imgConnfilter->SetSeedData( seedData ); +// imgConnfilter->SetSizeRange(0, 99); + } // if lst + } // ExtractionMode if (bbGetInputScalarRange().size()==2) { imgConnfilter->SetScalarRange( bbGetInputScalarRange()[0], bbGetInputScalarRange()[1] ); } // Range - imgConnfilter->Update(); + imgConnfilter->Update( ); bbSetOutputOut( imgConnfilter->GetOutput() ); } else { printf("EED Warning!!!! ImageConnectivityFilter - Input image not defined.\n "); }// In - } //===== // 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) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.h b/bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.h index bec7295..2abf399 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.h @@ -25,6 +25,9 @@ class bbcreaVtk_EXPORT ImageConnectivityFilter BBTK_DECLARE_INPUT(In,vtkImageData*); BBTK_DECLARE_INPUT(ExtractionMode,int); BBTK_DECLARE_INPUT(ScalarRange,std::vector< double >); + BBTK_DECLARE_INPUT(LstX,std::vector< double >); + BBTK_DECLARE_INPUT(LstY,std::vector< double >); + BBTK_DECLARE_INPUT(LstZ,std::vector< double >); BBTK_DECLARE_OUTPUT(Out,vtkImageData*); BBTK_PROCESS(Process); @@ -43,8 +46,11 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(ImageConnectivityFilter,bbtk::AtomicBlackBox); BBTK_CATEGORY("empty"); BBTK_INPUT(ImageConnectivityFilter,In,"Input image",vtkImageData*,""); - BBTK_INPUT(ImageConnectivityFilter,ExtractionMode,"(default 0) 0=LargestRegion 1=AllRegions 2=SeededRegions",int,""); + BBTK_INPUT(ImageConnectivityFilter,ExtractionMode,"(default 0) 0=LargestRegion, 1=AllRegions, 2=SeededRegions use LstX LstY LstZ,",int,""); BBTK_INPUT(ImageConnectivityFilter,ScalarRange,"threshold [Min Max]",std::vector< double >,""); + BBTK_INPUT(ImageConnectivityFilter,LstX,"list X",std::vector< double >,""); + BBTK_INPUT(ImageConnectivityFilter,LstY,"list Y",std::vector< double >,""); + BBTK_INPUT(ImageConnectivityFilter,LstZ,"list Z",std::vector< double >,""); BBTK_OUTPUT(ImageConnectivityFilter,Out,"Output image",vtkImageData*,""); diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkImageThresholdConnectivity.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkImageThresholdConnectivity.cxx index 7136643..a7ddb49 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkImageThresholdConnectivity.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkImageThresholdConnectivity.cxx @@ -3,6 +3,9 @@ //===== #include "bbcreaVtkImageThresholdConnectivity.h" #include "bbcreaVtkPackage.h" +#include "vtkImageThresholdConnectivity.h" +#include "vtkPoints.h" + namespace bbcreaVtk { @@ -13,7 +16,6 @@ BBTK_BLACK_BOX_IMPLEMENTATION(ImageThresholdConnectivity,bbtk::AtomicBlackBox); //===== void ImageThresholdConnectivity::Process() { - // THE MAIN PROCESSING METHOD BODY // Here we simply set the input 'In' value to the output 'Out' // And print out the output value @@ -26,49 +28,103 @@ void ImageThresholdConnectivity::Process() // * TYPE is the C++ type of the input/output // (the one provided in the attribute 'type' of the tag 'input') - - printf("EED ImageThresholdConnectivity::Process Error this box is not implemented .... \n"); - printf("EED ImageThresholdConnectivity::Process Error this box is not implemented .... \n"); - printf("EED ImageThresholdConnectivity::Process Error this box is not implemented .... \n"); - printf("EED ImageThresholdConnectivity::Process Error this box is not implemented .... \n"); + std::vector lstX; + std::vector lstY; + std::vector lstZ; + std::vector point = bbGetInputPoint(); + + if (bbGetInputPoint().size()==3) + { + lstX.push_back( point[0] ); + lstY.push_back( point[1] ); + lstZ.push_back( point[2] ); + } else { + lstX = bbGetInputLstX(); + lstY = bbGetInputLstY(); + lstZ = bbGetInputLstZ(); + } + + if ( (bbGetInputIn()!=NULL) && (lstX.size()>0) && (lstX.size()==lstY.size()) && (lstX.size()==lstZ.size()) ) + { + vtkImageThresholdConnectivity *filter = vtkImageThresholdConnectivity::New(); + double spc[3]; + bbGetInputIn()->GetSpacing(spc); + int border = bbGetInputBorder(); + int minX = 32000; + int minY = 32000; + int minZ = 32000; + int maxX = -32000; + int maxY = -32000; + int maxZ = -32000; + int i,size = lstX.size(); + double p[3]; + vtkPoints *points = vtkPoints::New(); + for (i=0; iInsertNextPoint(p); + if ( lstX[i] < minX ) { minX = lstX[i]; } + if ( lstY[i] < minY ) { minY = lstY[i]; } + if ( lstZ[i] < minZ ) { minZ = lstZ[i]; } + if ( lstX[i] > maxX ) { maxX = lstX[i]; } + if ( lstY[i] > maxY ) { maxY = lstY[i]; } + if ( lstZ[i] > maxZ ) { maxZ = lstZ[i]; } + } // for i + filter->SetSeedPoints( points ); + filter->SetInputData( bbGetInputIn() ); + filter->ThresholdBetween(10, 100); + // filter->SetNeighborhoodRadius (4, 4, 4 ); + filter->SetInValue(255); + filter->SetOutValue(0); + // filter->ReplaceInOn(); + // filter->ReplaceOutOn(); + filter->SetSliceRangeX(minX-border,maxX+border); + filter->SetSliceRangeY(minY-border,maxY+border); + filter->SetSliceRangeZ(minZ-border,maxZ+border); + filter->Update(); + bbSetOutputOut( filter->GetOutput() ); + } // if lst } //===== // 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 ImageThresholdConnectivity::bbUserSetDefaultValues() { - // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX // Here we initialize the input 'In' to 0 - bbSetInputIn(NULL); - + bbSetInputIn(NULL); + bbSetInputBorder(10); + std::vector maskValue; + maskValue.push_back(0); + maskValue.push_back(255); + bbSetInputMaskValue(maskValue); + } + //===== // 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 ImageThresholdConnectivity::bbUserInitializeProcessing() { - // THE INITIALIZATION METHOD BODY : // Here does nothing // but this is where you should allocate the internal/output pointers -// if any - - +// 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 ImageThresholdConnectivity::bbUserFinalizeProcessing() { - // THE FINALIZATION METHOD BODY : // Here does nothing // but this is where you should desallocate the internal/output pointers // if any - -} } -// EO namespace bbcreaVtk + +}// EO namespace bbcreaVtk diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkImageThresholdConnectivity.h b/bbtk_creaVtk_PKG/src/bbcreaVtkImageThresholdConnectivity.h index a629e1c..ec9bcfa 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkImageThresholdConnectivity.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkImageThresholdConnectivity.h @@ -23,6 +23,12 @@ class bbcreaVtk_EXPORT ImageThresholdConnectivity // 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(Point,std::vector); + BBTK_DECLARE_INPUT(LstX,std::vector); + BBTK_DECLARE_INPUT(LstY,std::vector); + BBTK_DECLARE_INPUT(LstZ,std::vector); + BBTK_DECLARE_INPUT(MaskValue,std::vector); + BBTK_DECLARE_INPUT(Border,int); BBTK_DECLARE_OUTPUT(Out,vtkImageData*); BBTK_PROCESS(Process); void Process(); @@ -38,6 +44,12 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(ImageThresholdConnectivity,bbtk::AtomicBlackBox); BBTK_CATEGORY("empty"); BBTK_INPUT(ImageThresholdConnectivity,In,"Input image",vtkImageData*,""); + BBTK_INPUT(ImageThresholdConnectivity,Point,"[x y z] seed point",std::vector,""); + BBTK_INPUT(ImageThresholdConnectivity,LstX,"LstX seeds in voxels",std::vector,""); + BBTK_INPUT(ImageThresholdConnectivity,LstY,"LstY seeds in voxels",std::vector,""); + BBTK_INPUT(ImageThresholdConnectivity,LstZ,"LstZ seeds in voxels",std::vector,""); + BBTK_INPUT(ImageThresholdConnectivity,MaskValue,"( default [O 255] ) [Out In] values of the output mask",std::vector,""); + BBTK_INPUT(ImageThresholdConnectivity,Border,"(default 10)Border of the min and max positions",int,""); BBTK_OUTPUT(ImageThresholdConnectivity,Out,"Output image",vtkImageData*,""); -- 2.47.1