diff --git a/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionToSeparateImageFilter.h b/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionToSeparateImageFilter.h index bd1433bcc8..25d5223342 100644 --- a/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionToSeparateImageFilter.h +++ b/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionToSeparateImageFilter.h @@ -1,95 +1,107 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef ITKB0IMAGEEXTRACTIONTOSEPARATEIMAGEFILTER_H #define ITKB0IMAGEEXTRACTIONTOSEPARATEIMAGEFILTER_H #include "itkImageToImageFilter.h" namespace itk { /** \class B0ImageExtractionToSeparateImageFilter \brief This class has an advanced functionality to the B0ImageExtractionImageFilter, however the b0 images are stored in a 3D+t image with each b0 image beeing a separate timestep and not averaged to a single 3D volume */ template< class TInputImagePixelType, class TOutputImagePixelType > class B0ImageExtractionToSeparateImageFilter : public ImageToImageFilter< VectorImage, Image< TOutputImagePixelType, 4 > > { public: typedef B0ImageExtractionToSeparateImageFilter Self; typedef SmartPointer Pointer; typedef SmartPointer ConstPointer; typedef TInputImagePixelType InputPixelType; typedef TOutputImagePixelType OutputPixelType; typedef ImageToImageFilter< VectorImage, Image< TOutputImagePixelType, 4 > > Superclass; /** typedefs from superclass */ typedef typename Superclass::InputImageType InputImageType; - typedef typename Superclass::OutputImageType OutputImageType; + //typedef typename Superclass::OutputImageType OutputImageType; + typedef Image< TOutputImagePixelType, 4 > OutputImageType; - typedef typename Superclass::OutputImageRegionType - OutputImageRegionType; + typedef typename OutputImageType::RegionType OutputImageRegionType; typedef vnl_vector_fixed< double, 3 > GradientDirectionType; typedef itk::VectorContainer< unsigned int, GradientDirectionType > GradientDirectionContainerType; typedef typename GradientDirectionContainerType::Iterator GradContainerIteratorType; /** Method for creation through the object factory. */ itkNewMacro(Self); /** Runtime information support. */ itkTypeMacro(B0ImageExtractionToSeparateImageFilter, ImageToImageFilter); GradientDirectionContainerType::Pointer GetDirections() { return m_Directions; } void SetDirections( GradientDirectionContainerType::Pointer directions ) { this->m_Directions = directions; } protected: B0ImageExtractionToSeparateImageFilter(); virtual ~B0ImageExtractionToSeparateImageFilter(){}; void GenerateData(); + /** The dimension of the output does not match the dimension of the input + hence we need to re-implement the CopyInformation method to avoid + executing the default implementation which tries to copy the input information to the + output + */ + virtual void CopyInformation( const DataObject *data); + + /** Override of the ProcessObject::GenerateOutputInformation() because of different + dimensionality of the input and the output + */ + virtual void GenerateOutputInformation(); + GradientDirectionContainerType::Pointer m_Directions; }; } // end namespace itk #ifndef ITK_MANUAL_INSTANTIATION #include "itkB0ImageExtractionToSeparateImageFilter.txx" #endif #endif // ITKB0IMAGEEXTRACTIONTOSEPARATEIMAGEFILTER_H diff --git a/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionToSeparateImageFilter.txx b/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionToSeparateImageFilter.txx index 2b46e2d947..251105af8c 100644 --- a/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionToSeparateImageFilter.txx +++ b/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionToSeparateImageFilter.txx @@ -1,132 +1,148 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __itkB0ImageExtractionToSeparateImageFilter_txx #define __itkB0ImageExtractionToSeparateImageFilter_txx #include "itkB0ImageExtractionToSeparateImageFilter.h" template< class TInputImagePixelType, class TOutputImagePixelType> - itk::B0ImageExtractionToSeparateImageFilter< TInputImagePixelType, TOutputImagePixelType > - ::B0ImageExtractionToSeparateImageFilter() - { - this->SetNumberOfRequiredInputs( 1 ); - } +itk::B0ImageExtractionToSeparateImageFilter< TInputImagePixelType, TOutputImagePixelType > +::B0ImageExtractionToSeparateImageFilter() +{ + this->SetNumberOfRequiredInputs( 1 ); +} template< class TInputImagePixelType, class TOutputImagePixelType> - void itk::B0ImageExtractionToSeparateImageFilter< - TInputImagePixelType, TOutputImagePixelType >::GenerateData() - { +void itk::B0ImageExtractionToSeparateImageFilter< +TInputImagePixelType, TOutputImagePixelType >::CopyInformation( const DataObject *data) +{ - GradContainerIteratorType begin = m_Directions->Begin(); - GradContainerIteratorType end = m_Directions->End(); +} - // Find the indices of the b0 images in the diffusion image - std::vector indices; - int index = 0; - while(begin!=end) +template< class TInputImagePixelType, + class TOutputImagePixelType> +void itk::B0ImageExtractionToSeparateImageFilter< +TInputImagePixelType, TOutputImagePixelType >::GenerateOutputInformation() +{ + +} + +template< class TInputImagePixelType, + class TOutputImagePixelType> +void itk::B0ImageExtractionToSeparateImageFilter< +TInputImagePixelType, TOutputImagePixelType >::GenerateData() +{ + + GradContainerIteratorType begin = m_Directions->Begin(); + GradContainerIteratorType end = m_Directions->End(); + + // Find the indices of the b0 images in the diffusion image + std::vector indices; + int index = 0; + while(begin!=end) { GradientDirectionType grad = begin->Value(); if(grad[0] == 0 && grad[1] == 0 && grad[2] == 0) - { - indices.push_back(index); - } + { + indices.push_back(index); + } ++index; ++begin; } - // declare the output image - // this will have the b0 images stored as timesteps - typedef itk::Image OutputImageType; - OutputImageType::Pointer outputImage = OutputImageType::New(); + // declare the output image + // this will have the b0 images stored as timesteps + typename OutputImageType::Pointer outputImage = this->GetOutput(); + //OutputImageType::New(); - // get the input region - typename Superclass::InputImageType::RegionType inputRegion = - this->GetInput()->GetLargestPossibleRegion(); + // get the input region + typename Superclass::InputImageType::RegionType inputRegion = + this->GetInput()->GetLargestPossibleRegion(); - // allocate image with - // - dimension: [DimX, DimY, DimZ, NumOfb0 ] - // - spacing: old one, 1.0 time + // allocate image with + // - dimension: [DimX, DimY, DimZ, NumOfb0 ] + // - spacing: old one, 1.0 time - OutputImageType::SpacingType spacing; - spacing.Fill(1); + typename OutputImageType::SpacingType spacing; + spacing.Fill(1); - OutputImageType::PointType origin; - origin.Fill(0); + typename OutputImageType::PointType origin; + origin.Fill(0); - OutputImageType::RegionType outputRegion; + OutputImageRegionType outputRegion; - // the spacing and origin corresponds to the respective values in the input image (3D) - // the same for the region - for (unsigned int i=0; i< 3; i++) + // the spacing and origin corresponds to the respective values in the input image (3D) + // the same for the region + for (unsigned int i=0; i< 3; i++) { spacing[i] = (this->GetInput()->GetSpacing())[i]; origin[i] = (this->GetInput()->GetOrigin())[i]; outputRegion.SetSize(i, this->GetInput()->GetLargestPossibleRegion().GetSize()[i]); outputRegion.SetIndex(i, this->GetInput()->GetLargestPossibleRegion().GetIndex()[i]); } - // number of timesteps = number of b0 images - outputRegion.SetSize(3, indices.size()); - outputRegion.SetIndex( 3, 0 ); + // number of timesteps = number of b0 images + outputRegion.SetSize(3, indices.size()); + outputRegion.SetIndex( 3, 0 ); - outputImage->SetSpacing( spacing ); - outputImage->SetOrigin( origin ); - // FIXME: direction matrix - outputImage->SetRegions( outputRegion ); - outputImage->Allocate(); + outputImage->SetSpacing( spacing ); + outputImage->SetOrigin( origin ); + // FIXME: direction matrix + outputImage->SetRegions( outputRegion ); + outputImage->Allocate(); - // input iterator - itk::ImageRegionConstIterator inputIt( this->GetInput(), this->GetInput()->GetLargestPossibleRegion() ); + // input iterator + itk::ImageRegionConstIterator inputIt( this->GetInput(), this->GetInput()->GetLargestPossibleRegion() ); - // we want to iterate separately over each 3D volume of the output image - // so reset the regions last dimension - outputRegion.SetSize(3,1); - unsigned int currentTimeStep = 0; + // we want to iterate separately over each 3D volume of the output image + // so reset the regions last dimension + outputRegion.SetSize(3,1); + unsigned int currentTimeStep = 0; - // extract b0 and insert them as a new time step - for(std::vector::iterator indexIt = indices.begin(); + // extract b0 and insert them as a new time step + for(std::vector::iterator indexIt = indices.begin(); indexIt != indices.end(); indexIt++) { // set the time step outputRegion.SetIndex(3, currentTimeStep); itk::ImageRegionIterator< OutputImageType> outputIt( outputImage.GetPointer(), outputRegion ); // iterate over the current b0 image and store it to corresponding place outputIt = outputIt.Begin(); while( !outputIt.IsAtEnd() && !inputIt.IsAtEnd() ) - { - // the input vector - typename InputImageType::PixelType vec = inputIt.Get(); + { + // the input vector + typename InputImageType::PixelType vec = inputIt.Get(); - outputIt.Set( vec[*indexIt]); - ++outputIt; - ++inputIt; - } + outputIt.Set( vec[*indexIt]); + ++outputIt; + ++inputIt; + } // increase time step currentTimeStep++; } - } +} #endif // ifndef __itkB0ImageExtractionToSeparateImageFilter_txx