VTK  9.5.20250605
vtkAbstractImageInterpolator.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
21#ifndef vtkAbstractImageInterpolator_h
22#define vtkAbstractImageInterpolator_h
23
24#include "vtkImagingCoreModule.h" // For export macro
25#include "vtkObject.h"
26#include "vtkWrappingHints.h"
27
29{
33};
34
35VTK_ABI_NAMESPACE_BEGIN
36class vtkDataObject;
37class vtkImageData;
38class vtkDataArray;
41
42class VTKIMAGINGCORE_EXPORT VTK_MARSHALAUTO vtkAbstractImageInterpolator : public vtkObject
43{
44public:
46 void PrintSelf(ostream& os, vtkIndent indent) override;
47
51 virtual void Initialize(vtkDataObject* data);
52
56 virtual void ReleaseData();
57
63
69 virtual void Update();
70
78 double Interpolate(double x, double y, double z, int component);
79
87 bool Interpolate(const double point[3], double* value);
88
92 void SetOutValue(double outValue);
93 double GetOutValue() { return this->OutValue; }
94
100 void SetTolerance(double tol);
101 double GetTolerance() { return this->Tolerance; }
102
109 void SetComponentOffset(int offset);
110 int GetComponentOffset() { return this->ComponentOffset; }
111
118 void SetComponentCount(int count);
119 int GetComponentCount() { return this->ComponentCount; }
120
125 int ComputeNumberOfComponents(int inputComponents);
126
133
135
140 void InterpolateIJK(const double point[3], double* value);
141 void InterpolateIJK(const float point[3], float* value);
143
145
151 bool CheckBoundsIJK(const double x[3]);
152 bool CheckBoundsIJK(const float x[3]);
154
156
164 void SetBorderModeToClamp() { this->SetBorderMode(VTK_IMAGE_BORDER_CLAMP); }
165 void SetBorderModeToRepeat() { this->SetBorderMode(VTK_IMAGE_BORDER_REPEAT); }
166 void SetBorderModeToMirror() { this->SetBorderMode(VTK_IMAGE_BORDER_MIRROR); }
167 vtkImageBorderMode GetBorderMode() { return this->BorderMode; }
170
178 void SetSlidingWindow(bool x);
179 void SlidingWindowOn() { this->SetSlidingWindow(true); }
180 void SlidingWindowOff() { this->SetSlidingWindow(false); }
181 bool GetSlidingWindow() { return this->SlidingWindow; }
182
189 virtual void ComputeSupportSize(const double matrix[16], int support[3]) = 0;
190
197 virtual bool IsSeparable() = 0;
198
200
210 virtual void PrecomputeWeightsForExtent(const double matrix[16], const int extent[6],
211 int checkExtent[6], vtkInterpolationWeights*& weights);
212 virtual void PrecomputeWeightsForExtent(const float matrix[16], const int extent[6],
213 int checkExtent[6], vtkInterpolationWeights*& weights);
215
220
222
228 void InterpolateRow(
229 vtkInterpolationWeights*& weights, int xIdx, int yIdx, int zIdx, double* value, int n);
230 void InterpolateRow(
231 vtkInterpolationWeights*& weights, int xIdx, int yIdx, int zIdx, float* value, int n);
233
235
238 vtkGetVector3Macro(Spacing, double);
240
242
245 vtkGetVectorMacro(Direction, double, 9);
247
249
252 vtkGetVector3Macro(Origin, double);
254
256
259 vtkGetVector6Macro(Extent, int);
261
262protected:
265
269 virtual void InternalUpdate() = 0;
270
275
279 void CoordinateToIJK(const double point[3], double ijk[3]);
280
282
286 void (**doublefunc)(vtkInterpolationInfo*, const double[3], double*));
288 void (**floatfunc)(vtkInterpolationInfo*, const float[3], float*));
290
292
296 void (**doublefunc)(vtkInterpolationWeights*, int, int, int, double*, int));
298 void (**floatfunc)(vtkInterpolationWeights*, int, int, int, float*, int));
300
302
306 void (**doublefunc)(vtkInterpolationWeights*, int, int, int, double*, int));
308 void (**floatfunc)(vtkInterpolationWeights*, int, int, int, float*, int));
310
312 double StructuredBoundsDouble[6];
313 float StructuredBoundsFloat[6];
314 int Extent[6];
315 double Spacing[3];
316 double Direction[9];
317 double InverseDirection[9];
318 double Origin[3];
319 double OutValue;
320 double Tolerance;
326
327 // information needed by the interpolator funcs
329
330 void (*InterpolationFuncDouble)(
331 vtkInterpolationInfo* info, const double point[3], double* outPtr);
332 void (*InterpolationFuncFloat)(vtkInterpolationInfo* info, const float point[3], float* outPtr);
333
334 void (*RowInterpolationFuncDouble)(
335 vtkInterpolationWeights* weights, int idX, int idY, int idZ, double* outPtr, int n);
336 void (*RowInterpolationFuncFloat)(
337 vtkInterpolationWeights* weights, int idX, int idY, int idZ, float* outPtr, int n);
338
339private:
341 void operator=(const vtkAbstractImageInterpolator&) = delete;
342};
343
344inline void vtkAbstractImageInterpolator::InterpolateIJK(const double point[3], double* value)
345{
346 this->InterpolationFuncDouble(this->InterpolationInfo, point, value);
347}
348
349inline void vtkAbstractImageInterpolator::InterpolateIJK(const float point[3], float* value)
350{
351 this->InterpolationFuncFloat(this->InterpolationInfo, point, value);
352}
353
355{
356 const double* bounds = this->StructuredBoundsDouble;
357 return !((x[0] < bounds[0]) || (x[0] > bounds[1]) || (x[1] < bounds[2]) || (x[1] > bounds[3]) ||
358 (x[2] < bounds[4]) || (x[2] > bounds[5]));
359}
360
362{
363 const float* bounds = this->StructuredBoundsFloat;
364 return !((x[0] < bounds[0]) || (x[0] > bounds[1]) || (x[1] < bounds[2]) || (x[1] > bounds[3]) ||
365 (x[2] < bounds[4]) || (x[2] > bounds[5]));
366}
367
369 vtkInterpolationWeights*& weights, int xIdx, int yIdx, int zIdx, double* value, int n)
370{
371 this->RowInterpolationFuncDouble(weights, xIdx, yIdx, zIdx, value, n);
372}
373
375 vtkInterpolationWeights*& weights, int xIdx, int yIdx, int zIdx, float* value, int n)
376{
377 this->RowInterpolationFuncFloat(weights, xIdx, yIdx, zIdx, value, n);
378}
379
380VTK_ABI_NAMESPACE_END
381#endif
interpolate data values from images
virtual void Update()
Update the interpolator.
void SetBorderMode(vtkImageBorderMode mode)
The border mode (default: clamp).
virtual void PrecomputeWeightsForExtent(const float matrix[16], const int extent[6], int checkExtent[6], vtkInterpolationWeights *&weights)
If the data is going to be sampled on a regular grid, then the interpolation weights can be precomput...
void(* InterpolationFuncDouble)(vtkInterpolationInfo *info, const double point[3], double *outPtr)
virtual void ComputeSupportSize(const double matrix[16], int support[3])=0
Get the support size for use in computing update extents.
virtual bool IsSeparable()=0
True if the interpolation is separable, which means that the weights can be precomputed in order to a...
void SetBorderModeToClamp()
The border mode (default: clamp).
~vtkAbstractImageInterpolator() override
int ComputeNumberOfComponents(int inputComponents)
Compute the number of output components based on the ComponentOffset, ComponentCount,...
void SetComponentCount(int count)
This method specifies the number of components to extract.
virtual void GetRowInterpolationFunc(void(**floatfunc)(vtkInterpolationWeights *, int, int, int, float *, int))
Get the row interpolation functions.
virtual void GetSlidingWindowFunc(void(**doublefunc)(vtkInterpolationWeights *, int, int, int, double *, int))
Get the sliding window interpolation functions.
void SetComponentOffset(int offset)
This method specifies which component of the input will be interpolated, or if ComponentCount is also...
virtual void ReleaseData()
Release any data stored by the interpolator.
void SetSlidingWindow(bool x)
Enable sliding window for separable kernels.
virtual void Initialize(vtkDataObject *data)
Initialize the interpolator with the data that you wish to interpolate.
bool CheckBoundsIJK(const double x[3])
Check an x,y,z point to see if it is within the bounds for the structured coords of the image.
virtual void PrecomputeWeightsForExtent(const double matrix[16], const int extent[6], int checkExtent[6], vtkInterpolationWeights *&weights)
If the data is going to be sampled on a regular grid, then the interpolation weights can be precomput...
void SetBorderModeToMirror()
The border mode (default: clamp).
double Interpolate(double x, double y, double z, int component)
Get the result of interpolating the specified component of the input data, which should be set to zer...
void CoordinateToIJK(const double point[3], double ijk[3])
Convert XYZ coordinate to IJK continuous index.
vtkImageBorderMode GetBorderMode()
The border mode (default: clamp).
void InterpolateRow(vtkInterpolationWeights *&weights, int xIdx, int yIdx, int zIdx, double *value, int n)
Get a row of samples, using the weights that were precomputed by PrecomputeWeightsForExtent.
void SetOutValue(double outValue)
The value to return when the point is out of bounds.
void(* RowInterpolationFuncDouble)(vtkInterpolationWeights *weights, int idX, int idY, int idZ, double *outPtr, int n)
void(* InterpolationFuncFloat)(vtkInterpolationInfo *info, const float point[3], float *outPtr)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void GetSlidingWindowFunc(void(**floatfunc)(vtkInterpolationWeights *, int, int, int, float *, int))
Get the sliding window interpolation functions.
int GetNumberOfComponents()
Get the number of components that will be returned when Interpolate() is called.
virtual void FreePrecomputedWeights(vtkInterpolationWeights *&weights)
Free the weights that were provided by PrecomputeWeightsForExtent.
void DeepCopy(vtkAbstractImageInterpolator *obj)
Copy the interpolator.
virtual void GetRowInterpolationFunc(void(**doublefunc)(vtkInterpolationWeights *, int, int, int, double *, int))
Get the row interpolation functions.
virtual void InternalDeepCopy(vtkAbstractImageInterpolator *obj)=0
Subclass-specific copy.
virtual void GetInterpolationFunc(void(**doublefunc)(vtkInterpolationInfo *, const double[3], double *))
Get the interpolation functions.
void SetBorderModeToRepeat()
The border mode (default: clamp).
void(* RowInterpolationFuncFloat)(vtkInterpolationWeights *weights, int idX, int idY, int idZ, float *outPtr, int n)
virtual void InternalUpdate()=0
Subclass-specific updates.
virtual void GetInterpolationFunc(void(**floatfunc)(vtkInterpolationInfo *, const float[3], float *))
Get the interpolation functions.
void InterpolateIJK(const double point[3], double *value)
A version of Interpolate that takes structured coords instead of data coords.
const char * GetBorderModeAsString()
The border mode (default: clamp).
bool Interpolate(const double point[3], double *value)
Sample the input data.
void SetTolerance(double tol)
The tolerance to apply when checking whether a point is out of bounds.
abstract superclass for arrays of numeric data
general representation of visualization data
topologically and geometrically regular array of data
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162
#define VTK_MARSHALAUTO