VTK
vtkAbstractImageInterpolator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkAbstractImageInterpolator.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
29 #ifndef __vtkAbstractImageInterpolator_h
30 #define __vtkAbstractImageInterpolator_h
31 
32 #include "vtkObject.h"
33 
34 #define VTK_IMAGE_BORDER_CLAMP 0
35 #define VTK_IMAGE_BORDER_REPEAT 1
36 #define VTK_IMAGE_BORDER_MIRROR 2
37 
38 class vtkDataObject;
39 class vtkImageData;
40 class vtkDataArray;
43 
45 {
46 public:
48  virtual void PrintSelf(ostream& os, vtkIndent indent);
49 
52  virtual void Initialize(vtkDataObject *data);
53 
55  virtual void ReleaseData();
56 
59  void DeepCopy(vtkAbstractImageInterpolator *obj);
60 
64  void Update();
65 
71  double Interpolate(double x, double y, double z, int component);
72 
78  bool Interpolate(const double point[3], double *value);
79 
81 
82  void SetOutValue(double outValue);
83  double GetOutValue() { return this->OutValue; }
85 
87 
90  void SetTolerance(double tol);
91  double GetTolerance() { return this->Tolerance; }
93 
95 
99  void SetComponentOffset(int offset);
100  int GetComponentOffset() { return this->ComponentOffset; }
102 
104 
108  void SetComponentCount(int count);
109  int GetComponentCount() { return this->ComponentCount; }
111 
114  int ComputeNumberOfComponents(int inputComponents);
115 
119  int GetNumberOfComponents();
120 
122 
125  void InterpolateIJK(const double point[3], double *value);
126  void InterpolateIJK(const float point[3], float *value);
128 
130 
134  bool CheckBoundsIJK(const double x[3]);
135  bool CheckBoundsIJK(const float x[3]);
137 
139 
144  void SetBorderMode(int mode);
146  this->SetBorderMode(VTK_IMAGE_BORDER_CLAMP); }
148  this->SetBorderMode(VTK_IMAGE_BORDER_REPEAT); }
150  this->SetBorderMode(VTK_IMAGE_BORDER_MIRROR); }
151  int GetBorderMode() { return this->BorderMode; }
152  const char *GetBorderModeAsString();
154 
160  virtual void ComputeSupportSize(const double matrix[16], int support[3]) = 0;
161 
166  virtual bool IsSeparable() = 0;
167 
169 
177  virtual void PrecomputeWeightsForExtent(
178  const double matrix[16], const int extent[6], int checkExtent[6],
179  vtkInterpolationWeights *&weights);
180  virtual void PrecomputeWeightsForExtent(
181  const float matrix[16], const int extent[6], int checkExtent[6],
182  vtkInterpolationWeights *&weights);
184 
186  virtual void FreePrecomputedWeights(vtkInterpolationWeights *&weights);
187 
189 
193  void InterpolateRow(
194  vtkInterpolationWeights *&weights, int xIdx, int yIdx, int zIdx,
195  double *value, int n);
196  void InterpolateRow(
197  vtkInterpolationWeights *&weights, int xIdx, int yIdx, int zIdx,
198  float *value, int n);
200 
202 
203  vtkGetVector3Macro(Spacing, double);
205 
207 
208  vtkGetVector3Macro(Origin, double);
210 
212 
213  vtkGetVector6Macro(Extent, int);
215 
217 
219  vtkGetVector6Macro(WholeExtent, int);
221 
222 protected:
225 
227  virtual void InternalUpdate() = 0;
228 
230  virtual void InternalDeepCopy(vtkAbstractImageInterpolator *obj) = 0;
231 
233 
234  virtual void GetInterpolationFunc(
235  void (**doublefunc)(
236  vtkInterpolationInfo *, const double [3], double *));
237  virtual void GetInterpolationFunc(
238  void (**floatfunc)(
239  vtkInterpolationInfo *, const float [3], float *));
241 
243 
244  virtual void GetRowInterpolationFunc(
245  void (**doublefunc)(
246  vtkInterpolationWeights *, int, int, int, double *, int));
247  virtual void GetRowInterpolationFunc(
248  void (**floatfunc)(
249  vtkInterpolationWeights *, int, int, int, float *, int));
251 
253  double StructuredBoundsDouble[6];
254  float StructuredBoundsFloat[6];
255  int WholeExtent[6];
256  int Extent[6];
257  double Spacing[3];
258  double Origin[3];
259  double OutValue;
260  double Tolerance;
264 
265  // information needed by the interpolator funcs
267 
268  void (*InterpolationFuncDouble)(
269  vtkInterpolationInfo *info, const double point[3], double *outPtr);
270  void (*InterpolationFuncFloat)(
271  vtkInterpolationInfo *info, const float point[3], float *outPtr);
272 
273  void (*RowInterpolationFuncDouble)(
274  vtkInterpolationWeights *weights, int idX, int idY, int idZ,
275  double *outPtr, int n);
276  void (*RowInterpolationFuncFloat)(
277  vtkInterpolationWeights *weights, int idX, int idY, int idZ,
278  float *outPtr, int n);
279 
280 private:
281 
283  void operator=(const vtkAbstractImageInterpolator&); // Not implemented.
284 };
285 
287  const double point[3], double *value)
288 {
289  this->InterpolationFuncDouble(this->InterpolationInfo, point, value);
290 }
291 
293  const float point[3], float *value)
294 {
295  this->InterpolationFuncFloat(this->InterpolationInfo, point, value);
296 }
297 
298 inline bool vtkAbstractImageInterpolator::CheckBoundsIJK(const double x[3])
299 {
300  double *bounds = this->StructuredBoundsDouble;
301  return !((x[0] < bounds[0]) | (x[0] > bounds[1]) |
302  (x[1] < bounds[2]) | (x[1] > bounds[3]) |
303  (x[2] < bounds[4]) | (x[2] > bounds[5]));
304 }
305 
306 inline bool vtkAbstractImageInterpolator::CheckBoundsIJK(const float x[3])
307 {
308  float *bounds = this->StructuredBoundsFloat;
309  return !((x[0] < bounds[0]) | (x[0] > bounds[1]) |
310  (x[1] < bounds[2]) | (x[1] > bounds[3]) |
311  (x[2] < bounds[4]) | (x[2] > bounds[5]));
312 }
313 
315  vtkInterpolationWeights *&weights, int xIdx, int yIdx, int zIdx,
316  double *value, int n)
317 {
318  this->RowInterpolationFuncDouble(weights, xIdx, yIdx, zIdx, value, n);
319 }
320 
322  vtkInterpolationWeights *&weights, int xIdx, int yIdx, int zIdx,
323  float *value, int n)
324 {
325  this->RowInterpolationFuncFloat(weights, xIdx, yIdx, zIdx, value, n);
326 }
327 
328 #endif