ITK  5.2.0
Insight Toolkit
itkImageFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 {
54 template <typename TInputImage, typename TOutput, typename TCoordRep = float>
55 class ITK_TEMPLATE_EXPORT ImageFunction : public FunctionBase<Point<TCoordRep, TInputImage::ImageDimension>, TOutput>
56 {
57 public:
58  ITK_DISALLOW_COPY_AND_MOVE(ImageFunction);
59 
61  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
62 
65 
67 
70 
72  itkTypeMacro(ImageFunction, FunctionBase);
73 
75  using InputImageType = TInputImage;
76 
78  using InputPixelType = typename InputImageType::PixelType;
79 
81  using InputImageConstPointer = typename InputImageType::ConstPointer;
82 
84  using OutputType = TOutput;
85 
87  using CoordRepType = TCoordRep;
88 
92 
95 
98 
103  virtual void
104  SetInputImage(const InputImageType * ptr);
105 
107  const InputImageType *
109  {
110  return m_Image.GetPointer();
111  }
112 
115  TOutput
116  Evaluate(const PointType & point) const override = 0;
117 
120  virtual TOutput
121  EvaluateAtIndex(const IndexType & index) const = 0;
122 
125  virtual TOutput
126  EvaluateAtContinuousIndex(const ContinuousIndexType & index) const = 0;
127 
134  virtual bool
135  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
156  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] && index[j] < m_EndContinuousIndex[j]))
162  {
163  return false;
164  }
165  }
166  return true;
167  }
169 
173  virtual bool
174  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 
187  void
188  ConvertPointToNearestIndex(const PointType & point, IndexType & index) const
189  {
190  ContinuousIndexType cindex;
191 
192  m_Image->TransformPhysicalPointToContinuousIndex(point, cindex);
193  this->ConvertContinuousIndexToNearestIndex(cindex, index);
194  }
195 
197  void
199  {
200  m_Image->TransformPhysicalPointToContinuousIndex(point, cindex);
201  }
202 
204  inline void
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();
218  ~ImageFunction() override = default;
219  void
220  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
itk::ImageFunction::m_EndContinuousIndex
ContinuousIndexType m_EndContinuousIndex
Definition: itkImageFunction.h:230
itk::ImageFunction< TInputImage, TOutput, TOutput >::InputImageType
TInputImage InputImageType
Definition: itkImageFunction.h:75
itk::ImageFunction< TInputImage, TOutput, TOutput >::InputPixelType
typename InputImageType::PixelType InputPixelType
Definition: itkImageFunction.h:78
itk::ImageFunction< TInputImage, TOutput, TOutput >::IndexType
typename InputImageType::IndexType IndexType
Definition: itkImageFunction.h:90
itk::ImageFunction< TInputImage, TOutput, TOutput >::InputImageConstPointer
typename InputImageType::ConstPointer InputImageConstPointer
Definition: itkImageFunction.h:81
itk::ImageFunction::IsInsideBuffer
virtual bool IsInsideBuffer(const IndexType &index) const
Definition: itkImageFunction.h:135
itk::ImageFunction::m_Image
InputImageConstPointer m_Image
Definition: itkImageFunction.h:223
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::ImageFunction< TInputImage, TOutput, TOutput >::CoordRepType
TOutput CoordRepType
Definition: itkImageFunction.h:87
itk::ImageFunction::ConvertPointToNearestIndex
void ConvertPointToNearestIndex(const PointType &point, IndexType &index) const
Definition: itkImageFunction.h:188
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ImageFunction::m_EndIndex
IndexType m_EndIndex
Definition: itkImageFunction.h:227
itk::FunctionBase< Point< TOutput, TInputImage::ImageDimension >, TOutput >::OutputType
TOutput OutputType
Definition: itkFunctionBase.h:62
itk::ImageFunction::ConvertContinuousIndexToNearestIndex
void ConvertContinuousIndexToNearestIndex(const ContinuousIndexType &cindex, IndexType &index) const
Definition: itkImageFunction.h:205
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itkFunctionBase.h
itk::ImageFunction
Evaluates a function of an image at specified position.
Definition: itkImageFunction.h:55
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::ImageFunction::m_StartIndex
IndexType m_StartIndex
Definition: itkImageFunction.h:226
itkIndex.h
itk::ImageFunction::IsInsideBuffer
virtual bool IsInsideBuffer(const PointType &point) const
Definition: itkImageFunction.h:174
itk::ImageFunction::IsInsideBuffer
virtual bool IsInsideBuffer(const ContinuousIndexType &index) const
Definition: itkImageFunction.h:156
itk::FunctionBase
Base class for all ITK function objects.
Definition: itkFunctionBase.h:44
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ImageFunction::m_StartContinuousIndex
ContinuousIndexType m_StartContinuousIndex
Definition: itkImageFunction.h:229
itk::ContinuousIndex< TOutput, Self::ImageDimension >
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:53
itk::ImageFunction::ConvertPointToContinuousIndex
void ConvertPointToContinuousIndex(const PointType &point, ContinuousIndexType &cindex) const
Definition: itkImageFunction.h:198
itk::ImageFunction::GetInputImage
const InputImageType * GetInputImage() const
Definition: itkImageFunction.h:108
itk::ImageFunction< TInputImage, TOutput, TOutput >::IndexValueType
typename InputImageType::IndexValueType IndexValueType
Definition: itkImageFunction.h:91
itkImageBase.h