From 2a263de926f8dd60676281d7aeeac501d9d57625 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Mon, 20 Jul 2020 15:23:51 +0200 Subject: [PATCH] #3457 creaVtk Feature New Normal - new box VtkWriteLstImages --- .../src/bbcreaVtkImageExtractComponents.cxx | 4 +- .../src/bbcreaVtkWriteLstImages.cxx | 119 ++++++++++++++++++ .../src/bbcreaVtkWriteLstImages.h | 61 +++++++++ 3 files changed, 181 insertions(+), 3 deletions(-) create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.cxx create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.h diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkImageExtractComponents.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkImageExtractComponents.cxx index 4d274db..e4bd318 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkImageExtractComponents.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkImageExtractComponents.cxx @@ -107,15 +107,13 @@ void ImageExtractComponents::Process() vtkImageExtractComponents* IEC; IEC=vtkImageExtractComponents::New(); IEC->SetInputData( bbGetInputIn() ); - IEC->SetComponents( bbGetInputComponent2() ); + IEC->SetComponents( i ); IEC->Update(); lstIEC.push_back( IEC); lstOut.push_back( IEC->GetOutput() ); - IEC->Delete(); } // for i bbSetOutputLstOut( lstOut ); } // Type 1 - } //===== diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.cxx new file mode 100644 index 0000000..973a7b7 --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.cxx @@ -0,0 +1,119 @@ +//===== +// 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 "bbcreaVtkWriteLstImages.h" +#include "bbcreaVtkPackage.h" + +#include "vtkMetaImageWriter.h" +#include +namespace bbcreaVtk +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,WriteLstImages) +BBTK_BLACK_BOX_IMPLEMENTATION(WriteLstImages,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 WriteLstImages::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') +// bbSetOutputOut( bbGetInputIn() ); +// std::cout << "Output value = " <SetInputData( inImg ); + w->SetCompression( bbGetInputCompression() ); + w->SetFileDimensionality(inImg->GetDataDimension()); // NTU + std::string filename = bbGetInputOutputDir()+"/"+bbGetInputFileName()+"-"+txtNum+".mhd"; + w->SetFileName(filename.c_str()); + w->Write(); + w->Delete(); + } // Type + + if (bbGetInputType()==1) // NIFTI + { + vtkNIFTIImageWriter* w = vtkNIFTIImageWriter::New(); + w->SetInputData( inImg ); + std::string filename = bbGetInputOutputDir()+"/"+bbGetInputFileName()+"-"+txtNum+".nii"; + w->SetFileName(filename.c_str()); + w->Write(); + w->Delete(); + } // Type + + + + } // for i +printf("EED WriteLstImages::Process END\n"); + +} +//===== +// 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 WriteLstImages::bbUserSetDefaultValues() +{ + +// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX +// Here we initialize the input 'In' to 0 + bbSetInputType(0); + bbSetInputCompression(false); + bbSetInputFileName("void"); + bbSetInputOutputDir("."); +} +//===== +// 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 WriteLstImages::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 WriteLstImages::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/bbcreaVtkWriteLstImages.h b/bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.h new file mode 100644 index 0000000..412b32f --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.h @@ -0,0 +1,61 @@ +//===== +// 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 __bbcreaVtkWriteLstImages_h_INCLUDED__ +#define __bbcreaVtkWriteLstImages_h_INCLUDED__ + +#include "bbcreaVtk_EXPORT.h" +#include "bbtkAtomicBlackBox.h" +#include "iostream" + +#include +#include "vtkImageData.h" + + +namespace bbcreaVtk +{ + +class bbcreaVtk_EXPORT WriteLstImages + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(WriteLstImages,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(Type,int); + BBTK_DECLARE_INPUT(OutputDir,std::string); + BBTK_DECLARE_INPUT(LstImages,std::vector< vtkImageData* >); + BBTK_DECLARE_INPUT(FileName,std::string); + BBTK_DECLARE_INPUT(Compression,bool); +// BBTK_DECLARE_OUTPUT(Out,double); + 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(WriteLstImages,bbtk::AtomicBlackBox); + BBTK_NAME("WriteLstImages"); + BBTK_AUTHOR("InfoDev"); + BBTK_DESCRIPTION("No Description."); + BBTK_CATEGORY("empty"); + + BBTK_INPUT(WriteLstImages,Type,"(default 0) 0:mhd 1:nii",int,""); + BBTK_INPUT(WriteLstImages,OutputDir,"Output directory",std::string,""); + BBTK_INPUT(WriteLstImages,LstImages,"Lst of images",std::vector< vtkImageData* >,""); + BBTK_INPUT(WriteLstImages,FileName,"File name (no extension)",std::string,""); + BBTK_INPUT(WriteLstImages,Compression,"(Default false) true/false just for mhd",bool,""); + +// BBTK_OUTPUT(WriteLstImages,Out,"First output",double,""); + +BBTK_END_DESCRIBE_BLACK_BOX(WriteLstImages); +//===== +// 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 // __bbcreaVtkWriteLstImages_h_INCLUDED__ + -- 2.45.1