From 5fa7a5c1b2be4ffe803bf21f8545e46ad773ff6d Mon Sep 17 00:00:00 2001 From: "eduardo.davila@creatis.insa-lyon.fr" Date: Fri, 12 Jun 2026 15:29:59 +0200 Subject: [PATCH] #3539 ImageSlabFilter box --- .../bbs/appli/exampleImageSlabFilter.bbg | 117 ++++++++++++++++ .../bbs/appli/exampleImageSlabFilter.bbs | 72 ++++++++++ .../src/bbcreaVtkImageAccumulate.h | 4 +- bbtk_creaVtk_PKG/src/bbcreaVtkImageSlab.cxx | 33 ++--- .../src/bbcreaVtkImageSlabFilter.cxx | 126 ++++++++++++++++++ .../src/bbcreaVtkImageSlabFilter.h | 53 ++++++++ 6 files changed, 380 insertions(+), 25 deletions(-) create mode 100644 bbtk_creaVtk_PKG/bbs/appli/exampleImageSlabFilter.bbg create mode 100644 bbtk_creaVtk_PKG/bbs/appli/exampleImageSlabFilter.bbs create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkImageSlabFilter.cxx create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkImageSlabFilter.h diff --git a/bbtk_creaVtk_PKG/bbs/appli/exampleImageSlabFilter.bbg b/bbtk_creaVtk_PKG/bbs/appli/exampleImageSlabFilter.bbg new file mode 100644 index 0000000..6db4692 --- /dev/null +++ b/bbtk_creaVtk_PKG/bbs/appli/exampleImageSlabFilter.bbg @@ -0,0 +1,117 @@ +# ---------------------------------- +# - BBTKGEditor v 1.6 BBG BlackBox Diagram file +# - /Users/davila/Creatis/C24/creatools_source/creaVtk/bbtk_creaVtk_PKG/bbs/appli/exampleImageSlabFilter.bbg +# ---------------------------------- + +APP_START +CATEGORY: +DESCRIPTION:Description ?? +AUTHOR:Author ?? +EXPORTFORMAT:0 +COMPLEXBOX:FALSE +COMPLEXINPUTS:0 +BOXES:8 +BOX +vtk:LoadHola:Box00 +ISEXEC:FALSE +-13.385127:34.077248:-900.000000 +8.164873:31.577248:-900.000000 +FIN_BOX +BOX +creaVtk:ImageSlabFilter:Box01 +ISEXEC:FALSE +4.760729:5.017080:-900.000000 +26.885729:2.517080:-900.000000 +PORT +Size:"5" +PORT +Type:"3" +FIN_BOX +BOX +wx:LayoutLine:Box02 +ISEXEC:FALSE +-22.836297:-21.138336:-900.000000 +12.243703:-23.638336:-900.000000 +PORT +Orientation:"H" +FIN_BOX +BOX +creaMaracasVisu:ViewerNV:Box03 +ISEXEC:FALSE +-43.199653:-2.361547:-900.000000 +0.680347:-4.861547:-900.000000 +PORT +nTypeView:"6 1 2 0" +FIN_BOX +BOX +creaMaracasVisu:ViewerNV:Box04 +ISEXEC:FALSE +19.294175:-10.455184:-900.000000 +63.174175:-12.955184:-900.000000 +PORT +nTypeView:"6 1 2 0" +FIN_BOX +BOX +wx:LayoutSplit:Box05 +ISEXEC:TRUE +-0.843323:-38.207923:-900.000000 +23.676677:-40.707923:-900.000000 +PORT +Orientation:"H" +FIN_BOX +BOX +wx:LayoutLine:Box06 +ISEXEC:FALSE +24.851805:-20.430932:-900.000000 +59.931805:-22.930932:-900.000000 +FIN_BOX +BOX +wx:Slider:Box07 +ISEXEC:FALSE +27.335926:24.671393:-900.000000 +58.895926:22.171393:-900.000000 +PORT +In:"2" +PORT +Label:"true" +PORT +Max:"20" +PORT +Min:"0" +PORT +ReactiveOnTrack:"true" +PORT +Title:"Mip size" +FIN_BOX +CONNECTIONS:10 +CONNECTION +Box00:Out:Box01:In +NumberOfControlPoints:0 +CONNECTION +Box03:Widget:Box02:Widget2 +NumberOfControlPoints:0 +CONNECTION +Box04:Widget:Box02:Widget4 +NumberOfControlPoints:0 +CONNECTION +Box00:Out:Box03:In +NumberOfControlPoints:0 +CONNECTION +Box01:Out:Box04:In +NumberOfControlPoints:0 +CONNECTION +Box02:Widget:Box05:Widget1 +NumberOfControlPoints:0 +CONNECTION +Box06:Widget:Box05:Widget2 +NumberOfControlPoints:0 +CONNECTION +Box07:Widget:Box06:Widget3 +NumberOfControlPoints:0 +CONNECTION +Box07:Out:Box01:Size +NumberOfControlPoints:0 +CONNECTION +Box07:BoxChange:Box04:BoxExecute +NumberOfControlPoints:0 +APP_END diff --git a/bbtk_creaVtk_PKG/bbs/appli/exampleImageSlabFilter.bbs b/bbtk_creaVtk_PKG/bbs/appli/exampleImageSlabFilter.bbs new file mode 100644 index 0000000..e967ad9 --- /dev/null +++ b/bbtk_creaVtk_PKG/bbs/appli/exampleImageSlabFilter.bbs @@ -0,0 +1,72 @@ +# ---------------------------------- +# - BBTKGEditor v 1.6 BBS BlackBox Script +# - /Users/davila/Creatis/C24/creatools_source/creaVtk/bbtk_creaVtk_PKG/bbs/appli/exampleImageSlabFilter.bbs +# ---------------------------------- + +# BBTK GEditor Script +# ---------------------- + +include std +include itkvtk +include vtk +include creaVtk +include wx +include creaMaracasVisu + +author "Author ??" +description "Description ??" +category "" + +new vtk:LoadHola Box00 + +new creaVtk:ImageSlabFilter Box01 + set Box01.Size "5" + set Box01.Type "3" + +new wx:LayoutLine Box02 + set Box02.Orientation "H" + +new creaMaracasVisu:ViewerNV Box03 + set Box03.nTypeView "6 1 2 0" + +new creaMaracasVisu:ViewerNV Box04 + set Box04.nTypeView "6 1 2 0" + +new wx:LayoutSplit Box05 + set Box05.Orientation "H" + +new wx:LayoutLine Box06 + +new wx:Slider Box07 + set Box07.In "2" + set Box07.Label "true" + set Box07.Max "20" + set Box07.Min "0" + set Box07.ReactiveOnTrack "true" + set Box07.Title "Mip size" + + +connect Box00.Out Box01.In + +connect Box03.Widget Box02.Widget2 + +connect Box04.Widget Box02.Widget4 + +connect Box00.Out Box03.In + +connect Box01.Out Box04.In + +connect Box02.Widget Box05.Widget1 + +connect Box06.Widget Box05.Widget2 + +connect Box07.Widget Box06.Widget3 + +connect Box07.Out Box01.Size + +connect Box07.BoxChange Box04.BoxExecute + + + +# Complex input ports +exec Box05 diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkImageAccumulate.h b/bbtk_creaVtk_PKG/src/bbcreaVtkImageAccumulate.h index 48f186f..1ac3d65 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkImageAccumulate.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkImageAccumulate.h @@ -26,9 +26,7 @@ class bbcreaVtk_EXPORT ImageAccumulate BBTK_DECLARE_OUTPUT(VoxelCount,int); BBTK_PROCESS(Process); void Process(); - - vtkImageAccumulate *acc; - + vtkImageAccumulate *acc; //===== // 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/bbcreaVtkImageSlab.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkImageSlab.cxx index 53dbbb4..72af8b0 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkImageSlab.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkImageSlab.cxx @@ -8,12 +8,12 @@ namespace bbcreaVtk BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ImageSlab) BBTK_BLACK_BOX_IMPLEMENTATION(ImageSlab,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 ImageSlab::Process() { - // THE MAIN PROCESSING METHOD BODY // Here we simply set the input 'In' value to the output 'Out' // And print out the output value @@ -25,23 +25,17 @@ void ImageSlab::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') - -// bbSetOutputOut( bbGetInputIn() ); -// std::cout << "Output value = " <SetOperationToMean(); } if (bbGetInputType()==1) { imageSlab->SetOperationToSum(); } if (bbGetInputType()==2) { imageSlab->SetOperationToMin(); } if (bbGetInputType()==3) { imageSlab->SetOperationToMax(); } imageSlab->MultiSliceOutputOff(); imageSlab->SetOutputScalarTypeToInputScalarType(); - //EED 2017-01-01 Migration VTK7 #if VTK_MAJOR_VERSION <= 5 imageSlab->SetInput( bbGetInputIn() ); @@ -50,47 +44,42 @@ void ImageSlab::Process() imageSlab->Update(); #endif bbSetOutputOut( imageSlab->GetOutput() ); - } -//===== + +//===== // 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 ImageSlab::bbUserSetDefaultValues() { - // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX // Here we initialize the input 'In' to 0 - firsttime=true; bbSetInputIn(NULL); bbSetInputType(0); } -//===== + +//===== // 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 ImageSlab::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 ImageSlab::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/bbcreaVtkImageSlabFilter.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkImageSlabFilter.cxx new file mode 100644 index 0000000..31c5a0c --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkImageSlabFilter.cxx @@ -0,0 +1,126 @@ +//===== +// 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 "bbcreaVtkImageSlabFilter.h" +#include "bbcreaVtkPackage.h" + +#include +#include + +namespace bbcreaVtk +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ImageSlabFilter) +BBTK_BLACK_BOX_IMPLEMENTATION(ImageSlabFilter,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 ImageSlabFilter::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) + { + int ext[6]; + bbGetInputIn()->GetExtent(ext); + int dim[3]; + dim[0] = ext[1]-ext[0]+1; + dim[1] = ext[3]-ext[2]+1; + dim[2] = ext[5]-ext[4]+1; + double spc[3]; + bbGetInputIn()->GetSpacing(spc); + + // Create resultImage + vtkImageData *imageoutput = vtkImageData::New(); + imageoutput->Initialize(); + imageoutput->SetSpacing( spc ); + imageoutput->SetDimensions( dim[0], dim[1], dim[2] ); + imageoutput->AllocateScalars( bbGetInputIn()->GetScalarType(),1 ); + imageoutput->Modified(); + + int start,end; + int i,sizeImg=dim[2]; + for (i=0; i=sizeImg){ end=sizeImg-1; } + + // voi + vtkExtractVOI *VOIfilter = vtkExtractVOI::New(); + VOIfilter->SetInputData( bbGetInputIn() ); + VOIfilter->SetVOI(0,dim[0],0,dim[1],start,end); + VOIfilter->Update(); + + // slab + vtkImageSlab *slabFilter = vtkImageSlab::New(); + if (bbGetInputType()==0) { slabFilter->SetOperationToMean(); } + if (bbGetInputType()==1) { slabFilter->SetOperationToSum(); } + if (bbGetInputType()==2) { slabFilter->SetOperationToMin(); } + if (bbGetInputType()==3) { slabFilter->SetOperationToMax(); } + slabFilter->MultiSliceOutputOff(); + slabFilter->SetOutputScalarTypeToInputScalarType(); + slabFilter->SetInputData( VOIfilter->GetOutput() ); + slabFilter->Update(); + vtkImageData *slabImage= slabFilter->GetOutput(); + // replace slice with slap + memcpy( (void*)imageoutput->GetScalarPointer(0,0,i) , (void*)slabImage->GetScalarPointer(0,0,0), dim[0] * dim[1] * imageoutput->GetScalarSize() ); + + // clean memory + VOIfilter->Delete(); + slabFilter->Delete(); + } // for i + bbSetOutputOut( imageoutput ); + } // if In !=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 ImageSlabFilter::bbUserSetDefaultValues() +{ +// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX +// Here we initialize the input 'In' to 0 + bbSetInputIn(NULL); + bbSetInputType(0); + bbSetInputSize(2); +} + +//===== +// 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 ImageSlabFilter::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 ImageSlabFilter::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/bbcreaVtkImageSlabFilter.h b/bbtk_creaVtk_PKG/src/bbcreaVtkImageSlabFilter.h new file mode 100644 index 0000000..6948ce0 --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkImageSlabFilter.h @@ -0,0 +1,53 @@ +//===== +// 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 __bbcreaVtkImageSlabFilter_h_INCLUDED__ +#define __bbcreaVtkImageSlabFilter_h_INCLUDED__ + +#include "bbcreaVtk_EXPORT.h" +#include "bbtkAtomicBlackBox.h" +#include "iostream" + +#include +#include + +namespace bbcreaVtk +{ + +class bbcreaVtk_EXPORT ImageSlabFilter + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(ImageSlabFilter,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(Type,int); + BBTK_DECLARE_INPUT(Size,int); + BBTK_DECLARE_OUTPUT(Out,vtkImageData*); + BBTK_PROCESS(Process); + void Process(); +//===== +// 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(ImageSlabFilter,bbtk::AtomicBlackBox); + BBTK_NAME("ImageSlabFilter"); + BBTK_AUTHOR("Info-Dev"); + BBTK_DESCRIPTION("Each slice is the result of the slab depth"); + BBTK_CATEGORY("empty"); + BBTK_INPUT(ImageSlabFilter,In,"Input image",vtkImageData*,""); + BBTK_INPUT(ImageSlabFilter,Type,"(0 default) 0 Mean, 1 Sum, 2 Min, 3 Max",int,""); + BBTK_INPUT(ImageSlabFilter,Size,"(2 default) depth=2*Size+1",int,""); + BBTK_OUTPUT(ImageSlabFilter,Out,"Output image",vtkImageData*,""); +BBTK_END_DESCRIBE_BLACK_BOX(ImageSlabFilter); +//===== +// 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 // __bbcreaVtkImageSlabFilter_h_INCLUDED__ + -- 2.54.0