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
25namespace itk
26{
54template <typename TInputImage, typename TOutput, typename TCoordRep = float>
55class ITK_TEMPLATE_EXPORT ImageFunction : public FunctionBase<Point<TCoordRep, 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 CoordRepType = TCoordRep;
88
92
95
98
103 virtual void
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
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
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
214protected:
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
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.
const InputImageType * GetInputImage() const
void ConvertContinuousIndexToNearestIndex(const ContinuousIndexType &cindex, IndexType &index) const
TInputImage InputImageType
virtual TOutput EvaluateAtContinuousIndex(const ContinuousIndexType &index) const =0
virtual bool IsInsideBuffer(const PointType &point) const
TOutput Evaluate(const PointType &point) const override=0
typename InputImageType::PixelType InputPixelType
virtual bool IsInsideBuffer(const ContinuousIndexType &index) const
virtual bool IsInsideBuffer(const IndexType &index) const
~ImageFunction() override=default
void ConvertPointToContinuousIndex(const PointType &point, ContinuousIndexType &cindex) const
void ConvertPointToNearestIndex(const PointType &point, IndexType &index) const
typename InputImageType::IndexValueType IndexValueType
virtual void SetInputImage(const InputImageType *ptr)
void PrintSelf(std::ostream &os, Indent indent) const override
virtual TOutput EvaluateAtIndex(const IndexType &index) const =0
typename InputImageType::ConstPointer InputImageConstPointer
typename InputImageType::IndexType IndexType
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:90