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
25namespace itk
26{
54template <typename TInputImage, typename TOutput, typename TCoordinate = float>
55class ITK_TEMPLATE_EXPORT ImageFunction : public FunctionBase<Point<TCoordinate, TInputImage::ImageDimension>, TOutput>
56{
57public:
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
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
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
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
218protected:
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
A templated class holding a point in n-Dimensional image space.
Base class for all ITK function objects.
Evaluates a function of an image at specified position.
void ConvertPointToContinuousIndex(const PointType &point, ContinuousIndexType &cindex) const
TCoordinate CoordinateType
void PrintSelf(std::ostream &os, Indent indent) const override
virtual void SetInputImage(const InputImageType *ptr)
~ImageFunction() override=default
virtual TOutput EvaluateAtContinuousIndex(const ContinuousIndexType &index) const =0
virtual bool IsInsideBuffer(const ContinuousIndexType &index) const
typename InputImageType::PixelType InputPixelType
virtual TOutput EvaluateAtIndex(const IndexType &index) const =0
void ConvertPointToNearestIndex(const PointType &point, IndexType &index) const
typename InputImageType::ConstPointer InputImageConstPointer
typename InputImageType::IndexValueType IndexValueType
OutputType Evaluate(const PointType &point) const override=0
const InputImageType * GetInputImage() const
virtual bool IsInsideBuffer(const PointType &point) const
typename InputImageType::IndexType IndexType
void ConvertContinuousIndexToNearestIndex(const ContinuousIndexType &cindex, IndexType &index) const
TInputImage InputImageType
virtual bool IsInsideBuffer(const IndexType &index) const
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:54
SmartPointer< const Self > ConstPointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
*par Constraints *The filter 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
long IndexValueType
Definition: itkIntTypes.h:93