ITK  5.3.0
Insight Toolkit
itkCastImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 itkCastImageFilter_h
19 #define itkCastImageFilter_h
20 
22 #include "itkProgressReporter.h"
24 
25 #include <type_traits>
26 
27 namespace itk
28 {
29 #if !defined(ITK_LEGACY_REMOVE)
30 namespace Functor
31 {
38 template <typename TInput, typename TOutput>
39 class ITK_TEMPLATE_EXPORT Cast
40 {
41 public:
42  Cast() = default;
43  virtual ~Cast() = default;
44  bool
45  operator==(const Cast &) const
46  {
47  return true;
48  }
49 
50  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Cast);
51 
52  inline TOutput
53  operator()(const TInput & A) const
54  {
55  return static_cast<TOutput>(A);
56  }
57 };
58 } // namespace Functor
59 #endif
60 
61 
99 template <typename TInputImage, typename TOutputImage>
100 class ITK_TEMPLATE_EXPORT CastImageFilter : public InPlaceImageFilter<TInputImage, TOutputImage>
101 {
102 public:
103  ITK_DISALLOW_COPY_AND_MOVE(CastImageFilter);
104 
107 
109 
112 
113 
114  using typename Superclass::OutputImageRegionType;
115 
116  using InputPixelType = typename TInputImage::PixelType;
117  using OutputPixelType = typename TOutputImage::PixelType;
118 
120  itkNewMacro(Self);
121 
123  itkTypeMacro(CastImageFilter, InPlaceImageFilter);
124 
125 protected:
126  CastImageFilter();
127  ~CastImageFilter() override = default;
128 
129  void
130  GenerateOutputInformation() override;
131 
132  void
133  GenerateData() override;
134 
135  void
136  DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
137 
138  template <typename TInputPixelType,
139  typename TOutputPixelType,
140  std::enable_if_t<mpl::is_static_castable<TInputPixelType, TOutputPixelType>::value, int> = 0>
141  void
142  DynamicThreadedGenerateDataDispatched(const OutputImageRegionType & outputRegionForThread);
143 
144  template <typename TInputPixelType,
145  typename TOutputPixelType,
146  std::enable_if_t<!mpl::is_static_castable<TInputPixelType, TOutputPixelType>::value, int> = 0>
147  void
148  DynamicThreadedGenerateDataDispatched(const OutputImageRegionType & outputRegionForThread);
149 
150 private:
151 };
152 } // end namespace itk
153 
154 #endif
155 
156 
157 #ifndef ITK_MANUAL_INSTANTIATION
158 #include "itkCastImageFilter.hxx"
159 #endif
itk::CastImageFilter
Casts input pixels to output pixel type.
Definition: itkCastImageFilter.h:100
itkUnaryFunctorImageFilter.h
itk::CastImageFilter< FeatureImageType, ImageType >::OutputPixelType
typename ImageType ::PixelType OutputPixelType
Definition: itkCastImageFilter.h:117
itk::InPlaceImageFilter
Base class for filters that take an image as input and overwrite that image as the output.
Definition: itkInPlaceImageFilter.h:77
itkProgressReporter.h
itk::SmartPointer< Self >
itkMetaProgrammingLibrary.h
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::operator==
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:536
itk::CastImageFilter< FeatureImageType, ImageType >::InputPixelType
typename FeatureImageType ::PixelType InputPixelType
Definition: itkCastImageFilter.h:116
itk::ImageSource< ImageType >::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24