ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkOrientImageFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkOrientImageFilter_h
00019 #define __itkOrientImageFilter_h
00020 
00021 #include "itkPermuteAxesImageFilter.h"
00022 #include "itkFlipImageFilter.h"
00023 #include "itkSpatialOrientationAdapter.h"
00024 #include <map>
00025 #include <string>
00026 
00027 namespace itk
00028 {
00139 template< class TInputImage, class TOutputImage >
00140 class ITK_EXPORT OrientImageFilter:
00141   public ImageToImageFilter< TInputImage, TOutputImage >
00142 {
00143 public:
00145   typedef OrientImageFilter                               Self;
00146   typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass;
00147   typedef SmartPointer< Self >                            Pointer;
00148   typedef SmartPointer< const Self >                      ConstPointer;
00149 
00151   typedef TInputImage                            InputImageType;
00152   typedef typename InputImageType::Pointer       InputImagePointer;
00153   typedef typename InputImageType::ConstPointer  InputImageConstPointer;
00154   typedef typename InputImageType::RegionType    InputImageRegionType;
00155   typedef typename InputImageType::PixelType     InputImagePixelType;
00156   typedef TOutputImage                           OutputImageType;
00157   typedef typename OutputImageType::Pointer      OutputImagePointer;
00158   typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
00159   typedef typename OutputImageType::RegionType   OutputImageRegionType;
00160   typedef typename OutputImageType::PixelType    OutputImagePixelType;
00161   typedef SpatialOrientation::ValidCoordinateOrientationFlags
00162   CoordinateOrientationCode;
00163 
00165   typedef PermuteAxesImageFilter< TInputImage >        PermuterType;
00166   typedef typename PermuterType::PermuteOrderArrayType PermuteOrderArrayType;
00167 
00169   typedef FlipImageFilter< TInputImage >          FlipperType;
00170   typedef typename FlipperType::FlipAxesArrayType FlipAxesArrayType;
00171 
00173   itkStaticConstMacro(InputImageDimension, unsigned int,
00174                       TInputImage::ImageDimension);
00175   itkStaticConstMacro(OutputImageDimension, unsigned int,
00176                       TOutputImage::ImageDimension);
00178 
00180   itkNewMacro(Self);
00181 
00183   itkTypeMacro(OrientImageFilter, ImageToImageFilter);
00184 
00186   itkGetEnumMacro(GivenCoordinateOrientation, CoordinateOrientationCode);
00187   void SetGivenCoordinateOrientation(CoordinateOrientationCode newCode);
00189 
00190   inline void SetGivenCoordinateDirection(const typename TInputImage::DirectionType & GivenDirection)
00191   {
00192     SetGivenCoordinateOrientation(
00193       itk::SpatialOrientationAdapter().FromDirectionCosines(GivenDirection) );
00194   }
00195 
00196   itkGetEnumMacro(DesiredCoordinateOrientation, CoordinateOrientationCode);
00197   void SetDesiredCoordinateOrientation(CoordinateOrientationCode newCode);
00198 
00199   inline void SetDesiredCoordinateDirection(const typename TOutputImage::DirectionType & DesiredDirection)
00200   {
00201     SetDesiredCoordinateOrientation(
00202       itk::SpatialOrientationAdapter().FromDirectionCosines(DesiredDirection) );
00203   }
00204 
00212   itkBooleanMacro(UseImageDirection);
00213   itkGetConstMacro(UseImageDirection, bool);
00214   itkSetMacro(UseImageDirection, bool);
00216 
00218   itkGetConstReferenceMacro(PermuteOrder, PermuteOrderArrayType);
00219 
00221   itkGetConstReferenceMacro(FlipAxes, FlipAxesArrayType);
00222 
00236   void SetDesiredCoordinateOrientationToAxial()
00237   {
00238     this->SetDesiredCoordinateOrientation (SpatialOrientation::ITK_COORDINATE_ORIENTATION_RAI);
00239   }
00240 
00241   void SetDesiredCoordinateOrientationToCoronal()
00242   {
00243     this->SetDesiredCoordinateOrientation (SpatialOrientation::ITK_COORDINATE_ORIENTATION_RSA);
00244   }
00245 
00246   void SetDesiredCoordinateOrientationToSagittal()
00247   {
00248     this->SetDesiredCoordinateOrientation (SpatialOrientation::ITK_COORDINATE_ORIENTATION_ASL);
00249   }
00250 
00258   virtual void GenerateOutputInformation();
00259 
00260 #ifdef ITK_USE_CONCEPT_CHECKING
00261 
00262   itkConceptMacro( InputConvertibleToOutput,
00263                    ( Concept::Convertible< InputImagePixelType, OutputImagePixelType > ) );
00264   itkConceptMacro( SameDimension,
00265                    ( Concept::SameDimension< itkGetStaticConstMacro(InputImageDimension),
00266                                              itkGetStaticConstMacro(OutputImageDimension) > ) );
00267   itkConceptMacro( DimensionShouldBe3,
00268                    ( Concept::SameDimension< itkGetStaticConstMacro(InputImageDimension), 3 > ) );
00269 
00271 #endif
00272 protected:
00273   OrientImageFilter();
00274   ~OrientImageFilter() {}
00275   void PrintSelf(std::ostream & os, Indent indent) const;
00277 
00281   void GenerateInputRequestedRegion();
00282 
00284   void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) );
00285 
00286 /*** Member functions used by GenerateData: */
00287   void DeterminePermutationsAndFlips(const SpatialOrientation::ValidCoordinateOrientationFlags fixed_orient,
00288                                      const SpatialOrientation::ValidCoordinateOrientationFlags moving_orient);
00289 
00290   bool NeedToPermute();
00291 
00292   bool NeedToFlip();
00293 
00296   void GenerateData();
00297 
00298 private:
00299   OrientImageFilter(const Self &); //purposely not implemented
00300   void operator=(const Self &);    //purposely not implemented
00301 
00302   std::string GetMajorAxisFromPatientRelativeDirectionCosine(double x, double y, double z);
00303 
00304   CoordinateOrientationCode m_GivenCoordinateOrientation;
00305   CoordinateOrientationCode m_DesiredCoordinateOrientation;
00306   bool                      m_UseImageDirection;
00307 
00308   PermuteOrderArrayType m_PermuteOrder;
00309   FlipAxesArrayType     m_FlipAxes;
00310 
00311   std::map< std::string, CoordinateOrientationCode > m_StringToCode;
00312   std::map< CoordinateOrientationCode, std::string > m_CodeToString;
00313 }; // end of class
00314 } // end namespace itk
00315 
00316 #ifndef ITK_MANUAL_INSTANTIATION
00317 #include "itkOrientImageFilter.hxx"
00318 #endif
00319 
00320 #endif
00321