ITK  6.0.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  * https://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 TCoordinate = float>
55 class ITK_TEMPLATE_EXPORT ImageFunction : public FunctionBase<Point<TCoordinate, 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  itkOverrideGetNameOfClassMacro(ImageFunction);
73 
75  using InputImageType = TInputImage;
76 
78  using InputPixelType = typename InputImageType::PixelType;
79 
82 
84  using OutputType = TOutput;
85 
87  using CoordinateType = TCoordinate;
88 #ifndef ITK_FUTURE_LEGACY_REMOVE
89  using CoordRepType ITK_FUTURE_DEPRECATED(
90  "ITK 6 discourages using `CoordRepType`. Please use `CoordinateType` instead!") = CoordinateType;
91 #endif
92 
96 
99 
102 
107  virtual void
108  SetInputImage(const InputImageType * ptr);
109 
111  const InputImageType *
113  {
114  return m_Image.GetPointer();
115  }
116 
119  OutputType
120  Evaluate(const PointType & point) const override = 0;
121 
124  virtual TOutput
125  EvaluateAtIndex(const IndexType & index) const = 0;
126 
129  virtual TOutput
130  EvaluateAtContinuousIndex(const ContinuousIndexType & index) const = 0;
131 
138  virtual bool
139  IsInsideBuffer(const IndexType & index) const
140  {
141  for (unsigned int j = 0; j < ImageDimension; ++j)
142  {
143  if (index[j] < m_StartIndex[j])
144  {
145  return false;
146  }
147  if (index[j] > m_EndIndex[j])
148  {
149  return false;
150  }
151  }
152  return true;
153  }
159  virtual bool
160  IsInsideBuffer(const ContinuousIndexType & index) const
161  {
162  for (unsigned int j = 0; j < ImageDimension; ++j)
163  {
164  /* Test for negative of a positive so we can catch NaN's. */
165  if (!(index[j] >= m_StartContinuousIndex[j] && index[j] < m_EndContinuousIndex[j]))
166  {
167  return false;
168  }
169  }
170  return true;
171  }
177  virtual bool
179  {
180  const ContinuousIndexType index = m_Image->template TransformPhysicalPointToContinuousIndex<TCoordinate>(point);
181  /* Call IsInsideBuffer to test against BufferedRegion bounds.
182  * TransformPhysicalPointToContinuousIndex tests against
183  * LargestPossibleRegion */
184  const bool isInside = IsInsideBuffer(index);
185  return isInside;
186  }
190  void
192  {
193  const ContinuousIndexType cindex = m_Image->template TransformPhysicalPointToContinuousIndex<TCoordinate>(point);
194  this->ConvertContinuousIndexToNearestIndex(cindex, index);
195  }
199  void
201  {
202  cindex = m_Image->template TransformPhysicalPointToContinuousIndex<TCoordinate>(point);
203  }
204 
206  inline void
208  {
209  index.CopyWithRound(cindex);
210  }
211 
212  itkGetConstReferenceMacro(StartIndex, IndexType);
213  itkGetConstReferenceMacro(EndIndex, IndexType);
214 
215  itkGetConstReferenceMacro(StartContinuousIndex, ContinuousIndexType);
216  itkGetConstReferenceMacro(EndContinuousIndex, ContinuousIndexType);
217 
218 protected:
219  ImageFunction();
220  ~ImageFunction() override = default;
221  void
222  PrintSelf(std::ostream & os, Indent indent) const override;
223 
226 
228  IndexType m_StartIndex{};
229  IndexType m_EndIndex{};
230 
231  ContinuousIndexType m_StartContinuousIndex{};
232  ContinuousIndexType m_EndContinuousIndex{};
233 };
234 } // end namespace itk
235 
236 #ifndef ITK_MANUAL_INSTANTIATION
237 # include "itkImageFunction.hxx"
238 #endif
239 
240 #endif
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::ImageFunction::ConvertContinuousIndexToNearestIndex
void ConvertContinuousIndexToNearestIndex(const ContinuousIndexType &cindex, IndexType &index) const
Definition: itkImageFunction.h:207
itk::ImageFunction::GetInputImage
const InputImageType * GetInputImage() const
Definition: itkImageFunction.h:112
itk::ImageFunction< TImageType, NumericTraits< TImageType ::PixelType >::RealType, TCoordinate >::InputImageType
TImageType InputImageType
Definition: itkImageFunction.h:75
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::FunctionBase< Point< TCoordinate, TImageType ::ImageDimension >, NumericTraits< TImageType ::PixelType >::RealType >::OutputType
NumericTraits< TImageType ::PixelType >::RealType OutputType
Definition: itkFunctionBase.h:62
itk::ImageFunction::IsInsideBuffer
virtual bool IsInsideBuffer(const IndexType &index) const
Definition: itkImageFunction.h:139
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:93
itk::ImageFunction< TImageType, NumericTraits< TImageType ::PixelType >::RealType, TCoordinate >::CoordinateType
TCoordinate CoordinateType
Definition: itkImageFunction.h:87
itk::ImageFunction< TImageType, NumericTraits< TImageType ::PixelType >::RealType, TCoordinate >::InputImageConstPointer
typename InputImageType::ConstPointer InputImageConstPointer
Definition: itkImageFunction.h:81
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageFunction::IsInsideBuffer
virtual bool IsInsideBuffer(const PointType &point) const
Definition: itkImageFunction.h:178
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:55
itk::point
*par Constraints *The filter requires an image with at least two dimensions and a vector *length of at least The theory supports extension to scalar but *the implementation of the itk vector classes do not **The template parameter TRealType must be floating point(float or double) or *a user-defined "real" numerical type with arithmetic operations defined *sufficient to compute derivatives. **\par Performance *This filter will automatically multithread if run with *SetUsePrincipleComponents
itk::ImageFunction< TImageType, NumericTraits< TImageType ::PixelType >::RealType, TCoordinate >::IndexValueType
typename InputImageType::IndexValueType IndexValueType
Definition: itkImageFunction.h:95
itk::ImageFunction::ConvertPointToContinuousIndex
void ConvertPointToContinuousIndex(const PointType &point, ContinuousIndexType &cindex) const
Definition: itkImageFunction.h:200
itk::ImageFunction< TImageType, NumericTraits< TImageType ::PixelType >::RealType, TCoordinate >::InputPixelType
typename InputImageType::PixelType InputPixelType
Definition: itkImageFunction.h:78
itkIndex.h
itk::ImageFunction::IsInsideBuffer
virtual bool IsInsideBuffer(const ContinuousIndexType &index) const
Definition: itkImageFunction.h:160
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: itkAnatomicalOrientation.h:29
itk::ContinuousIndex< TCoordinate, Self::ImageDimension >
itk::ImageFunction::ConvertPointToNearestIndex
void ConvertPointToNearestIndex(const PointType &point, IndexType &index) const
Definition: itkImageFunction.h:191
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:53
itk::ImageFunction< TImageType, NumericTraits< TImageType ::PixelType >::RealType, TCoordinate >::IndexType
typename InputImageType::IndexType IndexType
Definition: itkImageFunction.h:94
itkImageBase.h