From 9cdfabc67eb004e921e7adbe98a56f30e3a3326d Mon Sep 17 00:00:00 2001 From: dsarrut Date: Wed, 7 Jul 2010 13:39:37 +0000 Subject: [PATCH] extract a slice from a 3D image --- itk/clitkExtractSliceFilter.h | 118 ++++++++++++++++++++++++++++++++ itk/clitkExtractSliceFilter.txx | 106 ++++++++++++++++++++++++++++ 2 files changed, 224 insertions(+) create mode 100644 itk/clitkExtractSliceFilter.h create mode 100644 itk/clitkExtractSliceFilter.txx diff --git a/itk/clitkExtractSliceFilter.h b/itk/clitkExtractSliceFilter.h new file mode 100644 index 0000000..93d3cd0 --- /dev/null +++ b/itk/clitkExtractSliceFilter.h @@ -0,0 +1,118 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ======================================================================-====*/ + +#ifndef CLITKEXTRACTSLICEFILTER_H +#define CLITKEXTRACTSLICEFILTER_H + +// clitk +#include "clitkFilterBase.h" + +// itk +#include "itkPasteImageFilter.h" + +// itk ENST +#include "RelativePositionPropImageFilter.h" + +namespace clitk { + + //-------------------------------------------------------------------- + /* + Let A be an initial label image. + Let B be a label image with an object. + Let o be an orientation relatively to the B object (for example RightTo, AntTo, InferiorTo ...) + + This filter removes (=set background) from A all points that are + not in the wanted o orientation. It uses downsampled version for + faster processing, and (try to) take into account discretization + problem. Uses [Bloch 1999]. + */ + //-------------------------------------------------------------------- + + template + class ITK_EXPORT ExtractSliceFilter: + public clitk::FilterBase, + public itk::ImageToImageFilter::Pointer> > + { + + public: + /** Standard class typedefs. */ + typedef itk::ImageToImageFilter Superclass; + typedef ExtractSliceFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(ExtractSliceFilter, ImageToImageFilter); + FILTERBASE_INIT; + + /** Some convenient typedefs. */ + typedef typename ImageType::ConstPointer ImageConstPointer; + typedef typename ImageType::Pointer ImagePointer; + typedef typename ImageType::RegionType RegionType; + typedef typename ImageType::PixelType PixelType; + typedef typename ImageType::SpacingType SpacingType; + typedef typename ImageType::SizeType SizeType; + + /** ImageDimension constants */ + itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension); + + /** Slice image type **/ + typedef itk::Image SliceType; + typedef typename SliceType::Pointer SliceTypePointer; + + /** Input : initial image and object */ + void SetInput(const ImageType * image); + + // Options + itkGetConstMacro(Direction, int); + itkSetMacro(Direction, int); + + protected: + ExtractSliceFilter(); + virtual ~ExtractSliceFilter() {} + + int m_Direction; + + virtual void GenerateOutputInformation(); + virtual void GenerateInputRequestedRegion(); + virtual void GenerateData(); + + ImagePointer input; + ImagePointer object; + std::vector output; + + private: + ExtractSliceFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + }; // end class + //-------------------------------------------------------------------- + +} // end namespace clitk +//-------------------------------------------------------------------- + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkExtractSliceFilter.txx" +#endif + +#endif diff --git a/itk/clitkExtractSliceFilter.txx b/itk/clitkExtractSliceFilter.txx new file mode 100644 index 0000000..40f7982 --- /dev/null +++ b/itk/clitkExtractSliceFilter.txx @@ -0,0 +1,106 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ======================================================================-====*/ + +// clitk +#include "clitkCommon.h" + + +//-------------------------------------------------------------------- +template +clitk::ExtractSliceFilter:: +ExtractSliceFilter(): + clitk::FilterBase(), + itk::ImageToImageFilter() +{ + this->SetNumberOfRequiredInputs(1); + SetDirection(2); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractSliceFilter:: +SetInput(const ImageType * image) { + // Process object is not const-correct so the const casting is required. + this->SetNthInput(0, const_cast(image)); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractSliceFilter:: +GenerateOutputInformation() { + DD("GenerateOutputInformation"); + ImagePointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); + // ImagePointer outputImage = this->GetOutput(0); + // outputImage->SetRegions(input->GetLargestPossibleRegion()); + + output = this->GetOutput(0); + + // create vector + typename SliceType::RegionType SliceRegionType; + typename SliceType::SizeType SliceSizeType; + typename SliceType::IndexType SliceIndexType; + // SliceRegionType region; + + // create region + // loop ExtractImageFilter with region updated, push_back + + +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractSliceFilter:: +GenerateInputRequestedRegion() { + DD("GenerateInputRequestedRegion"); + // Call default + itk::ImageToImageFilter::GenerateInputRequestedRegion(); + // Get input pointers and set requested region to common region + ImagePointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); + input->SetRequestedRegion(input->GetLargestPossibleRegion()); +} +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +template +void +clitk::ExtractSliceFilter:: +GenerateData() { + DD("GenerateData"); + + // Get input pointer + input = dynamic_cast(itk::ProcessObject::GetInput(0)); + + + + //-------------------------------------------------------------------- + //-------------------------------------------------------------------- + // Final Step -> set output + //this->SetNthOutput(0, working_image); + return; +} +//-------------------------------------------------------------------- + -- 2.47.1