ITK  5.0.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:
145  ITK_DISALLOW_COPY_AND_ASSIGN(OrientImageFilter);
146 
152 
154  using InputImageType = TInputImage;
155  using InputImagePointer = typename InputImageType::Pointer;
156  using InputImageConstPointer = typename InputImageType::ConstPointer;
158  using InputImagePixelType = typename InputImageType::PixelType;
159  using OutputImageType = TOutputImage;
160  using OutputImagePointer = typename OutputImageType::Pointer;
161  using OutputImageConstPointer = typename OutputImageType::ConstPointer;
163  using OutputImagePixelType = typename OutputImageType::PixelType;
165 
169 
173 
175  static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
176  static constexpr unsigned int OutputImageDimension = TOutputImage::ImageDimension;
177 
179  itkNewMacro(Self);
180 
182  itkTypeMacro(OrientImageFilter, ImageToImageFilter);
183 
185  itkGetEnumMacro(GivenCoordinateOrientation, CoordinateOrientationCode);
186  void SetGivenCoordinateOrientation(CoordinateOrientationCode newCode);
188 
189  inline void SetGivenCoordinateDirection(const typename TInputImage::DirectionType & GivenDirection)
190  {
191  SetGivenCoordinateOrientation(
192  itk::SpatialOrientationAdapter().FromDirectionCosines(GivenDirection) );
193  }
194 
195  itkGetEnumMacro(DesiredCoordinateOrientation, CoordinateOrientationCode);
196  void SetDesiredCoordinateOrientation(CoordinateOrientationCode newCode);
197 
198  inline void SetDesiredCoordinateDirection(const typename TOutputImage::DirectionType & DesiredDirection)
199  {
200  SetDesiredCoordinateOrientation(
201  itk::SpatialOrientationAdapter().FromDirectionCosines(DesiredDirection) );
202  }
203 
210  itkBooleanMacro(UseImageDirection);
211  itkGetConstMacro(UseImageDirection, bool);
212  itkSetMacro(UseImageDirection, bool);
214 
216  itkGetConstReferenceMacro(PermuteOrder, PermuteOrderArrayType);
217 
219  itkGetConstReferenceMacro(FlipAxes, FlipAxesArrayType);
220 
235  {
236  this->SetDesiredCoordinateOrientation (SpatialOrientation::ITK_COORDINATE_ORIENTATION_RAI);
237  }
238 
240  {
241  this->SetDesiredCoordinateOrientation (SpatialOrientation::ITK_COORDINATE_ORIENTATION_RSA);
242  }
243 
245  {
246  this->SetDesiredCoordinateOrientation (SpatialOrientation::ITK_COORDINATE_ORIENTATION_ASL);
247  }
248 
256  void GenerateOutputInformation() override;
257 
258 #ifdef ITK_USE_CONCEPT_CHECKING
259  // Begin concept checking
260  itkConceptMacro( InputConvertibleToOutput,
262  itkConceptMacro( SameDimension,
263  ( Concept::SameDimension< Self::InputImageDimension,
264  Self::OutputImageDimension > ) );
265  itkConceptMacro( DimensionShouldBe3,
267  // End concept checking
268 #endif
269 
270 protected:
272  ~OrientImageFilter() override = default;
273  void PrintSelf(std::ostream & os, Indent indent) const override;
274 
278  void GenerateInputRequestedRegion() override;
279 
281  void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) ) override;
282 
283 /*** Member functions used by GenerateData: */
284  void DeterminePermutationsAndFlips(const SpatialOrientation::ValidCoordinateOrientationFlags fixed_orient,
286 
288  bool NeedToPermute();
289 
291  bool NeedToFlip();
292 
295  void GenerateData() override;
296 
297 private:
298  std::string GetMajorAxisFromPatientRelativeDirectionCosine(double x, double y, double z);
299 
302  bool m_UseImageDirection{false};
303 
306 
307  std::map< std::string, CoordinateOrientationCode > m_StringToCode;
308  std::map< CoordinateOrientationCode, std::string > m_CodeToString;
309 }; // end of class
310 } // end namespace itk
311 
312 #ifndef ITK_MANUAL_INSTANTIATION
313 #include "itkOrientImageFilter.hxx"
314 #endif
315 
316 #endif
void SetGivenCoordinateDirection(const typename TInputImage::DirectionType &GivenDirection)
typename OutputImageType::Pointer OutputImagePointer
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Base class for all process objects that output image data.
Converts SpatialOrientation flags to/from direction cosines.
typename OutputImageType::PixelType OutputImagePixelType
typename InputImageType::PixelType InputImagePixelType
typename PermuterType::PermuteOrderArrayType PermuteOrderArrayType
typename InputImageType::Pointer InputImagePointer
Permute axes and then flip images as needed to obtain agreement in coordinateOrientation codes...
typename OutputImageType::RegionType OutputImageRegionType
TOutputImage OutputImageType
void SetDesiredCoordinateDirection(const typename TOutputImage::DirectionType &DesiredDirection)
std::map< CoordinateOrientationCode, std::string > m_CodeToString
Permutes the image axes according to a user specified order.
Flips an image across user specified axes.
typename FlipperType::FlipAxesArrayType FlipAxesArrayType
typename InputImageType::RegionType InputImageRegionType
PermuteOrderArrayType m_PermuteOrder
Base class for filters that take an image as input and produce an image as output.
typename OutputImageType::ConstPointer OutputImageConstPointer
Control indentation during Print() invocation.
Definition: itkIndent.h:49
std::map< std::string, CoordinateOrientationCode > m_StringToCode
#define itkConceptMacro(name, concept)
FlipAxesArrayType m_FlipAxes
typename InputImageType::ConstPointer InputImageConstPointer
Base class for all data objects in ITK.