ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkOrientImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkOrientImageFilter_h
19 #define itkOrientImageFilter_h
20 
22 #include "itkFlipImageFilter.h"
24 #include <map>
25 #include <string>
26 
27 namespace itk
28 {
140 template< typename TInputImage, typename TOutputImage >
141 class ITK_TEMPLATE_EXPORT OrientImageFilter:
142  public ImageToImageFilter< TInputImage, TOutputImage >
143 {
144 public:
150 
152  typedef TInputImage InputImageType;
153  typedef typename InputImageType::Pointer InputImagePointer;
154  typedef typename InputImageType::ConstPointer InputImageConstPointer;
155  typedef typename InputImageType::RegionType InputImageRegionType;
156  typedef typename InputImageType::PixelType InputImagePixelType;
157  typedef TOutputImage OutputImageType;
158  typedef typename OutputImageType::Pointer OutputImagePointer;
159  typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
160  typedef typename OutputImageType::RegionType OutputImageRegionType;
161  typedef typename OutputImageType::PixelType OutputImagePixelType;
164 
168 
172 
174  itkStaticConstMacro(InputImageDimension, unsigned int,
175  TInputImage::ImageDimension);
176  itkStaticConstMacro(OutputImageDimension, unsigned int,
177  TOutputImage::ImageDimension);
179 
181  itkNewMacro(Self);
182 
184  itkTypeMacro(OrientImageFilter, ImageToImageFilter);
185 
187  itkGetEnumMacro(GivenCoordinateOrientation, CoordinateOrientationCode);
188  void SetGivenCoordinateOrientation(CoordinateOrientationCode newCode);
190 
191  inline void SetGivenCoordinateDirection(const typename TInputImage::DirectionType & GivenDirection)
192  {
193  SetGivenCoordinateOrientation(
194  itk::SpatialOrientationAdapter().FromDirectionCosines(GivenDirection) );
195  }
196 
197  itkGetEnumMacro(DesiredCoordinateOrientation, CoordinateOrientationCode);
198  void SetDesiredCoordinateOrientation(CoordinateOrientationCode newCode);
199 
200  inline void SetDesiredCoordinateDirection(const typename TOutputImage::DirectionType & DesiredDirection)
201  {
202  SetDesiredCoordinateOrientation(
203  itk::SpatialOrientationAdapter().FromDirectionCosines(DesiredDirection) );
204  }
205 
212  itkBooleanMacro(UseImageDirection);
213  itkGetConstMacro(UseImageDirection, bool);
214  itkSetMacro(UseImageDirection, bool);
216 
218  itkGetConstReferenceMacro(PermuteOrder, PermuteOrderArrayType);
219 
221  itkGetConstReferenceMacro(FlipAxes, FlipAxesArrayType);
222 
237  {
238  this->SetDesiredCoordinateOrientation (SpatialOrientation::ITK_COORDINATE_ORIENTATION_RAI);
239  }
240 
242  {
243  this->SetDesiredCoordinateOrientation (SpatialOrientation::ITK_COORDINATE_ORIENTATION_RSA);
244  }
245 
247  {
248  this->SetDesiredCoordinateOrientation (SpatialOrientation::ITK_COORDINATE_ORIENTATION_ASL);
249  }
250 
258  virtual void GenerateOutputInformation() ITK_OVERRIDE;
259 
260 #ifdef ITK_USE_CONCEPT_CHECKING
261  // Begin concept checking
262  itkConceptMacro( InputConvertibleToOutput,
264  itkConceptMacro( SameDimension,
265  ( Concept::SameDimension< itkGetStaticConstMacro(InputImageDimension),
266  itkGetStaticConstMacro(OutputImageDimension) > ) );
267  itkConceptMacro( DimensionShouldBe3,
268  ( Concept::SameDimension< itkGetStaticConstMacro(InputImageDimension), 3 > ) );
269  // End concept checking
270 #endif
271 
272 protected:
274  ~OrientImageFilter() ITK_OVERRIDE {}
275  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
276 
280  void GenerateInputRequestedRegion() ITK_OVERRIDE;
281 
283  void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) ) ITK_OVERRIDE;
284 
285 /*** Member functions used by GenerateData: */
286  void DeterminePermutationsAndFlips(const SpatialOrientation::ValidCoordinateOrientationFlags fixed_orient,
287  const SpatialOrientation::ValidCoordinateOrientationFlags moving_orient);
288 
290  bool NeedToPermute();
291 
293  bool NeedToFlip();
294 
297  void GenerateData() ITK_OVERRIDE;
298 
299 private:
300  ITK_DISALLOW_COPY_AND_ASSIGN(OrientImageFilter);
301 
302  std::string GetMajorAxisFromPatientRelativeDirectionCosine(double x, double y, double z);
303 
304  CoordinateOrientationCode m_GivenCoordinateOrientation;
305  CoordinateOrientationCode m_DesiredCoordinateOrientation;
306  bool m_UseImageDirection;
307 
308  PermuteOrderArrayType m_PermuteOrder;
309  FlipAxesArrayType m_FlipAxes;
310 
311  std::map< std::string, CoordinateOrientationCode > m_StringToCode;
312  std::map< CoordinateOrientationCode, std::string > m_CodeToString;
313 }; // end of class
314 } // end namespace itk
315 
316 #ifndef ITK_MANUAL_INSTANTIATION
317 #include "itkOrientImageFilter.hxx"
318 #endif
319 
320 #endif
void SetGivenCoordinateDirection(const typename TInputImage::DirectionType &GivenDirection)
SmartPointer< Self > Pointer
OutputImageType::PixelType OutputImagePixelType
InputImageType::RegionType InputImageRegionType
InputImageType::Pointer InputImagePointer
OutputImageType::RegionType OutputImageRegionType
PermuterType::PermuteOrderArrayType PermuteOrderArrayType
FlipperType::FlipAxesArrayType FlipAxesArrayType
Base class for all process objects that output image data.
Converts SpatialOrientation flags to/from direction cosines.
InputImageType::ConstPointer InputImageConstPointer
PermuteAxesImageFilter< TInputImage > PermuterType
Permute axes and then flip images as needed to obtain agreement in coordinateOrientation codes...
FlipImageFilter< TInputImage > FlipperType
InputImageType::PixelType InputImagePixelType
void SetDesiredCoordinateDirection(const typename TOutputImage::DirectionType &DesiredDirection)
Permutes the image axes according to a user specified order.
Flips an image across user specified axes.
OutputImageType::Pointer OutputImagePointer
SpatialOrientation::ValidCoordinateOrientationFlags CoordinateOrientationCode
Base class for filters that take an image as input and produce an image as output.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
OutputImageType::ConstPointer OutputImageConstPointer
ImageToImageFilter< TInputImage, TOutputImage > Superclass
#define itkConceptMacro(name, concept)
SmartPointer< const Self > ConstPointer
Base class for all data objects in ITK.