VTK  9.7.1
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 
35 VTK_ABI_NAMESPACE_BEGIN
36 class vtkDataObject;
37 class vtkImageData;
38 class vtkDataArray;
41 
42 class VTKIMAGINGCORE_EXPORT VTK_MARSHALAUTO vtkAbstractImageInterpolator : public vtkObject
43 {
44 public:
46  void PrintSelf(ostream& os, vtkIndent indent) override;
47 
51  virtual void Initialize(vtkDataObject* data);
52 
56  virtual void ReleaseData();
57 
62  void DeepCopy(vtkAbstractImageInterpolator* obj);
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 
132  int GetNumberOfComponents();
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 
163  void SetBorderMode(vtkImageBorderMode mode);
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; }
168  const char* GetBorderModeAsString();
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 
219  virtual void FreePrecomputedWeights(vtkInterpolationWeights*& weights);
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 
262 protected:
264  ~vtkAbstractImageInterpolator() override;
265 
269  virtual void InternalUpdate() = 0;
270 
274  virtual void InternalDeepCopy(vtkAbstractImageInterpolator* obj) = 0;
275 
279  void CoordinateToIJK(const double point[3], double ijk[3]);
280 
282 
285  virtual void GetInterpolationFunc(
286  void (**doublefunc)(VTK_FUTURE_CONST vtkInterpolationInfo*, const double[3], double*));
287  virtual void GetInterpolationFunc(
288  void (**floatfunc)(VTK_FUTURE_CONST vtkInterpolationInfo*, const float[3], float*));
290 
292 
295  virtual void GetRowInterpolationFunc(
296  void (**doublefunc)(vtkInterpolationWeights*, int, int, int, double*, int));
297  virtual void GetRowInterpolationFunc(
298  void (**floatfunc)(vtkInterpolationWeights*, int, int, int, float*, int));
300 
302 
305  virtual void GetSlidingWindowFunc(
306  void (**doublefunc)(vtkInterpolationWeights*, int, int, int, double*, int));
307  virtual void GetSlidingWindowFunc(
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  VTK_FUTURE_CONST vtkInterpolationInfo* info, const double point[3], double* outPtr);
332  void (*InterpolationFuncFloat)(
333  VTK_FUTURE_CONST vtkInterpolationInfo* info, const float point[3], float* outPtr);
334 
335  void (*RowInterpolationFuncDouble)(
336  vtkInterpolationWeights* weights, int idX, int idY, int idZ, double* outPtr, int n);
337  void (*RowInterpolationFuncFloat)(
338  vtkInterpolationWeights* weights, int idX, int idY, int idZ, float* outPtr, int n);
339 
340 private:
342  void operator=(const vtkAbstractImageInterpolator&) = delete;
343 };
344 
345 inline void vtkAbstractImageInterpolator::InterpolateIJK(const double point[3], double* value)
346 {
347  this->InterpolationFuncDouble(this->InterpolationInfo, point, value);
348 }
349 
350 inline void vtkAbstractImageInterpolator::InterpolateIJK(const float point[3], float* value)
351 {
352  this->InterpolationFuncFloat(this->InterpolationInfo, point, value);
353 }
354 
355 inline bool vtkAbstractImageInterpolator::CheckBoundsIJK(const double x[3])
356 {
357  const double* bounds = this->StructuredBoundsDouble;
358  return !((x[0] < bounds[0]) || (x[0] > bounds[1]) || (x[1] < bounds[2]) || (x[1] > bounds[3]) ||
359  (x[2] < bounds[4]) || (x[2] > bounds[5]));
360 }
361 
362 inline bool vtkAbstractImageInterpolator::CheckBoundsIJK(const float x[3])
363 {
364  const float* bounds = this->StructuredBoundsFloat;
365  return !((x[0] < bounds[0]) || (x[0] > bounds[1]) || (x[1] < bounds[2]) || (x[1] > bounds[3]) ||
366  (x[2] < bounds[4]) || (x[2] > bounds[5]));
367 }
368 
370  vtkInterpolationWeights*& weights, int xIdx, int yIdx, int zIdx, double* value, int n)
371 {
372  this->RowInterpolationFuncDouble(weights, xIdx, yIdx, zIdx, value, n);
373 }
374 
376  vtkInterpolationWeights*& weights, int xIdx, int yIdx, int zIdx, float* value, int n)
377 {
378  this->RowInterpolationFuncFloat(weights, xIdx, yIdx, zIdx, value, n);
379 }
380 
381 // The interpolator info struct
383 {
384  const void* Pointer;
385  int Extent[6];
391  void* ExtraInfo;
392 
395 };
396 
397 // The interpolation weights struct
399 {
401  void* Weights[3];
402  int WeightExtent[6];
403  int KernelSize[3];
404  int WeightType; // VTK_FLOAT or VTK_DOUBLE
405  void* Workspace;
406  int LastY;
407  int LastZ;
408 
409  // partial copy constructor from superclass
411  : vtkInterpolationInfo(info)
412  , Workspace(nullptr)
413  {
414  }
415 };
416 
417 VTK_ABI_NAMESPACE_END
418 #endif
interpolate data values from images
void(* InterpolationFuncDouble)(VTK_FUTURE_CONST vtkInterpolationInfo *info, const double point[3], double *outPtr)
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetBorderModeToRepeat()
The border mode (default: clamp).
int vtkIdType
Definition: vtkType.h:363
void InterpolateIJK(const double point[3], double *value)
A version of Interpolate that takes structured coords instead of data coords.
a simple class to control print indentation
Definition: vtkIndent.h:28
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
vtkImageBorderMode GetBorderMode()
The border mode (default: clamp).
void(* RowInterpolationFuncDouble)(vtkInterpolationWeights *weights, int idX, int idY, int idZ, double *outPtr, int n)
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...
void(* InterpolationFuncFloat)(VTK_FUTURE_CONST vtkInterpolationInfo *info, const float point[3], float *outPtr)
#define VTK_MARSHALAUTO
void(* RowInterpolationFuncFloat)(vtkInterpolationWeights *weights, int idX, int idY, int idZ, float *outPtr, int n)
general representation of visualization data
Definition: vtkDataObject.h:55
vtkInterpolationWeights(const vtkInterpolationInfo &info)
void SetBorderModeToClamp()
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 SetBorderModeToMirror()
The border mode (default: clamp).