ITK  4.6.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  typename TInputImage,
55  typename TOutput,
56  typename TCoordRep = float
57  >
59  public FunctionBase< Point< TCoordRep, TInputImage::ImageDimension >, TOutput >
60 {
61 public:
63  itkStaticConstMacro(ImageDimension, unsigned int,
64  TInputImage::ImageDimension);
65 
68 
69  typedef FunctionBase<
70  Point< TCoordRep,
71  itkGetStaticConstMacro(ImageDimension) >,
72  TOutput > Superclass;
73 
76 
78  itkTypeMacro(ImageFunction, FunctionBase);
79 
81  typedef TInputImage InputImageType;
82 
84  typedef typename InputImageType::PixelType InputPixelType;
85 
87  typedef typename InputImageType::ConstPointer InputImageConstPointer;
88 
90  typedef TOutput OutputType;
91 
93  typedef TCoordRep CoordRepType;
94 
96  typedef typename InputImageType::IndexType IndexType;
98 
100  typedef ContinuousIndex< TCoordRep,
101  itkGetStaticConstMacro(ImageDimension) > ContinuousIndexType;
102 
105 
110  virtual void SetInputImage(const InputImageType *ptr);
111 
114  { return m_Image.GetPointer(); }
115 
118  virtual TOutput Evaluate(const PointType & point) const = 0;
119 
122  virtual TOutput EvaluateAtIndex(const IndexType & index) const = 0;
123 
126  virtual TOutput EvaluateAtContinuousIndex(
127  const ContinuousIndexType & index) const = 0;
128 
135  virtual bool IsInsideBuffer(const IndexType & index) const
136  {
137  for ( unsigned int j = 0; j < ImageDimension; j++ )
138  {
139  if ( index[j] < m_StartIndex[j] )
140  {
141  return false;
142  }
143  if ( index[j] > m_EndIndex[j] )
144  {
145  return false;
146  }
147  }
148  return true;
149  }
151 
155  virtual bool IsInsideBuffer(const ContinuousIndexType & index) const
156  {
157  for ( unsigned int j = 0; j < ImageDimension; j++ )
158  {
159  /* Test for negative of a positive so we can catch NaN's. */
160  if ( ! (index[j] >= m_StartContinuousIndex[j] &&
161  index[j] < m_EndContinuousIndex[j] ) )
162  {
163  return false;
164  }
165  }
166  return true;
167  }
169 
173  virtual bool IsInsideBuffer(const PointType & point) const
174  {
175  ContinuousIndexType index;
176  m_Image->TransformPhysicalPointToContinuousIndex(point, index);
177  /* Call IsInsideBuffer to test against BufferedRegion bounds.
178  * TransformPhysicalPointToContinuousIndex tests against
179  * LargestPossibleRegion */
180  bool isInside = IsInsideBuffer( index );
181  return isInside;
182  }
184 
187  IndexType & index) const
188  {
189  ContinuousIndexType cindex;
190 
191  m_Image->TransformPhysicalPointToContinuousIndex(point, cindex);
192  this->ConvertContinuousIndexToNearestIndex(cindex, index);
193  }
194 
197  ContinuousIndexType & cindex) const
198  {
199  m_Image->TransformPhysicalPointToContinuousIndex(point, cindex);
200  }
201 
204  const ContinuousIndexType & cindex,
205  IndexType & index) const
206  {
207  index.CopyWithRound(cindex);
208  }
209 
210  itkGetConstReferenceMacro(StartIndex, IndexType);
211  itkGetConstReferenceMacro(EndIndex, IndexType);
212 
213  itkGetConstReferenceMacro(StartContinuousIndex, ContinuousIndexType);
214  itkGetConstReferenceMacro(EndContinuousIndex, ContinuousIndexType);
215 
216 protected:
217  ImageFunction();
219  void PrintSelf(std::ostream & os, Indent indent) const;
220 
223 
227 
230 
231 private:
232  ImageFunction(const Self &); //purposely not implemented
233  void operator=(const Self &); //purposely not implemented
234 };
235 } // end namespace itk
236 
237 #ifndef ITK_MANUAL_INSTANTIATION
238 #include "itkImageFunction.hxx"
239 #endif
240 
241 #endif
void ConvertPointToContinuousIndex(const PointType &point, ContinuousIndexType &cindex) const
InputImageType::ConstPointer InputImageConstPointer
Light weight base class for most itk classes.
Point< TCoordRep, itkGetStaticConstMacro(ImageDimension) > PointType
virtual TOutput Evaluate(const PointType &point) const =0
ContinuousIndexType m_EndContinuousIndex
virtual bool IsInsideBuffer(const IndexType &index) const
signed long IndexValueType
Definition: itkIntTypes.h:150
void ConvertPointToNearestIndex(const PointType &point, IndexType &index) const
virtual TOutput EvaluateAtContinuousIndex(const ContinuousIndexType &index) const =0
ContinuousIndexType m_StartContinuousIndex
virtual void SetInputImage(const InputImageType *ptr)
static const unsigned int ImageDimension
const InputImageType * GetInputImage() const
Base class for all ITK function objects.
InputImageType::PixelType InputPixelType
SmartPointer< const Self > ConstPointer
InputImageType::IndexType IndexType
TInputImage InputImageType
ImageFunction Self
FunctionBase< Point< TCoordRep, itkGetStaticConstMacro(ImageDimension) >, TOutput > Superclass
ContinuousIndex< TCoordRep, itkGetStaticConstMacro(ImageDimension) > ContinuousIndexType
virtual bool IsInsideBuffer(const PointType &point) const
virtual bool IsInsideBuffer(const ContinuousIndexType &index) const
void PrintSelf(std::ostream &os, Indent indent) const
A templated class holding a point in n-Dimensional image space.
void operator=(const Self &)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
InputImageConstPointer m_Image
void ConvertContinuousIndexToNearestIndex(const ContinuousIndexType &cindex, IndexType &index) const
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:51
Evaluates a function of an image at specified position.
InputImageType::IndexValueType IndexValueType
virtual TOutput EvaluateAtIndex(const IndexType &index) const =0
SmartPointer< Self > Pointer