ITK  5.4.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 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  itkOverrideGetNameOfClassMacro(ImageFunction);
73 
75  using InputImageType = TInputImage;
76 
78  using InputPixelType = typename InputImageType::PixelType;
79 
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  }
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  }
173  virtual bool
175  {
176  const ContinuousIndexType index = m_Image->template TransformPhysicalPointToContinuousIndex<TCoordRep>(point);
177  /* Call IsInsideBuffer to test against BufferedRegion bounds.
178  * TransformPhysicalPointToContinuousIndex tests against
179  * LargestPossibleRegion */
180  bool isInside = IsInsideBuffer(index);
181  return isInside;
182  }
186  void
188  {
189  const ContinuousIndexType cindex = m_Image->template TransformPhysicalPointToContinuousIndex<TCoordRep>(point);
190  this->ConvertContinuousIndexToNearestIndex(cindex, index);
191  }
195  void
197  {
198  cindex = m_Image->template TransformPhysicalPointToContinuousIndex<TCoordRep>(point);
199  }
200 
202  inline void
204  {
205  index.CopyWithRound(cindex);
206  }
207 
208  itkGetConstReferenceMacro(StartIndex, IndexType);
209  itkGetConstReferenceMacro(EndIndex, IndexType);
210 
211  itkGetConstReferenceMacro(StartContinuousIndex, ContinuousIndexType);
212  itkGetConstReferenceMacro(EndContinuousIndex, ContinuousIndexType);
213 
214 protected:
215  ImageFunction();
216  ~ImageFunction() override = default;
217  void
218  PrintSelf(std::ostream & os, Indent indent) const override;
219 
222 
224  IndexType m_StartIndex{};
225  IndexType m_EndIndex{};
226 
227  ContinuousIndexType m_StartContinuousIndex{};
228  ContinuousIndexType m_EndContinuousIndex{};
229 };
230 } // end namespace itk
231 
232 #ifndef ITK_MANUAL_INSTANTIATION
233 # include "itkImageFunction.hxx"
234 #endif
235 
236 #endif
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
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::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:187
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
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:203
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:90
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: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
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::ContinuousIndex< TOutput, Self::ImageDimension >
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:196
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