ITK  4.3.0
Insight Segmentation and Registration 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"
23 
24 namespace itk
25 {
63 namespace Functor
64 {
65 template< class TInput, class TOutput >
66 class Cast
67 {
68 public:
69  Cast() {}
70  virtual ~Cast() {}
71  bool operator!=(const Cast &) const
72  {
73  return false;
74  }
75 
76  bool operator==(const Cast & other) const
77  {
78  return !( *this != other );
79  }
80 
81  inline TOutput operator()(const TInput & A) const
82  {
83  return static_cast< TOutput >( A );
84  }
85 };
86 }
87 
88 template< class TInputImage, class TOutputImage >
89 class ITK_EXPORT CastImageFilter:
90  public
91  UnaryFunctorImageFilter< TInputImage, TOutputImage,
92  Functor::Cast<
93  typename TInputImage::PixelType,
94  typename TOutputImage::PixelType > >
95 {
96 public:
99  typedef UnaryFunctorImageFilter< TInputImage, TOutputImage,
101  typename TInputImage::PixelType,
102  typename TOutputImage::PixelType >
104 
107 
109  itkNewMacro(Self);
110 
113 
114 #ifdef ITK_USE_CONCEPT_CHECKING
115 
116  itkConceptMacro( InputConvertibleToOutputCheck,
117  ( Concept::Convertible< typename TInputImage::PixelType,
118  typename TOutputImage::PixelType > ) );
119 
121 #endif
122 
123 protected:
125  virtual ~CastImageFilter() {}
126 
127  void GenerateData()
128  {
129  if ( this->GetInPlace() && this->CanRunInPlace() )
130  {
131  // nothing to do, so avoid iterating over all the pixels
132  // for nothing! Allocate the output, generate a fake progress and exit
133  this->AllocateOutputs();
134  ProgressReporter progress(this, 0, 1);
135  return;
136  }
137  Superclass::GenerateData();
138  }
139 
140 private:
141  CastImageFilter(const Self &); //purposely not implemented
142  void operator=(const Self &); //purposely not implemented
143 };
144 } // end namespace itk
145 
146 #endif
147