From: jef Date: Fri, 23 Jul 2010 14:56:20 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: v1.2.0~480 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=a26cd8a19e1b9ad8344ab501436045f171a73713;p=clitk.git *** empty log message *** --- diff --git a/filters/clitkBinarizeImage.ggo b/filters/clitkBinarizeImage.ggo deleted file mode 100644 index 6f99548..0000000 --- a/filters/clitkBinarizeImage.ggo +++ /dev/null @@ -1,18 +0,0 @@ -#File clitkBinarizeImage.ggo -package "clitkBinarizeImage" -version "1.0" -purpose "" - -option "config" - "Config file" string no -option "verbose" v "Verbose" flag off -option "imagetypes" - "Display allowed image types" flag off - -option "input" i "Input image filename" string yes -option "output" o "Output image filename" string yes -option "lower" l "Lower intensity (default=min), fg is greater than this value" double no -option "upper" u "Upper intensity (default=max), fg is lower than this value" double no - -option "fg" - "Foreground (FG) or 'inside' value" double no default="1" -option "bg" - "Background (BG) or 'ouside' value" double no default="0" -option "mode" - "Use FG and/or BG values (if FG, the BG is replaced by the input image values)" values="FG","BG","both" default="both" required - diff --git a/filters/clitkBinarizeImageGenericFilter.h b/filters/clitkBinarizeImageGenericFilter.h deleted file mode 100644 index 7f6ba4c..0000000 --- a/filters/clitkBinarizeImageGenericFilter.h +++ /dev/null @@ -1,74 +0,0 @@ -/*========================================================================= - 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 CLITKBINARIZEIMAGEGENERICFILTER_H -#define CLITKBINARIZEIMAGEGENERICFILTER_H - -#include "clitkIO.h" -#include "clitkImageToImageGenericFilter.h" - -//-------------------------------------------------------------------- -namespace clitk -{ - - template - class ITK_EXPORT BinarizeImageGenericFilter: - public ImageToImageGenericFilter > - { - - public: - - //-------------------------------------------------------------------- - BinarizeImageGenericFilter(); - - //-------------------------------------------------------------------- - typedef BinarizeImageGenericFilter Self; - typedef itk::SmartPointer Pointer; - typedef itk::SmartPointer ConstPointer; - - //-------------------------------------------------------------------- - // Method for creation through the object factory - // and Run-time type information (and related methods) - itkNewMacro(Self); - itkTypeMacro(BinarizeImageGenericFilter, LightObject); - - //-------------------------------------------------------------------- - void SetArgsInfo(const args_info_type & a); - - //-------------------------------------------------------------------- - // Main function called each time the filter is updated - template - void UpdateWithInputImageType(); - - protected: - template void InitializeImageType(); - args_info_type mArgsInfo; - - }; // end class - //-------------------------------------------------------------------- - -} // end namespace clitk -//-------------------------------------------------------------------- - -//-------------------------------------------------------------------- -#ifndef ITK_MANUAL_INSTANTIATION -#include "clitkBinarizeImageGenericFilter.txx" -#endif -//-------------------------------------------------------------------- - -#endif // #define clitkBinarizeImageGenericFilter_h diff --git a/filters/clitkBinarizeImageGenericFilter.txx b/filters/clitkBinarizeImageGenericFilter.txx deleted file mode 100644 index 61a4277..0000000 --- a/filters/clitkBinarizeImageGenericFilter.txx +++ /dev/null @@ -1,168 +0,0 @@ -/*========================================================================= - 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 CLITKBINARIZEIMAGEGENERICFILTER_TXX -#define CLITKBINARIZEIMAGEGENERICFILTER_TXX - -// itk include -#include "itkBinaryThresholdImageFilter.h" -#include "itkMaskImageFilter.h" -#include "itkMaskNegatedImageFilter.h" - -#include -// #include - -namespace clitk -{ - -//-------------------------------------------------------------------- -template -BinarizeImageGenericFilter::BinarizeImageGenericFilter(): - ImageToImageGenericFilter("Binarize") -{ - InitializeImageType<2>(); - InitializeImageType<3>(); - InitializeImageType<4>(); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -template -void BinarizeImageGenericFilter::InitializeImageType() -{ - ADD_DEFAULT_IMAGE_TYPES(Dim); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -void BinarizeImageGenericFilter::SetArgsInfo(const args_info_type & a) -{ - mArgsInfo=a; - SetIOVerbose(mArgsInfo.verbose_flag); - if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); - - if (mArgsInfo.input_given) { - SetInputFilename(mArgsInfo.input_arg); - } - if (mArgsInfo.output_given) { - SetOutputFilename(mArgsInfo.output_arg); - } -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -// Update with the number of dimensions and the pixeltype -//-------------------------------------------------------------------- -template -template -void -BinarizeImageGenericFilter::UpdateWithInputImageType() -{ - - // Reading input - typename InputImageType::Pointer input = this->template GetInput(0); - - // Main filter - typedef typename InputImageType::PixelType PixelType; - typedef itk::Image OutputImageType; - - // Filter - typedef itk::BinaryThresholdImageFilter BinaryThresholdImageFilterType; - typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New(); - thresholdFilter->SetInput(input); - thresholdFilter->SetInsideValue(mArgsInfo.fg_arg); - - if (mArgsInfo.lower_given) thresholdFilter->SetLowerThreshold(static_cast(mArgsInfo.lower_arg)); - if (mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast(mArgsInfo.upper_arg)); - - // DD(mArgsInfo.lower_given); - // DD(mArgsInfo.upper_given); - // DD(mArgsInfo.lower_arg); - // DD(mArgsInfo.upper_arg); - // DD(mArgsInfo.fg_arg); - // DD(mArgsInfo.bg_arg); - // DD(mArgsInfo.fg_given); - // DD(mArgsInfo.bg_given); - // DD(mArgsInfo.mode_arg); - -// DD(mArgsInfo.useFG_flag); -// DD(mArgsInfo.useBG_flag); - -// thresholdFilter->SetInsideValue(mArgsInfo.fg_arg); - -// // Keep BG value to 0 if maskFilterType is used after -// if (mArgsInfo.useBG_flag && mArgsInfo.useFG_flag) { -// thresholdFilter->SetOutsideValue(mArgsInfo.bg_arg); -// } -// else { -// DD("0"); -// thresholdFilter->SetOutsideValue(0); -// } - -// // thresholdFilter->Update(); - -// // If no BG or no FG : new image, copy input with MaskImageFilter -// // If setFG -> FG BG have been changed -// if (mArgsInfo.useBG_flag && mArgsInfo.useFG_flag) { -// ======= - /* Three modes : - - FG -> only use FG value for pixel in the Foreground (or Inside), keep input values for outside - - BG -> only use BG value for pixel in the Background (or Outside), keep input values for inside - - both -> use FG and BG (real binary image) - */ - if (mArgsInfo.mode_arg == std::string("both")) { - thresholdFilter->SetOutsideValue(mArgsInfo.bg_arg); - thresholdFilter->Update(); - //>>>>>>> 1.5 - typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput(); - this->template SetNextOutput(outputImage); - } else { - typename InputImageType::Pointer outputImage; - thresholdFilter->SetOutsideValue(0); - if (mArgsInfo.mode_arg == std::string("BG")) { - typedef itk::MaskImageFilter maskFilterType; - typename maskFilterType::Pointer maskFilter = maskFilterType::New(); - maskFilter->SetInput1(input); - maskFilter->SetInput2(thresholdFilter->GetOutput()); - maskFilter->SetOutsideValue(mArgsInfo.bg_arg); - maskFilter->Update(); - outputImage = maskFilter->GetOutput(); - } else { - typedef itk::MaskNegatedImageFilter maskFilterType; - typename maskFilterType::Pointer maskFilter = maskFilterType::New(); - maskFilter->SetInput1(input); - maskFilter->SetInput2(thresholdFilter->GetOutput()); - maskFilter->SetOutsideValue(mArgsInfo.fg_arg); - maskFilter->Update(); - outputImage = maskFilter->GetOutput(); - } - // Write/Save results - this->template SetNextOutput(outputImage); - } -} -//-------------------------------------------------------------------- - - -}//end clitk - -#endif //#define clitkBinarizeImageGenericFilter_txx diff --git a/filters/clitkImageFillRegionGenericFilter.cxx b/filters/clitkImageFillRegionGenericFilter.cxx deleted file mode 100644 index dd5a51a..0000000 --- a/filters/clitkImageFillRegionGenericFilter.cxx +++ /dev/null @@ -1,190 +0,0 @@ -/*========================================================================= - 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 CLITKIMAGEFILLREGIONGENERICFILTER_CXX -#define CLITKIMAGEFILLREGIONGENERICFILTER_CXX -/** - ------------------------------------------------------------------- - * @file clitkImageFillRegionGenericFilter.cxx - * @author David Sarrut - * @date 23 Feb 2008 - - * @brief - -------------------------------------------------------------------*/ - -#include "clitkImageFillRegionGenericFilter.h" - -//-------------------------------------------------------------------- -clitk::ImageFillRegionGenericFilter::ImageFillRegionGenericFilter(): - clitk::ImageToImageGenericFilter("ImageFillRegion") -{ - InitializeImageType<2>(); - InitializeImageType<3>(); - mPixelValue = 0; - m_IsCentered=false; - mSphericRegion=false; -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -void clitk::ImageFillRegionGenericFilter::InitializeImageType() -{ - // ADD_IMAGE_TYPE(Dim, char); - ADD_IMAGE_TYPE(Dim, short); - // ADD_IMAGE_TYPE(Dim, unsigned short); -// ADD_IMAGE_TYPE(Dim, int); - ADD_IMAGE_TYPE(Dim, float); - // ADD_IMAGE_TYPE(Dim, double); -} -//-------------------------------------------------------------------- - - - -//-------------------------------------------------------------------- -template -void clitk::ImageFillRegionGenericFilter::UpdateWithInputImageType() -{ - - // Typedef - typedef typename ImageType::PixelType PixelType; - static unsigned int Dim = ImageType::ImageDimension; - - // Spheric region - if (mSphericRegion) return Update_WithDimAndPixelType_SphericRegion(); - - // Read input - typename ImageType::Pointer input = GetInput(0); - - // Get pixel value in correct type - PixelType value = PixelTypeDownCast(mPixelValue); - - // Get region - typedef typename ImageType::RegionType RegionType; - typedef typename ImageType::SizeType SizeType; - typedef typename ImageType::IndexType IndexType; - RegionType region; - SizeType size; - IndexType start; - for(unsigned int i=0; i IteratorType; - IteratorType it(input, region); - it.GoToBegin(); - while (!it.IsAtEnd()) { - it.Set(value); - ++it; - } - - // Write results - SetNextOutput(input); -} -//-------------------------------------------------------------------- - -//-------------------------------------------------------------------- -template -void clitk::ImageFillRegionGenericFilter::Update_WithDimAndPixelType_SphericRegion() -{ - - // Read input - typedef itk::Image ImageType; - //typename ImageType::Pointer input = clitk::readImage(mInputFilenames[0], mIOVerbose); - typename ImageType::Pointer input = GetInput(0); - - // Get pixel value in correct type - PixelType value = PixelTypeDownCast(mPixelValue); - - // Centered? - if(m_IsCentered) { - typename ImageType::SizeType size= input->GetLargestPossibleRegion().GetSize(); - typename ImageType::SpacingType spacing= input->GetSpacing(); - typename ImageType::PointType origin= input->GetOrigin(); - mCenter.resize(Dim); - for (unsigned int i=0; i IteratorType; - IteratorType it(input, input->GetLargestPossibleRegion()); - it.GoToBegin(); - - typename ImageType::PointType point; - //typename itk::Vector distance; - typename ImageType::IndexType index; - //bool inside; - double distance; - - while (!it.IsAtEnd()) { - // inside=true; - index=it.GetIndex(); - input->TransformIndexToPhysicalPoint(index, point); - distance=0.0; - for(unsigned int i=0; i(input); -} - -//-------------------------------------------------------------------- - - - -//-------------------------------------------------------------------- -void clitk::ImageFillRegionGenericFilter::SetSphericRegion(std::vector & radius, - std::vector & center) -{ - mRadius.clear(); - mRadius.resize(radius.size()); - std::copy(radius.begin(), radius.end(), mRadius.begin()); - mCenter.clear(); - mCenter.resize(center.size()); - std::copy(center.begin(), center.end(), mCenter.begin()); - mSphericRegion = true; - m_IsCentered=false; -} - -void clitk::ImageFillRegionGenericFilter::SetSphericRegion(std::vector & radius) -{ - mRadius.clear(); - mRadius.resize(radius.size()); - std::copy(radius.begin(), radius.end(), mRadius.begin()); - m_IsCentered=true; - mSphericRegion = true; -} -//-------------------------------------------------------------------- - - -#endif //define CLITKIMAGEFILLREGIONGENERICFILTER_CXX diff --git a/filters/clitkImageFillRegionGenericFilter.h b/filters/clitkImageFillRegionGenericFilter.h deleted file mode 100644 index 1ef79ee..0000000 --- a/filters/clitkImageFillRegionGenericFilter.h +++ /dev/null @@ -1,91 +0,0 @@ -/*========================================================================= - 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 CLITKIMAGEFILLREGIONGENERICFILTER_H -#define CLITKIMAGEFILLREGIONGENERICFILTER_H -/** - ------------------------------------------------------------------- - * @file clitkImageFillRegionGenericFilter.h - * @author David Sarrut - * @date 23 Feb 2008 - -------------------------------------------------------------------*/ - -// clitk include -#include "clitkCommon.h" -#include "clitkImageCommon.h" -#include "clitkImageToImageGenericFilter.h" - -// itk include -#include "itkImage.h" -#include "itkImageIOBase.h" -#include "itkImageRegionIterator.h" -#include "itkImageRegionConstIterator.h" -#include "itkImageRegionIteratorWithIndex.h" - -namespace clitk { - - //-------------------------------------------------------------------- - class ImageFillRegionGenericFilter: - public clitk::ImageToImageGenericFilter { - - public: - - // Constructor - ImageFillRegionGenericFilter (); - ~ImageFillRegionGenericFilter (){;} - - // Types - typedef ImageFillRegionGenericFilter Self; - typedef itk::SmartPointer Pointer; - typedef itk::SmartPointer ConstPointer; - - // New - itkNewMacro(Self); - - // Set methods - void SetFillPixelValue (double value) { mPixelValue = value; } - void SetRegion(int * size, int * start) { mSize = size; mStart = start ; } - void SetSphericRegion(std::vector & radius, std::vector & center); - void SetSphericRegion(std::vector & radius); - - //-------------------------------------------------------------------- - // Main function called each time the filter is updated - template - void UpdateWithInputImageType(); - - protected: - template void InitializeImageType(); - double mPixelValue; - int * mSize; - int * mStart; - std::vector mCenter; - std::vector mRadius; - bool mSphericRegion; - bool m_IsCentered; - - template void Update_WithDimAndPixelType_SphericRegion(); - - }; // end class ImageFillRegionGenericFilter -//-------------------------------------------------------------------- - -#include "clitkImageFillRegionGenericFilter.txx" - -} // end namespace -//-------------------------------------------------------------------- - -#endif //#define CLITKIMAGEFILLREGIONGENERICFILTER_H - diff --git a/filters/clitkImageResample.ggo b/filters/clitkImageResample.ggo deleted file mode 100644 index b36e394..0000000 --- a/filters/clitkImageResample.ggo +++ /dev/null @@ -1,17 +0,0 @@ -#File clitkImageResample.ggo -package "clitkImageResample" -version "1.0" -purpose "Resample an image. You can specify the interpolation, you can apply a Gaussian filter before." - -option "config" - "Config file" string no -option "input" i "Input image filename" string yes -option "output" o "Output image filename" string yes -option "verbose" v "Verbose" flag off -option "interp" - "Interpolation type: {nn, linear, bspline, blut}" string no default="nn" -option "order" b "BSpline ordre (range 0-5)" int no default="3" -option "sampling" s "BLUT sampling value" int no default="30" -option "size" - "Number of pixels of each coordonate" int no multiple default="0" -option "spacing" - "Spacing in mm between pixels" float no multiple default="0.0" -option "gauss" g "Apply Gaussian before (sigma in mm) ; no Gaussian if not given" float no multiple default="1.0" -option "default" d "Default pixel value" float no default = "0.0" - diff --git a/itk/clitkBackProjectImageFilter.h b/itk/clitkBackProjectImageFilter.h new file mode 100644 index 0000000..93e588a --- /dev/null +++ b/itk/clitkBackProjectImageFilter.h @@ -0,0 +1,280 @@ +/*========================================================================= + 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 __clitkBackProjectImageFilter_h +#define __clitkBackProjectImageFilter_h +#include "clitkTransformUtilities.h" + +//itk include +#include "itkInterpolateImageFunction.h" +#include "itkImageToImageFilter.h" +#include "itkTransform.h" +#include "itkVector.h" + + +namespace clitk +{ + + template + class ITK_EXPORT BackProjectImageFilter : + public itk::ImageToImageFilter + { + public: + //------------------------------------ + // Standard itk typedefs + //----------------------------------- + typedef BackProjectImageFilter Self; + typedef itk::ImageToImageFilter Superclass; + 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(BackProjectImageFilter, ImageToImageFilter); + + /** Dimension of the domain space. */ + itkStaticConstMacro(InputImageDimension, unsigned int, Superclass::InputImageDimension); + itkStaticConstMacro(OutputImageDimension, unsigned int, Superclass::OutputImageDimension); + + //------------------------------------ + // Typedefs + //------------------------------------ + typedef typename InputImageType::Pointer InputImagePointer; + typedef typename InputImageType::ConstPointer InputImageConstPointer; + typedef typename InputImageType::PixelType InputPixelType; + typedef typename InputImageType::SizeType InputSizeType; + typedef typename InputImageType::SpacingType InputSpacingType; + typedef typename InputImageType::DirectionType InputDirectionType; + typedef typename InputImageType::IndexType InputIndexType; + typedef typename InputImageType::PointType InputPointType; + typedef typename itk::ContinuousIndex ContinuousInputIndexType; + typedef typename InputImageType::RegionType InputImageRegionType; + typedef itk::Vector HomogeneInputVectorType; + typedef itk::Vector Homogene2DVectorType; + typedef itk::Point HomogeneInputPointType; + typedef itk::Point Homogene2DPointType; + + typedef typename OutputImageType::Pointer OutputImagePointer; + typedef typename OutputImageType::ConstPointer OutputImageConstPointer; + typedef typename OutputImageType::PixelType OutputPixelType; + typedef typename OutputImageType::SizeType OutputSizeType; + typedef typename OutputImageType::SpacingType OutputSpacingType; + typedef typename OutputImageType::DirectionType OutputDirectionType; + typedef typename OutputImageType::IndexType OutputIndexType; + typedef typename OutputImageType::PointType OutputPointType; + typedef typename itk::ContinuousIndex ContinuousOutputIndexType; + typedef typename OutputImageType::RegionType OutputImageRegionType; + typedef itk::Vector HomogeneOutputVectorType; + typedef itk::Point HomogeneOutputPointType; + + typedef itk::Matrix MatrixType; + + //------------------------------------ + // Projection geometry + //----------------------------------- + void SetIsoCenter( const OutputPointType& i ) + { + if( m_IsoCenter!=i) + { + m_IsoCenter=i; + m_IsInitialized=false; + this->Modified(); + } + } + + void SetSourceToScreen(const double &s) + { + if( m_SourceToScreen!=s) + { + m_SourceToScreen=s; + m_IsInitialized=false; + this->Modified(); + } + } + + void SetSourceToAxis( const double& s) + { + if( m_SourceToAxis!=s) + { + m_SourceToAxis=s; + m_IsInitialized=false; + this->Modified(); + } + } + + void SetProjectionAngle(const double& s) + { + if( m_SourceToScreen!=s) + { + m_ProjectionAngle=s; + m_IsInitialized=false; + this->Modified(); + } + } + + void SetRigidTransformMatrix(const MatrixType& m) + { + if(m_RigidTransformMatrix != m) + { + m_RigidTransformMatrix=m; + m_IsInitialized=false; + this->Modified(); + } + } + + void SetEdgePaddingValue(const OutputPixelType& p) + { + if (m_EdgePaddingValue!=p) + { + m_EdgePaddingValue=p; + m_IsInitialized=false; + this->Modified(); + } + } + + // itkSetMacro(IsoCenter, OutputPointType); + // itkGetConstReferenceMacro(IsoCenter, OutputPointType) + // itkSetMacro( SourceToScreen, double ); + // itkGetMacro( SourceToScreen, double ); + // itkSetMacro( SourceToAxis, double ); + // itkGetMacro( SourceToAxis, double ); + // itkSetMacro(RigidTransformMatrix, itk::Matrix)); + // itkGetConstReferenceMacro(RigidTransformMatrix, itk::Matrix); + // void SetRigidTransformMatrix(const itk::Matrix & m); + // itk::Matrix GetRigidTransformMatrix( void ){return m_RigidTransformMatrix;} + // itkSetMacro( EdgePaddingValue, OutputPixelType ); + // itkGetMacro( EdgePaddingValue, OutputPixelType ); + // itkSetMacro( ProjectionAngle, double ); + // itkGetMacro( ProjectionAngle, double ); + + //----------------------------------- + //Output image properties + //----------------------------------- + void SetOutputSize(const OutputSizeType& p) + { + if (m_OutputSize!=p) + { + m_OutputSize=p; + m_IsInitialized=false; + this->Modified(); + } + } + + /** Set the output image spacing. */ + void SetOutputSpacing(const OutputSpacingType & p) + { + if (m_OutputSpacing!=p) + { + m_OutputSpacing=p; + m_IsInitialized=false; + this->Modified(); + } + } + + /** Set the output image origin. */ + void SetOutputOrigin(const OutputPointType& p) + { + if (m_OutputOrigin!=p) + { + m_OutputOrigin=p; + m_IsInitialized=false; + this->Modified(); + } + } + + /** Helper method to set the output parameters based on this image */ + void SetOutputParametersFromImage( const OutputImagePointer image ); + + /** Helper method to set the output parameters based on this image */ + void SetOutputParametersFromImage( const OutputImageConstPointer image ); + + + void Initialize(void) throw (itk::ExceptionObject); + + protected: + + // Constructor + BackProjectImageFilter(); + + // Destructor + ~BackProjectImageFilter(){}; + + // Print the object + void PrintSelf(std::ostream& os, itk::Indent indent) const; + + // Calculate the projection matrix + void CalculateProjectionMatrix(void); + + // Calculate the coordinate increments + void CalculateCoordinateIncrements( void ); + + /** Overrides GenerateInputRequestedRegion() in order to inform + * the pipeline execution model of different input requested regions + * than the output requested region. + * \sa ImageToImageFilter::GenerateInputRequestedRegion() */ + virtual void GenerateInputRequestedRegion(); + + // Generate Output Information + virtual void GenerateOutputInformation (void); + + // Threaded Generate Data + void BeforeThreadedGenerateData(void ); + + // Threaded Generate Data + void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, int threadId ); + + + //------------------------------------------------ + //Member data + //------------------------------------------------ + bool m_IsInitialized; + + // Input + InputImagePointer m_ModifiedInput; + + // Projection geometry + OutputPointType m_IsoCenter; + itk::Matrix m_ProjectionMatrix; + HomogeneInputVectorType m_LineInc, m_ColInc, m_PlaneInc; + // Homogene2DVectorType m_LineInc, m_ColInc, m_PlaneInc; + MatrixType m_RigidTransformMatrix; + double m_SourceToScreen; + double m_SourceToAxis; + OutputPixelType m_EdgePaddingValue; + double m_ProjectionAngle; + + // Output image info + OutputSizeType m_OutputSize; // Size of the output image + OutputSpacingType m_OutputSpacing; // output image spacing + OutputPointType m_OutputOrigin; // output image origin + + private: + BackProjectImageFilter( const Self& ); //purposely not implemented + void operator=( const Self& ); //purposely not implemented + + + }; + +} // namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkBackProjectImageFilter.txx" +#endif + +#endif diff --git a/itk/clitkBackProjectImageFilter.txx b/itk/clitkBackProjectImageFilter.txx new file mode 100644 index 0000000..f70fa9e --- /dev/null +++ b/itk/clitkBackProjectImageFilter.txx @@ -0,0 +1,390 @@ +/*========================================================================= + 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 __clitkBackProjectImageFilter_txx +#define __clitkBackProjectImageFilter_txx +#include "clitkBackProjectImageFilter.h" +#include "itkContinuousIndex.h" +#include "vnl/vnl_math.h" + +namespace clitk +{ + + //----------------------------------------------------------------------- + // Constructor + //----------------------------------------------------------------------- + + template + BackProjectImageFilter< InputImageType, OutputImageType > + ::BackProjectImageFilter() + { + + //Parameters for backprojection + this->m_IsoCenter.Fill(0.0); + this->m_SourceToScreen = 1536.0; + this->m_SourceToAxis = 1000.0; + this->m_EdgePaddingValue = itk::NumericTraits::Zero;//density images + this->m_RigidTransformMatrix.SetIdentity(); + + //Parameters for output + this->m_OutputSpacing.Fill(1); + this->m_OutputOrigin.Fill(0.0); + this->m_OutputSize.Fill( 512 ); + + this->m_IsInitialized=false; + } + + + //----------------------------------------------------------------------- + // PrintSelf + //----------------------------------------------------------------------- + template + void + BackProjectImageFilter< InputImageType, OutputImageType > + ::PrintSelf(std::ostream& os, itk::Indent indent) const + { + this->Superclass::PrintSelf(os,indent); + + os << indent << "IsoCenter: " << m_IsoCenter << std::endl; + os << indent << "SourceToScreen: " << m_SourceToScreen << std::endl; + os << indent << "SourceToAxis: " << m_SourceToAxis << std::endl; + os << indent << "Edge Padding Value: " << m_EdgePaddingValue << std::endl; + os << indent << "Rigid Transform matrix: " << m_EdgePaddingValue << std::endl; + } + + + //----------------------------------------------------------------------- + // Set output info from image + //----------------------------------------------------------------------- + template + void + BackProjectImageFilter + ::SetOutputParametersFromImage ( const OutputImagePointer image ) + { + this->SetOutputOrigin( image->GetOrigin() ); + this->SetOutputSpacing( image->GetSpacing() ); + this->SetOutputSize( image->GetLargestPossibleRegion().GetSize() ); + } + + + //----------------------------------------------------------------------- + // Set output info from image + //----------------------------------------------------------------------- + template + void + BackProjectImageFilter + ::SetOutputParametersFromImage (const OutputImageConstPointer image ) + { + this->SetOutputOrigin( image->GetOrigin() ); + this->SetOutputSpacing( image->GetSpacing() ); + this->SetOutputSize( image->GetLargestPossibleRegion().GetSize() ); + } + + + //----------------------------------------------------------------------- + // Generate output information + //----------------------------------------------------------------------- + template + void + BackProjectImageFilter< InputImageType, OutputImageType > + ::GenerateOutputInformation( void ) + { + // Don not call the superclass' implementation of this method (!=Dimensions) + // Superclass::GenerateOutputInformation(); + + // get pointer to the output + OutputImagePointer outputPtr = this->GetOutput(); + InputImageConstPointer inputPtr = this->GetInput(); + + if ( !outputPtr || ! inputPtr) + { + return; + } + + // Set the output image largest possible region. Use a RegionCopier + // so that the input and output images can be different dimensions. + OutputImageRegionType outputLargestPossibleRegion; + this->CallCopyInputRegionToOutputRegion(outputLargestPossibleRegion, + inputPtr->GetLargestPossibleRegion()); + + + //OutputImageRegionType region; + outputLargestPossibleRegion.SetSize( m_OutputSize ); + outputPtr->SetLargestPossibleRegion( outputLargestPossibleRegion ); + outputPtr->SetSpacing( m_OutputSpacing ); + outputPtr->SetOrigin( m_OutputOrigin ); + + } + + + //----------------------------------------------------------------------- + // Generate input Requested region + //----------------------------------------------------------------------- + template + void + BackProjectImageFilter + ::GenerateInputRequestedRegion() + { + //Call superclass + Superclass::GenerateInputRequestedRegion(); + + if (!this->GetOutput()) + { + return; + } + OutputImageRegionType outputRegion = this->GetOutput()->GetRequestedRegion(); + InputImagePointer inputPtr = const_cast(this->GetInput()); + + if ( !inputPtr ) + { + // Because DataObject::PropagateRequestedRegion() allows only + // InvalidRequestedRegionError, it's impossible to write simply: + // itkExceptionMacro(<< "Missing input " << idx); + itk::InvalidRequestedRegionError e(__FILE__, __LINE__); + e.SetLocation(ITK_LOCATION); + e.SetDescription("Missing input."); + e.SetDataObject(this->GetOutput()); + throw e; + } + + InputImageRegionType inputRegion; + inputRegion=inputPtr->GetLargestPossibleRegion(); + inputPtr->SetRequestedRegion(inputRegion); + + } + + + + //----------------------------------------------------------------------- + // Before threaded data + //----------------------------------------------------------------------- + template + void + BackProjectImageFilter + ::BeforeThreadedGenerateData( void ) + { + if (!m_IsInitialized) this->Initialize(); + } + + + //----------------------------------------------------------------------- + // Initialize + //----------------------------------------------------------------------- + template + void + BackProjectImageFilter + ::Initialize( void ) throw (itk::ExceptionObject) + { + //Change the origin of the 2D input + typename InputImageType::ConstPointer inputPtr=this->GetInput(); + m_ModifiedInput=InputImageType::New(); + m_ModifiedInput->CopyInformation(inputPtr); + InputSizeType size=inputPtr->GetLargestPossibleRegion().GetSize(); + InputSpacingType spacing=inputPtr->GetSpacing(); + + //Change the origin + InputPointType newOrigin; + newOrigin[0] =-static_cast(size[0]-1)*spacing[0]/2.0;//-static_cast(size[0]-1)*spacing[0]/2.0; + newOrigin[1] =-static_cast(size[1]-1)*spacing[1]/2.0;//-static_cast(size[1]-1)*spacing[1]/2.0; + m_ModifiedInput->SetOrigin(newOrigin); + + // Calculate the projection matrix + this->CalculateProjectionMatrix(); + + // Calculate the coordinate increments + this->CalculateCoordinateIncrements(); + + m_IsInitialized=true; + } + + + //----------------------------------------------------------------------- + // Calculate Projection Matrix + //----------------------------------------------------------------------- + template + void + BackProjectImageFilter + ::CalculateProjectionMatrix( void ) + { + InputSpacingType inputSpacing=this->GetInput()->GetSpacing(); + + // Projection on YZ plane+pixelTrans + itk::Matrix temp; + temp.Fill(itk::NumericTraits::Zero); + // temp(0,0)=-0.5*inputSpacing[0]; + // temp(1,0)=-0.5*inputSpacing[1]; + temp(2,0)=1; + temp(0,1)=m_SourceToScreen;//Invert Y/X? for correspondence to real projections + temp(1,2)=m_SourceToScreen; + // temp(0,3)=m_SourceToAxis*0.5*inputSpacing[0]; + // temp(1,3)=m_SourceToAxis*0.5*inputSpacing[1]; + temp(2,3)=-m_SourceToAxis;//-m_IsoCenter[0]-m_SourceToAxis; + + // Get the rotation parameter array + itk::Array rotationParameters(3); + const double dtr = ( atan(1.0) * 4.0 ) / 180.0; //constant for converting degrees into radians + rotationParameters[0]= 0.; + rotationParameters[1]= 0.; + rotationParameters[2]= -dtr*(double) m_ProjectionAngle; + + // We first perform rigid transform (of source and panel), then a centered rotation around the transformed center + itk::Matrix rigidRotation = GetRotationalPartMatrix3D(m_RigidTransformMatrix); + itk::Vector rigidTranslation = GetTranslationPartMatrix3D(m_RigidTransformMatrix); + OutputPointType transformedIsoCenter = rigidRotation * m_IsoCenter + rigidTranslation; + + // Calculate the centered rotation matrix + itk::Matrix centeredRotationMatrix=GetCenteredRotationMatrix3D(rotationParameters,transformedIsoCenter); + + // Define the voxel pixel transforms (shift half a pixel/voxel) + itk::Matrix voxelTrans; voxelTrans.SetIdentity(); + for (unsigned int i=0;i<3;i++)voxelTrans(i,3)=0.5*m_OutputSpacing[i]; + + // Compose the rotation with the rigid transform matrix and the voxel transform + itk::Matrix finalTransform = centeredRotationMatrix * m_RigidTransformMatrix; + itk::Matrix invFinalTransform ( finalTransform.GetInverse()); + invFinalTransform=invFinalTransform*voxelTrans; + + // Apply rigid transform to the projection matrix + for (unsigned int i=0; i<3;i++) + for (unsigned int j=0; j<4;j++) + { + m_ProjectionMatrix(i,j)=itk::NumericTraits::Zero; + for (unsigned int k=0; k<4;k++) + m_ProjectionMatrix(i,j)+=temp(i,k)*invFinalTransform(k,j); + } + } + + + //----------------------------------------------------------------------- + // Calculate the coordinate increments + //----------------------------------------------------------------------- + template + void + BackProjectImageFilter + ::CalculateCoordinateIncrements( void ) + { + //Compute Line increment + m_LineInc[0]=m_ProjectionMatrix[0][0]*m_OutputSpacing[0]; + m_LineInc[1]=m_ProjectionMatrix[1][0]*m_OutputSpacing[0]; + m_LineInc[2]=m_ProjectionMatrix[2][0]*m_OutputSpacing[0]; + + //Compute column increment (and restart at the beginning of the line) + m_ColInc[0]=m_ProjectionMatrix[0][1]*m_OutputSpacing[1]-m_OutputSize[0]*m_LineInc[0]; + m_ColInc[1]=m_ProjectionMatrix[1][1]*m_OutputSpacing[1]-m_OutputSize[0]*m_LineInc[1]; + m_ColInc[2]=m_ProjectionMatrix[2][1]*m_OutputSpacing[1]-m_OutputSize[0]*m_LineInc[2]; + + //Compute plane increment (and restart at the beginning of the columns) + m_PlaneInc[0]=m_ProjectionMatrix[0][2]*m_OutputSpacing[2]-m_ProjectionMatrix[0][1]*m_OutputSpacing[1]*m_OutputSize[1]; + m_PlaneInc[1]=m_ProjectionMatrix[1][2]*m_OutputSpacing[2]-m_ProjectionMatrix[1][1]*m_OutputSpacing[1]*m_OutputSize[1]; + m_PlaneInc[2]=m_ProjectionMatrix[2][2]*m_OutputSpacing[2]-m_ProjectionMatrix[2][1]*m_OutputSpacing[1]*m_OutputSize[1]; + } + + + //----------------------------------------------------------------------- + // Threaded generate data + //----------------------------------------------------------------------- + template + void + BackProjectImageFilter + ::ThreadedGenerateData( const OutputImageRegionType & outputRegionForThread, int threadId ) + { + //Projection pointer + InputImageConstPointer inputPtr=this->GetInput(); + InputPixelType * beginPtr=const_cast(this->GetInput()->GetBufferPointer()); + InputPixelType * pp; + + //Volume pointer + OutputImagePointer outputPTr= this->GetOutput(); + + //Iterator for the thread region + typedef itk::ImageRegionIterator OutputIteratorType; + OutputIteratorType iterator(outputPTr, outputRegionForThread); + OutputSizeType outputSizeForThread=outputRegionForThread.GetSize(); + + //Some temp variables + OutputPixelType value; + HomogeneOutputPointType homOutputPoint; + HomogeneInputPointType homInputPoint; + OutputPointType oPoint; + InputPointType iPoint; + iPoint.Fill(itk::NumericTraits::Zero); + OutputIndexType oIndex; + ContinuousInputIndexType iIndex; + InputSizeType inputSize=inputPtr->GetLargestPossibleRegion().GetSize(); + double dx,dy,dxm,dym; + int lx, ly; + + //Get the first output coordinate + oIndex=iterator.GetIndex();//costly but only once a thread + outputPTr->TransformIndexToPhysicalPoint(oIndex,oPoint); + + for (unsigned int i=0;iTransformPhysicalPointToContinuousIndex(iPoint, iIndex) ) + { + //Own (fast bilinear) interpolation + lx = (int)floor(iIndex[0]); dx = iIndex[0]-lx; dxm = 1.-dx; + ly = (int)floor(iIndex[1]); dy = iIndex[1]-ly; dym = 1.-dy; + pp = beginPtr + ly*inputSize[0]+lx; + value =static_cast( ( dxm * dym*(double)(*pp) + + dx * dym*(double)(*(pp+1)) + + dxm* dy *(double)(*(pp + inputSize[0])) + + dx * dy *(double)(*(pp + inputSize[0]+1))) ); + + } + //Outside: padding value + else value=m_EdgePaddingValue; + + //Set it + iterator.Set(value); + + //Advance one step in the line + homInputPoint+=m_LineInc; + ++iterator; + } + + //Advance one line + homInputPoint+=m_ColInc; + } + + //Advance one plane + homInputPoint+=m_PlaneInc; + } + } + + +} // namespace clitk + + +#endif diff --git a/itk/clitkComposeVFFilter.h b/itk/clitkComposeVFFilter.h new file mode 100755 index 0000000..868ff0d --- /dev/null +++ b/itk/clitkComposeVFFilter.h @@ -0,0 +1,92 @@ +/*========================================================================= + 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 __clitkComposeVFFilter_h +#define __clitkComposeVFFilter_h +#include "clitkImageCommon.h" + +#include "itkImageToImageFilter.h" +#include "itkImage.h" +#include "itkImageRegionIterator.h" +#include "itkImageRegionIteratorWithIndex.h" +#include "itkNumericTraits.h" + +namespace clitk +{ + + template + class ITK_EXPORT ComposeVFFilter : public itk::ImageToImageFilter + + { + public: + typedef ComposeVFFilter Self; + typedef itk::ImageToImageFilter Superclass; + 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( ComposeVFFilter, ImageToImageFilter ); + + /** Determine the image dimension. */ + itkStaticConstMacro(ImageDimension, unsigned int, + InputImageType::ImageDimension ); + + /** Typedef to describe the output image region type. */ + typedef typename OutputImageType::RegionType OutputImageRegionType; + + //======================================================================================== + //typedefs + typedef double CoordRepType; + typedef typename OutputImageType::PixelType PixelType; + typedef itk::Point PointType; + + //Set Methods(inline) + void SetEdgePaddingValue(PixelType m); + void SetVerbose(bool m){m_Verbose=m;} + void SetInput1(typename InputImageType::Pointer m) + { + //call the superclass method (at least one input required!) + this->SetInput(m); + m_Input1=m; + } + void SetInput2(typename InputImageType::Pointer m){m_Input2=m;} + + protected: + ComposeVFFilter(); + ~ComposeVFFilter() {}; + + + //======================================================================================== + //Threaded execution should implement generate threaded data + void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ); + + bool m_Verbose; + PixelType m_EdgePaddingValue; + typename InputImageType::Pointer m_Input1; + typename InputImageType::Pointer m_Input2; + }; + + +} // end namespace clitk +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkComposeVFFilter.txx" +#endif + +#endif // #define __clitkComposeVFFilter_h diff --git a/itk/clitkComposeVFFilter.txx b/itk/clitkComposeVFFilter.txx new file mode 100755 index 0000000..c456d82 --- /dev/null +++ b/itk/clitkComposeVFFilter.txx @@ -0,0 +1,163 @@ +/*========================================================================= + 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 __clitkComposeVFFilter_txx +#define __clitkComposeVFFilter_txx +#include "clitkComposeVFFilter.h" + + +namespace clitk +{ + + //========================================================================================================================= + //constructor + template + ComposeVFFilter::ComposeVFFilter() + { + for (unsigned int i=0; i + void ComposeVFFilter::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ) + { + + //Get pointer to the output + typename OutputImageType::Pointer outputPtr = this->GetOutput(); + + //Iterator over output + typedef itk::ImageRegionConstIteratorWithIndex Input1ImageIteratorType; + typedef itk::ImageRegionIterator OutputImageIteratorType; + + //define the output and input1 iterator over the outputRegionForThread + OutputImageIteratorType outputIt(outputPtr, outputRegionForThread); + Input1ImageIteratorType input1It(m_Input1, outputRegionForThread); + + //Initialize + typename InputImageType::IndexType index; + itk::ContinuousIndex contIndex; + typename InputImageType::PointType point1; + typename InputImageType::PointType point2; + typedef typename OutputImageType::PixelType DisplacementType; + DisplacementType displacement; + DisplacementType totalDisplacement; + input1It.GoToBegin(); + + //define some temp variables outside the loop + signed long baseIndex[ImageDimension]; + // long tIndex; + double distance[ImageDimension]; + unsigned int dim; + double totalOverlap; + double overlap; + unsigned int upper; + unsigned int counter; + typename OutputImageType::IndexType neighIndex; + + + //Find the number of neighbors + unsigned int neighbors = 1 << ImageDimension; + + //================================================================================================== + //1. loop over the region of the deformationfield and compose the displacements + while( !input1It.IsAtEnd() ) + { + // get the input image index + index = input1It.GetIndex(); + m_Input1->TransformIndexToPhysicalPoint( index, point1 ); + + // get the displacement of input 1 + displacement = input1It.Get(); + + // compute the required image point in input2 + for(unsigned int j = 0; j < ImageDimension; j++ ) point2[j] = point1[j] + (double)displacement[j]; + + //JV TODO add something for the borders + //true if inside image + if(m_Input2->TransformPhysicalPointToContinuousIndex(point2, contIndex ) ) + { + + for(dim = 0; dim < ImageDimension; dim++) + { + // The following block is equivalent to the following line without + // having to call floor. (Only for positive inputs, we already now that is in the image) + // baseIndex[dim] = (long) vcl_floor(contIndex[dim] ); + + baseIndex[dim] = (long) contIndex[dim]; + distance[dim] = contIndex[dim] - double( baseIndex[dim] ); + + //Reset the accumulator + totalDisplacement[dim]=0.0; + } + + //Add contribution for each neighbor + totalOverlap = itk::NumericTraits::Zero; + for( counter = 0; counter < neighbors ; counter++ ) + { + overlap = 1.0; // fraction overlap + upper = counter; // each bit indicates upper/lower neighbour + + + // get neighbor index and overlap fraction + for( dim = 0; dim < 3; dim++ ) + { + if ( upper & 1 ) + { + neighIndex[dim] = baseIndex[dim] + 1; + overlap *= distance[dim]; + } + else + { + neighIndex[dim] = baseIndex[dim]; + overlap *= 1.0 - distance[dim]; + } + upper >>= 1; + } + + //JV shouldn't we verify that the index is not over the upper border instead of zero? + // Set neighbor value only if overlap is not zero and index is still in image + if( overlap>0.0 && neighIndex[0]>=0 && neighIndex[1]>=0 && neighIndex[2]>=0 ) + { + //what to store? the weighted displacement vector of Input2? + totalDisplacement+=m_Input2->GetPixel(neighIndex)*overlap; + //JV don't we loose more by adding and verifyning each time, it will never be 1.0 before the end no? + totalOverlap += overlap; + } + + if( totalOverlap == 1.0 ) + { + // finished + break; + } + } + //add the displacement of input1 and the interpolated displacement of input2 to the output + outputIt.Set(static_cast(input1It.Get())+totalDisplacement); + } + //displacement from input1 goes outside input2 + else outputIt.Set(m_EdgePaddingValue); + + ++input1It; + ++outputIt; + } + } + +} + +#endif diff --git a/itk/clitkExtractImageFilter.h b/itk/clitkExtractImageFilter.h new file mode 100644 index 0000000..2bc1e2e --- /dev/null +++ b/itk/clitkExtractImageFilter.h @@ -0,0 +1,115 @@ + +/*========================================================================= + 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 __clitkExtractImageFilter_h +#define __clitkExtractImageFilter_h + +#include "itkImageToImageFilter.h" +#include "itkSmartPointer.h" +#include "itkExtractImageFilterRegionCopier.h" + +namespace clitk +{ + +template +class ITK_EXPORT ExtractImageFilter: + public itk::ImageToImageFilter +{ +public: + /** Standard class typedefs. */ + typedef ExtractImageFilter Self; + typedef itk::ImageToImageFilter Superclass; + 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(ExtractImageFilter, ImageToImageFilter); + + /** Image type information. */ + typedef TInputImage InputImageType; + typedef TOutputImage OutputImageType; + + /** Typedef to describe the output and input image region types. */ + typedef typename TOutputImage::RegionType OutputImageRegionType; + typedef typename TInputImage::RegionType InputImageRegionType; + + /** Typedef to describe the type of pixel. */ + typedef typename TOutputImage::PixelType OutputImagePixelType; + typedef typename TInputImage::PixelType InputImagePixelType; + + /** Typedef to describe the output and input image index and size types. */ + typedef typename TOutputImage::IndexType OutputImageIndexType; + typedef typename TInputImage::IndexType InputImageIndexType; + typedef typename TOutputImage::SizeType OutputImageSizeType; + typedef typename TInputImage::SizeType InputImageSizeType; + + /** ImageDimension enumeration */ + itkStaticConstMacro(InputImageDimension, unsigned int, + TInputImage::ImageDimension); + itkStaticConstMacro(OutputImageDimension, unsigned int, + TOutputImage::ImageDimension); + + typedef itk::ImageToImageFilterDetail::ExtractImageFilterRegionCopier< + itkGetStaticConstMacro(InputImageDimension), + itkGetStaticConstMacro(OutputImageDimension)> ExtractImageFilterRegionCopierType; + + void SetExtractionRegion(InputImageRegionType extractRegion); + itkGetMacro(ExtractionRegion, InputImageRegionType); + +#ifdef ITK_USE_CONCEPT_CHECKING + /** Begin concept checking */ + itkConceptMacro(InputCovertibleToOutputCheck, + (itk::Concept::Convertible)); + /** End concept checking */ +#endif + +protected: + ExtractImageFilter(); + ~ExtractImageFilter() {}; + void PrintSelf(std::ostream& os, itk::Indent indent) const; + + + virtual void GenerateOutputInformation(); + + + virtual void CallCopyOutputRegionToInputRegion(InputImageRegionType &destRegion, + const OutputImageRegionType &srcRegion); + + + void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, + int threadId ); + InputImageRegionType m_ExtractionRegion; + OutputImageRegionType m_OutputImageRegion; + +private: + ExtractImageFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + +}; + + +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkExtractImageFilter.txx" +#endif + +#endif diff --git a/itk/clitkExtractImageFilter.txx b/itk/clitkExtractImageFilter.txx new file mode 100644 index 0000000..d88ecc6 --- /dev/null +++ b/itk/clitkExtractImageFilter.txx @@ -0,0 +1,275 @@ +/*========================================================================= + 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 _clitkExtractImageFilter_txx +#define _clitkExtractImageFilter_txx + +#include "clitkExtractImageFilter.h" +#include "itkImageRegionIterator.h" +#include "itkImageRegionConstIterator.h" +#include "itkObjectFactory.h" +#include "itkExtractImageFilterRegionCopier.h" +#include "itkProgressReporter.h" + + +namespace clitk +{ + +/** + * + */ +template +ExtractImageFilter +::ExtractImageFilter() +{ +} + + +/** + * + */ +template +void +ExtractImageFilter +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf(os,indent); + + os << indent << "ExtractionRegion: " << m_ExtractionRegion << std::endl; + os << indent << "OutputImageRegion: " << m_OutputImageRegion << std::endl; +} + + +template +void +ExtractImageFilter +::CallCopyOutputRegionToInputRegion(InputImageRegionType &destRegion, + const OutputImageRegionType &srcRegion) +{ + ExtractImageFilterRegionCopierType extractImageRegionCopier; + extractImageRegionCopier(destRegion, srcRegion, m_ExtractionRegion); +} + + +template +void +ExtractImageFilter +::SetExtractionRegion(InputImageRegionType extractRegion) +{ + m_ExtractionRegion = extractRegion; + + unsigned int nonzeroSizeCount = 0; + InputImageSizeType inputSize = extractRegion.GetSize(); + OutputImageSizeType outputSize; + OutputImageIndexType outputIndex; + + /** + * check to see if the number of non-zero entries in the extraction region + * matches the number of dimensions in the output image. + **/ + for (unsigned int i = 0; i < InputImageDimension; ++i) + { + if (inputSize[i]) + { + outputSize[nonzeroSizeCount] = inputSize[i]; + outputIndex[nonzeroSizeCount] = extractRegion.GetIndex()[i]; + nonzeroSizeCount++; + } + } + + if (nonzeroSizeCount != OutputImageDimension) + { + itkExceptionMacro("Extraction Region not consistent with output image"); + } + + m_OutputImageRegion.SetSize(outputSize); + m_OutputImageRegion.SetIndex(outputIndex); + this->Modified(); +} + + + +/** + * ExtractImageFilter can produce an image which is a different resolution + * than its input image. As such, ExtractImageFilter needs to provide an + * implementation for GenerateOutputInformation() in order to inform + * the pipeline execution model. The original documentation of this + * method is below. + * + * \sa ProcessObject::GenerateOutputInformaton() + */ +template +void +ExtractImageFilter +::GenerateOutputInformation() +{ + // do not call the superclass' implementation of this method since + // this filter allows the input and the output to be of different dimensions + + // get pointers to the input and output + typename Superclass::OutputImagePointer outputPtr = this->GetOutput(); + typename Superclass::InputImageConstPointer inputPtr = this->GetInput(); + + if ( !outputPtr || !inputPtr) + { + return; + } + + // Set the output image size to the same value as the extraction region. + outputPtr->SetLargestPossibleRegion( m_OutputImageRegion ); + + // Set the output spacing and origin + const itk::ImageBase *phyData; + + phyData + = dynamic_cast*>(this->GetInput()); + + if (phyData) + { + // Copy what we can from the image from spacing and origin of the input + // This logic needs to be augmented with logic that select which + // dimensions to copy + + unsigned int i; + const typename InputImageType::SpacingType& + inputSpacing = inputPtr->GetSpacing(); + const typename InputImageType::DirectionType& + inputDirection = inputPtr->GetDirection(); + const typename InputImageType::PointType& + inputOrigin = inputPtr->GetOrigin(); + + typename OutputImageType::SpacingType outputSpacing; + typename OutputImageType::DirectionType outputDirection; + typename OutputImageType::PointType outputOrigin; + + if ( static_cast(OutputImageDimension) > + static_cast(InputImageDimension ) ) + { + // copy the input to the output and fill the rest of the + // output with zeros. + for (i=0; i < InputImageDimension; ++i) + { + outputSpacing[i] = inputSpacing[i]; + outputOrigin[i] = inputOrigin[i]; + for (unsigned int dim = 0; dim < InputImageDimension; ++dim) + { + outputDirection[i][dim] = inputDirection[i][dim]; + } + } + for (; i < OutputImageDimension; ++i) + { + outputSpacing[i] = 1.0; + outputOrigin[i] = 0.0; + for (unsigned int dim = 0; dim < InputImageDimension; ++dim) + { + outputDirection[i][dim] = 0.0; + } + outputDirection[i][i] = 1.0; + } + } + else + { + // copy the non-collapsed part of the input spacing and origing to the output + int nonZeroCount = 0; + for (i=0; i < InputImageDimension; ++i) + { + if (m_ExtractionRegion.GetSize()[i]) + { + outputSpacing[nonZeroCount] = inputSpacing[i]; + outputOrigin[nonZeroCount] = inputOrigin[i]; + int nonZeroCount2 = 0; + for (unsigned int dim = 0; dim < InputImageDimension; ++dim) + { + if (m_ExtractionRegion.GetSize()[dim]) + { + outputDirection[nonZeroCount][nonZeroCount2] = + inputDirection[i][dim]; + ++nonZeroCount2; + } + } + nonZeroCount++; + } + } + } + + // set the spacing and origin + outputPtr->SetSpacing( outputSpacing ); + outputPtr->SetDirection( outputDirection ); + outputPtr->SetOrigin( outputOrigin ); + outputPtr->SetNumberOfComponentsPerPixel(inputPtr->GetNumberOfComponentsPerPixel() ); + } + else + { + // pointer could not be cast back down + itkExceptionMacro(<< "itk::ExtractImageFilter::GenerateOutputInformation " + << "cannot cast input to " + << typeid(itk::ImageBase*).name() ); + } +} + +/** + * ExtractImageFilter can be implemented as a multithreaded filter. + * Therefore, this implementation provides a ThreadedGenerateData() + * routine which is called for each processing thread. The output + * image data is allocated automatically by the superclass prior to + * calling ThreadedGenerateData(). ThreadedGenerateData can only + * write to the portion of the output image specified by the + * parameter "outputRegionForThread" + * + * \sa ImageToImageFilter::ThreadedGenerateData(), + * ImageToImageFilter::GenerateData() + */ +template +void +ExtractImageFilter +::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, + int threadId) +{ + itkDebugMacro(<<"Actually executing"); + + // Get the input and output pointers + typename Superclass::InputImageConstPointer inputPtr = this->GetInput(); + typename Superclass::OutputImagePointer outputPtr = this->GetOutput(); + + // support progress methods/callbacks + itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels()); + + // Define the portion of the input to walk for this thread + InputImageRegionType inputRegionForThread; + this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread); + + // Define the iterators. + typedef itk::ImageRegionIterator OutputIterator; + typedef itk::ImageRegionConstIterator InputIterator; + + OutputIterator outIt(outputPtr, outputRegionForThread); + InputIterator inIt(inputPtr, inputRegionForThread); + + // walk the output region, and sample the input image + while( !outIt.IsAtEnd() ) + { + // copy the input pixel to the output + outIt.Set( static_cast(inIt.Get())); + ++outIt; + ++inIt; + progress.CompletedPixel(); + } +} + +} // end namespace clitk + +#endif diff --git a/itk/clitkGenericInterpolator.h b/itk/clitkGenericInterpolator.h deleted file mode 100644 index 6456bd4..0000000 --- a/itk/clitkGenericInterpolator.h +++ /dev/null @@ -1,94 +0,0 @@ -/*========================================================================= - 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 __clitkGenericInterpolator_h -#define __clitkGenericInterpolator_h -#include "clitkImageCommon.h" - -//itk include -#include "itkNearestNeighborInterpolateImageFunction.h" -#include "itkLinearInterpolateImageFunction.h" -#include "itkBSplineInterpolateImageFunction.h" -#include "itkBSplineInterpolateImageFunctionWithLUT.h" - - -/* - -Requires at least the following section is the .ggo file - -option "interp" - "Interpolation: 0=NN, 1=Linear, 2=BSpline, 3=BLUT" int no default="1" -option "interpOrder" - "Order if BLUT or BSpline (0-5)" int no default="3" -option "interpSF" - "Sampling factor if BLUT" int no default="20" - -The use will something like - -typedef clitk::GenericVectorInterpolator GenericVectorInterpolatorType; -typename GenericVectorInterpolatorType::Pointer genericInterpolator=GenericVectorInterpolatorType::New(); -genericInterpolator->SetArgsInfo(m_ArgsInfo); -typedef itk::VectorInterpolateImageFunction InterpolatorType; -typename InterpolatorType::Pointer interpolator=genericInterpolator->GetInterpolatorPointer(); - -*/ - -namespace clitk -{ - - template - class GenericInterpolator : public itk::LightObject - { - public: - //============================================== - typedef GenericInterpolator Self; - typedef itk::LightObject Superclass; - typedef itk::SmartPointer Pointer; - typedef itk::SmartPointer ConstPointer; - - typedef itk::InterpolateImageFunction InterpolatorType; - typedef typename InterpolatorType::Pointer InterpolatorPointer; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - //============================================== - //Set members - void SetArgsInfo(args_info_type args_info) - { - m_ArgsInfo= args_info; - m_Verbose=m_ArgsInfo.verbose_flag; - } - - //============================================== - //Get members - InterpolatorPointer GetInterpolatorPointer(void); - - //============================================== - protected: - GenericInterpolator(); - ~GenericInterpolator() {}; - - private: - args_info_type m_ArgsInfo; - InterpolatorPointer m_Interpolator; - bool m_Verbose; - }; - -} // end namespace clitk -#ifndef ITK_MANUAL_INSTANTIATION -#include "clitkGenericInterpolator.txx" -#endif - -#endif // #define __clitkGenericInterpolator_h diff --git a/itk/clitkGenericInterpolator.txx b/itk/clitkGenericInterpolator.txx deleted file mode 100644 index c401e8f..0000000 --- a/itk/clitkGenericInterpolator.txx +++ /dev/null @@ -1,88 +0,0 @@ -/*========================================================================= - 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 __clitkGenericInterpolator_txx -#define __clitkGenericInterpolator_txx -#include "clitkGenericInterpolator.h" - - -namespace clitk -{ - -//========================================================================================================================= -//constructor -template -GenericInterpolator::GenericInterpolator() -{ - m_Interpolator=NULL; - m_Verbose=false; -} - - -//========================================================================================================================= -//Get the pointer -template -typename GenericInterpolator::InterpolatorPointer -GenericInterpolator::GetInterpolatorPointer() -{ - //============================================================================ - // We retrieve the type of interpolation from the command line - //============================================================================ - typename InterpolatorType::Pointer interpolator; - - switch ( m_ArgsInfo.interp_arg ) { - case 0: - - interpolator= itk::NearestNeighborInterpolateImageFunction< ImageType,TCoordRep >::New(); - if (m_Verbose) std::cout<<"Using nearestneighbor interpolation..."<::New(); - if (m_Verbose) std::cout<<"Using linear interpolation..."<::Pointer m =itk::BSplineInterpolateImageFunction< ImageType,TCoordRep >::New(); - m->SetSplineOrder(m_ArgsInfo.interpOrder_arg); - interpolator=m; - if (m_Verbose) std::cout<<"Using Bspline interpolation..."<::Pointer m =itk::BSplineInterpolateImageFunctionWithLUT< ImageType,TCoordRep >::New(); - m->SetSplineOrder(m_ArgsInfo.interpOrder_arg); - m->SetLUTSamplingFactor(m_ArgsInfo.interpSF_arg); - interpolator=m; - if (m_Verbose) std::cout<<"Using BLUT interpolation..."< - class GenericVectorInterpolator : public itk::LightObject - { - public: - //============================================== - typedef GenericVectorInterpolator Self; - typedef itk::LightObject Superclass; - typedef itk::SmartPointer Pointer; - typedef itk::SmartPointer ConstPointer; - - typedef itk::VectorInterpolateImageFunction InterpolatorType; - typedef typename InterpolatorType::Pointer InterpolatorPointer; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - //============================================== - //Set members - void SetArgsInfo(args_info_type args_info) - { - m_ArgsInfo= args_info; - m_Verbose=m_ArgsInfo.verbose_flag; - } - - //============================================== - //Get members - InterpolatorPointer GetInterpolatorPointer(void); - - //============================================== - protected: - GenericVectorInterpolator(); - ~GenericVectorInterpolator() {}; - - private: - args_info_type m_ArgsInfo; - InterpolatorPointer m_Interpolator; - bool m_Verbose; - }; - -} // end namespace clitk -#ifndef ITK_MANUAL_INSTANTIATION -#include "clitkGenericVectorInterpolator.txx" -#endif - -#endif // #define __clitkGenericVectorInterpolator_h diff --git a/itk/clitkGenericVectorInterpolator.txx b/itk/clitkGenericVectorInterpolator.txx deleted file mode 100644 index b277849..0000000 --- a/itk/clitkGenericVectorInterpolator.txx +++ /dev/null @@ -1,87 +0,0 @@ -/*========================================================================= - 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 __clitkGenericVectorInterpolator_txx -#define __clitkGenericVectorInterpolator_txx -#include "clitkGenericVectorInterpolator.h" - - -namespace clitk -{ - -//========================================================================================================================= -//constructor -template -GenericVectorInterpolator::GenericVectorInterpolator() -{ - m_Interpolator=NULL; - m_Verbose=false; -} - - -//========================================================================================================================= -//Get the pointer -template -typename GenericVectorInterpolator::InterpolatorPointer -GenericVectorInterpolator::GetInterpolatorPointer() -{ - //============================================================================ - // We retrieve the type of interpolation from the command line - //============================================================================ - typename InterpolatorType::Pointer interpolator; - - switch ( m_ArgsInfo.interpVF_arg ) { - case 0: - - interpolator= itk::VectorNearestNeighborInterpolateImageFunction< ImageType,TCoordRep >::New(); - if (m_Verbose) std::cout<<"Using nearestneighbor interpolation..."<::New(); - if (m_Verbose) std::cout<<"Using linear interpolation..."<::Pointer m =clitk::VectorBSplineInterpolateImageFunction< ImageType,TCoordRep >::New(); - m->SetSplineOrder(m_ArgsInfo.interpVFOrder_arg); - interpolator=m; - if (m_Verbose) std::cout<<"Using Bspline interpolation..."<::Pointer m =clitk::VectorBSplineInterpolateImageFunctionWithLUT< ImageType,TCoordRep >::New(); - m->SetSplineOrder(m_ArgsInfo.interpVFOrder_arg); - m->SetLUTSamplingFactor(m_ArgsInfo.interpVFSF_arg); - interpolator=m; - if (m_Verbose) std::cout<<"Using BLUT interpolation..."< +class ITK_EXPORT RayCastInterpolateImageFunctionWithOrigin : + public itk::InterpolateImageFunction +{ +public: + /** Standard class typedefs. */ + typedef RayCastInterpolateImageFunctionWithOrigin Self; + typedef itk::InterpolateImageFunction Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + /** Constants for the image dimensions */ + itkStaticConstMacro(InputImageDimension, unsigned int, + TInputImage::ImageDimension); + + /** + * Type of the Transform Base class + * The fixed image should be a 3D image + */ + typedef itk::Transform TransformType; + + typedef typename TransformType::Pointer TransformPointer; + typedef typename TransformType::InputPointType InputPointType; + typedef typename TransformType::OutputPointType OutputPointType; + typedef typename TransformType::ParametersType TransformParametersType; + typedef typename TransformType::JacobianType TransformJacobianType; + + typedef typename Superclass::InputPixelType PixelType; + + typedef typename TInputImage::SizeType SizeType; + + typedef itk::Vector DirectionType; + + /** Type of the Interpolator Base class */ + typedef itk::InterpolateImageFunction InterpolatorType; + + typedef typename InterpolatorType::Pointer InterpolatorPointer; + + //JV Type of the Interpolator for the transform + typedef itk::InterpolateImageFunction DeformableTransformInterpolatorType; + typedef typename DeformableTransformInterpolatorType::Pointer DeformableTransformInterpolatorPointer; + + + /** Run-time type information (and related methods). */ + itkTypeMacro(RayCastInterpolateImageFunctionWithOrigin, InterpolateImageFunction); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** OutputType typedef support. */ + typedef typename Superclass::OutputType OutputType; + + /** InputImageType typedef support. */ + typedef typename Superclass::InputImageType InputImageType; + + /** RealType typedef support. */ + typedef typename Superclass::RealType RealType; + + /** Dimension underlying input image. */ + itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension); + + /** Point typedef support. */ + typedef typename Superclass::PointType PointType; + + /** Index typedef support. */ + typedef typename Superclass::IndexType IndexType; + + /** ContinuousIndex typedef support. */ + typedef typename Superclass::ContinuousIndexType ContinuousIndexType; + + /** \brief + * Interpolate the image at a point position. + * + * Returns the interpolated image intensity at a + * specified point position. No bounds checking is done. + * The point is assume to lie within the image buffer. + * + * ImageFunction::IsInsideBuffer() can be used to check bounds before + * calling the method. + */ + virtual OutputType Evaluate( const PointType& point ) const; + + /** Interpolate the image at a continuous index position + * + * Returns the interpolated image intensity at a + * specified index position. No bounds checking is done. + * The point is assume to lie within the image buffer. + * + * Subclasses must override this method. + * + * ImageFunction::IsInsideBuffer() can be used to check bounds before + * calling the method. + */ + virtual OutputType EvaluateAtContinuousIndex( + const ContinuousIndexType &index ) const; + + + /** Connect the Transform. */ + itkSetObjectMacro( Transform, TransformType ); + /** Get a pointer to the Transform. */ + itkGetObjectMacro( Transform, TransformType ); + + /** Connect the Interpolator. */ + itkSetObjectMacro( Interpolator, InterpolatorType ); + /** Get a pointer to the Interpolator. */ + itkGetObjectMacro( Interpolator, InterpolatorType ); + + /** Connect the focalPoint. */ + itkSetMacro( FocalPoint, InputPointType ); + /** Get a pointer to the focalpoint. */ + itkGetMacro( FocalPoint, InputPointType ); + + /** Connect the threshold. */ + itkSetMacro( Threshold, double ); + /** Get a pointer to the threshhold. */ + itkGetMacro( Threshold, double ); + + /** Check if a point is inside the image buffer. + * \warning For efficiency, no validity checking of + * the input image pointer is done. */ + inline bool IsInsideBuffer( const PointType & ) const + { + return true; + } + bool IsInsideBuffer( const ContinuousIndexType & ) const + { + return true; + } + bool IsInsideBuffer( const IndexType & ) const + { + return true; + } + + //JV transform is deformable + itkSetMacro( TransformIsDeformable, bool ); + itkGetMacro( TransformIsDeformable, bool ); + + //JV interpolator for deformable transform + itkSetObjectMacro( DeformableTransformInterpolator, DeformableTransformInterpolatorType ); + itkGetObjectMacro( DeformableTransformInterpolator, DeformableTransformInterpolatorType ); + +protected: + + /// Constructor + RayCastInterpolateImageFunctionWithOrigin(); + + /// Destructor + ~RayCastInterpolateImageFunctionWithOrigin(){}; + + /// Print the object + void PrintSelf(std::ostream& os, itk::Indent indent) const; + + /// Transformation used to calculate the new focal point position + TransformPointer m_Transform; + + /// The focal point or position of the ray source + InputPointType m_FocalPoint; + + /// The threshold above which voxels along the ray path are integrated. + double m_Threshold; + + /// Pointer to the interpolator + InterpolatorPointer m_Interpolator; + + //JV Pointer to the deformable transform interpolator + DeformableTransformInterpolatorPointer m_DeformableTransformInterpolator; + + + //JV Transform is deformable: fetch interpolated value at transformed intersect + bool m_TransformIsDeformable; + + +private: + RayCastInterpolateImageFunctionWithOrigin( const Self& ); //purposely not implemented + void operator=( const Self& ); //purposely not implemented + + +}; + +} // namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkRayCastInterpolateImageFunctionWithOrigin.txx" +#endif + +#endif diff --git a/itk/clitkRayCastInterpolateImageFunctionWithOrigin.txx b/itk/clitkRayCastInterpolateImageFunctionWithOrigin.txx new file mode 100755 index 0000000..92cb8db --- /dev/null +++ b/itk/clitkRayCastInterpolateImageFunctionWithOrigin.txx @@ -0,0 +1,1706 @@ +/*========================================================================= + 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 __clitkRayCastInterpolateImageFunctionWithOrigin_txx +#define __clitkRayCastInterpolateImageFunctionWithOrigin_txx +#include "clitkRayCastInterpolateImageFunctionWithOrigin.h" +#include "itkContinuousIndex.h" +#include "vnl/vnl_math.h" + + +// Put the helper class in an anonymous namespace so that it is not +// exposed to the user +namespace { + + /** \class Helper class to maintain state when casting a ray. + * This helper class keeps the RayCastInterpolateImageFunctionWithOrigin thread safe. + */ + template + class RayCastHelper + { + public: + /** Constants for the image dimensions */ + itkStaticConstMacro(InputImageDimension, unsigned int, + TInputImage::ImageDimension); + + /** + * Type of the Transform Base class + * The fixed image should be a 3D image + */ + typedef itk::Transform TransformType; + + typedef typename TransformType::Pointer TransformPointer; + typedef typename TransformType::InputPointType InputPointType; + typedef typename TransformType::OutputPointType OutputPointType; + typedef typename TransformType::ParametersType TransformParametersType; + typedef typename TransformType::JacobianType TransformJacobianType; + + typedef typename TInputImage::SizeType SizeType; + typedef itk::Vector DirectionType; + typedef itk::Point PointType; + + typedef TInputImage InputImageType; + typedef typename InputImageType::PixelType PixelType; + typedef typename InputImageType::IndexType IndexType; + typedef itk::ContinuousIndex ContinuousIndexType; + + + //JV Add an interpolator for the deformable transform + typedef itk::InterpolateImageFunction InterpolatorType; + typedef typename InterpolatorType::Pointer InterpolatorPointer; + + + /** + * Set the image class + */ + void SetImage(const InputImageType *input) + { + m_Image = input; + } + + /** + * Initialise the ray using the position and direction of a line. + * + * \param RayPosn The position of the ray in 3D (mm). + * \param RayDirn The direction of the ray in 3D (mm). + * + * \return True if this is a valid ray. + */ + bool SetRay(OutputPointType RayPosn, DirectionType RayDirn); + + + /** \brief + * Integrate the interpolated intensities along the ray and + * return the result. + * + * This routine can be called after instantiating the ray and + * calling SetProjectionCoord2D() or Reset(). It may then be called + * as many times thereafter for different 2D projection + * coordinates. + * + * \param integral The integrated intensities along the ray. + * + * \return True if a valid ray was specified. + */ + bool Integrate(double &integral) + { + return IntegrateAboveThreshold(integral, 0); + }; + + + /** \brief + * Integrate the interpolated intensities above a given threshold, + * along the ray and return the result. + * + * This routine can be called after instantiating the ray and + * calling SetProjectionCoord2D() or Reset(). It may then be called + * as many times thereafter for different 2D projection + * coordinates. + * + * \param integral The integrated intensities along the ray. + * \param threshold The integration threshold [default value: 0] + * + * \return True if a valid ray was specified. + */ + bool IntegrateAboveThreshold(double &integral, double threshold); + + /** \brief + * Increment each of the intensities of the 4 planar voxels + * surrounding the current ray point. + * + * \parameter increment Intensity increment for each of the current 4 voxels + */ + void IncrementIntensities(double increment=1); + + /// Reset the iterator to the start of the ray. + void Reset(void); + + /// Return the interpolated intensity of the current ray point. + double GetCurrentIntensity(void) const; + + /// Return the ray point spacing in mm + double GetRayPointSpacing(void) const { + typename InputImageType::SpacingType spacing=this->m_Image->GetSpacing(); + + if (m_ValidRay) + return vcl_sqrt(m_VoxelIncrement[0]*spacing[0]*m_VoxelIncrement[0]*spacing[0] + + m_VoxelIncrement[1]*spacing[1]*m_VoxelIncrement[1]*spacing[1] + + m_VoxelIncrement[2]*spacing[2]*m_VoxelIncrement[2]*spacing[2] ); + else + return 0.; + }; + + /// Set the initial zero state of the object + void ZeroState(); + + /// Initialise the object + void Initialise(void); + + //JV set transform and interpolator + void SetTransformIsDeformable(bool m){m_TransformIsDeformable=m;} + void SetTransform (TransformType* m){m_Transform=m;} + void SetDeformableTransformInterpolator(InterpolatorType* m){m_DeformableTransformInterpolator=m;} + + protected: + /// Calculate the endpoint coordinats of the ray in voxels. + void EndPointsInVoxels(void); + + /** + * Calculate the incremental direction vector in voxels, 'dVoxel', + * required to traverse the ray. + */ + void CalcDirnVector(void); + + /** + * Reduce the length of the ray until both start and end + * coordinates lie inside the volume. + * + * \return True if a valid ray has been, false otherwise. + */ + bool AdjustRayLength(void); + + /** + * Obtain pointers to the four voxels surrounding the point where the ray + * enters the volume. + */ + void InitialiseVoxelPointers(void); + + /// Increment the voxel pointers surrounding the current point on the ray. + void IncrementVoxelPointers(void); + + /// Record volume dimensions and resolution + void RecordVolumeDimensions(void); + + /// Define the corners of the volume + void DefineCorners(void); + + /** \brief + * Calculate the planes which define the volume. + * + * Member function to calculate the equations of the planes of 4 of + * the sides of the volume, calculate the positions of the 8 corners + * of the volume in mm in World, also calculate the values of the + * slopes of the lines which go to make up the volume( defined as + * lines in cube x,y,z dirn and then each of these lines has a slope + * in the world x,y,z dirn [3]) and finally also to return the length + * of the sides of the lines in mm. + */ + void CalcPlanesAndCorners(void); + + /** \brief + * Calculate the ray intercepts with the volume. + * + * See where the ray cuts the volume, check that truncation does not occur, + * if not, then start ray where it first intercepts the volume and set + * x_max to be where it leaves the volume. + * + * \return True if a valid ray has been specified, false otherwise. + */ + bool CalcRayIntercepts(void); + + /** + * The ray is traversed by stepping in the axial direction + * that enables the greatest number of planes in the volume to be + * intercepted. + */ + typedef enum { + UNDEFINED_DIRECTION=0, //!< Undefined + TRANSVERSE_IN_X, //!< x + TRANSVERSE_IN_Y, //!< y + TRANSVERSE_IN_Z, //!< z + LAST_DIRECTION + } TraversalDirection; + + // Cache the image in the structure. Skip the smart pointer for + // efficiency. This inner class will go in/out of scope with every + // call to Evaluate() + const InputImageType *m_Image; + + /// Flag indicating whether the current ray is valid + bool m_ValidRay; + + /** \brief + * The start position of the ray in voxels. + * + * NB. Two of the components of this coordinate (i.e. those lying within + * the planes of voxels being traversed) will be shifted by half a + * voxel. This enables indices of the neighbouring voxels within the plane + * to be determined by simply casting to 'int' and optionally adding 1. + */ + double m_RayVoxelStartPosition[3]; + + /** \brief + * The end coordinate of the ray in voxels. + * + * NB. Two of the components of this coordinate (i.e. those lying within + * the planes of voxels being traversed) will be shifted by half a + * voxel. This enables indices of the neighbouring voxels within the plane + * to be determined by simply casting to 'int' and optionally adding 1. + */ + double m_RayVoxelEndPosition[3]; + + + /** \brief + * The current coordinate on the ray in voxels. + * + * NB. Two of the components of this coordinate (i.e. those lying within + * the planes of voxels being traversed) will be shifted by half a + * voxel. This enables indices of the neighbouring voxels within the plane + * to be determined by simply casting to 'int' and optionally adding 1. + */ + double m_Position3Dvox[3]; + + /** The incremental direction vector of the ray in voxels. */ + double m_VoxelIncrement[3]; + + /// The direction in which the ray is incremented thorough the volume (x, y or z). + TraversalDirection m_TraversalDirection; + + /// The total number of planes of voxels traversed by the ray. + int m_TotalRayVoxelPlanes; + + /// The current number of planes of voxels traversed by the ray. + int m_NumVoxelPlanesTraversed; + + /// Pointers to the current four voxels surrounding the ray's trajectory. + const PixelType *m_RayIntersectionVoxels[4]; + + /** + * The voxel coordinate of the bottom-left voxel of the current + * four voxels surrounding the ray's trajectory. + */ + int m_RayIntersectionVoxelIndex[3]; + + /// The dimension in voxels of the 3D volume in along the x axis + int m_NumberOfVoxelsInX; + /// The dimension in voxels of the 3D volume in along the y axis + int m_NumberOfVoxelsInY; + /// The dimension in voxels of the 3D volume in along the z axis + int m_NumberOfVoxelsInZ; + + /// Voxel dimension in x + double m_VoxelDimensionInX; + /// Voxel dimension in y + double m_VoxelDimensionInY; + /// Voxel dimension in z + double m_VoxelDimensionInZ; + + /// The coordinate of the point at which the ray enters the volume in mm. + double m_RayStartCoordInMM[3]; + /// The coordinate of the point at which the ray exits the volume in mm. + double m_RayEndCoordInMM[3]; + + + /** \brief + Planes which define the boundary of the volume in mm + (six planes and four parameters: Ax+By+Cz+D). */ + double m_BoundingPlane[6][4]; + /// The eight corners of the volume (x,y,z coordinates for each). + double m_BoundingCorner[8][3]; + + /// The position of the ray + double m_CurrentRayPositionInMM[3]; + + /// The direction of the ray + double m_RayDirectionInMM[3]; + + //JV transform is deformable + bool m_TransformIsDeformable; + TransformType* m_Transform; + InterpolatorType* m_DeformableTransformInterpolator; + + }; + + /* ----------------------------------------------------------------------- + Initialise() - Initialise the object + ----------------------------------------------------------------------- */ + + template + void + RayCastHelper + ::Initialise(void) + { + // Save the dimensions of the volume and calculate the bounding box + this->RecordVolumeDimensions(); + + // Calculate the planes and corners which define the volume. + this->DefineCorners(); + this->CalcPlanesAndCorners(); + } + + + /* ----------------------------------------------------------------------- + RecordVolumeDimensions() - Record volume dimensions and resolution + ----------------------------------------------------------------------- */ + + template + void + RayCastHelper + ::RecordVolumeDimensions(void) + { + typename InputImageType::SpacingType spacing=this->m_Image->GetSpacing(); + SizeType dim=this->m_Image->GetLargestPossibleRegion().GetSize(); + + m_NumberOfVoxelsInX = dim[0]; + m_NumberOfVoxelsInY = dim[1]; + m_NumberOfVoxelsInZ = dim[2]; + + m_VoxelDimensionInX = spacing[0]; + m_VoxelDimensionInY = spacing[1]; + m_VoxelDimensionInZ = spacing[2]; + } + + + /* ----------------------------------------------------------------------- + DefineCorners() - Define the corners of the volume + ----------------------------------------------------------------------- */ + + template + void + RayCastHelper + ::DefineCorners(void) + { + // Define corner positions as if at the origin + + m_BoundingCorner[0][0] = + m_BoundingCorner[1][0] = + m_BoundingCorner[2][0] = + m_BoundingCorner[3][0] = 0; + + m_BoundingCorner[4][0] = + m_BoundingCorner[5][0] = + m_BoundingCorner[6][0] = + m_BoundingCorner[7][0] = m_VoxelDimensionInX*m_NumberOfVoxelsInX; + + m_BoundingCorner[1][1] = + m_BoundingCorner[3][1] = + m_BoundingCorner[5][1] = + m_BoundingCorner[7][1] = m_VoxelDimensionInY*m_NumberOfVoxelsInY; + + m_BoundingCorner[0][1] = + m_BoundingCorner[2][1] = + m_BoundingCorner[4][1] = + m_BoundingCorner[6][1] = 0; + + m_BoundingCorner[0][2] = + m_BoundingCorner[1][2] = + m_BoundingCorner[4][2] = + m_BoundingCorner[5][2] = + m_VoxelDimensionInZ*m_NumberOfVoxelsInZ; + + m_BoundingCorner[2][2] = + m_BoundingCorner[3][2] = + m_BoundingCorner[6][2] = + m_BoundingCorner[7][2] = 0; + + } + + /* ----------------------------------------------------------------------- + CalcPlanesAndCorners() - Calculate the planes and corners of the volume. + ----------------------------------------------------------------------- */ + + template + void + RayCastHelper + ::CalcPlanesAndCorners(void) + { + int j; + + + // find the equations of the planes + + int c1=0, c2=0, c3=0; + + for (j=0; j<6; j++) + { // loop around for planes + switch (j) + { // which corners to take + case 0: + c1=1; c2=2; c3=3; + break; + case 1: + c1=4; c2=5; c3=6; + break; + case 2: + c1=5; c2=3; c3=7; + break; + case 3: + c1=2; c2=4; c3=6; + break; + case 4: + c1=1; c2=5; c3=0; + break; + case 5: + c1=3; c2=7; c3=2; + break; + } + + + double line1x, line1y, line1z; + double line2x, line2y, line2z; + + // lines from one corner to another in x,y,z dirns + line1x = m_BoundingCorner[c1][0] - m_BoundingCorner[c2][0]; + line2x = m_BoundingCorner[c1][0] - m_BoundingCorner[c3][0]; + + line1y = m_BoundingCorner[c1][1] - m_BoundingCorner[c2][1]; + line2y = m_BoundingCorner[c1][1] - m_BoundingCorner[c3][1]; + + line1z = m_BoundingCorner[c1][2] - m_BoundingCorner[c2][2]; + line2z = m_BoundingCorner[c1][2] - m_BoundingCorner[c3][2]; + + double A, B, C, D; + + // take cross product + A = line1y*line2z - line2y*line1z; + B = line2x*line1z - line1x*line2z; + C = line1x*line2y - line2x*line1y; + + // find constant + D = -( A*m_BoundingCorner[c1][0] + + B*m_BoundingCorner[c1][1] + + C*m_BoundingCorner[c1][2] ); + + // initialise plane value and normalise + m_BoundingPlane[j][0] = A/vcl_sqrt(A*A + B*B + C*C); + m_BoundingPlane[j][1] = B/vcl_sqrt(A*A + B*B + C*C); + m_BoundingPlane[j][2] = C/vcl_sqrt(A*A + B*B + C*C); + m_BoundingPlane[j][3] = D/vcl_sqrt(A*A + B*B + C*C); + + if ( (A*A + B*B + C*C) == 0 ) + { + itk::ExceptionObject err(__FILE__, __LINE__); + err.SetLocation( ITK_LOCATION ); + err.SetDescription( "Division by zero (planes) " + "- CalcPlanesAndCorners()."); + throw err; + } + } + + } + + + /* ----------------------------------------------------------------------- + CalcRayIntercepts() - Calculate the ray intercepts with the volume. + ----------------------------------------------------------------------- */ + + template + bool + RayCastHelper + ::CalcRayIntercepts() + { + double maxInterDist, interDist; + double cornerVect[4][3]; + int cross[4][3], noInterFlag[6]; + int nSidesCrossed, crossFlag, c[4]; + double ax, ay, az, bx, by, bz; + double cubeInter[6][3]; + double denom; + + int i,j, k; + int NoSides = 6; // =6 to allow truncation: =4 to remove truncated rays + + // Calculate intercept of ray with planes + + double interceptx[6], intercepty[6], interceptz[6]; + double d[6]; + + for( j=0; j=0 + && cross[1][i]>=0 + && cross[2][i]>=0 + && cross[3][i]>=0) ) + { + crossFlag++; + } + } + + + if( crossFlag==3 && noInterFlag[j]==1 ) + { + cubeInter[nSidesCrossed][0] = interceptx[j]; + cubeInter[nSidesCrossed][1] = intercepty[j]; + cubeInter[nSidesCrossed][2] = interceptz[j]; + nSidesCrossed++; + } + + } // End of loop over all four planes + + m_RayStartCoordInMM[0] = cubeInter[0][0]; + m_RayStartCoordInMM[1] = cubeInter[0][1]; + m_RayStartCoordInMM[2] = cubeInter[0][2]; + + m_RayEndCoordInMM[0] = cubeInter[1][0]; + m_RayEndCoordInMM[1] = cubeInter[1][1]; + m_RayEndCoordInMM[2] = cubeInter[1][2]; + + if( nSidesCrossed >= 5 ) + { + std::cerr << "WARNING: No. of sides crossed equals: " << nSidesCrossed << std::endl; + } + + // If 'nSidesCrossed' is larger than 2, this means that the ray goes through + // a corner of the volume and due to rounding errors, the ray is + // deemed to go through more than two planes. To obtain the correct + // start and end positions we choose the two intercept values which + // are furthest from each other. + + + if( nSidesCrossed >= 3 ) + { + maxInterDist = 0; + for( j=0; j maxInterDist ) + { + maxInterDist = interDist; + + m_RayStartCoordInMM[0] = cubeInter[j][0]; + m_RayStartCoordInMM[1] = cubeInter[j][1]; + m_RayStartCoordInMM[2] = cubeInter[j][2]; + + m_RayEndCoordInMM[0] = cubeInter[k][0]; + m_RayEndCoordInMM[1] = cubeInter[k][1]; + m_RayEndCoordInMM[2] = cubeInter[k][2]; + } + } + } + nSidesCrossed = 2; + } + + if (nSidesCrossed == 2 ) + { + return true; + } + else + { + return false; + } + } + + + /* ----------------------------------------------------------------------- + SetRay() - Set the position and direction of the ray + ----------------------------------------------------------------------- */ + + template + bool + RayCastHelper + ::SetRay(OutputPointType RayPosn, DirectionType RayDirn) + { + + // Store the position and direction of the ray + typename TInputImage::SpacingType spacing=this->m_Image->GetSpacing(); + SizeType dim=this->m_Image->GetLargestPossibleRegion().GetSize(); + + // we need to translate the _center_ of the volume to the origin + m_NumberOfVoxelsInX = dim[0]; + m_NumberOfVoxelsInY = dim[1]; + m_NumberOfVoxelsInZ = dim[2]; + + m_VoxelDimensionInX = spacing[0]; + m_VoxelDimensionInY = spacing[1]; + m_VoxelDimensionInZ = spacing[2]; + + // (Aviv) Incorporating a fix by Jian Wu + // http://public.kitware.com/pipermail/insight-users/2006-March/017265.html + m_CurrentRayPositionInMM[0] = RayPosn[0]; + m_CurrentRayPositionInMM[1] = RayPosn[1]; + m_CurrentRayPositionInMM[2] = RayPosn[2]; + + m_RayDirectionInMM[0] = RayDirn[0]; + m_RayDirectionInMM[1] = RayDirn[1]; + m_RayDirectionInMM[2] = RayDirn[2]; + + // Compute the ray path for this coordinate in mm + + m_ValidRay = this->CalcRayIntercepts(); + + if (! m_ValidRay) + { + Reset(); + return false; + } + + // Convert the start and end coordinates of the ray to voxels + + this->EndPointsInVoxels(); + + /* Calculate the ray direction vector in voxels and hence the voxel + increment required to traverse the ray, and the number of + interpolation points on the ray. + + This routine also shifts the coordinate frame by half a voxel for + two of the directional components (i.e. those lying within the + planes of voxels being traversed). */ + + this->CalcDirnVector(); + + + /* Reduce the length of the ray until both start and end + coordinates lie inside the volume. */ + + m_ValidRay = this->AdjustRayLength(); + + // Reset the iterator to the start of the ray. + + Reset(); + + return m_ValidRay; + } + + + /* ----------------------------------------------------------------------- + EndPointsInVoxels() - Convert the endpoints to voxels + ----------------------------------------------------------------------- */ + + template + void + RayCastHelper + ::EndPointsInVoxels(void) + { + m_RayVoxelStartPosition[0] = m_RayStartCoordInMM[0]/m_VoxelDimensionInX; + m_RayVoxelStartPosition[1] = m_RayStartCoordInMM[1]/m_VoxelDimensionInY; + m_RayVoxelStartPosition[2] = m_RayStartCoordInMM[2]/m_VoxelDimensionInZ; + + m_RayVoxelEndPosition[0] = m_RayEndCoordInMM[0]/m_VoxelDimensionInX; + m_RayVoxelEndPosition[1] = m_RayEndCoordInMM[1]/m_VoxelDimensionInY; + m_RayVoxelEndPosition[2] = m_RayEndCoordInMM[2]/m_VoxelDimensionInZ; + + } + + + /* ----------------------------------------------------------------------- + CalcDirnVector() - Calculate the incremental direction vector in voxels. + ----------------------------------------------------------------------- */ + + template + void + RayCastHelper + ::CalcDirnVector(void) + { + double xNum, yNum, zNum; + + // Calculate the number of voxels in each direction + + xNum = vcl_fabs(m_RayVoxelStartPosition[0] - m_RayVoxelEndPosition[0]); + yNum = vcl_fabs(m_RayVoxelStartPosition[1] - m_RayVoxelEndPosition[1]); + zNum = vcl_fabs(m_RayVoxelStartPosition[2] - m_RayVoxelEndPosition[2]); + + // The direction iterated in is that with the greatest number of voxels + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + // Iterate in X direction + + if( (xNum >= yNum) && (xNum >= zNum) ) + { + if( m_RayVoxelStartPosition[0] < m_RayVoxelEndPosition[0] ) + { + m_VoxelIncrement[0] = 1; + + m_VoxelIncrement[1] + = (m_RayVoxelStartPosition[1] + - m_RayVoxelEndPosition[1])/(m_RayVoxelStartPosition[0] + - m_RayVoxelEndPosition[0]); + + m_VoxelIncrement[2] + = (m_RayVoxelStartPosition[2] + - m_RayVoxelEndPosition[2])/(m_RayVoxelStartPosition[0] + - m_RayVoxelEndPosition[0]); + } + else + { + m_VoxelIncrement[0] = -1; + + m_VoxelIncrement[1] + = -(m_RayVoxelStartPosition[1] + - m_RayVoxelEndPosition[1])/(m_RayVoxelStartPosition[0] + - m_RayVoxelEndPosition[0]); + + m_VoxelIncrement[2] + = -(m_RayVoxelStartPosition[2] + - m_RayVoxelEndPosition[2])/(m_RayVoxelStartPosition[0] + - m_RayVoxelEndPosition[0]); + } + + // This section is to alter the start position in order to + // place the center of the voxels in there correct positions, + // rather than placing them at the corner of voxels which is + // what happens if this is not carried out. The reason why + // x has no -0.5 is because this is the direction we are going + // to iterate in and therefore we wish to go from center to + // center rather than finding the surrounding voxels. + + m_RayVoxelStartPosition[1] += ( (int)m_RayVoxelStartPosition[0] + - m_RayVoxelStartPosition[0])*m_VoxelIncrement[1]*m_VoxelIncrement[0] + + 0.5*m_VoxelIncrement[1] - 0.5; + + m_RayVoxelStartPosition[2] += ( (int)m_RayVoxelStartPosition[0] + - m_RayVoxelStartPosition[0])*m_VoxelIncrement[2]*m_VoxelIncrement[0] + + 0.5*m_VoxelIncrement[2] - 0.5; + + m_RayVoxelStartPosition[0] = (int)m_RayVoxelStartPosition[0] + 0.5*m_VoxelIncrement[0]; + + m_TotalRayVoxelPlanes = (int)xNum; + + m_TraversalDirection = TRANSVERSE_IN_X; + } + + // Iterate in Y direction + + else if( (yNum >= xNum) && (yNum >= zNum) ) + { + + if( m_RayVoxelStartPosition[1] < m_RayVoxelEndPosition[1] ) + { + m_VoxelIncrement[1] = 1; + + m_VoxelIncrement[0] + = (m_RayVoxelStartPosition[0] + - m_RayVoxelEndPosition[0])/(m_RayVoxelStartPosition[1] + - m_RayVoxelEndPosition[1]); + + m_VoxelIncrement[2] + = (m_RayVoxelStartPosition[2] + - m_RayVoxelEndPosition[2])/(m_RayVoxelStartPosition[1] + - m_RayVoxelEndPosition[1]); + } + else + { + m_VoxelIncrement[1] = -1; + + m_VoxelIncrement[0] + = -(m_RayVoxelStartPosition[0] + - m_RayVoxelEndPosition[0])/(m_RayVoxelStartPosition[1] + - m_RayVoxelEndPosition[1]); + + m_VoxelIncrement[2] + = -(m_RayVoxelStartPosition[2] + - m_RayVoxelEndPosition[2])/(m_RayVoxelStartPosition[1] + - m_RayVoxelEndPosition[1]); + } + + + m_RayVoxelStartPosition[0] += ( (int)m_RayVoxelStartPosition[1] + - m_RayVoxelStartPosition[1])*m_VoxelIncrement[0]*m_VoxelIncrement[1] + + 0.5*m_VoxelIncrement[0] - 0.5; + + m_RayVoxelStartPosition[2] += ( (int)m_RayVoxelStartPosition[1] + - m_RayVoxelStartPosition[1])*m_VoxelIncrement[2]*m_VoxelIncrement[1] + + 0.5*m_VoxelIncrement[2] - 0.5; + + m_RayVoxelStartPosition[1] = (int)m_RayVoxelStartPosition[1] + 0.5*m_VoxelIncrement[1]; + + m_TotalRayVoxelPlanes = (int)yNum; + + m_TraversalDirection = TRANSVERSE_IN_Y; + } + + // Iterate in Z direction + + else + { + + if( m_RayVoxelStartPosition[2] < m_RayVoxelEndPosition[2] ) + { + m_VoxelIncrement[2] = 1; + + m_VoxelIncrement[0] + = (m_RayVoxelStartPosition[0] + - m_RayVoxelEndPosition[0])/(m_RayVoxelStartPosition[2] + - m_RayVoxelEndPosition[2]); + + m_VoxelIncrement[1] + = (m_RayVoxelStartPosition[1] + - m_RayVoxelEndPosition[1])/(m_RayVoxelStartPosition[2] + - m_RayVoxelEndPosition[2]); + } + else + { + m_VoxelIncrement[2] = -1; + + m_VoxelIncrement[0] + = -(m_RayVoxelStartPosition[0] + - m_RayVoxelEndPosition[0])/(m_RayVoxelStartPosition[2] + - m_RayVoxelEndPosition[2]); + + m_VoxelIncrement[1] + = -(m_RayVoxelStartPosition[1] + - m_RayVoxelEndPosition[1])/(m_RayVoxelStartPosition[2] + - m_RayVoxelEndPosition[2]); + } + + m_RayVoxelStartPosition[0] += ( (int)m_RayVoxelStartPosition[2] + - m_RayVoxelStartPosition[2])*m_VoxelIncrement[0]*m_VoxelIncrement[2] + + 0.5*m_VoxelIncrement[0] - 0.5; + + m_RayVoxelStartPosition[1] += ( (int)m_RayVoxelStartPosition[2] + - m_RayVoxelStartPosition[2])*m_VoxelIncrement[1]*m_VoxelIncrement[2] + + 0.5*m_VoxelIncrement[1] - 0.5; + + m_RayVoxelStartPosition[2] = (int)m_RayVoxelStartPosition[2] + 0.5*m_VoxelIncrement[2]; + + m_TotalRayVoxelPlanes = (int)zNum; + + m_TraversalDirection = TRANSVERSE_IN_Z; + } + } + + + /* ----------------------------------------------------------------------- + AdjustRayLength() - Ensure that the ray lies within the volume + ----------------------------------------------------------------------- */ + + template + bool + RayCastHelper + ::AdjustRayLength(void) + { + bool startOK, endOK; + + int Istart[3]; + int Idirn[3]; + + if (m_TraversalDirection == TRANSVERSE_IN_X) + { + Idirn[0] = 0; + Idirn[1] = 1; + Idirn[2] = 1; + } + else if (m_TraversalDirection == TRANSVERSE_IN_Y) + { + Idirn[0] = 1; + Idirn[1] = 0; + Idirn[2] = 1; + } + else if (m_TraversalDirection == TRANSVERSE_IN_Z) + { + Idirn[0] = 1; + Idirn[1] = 1; + Idirn[2] = 0; + } + else + { + itk::ExceptionObject err(__FILE__, __LINE__); + err.SetLocation( ITK_LOCATION ); + err.SetDescription( "The ray traversal direction is unset " + "- AdjustRayLength()."); + throw err; + return false; + } + + + do + { + + startOK = false; + endOK = false; + + Istart[0] = (int) vcl_floor(m_RayVoxelStartPosition[0]); + Istart[1] = (int) vcl_floor(m_RayVoxelStartPosition[1]); + Istart[2] = (int) vcl_floor(m_RayVoxelStartPosition[2]); + + if( (Istart[0] >= 0) && (Istart[0] + Idirn[0] < m_NumberOfVoxelsInX) && + (Istart[1] >= 0) && (Istart[1] + Idirn[1] < m_NumberOfVoxelsInY) && + (Istart[2] >= 0) && (Istart[2] + Idirn[2] < m_NumberOfVoxelsInZ) ) + { + + startOK = true; + } + else + { + m_RayVoxelStartPosition[0] += m_VoxelIncrement[0]; + m_RayVoxelStartPosition[1] += m_VoxelIncrement[1]; + m_RayVoxelStartPosition[2] += m_VoxelIncrement[2]; + + m_TotalRayVoxelPlanes--; + } + + Istart[0] = (int) vcl_floor(m_RayVoxelStartPosition[0] + + m_TotalRayVoxelPlanes*m_VoxelIncrement[0]); + + Istart[1] = (int) vcl_floor(m_RayVoxelStartPosition[1] + + m_TotalRayVoxelPlanes*m_VoxelIncrement[1]); + + Istart[2] = (int) vcl_floor(m_RayVoxelStartPosition[2] + + m_TotalRayVoxelPlanes*m_VoxelIncrement[2]); + + if( (Istart[0] >= 0) && (Istart[0] + Idirn[0] < m_NumberOfVoxelsInX) && + (Istart[1] >= 0) && (Istart[1] + Idirn[1] < m_NumberOfVoxelsInY) && + (Istart[2] >= 0) && (Istart[2] + Idirn[2] < m_NumberOfVoxelsInZ) ) + { + + endOK = true; + } + else + { + m_TotalRayVoxelPlanes--; + } + + } while ( (! (startOK && endOK)) && (m_TotalRayVoxelPlanes > 1) ); + + + return (startOK && endOK); + } + + + /* ----------------------------------------------------------------------- + Reset() - Reset the iterator to the start of the ray. + ----------------------------------------------------------------------- */ + + template + void + RayCastHelper + ::Reset(void) + { + int i; + + m_NumVoxelPlanesTraversed = -1; + + // If this is a valid ray... + + if (m_ValidRay) + { + for (i=0; i<3; i++) + { + m_Position3Dvox[i] = m_RayVoxelStartPosition[i]; + } + this->InitialiseVoxelPointers(); + } + + // otherwise set parameters to zero + + else + { + for (i=0; i<3; i++) + { + m_RayVoxelStartPosition[i] = 0.; + } + for (i=0; i<3; i++) + { + m_RayVoxelEndPosition[i] = 0.; + } + for (i=0; i<3; i++) + { + m_VoxelIncrement[i] = 0.; + } + m_TraversalDirection = UNDEFINED_DIRECTION; + + m_TotalRayVoxelPlanes = 0; + + for (i=0; i<4; i++) + { + m_RayIntersectionVoxels[i] = 0; + } + for (i=0; i<3; i++) + { + m_RayIntersectionVoxelIndex[i] = 0; + } + } + } + + + /* ----------------------------------------------------------------------- + InitialiseVoxelPointers() - Obtain pointers to the first four voxels + ----------------------------------------------------------------------- */ + + template + void + RayCastHelper + ::InitialiseVoxelPointers(void) + { + + //JV don't do anything if deformable + if(!m_TransformIsDeformable) + { + IndexType index; + + int Ix, Iy, Iz; + + Ix = (int)(m_RayVoxelStartPosition[0]); + Iy = (int)(m_RayVoxelStartPosition[1]); + Iz = (int)(m_RayVoxelStartPosition[2]); + + m_RayIntersectionVoxelIndex[0] = Ix; + m_RayIntersectionVoxelIndex[1] = Iy; + m_RayIntersectionVoxelIndex[2] = Iz; + + switch( m_TraversalDirection ) + { + case TRANSVERSE_IN_X: + { + + if( (Ix >= 0) && (Ix < m_NumberOfVoxelsInX) && + (Iy >= 0) && (Iy + 1 < m_NumberOfVoxelsInY) && + (Iz >= 0) && (Iz + 1 < m_NumberOfVoxelsInZ)) + { + index[0]=Ix; index[1]=Iy; index[2]=Iz; + m_RayIntersectionVoxels[0] + = this->m_Image->GetBufferPointer() + this->m_Image->ComputeOffset(index); + + index[0]=Ix; index[1]=Iy+1; index[2]=Iz; + m_RayIntersectionVoxels[1] + = ( this->m_Image->GetBufferPointer() + this->m_Image->ComputeOffset(index) ); + + index[0]=Ix; index[1]=Iy; index[2]=Iz+1; + m_RayIntersectionVoxels[2] + = ( this->m_Image->GetBufferPointer() + this->m_Image->ComputeOffset(index) ); + + index[0]=Ix; index[1]=Iy+1; index[2]=Iz+1; + m_RayIntersectionVoxels[3] + = ( this->m_Image->GetBufferPointer() + this->m_Image->ComputeOffset(index) ); + } + else + { + m_RayIntersectionVoxels[0] = + m_RayIntersectionVoxels[1] = + m_RayIntersectionVoxels[2] = + m_RayIntersectionVoxels[3] = NULL; + } + break; + } + + case TRANSVERSE_IN_Y: + { + + if( (Ix >= 0) && (Ix + 1 < m_NumberOfVoxelsInX) && + (Iy >= 0) && (Iy < m_NumberOfVoxelsInY) && + (Iz >= 0) && (Iz + 1 < m_NumberOfVoxelsInZ)) + { + + index[0]=Ix; index[1]=Iy; index[2]=Iz; + m_RayIntersectionVoxels[0] = ( this->m_Image->GetBufferPointer() + + this->m_Image->ComputeOffset(index) ); + + index[0]=Ix+1; index[1]=Iy; index[2]=Iz; + m_RayIntersectionVoxels[1] = ( this->m_Image->GetBufferPointer() + + this->m_Image->ComputeOffset(index) ); + + index[0]=Ix; index[1]=Iy; index[2]=Iz+1; + m_RayIntersectionVoxels[2] = ( this->m_Image->GetBufferPointer() + + this->m_Image->ComputeOffset(index) ); + + index[0]=Ix+1; index[1]=Iy; index[2]=Iz+1; + m_RayIntersectionVoxels[3] = ( this->m_Image->GetBufferPointer() + + this->m_Image->ComputeOffset(index) ); + } + else + { + m_RayIntersectionVoxels[0] + = m_RayIntersectionVoxels[1] + = m_RayIntersectionVoxels[2] + = m_RayIntersectionVoxels[3] = NULL; + } + break; + } + + case TRANSVERSE_IN_Z: + { + + if( (Ix >= 0) && (Ix + 1 < m_NumberOfVoxelsInX) && + (Iy >= 0) && (Iy + 1 < m_NumberOfVoxelsInY) && + (Iz >= 0) && (Iz < m_NumberOfVoxelsInZ)) + { + + index[0]=Ix; index[1]=Iy; index[2]=Iz; + m_RayIntersectionVoxels[0] = ( this->m_Image->GetBufferPointer() + + this->m_Image->ComputeOffset(index) ); + + index[0]=Ix+1; index[1]=Iy; index[2]=Iz; + m_RayIntersectionVoxels[1] = ( this->m_Image->GetBufferPointer() + + this->m_Image->ComputeOffset(index) ); + + index[0]=Ix; index[1]=Iy+1; index[2]=Iz; + m_RayIntersectionVoxels[2] = ( this->m_Image->GetBufferPointer() + + this->m_Image->ComputeOffset(index) ); + + index[0]=Ix+1; index[1]=Iy+1; index[2]=Iz; + m_RayIntersectionVoxels[3] = ( this->m_Image->GetBufferPointer() + + this->m_Image->ComputeOffset(index) ); + + } + else + { + m_RayIntersectionVoxels[0] + = m_RayIntersectionVoxels[1] + = m_RayIntersectionVoxels[2] + = m_RayIntersectionVoxels[3] = NULL; + } + break; + } + + default: + { + itk::ExceptionObject err(__FILE__, __LINE__); + err.SetLocation( ITK_LOCATION ); + err.SetDescription( "The ray traversal direction is unset " + "- InitialiseVoxelPointers()."); + throw err; + return; + } + } + + }//JV end if deformable + } + + /* ----------------------------------------------------------------------- + IncrementVoxelPointers() - Increment the voxel pointers + ----------------------------------------------------------------------- */ + + template + void + RayCastHelper + ::IncrementVoxelPointers(void) + { + + + double xBefore = m_Position3Dvox[0]; + double yBefore = m_Position3Dvox[1]; + double zBefore = m_Position3Dvox[2]; + + m_Position3Dvox[0] += m_VoxelIncrement[0]; + m_Position3Dvox[1] += m_VoxelIncrement[1]; + m_Position3Dvox[2] += m_VoxelIncrement[2]; + + + //JV don't do anything to pointers if deformable + if(!m_TransformIsDeformable) + { + int dx = ((int) m_Position3Dvox[0]) - ((int) xBefore); + int dy = ((int) m_Position3Dvox[1]) - ((int) yBefore); + int dz = ((int) m_Position3Dvox[2]) - ((int) zBefore); + + m_RayIntersectionVoxelIndex[0] += dx; + m_RayIntersectionVoxelIndex[1] += dy; + m_RayIntersectionVoxelIndex[2] += dz; + + int totalRayVoxelPlanes + = dx + dy*m_NumberOfVoxelsInX + dz*m_NumberOfVoxelsInX*m_NumberOfVoxelsInY; + + m_RayIntersectionVoxels[0] += totalRayVoxelPlanes; + m_RayIntersectionVoxels[1] += totalRayVoxelPlanes; + m_RayIntersectionVoxels[2] += totalRayVoxelPlanes; + m_RayIntersectionVoxels[3] += totalRayVoxelPlanes; + }//JV end if deformable + } + + + /* ----------------------------------------------------------------------- + GetCurrentIntensity() - Get the intensity of the current ray point. + ----------------------------------------------------------------------- */ + + template + double + RayCastHelper + ::GetCurrentIntensity(void) const + { + + //DD("In get current intensity"); + //JV fetch the interpolated value by applying the deformable transform + if(m_TransformIsDeformable) + { + //3DPositionVox is in voxels AND shifted half a voxel in plane + typename InputImageType::PointType inputPoint; + // switch( m_TraversalDirection ) + // { + // case TRANSVERSE_IN_X: + // { + // double x = (int)m_Position3Dvox[0] - 0.5*m_VoxelIncrement[0]; + // inputPoint[0]=x*m_VoxelDimensionInX; + + // inputPoint[1] -= ( (int(x)-x)*m_VoxelIncrement[1]*m_VoxelIncrement[0] + // + 0.5*m_VoxelIncrement[1] - 0.5)*m_VoxelDimensionInY; + + // inputPoint[2] -= ( (int(x)-x)*m_VoxelIncrement[2]*m_VoxelIncrement[0] + // + 0.5*m_VoxelIncrement[2] - 0.5)*m_VoxelDimensionInZ; + + // // inputPoint[0]=m_Position3Dvox[0]*m_VoxelDimensionInX; + // // inputPoint[1]=(m_Position3Dvox[1]+0.5)*m_VoxelDimensionInY; + // // inputPoint[2]=(m_Position3Dvox[2]+0.5)*m_VoxelDimensionInZ; + // // DD("X"); + // break; + // } + // case TRANSVERSE_IN_Y: + // { + // double y = (int)m_Position3Dvox[1] - 0.5*m_VoxelIncrement[1]; + // double y=m_Position3Dvox[1]; + // inputPoint[1]=y*m_VoxelDimensionInY; + + // inputPoint[0] = (m_Position3Dvox[0]- ((int)y-y)*m_VoxelIncrement[0]*m_VoxelIncrement[1] + // + 0.5*m_VoxelIncrement[0] - 0.5) * m_VoxelDimensionInX; + + // inputPoint[2] = (m_Position3Dvox[2]- ((int)y-y)*m_VoxelIncrement[2]*m_VoxelIncrement[1] + // + 0.5*m_VoxelIncrement[2] - 0.5) * m_VoxelDimensionInZ; + + // // inputPoint[0]=(m_Position3Dvox[0]+0)*m_VoxelDimensionInX; + // // inputPoint[1]=m_Position3Dvox[1]*m_VoxelDimensionInY; + // // inputPoint[2]=(m_Position3Dvox[2]+0.5)*m_VoxelDimensionInZ; + + // break; + // } + // case TRANSVERSE_IN_Z: + // { + // double z = (int)m_Position3Dvox[2] - 0.5*m_VoxelIncrement[2]; + // inputPoint[2]=z*m_VoxelDimensionInZ; + + // inputPoint[0] += -( z*m_VoxelIncrement[1]*m_VoxelIncrement[0] + // - 0.5*m_VoxelIncrement[2] + 0.5)*m_VoxelDimensionInZ; + + // inputPoint[1] += -( z*m_VoxelIncrement[1]*m_VoxelIncrement[0] + // - 0.5*m_VoxelIncrement[2] + 0.5)*m_VoxelDimensionInZ; + + // // inputPoint[0]=(m_Position3Dvox[0]+0.5)*m_VoxelDimensionInX; + // // inputPoint[1]=(m_Position3Dvox[1]+0.5)*m_VoxelDimensionInY; + // // inputPoint[2]=m_Position3Dvox[2]*m_VoxelDimensionInZ; + // // DD("Z"); + // break; + // } + + // default: + // { + // itk::ExceptionObject err(__FILE__, __LINE__); + // err.SetLocation( ITK_LOCATION ); + // err.SetDescription( "The ray traversal direction is unset " + // "- GetCurrentIntensity()."); + // throw err; + // return 0; + // } + // } + + + //JV there seems to remain an small offset + inputPoint[0]=(m_Position3Dvox[0])*m_VoxelDimensionInX; + inputPoint[1]=(m_Position3Dvox[1])*m_VoxelDimensionInY; + inputPoint[2]=m_Position3Dvox[2]*m_VoxelDimensionInZ; + //JV work around, call Deformably transform point (no bulk) + typedef clitk::BSplineDeformableTransform DeformableTransformType; + DeformableTransformType* bsplineTransform=dynamic_cast(m_Transform); + typename DeformableTransformType::OutputPointType transformedPoint=bsplineTransform->DeformablyTransformPoint(inputPoint); + + //check wether inside + ContinuousIndexType contIndex; + if (m_Image->TransformPhysicalPointToContinuousIndex(transformedPoint, contIndex)) + //interpolate this position in the input image + return this->m_DeformableTransformInterpolator->EvaluateAtContinuousIndex(contIndex); + else return 0;//m_EdgePaddingValue; + + }//JV end if deformable + + else + { + double a, b, c, d; + double y, z; + + if (! m_ValidRay) + { + return 0; + } + a = (double) (*m_RayIntersectionVoxels[0]); + b = (double) (*m_RayIntersectionVoxels[1] - a); + c = (double) (*m_RayIntersectionVoxels[2] - a); + d = (double) (*m_RayIntersectionVoxels[3] - a - b - c); + + switch( m_TraversalDirection ) + { + case TRANSVERSE_IN_X: + { + y = m_Position3Dvox[1] - vcl_floor(m_Position3Dvox[1]); + z = m_Position3Dvox[2] - vcl_floor(m_Position3Dvox[2]); + break; + } + case TRANSVERSE_IN_Y: + { + y = m_Position3Dvox[0] - vcl_floor(m_Position3Dvox[0]); + z = m_Position3Dvox[2] - vcl_floor(m_Position3Dvox[2]); + break; + } + case TRANSVERSE_IN_Z: + { + y = m_Position3Dvox[0] - vcl_floor(m_Position3Dvox[0]); + z = m_Position3Dvox[1] - vcl_floor(m_Position3Dvox[1]); + break; + } + default: + { + itk::ExceptionObject err(__FILE__, __LINE__); + err.SetLocation( ITK_LOCATION ); + err.SetDescription( "The ray traversal direction is unset " + "- GetCurrentIntensity()."); + throw err; + return 0; + } + } + + return a + b*y + c*z + d*y*z; + } + } + + /* ----------------------------------------------------------------------- + IncrementIntensities() - Increment the intensities of the current ray point + ----------------------------------------------------------------------- */ + + template + void + RayCastHelper + ::IncrementIntensities(double increment) + { + short inc = (short) vcl_floor(increment + 0.5); + + if (! m_ValidRay) + { + return; + } + *m_RayIntersectionVoxels[0] += inc; + *m_RayIntersectionVoxels[1] += inc; + *m_RayIntersectionVoxels[2] += inc; + *m_RayIntersectionVoxels[3] += inc; + + return; + } + + + /* ----------------------------------------------------------------------- + IntegrateAboveThreshold() - Integrate intensities above a threshold. + ----------------------------------------------------------------------- */ + + template + bool + RayCastHelper + ::IntegrateAboveThreshold(double &integral, double threshold) + { + double intensity; + // double posn3D_x, posn3D_y, posn3D_z; + + integral = 0.; + + // Check if this is a valid ray + + if (! m_ValidRay) + { + return false; + } + /* Step along the ray as quickly as possible + integrating the interpolated intensities. */ + + for (m_NumVoxelPlanesTraversed=0; + m_NumVoxelPlanesTraversedGetCurrentIntensity(); + + if (intensity > threshold) + { + integral += intensity - threshold; + } + this->IncrementVoxelPointers(); + } + + /* The ray passes through the volume one plane of voxels at a time, + however, if its moving diagonally the ray points will be further + apart so account for this by scaling by the distance moved. */ + + integral *= this->GetRayPointSpacing(); + + return true; + } + + /* ----------------------------------------------------------------------- + ZeroState() - Set the default (zero) state of the object + ----------------------------------------------------------------------- */ + + template + void + RayCastHelper + ::ZeroState() + { + int i; + + m_ValidRay = false; + + m_NumberOfVoxelsInX = 0; + m_NumberOfVoxelsInY = 0; + m_NumberOfVoxelsInZ = 0; + + m_VoxelDimensionInX = 0; + m_VoxelDimensionInY = 0; + m_VoxelDimensionInZ = 0; + + for (i=0; i<3; i++) + { + m_CurrentRayPositionInMM[i] = 0.; + } + for (i=0; i<3; i++) + { + m_RayDirectionInMM[i] = 0.; + } + for (i=0; i<3; i++) + { + m_RayVoxelStartPosition[i] = 0.; + } + for (i=0; i<3; i++) + { + m_RayVoxelEndPosition[i] = 0.; + } + for (i=0; i<3; i++) + { + m_VoxelIncrement[i] = 0.; + } + m_TraversalDirection = UNDEFINED_DIRECTION; + + m_TotalRayVoxelPlanes = 0; + m_NumVoxelPlanesTraversed = -1; + + for (i=0; i<4; i++) + { + m_RayIntersectionVoxels[i] = 0; + } + for (i=0; i<3; i++) + { + m_RayIntersectionVoxelIndex[i] = 0; + } + } +}; // end of anonymous namespace + + +namespace clitk +{ + + /************************************************************************** + * + * + * Rest of this code is the actual RayCastInterpolateImageFunctionWithOrigin + * class + * + * + **************************************************************************/ + + /* ----------------------------------------------------------------------- + Constructor + ----------------------------------------------------------------------- */ + + template + RayCastInterpolateImageFunctionWithOrigin< TInputImage, TCoordRep > + ::RayCastInterpolateImageFunctionWithOrigin() + { + m_Threshold = 0.; + + m_FocalPoint[0] = 0.; + m_FocalPoint[1] = 0.; + m_FocalPoint[2] = 0.; + + //JV + m_TransformIsDeformable=false; + } + + + /* ----------------------------------------------------------------------- + PrintSelf + ----------------------------------------------------------------------- */ + + template + void + RayCastInterpolateImageFunctionWithOrigin< TInputImage, TCoordRep > + ::PrintSelf(std::ostream& os, itk::Indent indent) const + { + this->Superclass::PrintSelf(os,indent); + + os << indent << "Threshold: " << m_Threshold << std::endl; + os << indent << "FocalPoint: " << m_FocalPoint << std::endl; + os << indent << "Transform: " << m_Transform.GetPointer() << std::endl; + os << indent << "Interpolator: " << m_Interpolator.GetPointer() << std::endl; + + } + + /* ----------------------------------------------------------------------- + Evaluate at image index position + ----------------------------------------------------------------------- */ + + template + typename RayCastInterpolateImageFunctionWithOrigin< TInputImage, TCoordRep > + ::OutputType + RayCastInterpolateImageFunctionWithOrigin< TInputImage, TCoordRep > + ::Evaluate( const PointType& point ) const + { + double integral = 0; + + OutputPointType transformedFocalPoint + = m_Transform->TransformPoint( m_FocalPoint ); + + DirectionType direction = transformedFocalPoint - point; + + RayCastHelper ray; + + //JV + ray.SetTransformIsDeformable(m_TransformIsDeformable); + if (m_TransformIsDeformable) + { + ray.SetTransform(m_Transform); + ray.SetDeformableTransformInterpolator(m_DeformableTransformInterpolator); + } + //JV + + ray.SetImage( this->m_Image ); + ray.ZeroState(); + + ray.Initialise(); + // (Aviv) Added support for images with non-zero origin + // ray.SetRay(point, direction); + ray.SetRay(point - this->m_Image->GetOrigin().GetVectorFromOrigin(), direction); + ray.IntegrateAboveThreshold(integral, m_Threshold); + + return ( static_cast( integral )); + } + + template + typename RayCastInterpolateImageFunctionWithOrigin< TInputImage, TCoordRep > + ::OutputType + RayCastInterpolateImageFunctionWithOrigin< TInputImage, TCoordRep > + ::EvaluateAtContinuousIndex( const ContinuousIndexType& index ) const + { + OutputPointType point; + this->m_Image->TransformContinuousIndexToPhysicalPoint(index, point); + + return this->Evaluate( point ); + } + +} // namespace clitk + + +#endif diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 1bbad25..b273429 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -11,36 +11,32 @@ ADD_EXECUTABLE(clitkImageInfo clitkImageInfo.cxx ${clitkImageInfo_GGO_C}) TARGET_LINK_LIBRARIES(clitkImageInfo clitkCommon ITKIO) WRAP_GGO(clitkImageConvert_GGO_C clitkImageConvert.ggo) -ADD_EXECUTABLE(clitkImageConvert clitkImageConvert.cxx ${clitkImageConvert_GGO_C}) -TARGET_LINK_LIBRARIES(clitkImageConvert clitkCommon ITKIO clitkFilters) +ADD_EXECUTABLE(clitkImageConvert clitkImageConvert.cxx clitkImageConvertGenericFilter.cxx ${clitkImageConvert_GGO_C}) +TARGET_LINK_LIBRARIES(clitkImageConvert clitkCommon ITKIO) # WRAP_GGO(clitkImageResample_GGO_C clitkImageResample.ggo) # ADD_EXECUTABLE(clitkImageResample clitkImageResample.cxx ${clitkImageResample_GGO_C}) -# TARGET_LINK_LIBRARIES(clitkImageResample clitkCommon ITKIO clitkFilters) +# TARGET_LINK_LIBRARIES(clitkImageResample clitkCommon ITKIO ) -WRAP_GGO(clitkVFResample_GGO_C clitkVFResample.ggo) -ADD_EXECUTABLE(clitkVFResample clitkVFResample.cxx ${clitkImageResample_GGO_C}) -TARGET_LINK_LIBRARIES(clitkVFResample clitkCommon ITKIO clitkFilters) +WRAP_GGO(clitkVFResample_GGO_C clitkImageResample.ggo) +ADD_EXECUTABLE(clitkVFResample clitkVFResample.cxx clitkVFResampleGenericFilter.cxx ${clitkVFResample_GGO_C}) +TARGET_LINK_LIBRARIES(clitkVFResample clitkCommon ITKIO) WRAP_GGO(clitkImageCreate_GGO_C clitkImageCreate.ggo) ADD_EXECUTABLE(clitkImageCreate clitkImageCreate.cxx ${clitkImageCreate_GGO_C}) -TARGET_LINK_LIBRARIES(clitkImageCreate clitkCommon ITKStatistics ITKIO) - -WRAP_GGO(clitkImageFillRegion_GGO_C clitkImageFillRegion.ggo) -ADD_EXECUTABLE(clitkImageFillRegion clitkImageFillRegion.cxx ${clitkImageFillRegion_GGO_C}) -TARGET_LINK_LIBRARIES(clitkImageFillRegion clitkCommon ITKIO ITKStatistics clitkFilters) +TARGET_LINK_LIBRARIES(clitkImageCreate clitkCommon ITKIO) WRAP_GGO(clitkZeroVF_GGO_C clitkZeroVF.ggo) ADD_EXECUTABLE(clitkZeroVF clitkZeroVF.cxx ${clitkZeroVF_GGO_C} clitkZeroVFGenericFilter.cxx) -TARGET_LINK_LIBRARIES(clitkZeroVF clitkCommon ITKStatistics ITKIO) +TARGET_LINK_LIBRARIES(clitkZeroVF clitkCommon ITKIO) WRAP_GGO(clitkImageExtractLine_GGO_C clitkImageExtractLine.ggo) ADD_EXECUTABLE(clitkImageExtractLine clitkImageExtractLine.cxx ${clitkImageExtractLine_GGO_C}) -TARGET_LINK_LIBRARIES(clitkImageExtractLine clitkCommon ITKStatistics ITKIO) +TARGET_LINK_LIBRARIES(clitkImageExtractLine clitkCommon ITKIO) WRAP_GGO(clitkSplitImage_GGO_C clitkSplitImage.ggo) -ADD_EXECUTABLE(clitkSplitImage clitkSplitImage.cxx ${clitkSplitImage_GGO_C}) -TARGET_LINK_LIBRARIES(clitkSplitImage ITKBasicFilters clitkCommon ITKIO clitkFilters) +ADD_EXECUTABLE(clitkSplitImage clitkSplitImage.cxx clitkSplitImageGenericFilter.cxx ${clitkSplitImage_GGO_C}) +TARGET_LINK_LIBRARIES(clitkSplitImage clitkCommon ITKIO ) WRAP_GGO(clitkVFMerge_GGO_C clitkVFMerge.ggo) ADD_EXECUTABLE(clitkVFMerge clitkVFMerge.cxx ${clitkVFMerge_GGO_C}) @@ -48,11 +44,11 @@ TARGET_LINK_LIBRARIES(clitkVFMerge ITKBasicFilters clitkCommon ITKIO) WRAP_GGO(clitkWriteDicomSeries_GGO_C clitkWriteDicomSeries.ggo) ADD_EXECUTABLE(clitkWriteDicomSeries clitkWriteDicomSeries.cxx ${clitkWriteDicomSeries_GGO_C}) -TARGET_LINK_LIBRARIES(clitkWriteDicomSeries clitkCommon ITKIO clitkFilters) +TARGET_LINK_LIBRARIES(clitkWriteDicomSeries clitkCommon ITKIO ) WRAP_GGO(clitkAverageTemporalDimension_GGO_C clitkAverageTemporalDimension.ggo) ADD_EXECUTABLE(clitkAverageTemporalDimension clitkAverageTemporalDimension.cxx ${clitkAverageTemporalDimension_GGO_C}) -TARGET_LINK_LIBRARIES(clitkAverageTemporalDimension clitkCommon ITKIO clitkFilters) +TARGET_LINK_LIBRARIES(clitkAverageTemporalDimension clitkCommon ITKIO ) WRAP_GGO(clitkWarpImage_GGO_C clitkWarpImage.ggo) ADD_EXECUTABLE(clitkWarpImage clitkWarpImage.cxx ${clitkWarpImage_GGO_C} clitkWarpImageGenericFilter.cxx) @@ -60,34 +56,35 @@ TARGET_LINK_LIBRARIES(clitkWarpImage ITKBasicFilters clitkCommon ITKIO) WRAP_GGO(clitkInvertVF_GGO_C clitkInvertVF.ggo) ADD_EXECUTABLE(clitkInvertVF clitkInvertVF.cxx ${clitkInvertVF_GGO_C}) -TARGET_LINK_LIBRARIES(clitkInvertVF clitkCommon ITKIO clitkFilters) +TARGET_LINK_LIBRARIES(clitkInvertVF clitkCommon ITKIO ) WRAP_GGO(clitkAffineTransform_GGO_C clitkAffineTransform.ggo) ADD_EXECUTABLE(clitkAffineTransform clitkAffineTransform.cxx ${clitkAffineTransform_GGO_C}) -TARGET_LINK_LIBRARIES(clitkAffineTransform clitkCommon ITKIO clitkFilters) +TARGET_LINK_LIBRARIES(clitkAffineTransform clitkCommon ITKIO ) WRAP_GGO(clitkSetBackground_GGO_C clitkSetBackground.ggo) ADD_EXECUTABLE(clitkSetBackground clitkSetBackground.cxx clitkSetBackgroundGenericFilter.cxx ${clitkSetBackground_GGO_C}) TARGET_LINK_LIBRARIES(clitkSetBackground clitkCommon ITKIO) WRAP_GGO(clitkGuerreroVentilation_GGO_C clitkGuerreroVentilation.ggo) -ADD_EXECUTABLE(clitkGuerreroVentilation clitkGuerreroVentilation.cxx ${clitkGuerreroVentilation_GGO_C}) -TARGET_LINK_LIBRARIES(clitkGuerreroVentilation clitkCommon ITKIO ITKBasicFilters clitkFilters) - -ADD_EXECUTABLE(clitkImageArithm clitkImageArithm.cxx) -TARGET_LINK_LIBRARIES(clitkImageArithm clitkCommon ITKIO ITKStatistics clitkFilters) +ADD_EXECUTABLE(clitkGuerreroVentilation clitkGuerreroVentilation.cxx clitkGuerreroVentilationGenericFilter.cxx ${clitkGuerreroVentilation_GGO_C}) +TARGET_LINK_LIBRARIES(clitkGuerreroVentilation clitkCommon ITKIO) -ADD_EXECUTABLE(clitkUnsharpMask clitkUnsharpMask.cxx) -TARGET_LINK_LIBRARIES(clitkUnsharpMask clitkCommon ITKIO clitkFilters) +WRAP_GGO(clitkImageArithm_GGO_C clitkImageArithm.ggo) +ADD_EXECUTABLE(clitkImageArithm clitkImageArithm.cxx ${clitkImageArithm_GGO_C}) +TARGET_LINK_LIBRARIES(clitkImageArithm clitkCommon ITKIO ) -ADD_EXECUTABLE(clitkFooImage clitkFooImage.cxx) -TARGET_LINK_LIBRARIES(clitkFooImage clitkCommon ITKIO clitkFilters) +WRAP_GGO(clitkUnsharpMask_GGO_C clitkUnsharpMask.ggo) +ADD_EXECUTABLE(clitkUnsharpMask clitkUnsharpMask.cxx ${clitkUnsharpMask_GGO_C}) +TARGET_LINK_LIBRARIES(clitkUnsharpMask clitkCommon ITKIO ) -ADD_EXECUTABLE(clitkBinarizeImage clitkBinarizeImage.cxx) -TARGET_LINK_LIBRARIES(clitkBinarizeImage clitkCommon ITKIO clitkFilters) +WRAP_GGO(clitkFooImage_GGO_C clitkFooImage.ggo) +ADD_EXECUTABLE(clitkFooImage clitkFooImage.cxx ${clitkFooImage_GGO_C}) +TARGET_LINK_LIBRARIES(clitkFooImage clitkCommon ITKIO ) -ADD_EXECUTABLE(clitkMedianImageFilter clitkMedianImageFilter.cxx) -TARGET_LINK_LIBRARIES(clitkMedianImageFilter clitkCommon ITKIO ITKBasicFilters clitkFilters) +WRAP_GGO(clitkMedianImageFilter_GGO_C clitkMedianImageFilter.ggo) +ADD_EXECUTABLE(clitkMedianImageFilter clitkMedianImageFilter.cxx ${clitkMedianImageFilter_GGO_C}) +TARGET_LINK_LIBRARIES(clitkMedianImageFilter clitkCommon ITKIO ITKBasicFilters ) WRAP_GGO(clitkResampleImage_GGO_C clitkResampleImage.ggo) ADD_EXECUTABLE(clitkResampleImage clitkResampleImage.cxx clitkResampleImageGenericFilter.cxx ${clitkResampleImage_GGO_C}) @@ -95,92 +92,121 @@ TARGET_LINK_LIBRARIES(clitkResampleImage clitkCommon ITKIO) WRAP_GGO(clitkMinMaxMask_GGO_C clitkMinMaxMask.ggo) ADD_EXECUTABLE(clitkMinMaxMask clitkMinMaxMask.cxx ${clitkMinMaxMask_GGO_C}) -TARGET_LINK_LIBRARIES(clitkMinMaxMask clitkCommon ITKIO ITKStatistics clitkFilters) +TARGET_LINK_LIBRARIES(clitkMinMaxMask clitkCommon ITKIO ) -ADD_EXECUTABLE(clitkAutoCrop clitkAutoCrop.cxx) -TARGET_LINK_LIBRARIES(clitkAutoCrop clitkCommon ITKIO ITKStatistics clitkFilters) +WRAP_GGO(clitkAutoCrop_GGO_C clitkAutoCrop.ggo) +ADD_EXECUTABLE(clitkAutoCrop clitkAutoCrop.cxx ${clitkAutoCrop_GGO_C}) +TARGET_LINK_LIBRARIES(clitkAutoCrop clitkCommon ITKIO ) WRAP_GGO(clitkDicomRTStruct2BinaryImage_GGO_C clitkDicomRTStruct2BinaryImage.ggo) ADD_EXECUTABLE(clitkDicomRTStruct2BinaryImage clitkDicomRT_ROI_ConvertToImageFilter.cxx clitkDicomRTStruct2BinaryImage.cxx ${clitkDicomRTStruct2BinaryImage_GGO_C}) TARGET_LINK_LIBRARIES(clitkDicomRTStruct2BinaryImage ITKCommon clitkDicomRTStruct clitkCommon ITKIO QVTK) -ADD_EXECUTABLE(clitkImageLog clitkImageLog.cxx clitkImageLog_ggo.c) -TARGET_LINK_LIBRARIES(clitkImageLog clitkJef ITKIO clitkCommon fftw3) +WRAP_GGO(clitkImageLog_GGO_C clitkImageLog.ggo) +ADD_EXECUTABLE(clitkImageLog clitkImageLog.cxx ${clitkImageLog_GGO_C}) +TARGET_LINK_LIBRARIES(clitkImageLog ITKIO clitkCommon) -ADD_EXECUTABLE(clitkFilter clitkFilter.cxx clitkFilterGenericFilter.cxx clitkFilter_ggo.c) +WRAP_GGO(clitkFilter_GGO_C clitkFilter.ggo) +ADD_EXECUTABLE(clitkFilter clitkFilter.cxx clitkFilterGenericFilter.cxx ${clitkFilter_GGO_C}) TARGET_LINK_LIBRARIES(clitkFilter ITKIO clitkCommon) -ADD_EXECUTABLE(clitkConeBeamProjectImage clitkConeBeamProjectImage.cxx clitkConeBeamProjectImageGenericFilter.cxx clitkConeBeamProjectImage_ggo.c) -TARGET_LINK_LIBRARIES(clitkConeBeamProjectImage ITKIO clitkCommon clitkJef) +WRAP_GGO(clitkConeBeamProjectImage_GGO_C clitkConeBeamProjectImage.ggo) +ADD_EXECUTABLE(clitkConeBeamProjectImage clitkConeBeamProjectImage.cxx clitkConeBeamProjectImageGenericFilter.cxx ${clitkConeBeamProjectImage_GGO_C}) +TARGET_LINK_LIBRARIES(clitkConeBeamProjectImage ITKIO clitkCommon ) -ADD_EXECUTABLE(clitkComposeVF clitkComposeVFGenericFilter.cxx clitkComposeVF.cxx clitkComposeVF_ggo.c) +WRAP_GGO(clitkComposeVF_GGO_C clitkComposeVF.ggo) +ADD_EXECUTABLE(clitkComposeVF clitkComposeVFGenericFilter.cxx clitkComposeVF.cxx ${clitkComposeVF_GGO_C}) TARGET_LINK_LIBRARIES(clitkComposeVF ITKBasicFilters ITKIO clitkCommon) -ADD_EXECUTABLE(clitkShroud clitkShroudGenericFilter.cxx clitkShroud.cxx clitkShroud_ggo.c) -TARGET_LINK_LIBRARIES(clitkShroud ITKIO clitkCommon clitkJef fftw3) - -ADD_EXECUTABLE(clitkMergeSequence clitkMergeSequence.cxx clitkMergeSequenceGenericFilter.cxx clitkMergeSequence_ggo.c) +WRAP_GGO(clitkMergeSequence_GGO_C clitkMergeSequence.ggo) +ADD_EXECUTABLE(clitkMergeSequence clitkMergeSequence.cxx clitkMergeSequenceGenericFilter.cxx ${clitkMergeSequence_GGO_C}) TARGET_LINK_LIBRARIES(clitkMergeSequence ITKIO clitkCommon) -ADD_EXECUTABLE(clitkBackProjectImage clitkBackProjectImage.cxx clitkBackProjectImageGenericFilter.cxx clitkBackProjectImage_ggo.c) -TARGET_LINK_LIBRARIES(clitkBackProjectImage ITKIO clitkCommon clitkJef) +WRAP_GGO(clitkBackProjectImage_GGO_C clitkBackProjectImage.ggo) +ADD_EXECUTABLE(clitkBackProjectImage clitkBackProjectImage.cxx clitkBackProjectImageGenericFilter.cxx ${clitkBackProjectImage_GGO_C}) +TARGET_LINK_LIBRARIES(clitkBackProjectImage ITKIO clitkCommon ) -ADD_EXECUTABLE(clitkCropImage clitkCropImage.cxx clitkCropImageGenericFilter.cxx clitkCropImage_ggo.c) +WRAP_GGO(clitkCropImage_GGO_C clitkCropImage.ggo) +ADD_EXECUTABLE(clitkCropImage clitkCropImage.cxx clitkCropImageGenericFilter.cxx ${clitkCropImage_GGO_C}) TARGET_LINK_LIBRARIES(clitkCropImage clitkCommon ITKIO) -ADD_EXECUTABLE(clitkExtractSlice clitkExtractSlice.cxx clitkExtractSliceGenericFilter.cxx clitkExtractSlice_ggo.c) -TARGET_LINK_LIBRARIES(clitkExtractSlice clitkCommon ITKIO) +# WRAP_GGO(clitkExtractSlice_GGO_C clitkExtractSlice.ggo) +# ADD_EXECUTABLE(clitkExtractSlice clitkExtractSlice.cxx clitkExtractSliceGenericFilter.cxx ${clitkExtractSlice_GGO_C}) +# TARGET_LINK_LIBRARIES(clitkExtractSlice clitkCommon ITKIO) -ADD_EXECUTABLE(clitkFlipImage clitkFlipImage.cxx clitkFlipImageGenericFilter.cxx clitkFlipImage_ggo.c) +WRAP_GGO(clitkFlipImage_GGO_C clitkFlipImage.ggo) +ADD_EXECUTABLE(clitkFlipImage clitkFlipImage.cxx clitkFlipImageGenericFilter.cxx ${clitkFlipImage_GGO_C}) TARGET_LINK_LIBRARIES(clitkFlipImage clitkCommon ITKIO) -ADD_EXECUTABLE(clitkMirrorPadImage clitkMirrorPadImage.cxx clitkMirrorPadImageGenericFilter.cxx clitkMirrorPadImage_ggo.c) +WRAP_GGO(clitkMirrorPadImage_GGO_C clitkMirrorPadImage.ggo) +ADD_EXECUTABLE(clitkMirrorPadImage clitkMirrorPadImage.cxx clitkMirrorPadImageGenericFilter.cxx ${clitkMirrorPadImage_GGO_C}) TARGET_LINK_LIBRARIES(clitkMirrorPadImage clitkCommon ITKIO) -ADD_EXECUTABLE(clitkImageMoment clitkImageMoment.cxx clitkImageMomentGenericFilter.cxx clitkImageMoment_ggo.c) -TARGET_LINK_LIBRARIES(clitkImageMoment clitkCommon ITKI) +WRAP_GGO(clitkImageMoment_GGO_C clitkImageMoment.ggo) +ADD_EXECUTABLE(clitkImageMoment clitkImageMoment.cxx clitkImageMomentGenericFilter.cxx ${clitkImageMoment_GGO_C}) +TARGET_LINK_LIBRARIES(clitkImageMoment clitkCommon ITKIO) -ADD_EXECUTABLE(clitkImageStatistics clitkImageStatistics.cxx clitkImageStatisticsGenericFilter.cxx clitkImageStatistics_ggo.c) +WRAP_GGO(clitkImageStatistics_GGO_C clitkImageStatistics.ggo) +ADD_EXECUTABLE(clitkImageStatistics clitkImageStatistics.cxx clitkImageStatisticsGenericFilter.cxx ${clitkImageStatistics_GGO_C}) TARGET_LINK_LIBRARIES(clitkImageStatistics clitkCommon ITKIO ITKStatistics) -ADD_EXECUTABLE(clitkSetOrigin clitkSetOrigin.cxx clitkSetOriginGenericFilter.cxx clitkSetOrigin_ggo.c) -TARGET_LINK_LIBRARIES(clitkSetOrigin clitkCommon ITKIO ITKStatistics) - -ADD_EXECUTABLE(clitkGetOrigin clitkGetOrigin.cxx clitkGetOriginGenericFilter.cxx clitkGetOrigin_ggo.c) +WRAP_GGO(clitkSetOrigin_GGO_C clitkSetOrigin.ggo) +ADD_EXECUTABLE(clitkSetOrigin clitkSetOrigin.cxx clitkSetOriginGenericFilter.cxx ${clitkSetOrigin_GGO_C}) +TARGET_LINK_LIBRARIES(clitkSetOrigin clitkCommon ITKIO ) + +WRAP_GGO(clitkGetOrigin_GGO_C clitkGetOrigin.ggo) +ADD_EXECUTABLE(clitkGetOrigin clitkGetOrigin.cxx clitkGetOriginGenericFilter.cxx ${clitkGetOrigin_GGO_C}) TARGET_LINK_LIBRARIES(clitkGetOrigin clitkCommon ITKIO ) -ADD_EXECUTABLE(clitkGetDirection clitkGetDirection.cxx clitkGetDirectionGenericFilter.cxx clitkGetDirection_ggo.c) +WRAP_GGO(clitkGetDirection_GGO_C clitkGetDirection.ggo) +ADD_EXECUTABLE(clitkGetDirection clitkGetDirection.cxx clitkGetDirectionGenericFilter.cxx ${clitkGetDirection_GGO_C}) TARGET_LINK_LIBRARIES(clitkGetDirection clitkCommon ITKIO) -ADD_EXECUTABLE(clitkSetDirection clitkSetDirection.cxx clitkSetDirectionGenericFilter.cxx clitkSetDirection_ggo.c) +WRAP_GGO(clitkSetDirection_GGO_C clitkSetDirection.ggo) +ADD_EXECUTABLE(clitkSetDirection clitkSetDirection.cxx clitkSetDirectionGenericFilter.cxx ${clitkSetDirection_GGO_C}) TARGET_LINK_LIBRARIES(clitkSetDirection clitkCommon ITKIO) -ADD_EXECUTABLE(clitkGetSize clitkGetSize.cxx clitkGetSizeGenericFilter.cxx clitkGetSize_ggo.c) -TARGET_LINK_LIBRARIES(clitkGetSize clitkJef clitkCommon ITKNumerics ITKStatistics ITKIO) +WRAP_GGO(clitkGetSize_GGO_C clitkGetSize.ggo) +ADD_EXECUTABLE(clitkGetSize clitkGetSize.cxx clitkGetSizeGenericFilter.cxx ${clitkGetSize_GGO_C}) +TARGET_LINK_LIBRARIES(clitkGetSize clitkCommon ITKIO) -ADD_EXECUTABLE(clitkGetSpacing clitkGetSpacing.cxx clitkGetSpacingGenericFilter.cxx clitkGetSpacing_ggo.c) -TARGET_LINK_LIBRARIES(clitkGetSpacing clitkJef clitkCommon ITKNumerics ITKStatistics ITKIO) +WRAP_GGO(clitkGetSpacing_GGO_C clitkGetSpacing.ggo) +ADD_EXECUTABLE(clitkGetSpacing clitkGetSpacing.cxx clitkGetSpacingGenericFilter.cxx ${clitkGetSpacing_GGO_C}) +TARGET_LINK_LIBRARIES(clitkGetSpacing clitkCommon ITKIO) -ADD_EXECUTABLE(clitkSetSpacing clitkSetSpacing.cxx clitkSetSpacingGenericFilter.cxx clitkSetSpacing_ggo.c) -TARGET_LINK_LIBRARIES(clitkSetSpacing clitkJef clitkCommon ITKNumerics ITKStatistics ITKIO) +WRAP_GGO(clitkSetSpacing_GGO_C clitkSetSpacing.ggo) +ADD_EXECUTABLE(clitkSetSpacing clitkSetSpacing.cxx clitkSetSpacingGenericFilter.cxx ${clitkSetSpacing_GGO_C}) +TARGET_LINK_LIBRARIES(clitkSetSpacing clitkCommon ITKIO) -ADD_EXECUTABLE(clitkCombineImage clitkCombineImage.cxx clitkCombineImageGenericFilter.cxx clitkCombineImage_ggo.c) +WRAP_GGO(clitkCombineImage_GGO_C clitkCombineImage.ggo) +ADD_EXECUTABLE(clitkCombineImage clitkCombineImage.cxx clitkCombineImageGenericFilter.cxx ${clitkCombineImage_GGO_C}) TARGET_LINK_LIBRARIES(clitkCombineImage clitkCommon ITKIO) -ADD_EXECUTABLE(clitkPermuteAxes clitkPermuteAxes.cxx clitkPermuteAxesGenericFilter.cxx clitkPermuteAxes_ggo.c) +WRAP_GGO(clitkPermuteAxes_GGO_C clitkPermuteAxes.ggo) +ADD_EXECUTABLE(clitkPermuteAxes clitkPermuteAxes.cxx clitkPermuteAxesGenericFilter.cxx ${clitkPermuteAxes_GGO_C}) TARGET_LINK_LIBRARIES(clitkPermuteAxes clitkCommon ITKIO) -ADD_EXECUTABLE(clitkChangeImageOrientation clitkChangeImageOrientation.cxx clitkChangeImageOrientationGenericFilter.cxx clitkChangeImageOrientation_ggo.c) +WRAP_GGO(clitkChangeImageOrientation_GGO_C clitkChangeImageOrientation.ggo) +ADD_EXECUTABLE(clitkChangeImageOrientation clitkChangeImageOrientation.cxx clitkChangeImageOrientationGenericFilter.cxx ${clitkChangeImageOrientation_GGO_C}) TARGET_LINK_LIBRARIES(clitkChangeImageOrientation clitkCommon ITKIO) -ADD_EXECUTABLE(clitkVFArithm clitkVFArithm.cxx clitkVFArithmGenericFilter.cxx clitkVFArithm_ggo.c) -TARGET_LINK_LIBRARIES(clitkVFArithm clitkJef clitkCommon ITKNumerics ITKStatistics ITKIO) - -ADD_EXECUTABLE(clitkVFConvert clitkVFConvert.cxx clitkVFConvertGenericFilter.cxx clitkVFConvert_ggo.c) +WRAP_GGO(clitkVFConvert_GGO_C clitkVFConvert.ggo) +ADD_EXECUTABLE(clitkVFConvert clitkVFConvert.cxx clitkVFConvertGenericFilter.cxx ${clitkVFConvert_GGO_C}) TARGET_LINK_LIBRARIES(clitkVFConvert ITKBasicFilters ITKIO clitkCommon ) -ADD_EXECUTABLE(clitkImageToVectorImage clitkImageToVectorImage.cxx clitkImageToVectorImageGenericFilter.cxx clitkImageToVectorImage_ggo.c) -TARGET_LINK_LIBRARIES(clitkImageToVectorImage clitkJef clitkCommon ITKNumerics ITKStatistics ITKIO) +WRAP_GGO(clitkImageToVectorImage_GGO_C clitkImageToVectorImage.ggo) +ADD_EXECUTABLE(clitkImageToVectorImage clitkImageToVectorImage.cxx clitkImageToVectorImageGenericFilter.cxx ${clitkImageToVectorImage_GGO_C}) +TARGET_LINK_LIBRARIES(clitkImageToVectorImage clitkCommon ITKIO) + +WRAP_GGO(clitkVectorImageToImage_GGO_C clitkVectorImageToImage.ggo) +ADD_EXECUTABLE(clitkVectorImageToImage clitkVectorImageToImage.cxx clitkVectorImageToImageGenericFilter.cxx ${clitkVectorImageToImage_GGO_C}) +TARGET_LINK_LIBRARIES(clitkVectorImageToImage clitkCommon ITKIO) + +WRAP_GGO(clitkBSplineCoefficientsToValues_GGO_C clitkBSplineCoefficientsToValues.ggo) +ADD_EXECUTABLE(clitkBSplineCoefficientsToValues clitkBSplineCoefficientsToValues.cxx clitkBSplineCoefficientsToValuesGenericFilter.cxx ${clitkBSplineCoefficientsToValues_GGO_C}) +TARGET_LINK_LIBRARIES(clitkBSplineCoefficientsToValues clitkCommon ITKIO) + +WRAP_GGO(clitkValuesToBSplineCoefficients_GGO_C clitkValuesToBSplineCoefficients.ggo) +ADD_EXECUTABLE(clitkValuesToBSplineCoefficients clitkValuesToBSplineCoefficients.cxx clitkValuesToBSplineCoefficientsGenericFilter.cxx ${clitkValuesToBSplineCoefficients_GGO_C}) +TARGET_LINK_LIBRARIES(clitkValuesToBSplineCoefficients clitkCommon ITKIO) -ADD_EXECUTABLE(clitkVectorImageToImage clitkVectorImageToImage.cxx clitkVectorImageToImageGenericFilter.cxx clitkVectorImageToImage_ggo.c) -TARGET_LINK_LIBRARIES(clitkVectorImageToImage clitkJef clitkCommon ITKNumerics ITKStatistics ITKIO) diff --git a/filters/clitkAutoCrop.ggo b/tools/clitkAutoCrop.ggo old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkAutoCrop.ggo rename to tools/clitkAutoCrop.ggo diff --git a/filters/clitkAutoCropGenericFilter.h b/tools/clitkAutoCropGenericFilter.h old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkAutoCropGenericFilter.h rename to tools/clitkAutoCropGenericFilter.h diff --git a/filters/clitkAutoCropGenericFilter.txx b/tools/clitkAutoCropGenericFilter.txx old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkAutoCropGenericFilter.txx rename to tools/clitkAutoCropGenericFilter.txx diff --git a/tools/clitkBSplineCoefficientsToValues.cxx b/tools/clitkBSplineCoefficientsToValues.cxx new file mode 100644 index 0000000..4df0119 --- /dev/null +++ b/tools/clitkBSplineCoefficientsToValues.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkBSplineCoefficientsToValues.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkBSplineCoefficientsToValues_ggo.h" +#include "clitkIO.h" +#include "clitkBSplineCoefficientsToValuesGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkBSplineCoefficientsToValues, args_info); + CLITK_INIT; + + // Filter + clitk::BSplineCoefficientsToValuesGenericFilter::Pointer genericFilter=clitk::BSplineCoefficientsToValuesGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkBSplineCoefficientsToValues.ggo b/tools/clitkBSplineCoefficientsToValues.ggo new file mode 100644 index 0000000..41d6688 --- /dev/null +++ b/tools/clitkBSplineCoefficientsToValues.ggo @@ -0,0 +1,21 @@ +#File clitkBSplineCoefficientsToValues.ggo +Package "clitkBSplineCoefficientsToValues" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +section "I/O" +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "matrix" m "Matrix transform to add" string no + +section "Options" +option "like" l "Resample output this image (size, spacing,origin)" string no +option "size" - "New output size if different from input" int no multiple +option "spacing" - "New output spacing if different from input" double no multiple +option "origin" - "New output origin if different from input" double no multiple +option "pad" - "Edge padding value" double no default="0.0" +option "order" - "Spline order of the coefficient image" int no default="3" + diff --git a/tools/clitkBSplineCoefficientsToValuesGenericFilter.cxx b/tools/clitkBSplineCoefficientsToValuesGenericFilter.cxx new file mode 100644 index 0000000..e1c4523 --- /dev/null +++ b/tools/clitkBSplineCoefficientsToValuesGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkBSplineCoefficientsToValuesGenericFilter_cxx +#define clitkBSplineCoefficientsToValuesGenericFilter_cxx + +/* ================================================= + * @file clitkBSplineCoefficientsToValuesGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkBSplineCoefficientsToValuesGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + BSplineCoefficientsToValuesGenericFilter::BSplineCoefficientsToValuesGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void BSplineCoefficientsToValuesGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension, Components; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components); + + + // Call UpdateWithDim + // if(Dimension==2) UpdateWithDim<2>(PixelType, Components); + if(Dimension==3) UpdateWithDim<3>(PixelType, Components); + //else if (Dimension==4)UpdateWithDim<4>(PixelType, Components); + else + { + std::cout<<"Error, Only for 2, 3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( BSplineCoefficientsToValuesGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkBSplineCoefficientsToValues & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + BSplineCoefficientsToValuesGenericFilter(); + ~BSplineCoefficientsToValuesGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType, unsigned int Components); + template void UpdateWithDimAndPixelType(); + template void UpdateWithDimAndVectorType(); + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkBSplineCoefficientsToValues m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkBSplineCoefficientsToValuesGenericFilter.txx" +#endif + +#endif // #define clitkBSplineCoefficientsToValuesGenericFilter_h diff --git a/tools/clitkBSplineCoefficientsToValuesGenericFilter.txx b/tools/clitkBSplineCoefficientsToValuesGenericFilter.txx new file mode 100644 index 0000000..76be246 --- /dev/null +++ b/tools/clitkBSplineCoefficientsToValuesGenericFilter.txx @@ -0,0 +1,322 @@ +/*========================================================================= + 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 clitkBSplineCoefficientsToValuesGenericFilter_txx +#define clitkBSplineCoefficientsToValuesGenericFilter_txx + +/* ================================================= + * @file clitkBSplineCoefficientsToValuesGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + BSplineCoefficientsToValuesGenericFilter::UpdateWithDim(std::string PixelType, unsigned int Components) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + // } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + // else if (PixelType == "unsigned_char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + // else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + // } + } + + else + if (Components==3) + { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 3D float (DVF)" << std::endl; + UpdateWithDimAndVectorType >(); + } + + else std::cerr<<"Number of components is "< + void + BSplineCoefficientsToValuesGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + //Filter + typedef itk::ResampleImageFilter< InputImageType,OutputImageType > ResampleFilterType; + typename ResampleFilterType::Pointer resampler = ResampleFilterType::New(); + + // Properties + if (m_ArgsInfo.like_given) + { + typename InputReaderType::Pointer likeReader=InputReaderType::New(); + likeReader->SetFileName(m_ArgsInfo.like_arg); + likeReader->Update(); + resampler->SetOutputParametersFromImage(likeReader->GetOutput()); + if (m_Verbose)std::cout<<"Resampling output like "<GetLargestPossibleRegion().GetSize(); + if (m_Verbose)std::cout<<"Setting the size to "<GetSpacing(); + if (m_Verbose)std::cout<<"Setting the spacing to "<GetOrigin(); + if (m_Verbose)std::cout<<"Setting the origin to "<SetSize( outputSize ); + resampler->SetOutputSpacing( outputSpacing ); + resampler->SetOutputOrigin( outputOrigin ); + + } + + // Interp : coeff + typedef itk::BSplineResampleImageFunction InterpolatorType; + typename InterpolatorType::Pointer interpolator=InterpolatorType::New(); + interpolator->SetSplineOrder(m_ArgsInfo.order_arg); + + // Set + resampler->SetInterpolator( interpolator); + resampler->SetDefaultPixelValue( static_cast(m_ArgsInfo.pad_arg) ); + resampler->SetInput( input ); + + // Update + try + { + resampler->Update(); + } + catch(itk::ExceptionObject) + { + std::cerr<<"Error resampling the image"<GetOutput(); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the Vectortype + //------------------------------------------------------------------- + template + void + BSplineCoefficientsToValuesGenericFilter::UpdateWithDimAndVectorType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + //Filter + typedef itk::VectorResampleImageFilter< InputImageType,OutputImageType > ResampleFilterType; + typename ResampleFilterType::Pointer resampler = ResampleFilterType::New(); + + // Properties + if (m_ArgsInfo.like_given) + { + typename InputReaderType::Pointer likeReader=InputReaderType::New(); + likeReader->SetFileName(m_ArgsInfo.like_arg); + likeReader->Update(); + + // Set + resampler->SetSize( likeReader->GetOutput()->GetLargestPossibleRegion().GetSize() ); + resampler->SetOutputSpacing(likeReader->GetOutput()->GetSpacing() ); + resampler->SetOutputOrigin( likeReader->GetOutput()->GetOrigin() ); + if (m_Verbose)std::cout<<"Resampling output like "<GetLargestPossibleRegion().GetSize(); + if (m_Verbose)std::cout<<"Setting the size to "<GetSpacing(); + if (m_Verbose)std::cout<<"Setting the spacing to "<GetOrigin(); + if (m_Verbose)std::cout<<"Setting the origin to "<SetSize( outputSize ); + resampler->SetOutputSpacing( outputSpacing ); + resampler->SetOutputOrigin( outputOrigin ); + + } + + // Interp : coeff + typedef clitk::VectorBSplineResampleImageFunction InterpolatorType; + typename InterpolatorType::Pointer interpolator=InterpolatorType::New(); + interpolator->SetSplineOrder(m_ArgsInfo.order_arg); + + + // Set + resampler->SetInterpolator( interpolator); + resampler->SetDefaultPixelValue( static_cast(m_ArgsInfo.pad_arg) ); + resampler->SetInput( input ); + + // Update + try + { + resampler->Update(); + } + catch(itk::ExceptionObject) + { + std::cerr<<"Error resampling the image"<GetOutput(); + writeImage(output, "/home/jef/tmp/output1.mhd", true); + + + // Matrix Transform + if(m_ArgsInfo.matrix_given) + { + typedef itk::TransformToDeformationFieldSource ConvertorType; + typename ConvertorType::Pointer filter= ConvertorType::New(); + filter->SetOutputParametersFromImage(output); + + typedef itk::AffineTransform TransformType; + typename TransformType::Pointer transform =TransformType::New(); + itk::Matrix homMatrix= ReadMatrix( m_ArgsInfo.matrix_arg); + itk::Matrix matrix =GetRotationalPartMatrix( homMatrix); + itk::Vector offset= GetTranslationPartMatrix( homMatrix); + transform->SetMatrix(matrix); + transform->SetOffset(offset); + filter->SetTransform(transform); + filter->Update(); + typename OutputImageType::Pointer output2=filter->GetOutput(); + writeImage(output2, "/home/jef/tmp/output2.mhd", true); + + // Add + typedef itk::AddImageFilter< OutputImageType, OutputImageType, OutputImageType > AddType; + typename AddType::Pointer adder= AddType::New(); + adder->SetInput(output); + adder->SetInput(1,output2); + adder->Update(); + output=adder->GetOutput(); + } + + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + } + +}//end clitk + +#endif //#define clitkBSplineCoefficientsToValuesGenericFilter_txx diff --git a/tools/clitkBackProjectImage.cxx b/tools/clitkBackProjectImage.cxx new file mode 100755 index 0000000..abc48d3 --- /dev/null +++ b/tools/clitkBackProjectImage.cxx @@ -0,0 +1,56 @@ +/*========================================================================= + 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 CLITKBACKPROJECTIMAGE_CXX +#define CLITKBACKPROJECTIMAGE_CXX +/** + ================================================= + * @file clitkBackProjectImage.cxx + * @author Jef Vandemeulebroucke + * @date 24 February 2009 + * + * @brief "Back project a 3D image using a Cone-Beam geometry" + =================================================*/ + +// clitk include +#include "clitkBackProjectImage_ggo.h" +#include "clitkBackProjectImageGenericFilter.h" +#include "clitkIO.h" +#include "clitkImageCommon.h" +#include "clitkTransformUtilities.h" + +int main(int argc, char * argv[]) { + + //Init command line + GGO(clitkBackProjectImage, args_info); + CLITK_INIT; + + //Creation of a generic filter + clitk::BackProjectImageGenericFilter::Pointer genericFilter = clitk::BackProjectImageGenericFilter::New(); + + //Passing the arguments to the generic filter + genericFilter->SetArgsInfo(args_info); + + //update + genericFilter->Update(); + + return 0; +} + +#endif + + diff --git a/tools/clitkBackProjectImage.ggo b/tools/clitkBackProjectImage.ggo new file mode 100755 index 0000000..12a2a6c --- /dev/null +++ b/tools/clitkBackProjectImage.ggo @@ -0,0 +1,41 @@ +#File clitkConeBeamProjectImage.ggo +#Author: Jef Vandemeulebroucke +#Date : Tue 24 February 2009 16.35 + +Package "clitk" +Version "Back project a 2D image with cone-beam geometry" + +option "config" - "Config file" string no + + +section "Run Time" + +option "verbose" v "Verbose" flag off +option "threads" - "Number of threads to use (default=min(cores,8))" int no + + +section "Input" + +option "input" i "Input grid filename" string yes +option "output" o "Output grid filename" string yes +option "mask" m "3D Mask in which the filter should be applied (not supported yet;-)" string no + + +section "Projection Parameters" + +option "iso" - "The isocenter" float no multiple default="0.0" +option "screen" - "Specify the source to screen distance in mm" float no default="1536.0" +option "axis" - "Specify the source to axis distance in mm" float no default="1000.0" +option "angle" - "Specify the projection angle" float no default="0.0" +option "matrix" - "Rigid tranform prior to projection (4x4)" string no +option "pad" - "Padding value" float no default="0.0" + + +section "Output Image" + +option "like" - "Make output like this image" string no +option "origin" - "Origin for the output image" double multiple no default="0.0" +option "size" - "Size for the output image" int multiple no default="100" +option "spacing" - "Spacing for the output image" double multiple no default="1.0" + + diff --git a/tools/clitkBackProjectImageGenericFilter.cxx b/tools/clitkBackProjectImageGenericFilter.cxx new file mode 100755 index 0000000..ecf821d --- /dev/null +++ b/tools/clitkBackProjectImageGenericFilter.cxx @@ -0,0 +1,92 @@ +/*========================================================================= + 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 CLITKBACKPROJECTIMAGEGENERICFILTER_CXX +#define CLITKBACKPROJECTIMAGEGENERICFILTER_CXX + +/** + * @file clitkBackProjectImageGenericFilter.cxx + * @author Jef Vandemeulebroucke + * @date Wed April 30 13:47:57 2008 + * + * @brief + * + * + */ + +#include "clitkBackProjectImageGenericFilter.h" + +namespace clitk +{ + + //==================================================================== + // Constructor + BackProjectImageGenericFilter::BackProjectImageGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + //==================================================================== + // Update + void BackProjectImageGenericFilter::Update() + { + + //Read the PixelType and dimension of the input image + int Dimension; + std::string PixelType; + clitk::ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + //Launch for the right pixelType + if (Dimension==2) + { + if (m_Verbose) std::cout << "Input was detected to be "<< Dimension << "D and " << PixelType << "..." << std::endl; + + + if(PixelType == "short"){ + if (m_Verbose) std::cout << "Launching back projection in signed short..." << std::endl; + UpdateWithPixelType(); + } + +// else if(PixelType == "unsigned_short"){ +// if (m_Verbose) std::cout << "Launching Projection in unsigned_short..." << std::endl; +// UpdateWithPixelType(); +// } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching Projection in unsigned_char..." << std::endl; + UpdateWithPixelType(); + } + +// else if (PixelType == "char"){ +// if (m_Verbose) std::cout << "Launching Projection in signed_char..." << std::endl; +// UpdateWithPixelType(); +// } + else { + if (m_Verbose) std::cout << "Launching Projection in float..." << std::endl; + UpdateWithPixelType(); + } + } + else std::cerr<<"The input image should be 2D!"< + * @date 30 April 2008 + * + * @brief Project a 3D image using a ConeBeam geometry + * + =================================================*/ + +// clitk include +#include "clitkIO.h" +#include "clitkImageCommon.h" +#include "clitkCommon.h" +#include "clitkImageCommon.h" +#include "clitkBackProjectImageFilter.h" +#include "clitkBackProjectImage_ggo.h" + +// itk include +#include "itkLightObject.h" + + +namespace clitk { + + //==================================================================== + class BackProjectImageGenericFilter: public itk::LightObject + { + public: + + //================================================ + typedef BackProjectImageGenericFilter Self; + typedef itk::LightObject Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + //================================================ + itkNewMacro(Self); + + //==================================================================== + // Set methods + void SetArgsInfo(const args_info_clitkBackProjectImage a) + { + m_ArgsInfo=a; + m_InputFileName=m_ArgsInfo.input_arg; + m_Verbose=m_ArgsInfo.verbose_flag; + } + + //==================================================================== + // Update + virtual void Update(); + + protected: + const char * GetNameOfClass() const { return "BackProjectImageGenericFilter"; } + + //==================================================================== + // Constructor & Destructor + BackProjectImageGenericFilter(); + ~BackProjectImageGenericFilter(){;} + + //==================================================================== + //Protected member functions + template void UpdateWithPixelType(); + + args_info_clitkBackProjectImage m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + +} // end namespace clitk +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkBackProjectImageGenericFilter.txx" +#endif + +#endif //#define CLITKBACKPROJECTIMAGEGENERICFILTER__H diff --git a/tools/clitkBackProjectImageGenericFilter.txx b/tools/clitkBackProjectImageGenericFilter.txx new file mode 100755 index 0000000..2e3e4e5 --- /dev/null +++ b/tools/clitkBackProjectImageGenericFilter.txx @@ -0,0 +1,138 @@ +/*========================================================================= + 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 CLITKBACKPROJECTIMAGEGENERICFILTER_TXX +#define CLITKBACKPROJECTIMAGEGENERICFILTER_TXX +/** + ================================================= + * @file clitkBackProjectImageGenericFilter.txx + * @author Jef Vandemeulebroucke + * @date 30 April 2008 + * + * @brief Project a 3D image using a cone-beam geometry + * + =================================================*/ + + +namespace clitk +{ + + //================================================================================ + template void BackProjectImageGenericFilter::UpdateWithPixelType() + { + + //--------------------------------- + // Define the images + //--------------------------------- + const unsigned int InputImageDimension=2; + typedef itk::Image InputImageType; + typedef itk::ImageFileReader ImageReaderType; + typename ImageReaderType::Pointer reader = ImageReaderType::New(); + reader->SetFileName(m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input = reader->GetOutput(); + + //Define the output type + //JV always float? + const unsigned int OutputImageDimension=3; + typedef float OutputPixelType; + typedef itk::Image OutputImageType; + + //Create the BackProjectImageFilter + typedef BackProjectImageFilter BackProjectImageFilterType; + typename BackProjectImageFilterType::Pointer filter=BackProjectImageFilterType::New(); + + + //--------------------------------- + //Pass all the necessary parameters + //--------------------------------- + unsigned int i=0; + filter->SetInput(input); + if (m_ArgsInfo.threads_given) filter->SetNumberOfThreads(m_ArgsInfo.threads_arg); + + //Projection parameters + OutputImageType::PointType iso; + if (m_ArgsInfo.iso_given) + { + for(i=0;iSetIsoCenter(iso); + } + filter->SetSourceToScreen(m_ArgsInfo.screen_arg); + filter->SetSourceToAxis(m_ArgsInfo.axis_arg); + filter->SetProjectionAngle(m_ArgsInfo.angle_arg); + if (m_ArgsInfo.matrix_given) + { + itk::Matrix rt =ReadMatrix3D(m_ArgsInfo.matrix_arg); + filter->SetRigidTransformMatrix(rt); + } + filter->SetEdgePaddingValue(static_cast(m_ArgsInfo.pad_arg)); + + //Output image info + if (m_ArgsInfo.like_given) + { + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader2=ReaderType::New(); + reader2->SetFileName(m_ArgsInfo.like_arg); + reader2->Update(); + + OutputImageType::Pointer image=reader2->GetOutput(); + filter->SetOutputParametersFromImage(image); + } + else + { + if(m_ArgsInfo.origin_given) + { + OutputImageType::PointType origin; + for(i=0;iSetOutputOrigin(origin); + } + if (m_ArgsInfo.spacing_given) + { + OutputImageType::SpacingType spacing; + for(i=0;iSetOutputSpacing(spacing); + } + if (m_ArgsInfo.spacing_given) + { + OutputImageType::SizeType size; + for(i=0;iSetOutputSize(size); + } + } + + //Go + filter->Update(); + + //Get the output + OutputImageType::Pointer output=filter->GetOutput(); + + //Write the output + typedef itk::ImageFileWriter OutputWriterType; + OutputWriterType::Pointer outputWriter = OutputWriterType::New(); + outputWriter->SetInput(output); + outputWriter->SetFileName(m_ArgsInfo.output_arg); + if (m_Verbose)std::cout<<"Writing back projected image..."<Update(); + } + +} + +#endif //#define CLITKBACKPROJECTIMAGEGENERICFILTER_TXX diff --git a/tools/clitkChangeImageOrientation.cxx b/tools/clitkChangeImageOrientation.cxx new file mode 100755 index 0000000..466798d --- /dev/null +++ b/tools/clitkChangeImageOrientation.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkChangeImageOrientation.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkChangeImageOrientation_ggo.h" +#include "clitkIO.h" +#include "clitkChangeImageOrientationGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkChangeImageOrientation, args_info); + CLITK_INIT; + + // Filter + clitk::ChangeImageOrientationGenericFilter::Pointer genericFilter=clitk::ChangeImageOrientationGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkChangeImageOrientation.ggo b/tools/clitkChangeImageOrientation.ggo new file mode 100755 index 0000000..1470d13 --- /dev/null +++ b/tools/clitkChangeImageOrientation.ggo @@ -0,0 +1,12 @@ +#File clitkChangeImageOrientation.ggo +Package "clitkChangeImageOrientation" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes + + diff --git a/tools/clitkChangeImageOrientationGenericFilter.cxx b/tools/clitkChangeImageOrientationGenericFilter.cxx new file mode 100755 index 0000000..5dce63e --- /dev/null +++ b/tools/clitkChangeImageOrientationGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkChangeImageOrientationGenericFilter_cxx +#define clitkChangeImageOrientationGenericFilter_cxx + +/* ================================================= + * @file clitkChangeImageOrientationGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkChangeImageOrientationGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + ChangeImageOrientationGenericFilter::ChangeImageOrientationGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void ChangeImageOrientationGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + // if(Dimension==2) UpdateWithDim<2>(PixelType); + if(Dimension==3) UpdateWithDim<3>(PixelType); + // else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 3 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( ChangeImageOrientationGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkChangeImageOrientation & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + ChangeImageOrientationGenericFilter(); + ~ChangeImageOrientationGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkChangeImageOrientation m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkChangeImageOrientationGenericFilter.txx" +#endif + +#endif // #define clitkChangeImageOrientationGenericFilter_h diff --git a/tools/clitkChangeImageOrientationGenericFilter.txx b/tools/clitkChangeImageOrientationGenericFilter.txx new file mode 100755 index 0000000..73b974f --- /dev/null +++ b/tools/clitkChangeImageOrientationGenericFilter.txx @@ -0,0 +1,109 @@ +/*========================================================================= + 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 clitkChangeImageOrientationGenericFilter_txx +#define clitkChangeImageOrientationGenericFilter_txx + +/* ================================================= + * @file clitkChangeImageOrientationGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + ChangeImageOrientationGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + ChangeImageOrientationGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typedef itk::OrientImageFilter OrientFilterType; + typename OrientFilterType::Pointer orienter = itk::OrientImageFilter::New(); + orienter->UseImageDirectionOn(); + orienter->SetDesiredCoordinateOrientation(itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RIP); + orienter->SetInput(input); + orienter->Update(); + typename OutputImageType::Pointer output=orienter->GetOutput(); + + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + + } + + +}//end clitk + +#endif //#define clitkChangeImageOrientationGenericFilter_txx diff --git a/tools/clitkCombineImage.cxx b/tools/clitkCombineImage.cxx new file mode 100755 index 0000000..d365db7 --- /dev/null +++ b/tools/clitkCombineImage.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkCombineImage.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkCombineImage_ggo.h" +#include "clitkIO.h" +#include "clitkCombineImageGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkCombineImage, args_info); + CLITK_INIT; + + // Filter + clitk::CombineImageGenericFilter::Pointer genericFilter=clitk::CombineImageGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkCombineImage.ggo b/tools/clitkCombineImage.ggo new file mode 100755 index 0000000..9ad4023 --- /dev/null +++ b/tools/clitkCombineImage.ggo @@ -0,0 +1,14 @@ +#File clitkCombineImage.ggo +Package "clitkCombineImage" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "input2" j "Input image filename" string yes +option "mask" m "Binary image: if(mask) input1,else input2" string yes +option "output" o "Output image filename" string yes + + diff --git a/tools/clitkCombineImageFilter.h b/tools/clitkCombineImageFilter.h new file mode 100755 index 0000000..9cba3a8 --- /dev/null +++ b/tools/clitkCombineImageFilter.h @@ -0,0 +1,113 @@ +/*========================================================================= + 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 clitkCombineImageFilter_h +#define clitkCombineImageFilter_h + +/* ================================================= + * @file clitkCombineImageFilter.h + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk include +#include "clitkIO.h" +#include "clitkCommon.h" + +//itk include +#include "itkImageToImageFilter.h" + +namespace clitk +{ + + template + class ITK_EXPORT CombineImageFilter : + public itk::ImageToImageFilter + { + public: + //---------------------------------------- + // ITK + //---------------------------------------- + typedef CombineImageFilter Self; + typedef itk::ImageToImageFilter Superclass; + 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( CombineImageFilter, ImageToImageFilter ); + + /** Dimension of the domain space. */ + itkStaticConstMacro(InputImageDimension, unsigned int, Superclass::InputImageDimension); + itkStaticConstMacro(OutputImageDimension, unsigned int, Superclass::OutputImageDimension); + typedef itk::Image MaskImageType; + + //---------------------------------------- + // Typedefs + //---------------------------------------- + typedef typename InputImageType::RegionType OutputImageRegionType; + + //---------------------------------------- + // Set & Get + //---------------------------------------- + itkBooleanMacro(Verbose); + itkSetMacro( Verbose, bool); + itkGetConstReferenceMacro( Verbose, bool); + + void SetMask(typename MaskImageType::Pointer m){m_Mask=m;} + typename MaskImageType::Pointer GetMask(void){return m_Mask;} + + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + CombineImageFilter(); + ~CombineImageFilter() {}; + + //---------------------------------------- + // Update + //---------------------------------------- + // Generate Data + void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, int threadId); + + //---------------------------------------- + // Data members + //---------------------------------------- + bool m_Verbose; + typename MaskImageType::Pointer m_Mask; + + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkCombineImageFilter.txx" +#endif + +#endif // #define clitkCombineImageFilter_h + + diff --git a/tools/clitkCombineImageFilter.txx b/tools/clitkCombineImageFilter.txx new file mode 100755 index 0000000..21eade3 --- /dev/null +++ b/tools/clitkCombineImageFilter.txx @@ -0,0 +1,87 @@ +/*========================================================================= + 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 clitkCombineImageFilter_txx +#define clitkCombineImageFilter_txx + +/* ================================================= + * @file clitkCombineImageFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + CombineImageFilter::CombineImageFilter() + { + m_Verbose=false; + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + CombineImageFilter::ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, int threadId) + { + typename InputImageType::ConstPointer input1=this->GetInput(0); + typename InputImageType::ConstPointer input2=this->GetInput(1); + typename InputImageType::Pointer output=this->GetOutput(); + + typedef itk::ImageRegionIterator IteratorType; + typedef itk::ImageRegionConstIterator ConstIteratorType; + typedef itk::ImageRegionConstIterator MaskIteratorType; + + ConstIteratorType it1(input1, outputRegionForThread); + ConstIteratorType it2(input2, outputRegionForThread); + MaskIteratorType itM(m_Mask, outputRegionForThread); + IteratorType itO(output, outputRegionForThread); + + it1.GoToBegin(); + it2.GoToBegin(); + itM.GoToBegin(); + itO.GoToBegin(); + + while(! itO.IsAtEnd()) + { + if(itM.Get()) + itO.Set(it1.Get()); + else + itO.Set(it2.Get()); + + ++it1; + ++it2; + ++itM; + ++itO; + } + + } + + +}//end clitk + +#endif //#define clitkCombineImageFilter_txx diff --git a/tools/clitkCombineImageGenericFilter.cxx b/tools/clitkCombineImageGenericFilter.cxx new file mode 100755 index 0000000..76f40b5 --- /dev/null +++ b/tools/clitkCombineImageGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkCombineImageGenericFilter_cxx +#define clitkCombineImageGenericFilter_cxx + +/* ================================================= + * @file clitkCombineImageGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkCombineImageGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + CombineImageGenericFilter::CombineImageGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void CombineImageGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension, Components; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType, Components); + else if(Dimension==3) UpdateWithDim<3>(PixelType, Components); + else if (Dimension==4)UpdateWithDim<4>(PixelType, Components); + else + { + std::cout<<"Error, Only for 2, 3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( CombineImageGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkCombineImage & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + CombineImageGenericFilter(); + ~CombineImageGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType, int Components); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkCombineImage m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkCombineImageGenericFilter.txx" +#endif + +#endif // #define clitkCombineImageGenericFilter_h diff --git a/tools/clitkCombineImageGenericFilter.txx b/tools/clitkCombineImageGenericFilter.txx new file mode 100755 index 0000000..aa5940e --- /dev/null +++ b/tools/clitkCombineImageGenericFilter.txx @@ -0,0 +1,130 @@ +/*========================================================================= + 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 clitkCombineImageGenericFilter_txx +#define clitkCombineImageGenericFilter_txx + +/* ================================================= + * @file clitkCombineImageGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + CombineImageGenericFilter::UpdateWithDim(std::string PixelType, int Components) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + else if (Components==3) + { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 3D float (DVF)" << std::endl; + UpdateWithDimAndPixelType >(); + } + else std::cerr<<"Number of components is "< + void + CombineImageGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image MaskImageType; + typedef itk::Image OutputImageType; + + // Read the inputs + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input1= reader->GetOutput(); + typename InputReaderType::Pointer reader2 = InputReaderType::New(); + reader2->SetFileName( m_ArgsInfo.input2_arg); + reader2->Update(); + typename InputImageType::Pointer input2= reader2->GetOutput(); + + // Read the mask + typedef itk::ImageFileReader MaskReaderType; + typename MaskReaderType::Pointer mReader = MaskReaderType::New(); + mReader->SetFileName( m_ArgsInfo.mask_arg); + mReader->Update(); + typename MaskImageType::Pointer mask= mReader->GetOutput(); + + // Filter + typedef CombineImageFilter CombineImageFilterType; + typename CombineImageFilterType::Pointer filter=CombineImageFilterType::New(); + filter->SetInput( input1 ); + filter->SetInput(1, input2 ); + filter->SetMask( mask ); + filter->Update(); + typename OutputImageType::Pointer output=filter->GetOutput(); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + + } + + +}//end clitk + +#endif //#define clitkCombineImageGenericFilter_txx diff --git a/tools/clitkComposeVF.cxx b/tools/clitkComposeVF.cxx new file mode 100755 index 0000000..ed510d9 --- /dev/null +++ b/tools/clitkComposeVF.cxx @@ -0,0 +1,58 @@ +/*========================================================================= + 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 CLITKCOMPOSEVF_CXX +#define CLITKCOMPOSEVF_CXX + +/** + * @file clitkComposeVF.cxx + * @author Jef Vandemeulebroucke + * @date July 20 10:14:53 2007 + * + * @brief Read in two VF (ex mhd, vf)compose them using lirear interpolation. + * + */ + +// clitk include +#include "clitkComposeVF_ggo.h" +#include "clitkIO.h" +#include "clitkImageCommon.h" +#include "clitkComposeVFGenericFilter.h" + +int main( int argc, char *argv[] ) +{ + + // Init command line + GGO(clitkComposeVF, args_info); + CLITK_INIT; + + //Creation of the generic filter + clitk::ComposeVFGenericFilter::Pointer ComposeVFGenericFilter= clitk::ComposeVFGenericFilter::New(); + + //Pass the parameters + ComposeVFGenericFilter->SetInput1(args_info.input1_arg); + ComposeVFGenericFilter->SetInput2(args_info.input2_arg); + ComposeVFGenericFilter->SetOutput(args_info.output_arg); + //JV how to pass for different dims? + //ComposeVFGenericFilter->SetEdgePaddingValue(args_info.pad_arg); + ComposeVFGenericFilter->SetVerbose(args_info.verbose_flag); + ComposeVFGenericFilter->Update(); + + return EXIT_SUCCESS; +} +#endif + diff --git a/tools/clitkComposeVF.ggo b/tools/clitkComposeVF.ggo new file mode 100755 index 0000000..ac2b8dd --- /dev/null +++ b/tools/clitkComposeVF.ggo @@ -0,0 +1,14 @@ +#File clitkComposeVF.ggo +#Author: Jef Vandemeulebroucke +#Date : Tue 20 August 16.35 + +Package "clitk" +Version "Read two vector fields (.mhd, .vf, ..) and compose them using linear interpolation" + +option "config" - "Config file" string no +option "input1" i "Input1 VF filename" string yes +option "input2" j "Input2 VF filename" string yes +option "output" o "Output VF filename" string yes +option "pad" p "Edgepadding value" float multiple no default="0.0" +option "verbose" v "Verbose" flag off + diff --git a/filters/clitkImageFillRegionGenericFilter.txx b/tools/clitkComposeVFGenericFilter.cxx old mode 100644 new mode 100755 similarity index 52% rename from filters/clitkImageFillRegionGenericFilter.txx rename to tools/clitkComposeVFGenericFilter.cxx index 817ef8f..526a2ec --- a/filters/clitkImageFillRegionGenericFilter.txx +++ b/tools/clitkComposeVFGenericFilter.cxx @@ -1,7 +1,7 @@ /*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv - Authors belong to: + 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 @@ -15,14 +15,36 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ======================================================================-====*/ -#ifndef CLITKIMAGEFILLREGIONGENERICFILTER_TXX -#define CLITKIMAGEFILLREGIONGENERICFILTER_TXX +#ifndef CLITKCOMPOSEVFGENERICFILTER_CXX +#define CLITKCOMPOSEVFGENERICFILTER_CXX +#include "clitkComposeVFGenericFilter.h" -/*------------------------------------------------- - * @file clitkImageFillRegionGenericFilter.txx - * @author Cristina Gimenez - * @date 9 August 2006 - * - -------------------------------------------------*/ -#endif //#define CLITKIMAGEFILLREGIONGENERICFILTER_TXX +namespace clitk { + + clitk::ComposeVFGenericFilter::ComposeVFGenericFilter() + { + m_Verbose=false; + } + + + void clitk::ComposeVFGenericFilter::Update() + { + //Get the image Dimension and PixelType + int Dimension; + std::string PixelType; + + clitk::ReadImageDimensionAndPixelType(m_InputName1, Dimension, PixelType); + + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + else + { + std::cout<<"Error, Only for 2 and 3 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods) */ + itkTypeMacro( ComposeVFGenericFilter, ImageToImageFilter ); + + //Set Methods (inline) + void SetInput1(const std::string m){m_InputName1=m;} + void SetInput2(const std::string m){m_InputName2=m;} + void SetOutput(const std::string m){m_OutputName=m;} + void SetVerbose(const bool m){m_Verbose=m;} + + + //Update + void Update( ); + + protected: + + ComposeVFGenericFilter(); + ~ComposeVFGenericFilter() {}; + + //Templated members + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + std::string m_InputName1; + std::string m_InputName2; + std::string m_OutputName; + bool m_Verbose; + + }; + + +} // end namespace clitk +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkComposeVFGenericFilter.txx" +#endif + +#endif // #define __clitkComposeVFGenericFilter_h diff --git a/tools/clitkComposeVFGenericFilter.txx b/tools/clitkComposeVFGenericFilter.txx new file mode 100755 index 0000000..343c4ed --- /dev/null +++ b/tools/clitkComposeVFGenericFilter.txx @@ -0,0 +1,79 @@ +/*========================================================================= + 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 __clitkComposeVFGenericFilter_txx +#define __clitkComposeVFGenericFilter_txx +#include "clitkComposeVFGenericFilter.h" + + +namespace clitk +{ + + template + void ComposeVFGenericFilter::UpdateWithDim(std::string PixelType) + { + if (PixelType=="double") + { + UpdateWithDimAndPixelType(); + } + else + { + UpdateWithDimAndPixelType(); + } + } + + + template + void ComposeVFGenericFilter::UpdateWithDimAndPixelType() + { + + //Define the image type + typedef itk::Vector DisplacementType; + typedef itk::Image ImageType; + + //Read the input1 + typedef itk::ImageFileReader ImageReaderType; + typename ImageReaderType::Pointer reader1= ImageReaderType::New(); + reader1->SetFileName(m_InputName1); + reader1->Update(); + typename ImageType::Pointer input1 =reader1->GetOutput(); + + //Read the input2 + typename ImageReaderType::Pointer reader2= ImageReaderType::New(); + reader2->SetFileName(m_InputName2); + reader2->Update(); + typename ImageType::Pointer input2=reader2->GetOutput(); + + //Create the ComposeVFFilter + typedef clitk::ComposeVFFilter FilterType; + typename FilterType::Pointer filter =FilterType::New(); + filter->SetInput1(input1); + filter->SetInput2(input2); + filter->SetVerbose(m_Verbose); + filter->Update(); + + //Write the output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_OutputName); + writer->SetInput(filter->GetOutput()); + writer->Update(); + + } +} + +#endif diff --git a/tools/clitkConeBeamProjectImage.cxx b/tools/clitkConeBeamProjectImage.cxx new file mode 100755 index 0000000..699be4c --- /dev/null +++ b/tools/clitkConeBeamProjectImage.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 CLITKCONEBEAMPROJECTIMAGE_CXX +#define CLITKCONEBEAMPROJECTIMAGE_CXX +/** + ================================================= + * @file clitkConeBeamProjectImage.cxx + * @author Jef Vandemeulebroucke + * @date 30 April 2008 + * + * @brief "Project a 3D image using a Cone-Beam geometry" + =================================================*/ + +// clitk include +#include "clitkConeBeamProjectImage_ggo.h" +#include "clitkConeBeamProjectImageGenericFilter.h" +#include "clitkIO.h" +#include "clitkImageCommon.h" +#include "clitkTransformUtilities.h" + +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkConeBeamProjectImage, args_info); + CLITK_INIT; + + // Creation of a generic filter + clitk::ConeBeamProjectImageGenericFilter::Pointer genericFilter = clitk::ConeBeamProjectImageGenericFilter::New(); + + //Passing the arguments to the generic filter + genericFilter->SetArgsInfo(args_info); + + // //Passing the arguments to the generic filter + // genericFilter->SetVerbose(args_info.verbose_flag); + // genericFilter->SetInput(args_info.input_arg); + // genericFilter->SetOutput(args_info.output_arg); + // //genericFilter->SetMask(args_info.mask_arg); + + // //set the three components of the isocenter + // std::vector iso(3); + // for (unsigned int i=0 ; i<3 ; i++) iso[i]=args_info.iso_arg[i]; + // genericFilter->SetIsoCenter(iso); + // genericFilter->SetSourceToScreen(args_info.screen_arg); + // genericFilter->SetSourceToAxis(args_info.axis_arg); + // genericFilter->SetProjectionAngle(args_info.angle_arg); + // if (args_info.matrix_given) genericFilter->SetRigidTransformMatrix(clitk::ReadMatrix3D(args_info.matrix_arg)); + // genericFilter->SetEdgePaddingValue(args_info.pad_arg); + + //update + genericFilter->Update(); + + return 0; +} + +#endif + + diff --git a/tools/clitkConeBeamProjectImage.ggo b/tools/clitkConeBeamProjectImage.ggo new file mode 100755 index 0000000..f6d381f --- /dev/null +++ b/tools/clitkConeBeamProjectImage.ggo @@ -0,0 +1,37 @@ +#File clitkConeBeamProjectImage.ggo +Package "clitk" +Version "Project a 3D image with cone-beam geometry" + +option "config" - "Config file" string no + +section "Run Time" + +option "verbose" v "Verbose" flag off +option "threads" - "Number of threads to use (default=min(cores,8))" int no + + +section "Input" + +option "input" i "Input grid filename" string yes +option "output" o "Output grid filename" string yes +option "mask" m "2D Mask in which the filter should be applied (not supported yet;-)" string no + + +section "Projection Parameters" + +option "iso" - "The isocenter" double no multiple default="0.0" +option "screen" - "Specify the source to screen distance in mm" double no default="1536.0" +option "axis" - "Specify the source to axis distance in mm" double no default="1000.0" +option "angle" - "Specify the projection angle" double no default="0.0" +option "matrix" - "Rigid tranform prior to projection (4x4)" string no +option "pad" - "Padding value" float no default="0.0" + + +section "Output Image" + +option "like" - "Make output like this image" string no +option "origin" - "Origin for the output image" double multiple no default="0.0" +option "size" - "Size for the output image" int multiple no default="512" +option "spacing" - "Spacing for the output image" double multiple no default="0.8" + + diff --git a/tools/clitkConeBeamProjectImageFilter.h b/tools/clitkConeBeamProjectImageFilter.h new file mode 100755 index 0000000..6ef578a --- /dev/null +++ b/tools/clitkConeBeamProjectImageFilter.h @@ -0,0 +1,244 @@ +/*========================================================================= + 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 __clitkConeBeamProjectImageFilter_h +#define __clitkConeBeamProjectImageFilter_h +#include "clitkImageCommon.h" +#include "clitkImageCommon.h" +#include "clitkTransformUtilities.h" +#include "clitkExtractImageFilter.h" +#include "itkRayCastInterpolateImageFunctionWithOrigin.h" + +//ITK include +#include "itkLightObject.h" +#include "itkResampleImageFilter.h" +#include "itkEuler3DTransform.h" +#include "itkExtractImageFilter.h" +#include "itkFlipImageFilter.h" + +namespace clitk +{ + + template + class ITK_EXPORT ConeBeamProjectImageFilter : public itk::LightObject + + { + public: + + typedef ConeBeamProjectImageFilter Self; + typedef itk::LightObject Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Determine the image dimension. */ + itkStaticConstMacro(InputImageDimension, unsigned int, + InputImageType::ImageDimension ); + + itkStaticConstMacro(OutputImageDimension, unsigned int, + OutputImageType::ImageDimension ); + + + //======================================================================================== + //Typedefs + typedef typename InputImageType::Pointer InputImagePointer; + typedef typename InputImageType::ConstPointer InputImageConstPointer; + typedef typename InputImageType::PixelType InputPixelType; + typedef typename InputImageType::SizeType InputSizeType; + typedef typename InputImageType::SpacingType InputSpacingType; + typedef typename InputImageType::DirectionType InputDirectionType; + typedef typename InputImageType::IndexType InputIndexType; + typedef typename InputImageType::PointType InputPointType; + + typedef typename OutputImageType::Pointer OutputImagePointer; + typedef typename OutputImageType::ConstPointer OutputImageConstPointer; + typedef typename OutputImageType::PixelType OutputPixelType; + typedef typename OutputImageType::SizeType OutputSizeType; + typedef typename OutputImageType::SpacingType OutputSpacingType; + typedef typename OutputImageType::DirectionType OutputDirectionType; + typedef typename OutputImageType::IndexType OutputIndexType; + typedef typename OutputImageType::PointType OutputPointType; + + typedef itk::Image InternalImageType; + + //Pipeline + typedef itk::Euler3DTransform TransformType; + typedef itk::ResampleImageFilter ResampleImageFilterType; + typedef itk::RayCastInterpolateImageFunctionWithOrigin InterpolatorType; + typedef clitk::ExtractImageFilter ExtractImageFilterType; + typedef itk::FlipImageFilter FlipImageFilterType; + typedef itk::Matrix MatrixType; + + //======================================================================================== + //Set Methods + //======================================================================================== + // Run-time + void SetVerbose(const bool m){m_Verbose=m;} + void SetNumberOfThreads(const unsigned int v) + { + m_NumberOfThreadsIsGiven=true; + m_NumberOfThreads=v; + } + + void SetInput(const InputImagePointer m) {m_Input=m;} //no reinitialize + + //================================================================================= + //Geometry (reinitialize) + void SetIsoCenter( const InputPointType & i ) + { + if( m_IsoCenter!=i) + { + m_IsoCenter=i; + m_IsInitialized=false; + } + } + + void SetSourceToScreen(const double& s) + { + if( m_SourceToScreen!=s) + { + m_SourceToScreen=s; + m_IsInitialized=false; + } + } + + void SetSourceToAxis( const double& s) + { + if( m_SourceToAxis!=s) + { + m_SourceToAxis=s; + m_IsInitialized=false; + } + } + + void SetProjectionAngle( const double& s) + { + if( m_SourceToScreen!=s) + { + m_ProjectionAngle=s; + m_IsInitialized=false; + } + } + + void SetRigidTransformMatrix(const MatrixType& m) + { + if(m_RigidTransformMatrix != m) + { + m_RigidTransformMatrix=m; + m_IsInitialized=false; + } + } + + void SetEdgePaddingValue(const OutputPixelType& p) + { + if (m_EdgePaddingValue!=p) + { + m_EdgePaddingValue=p; + m_IsInitialized=false; + } + } + + + //======================================================================================== + //Output image properties + /** Get the size of the output image. */ + void SetOutputSize(const OutputSizeType& p) + { + if (m_OutputSize!=p) + { + m_OutputSize=p; + m_IsInitialized=false; + } + } + + /** Set the output image spacing. */ + void SetOutputSpacing(const OutputSpacingType& p) + { + if (m_OutputSpacing!=p) + { + m_OutputSpacing=p; + m_IsInitialized=false; + } + } + + /** Set the output image origin. */ + void SetOutputOrigin(const OutputPointType& p) + { + if (m_OutputOrigin!=p) + { + m_OutputOrigin=p; + m_IsInitialized=false; + } + } + + /** Helper method to set the output parameters based on this image */ + void SetOutputParametersFromImage( const OutputImagePointer image ); + + /** Helper method to set the output parameters based on this image */ + void SetOutputParametersFromImage( const OutputImageConstPointer image ); + + //======================================================================================== + //Update + void Initialize(void)throw (itk::ExceptionObject); + void Update(void); + OutputImagePointer GetOutput(void); + + protected: + ConeBeamProjectImageFilter(); + ~ConeBeamProjectImageFilter() {}; + + // Run time + bool m_Verbose; + bool m_NumberOfThreadsIsGiven; + unsigned int m_NumberOfThreads; + bool m_IsInitialized; + //std::string m_Mask; + + // Data + InputImageConstPointer m_Input; + OutputImagePointer m_Output; + + // Geometry + InputPointType m_IsoCenter; + double m_SourceToScreen; + double m_SourceToAxis; + double m_ProjectionAngle; + MatrixType m_RigidTransformMatrix; + OutputPixelType m_EdgePaddingValue; + + // Pipe + TransformType::Pointer m_Transform; + typename ResampleImageFilterType::Pointer m_Resampler; + typename InterpolatorType::Pointer m_Interpolator; + typename ExtractImageFilterType::Pointer m_ExtractImageFilter; + typename FlipImageFilterType::Pointer m_FlipImageFilter; + + // Output image info + OutputSizeType m_OutputSize; // Size of the output image + OutputSpacingType m_OutputSpacing; // output image spacing + OutputPointType m_OutputOrigin; // output image origin + }; + + +} // end namespace clitk +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkConeBeamProjectImageFilter.txx" +#endif + +#endif // #define __clitkConeBeamProjectImageFilter_h diff --git a/tools/clitkConeBeamProjectImageFilter.txx b/tools/clitkConeBeamProjectImageFilter.txx new file mode 100755 index 0000000..173411f --- /dev/null +++ b/tools/clitkConeBeamProjectImageFilter.txx @@ -0,0 +1,255 @@ +/*========================================================================= + 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 __clitkConeBeamProjectImageFilter_txx +#define __clitkConeBeamProjectImageFilter_txx +namespace clitk +{ + + + //========================================================================================================================= + //Constructor + template + ConeBeamProjectImageFilter:: + ConeBeamProjectImageFilter() + { + // Initialize with the default values (Elekta Synergie) + m_Verbose=false; + m_IsInitialized=false; + m_NumberOfThreadsIsGiven=false; + + // Geometry + m_IsoCenter.Fill(0.0); + m_SourceToScreen=1536.; + m_SourceToAxis=1000.; + m_ProjectionAngle=0.; + m_RigidTransformMatrix.SetIdentity(); + m_EdgePaddingValue=itk::NumericTraits::Zero;//density images + + // Pipe + m_Transform=TransformType::New(); + m_Resampler=ResampleImageFilterType::New(); + m_Interpolator= InterpolatorType::New(); + m_ExtractImageFilter=ExtractImageFilterType::New(); + m_FlipImageFilter=FlipImageFilterType::New(); + + // Parameters for output + this->m_OutputSpacing.Fill(0.8); + this->m_OutputOrigin.Fill(0.0); + this->m_OutputSize.Fill( 512 ); + + } + + + //----------------------------------------------------------------------- + // Set output info from image + //----------------------------------------------------------------------- + template + void + ConeBeamProjectImageFilter + ::SetOutputParametersFromImage ( OutputImagePointer image ) + { + this->SetOutputOrigin( image->GetOrigin() ); + this->SetOutputSpacing( image->GetSpacing() ); + this->SetOutputSize( image->GetLargestPossibleRegion().GetSize() ); + } + + + //----------------------------------------------------------------------- + // Set output info from image + //----------------------------------------------------------------------- + template + void + ConeBeamProjectImageFilter + ::SetOutputParametersFromImage ( OutputImageConstPointer image ) + { + this->SetOutputOrigin( image->GetOrigin() ); + this->SetOutputSpacing( image->GetSpacing() ); + this->SetOutputSize( image->GetLargestPossibleRegion().GetSize() ); + } + + + //========================================================================================================================= + // Initialize + template + void + ConeBeamProjectImageFilter + ::Initialize(void) throw (itk::ExceptionObject) + { + + //==================================================================== + // Define the transform: composition of rigid transfo around origin and a centered rotation + // The center of rotation should be placed at the isocenter! + + if (m_Verbose) std::cout<<"The isocenter is at "<< m_IsoCenter <<"..." < rotationParameters(3); + const double dtr = ( atan(1.0) * 4.0 ) / 180.0; //constant for converting degrees into radians + if (m_Verbose)std::cout<<"The projection angle is "<< m_ProjectionAngle <<"° (0° being lateral left)..."<< std::endl; + rotationParameters[0]= 0.; + rotationParameters[1]= 0.; + rotationParameters[2]= -dtr*(double) m_ProjectionAngle; + + // We first perform rigid transform (of source and panel), then a centered rotation around the transformed center + itk::Matrix rigidRotation = GetRotationalPartMatrix3D(m_RigidTransformMatrix); + itk::Vector rigidTranslation = GetTranslationPartMatrix3D(m_RigidTransformMatrix); + typename InputImageType::PointType transformedCenter = rigidRotation * m_IsoCenter + rigidTranslation; + + // Calculate the centered rotation matrix + itk::Matrix centeredRotationMatrix = GetCenteredRotationMatrix3D(rotationParameters,transformedCenter); + + // Compose this rotation with the rigid transform matrix + itk::Matrix finalTransform = centeredRotationMatrix * m_RigidTransformMatrix; + + // Set the rotation + itk::Matrix finalRotation = GetRotationalPartMatrix3D(finalTransform); + m_Transform->SetMatrix(finalRotation); + if (m_Verbose)std::cout<<"The final rotation is "< finalTranslation = GetTranslationPartMatrix3D(finalTransform); + m_Transform->SetTranslation(finalTranslation); + if (m_Verbose)std::cout<<"The final translation is "<SetNumberOfThreads(m_NumberOfThreads); + m_Resampler->SetDefaultPixelValue(m_EdgePaddingValue); + if (m_Verbose)std::cout<<"The edge padding value is "<SetTransform(m_Transform); + m_Interpolator->SetThreshold(0.); + + // Focalpoint: we presume that for an angle of 0° the kV is lateral left (for the patient on his back), or on the positive X-axis. + typename InterpolatorType::InputPointType focalpoint; + focalpoint[0]= m_IsoCenter[0] + m_SourceToAxis; + focalpoint[1]= m_IsoCenter[1]; + focalpoint[2]= m_IsoCenter[2]; + m_Interpolator->SetFocalPoint(focalpoint); + if (m_Verbose)std::cout<<"The focalpoint is at "<< focalpoint <<"..."<< std::endl; + + // Connect the interpolator and the transform with the m_Resampler + m_Resampler->SetInterpolator( m_Interpolator ); + m_Resampler->SetTransform( m_Transform ); + + // Describe the output projection image + typename InputImageType::SizeType sizeOuput; + sizeOuput[0] = 1; // number of pixels along X of the 2D DRR image + sizeOuput[1] = m_OutputSize[0]; // number of pixels along Y of the 2D DRR image + sizeOuput[2] = m_OutputSize[1]; // number of pixels along Z of the 2D DRR image + m_Resampler->SetSize( sizeOuput ); + if (m_Verbose)std::cout<<"The output size is "<< m_OutputSize <<"..."<< std::endl; + + typename InputImageType::SpacingType spacingOutput; + spacingOutput[0] = 1; // pixel spacing along X of the 2D DRR image [mm] + spacingOutput[1] = m_OutputSpacing[0]; // pixel spacing along Y of the 2D DRR image [mm] + spacingOutput[2] = m_OutputSpacing[1]; // pixel spacing along Y of the 2D DRR image [mm] + m_Resampler->SetOutputSpacing( spacingOutput ); + if (m_Verbose)std::cout<<"The output size is "<< m_OutputSpacing <<"..."<< std::endl; + + // The position of the DRR is specified, we presume that for an angle of 0° the flatpanel is located at the negative x-axis + // JV -1 seems to correspond better with shearwarp of Simon Rit + typename InterpolatorType::InputPointType originOutput; + originOutput[0] = m_IsoCenter[0]- (m_SourceToScreen - m_SourceToAxis); + originOutput[1] = m_IsoCenter[1]-static_cast(sizeOuput[1]-1)*spacingOutput[1]/2.0; + originOutput[2] = m_IsoCenter[2]-static_cast(sizeOuput[2]-1)*spacingOutput[2]/2.0; + m_Resampler->SetOutputOrigin( originOutput ); + if (m_Verbose)std::cout<<"The origin of the flat panel is at "<< originOutput <<",..."<< std::endl; + + // We define the region to be extracted. Projection was in the YZ plane, X should be set to zero + typename InternalImageType::RegionType::SizeType sizeTemp=sizeOuput; + sizeTemp[0]=0; + typename InternalImageType::IndexType startTemp; //=temp->GetLargestPossibleRegion().GetIndex(); + startTemp.Fill(0); + + typename InternalImageType::RegionType desiredRegion; + desiredRegion.SetSize( sizeTemp ); + desiredRegion.SetIndex( startTemp ); + m_ExtractImageFilter->SetExtractionRegion( desiredRegion ); + + // Prepare the Flip Image filter + typename FlipImageFilterType::FlipAxesArrayType flipArray; + flipArray[0] = 0; + flipArray[1] = 1; + m_FlipImageFilter->SetFlipAxes( flipArray ); + + // Initialization complete + m_IsInitialized=true; + + } + + //========================================================================================================================= + // Update + template + void + ConeBeamProjectImageFilter + ::Update(void) + { + + //================================================================== + // If geometry changed reinitialize + if (! m_IsInitialized) this->Initialize(); + + // Input + m_Resampler->SetInput( m_Input ); + + //================================================================== + // Execute the filter + if (m_Verbose)std::cout<<"Starting the projection..."<Update(); + } + catch( itk::ExceptionObject & err ) + { + std::cerr << "ExceptionObject caught! Projection failed!" << std::endl; + std::cerr << err << std::endl; + } + + //================================================================== + // Make a 2D image out of it + typename InternalImageType::Pointer temp=m_Resampler->GetOutput(); + m_ExtractImageFilter->SetInput(temp); + + // We should flip the Y axis + m_FlipImageFilter->SetInput(m_ExtractImageFilter->GetOutput()); + m_FlipImageFilter->Update(); + + // Get output + m_Output= m_FlipImageFilter->GetOutput(); + m_Output->Update(); + m_Output->SetOrigin(m_OutputOrigin); + } + + //========================================================================================================================= + // GetOutput + template + typename OutputImageType::Pointer + ConeBeamProjectImageFilter + ::GetOutput(void) + { + //JV it is not safe to repeatedly call getoutput/ always call Update first + return m_Output; + } + +} + + +#endif diff --git a/tools/clitkConeBeamProjectImageGenericFilter.cxx b/tools/clitkConeBeamProjectImageGenericFilter.cxx new file mode 100755 index 0000000..2128c81 --- /dev/null +++ b/tools/clitkConeBeamProjectImageGenericFilter.cxx @@ -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 +======================================================================-====*/ +#ifndef CLITKCONEBEAMPROJECTIMAGEGENERICFILTER_CXX +#define CLITKCONEBEAMPROJECTIMAGEGENERICFILTER_CXX + +/** + * @file clitkConeBeamProjectImageGenericFilter.cxx + * @author Jef Vandemeulebroucke + * @date Wed April 30 13:47:57 2008 + * + * @brief + * + * + */ + +#include "clitkConeBeamProjectImageGenericFilter.h" + +namespace clitk +{ + + //==================================================================== + // Constructor + ConeBeamProjectImageGenericFilter::ConeBeamProjectImageGenericFilter() + { + + m_Verbose=false; + m_InputFileName=""; + +// mIsoCenter.resize(3); +// for (unsigned int j=0; j < 3; j++) mIsoCenter[j]=128.; +// mSourceToScreen=1536.; +// mSourceToAxis=1000.; +// mProjectionAngle=0.; + +// // set the rigid transform matrix to the identity +// for (unsigned int i=0; i <4; i++) +// for (unsigned int j=0; j <4; j++) +// if (i==j)mRigidTransformMatrix[i][j]=1.; +// else mRigidTransformMatrix[i][j]=0.; + +// //Padding value +// mEdgePaddingValue=0.0; + } + + //==================================================================== + // Update + void ConeBeamProjectImageGenericFilter::Update() + { + //Read the PixelType and dimension of the input image + int Dimension; + std::string PixelType; + clitk::ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + if (Dimension == 3) + { + if (m_Verbose) std::cout << "Input was detected to be "<< Dimension << "D and " << PixelType << "..." << std::endl; + + if(PixelType == "short"){ + if (m_Verbose) std::cout << "Launching Projection in signed short..." << std::endl; + UpdateWithPixelType(); + } + +// else if(PixelType == "unsigned_short"){ +// if (m_Verbose) std::cout << "Launching Projection in unsigned_short..." << std::endl; +// UpdateWithPixelType(); +// } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching Projection in unsigned_char..." << std::endl; + UpdateWithPixelType(); + } + +// else if (PixelType == "char"){ +// if (m_Verbose) std::cout << "Launching Projection in signed_char..." << std::endl; +// UpdateWithPixelType(); +// } + else { + if (m_Verbose) std::cout << "Launching Projection in float..." << std::endl; + UpdateWithPixelType(); + } + } + + else {itkExceptionMacro(<< "Input Image dimension is " << Dimension + << " but I can only work on 3D images."); + } + } + + + //==================================================================== + +} +#endif //#define CLITKCONEBEAMPROJECTIMAGEGENERICFILTER_CXX diff --git a/tools/clitkConeBeamProjectImageGenericFilter.h b/tools/clitkConeBeamProjectImageGenericFilter.h new file mode 100755 index 0000000..9ed8826 --- /dev/null +++ b/tools/clitkConeBeamProjectImageGenericFilter.h @@ -0,0 +1,117 @@ +/*========================================================================= + 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 CLITKCONEBEAMPROJECTIMAGEGENERICFILTER__H +#define CLITKCONEBEAMPROJECTIMAGEGENERICFILTER__H +/** + ================================================= + * @file clitkConeBeamProjectImageGenericFilter.h + * @author Jef Vandemeulebroucke + * @date 30 April 2008 + * + * @brief Project a 3D image using a ConeBeam geometry + * + =================================================*/ + +// clitk include +#include "clitkIO.h" +#include "clitkImageCommon.h" +#include "clitkImageCommon.h" +#include "clitkConeBeamProjectImageFilter.h" +#include "clitkConeBeamProjectImage_ggo.h" + +// itk include +#include "itkLightObject.h" + + +namespace clitk { + + //==================================================================== + class ConeBeamProjectImageGenericFilter: public itk::LightObject + { + public: + + //Typedefs ITK================================================ + typedef ConeBeamProjectImageGenericFilter Self; + typedef itk::LightObject Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + //ITK Method for object creation================================================ + itkNewMacro(Self); + + + //==================================================================== + // Set methods + void SetArgsInfo(const args_info_clitkConeBeamProjectImage a) + { + m_ArgsInfo=a; + m_InputFileName=m_ArgsInfo.input_arg; + m_Verbose=m_ArgsInfo.verbose_flag; + } + + // void SetVerbose(const bool v){mVerbose=v;} + // void SetInput(const std::string i) { mInput = i; } + // void SetOutput(const std::string o) { mOutput = o; } + // void SetMask(const std::string m) {mMask = m;} + // void SetIsoCenter(const std::vector i) + // { + // mIsoCenter.resize(3); + // for (unsigned int j=0; j < 3; j++) mIsoCenter[j]=i[j]; + // } + // void SetSourceToScreen(const double s) {mSourceToScreen = s;} + // void SetSourceToAxis(const double s) {mSourceToAxis = s;} + // void SetProjectionAngle(const double a) {mProjectionAngle = a;} + // void SetRigidTransformMatrix(const itk::Matrix m) {mRigidTransformMatrix=m;} + // void SetEdgePaddingValue(const double m) {mEdgePaddingValue=m;} + + //==================================================================== + // Update + virtual void Update(); + + protected: + const char * GetNameOfClass() const { return "ConeBeamProjectImageGenericFilter"; } + + //==================================================================== + // Constructor & Destructor + ConeBeamProjectImageGenericFilter(); + ~ConeBeamProjectImageGenericFilter(){;} + + //==================================================================== + //Protected member functions + template void UpdateWithPixelType(); + + bool m_Verbose; + std::string m_InputFileName; + args_info_clitkConeBeamProjectImage m_ArgsInfo; + // std::string mOutput; + // std::string mMask; + // std::vector mIsoCenter; + // double mSourceToScreen; + // double mSourceToAxis; + // double mProjectionAngle; + // itk::Matrix mRigidTransformMatrix; + // double mEdgePaddingValue; + + }; + +} // end namespace clitk +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkConeBeamProjectImageGenericFilter.txx" +#endif + +#endif //#define CLITKCONEBEAMPROJECTIMAGEGENERICFILTER__H diff --git a/tools/clitkConeBeamProjectImageGenericFilter.txx b/tools/clitkConeBeamProjectImageGenericFilter.txx new file mode 100755 index 0000000..7391e35 --- /dev/null +++ b/tools/clitkConeBeamProjectImageGenericFilter.txx @@ -0,0 +1,135 @@ +/*========================================================================= + 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 CLITKCONEBEAMPROJECTIMAGEGENERICFILTER_TXX +#define CLITKCONEBEAMPROJECTIMAGEGENERICFILTER_TXX +/** + ================================================= + * @file clitkConeBeamProjectImageGenericFilter.txx + * @author Jef Vandemeulebroucke + * @date 30 April 2008 + * + * @brief Project a 3D image using a cone-beam geometry + * + =================================================*/ + + +namespace clitk +{ + + //================================================================================ + template void ConeBeamProjectImageGenericFilter::UpdateWithPixelType() + { + + //=================================================================== + // Read the input image + const unsigned int InputImageDimension=3; + typedef itk::Image InputImageType; + typedef itk::ImageFileReader ImageReaderType; + typename ImageReaderType::Pointer reader = ImageReaderType::New(); + reader->SetFileName(m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input = reader->GetOutput(); + + // Define the output type + //JV always float? + typedef float OutputPixelType; + const unsigned int OutputImageDimension=2; + typedef itk::Image OutputImageType; + + // Create the ConeBeamProjectImageFilter + typedef clitk::ConeBeamProjectImageFilter ConeBeamProjectImageFilterType; + typename ConeBeamProjectImageFilterType::Pointer filter=ConeBeamProjectImageFilterType::New(); + + // Pass all the necessary parameters + filter->SetInput(input); + filter->SetVerbose(m_Verbose); + if (m_ArgsInfo.threads_given) filter->SetNumberOfThreads(m_ArgsInfo.threads_arg); + + // Projection parameters + typename InputImageType::PointType iso; + unsigned int i; + if (m_ArgsInfo.iso_given) + for(i=0;iSetIsoCenter(iso); + } + filter->SetSourceToScreen(m_ArgsInfo.screen_arg); + filter->SetSourceToAxis(m_ArgsInfo.axis_arg); + filter->SetProjectionAngle(m_ArgsInfo.angle_arg); + if (m_ArgsInfo.matrix_given) + { + itk::Matrix rt =ReadMatrix3D(m_ArgsInfo.matrix_arg); + filter->SetRigidTransformMatrix(rt); + } + filter->SetEdgePaddingValue(static_cast(m_ArgsInfo.pad_arg)); + + // Output image info + if (m_ArgsInfo.like_given) + { + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader2=ReaderType::New(); + reader2->SetFileName(m_ArgsInfo.like_arg); + reader2->Update(); + + OutputImageType::Pointer image=reader2->GetOutput(); + filter->SetOutputParametersFromImage(image); + } + else + { + if (m_ArgsInfo.origin_given) + { + OutputImageType::PointType origin; + for(i=0;iSetOutputOrigin(origin); + } + if (m_ArgsInfo.spacing_given) + { + OutputImageType::SpacingType spacing; + for(i=0;iSetOutputSpacing(spacing); + } + if (m_ArgsInfo.size_given) + { + OutputImageType::SizeType size; + for(i=0;iSetOutputSize(size); + } + } + + //Go + filter->Update(); + + //Get the output + OutputImageType::Pointer output=filter->GetOutput(); + + //Write the output + typedef itk::ImageFileWriter OutputWriterType; + OutputWriterType::Pointer outputWriter = OutputWriterType::New(); + outputWriter->SetInput(output); + outputWriter->SetFileName(m_ArgsInfo.output_arg); + if (m_Verbose)std::cout<<"Writing projected image..."<Update(); + } + +} + +#endif //#define CLITKGENERICIMAGEFILTER diff --git a/tools/clitkCropImage.cxx b/tools/clitkCropImage.cxx new file mode 100755 index 0000000..daa81ec --- /dev/null +++ b/tools/clitkCropImage.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkCropImage.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkCropImage_ggo.h" +#include "clitkIO.h" +#include "clitkCropImageGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkCropImage, args_info); + CLITK_INIT; + + // Filter + clitk::CropImageGenericFilter::Pointer genericFilter=clitk::CropImageGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkCropImage.ggo b/tools/clitkCropImage.ggo new file mode 100755 index 0000000..d808921 --- /dev/null +++ b/tools/clitkCropImage.ggo @@ -0,0 +1,14 @@ +#File clitkCropImage.ggo +Package "clitkCropImage" +version "1.0" +purpose "Reduce the image size by removing regions at the lower and upper end." + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "boundingBox" b "Bounding box of the crop region" int no multiple +option "lower" l "Size of the lower crop region" int no multiple +option "upper" u "Size of the upper crop region" int no multiple +option "origin" - "Set new origin to zero" flag off diff --git a/tools/clitkCropImageGenericFilter.cxx b/tools/clitkCropImageGenericFilter.cxx new file mode 100755 index 0000000..7e37c1c --- /dev/null +++ b/tools/clitkCropImageGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkCropImageGenericFilter_cxx +#define clitkCropImageGenericFilter_cxx + +/* ================================================= + * @file clitkCropImageGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkCropImageGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + CropImageGenericFilter::CropImageGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void CropImageGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension, Components; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType, Components); + else if(Dimension==3) UpdateWithDim<3>(PixelType, Components); + else if (Dimension==4)UpdateWithDim<4>(PixelType, Components); + else + { + std::cout<<"Error, Only for 2, 3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( CropImageGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkCropImage & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + CropImageGenericFilter(); + ~CropImageGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType, unsigned int Components); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkCropImage m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkCropImageGenericFilter.txx" +#endif + +#endif // #define clitkCropImageGenericFilter_h diff --git a/tools/clitkCropImageGenericFilter.txx b/tools/clitkCropImageGenericFilter.txx new file mode 100755 index 0000000..b35e557 --- /dev/null +++ b/tools/clitkCropImageGenericFilter.txx @@ -0,0 +1,152 @@ +/*========================================================================= + 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 clitkCropImageGenericFilter_txx +#define clitkCropImageGenericFilter_txx + +/* ================================================= + * @file clitkCropImageGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + CropImageGenericFilter::UpdateWithDim(std::string PixelType, unsigned int Components) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + else if (Components==3) + { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 3D float (DVF)" << std::endl; + UpdateWithDimAndPixelType >(); + } + + else std::cerr<<"Number of components is "< + void + CropImageGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update( ); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typedef itk::CropImageFilter CropImageFilterType; + typename CropImageFilterType::Pointer cropFilter=CropImageFilterType::New(); + cropFilter->SetInput(input); + typename InputImageType::SizeType lSize, uSize; + + if (m_ArgsInfo.boundingBox_given) + { + for(unsigned int i=0;iGetLargestPossibleRegion().GetSize()[i]-m_ArgsInfo.boundingBox_arg[2*i+1]-1; + } + } + else + { + + if (m_ArgsInfo.lower_given) + for(unsigned int i=0;i(m_ArgsInfo.lower_arg[i]); + else lSize.Fill(0); + + if (m_ArgsInfo.upper_given) + for(unsigned int i=0;i(m_ArgsInfo.upper_arg[i]); + else uSize.Fill(0); + } + + cropFilter->SetLowerBoundaryCropSize(lSize); + cropFilter->SetUpperBoundaryCropSize(uSize); + cropFilter->Update(); + typename OutputImageType::Pointer output= cropFilter->GetOutput(); + + // Origin? + typename OutputImageType::PointType origin; + origin.Fill(itk::NumericTraits::Zero); + if (m_ArgsInfo.origin_flag) + { + output->SetOrigin(origin); + output->Update(); + if (m_Verbose) std::cout<<"Setting origin to "<< origin<<"..."< WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + } + + +}//end clitk + +#endif //#define clitkCropImageGenericFilter_txx diff --git a/tools/clitkExtractSlice.cxx b/tools/clitkExtractSlice.cxx new file mode 100755 index 0000000..60e6c83 --- /dev/null +++ b/tools/clitkExtractSlice.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkExtractSlice.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkExtractSlice_ggo.h" +#include "clitkIO.h" +#include "clitkExtractSliceGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkExtractSlice,args_info); + CLITK_INIT; + + // Filter + clitk::ExtractSliceGenericFilter::Pointer genericFilter=clitk::ExtractSliceGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkExtractSlice.ggo b/tools/clitkExtractSlice.ggo new file mode 100755 index 0000000..9f24736 --- /dev/null +++ b/tools/clitkExtractSlice.ggo @@ -0,0 +1,13 @@ +#File clitkExtractSlice.ggo +Package "clitkExtractSlice" +version "1.0" +purpose "Extract a slice: will collapse the dimension given by axe, retaining only the index given by slice." + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "axe" a "Axe (0,1, ...)" int no default="0" +option "slice" s "Slice index (0,1,....)" int no default="0" + diff --git a/tools/clitkExtractSliceGenericFilter.cxx b/tools/clitkExtractSliceGenericFilter.cxx new file mode 100755 index 0000000..b278d03 --- /dev/null +++ b/tools/clitkExtractSliceGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkExtractSliceGenericFilter_cxx +#define clitkExtractSliceGenericFilter_cxx + +/* ================================================= + * @file clitkExtractSliceGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkExtractSliceGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + ExtractSliceGenericFilter::ExtractSliceGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void ExtractSliceGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + // else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 2 or 3 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( ExtractSliceGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkExtractSlice & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + ExtractSliceGenericFilter(); + ~ExtractSliceGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkExtractSlice m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkExtractSliceGenericFilter.txx" +#endif + +#endif // #define clitkExtractSliceGenericFilter_h diff --git a/tools/clitkExtractSliceGenericFilter.txx b/tools/clitkExtractSliceGenericFilter.txx new file mode 100755 index 0000000..8b070cd --- /dev/null +++ b/tools/clitkExtractSliceGenericFilter.txx @@ -0,0 +1,130 @@ +/*========================================================================= + 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 clitkExtractSliceGenericFilter_txx +#define clitkExtractSliceGenericFilter_txx + +/* ================================================= + * @file clitkExtractSliceGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + ExtractSliceGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + ExtractSliceGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typedef clitk::ExtractImageFilter ExtractImageFilterType; + typename ExtractImageFilterType::Pointer extractFilter=ExtractImageFilterType::New(); + extractFilter->SetInput(input); + + // Verify input + if( (m_ArgsInfo.axe_arg<0) || (static_cast(m_ArgsInfo.axe_arg) >= Dimension) ) + { + std::cerr<<"The axe index does not name a dimension!!"<GetLargestPossibleRegion(); + typename InputImageType::RegionType::SizeType size= region.GetSize(); + + if( (m_ArgsInfo.slice_arg<0) || (static_cast(m_ArgsInfo.slice_arg) >= size[static_cast(m_ArgsInfo.axe_arg)]) ) + { + std::cerr<<"The slice index does not name a slice!!"<SetExtractionRegion(region); + extractFilter->Update(); + typename OutputImageType::Pointer output =extractFilter->GetOutput(); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + + } + + +}//end clitk + +#endif //#define clitkExtractSliceGenericFilter_txx diff --git a/filters/clitkBinarizeImageGenericFilter.cxx b/tools/clitkFilter.cxx old mode 100644 new mode 100755 similarity index 58% rename from filters/clitkBinarizeImageGenericFilter.cxx rename to tools/clitkFilter.cxx index 6e5a5f4..a7601be --- a/filters/clitkBinarizeImageGenericFilter.cxx +++ b/tools/clitkFilter.cxx @@ -1,7 +1,7 @@ /*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv - Authors belong to: + 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 @@ -15,18 +15,37 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ======================================================================-====*/ -#ifndef clitkBinarizeImageGenericFilter_cxx -#define clitkBinarizeImageGenericFilter_cxx /* ================================================= - * @file clitkBinarizeImageGenericFilter.cxx - * @author Jef Vandemeulebroucke - * @date 29 june 2009 - * - * @brief - * + * @file clitkFilter.cxx + * @author + * @date + * + * @brief + * ===================================================*/ -#include "clitkBinarizeImageGenericFilter.h" -#endif //#define clitkBinarizeImageGenericFilter_cxx +// clitk +#include "clitkFilter_ggo.h" +#include "clitkIO.h" +#include "clitkFilterGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkFilter, args_info); + CLITK_INIT; + + // Filter + clitk::FilterGenericFilter::Pointer genericFilter=clitk::FilterGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkFilter.ggo b/tools/clitkFilter.ggo new file mode 100755 index 0000000..6cceb75 --- /dev/null +++ b/tools/clitkFilter.ggo @@ -0,0 +1,30 @@ +#File clitkFilter.ggo +Package "clitkFilter" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "mask" m "Mask in which the filter should be applied" string no + +option "float" - "Convert to float first " flag off + +section "Filter" + +option "type" t "Type of filter: 0=derivative, 1= gradient magnitude, 2= projection, 3= intensity windowing, 4=BSplineDownsampling with factor 2, 5=normalize intensities (mean=0 ,SD=1), 6=anisotropic diffusion, 7=gradient anisotropic diffusion, 8=curvature anisotropic diffusion, 9= curvature flow" int no default="0" +option "order" - "0: what order" int no default="1" +option "direction" - "0-2: what direction" int no default="0" +option "projection" - "2: what accumulation (0=sum, 1=max, 2=min) " int no default="0" +option "inputMin" - "3: set window minimum" float no default="0" +option "inputMax" - "3: set window maximum" float no default="100" +option "outputMin" - "3: set output minimum" float no default="0" +option "outputMax" - "3: set output maximum" float no default="255" +option "resamplerType" - "4: Resampler type to use for the downsampling (0=Standard, 1=Centered, 2=L2, 3=L2Centered) " int no default="0" +option "splineOrder" - "4: SplineOrder to use for the downsampling (0-5, some resamplers only odd) " int no default="3" +option "cond" - "6-8: conductance parameter" double no default="3.0" +option "time" - "6-9: Time step (6,7: 0.25 for 2D and 0.125 for 3D; 8,9:0.125 for 2D and 0.0625 for 3D)" double no default="0.125" +option "iter" - "6-9: Iterations (6-8=5; 9=10)" double no default="5" +option "radius" - "9: radius" double no default="1" diff --git a/tools/clitkFilterGenericFilter.cxx b/tools/clitkFilterGenericFilter.cxx new file mode 100755 index 0000000..8ee07cc --- /dev/null +++ b/tools/clitkFilterGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkFilterGenericFilter_cxx +#define clitkFilterGenericFilter_cxx + +/* ================================================= + * @file clitkFilterGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkFilterGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + FilterGenericFilter::FilterGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void FilterGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 2 or 3 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( FilterGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkFilter & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + FilterGenericFilter(); + ~FilterGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkFilter m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkFilterGenericFilter.txx" +#endif + +#endif // #define clitkFilterGenericFilter_h diff --git a/tools/clitkFilterGenericFilter.txx b/tools/clitkFilterGenericFilter.txx new file mode 100755 index 0000000..9b70da0 --- /dev/null +++ b/tools/clitkFilterGenericFilter.txx @@ -0,0 +1,304 @@ +/*========================================================================= + 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 clitkFilterGenericFilter_txx +#define clitkFilterGenericFilter_txx + +/* ================================================= + * @file clitkFilterGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + FilterGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); +// } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + +// else if (PixelType == "unsigned_char"){ +// if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; +// UpdateWithDimAndPixelType(); +// } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + // else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); +// } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + FilterGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image InternalImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + + // Filter + typedef itk::ImageToImageFilter< InternalImageType, InternalImageType > ImageToImageFilterType; + typename ImageToImageFilterType::Pointer filter; + + switch ( m_ArgsInfo.type_arg ){ + + case 0:{ + typename itk::DerivativeImageFilter< InternalImageType,InternalImageType >::Pointer df = itk::DerivativeImageFilter::New(); + + //Set parameters + df->SetDirection(m_ArgsInfo.direction_arg); + df->SetOrder(m_ArgsInfo.order_arg); + filter=df; + if (m_Verbose) std::cout<<"Using the derivative image filter with order "<::Pointer gf = itk::GradientMagnitudeImageFilter::New(); + + //Set parameters + gf->SetUseImageSpacingOn(); + + filter=gf; + if (m_Verbose) std::cout<<"Using the gradient magnitude image filter... "<< std::endl; + break; + } + case 2:{ + + switch ( m_ArgsInfo.projection_arg ){ + + case 0:{ + //Sum + typename itk::SumProjectionImageFilter< InternalImageType,InternalImageType >::Pointer pf = itk::SumProjectionImageFilter::New(); + //Set parameters + pf->SetProjectionDimension(m_ArgsInfo.direction_arg); + + filter=pf; + if (m_Verbose) std::cout<<"Using the Sum projection image filter on the dimension "<< m_ArgsInfo.direction_arg << "..."<::Pointer pf = itk::MaximumProjectionImageFilter::New(); + //Set parameters + pf->SetProjectionDimension(m_ArgsInfo.direction_arg); + + filter=pf; + if (m_Verbose) std::cout<<"Using the maximum intensity projection image filter on the dimension "<< m_ArgsInfo.direction_arg << "..."<::Pointer pf = itk::MinimumProjectionImageFilter::New(); + //Set parameters + pf->SetProjectionDimension(m_ArgsInfo.direction_arg); + + filter=pf; + if (m_Verbose) std::cout<<"Using the minimum intensity projection image filter on the dimension "<< m_ArgsInfo.direction_arg << "..."<::Pointer pf + = itk::IntensityWindowingImageFilter::New(); + //Set parameters + pf->SetWindowMinimum((InternalPixelType) m_ArgsInfo.inputMin_arg); + pf->SetWindowMaximum((InternalPixelType) m_ArgsInfo.inputMax_arg); + pf->SetOutputMinimum((InternalPixelType) m_ArgsInfo.outputMin_arg); + pf->SetOutputMaximum((InternalPixelType) m_ArgsInfo.outputMax_arg); + + filter=pf; + if (m_Verbose) std::cout<<"Using the window intensity image filter with the window min and max being " + << m_ArgsInfo.inputMin_arg << " and "<< m_ArgsInfo.inputMax_arg + <<" and the output min and max being "< ResamplerType; + typedef itk::BSplineCenteredResampleImageFilterBase CenteredResamplerType; + typedef itk::BSplineL2ResampleImageFilterBase L2ResamplerType; + typedef itk::BSplineCenteredL2ResampleImageFilterBase CenteredL2ResamplerType; + + //ResamplerType + if(m_ArgsInfo.resamplerType_arg==0) + { + typename itk::BSplineDownsampleImageFilter< InternalImageType,InternalImageType, ResamplerType >::Pointer df + = itk::BSplineDownsampleImageFilter< InternalImageType,InternalImageType, ResamplerType >::New(); + df->SetSplineOrder(m_ArgsInfo.splineOrder_arg); + filter=df; + if (m_Verbose) std::cout<<"Using the BSpline downsample image filter with Standard Resampler"<::Pointer df + = itk::BSplineDownsampleImageFilter< InternalImageType,InternalImageType, CenteredResamplerType >::New(); + df->SetSplineOrder(m_ArgsInfo.splineOrder_arg); + filter=df; + if (m_Verbose) std::cout<<"Using the BSpline downsample image filter with Centered Resampler"<::Pointer df + = itk::BSplineDownsampleImageFilter< InternalImageType,InternalImageType,L2ResamplerType >::New(); + df->SetSplineOrder(m_ArgsInfo.splineOrder_arg); + filter=df; + if (m_Verbose) std::cout<<"Using the BSpline downsample image filter with L2 Resampler"<::Pointer df + = itk::BSplineDownsampleImageFilter< InternalImageType,InternalImageType,CenteredL2ResamplerType >::New(); + df->SetSplineOrder(m_ArgsInfo.splineOrder_arg); + filter=df; + if (m_Verbose) std::cout<<"Using the BSpline downsample image filter with L2 Centered Resampler"< NormalizeFilterType; + typename NormalizeFilterType::Pointer df = NormalizeFilterType::New(); + filter=df; + if (m_Verbose) std::cout << "Normalizing image intensities to a zero mean and 1 SD (float!)..." << std::endl; + break; + } +// case 6: { +// typedef itk::AnisotropicDiffusionImageFilter FilterType; +// typename FilterType::Pointer df = FilterType::New(); +// df->SetConductanceParameter(m_ArgsInfo.cond_arg); +// df->SetNumberOfIterations(m_ArgsInfo.iter_arg); +// df->SetTimeStep(m_ArgsInfo.time_arg); +// df->SetUseImageSpacing(true); + +// filter=df; +// if (m_Verbose) std::cout << "Using the anisotropic diffusion image filter..." << std::endl; +// break; +// } + + case 7: { + typedef itk::GradientAnisotropicDiffusionImageFilter FilterType; + typename FilterType::Pointer df = FilterType::New(); + df->SetConductanceParameter(m_ArgsInfo.cond_arg); + df->SetNumberOfIterations(m_ArgsInfo.iter_arg); + df->SetTimeStep(m_ArgsInfo.time_arg); + df->SetUseImageSpacing(true); + + filter=df; + if (m_Verbose) std::cout << "Using the gradient anisotropic diffusion image filter..." << std::endl; + break; + } + + case 8: { + typedef itk::CurvatureAnisotropicDiffusionImageFilter FilterType; + typename FilterType::Pointer df = FilterType::New(); + df->SetConductanceParameter(m_ArgsInfo.cond_arg); + df->SetNumberOfIterations(m_ArgsInfo.iter_arg); + df->SetTimeStep(m_ArgsInfo.time_arg); + df->SetUseImageSpacing(true); + + filter=df; + if (m_Verbose) std::cout << "Using the Curvature anisotropic diffusion image filter..." << std::endl; + break; + } + + case 9: { + typedef itk::CurvatureFlowImageFilter FilterType; + typename FilterType::Pointer df = FilterType::New(); + df->SetTimeStep(m_ArgsInfo.time_arg); + df->SetUseImageSpacing(true); + df->SetNumberOfIterations(m_ArgsInfo.iter_arg); + filter=df; + if (m_Verbose) std::cout << "Using the curvature flow image filter......" << std::endl; + break; + } + + + }//end switch filterType + + + //================================================================== + //execute the filter + filter->SetInput(input); + + + if (m_Verbose)std::cout<<"Starting filter..."<Update(); + } + catch( itk::ExceptionObject & err ) + { + std::cerr << "ExceptionObject caught! Filter failed!" << std::endl; + std::cerr << err << std::endl; + return; + } + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(filter->GetOutput()); + writer->Update(); + + } + + +}//end clitk + +#endif //#define clitkFilterGenericFilter_txx diff --git a/tools/clitkFlipImage.cxx b/tools/clitkFlipImage.cxx new file mode 100755 index 0000000..da52b19 --- /dev/null +++ b/tools/clitkFlipImage.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkFlipImage.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkFlipImage_ggo.h" +#include "clitkIO.h" +#include "clitkFlipImageGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkFlipImage, args_info); + CLITK_INIT; + + // Filter + clitk::FlipImageGenericFilter::Pointer genericFilter=clitk::FlipImageGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkFlipImage.ggo b/tools/clitkFlipImage.ggo new file mode 100755 index 0000000..9eabf27 --- /dev/null +++ b/tools/clitkFlipImage.ggo @@ -0,0 +1,12 @@ +#File clitkFlipImage.ggo +Package "clitkFlipImage" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "axe" a "Axe" int no default="0" +option "origin" - "Flip around origin" flag off diff --git a/tools/clitkFlipImageGenericFilter.cxx b/tools/clitkFlipImageGenericFilter.cxx new file mode 100755 index 0000000..3a5ea97 --- /dev/null +++ b/tools/clitkFlipImageGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkFlipImageGenericFilter_cxx +#define clitkFlipImageGenericFilter_cxx + +/* ================================================= + * @file clitkFlipImageGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkFlipImageGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + FlipImageGenericFilter::FlipImageGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void FlipImageGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 2,3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( FlipImageGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkFlipImage & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + FlipImageGenericFilter(); + ~FlipImageGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkFlipImage m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkFlipImageGenericFilter.txx" +#endif + +#endif // #define clitkFlipImageGenericFilter_h diff --git a/tools/clitkFlipImageGenericFilter.txx b/tools/clitkFlipImageGenericFilter.txx new file mode 100755 index 0000000..315ebc9 --- /dev/null +++ b/tools/clitkFlipImageGenericFilter.txx @@ -0,0 +1,120 @@ +/*========================================================================= + 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 clitkFlipImageGenericFilter_txx +#define clitkFlipImageGenericFilter_txx + +/* ================================================= + * @file clitkFlipImageGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + FlipImageGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + FlipImageGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typedef itk::FlipImageFilter FlipImageFilterType; + typename FlipImageFilterType::Pointer flipFilter=FlipImageFilterType::New(); + flipFilter->SetInput(input); + if ((unsigned int)m_ArgsInfo.axe_arg>= Dimension || (unsigned int)m_ArgsInfo.axe_arg<0) + { + std::cerr<<"Bad axe input!!"<SetFlipAxes(axes); + flipFilter->SetFlipAboutOrigin(m_ArgsInfo.origin_flag); + } + + flipFilter->Update(); + typename OutputImageType::Pointer output=flipFilter->GetOutput(); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + + } + + +}//end clitk + +#endif //#define clitkFlipImageGenericFilter_txx diff --git a/filters/clitkFooImage.ggo b/tools/clitkFooImage.ggo old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkFooImage.ggo rename to tools/clitkFooImage.ggo diff --git a/filters/clitkFooImageGenericFilter.h b/tools/clitkFooImageGenericFilter.h old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkFooImageGenericFilter.h rename to tools/clitkFooImageGenericFilter.h diff --git a/filters/clitkFooImageGenericFilter.txx b/tools/clitkFooImageGenericFilter.txx old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkFooImageGenericFilter.txx rename to tools/clitkFooImageGenericFilter.txx diff --git a/tools/clitkGetDirection.cxx b/tools/clitkGetDirection.cxx new file mode 100755 index 0000000..5fa146e --- /dev/null +++ b/tools/clitkGetDirection.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkGetDirection.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkGetDirection_ggo.h" +#include "clitkIO.h" +#include "clitkGetDirectionGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkGetDirection, args_info); + CLITK_INIT; + + // Filter + clitk::GetDirectionGenericFilter::Pointer genericFilter=clitk::GetDirectionGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkGetDirection.ggo b/tools/clitkGetDirection.ggo new file mode 100755 index 0000000..a9c70a5 --- /dev/null +++ b/tools/clitkGetDirection.ggo @@ -0,0 +1,11 @@ +#File clitkGetDirection.ggo +Package "clitkGetDirection" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes + + diff --git a/tools/clitkGetDirectionGenericFilter.cxx b/tools/clitkGetDirectionGenericFilter.cxx new file mode 100755 index 0000000..f7b4cd9 --- /dev/null +++ b/tools/clitkGetDirectionGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkGetDirectionGenericFilter_cxx +#define clitkGetDirectionGenericFilter_cxx + +/* ================================================= + * @file clitkGetDirectionGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkGetDirectionGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + GetDirectionGenericFilter::GetDirectionGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void GetDirectionGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 2,3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( GetDirectionGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkGetDirection & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + GetDirectionGenericFilter(); + ~GetDirectionGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkGetDirection m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkGetDirectionGenericFilter.txx" +#endif + +#endif // #define clitkGetDirectionGenericFilter_h diff --git a/tools/clitkGetDirectionGenericFilter.txx b/tools/clitkGetDirectionGenericFilter.txx new file mode 100755 index 0000000..165a71d --- /dev/null +++ b/tools/clitkGetDirectionGenericFilter.txx @@ -0,0 +1,103 @@ +/*========================================================================= + 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 clitkGetDirectionGenericFilter_txx +#define clitkGetDirectionGenericFilter_txx + +/* ================================================= + * @file clitkGetDirectionGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + GetDirectionGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + GetDirectionGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typename InputImageType::DirectionType direction=input->GetDirection(); + for (unsigned int i=0;iSetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkGetOrigin.ggo b/tools/clitkGetOrigin.ggo new file mode 100755 index 0000000..221498d --- /dev/null +++ b/tools/clitkGetOrigin.ggo @@ -0,0 +1,12 @@ +#File clitkGetOrigin.ggo +Package "clitkGetOrigin" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "comma" o "Output comma separated values" flag off + + diff --git a/tools/clitkGetOriginGenericFilter.cxx b/tools/clitkGetOriginGenericFilter.cxx new file mode 100755 index 0000000..54547cb --- /dev/null +++ b/tools/clitkGetOriginGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkGetOriginGenericFilter_cxx +#define clitkGetOriginGenericFilter_cxx + +/* ================================================= + * @file clitkGetOriginGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkGetOriginGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + GetOriginGenericFilter::GetOriginGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void GetOriginGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 2 or 3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( GetOriginGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkGetOrigin & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + GetOriginGenericFilter(); + ~GetOriginGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkGetOrigin m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkGetOriginGenericFilter.txx" +#endif + +#endif // #define clitkGetOriginGenericFilter_h diff --git a/tools/clitkGetOriginGenericFilter.txx b/tools/clitkGetOriginGenericFilter.txx new file mode 100755 index 0000000..6b0a1dd --- /dev/null +++ b/tools/clitkGetOriginGenericFilter.txx @@ -0,0 +1,102 @@ +/*========================================================================= + 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 clitkGetOriginGenericFilter_txx +#define clitkGetOriginGenericFilter_txx + +/* ================================================= + * @file clitkGetOriginGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + GetOriginGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + GetOriginGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + //Get Origin + typename InputImageType::PointType origin=input->GetOrigin(); + for(unsigned int i=0; iSetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkGetSize.ggo b/tools/clitkGetSize.ggo new file mode 100755 index 0000000..7243283 --- /dev/null +++ b/tools/clitkGetSize.ggo @@ -0,0 +1,12 @@ +#File clitkGetSize.ggo +Package "clitkGetSize" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "comma" c "Output comma separated values" flag off + + diff --git a/tools/clitkGetSizeGenericFilter.cxx b/tools/clitkGetSizeGenericFilter.cxx new file mode 100755 index 0000000..99d3c57 --- /dev/null +++ b/tools/clitkGetSizeGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkGetSizeGenericFilter_cxx +#define clitkGetSizeGenericFilter_cxx + +/* ================================================= + * @file clitkGetSizeGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkGetSizeGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + GetSizeGenericFilter::GetSizeGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void GetSizeGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 2 or 3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( GetSizeGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkGetSize & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + GetSizeGenericFilter(); + ~GetSizeGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkGetSize m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkGetSizeGenericFilter.txx" +#endif + +#endif // #define clitkGetSizeGenericFilter_h diff --git a/tools/clitkGetSizeGenericFilter.txx b/tools/clitkGetSizeGenericFilter.txx new file mode 100755 index 0000000..51d5744 --- /dev/null +++ b/tools/clitkGetSizeGenericFilter.txx @@ -0,0 +1,103 @@ +/*========================================================================= + 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 clitkGetSizeGenericFilter_txx +#define clitkGetSizeGenericFilter_txx + +/* ================================================= + * @file clitkGetSizeGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + GetSizeGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + // } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + //else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + //} + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + // else { + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + GetSizeGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typename InputImageType::SizeType size=input->GetLargestPossibleRegion().GetSize(); + for(unsigned int i=0; iSetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkGetSpacing.ggo b/tools/clitkGetSpacing.ggo new file mode 100755 index 0000000..f7a37e2 --- /dev/null +++ b/tools/clitkGetSpacing.ggo @@ -0,0 +1,12 @@ +#File clitkGetSpacing.ggo +Package "clitkGetSpacing" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "comma" o "Output comma separated values" flag off + + diff --git a/tools/clitkGetSpacingGenericFilter.cxx b/tools/clitkGetSpacingGenericFilter.cxx new file mode 100755 index 0000000..3536164 --- /dev/null +++ b/tools/clitkGetSpacingGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkGetSpacingGenericFilter_cxx +#define clitkGetSpacingGenericFilter_cxx + +/* ================================================= + * @file clitkGetSpacingGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkGetSpacingGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + GetSpacingGenericFilter::GetSpacingGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void GetSpacingGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 2 or 3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( GetSpacingGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkGetSpacing & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + GetSpacingGenericFilter(); + ~GetSpacingGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkGetSpacing m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkGetSpacingGenericFilter.txx" +#endif + +#endif // #define clitkGetSpacingGenericFilter_h diff --git a/tools/clitkGetSpacingGenericFilter.txx b/tools/clitkGetSpacingGenericFilter.txx new file mode 100755 index 0000000..4d8ab1f --- /dev/null +++ b/tools/clitkGetSpacingGenericFilter.txx @@ -0,0 +1,101 @@ +/*========================================================================= + 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 clitkGetSpacingGenericFilter_txx +#define clitkGetSpacingGenericFilter_txx + +/* ================================================= + * @file clitkGetSpacingGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + GetSpacingGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + // } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + // else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + // } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + // else { + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + GetSpacingGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typename InputImageType::SpacingType spacing=input->GetSpacing(); + for(unsigned int i=0; i + * @date 04 April 2008 15:28:32 + * + * @brief + * + * Take an inverse normalized log of the image intensity + =================================================*/ + +// clitk include +#include "clitkImageLog_ggo.h" +#include "clitkIO.h" +#include "clitkCommon.h" + +// itk include +#include "itkImageFileReader.h" +#include "itkImageFileWriter.h" +#include "itkImageRegionIterator.h" + +int main(int argc, char * argv[]) { + + // init command line + GGO(clitkImageLog, args_info); + CLITK_INIT; + + typedef float PixelType; + const unsigned int Dimension=3; + typedef itk::Image ImageType; + typedef itk::ImageFileReader ImageReaderType; + typedef itk::ImageFileWriter ImageWriterType; + typedef itk::ImageRegionIterator IteratorType; + + //Read input + ImageReaderType::Pointer reader= ImageReaderType::New(); + reader->SetFileName(args_info.input_arg); + reader->Update(); + ImageType::Pointer input = reader->GetOutput(); + + //Create iterators + IteratorType pi (input, input->GetLargestPossibleRegion()); + pi.GoToBegin(); + + PixelType max=std::numeric_limits::max(); + + //Create output + while(!pi.IsAtEnd()) + { + if (pi.Get()< 0) + { + pi.Set(0.); + } + else + { + pi.Set(-log((PixelType)(max-pi.Get()+1)/(PixelType)max)); + } + ++pi; + } + + ImageWriterType::Pointer writer= ImageWriterType::New(); + writer->SetFileName(args_info.output_arg); + writer->SetInput(input); + writer->Update(); + return 0; +} + + + +#endif /* end #define CLITKIMAGELOG_CXX */ diff --git a/tools/clitkImageLog.ggo b/tools/clitkImageLog.ggo new file mode 100755 index 0000000..783549f --- /dev/null +++ b/tools/clitkImageLog.ggo @@ -0,0 +1,9 @@ +# file clitkImageLog.ggo +Package "clitk" +version "Perform a inverse normalized log on the image" + +option "config" - "Config file" string no +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "verbose" v "Verbose" flag off + diff --git a/tools/clitkImageMoment.cxx b/tools/clitkImageMoment.cxx new file mode 100755 index 0000000..5f7076d --- /dev/null +++ b/tools/clitkImageMoment.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkImageMoment.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkImageMoment_ggo.h" +#include "clitkIO.h" +#include "clitkImageMomentGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkImageMoment, args_info); + CLITK_INIT; + + // Filter + clitk::ImageMomentGenericFilter::Pointer genericFilter=clitk::ImageMomentGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkImageMoment.ggo b/tools/clitkImageMoment.ggo new file mode 100755 index 0000000..4bdd355 --- /dev/null +++ b/tools/clitkImageMoment.ggo @@ -0,0 +1,12 @@ +#File clitkImageMoment.ggo +Package "clitkImageMoment" +version "1.0" +purpose "Calculate the image moment: the center of gravity" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "center" c "Compute center of gravity" flag on +option "second" s "Compute second order moments" flag off +option "axes" a "Compute the principal axes" flag off diff --git a/tools/clitkImageMomentGenericFilter.cxx b/tools/clitkImageMomentGenericFilter.cxx new file mode 100755 index 0000000..f0e3ff4 --- /dev/null +++ b/tools/clitkImageMomentGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkImageMomentGenericFilter_cxx +#define clitkImageMomentGenericFilter_cxx + +/* ================================================= + * @file clitkImageMomentGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkImageMomentGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + ImageMomentGenericFilter::ImageMomentGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void ImageMomentGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + // else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 2 or 3 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( ImageMomentGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkImageMoment & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + ImageMomentGenericFilter(); + ~ImageMomentGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkImageMoment m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkImageMomentGenericFilter.txx" +#endif + +#endif // #define clitkImageMomentGenericFilter_h diff --git a/tools/clitkImageMomentGenericFilter.txx b/tools/clitkImageMomentGenericFilter.txx new file mode 100755 index 0000000..8d56304 --- /dev/null +++ b/tools/clitkImageMomentGenericFilter.txx @@ -0,0 +1,116 @@ +/*========================================================================= + 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 clitkImageMomentGenericFilter_txx +#define clitkImageMomentGenericFilter_txx + +/* ================================================= + * @file clitkImageMomentGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + ImageMomentGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + ImageMomentGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typedef itk::ImageMomentsCalculator MomentsCalculatorType; + typename MomentsCalculatorType::Pointer momentsCalculator=MomentsCalculatorType::New(); + momentsCalculator->SetImage(input); + momentsCalculator->Compute(); + if (m_ArgsInfo.center_flag) + { + if (m_Verbose) std::cout<<"The center of gravity is located at (mm) "< center=momentsCalculator->GetCenterOfGravity(); + std::cout<GetCentralMoments()<GetPrincipalAxes()<SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkImageStatistics.ggo b/tools/clitkImageStatistics.ggo new file mode 100755 index 0000000..efc044d --- /dev/null +++ b/tools/clitkImageStatistics.ggo @@ -0,0 +1,15 @@ +#File clitkImageStatistics.ggo +Package "clitkImageStatistics" +version "1.0" +purpose "Compute statistics on an image, or on part of an image specified by a mask and label(s)" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "mask" m "Mask image filename (uchar)" string no +option "label" l "Label(s) in the mask image to consider" int no multiple default="1" +option "histogram" - "Compute histogram, allows median calculation" string no +option "bins" - "Number of histogram bins" int no default="100" +option "lower" - "Lower histogram bound" double no default="-1000" +option "upper" - "Upper histogram bound" double no default="1000" diff --git a/tools/clitkImageStatisticsGenericFilter.cxx b/tools/clitkImageStatisticsGenericFilter.cxx new file mode 100755 index 0000000..3779698 --- /dev/null +++ b/tools/clitkImageStatisticsGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkImageStatisticsGenericFilter_cxx +#define clitkImageStatisticsGenericFilter_cxx + +/* ================================================= + * @file clitkImageStatisticsGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkImageStatisticsGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + ImageStatisticsGenericFilter::ImageStatisticsGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void ImageStatisticsGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + // else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 2 or 3 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( ImageStatisticsGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkImageStatistics & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + ImageStatisticsGenericFilter(); + ~ImageStatisticsGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkImageStatistics m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkImageStatisticsGenericFilter.txx" +#endif + +#endif // #define clitkImageStatisticsGenericFilter_h diff --git a/tools/clitkImageStatisticsGenericFilter.txx b/tools/clitkImageStatisticsGenericFilter.txx new file mode 100755 index 0000000..46abbc2 --- /dev/null +++ b/tools/clitkImageStatisticsGenericFilter.txx @@ -0,0 +1,198 @@ +/*========================================================================= + 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 clitkImageStatisticsGenericFilter_txx +#define clitkImageStatisticsGenericFilter_txx + +/* ================================================= + * @file clitkImageStatisticsGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + ImageStatisticsGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + ImageStatisticsGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image LabelImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typedef itk::LabelStatisticsImageFilter StatisticsImageFilterType; + typename StatisticsImageFilterType::Pointer statisticsFilter=StatisticsImageFilterType::New(); + statisticsFilter->SetInput(input); + + // Label image + typename LabelImageType::Pointer labelImage; + if (m_ArgsInfo.mask_given) + { + typedef itk::ImageFileReader LabelImageReaderType; + typename LabelImageReaderType::Pointer labelImageReader=LabelImageReaderType::New(); + labelImageReader->SetFileName(m_ArgsInfo.mask_arg); + labelImageReader->Update(); + labelImage= labelImageReader->GetOutput(); + } + else + { + labelImage=LabelImageType::New(); + labelImage->SetRegions(input->GetLargestPossibleRegion()); + labelImage->SetOrigin(input->GetOrigin()); + labelImage->SetSpacing(input->GetSpacing()); + labelImage->Allocate(); + labelImage->FillBuffer(m_ArgsInfo.label_arg[0]); + } + statisticsFilter->SetLabelInput(labelImage); + + // For each Label + typename LabelImageType::PixelType label; + unsigned int numberOfLabels; + if (m_ArgsInfo.label_given) + numberOfLabels=m_ArgsInfo.label_given; + else + numberOfLabels=1; + + for (unsigned int k=0; k< numberOfLabels; k++) + { + label=m_ArgsInfo.label_arg[k]; + + std::cout<SetUseHistograms(true); + statisticsFilter->SetHistogramParameters(m_ArgsInfo.bins_arg, m_ArgsInfo.lower_arg, m_ArgsInfo.upper_arg); + } + statisticsFilter->Update(); + + + // Output + if (m_Verbose) std::cout<<"N° of pixels: "; + std::cout<GetCount(label)<GetMean(label)<GetSigma(label)<GetVariance(label)<GetMinimum(label)<GetMaximum(label)<GetSum(label)<GetBoundingBox(label).size(); i++) + std::cout<GetBoundingBox(label)[i]<<" "; + std::cout<GetMedian(label)<GetHistogram(label); + + // Screen + if (m_Verbose) std::cout<<"Histogram: "<GetBinMin(0,i)<<"\t"<GetMeasurement(i,0)<<"\t"<GetBinMax(0,i)<<"\t"<GetFrequency(i)<GetBinMin(0,i)<<"\t"<GetMeasurement(i,0)<<"\t"<GetBinMax(0,i)<<"\t"<GetFrequency(i)<SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkImageToVectorImage.ggo b/tools/clitkImageToVectorImage.ggo new file mode 100755 index 0000000..af0f0f5 --- /dev/null +++ b/tools/clitkImageToVectorImage.ggo @@ -0,0 +1,11 @@ +#File clitkImageToVectorImage.ggo +Package "clitkImageToVectorImage" +version "1.0" +purpose "Compose 3 images to 1 vector image" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "output" o "Output image filename" string yes + + diff --git a/tools/clitkImageToVectorImageGenericFilter.cxx b/tools/clitkImageToVectorImageGenericFilter.cxx new file mode 100755 index 0000000..8270269 --- /dev/null +++ b/tools/clitkImageToVectorImageGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkImageToVectorImageGenericFilter_cxx +#define clitkImageToVectorImageGenericFilter_cxx + +/* ================================================= + * @file clitkImageToVectorImageGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkImageToVectorImageGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + ImageToVectorImageGenericFilter::ImageToVectorImageGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void ImageToVectorImageGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 2 or 3 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( ImageToVectorImageGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkImageToVectorImage & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.inputs[0]; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + ImageToVectorImageGenericFilter(); + ~ImageToVectorImageGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkImageToVectorImage m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkImageToVectorImageGenericFilter.txx" +#endif + +#endif // #define clitkImageToVectorImageGenericFilter_h diff --git a/tools/clitkImageToVectorImageGenericFilter.txx b/tools/clitkImageToVectorImageGenericFilter.txx new file mode 100755 index 0000000..b6d7a85 --- /dev/null +++ b/tools/clitkImageToVectorImageGenericFilter.txx @@ -0,0 +1,108 @@ +/*========================================================================= + 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 clitkImageToVectorImageGenericFilter_txx +#define clitkImageToVectorImageGenericFilter_txx + +/* ================================================= + * @file clitkImageToVectorImageGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + ImageToVectorImageGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + ImageToVectorImageGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image, Dimension> OutputImageType; + + // Filter + typedef itk::Compose3DVectorImageFilter ComposeFilterType; + typename ComposeFilterType::Pointer composeFilter=ComposeFilterType::New(); + + // Read the inputs + typedef itk::ImageFileReader InputReaderType; + for (unsigned int i=0; i<3;i++) + { + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_ArgsInfo.inputs[i]); + reader->Update(); + composeFilter->SetInput(i, reader->GetOutput()); + } + composeFilter->Update(); + typename OutputImageType::Pointer output = composeFilter->GetOutput(); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + + } + + +}//end clitk + +#endif //#define clitkImageToVectorImageGenericFilter_txx diff --git a/filters/clitkMedianImageFilter.ggo b/tools/clitkMedianImageFilter.ggo similarity index 100% rename from filters/clitkMedianImageFilter.ggo rename to tools/clitkMedianImageFilter.ggo diff --git a/filters/clitkMedianImageGenericFilter.cxx b/tools/clitkMedianImageGenericFilter.cxx old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkMedianImageGenericFilter.cxx rename to tools/clitkMedianImageGenericFilter.cxx diff --git a/filters/clitkMedianImageGenericFilter.h b/tools/clitkMedianImageGenericFilter.h old mode 100644 new mode 100755 similarity index 98% rename from filters/clitkMedianImageGenericFilter.h rename to tools/clitkMedianImageGenericFilter.h index 8dee470..e4d68b6 --- a/filters/clitkMedianImageGenericFilter.h +++ b/tools/clitkMedianImageGenericFilter.h @@ -3,7 +3,7 @@ Program: clitk Module: $RCSfile: clitkMedianImageGenericFilter.h,v $ Language: C++ - Date: $Date: 2010/04/09 09:50:04 $ + Date: $Date: 2010/07/23 14:56:21 $ Version: $Revision: 1.1 $ Author : Bharath Navalpakkam Copyright (C) 2010 diff --git a/filters/clitkMedianImageGenericFilter.txx b/tools/clitkMedianImageGenericFilter.txx old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkMedianImageGenericFilter.txx rename to tools/clitkMedianImageGenericFilter.txx diff --git a/tools/clitkMergeSequence.cxx b/tools/clitkMergeSequence.cxx new file mode 100755 index 0000000..e2c0eb0 --- /dev/null +++ b/tools/clitkMergeSequence.cxx @@ -0,0 +1,60 @@ +/*========================================================================= + 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 CLITKMERGESEQUENCE_CXX +#define CLITKMERGESEQUENCE_CXX + +/** + * @file clitkMergeSequence.cxx + * @author Jef Vandemeulebroucke + * @date December 2 10:14:53 2008 + * + * @brief Read in one VF (ex mhd, vf) invert it using a splat with linear kernels to the target. + * + */ + +// clitk include +#include "clitkMergeSequence_ggo.h" +#include "clitkIO.h" +#include "clitkImageCommon.h" +#include "clitkMergeSequenceGenericFilter.h" + +int main( int argc, char *argv[] ) +{ + + // Init command line + GGO(clitkMergeSequence, args_info); + CLITK_INIT; + + //Creation of the generic filter + clitk::MergeSequenceGenericFilter::Pointer MergeSequenceGenericFilter= clitk::MergeSequenceGenericFilter::New(); + + //Pass the parameters + std::vector names; + for(unsigned int i=0; iSetInputs(names); + MergeSequenceGenericFilter->SetSpacing(args_info.spacing_arg); + MergeSequenceGenericFilter->SetOutput(args_info.output_arg); + MergeSequenceGenericFilter->SetVerbose(args_info.verbose_flag); + + //update + MergeSequenceGenericFilter->Update(); + return EXIT_SUCCESS; +} +#endif + + diff --git a/tools/clitkMergeSequence.ggo b/tools/clitkMergeSequence.ggo new file mode 100755 index 0000000..5354c1f --- /dev/null +++ b/tools/clitkMergeSequence.ggo @@ -0,0 +1,12 @@ +#File clitkMergeSequence.ggo +#Author: Jef Vandemeulebroucke +#Date : Tue 15 June 16.35 + +Package "clitk" +Version "Read a series a nD images (unnamed inputs) and merge them to a (n+1)D image" + +option "config" - "Config file" string no +option "spacing" s "Spacing for the new dimension" double no default="1" +option "output" o "Output VF filename" string yes +option "verbose" v "Verbose" flag off + diff --git a/tools/clitkMergeSequenceGenericFilter.cxx b/tools/clitkMergeSequenceGenericFilter.cxx new file mode 100755 index 0000000..b29ca82 --- /dev/null +++ b/tools/clitkMergeSequenceGenericFilter.cxx @@ -0,0 +1,50 @@ +/*========================================================================= + 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 CLITKMERGESEQUENCEGENERICFILTER_CXX +#define CLITKMERGESEQUENCEGENERICFILTER_CXX +#include "clitkMergeSequenceGenericFilter.h" + + +namespace clitk { + + clitk::MergeSequenceGenericFilter::MergeSequenceGenericFilter() + { + m_Verbose=false; + m_Spacing=1; + } + + + void clitk::MergeSequenceGenericFilter::Update() + { + //Get the image Dimension and PixelType + int Dimension, Components; + std::string PixelType; + + clitk::ReadImageDimensionAndPixelType(m_InputNames[0], Dimension, PixelType, Components); + + if(Dimension==2) UpdateWithDim<2>(PixelType, Components); + else if(Dimension==3) UpdateWithDim<3>(PixelType, Components); + else + { + std::cout<<"Error, Only for 2 and 3 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + //Set Methods (inline) + void SetInputs(const std::vector m){m_InputNames=m;} + void SetSpacing(const double m){m_Spacing=m;} + void SetOutput(const std::string m){m_OutputName=m;} + void SetVerbose(const bool m){m_Verbose=m;} + + //Update + void Update( ); + + + protected: + + MergeSequenceGenericFilter(); + ~MergeSequenceGenericFilter() {}; + + //Templated members + template void UpdateWithDim(std::string PixelType, unsigned int Components); + template void UpdateWithDimAndPixelType(); + + std::vector m_InputNames; + double m_Spacing; + std::string m_OutputName; + bool m_Verbose; + +}; + + +} // end namespace clitk +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkMergeSequenceGenericFilter.txx" +#endif + +#endif // #define __clitkMergeSequenceGenericFilter_h diff --git a/tools/clitkMergeSequenceGenericFilter.txx b/tools/clitkMergeSequenceGenericFilter.txx new file mode 100755 index 0000000..563b180 --- /dev/null +++ b/tools/clitkMergeSequenceGenericFilter.txx @@ -0,0 +1,101 @@ +/*========================================================================= + 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 __clitkMergeSequenceGenericFilter_txx +#define __clitkMergeSequenceGenericFilter_txx +#include "clitkMergeSequenceGenericFilter.h" + + +namespace clitk +{ + template + void MergeSequenceGenericFilter::UpdateWithDim(std::string PixelType, unsigned int Components) + { + + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + else if (Components==3) + { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 3D float (DVF)" << std::endl; + UpdateWithDimAndPixelType >(); + } + + else std::cerr<<"Number of components is "< + void MergeSequenceGenericFilter::UpdateWithDimAndPixelType() + { + + //Define the input and output image type + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + //Read the input image series + typedef itk::ImageSeriesReader ImageReaderType; + typename ImageReaderType::Pointer reader= ImageReaderType::New(); + reader->SetFileNames(m_InputNames); + reader->Update(); + typename OutputImageType::Pointer image =reader->GetOutput(); + + //Set the spacing + typename OutputImageType::SpacingType spacing=image->GetSpacing(); + spacing[Dimension]=m_Spacing; + image->SetSpacing(spacing); + + //Write the output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_OutputName); + writer->SetInput(reader->GetOutput()); + writer->Update(); + + } + + +} + +#endif + diff --git a/tools/clitkMirrorPadImage.cxx b/tools/clitkMirrorPadImage.cxx new file mode 100755 index 0000000..670c5e0 --- /dev/null +++ b/tools/clitkMirrorPadImage.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkMirrorPadImage.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkMirrorPadImage_ggo.h" +#include "clitkIO.h" +#include "clitkMirrorPadImageGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkMirrorPadImage, args_info); + CLITK_INIT; + + // Filter + clitk::MirrorPadImageGenericFilter::Pointer genericFilter=clitk::MirrorPadImageGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkMirrorPadImage.ggo b/tools/clitkMirrorPadImage.ggo new file mode 100755 index 0000000..c02bf21 --- /dev/null +++ b/tools/clitkMirrorPadImage.ggo @@ -0,0 +1,14 @@ +#File clitkMirrorPadImage.ggo +Package "clitkMirrorPadImage" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "mirror" m "Mirror the entire image along given axis" int no +option "pad" p "Mirror pad with given size" int multiple no +option "lower" l "Pad on lower end (else upper)" flag off +option "origin" - "Set new origin to 0" flag off diff --git a/tools/clitkMirrorPadImageGenericFilter.cxx b/tools/clitkMirrorPadImageGenericFilter.cxx new file mode 100755 index 0000000..c46e1fd --- /dev/null +++ b/tools/clitkMirrorPadImageGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkMirrorPadImageGenericFilter_cxx +#define clitkMirrorPadImageGenericFilter_cxx + +/* ================================================= + * @file clitkMirrorPadImageGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkMirrorPadImageGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + MirrorPadImageGenericFilter::MirrorPadImageGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void MirrorPadImageGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + // else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 2 or 3 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( MirrorPadImageGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkMirrorPadImage & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + MirrorPadImageGenericFilter(); + ~MirrorPadImageGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkMirrorPadImage m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkMirrorPadImageGenericFilter.txx" +#endif + +#endif // #define clitkMirrorPadImageGenericFilter_h diff --git a/tools/clitkMirrorPadImageGenericFilter.txx b/tools/clitkMirrorPadImageGenericFilter.txx new file mode 100755 index 0000000..b05fea8 --- /dev/null +++ b/tools/clitkMirrorPadImageGenericFilter.txx @@ -0,0 +1,144 @@ +/*========================================================================= + 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 clitkMirrorPadImageGenericFilter_txx +#define clitkMirrorPadImageGenericFilter_txx + +/* ================================================= + * @file clitkMirrorPadImageGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + MirrorPadImageGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + MirrorPadImageGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typedef itk::MirrorPadImageFilter MirrorPadImageFilterType; + typename MirrorPadImageFilterType::Pointer mirrorPadImageFilter=MirrorPadImageFilterType::New(); + mirrorPadImageFilter->SetInput(input); + + //Get the padding size + typename InputImageType::SizeType padSize; + + // Mirror the entire image + if (m_ArgsInfo.mirror_given) + { + typename InputImageType::SizeType inputSize=input->GetLargestPossibleRegion().GetSize(); + padSize.Fill(0); + padSize[m_ArgsInfo.mirror_arg]=inputSize[m_ArgsInfo.mirror_arg]; + if (m_Verbose) std::cout<<"Mirroring the entire image along axis "<< m_ArgsInfo.mirror_arg<<"..."<SetPadLowerBound(padSize); + + else + mirrorPadImageFilter->SetPadUpperBound(padSize); + + mirrorPadImageFilter->Update(); + typename OutputImageType::Pointer output = mirrorPadImageFilter->GetOutput(); + + // Origin? + typename OutputImageType::PointType origin; + origin.Fill(itk::NumericTraits::Zero); + if (m_ArgsInfo.origin_flag) + { + output->Update(); + output->SetOrigin(origin); + if (m_Verbose) std::cout<<"Setting origin to "<< output->GetOrigin()<<"..."< WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + } + + +}//end clitk + +#endif //#define clitkMirrorPadImageGenericFilter_txx diff --git a/tools/clitkPermuteAxes.cxx b/tools/clitkPermuteAxes.cxx new file mode 100755 index 0000000..f9c62e8 --- /dev/null +++ b/tools/clitkPermuteAxes.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkPermuteAxes.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkPermuteAxes_ggo.h" +#include "clitkIO.h" +#include "clitkPermuteAxesGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkPermuteAxes, args_info); + CLITK_INIT; + + // Filter + clitk::PermuteAxesGenericFilter::Pointer genericFilter=clitk::PermuteAxesGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkPermuteAxes.ggo b/tools/clitkPermuteAxes.ggo new file mode 100755 index 0000000..32c2f6b --- /dev/null +++ b/tools/clitkPermuteAxes.ggo @@ -0,0 +1,13 @@ +#File clitkPermuteAxes.ggo +Package "clitkPermuteAxes" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "order" - "The new order of the axes (n comma separated values [o,N])" int multiple yes + + diff --git a/tools/clitkPermuteAxesGenericFilter.cxx b/tools/clitkPermuteAxesGenericFilter.cxx new file mode 100755 index 0000000..2a3ccd5 --- /dev/null +++ b/tools/clitkPermuteAxesGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkPermuteAxesGenericFilter_cxx +#define clitkPermuteAxesGenericFilter_cxx + +/* ================================================= + * @file clitkPermuteAxesGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkPermuteAxesGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + PermuteAxesGenericFilter::PermuteAxesGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void PermuteAxesGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 2, 3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( PermuteAxesGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkPermuteAxes & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + PermuteAxesGenericFilter(); + ~PermuteAxesGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkPermuteAxes m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkPermuteAxesGenericFilter.txx" +#endif + +#endif // #define clitkPermuteAxesGenericFilter_h diff --git a/tools/clitkPermuteAxesGenericFilter.txx b/tools/clitkPermuteAxesGenericFilter.txx new file mode 100755 index 0000000..2505819 --- /dev/null +++ b/tools/clitkPermuteAxesGenericFilter.txx @@ -0,0 +1,119 @@ +/*========================================================================= + 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 clitkPermuteAxesGenericFilter_txx +#define clitkPermuteAxesGenericFilter_txx + +/* ================================================= + * @file clitkPermuteAxesGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + PermuteAxesGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + PermuteAxesGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typedef itk::PermuteAxesImageFilter PermuteFilterType; + typename PermuteFilterType::Pointer permuteFilter=PermuteFilterType::New(); + permuteFilter->SetInput(input); + typename PermuteFilterType::PermuteOrderArrayType order; + + if(m_ArgsInfo.order_given != Dimension) + { + std::cerr<<"Error: Number of order parameters is different from image dimension!"<SetOrder(order); + permuteFilter->Update(); + typename OutputImageType::Pointer output =permuteFilter->GetOutput(); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + + } + + +}//end clitk + +#endif //#define clitkPermuteAxesGenericFilter_txx diff --git a/tools/clitkSetDirection.cxx b/tools/clitkSetDirection.cxx new file mode 100755 index 0000000..44a5322 --- /dev/null +++ b/tools/clitkSetDirection.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkSetDirection.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkSetDirection_ggo.h" +#include "clitkIO.h" +#include "clitkSetDirectionGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkSetDirection, args_info); + CLITK_INIT; + + // Filter + clitk::SetDirectionGenericFilter::Pointer genericFilter=clitk::SetDirectionGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkSetDirection.ggo b/tools/clitkSetDirection.ggo new file mode 100755 index 0000000..45332ba --- /dev/null +++ b/tools/clitkSetDirection.ggo @@ -0,0 +1,12 @@ +#File clitkSetDirection.ggo +Package "clitkSetDirection" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "direction" d "Direction cosine matrix (defaults to identity)" double multiple no + diff --git a/tools/clitkSetDirectionGenericFilter.cxx b/tools/clitkSetDirectionGenericFilter.cxx new file mode 100755 index 0000000..daa2406 --- /dev/null +++ b/tools/clitkSetDirectionGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkSetDirectionGenericFilter_cxx +#define clitkSetDirectionGenericFilter_cxx + +/* ================================================= + * @file clitkSetDirectionGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkSetDirectionGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + SetDirectionGenericFilter::SetDirectionGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void SetDirectionGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + else if (Dimension==4)UpdateWithDim<4>(PixelType); + else + { + std::cout<<"Error, Only for 2,3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( SetDirectionGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkSetDirection & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + SetDirectionGenericFilter(); + ~SetDirectionGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkSetDirection m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkSetDirectionGenericFilter.txx" +#endif + +#endif // #define clitkSetDirectionGenericFilter_h diff --git a/tools/clitkSetDirectionGenericFilter.txx b/tools/clitkSetDirectionGenericFilter.txx new file mode 100755 index 0000000..2c71340 --- /dev/null +++ b/tools/clitkSetDirectionGenericFilter.txx @@ -0,0 +1,108 @@ +/*========================================================================= + 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 clitkSetDirectionGenericFilter_txx +#define clitkSetDirectionGenericFilter_txx + +/* ================================================= + * @file clitkSetDirectionGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + SetDirectionGenericFilter::UpdateWithDim(std::string PixelType) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //------------------------------------------------------------------- + template + void + SetDirectionGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typename InputImageType::DirectionType direction; + direction.SetIdentity(); + if(m_ArgsInfo.direction_given==Dimension*Dimension) + for (unsigned int i=0;iSetDirection(direction); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(input); + writer->Update(); + + } + + +}//end clitk + +#endif //#define clitkSetDirectionGenericFilter_txx diff --git a/tools/clitkSetOrigin.cxx b/tools/clitkSetOrigin.cxx new file mode 100755 index 0000000..f814c7b --- /dev/null +++ b/tools/clitkSetOrigin.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkSetOrigin.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkSetOrigin_ggo.h" +#include "clitkIO.h" +#include "clitkSetOriginGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkSetOrigin, args_info); + CLITK_INIT; + + // Filter + clitk::SetOriginGenericFilter::Pointer genericFilter=clitk::SetOriginGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkSetOrigin.ggo b/tools/clitkSetOrigin.ggo new file mode 100755 index 0000000..8f550d3 --- /dev/null +++ b/tools/clitkSetOrigin.ggo @@ -0,0 +1,12 @@ +#File clitkSetOrigin.ggo +Package "clitkSetOrigin" +version "1.0" +purpose "Set the origin field of a generic image" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "like" l "Like image filename" string no +option "origin" - "Origin" double multiple no default="0" diff --git a/tools/clitkSetOriginGenericFilter.cxx b/tools/clitkSetOriginGenericFilter.cxx new file mode 100755 index 0000000..57504e4 --- /dev/null +++ b/tools/clitkSetOriginGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkSetOriginGenericFilter_cxx +#define clitkSetOriginGenericFilter_cxx + +/* ================================================= + * @file clitkSetOriginGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkSetOriginGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + SetOriginGenericFilter::SetOriginGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void SetOriginGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension, Components; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType, Components); + else if(Dimension==3) UpdateWithDim<3>(PixelType, Components); + else if (Dimension==4)UpdateWithDim<4>(PixelType, Components); + else + { + std::cout<<"Error, Only for 2, 3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( SetOriginGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkSetOrigin & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + SetOriginGenericFilter(); + ~SetOriginGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType, int Components); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkSetOrigin m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkSetOriginGenericFilter.txx" +#endif + +#endif // #define clitkSetOriginGenericFilter_h diff --git a/tools/clitkSetOriginGenericFilter.txx b/tools/clitkSetOriginGenericFilter.txx new file mode 100755 index 0000000..81c1c89 --- /dev/null +++ b/tools/clitkSetOriginGenericFilter.txx @@ -0,0 +1,136 @@ +/*========================================================================= + 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 clitkSetOriginGenericFilter_txx +#define clitkSetOriginGenericFilter_txx + +/* ================================================= + * @file clitkSetOriginGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + SetOriginGenericFilter::UpdateWithDim(std::string PixelType, int Components) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + else if (Components==3) + { + if (m_Verbose) std::cout << "Launching transform in "<< Dimension <<"D and 3D float (DVF)" << std::endl; + UpdateWithDimAndPixelType >(); + } + + else std::cerr<<"Number of components is "< + void + SetOriginGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Origin + typename InputImageType::PointType origin; + origin.Fill(0.0); + + // Like? + if (m_ArgsInfo.like_given) + { + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer likeReader = InputReaderType::New(); + likeReader->SetFileName( m_ArgsInfo.like_arg); + likeReader->Update(); + typename InputImageType::Pointer like= likeReader->GetOutput(); + origin=like->GetOrigin(); + } + else + { + if (m_ArgsInfo.origin_given==Dimension) + for(unsigned int i=0; iSetOrigin(origin); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(input); + writer->Update(); + + } + + +}//end clitk + +#endif //#define clitkSetOriginGenericFilter_txx diff --git a/tools/clitkSetSpacing.cxx b/tools/clitkSetSpacing.cxx new file mode 100755 index 0000000..cf99dba --- /dev/null +++ b/tools/clitkSetSpacing.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkSetSpacing.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkSetSpacing_ggo.h" +#include "clitkIO.h" +#include "clitkSetSpacingGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkSetSpacing, args_info); + CLITK_INIT; + + // Filter + clitk::SetSpacingGenericFilter::Pointer genericFilter=clitk::SetSpacingGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkSetSpacing.ggo b/tools/clitkSetSpacing.ggo new file mode 100755 index 0000000..1320c3e --- /dev/null +++ b/tools/clitkSetSpacing.ggo @@ -0,0 +1,14 @@ +#File clitkSetSpacing.ggo +Package "clitkSetSpacing" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "like" l "Like image filename" string no +option "spacing" s "Spacing" double no multiple default="1" + + diff --git a/tools/clitkSetSpacingGenericFilter.cxx b/tools/clitkSetSpacingGenericFilter.cxx new file mode 100755 index 0000000..27c9a11 --- /dev/null +++ b/tools/clitkSetSpacingGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkSetSpacingGenericFilter_cxx +#define clitkSetSpacingGenericFilter_cxx + +/* ================================================= + * @file clitkSetSpacingGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkSetSpacingGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + SetSpacingGenericFilter::SetSpacingGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void SetSpacingGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension, Components; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType, Components); + else if(Dimension==3) UpdateWithDim<3>(PixelType, Components); + else if (Dimension==4)UpdateWithDim<4>(PixelType, Components); + else + { + std::cout<<"Error, Only for 2, 3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( SetSpacingGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkSetSpacing & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + SetSpacingGenericFilter(); + ~SetSpacingGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType, unsigned int Components); + template void UpdateWithDimAndPixelType(); + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkSetSpacing m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkSetSpacingGenericFilter.txx" +#endif + +#endif // #define clitkSetSpacingGenericFilter_h diff --git a/tools/clitkSetSpacingGenericFilter.txx b/tools/clitkSetSpacingGenericFilter.txx new file mode 100755 index 0000000..d6edc3f --- /dev/null +++ b/tools/clitkSetSpacingGenericFilter.txx @@ -0,0 +1,136 @@ +/*========================================================================= + 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 clitkSetSpacingGenericFilter_txx +#define clitkSetSpacingGenericFilter_txx + +/* ================================================= + * @file clitkSetSpacingGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + SetSpacingGenericFilter::UpdateWithDim(std::string PixelType , unsigned int Components) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + else if (Components==3) + { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 3D float (DVF)" << std::endl; + UpdateWithDimAndPixelType >(); + } + + else std::cerr<<"Number of components is "< + void + SetSpacingGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typename InputImageType::SpacingType spacing; + spacing.Fill(1.0); + + // Like? + if (m_ArgsInfo.like_given) + { + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer likeReader = InputReaderType::New(); + likeReader->SetFileName( m_ArgsInfo.like_arg); + likeReader->Update(); + typename InputImageType::Pointer like= likeReader->GetOutput(); + spacing=like->GetSpacing(); + } + else + { + if (m_ArgsInfo.spacing_given==Dimension) + for(unsigned int i=0; iSetSpacing(spacing); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(input); + writer->Update(); + + } + + +}//end clitk + +#endif //#define clitkSetSpacingGenericFilter_txx diff --git a/filters/clitkSplitImageGenericFilter.cxx b/tools/clitkSplitImageGenericFilter.cxx old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkSplitImageGenericFilter.cxx rename to tools/clitkSplitImageGenericFilter.cxx diff --git a/filters/clitkSplitImageGenericFilter.h b/tools/clitkSplitImageGenericFilter.h old mode 100644 new mode 100755 similarity index 99% rename from filters/clitkSplitImageGenericFilter.h rename to tools/clitkSplitImageGenericFilter.h index a325301..9c34e9d --- a/filters/clitkSplitImageGenericFilter.h +++ b/tools/clitkSplitImageGenericFilter.h @@ -25,6 +25,7 @@ -------------------------------------------------------------------*/ // clitk include +#include "clitkIO.h" #include "clitkCommon.h" #include "clitkImageCommon.h" #include "clitkImageToImageGenericFilter.h" diff --git a/filters/clitkSplitImageGenericFilter.txx b/tools/clitkSplitImageGenericFilter.txx old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkSplitImageGenericFilter.txx rename to tools/clitkSplitImageGenericFilter.txx diff --git a/filters/clitkUnsharpMask.ggo b/tools/clitkUnsharpMask.ggo similarity index 100% rename from filters/clitkUnsharpMask.ggo rename to tools/clitkUnsharpMask.ggo diff --git a/filters/clitkUnsharpMaskGenericFilter.h b/tools/clitkUnsharpMaskGenericFilter.h old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkUnsharpMaskGenericFilter.h rename to tools/clitkUnsharpMaskGenericFilter.h diff --git a/filters/clitkUnsharpMaskGenericFilter.txx b/tools/clitkUnsharpMaskGenericFilter.txx old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkUnsharpMaskGenericFilter.txx rename to tools/clitkUnsharpMaskGenericFilter.txx diff --git a/tools/clitkVFConvert.cxx b/tools/clitkVFConvert.cxx new file mode 100755 index 0000000..a607e03 --- /dev/null +++ b/tools/clitkVFConvert.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkVFConvert.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkVFConvert_ggo.h" +#include "clitkIO.h" +#include "clitkVFConvertGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkVFConvert, args_info); + CLITK_INIT; + + // Filter + clitk::VFConvertGenericFilter::Pointer genericFilter=clitk::VFConvertGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkVFConvert.ggo b/tools/clitkVFConvert.ggo new file mode 100755 index 0000000..32eec43 --- /dev/null +++ b/tools/clitkVFConvert.ggo @@ -0,0 +1,12 @@ +#File clitkVFConvert.ggo +Package "clitkVFConvert" +version "1.0" +purpose "Convert file format" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes + + diff --git a/tools/clitkVFConvertGenericFilter.cxx b/tools/clitkVFConvertGenericFilter.cxx new file mode 100755 index 0000000..2407805 --- /dev/null +++ b/tools/clitkVFConvertGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkVFConvertGenericFilter_cxx +#define clitkVFConvertGenericFilter_cxx + +/* ================================================= + * @file clitkVFConvertGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkVFConvertGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + VFConvertGenericFilter::VFConvertGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void VFConvertGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension, Components; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType,Components); + else if(Dimension==3) UpdateWithDim<3>(PixelType,Components); + else if (Dimension==4)UpdateWithDim<4>(PixelType,Components); + else + { + std::cout<<"Error, Only for 2, 3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( VFConvertGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkVFConvert & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + VFConvertGenericFilter(); + ~VFConvertGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType, unsigned int Components); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkVFConvert m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkVFConvertGenericFilter.txx" +#endif + +#endif // #define clitkVFConvertGenericFilter_h diff --git a/tools/clitkVFConvertGenericFilter.txx b/tools/clitkVFConvertGenericFilter.txx new file mode 100755 index 0000000..eb6ac60 --- /dev/null +++ b/tools/clitkVFConvertGenericFilter.txx @@ -0,0 +1,111 @@ +/*========================================================================= + 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 clitkVFConvertGenericFilter_txx +#define clitkVFConvertGenericFilter_txx + +/* ================================================= + * @file clitkVFConvertGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + VFConvertGenericFilter::UpdateWithDim(std::string PixelType, unsigned int Components) + { + if (m_Verbose) std::cout << "Image was detected to be "< >(); + } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D with "<< Components <<" components of float..." << std::endl; + UpdateWithDimAndPixelType >(); + } + } + else if (Components==3) + { + if (PixelType == "double"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D with "<< Components <<" components of double..." << std::endl; + UpdateWithDimAndPixelType >(); + } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D with "<< Components <<" components of float..." << std::endl; + UpdateWithDimAndPixelType >(); + } + } + else if (Components==4) + { + if (PixelType == "double"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D with "<< Components <<" components of double..." << std::endl; + UpdateWithDimAndPixelType >(); + } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D with "<< Components <<" components of float..." << std::endl; + UpdateWithDimAndPixelType >(); + } + } + else std::cerr<<"Only 2,3 and 4 components!"< + void + VFConvertGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(input); + writer->Update(); + + } + + +}//end clitk + +#endif //#define clitkVFConvertGenericFilter_txx diff --git a/tools/clitkVFResample.cxx b/tools/clitkVFResample.cxx index 91e4094..d6688e2 100644 --- a/tools/clitkVFResample.cxx +++ b/tools/clitkVFResample.cxx @@ -19,7 +19,7 @@ #define CLITKVFRESAMPLE_CXX /** ------------------------------------------------= - * @file clitkImageResample.cxx + * @file clitkVFResample.cxx * @author David Sarrut * @date 23 Feb 2008 08:37:53 ------------------------------------------------=*/ diff --git a/filters/clitkVFResampleGenericFilter.cxx b/tools/clitkVFResampleGenericFilter.cxx old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkVFResampleGenericFilter.cxx rename to tools/clitkVFResampleGenericFilter.cxx diff --git a/filters/clitkVFResampleGenericFilter.h b/tools/clitkVFResampleGenericFilter.h old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkVFResampleGenericFilter.h rename to tools/clitkVFResampleGenericFilter.h diff --git a/filters/clitkVFResampleGenericFilter.txx b/tools/clitkVFResampleGenericFilter.txx old mode 100644 new mode 100755 similarity index 100% rename from filters/clitkVFResampleGenericFilter.txx rename to tools/clitkVFResampleGenericFilter.txx diff --git a/tools/clitkValuesToBSplineCoefficients.cxx b/tools/clitkValuesToBSplineCoefficients.cxx new file mode 100644 index 0000000..e071445 --- /dev/null +++ b/tools/clitkValuesToBSplineCoefficients.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkValuesToBSplineCoefficients.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkValuesToBSplineCoefficients_ggo.h" +#include "clitkIO.h" +#include "clitkValuesToBSplineCoefficientsGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkValuesToBSplineCoefficients, args_info); + CLITK_INIT; + + // Filter + clitk::ValuesToBSplineCoefficientsGenericFilter::Pointer genericFilter=clitk::ValuesToBSplineCoefficientsGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkValuesToBSplineCoefficients.ggo b/tools/clitkValuesToBSplineCoefficients.ggo new file mode 100644 index 0000000..699f60a --- /dev/null +++ b/tools/clitkValuesToBSplineCoefficients.ggo @@ -0,0 +1,12 @@ +#File clitkValuesToBSplineCoefficients.ggo +Package "clitkValuesToBSplineCoefficients" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes + +option "order" - "Order of the BSpline coefficients" int no default="3" diff --git a/tools/clitkValuesToBSplineCoefficientsGenericFilter.cxx b/tools/clitkValuesToBSplineCoefficientsGenericFilter.cxx new file mode 100644 index 0000000..eb0256b --- /dev/null +++ b/tools/clitkValuesToBSplineCoefficientsGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkValuesToBSplineCoefficientsGenericFilter_cxx +#define clitkValuesToBSplineCoefficientsGenericFilter_cxx + +/* ================================================= + * @file clitkValuesToBSplineCoefficientsGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkValuesToBSplineCoefficientsGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + ValuesToBSplineCoefficientsGenericFilter::ValuesToBSplineCoefficientsGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void ValuesToBSplineCoefficientsGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension, Components; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType, Components); + else if(Dimension==3) UpdateWithDim<3>(PixelType, Components); + else if (Dimension==4)UpdateWithDim<4>(PixelType, Components); + else + { + std::cout<<"Error, Only for 2, 3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( ValuesToBSplineCoefficientsGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkValuesToBSplineCoefficients & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + ValuesToBSplineCoefficientsGenericFilter(); + ~ValuesToBSplineCoefficientsGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType, unsigned int Components); + template void UpdateWithDimAndPixelType(); + template void UpdateWithDimAndVectorType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkValuesToBSplineCoefficients m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkValuesToBSplineCoefficientsGenericFilter.txx" +#endif + +#endif // #define clitkValuesToBSplineCoefficientsGenericFilter_h diff --git a/tools/clitkValuesToBSplineCoefficientsGenericFilter.txx b/tools/clitkValuesToBSplineCoefficientsGenericFilter.txx new file mode 100644 index 0000000..782aad8 --- /dev/null +++ b/tools/clitkValuesToBSplineCoefficientsGenericFilter.txx @@ -0,0 +1,155 @@ +/*========================================================================= + 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 clitkValuesToBSplineCoefficientsGenericFilter_txx +#define clitkValuesToBSplineCoefficientsGenericFilter_txx + +/* ================================================= + * @file clitkValuesToBSplineCoefficientsGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + ValuesToBSplineCoefficientsGenericFilter::UpdateWithDim(std::string PixelType, unsigned int Components) + { + if (m_Verbose) std::cout << "Image was detected to be "<(); + } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + else if (PixelType == "unsigned_char"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); + } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); + } + } + + else if (Components==3) + { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 3D float (DVF)" << std::endl; + UpdateWithDimAndVectorType >(); + } + + else std::cerr<<"Number of components is "< + void + ValuesToBSplineCoefficientsGenericFilter::UpdateWithDimAndPixelType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typedef itk::BSplineDecompositionImageFilter FilterType; + typename FilterType::Pointer filter=FilterType::New(); + filter->SetInput(input); + filter->SetSplineOrder(m_ArgsInfo.order_arg); + filter->Update(); + typename OutputImageType::Pointer output=filter->GetOutput(); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + + } + + + //------------------------------------------------------------------- + // Update with the number of dimensions and the Vectortype + //------------------------------------------------------------------- + template + void + ValuesToBSplineCoefficientsGenericFilter::UpdateWithDimAndVectorType() + { + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typedef clitk::VectorBSplineDecompositionImageFilter FilterType; + typename FilterType::Pointer filter=FilterType::New(); + filter->SetInput(input); + filter->SetSplineOrder(m_ArgsInfo.order_arg); + filter->Update(); + typename OutputImageType::Pointer output=filter->GetOutput(); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + + } + + +}//end clitk + +#endif //#define clitkValuesToBSplineCoefficientsGenericFilter_txx diff --git a/tools/clitkVectorImageToImage.cxx b/tools/clitkVectorImageToImage.cxx new file mode 100755 index 0000000..e3b6210 --- /dev/null +++ b/tools/clitkVectorImageToImage.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + 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 +======================================================================-====*/ + +/* ================================================= + * @file clitkVectorImageToImage.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk +#include "clitkVectorImageToImage_ggo.h" +#include "clitkIO.h" +#include "clitkVectorImageToImageGenericFilter.h" + + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkVectorImageToImage, args_info); + CLITK_INIT; + + // Filter + clitk::VectorImageToImageGenericFilter::Pointer genericFilter=clitk::VectorImageToImageGenericFilter::New(); + + genericFilter->SetArgsInfo(args_info); + genericFilter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkVectorImageToImage.ggo b/tools/clitkVectorImageToImage.ggo new file mode 100755 index 0000000..8bca8ed --- /dev/null +++ b/tools/clitkVectorImageToImage.ggo @@ -0,0 +1,12 @@ +#File clitkVectorImageToImage.ggo +Package "clitkVectorImageToImage" +version "1.0" +purpose "Extract a component image from a vector image" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "componentIndex" c "Component index to extract" int no default="0" + diff --git a/tools/clitkVectorImageToImageGenericFilter.cxx b/tools/clitkVectorImageToImageGenericFilter.cxx new file mode 100755 index 0000000..b0cadb7 --- /dev/null +++ b/tools/clitkVectorImageToImageGenericFilter.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + 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 clitkVectorImageToImageGenericFilter_cxx +#define clitkVectorImageToImageGenericFilter_cxx + +/* ================================================= + * @file clitkVectorImageToImageGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkVectorImageToImageGenericFilter.h" + + +namespace clitk +{ + + + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + VectorImageToImageGenericFilter::VectorImageToImageGenericFilter() + { + m_Verbose=false; + m_InputFileName=""; + } + + + //----------------------------------------------------------- + // Update + //----------------------------------------------------------- + void VectorImageToImageGenericFilter::Update() + { + // Read the Dimension and PixelType + int Dimension, Components; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType, Components); + else if(Dimension==3) UpdateWithDim<3>(PixelType, Components); + else if (Dimension==4)UpdateWithDim<4>(PixelType, Components); + else + { + std::cout<<"Error, Only for 2, 3 or 4 Dimensions!!!"< Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( VectorImageToImageGenericFilter, LightObject ); + + + //---------------------------------------- + // Typedefs + //---------------------------------------- + + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const args_info_clitkVectorImageToImage & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + m_InputFileName=m_ArgsInfo.input_arg; + } + + + //---------------------------------------- + // Update + //---------------------------------------- + void Update(); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + VectorImageToImageGenericFilter(); + ~VectorImageToImageGenericFilter() {}; + + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithDim(std::string PixelType, unsigned int Components); + template void UpdateWithDimAndPixelType(); + + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkVectorImageToImage m_ArgsInfo; + bool m_Verbose; + std::string m_InputFileName; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkVectorImageToImageGenericFilter.txx" +#endif + +#endif // #define clitkVectorImageToImageGenericFilter_h diff --git a/tools/clitkVectorImageToImageGenericFilter.txx b/tools/clitkVectorImageToImageGenericFilter.txx new file mode 100755 index 0000000..dc2af9f --- /dev/null +++ b/tools/clitkVectorImageToImageGenericFilter.txx @@ -0,0 +1,91 @@ +/*========================================================================= + 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 clitkVectorImageToImageGenericFilter_txx +#define clitkVectorImageToImageGenericFilter_txx + +/* ================================================= + * @file clitkVectorImageToImageGenericFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + void + VectorImageToImageGenericFilter::UpdateWithDim(std::string PixelType, unsigned int Components) + { + if (m_Verbose) std::cout << "Image was detected to be "< >(); + } + else std::cerr<<"Number of components is "< + void + VectorImageToImageGenericFilter::UpdateWithDimAndPixelType() + { + // ImageTypes + typedef itk::Image InputImageType; + typedef typename PixelType::ComponentType ComponentType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + // Filter + typedef clitk::VectorImageToImageFilter FilterType; + typename FilterType::Pointer filter=FilterType::New(); + filter->SetInput(input); + filter->SetComponentIndex(m_ArgsInfo.componentIndex_arg); + filter->Update(); + typename OutputImageType::Pointer output=filter->GetOutput(); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + + } + + +}//end clitk + +#endif //#define clitkVectorImageToImageGenericFilter_txx