ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkImageFunction.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 __itkImageFunction_h
19 #define __itkImageFunction_h
20 
21 #include "itkFunctionBase.h"
22 #include "itkIndex.h"
23 #include "itkImageBase.h"
24 
25 namespace itk
26 {
53 template<
54  class TInputImage,
55  class TOutput,
56  class TCoordRep = float
57  >
58 class ITK_EXPORT ImageFunction:
59  public FunctionBase< Point< TCoordRep, TInputImage::ImageDimension >, TOutput >
60 {
61 public:
63  itkStaticConstMacro(ImageDimension, unsigned int,
64  TInputImage::ImageDimension);
65 
68  typedef FunctionBase<
70  TOutput > Superclass;
73 
75  itkTypeMacro(ImageFunction, FunctionBase);
76 
78  typedef TInputImage InputImageType;
79 
81  typedef typename InputImageType::PixelType InputPixelType;
82 
84  typedef typename InputImageType::ConstPointer InputImageConstPointer;
85 
87  typedef TOutput OutputType;
88 
90  typedef TCoordRep CoordRepType;
91 
93  typedef typename InputImageType::IndexType IndexType;
95 
99 
102 
107  virtual void SetInputImage(const InputImageType *ptr);
108 
110  const InputImageType * GetInputImage() const
111  { return m_Image.GetPointer(); }
112 
115  virtual TOutput Evaluate(const PointType & point) const = 0;
116 
119  virtual TOutput EvaluateAtIndex(const IndexType & index) const = 0;
120 
123  virtual TOutput EvaluateAtContinuousIndex(
124  const ContinuousIndexType & index) const = 0;
125 
132  virtual bool IsInsideBuffer(const IndexType & index) const
133  {
134  for ( unsigned int j = 0; j < ImageDimension; j++ )
135  {
136  if ( index[j] < m_StartIndex[j] )
137  {
138  return false;
139  }
140  if ( index[j] > m_EndIndex[j] )
141  {
142  return false;
143  }
144  }
145  return true;
146  }
148 
152  virtual bool IsInsideBuffer(const ContinuousIndexType & index) const
153  {
154  for ( unsigned int j = 0; j < ImageDimension; j++ )
155  {
156  /* Test for negative of a positive so we can catch NaN's. */
157  if ( ! (index[j] >= m_StartContinuousIndex[j] &&
158  index[j] < m_EndContinuousIndex[j] ) )
159  {
160  return false;
161  }
162  }
163  return true;
164  }
166 
170  virtual bool IsInsideBuffer(const PointType & point) const
171  {
172  ContinuousIndexType index;
173  m_Image->TransformPhysicalPointToContinuousIndex(point, index);
174  /* Call IsInsideBuffer to test against BufferedRegion bounds.
175  * TransformPhysicalPointToContinuousIndex tests against
176  * LargestPossibleRegion */
177  bool isInside = IsInsideBuffer( index );
178  return isInside;
179  }
181 
183  void ConvertPointToNearestIndex(const PointType & point,
184  IndexType & index) const
185  {
186  ContinuousIndexType cindex;
187 
188  m_Image->TransformPhysicalPointToContinuousIndex(point, cindex);
189  this->ConvertContinuousIndexToNearestIndex(cindex, index);
190  }
191 
193  void ConvertPointToContinuousIndex(const PointType & point,
194  ContinuousIndexType & cindex) const
195  {
196  m_Image->TransformPhysicalPointToContinuousIndex(point, cindex);
197  }
198 
200  inline void ConvertContinuousIndexToNearestIndex(
201  const ContinuousIndexType & cindex,
202  IndexType & index) const
203  {
204  index.CopyWithRound(cindex);
205  }
206 
207  itkGetConstReferenceMacro(StartIndex, IndexType);
208  itkGetConstReferenceMacro(EndIndex, IndexType);
209 
210  itkGetConstReferenceMacro(StartContinuousIndex, ContinuousIndexType);
211  itkGetConstReferenceMacro(EndContinuousIndex, ContinuousIndexType);
212 
213 protected:
214  ImageFunction();
216  void PrintSelf(std::ostream & os, Indent indent) const;
217 
220 
224 
227 
228 private:
229  ImageFunction(const Self &); //purposely not implemented
230  void operator=(const Self &); //purposely not implemented
231 };
232 } // end namespace itk
233 
234 #ifndef ITK_MANUAL_INSTANTIATION
235 #include "itkImageFunction.hxx"
236 #endif
237 
238 #endif
239