ITK  5.0.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  >
58 class ITK_TEMPLATE_EXPORT ImageFunction:
59  public FunctionBase< Point< TCoordRep, TInputImage::ImageDimension >, TOutput >
60 {
61 public:
62  ITK_DISALLOW_COPY_AND_ASSIGN(ImageFunction);
63 
65  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
66 
69 
70  using Superclass = FunctionBase<
71  Point< TCoordRep,
72  Self::ImageDimension >,
73  TOutput >;
74 
77 
79  itkTypeMacro(ImageFunction, FunctionBase);
80 
82  using InputImageType = TInputImage;
83 
85  using InputPixelType = typename InputImageType::PixelType;
86 
88  using InputImageConstPointer = typename InputImageType::ConstPointer;
89 
91  using OutputType = TOutput;
92 
94  using CoordRepType = TCoordRep;
95 
99 
101  using ContinuousIndexType = ContinuousIndex< TCoordRep,
102  Self::ImageDimension >;
103 
106 
111  virtual void SetInputImage(const InputImageType *ptr);
112 
115  { return m_Image.GetPointer(); }
116 
119  TOutput Evaluate(const PointType & point) const override = 0;
120 
123  virtual TOutput EvaluateAtIndex(const IndexType & index) const = 0;
124 
127  virtual TOutput EvaluateAtContinuousIndex(
128  const ContinuousIndexType & index) const = 0;
129 
136  virtual bool IsInsideBuffer(const IndexType & index) const
137  {
138  for ( unsigned int j = 0; j < ImageDimension; j++ )
139  {
140  if ( index[j] < m_StartIndex[j] )
141  {
142  return false;
143  }
144  if ( index[j] > m_EndIndex[j] )
145  {
146  return false;
147  }
148  }
149  return true;
150  }
152 
156  virtual bool IsInsideBuffer(const ContinuousIndexType & index) const
157  {
158  for ( unsigned int j = 0; j < ImageDimension; j++ )
159  {
160  /* Test for negative of a positive so we can catch NaN's. */
161  if ( ! (index[j] >= m_StartContinuousIndex[j] &&
162  index[j] < m_EndContinuousIndex[j] ) )
163  {
164  return false;
165  }
166  }
167  return true;
168  }
170 
174  virtual bool IsInsideBuffer(const PointType & point) const
175  {
176  ContinuousIndexType index;
177  m_Image->TransformPhysicalPointToContinuousIndex(point, index);
178  /* Call IsInsideBuffer to test against BufferedRegion bounds.
179  * TransformPhysicalPointToContinuousIndex tests against
180  * LargestPossibleRegion */
181  bool isInside = IsInsideBuffer( index );
182  return isInside;
183  }
185 
188  IndexType & index) const
189  {
190  ContinuousIndexType cindex;
191 
192  m_Image->TransformPhysicalPointToContinuousIndex(point, cindex);
193  this->ConvertContinuousIndexToNearestIndex(cindex, index);
194  }
195 
198  ContinuousIndexType & cindex) const
199  {
200  m_Image->TransformPhysicalPointToContinuousIndex(point, cindex);
201  }
202 
205  const ContinuousIndexType & cindex,
206  IndexType & index) const
207  {
208  index.CopyWithRound(cindex);
209  }
210 
211  itkGetConstReferenceMacro(StartIndex, IndexType);
212  itkGetConstReferenceMacro(EndIndex, IndexType);
213 
214  itkGetConstReferenceMacro(StartContinuousIndex, ContinuousIndexType);
215  itkGetConstReferenceMacro(EndContinuousIndex, ContinuousIndexType);
216 
217 protected:
218  ImageFunction();
219  ~ImageFunction() override = default;
220  void PrintSelf(std::ostream & os, Indent indent) const override;
221 
224 
228 
231 };
232 } // end namespace itk
233 
234 #ifndef ITK_MANUAL_INSTANTIATION
235 #include "itkImageFunction.hxx"
236 #endif
237 
238 #endif
void ConvertPointToContinuousIndex(const PointType &point, ContinuousIndexType &cindex) const
Light weight base class for most itk classes.
ContinuousIndexType m_EndContinuousIndex
typename InputImageType::ConstPointer InputImageConstPointer
virtual bool IsInsideBuffer(const IndexType &index) const
void ConvertPointToNearestIndex(const PointType &point, IndexType &index) const
ContinuousIndexType m_StartContinuousIndex
typename InputImageType::PixelType InputPixelType
const InputImageType * GetInputImage() const
Base class for all ITK function objects.
signed long IndexValueType
Definition: itkIntTypes.h:90
virtual bool IsInsideBuffer(const PointType &point) const
virtual bool IsInsideBuffer(const ContinuousIndexType &index) const
typename InputImageType::IndexType IndexType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename InputImageType::IndexValueType IndexValueType
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:52
Evaluates a function of an image at specified position.