From cb583d72f63e28fc654386c4eb02257b62f24ffe Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Fri, 23 Aug 2013 15:11:43 +0200 Subject: [PATCH] 2118 BBTK Feature New High InversCrop --- packages/vtk/src/bbvtkInversCrop.cxx | 151 +++++++++++++++++++++++++++ packages/vtk/src/bbvtkInversCrop.h | 57 ++++++++++ 2 files changed, 208 insertions(+) create mode 100644 packages/vtk/src/bbvtkInversCrop.cxx create mode 100644 packages/vtk/src/bbvtkInversCrop.h diff --git a/packages/vtk/src/bbvtkInversCrop.cxx b/packages/vtk/src/bbvtkInversCrop.cxx new file mode 100644 index 0000000..b56a851 --- /dev/null +++ b/packages/vtk/src/bbvtkInversCrop.cxx @@ -0,0 +1,151 @@ +//===== +// 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 "bbvtkInversCrop.h" +#include "bbvtkPackage.h" +namespace bbvtk +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,InversCrop) +BBTK_BLACK_BOX_IMPLEMENTATION(InversCrop,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 InversCrop::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 ((bbGetInputImageFix()!=NULL) && (bbGetInputImageMove()!=NULL) ) + { + if ( bbGetInputImageFix()->GetScalarType()==bbGetInputImageMove()->GetScalarType() ) + { + // Creating Image + int dim[3]; + int ext[6]; + + bbGetInputImageFix()->GetWholeExtent(ext); + dim[0]= ext[1]-ext[0]+1; + dim[1]= ext[3]-ext[2]+1; + dim[2]= ext[5]-ext[4]+1; + + _imageoutput = vtkImageData::New(); + _imageoutput->Initialize(); + _imageoutput->SetScalarType( bbGetInputImageFix()->GetScalarType() ); + _imageoutput->SetSpacing( bbGetInputImageFix()->GetSpacing() ); + _imageoutput->SetDimensions( dim[0], dim[1], dim[2] ); + _imageoutput->AllocateScalars(); + + // Duplicating Fix Image + long sizeimage = dim[0]*dim[1]*dim[2]*bbGetInputImageFix()->GetScalarSize(); + memcpy( _imageoutput->GetScalarPointer() , bbGetInputImageFix()->GetScalarPointer() , sizeimage); + + // Copy the Move Image + int j,k; + int px,py,pz; + + bbGetInputImageMove()->GetWholeExtent(ext); + int dimMoveX = ext[1]-ext[0]+1; + int dimMoveY = ext[3]-ext[2]+1; + int dimMoveZ = ext[5]-ext[4]+1; + + int spxM=0; // start px MoveImage + int sizeXM=0; // sizeX MoveImage + + px=bbGetInputOrigin()[0]; + spxM=0; + if (px<=0) + { + spxM=px*(-1); + px=0; + } + sizeXM = dimMoveX-spxM; + if (px+sizeXM>=dim[0]) sizeXM=dim[0]-px; + + sizeXM=sizeXM*bbGetInputImageFix()->GetScalarSize(); + for (k=0; k=0) && (pz>=0) && + (sizeXM>0) ) + { + memcpy( _imageoutput->GetScalarPointer(px,py,pz) , bbGetInputImageMove()->GetScalarPointer(spxM,j,k) , sizeXM ); + } + + } // for j + } // for k + _imageoutput->Modified(); + } // If Image Fixe Move the same GetScalarType + else { + printf ("ERROR: InversCrop both ImageFixe and ImageMove need the same format.\n"); + } + } // If Image Fixe Move != NULL + else { + printf ("ERROR: InversCrop need ImageFixe and ImageMove to run.\n"); + } + bbSetOutputOut(_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) +//===== +void InversCrop::bbUserSetDefaultValues() +{ + +// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX +// Here we initialize the input 'In' to 0 + bbSetInputImageFix(NULL); + bbSetInputImageMove(NULL); + + std::vector origin; + origin.push_back(0); + origin.push_back(0); + origin.push_back(0); + bbSetInputOrigin(origin); + + _imageoutput=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 InversCrop::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 InversCrop::bbUserFinalizeProcessing() +{ + +// THE FINALIZATION METHOD BODY : +// Here does nothing +// but this is where you should desallocate the internal/output pointers +// if any + +} +} +// EO namespace bbvtk + + diff --git a/packages/vtk/src/bbvtkInversCrop.h b/packages/vtk/src/bbvtkInversCrop.h new file mode 100644 index 0000000..63fb7ef --- /dev/null +++ b/packages/vtk/src/bbvtkInversCrop.h @@ -0,0 +1,57 @@ +//===== +// 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 __bbvtkInversCrop_h_INCLUDED__ +#define __bbvtkInversCrop_h_INCLUDED__ +#include "bbvtk_EXPORT.h" +#include "bbtkAtomicBlackBox.h" +#include "iostream" + + +#include "vtkImageData.h" + +namespace bbvtk +{ + +class bbvtk_EXPORT InversCrop + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(InversCrop,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(ImageFix,vtkImageData*); + BBTK_DECLARE_INPUT(ImageMove,vtkImageData*); + BBTK_DECLARE_INPUT(Origin,std::vector); + BBTK_DECLARE_OUTPUT(Out,vtkImageData*); + 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(InversCrop,bbtk::AtomicBlackBox); + BBTK_NAME("InversCrop"); + BBTK_AUTHOR("InfoDev"); + BBTK_DESCRIPTION("Invers Crop, Both images had to have the same format"); + BBTK_CATEGORY(""); + + BBTK_INPUT(InversCrop,ImageFix,"Fix Image (necesary). Need same format of ImageMove",vtkImageData*,""); + BBTK_INPUT(InversCrop,ImageMove,"Move Image (necesary). Need same format of ImageFix",vtkImageData*,""); + BBTK_INPUT(InversCrop,Origin,"Position to be put de Move Image (default 0,0,0 )",std::vector,""); + + BBTK_OUTPUT(InversCrop,Out,"First output",vtkImageData*,""); + +BBTK_END_DESCRIBE_BLACK_BOX(InversCrop); +//===== +// 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 bbvtk + +#endif // __bbvtkInversCrop_h_INCLUDED__ + -- 2.45.1