ITK  5.1.0
Insight Toolkit
itkCastImageFilter.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 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 false;
48  }
49 
50  bool
51  operator==(const Cast & other) const
52  {
53  return !(*this != other);
54  }
55 
56  inline TOutput
57  operator()(const TInput & A) const
58  {
59  return static_cast<TOutput>(A);
60  }
61 };
62 } // namespace Functor
63 #endif
64 
65 
103 template <typename TInputImage, typename TOutputImage>
104 class ITK_TEMPLATE_EXPORT CastImageFilter : public InPlaceImageFilter<TInputImage, TOutputImage>
105 {
106 public:
107  ITK_DISALLOW_COPY_AND_ASSIGN(CastImageFilter);
108 
111 
113 
116 
117 
118  using OutputImageRegionType = typename Superclass::OutputImageRegionType;
119 
120  using InputPixelType = typename TInputImage::PixelType;
121  using OutputPixelType = typename TOutputImage::PixelType;
122 
124  itkNewMacro(Self);
125 
127  itkTypeMacro(CastImageFilter, InPlaceImageFilter);
128 
129 protected:
130  CastImageFilter();
131  ~CastImageFilter() override = default;
132 
133  void
134  GenerateOutputInformation() override;
135 
136  void
137  GenerateData() override;
138 
139  void
140  DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
141 
142  template <typename TInputPixelType,
143  typename TOutputPixelType,
144  typename std::enable_if<mpl::is_static_castable<TInputPixelType, TOutputPixelType>::value, int>::type = 0>
145  void
146  DynamicThreadedGenerateDataDispatched(const OutputImageRegionType & outputRegionForThread);
147 
148  template <typename TInputPixelType,
149  typename TOutputPixelType,
150  typename std::enable_if<!mpl::is_static_castable<TInputPixelType, TOutputPixelType>::value, int>::type = 0>
151  void
152  DynamicThreadedGenerateDataDispatched(const OutputImageRegionType & outputRegionForThread);
153 
154 private:
155 };
156 } // end namespace itk
157 
158 #endif
159 
160 
161 #ifndef ITK_MANUAL_INSTANTIATION
162 #include "itkCastImageFilter.hxx"
163 #endif
itk::CastImageFilter
Casts input pixels to output pixel type.
Definition: itkCastImageFilter.h:104
itkUnaryFunctorImageFilter.h
itk::CastImageFilter< FeatureImageType, ImageType >::OutputPixelType
typename ImageType ::PixelType OutputPixelType
Definition: itkCastImageFilter.h:121
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:532
itk::CastImageFilter< FeatureImageType, ImageType >::InputPixelType
typename FeatureImageType ::PixelType InputPixelType
Definition: itkCastImageFilter.h:120
itk::ImageSource< ImageType >::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itk::operator!=
bool operator!=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:539
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26