ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkVectorIndexSelectionCastImageFilter.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 __itkVectorIndexSelectionCastImageFilter_h
19 #define __itkVectorIndexSelectionCastImageFilter_h
20 
22 
23 namespace itk
24 {
25 namespace Functor
26 {
27 template< typename TInput, typename TOutput >
29 {
30 public:
33 
34  unsigned int GetIndex() const { return m_Index; }
35  void SetIndex(unsigned int i) { m_Index = i; }
36 
37  bool operator!=(const VectorIndexSelectionCast & other) const
38  {
39  if ( m_Index != other.m_Index )
40  {
41  return true;
42  }
43  return false;
44  }
45 
46  bool operator==(const VectorIndexSelectionCast & other) const
47  {
48  return !( *this != other );
49  }
50 
51  inline TOutput operator()(const TInput & A) const
52  {
53  return static_cast< TOutput >( A[m_Index] );
54  }
55 
56 private:
57  unsigned int m_Index;
58 };
59 }
60 
84 template< typename TInputImage, typename TOutputImage >
86  public
87  UnaryFunctorImageFilter< TInputImage, TOutputImage,
88  Functor::VectorIndexSelectionCast< typename TInputImage::PixelType,
89  typename TOutputImage::PixelType > >
90 {
91 public:
95  TInputImage, TOutputImage,
96  Functor::VectorIndexSelectionCast< typename TInputImage::PixelType,
97  typename TOutputImage::PixelType > >
101 
103  itkNewMacro(Self);
104 
108 
110  void SetIndex(unsigned int i)
111  {
112  if ( i != this->GetFunctor().GetIndex() )
113  {
114  this->GetFunctor().SetIndex(i);
115  this->Modified();
116  }
117  }
119 
120  unsigned int GetIndex(void) const
121  {
122  return this->GetFunctor().GetIndex();
123  }
124 
125 #ifdef ITK_USE_CONCEPT_CHECKING
126  // Begin concept checking
127  itkConceptMacro( InputHasNumericTraitsCheck,
129  // End concept checking
130 #endif
131 
132 protected:
135 
137  {
138  const unsigned int index = this->GetIndex();
139  const TInputImage *image = this->GetInput();
140 
141  const unsigned int numberOfRunTimeComponents =
142  image->GetNumberOfComponentsPerPixel();
143 
144  typedef typename TInputImage::PixelType PixelType;
145 
146  typedef typename NumericTraits< PixelType >::RealType
147  PixelRealType;
148 
150  PixelScalarRealType;
151 
152  const unsigned int numberOfCompileTimeComponents =
153  sizeof( PixelRealType ) / sizeof( PixelScalarRealType );
154 
155  unsigned int numberOfComponents = numberOfRunTimeComponents;
156 
157  if ( numberOfCompileTimeComponents > numberOfRunTimeComponents )
158  {
159  numberOfComponents = numberOfCompileTimeComponents;
160  }
161 
162  if ( index >= numberOfComponents )
163  {
164  itkExceptionMacro(
165  << "Selected index = " << index
166  << " is greater than the number of components = "
167  << numberOfComponents);
168  }
169  }
170 
171 private:
172  VectorIndexSelectionCastImageFilter(const Self &); //purposely not implemented
173  void operator=(const Self &); //purposely not implemented
174 };
175 } // end namespace itk
176 
177 #endif
bool operator!=(const VectorIndexSelectionCast &other) const
Base class for all process objects that output image data.
const InputImageType * GetInput(void) const
bool operator==(const VectorIndexSelectionCast &other) const
virtual void Modified() const
Implements pixel-wise generic operation on one image.
Extracts the selected index of the vector that is the input pixel type.
Define additional traits for native types such as int or float.
#define itkConceptMacro(name, concept)
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::VectorIndexSelectionCast< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass