VTK
dox/Filtering/vtkAbstractImageInterpolator.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkAbstractImageInterpolator.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00029 #ifndef __vtkAbstractImageInterpolator_h
00030 #define __vtkAbstractImageInterpolator_h
00031 
00032 #include "vtkObject.h"
00033 
00034 #define VTK_IMAGE_BORDER_CLAMP 0
00035 #define VTK_IMAGE_BORDER_REPEAT 1
00036 #define VTK_IMAGE_BORDER_MIRROR 2
00037 
00038 class vtkDataObject;
00039 class vtkImageData;
00040 class vtkDataArray;
00041 struct vtkInterpolationInfo;
00042 struct vtkInterpolationWeights;
00043 
00044 class VTK_FILTERING_EXPORT vtkAbstractImageInterpolator : public vtkObject
00045 {
00046 public:
00047   vtkTypeMacro(vtkAbstractImageInterpolator, vtkObject);
00048   virtual void PrintSelf(ostream& os, vtkIndent indent);
00049 
00052   virtual void Initialize(vtkDataObject *data);
00053 
00055   virtual void ReleaseData();
00056 
00059   void DeepCopy(vtkAbstractImageInterpolator *obj);
00060 
00064   void Update();
00065 
00071   double Interpolate(double x, double y, double z, int component);
00072 
00078   bool Interpolate(const double point[3], double *value);
00079 
00081 
00082   void SetOutValue(double outValue);
00083   double GetOutValue() { return this->OutValue; }
00085 
00087 
00090   void SetTolerance(double tol);
00091   double GetTolerance() { return this->Tolerance; }
00093 
00095 
00099   void SetComponentOffset(int offset);
00100   int GetComponentOffset() { return this->ComponentOffset; }
00102 
00104 
00108   void SetComponentCount(int count);
00109   int GetComponentCount() { return this->ComponentCount; }
00111 
00114   int ComputeNumberOfComponents(int inputComponents);
00115 
00119   int GetNumberOfComponents();
00120 
00122 
00125   void InterpolateIJK(const double point[3], double *value);
00126   void InterpolateIJK(const float point[3], float *value);
00128 
00130 
00134   bool CheckBoundsIJK(const double x[3]);
00135   bool CheckBoundsIJK(const float x[3]);
00137 
00139 
00144   void SetBorderMode(int mode);
00145   void SetBorderModeToClamp() {
00146     this->SetBorderMode(VTK_IMAGE_BORDER_CLAMP); }
00147   void SetBorderModeToRepeat() {
00148     this->SetBorderMode(VTK_IMAGE_BORDER_REPEAT); }
00149   void SetBorderModeToMirror() {
00150     this->SetBorderMode(VTK_IMAGE_BORDER_MIRROR); }
00151   int GetBorderMode() { return this->BorderMode; }
00152   const char *GetBorderModeAsString();
00154 
00160   virtual void ComputeSupportSize(const double matrix[16], int support[3]) = 0;
00161 
00166   virtual bool IsSeparable() = 0;
00167 
00169 
00177   virtual void PrecomputeWeightsForExtent(
00178     const double matrix[16], const int extent[6], int checkExtent[6],
00179     vtkInterpolationWeights *&weights);
00180   virtual void PrecomputeWeightsForExtent(
00181     const float matrix[16], const int extent[6], int checkExtent[6],
00182     vtkInterpolationWeights *&weights);
00184 
00186   virtual void FreePrecomputedWeights(vtkInterpolationWeights *&weights);
00187 
00189 
00193   void InterpolateRow(
00194     vtkInterpolationWeights *&weights, int xIdx, int yIdx, int zIdx,
00195     double *value, int n);
00196   void InterpolateRow(
00197     vtkInterpolationWeights *&weights, int xIdx, int yIdx, int zIdx,
00198     float *value, int n);
00200 
00202 
00203   vtkGetVector3Macro(Spacing, double);
00205 
00207 
00208   vtkGetVector3Macro(Origin, double);
00210 
00212 
00213   vtkGetVector6Macro(Extent, int);
00215 
00217 
00219   vtkGetVector6Macro(WholeExtent, int);
00221 
00222 protected:
00223   vtkAbstractImageInterpolator();
00224   ~vtkAbstractImageInterpolator();
00225 
00227   virtual void InternalUpdate() = 0;
00228 
00230   virtual void InternalDeepCopy(vtkAbstractImageInterpolator *obj) = 0;
00231 
00233 
00234   virtual void GetInterpolationFunc(
00235     void (**doublefunc)(
00236       vtkInterpolationInfo *, const double [3], double *));
00237   virtual void GetInterpolationFunc(
00238     void (**floatfunc)(
00239       vtkInterpolationInfo *, const float [3], float *));
00241 
00243 
00244   virtual void GetRowInterpolationFunc(
00245     void (**doublefunc)(
00246       vtkInterpolationWeights *, int, int, int, double *, int));
00247   virtual void GetRowInterpolationFunc(
00248     void (**floatfunc)(
00249       vtkInterpolationWeights *, int, int, int, float *, int));
00251 
00252   vtkDataArray *Scalars;
00253   double StructuredBoundsDouble[6];
00254   float StructuredBoundsFloat[6];
00255   int WholeExtent[6];
00256   int Extent[6];
00257   double Spacing[3];
00258   double Origin[3];
00259   double OutValue;
00260   double Tolerance;
00261   int BorderMode;
00262   int ComponentOffset;
00263   int ComponentCount;
00264 
00265   // information needed by the interpolator funcs
00266   vtkInterpolationInfo *InterpolationInfo;
00267 
00268   void (*InterpolationFuncDouble)(
00269     vtkInterpolationInfo *info, const double point[3], double *outPtr);
00270   void (*InterpolationFuncFloat)(
00271     vtkInterpolationInfo *info, const float point[3], float *outPtr);
00272 
00273   void (*RowInterpolationFuncDouble)(
00274     vtkInterpolationWeights *weights, int idX, int idY, int idZ,
00275     double *outPtr, int n);
00276   void (*RowInterpolationFuncFloat)(
00277     vtkInterpolationWeights *weights, int idX, int idY, int idZ,
00278     float *outPtr, int n);
00279 
00280 private:
00281 
00282   vtkAbstractImageInterpolator(const vtkAbstractImageInterpolator&);  // Not implemented.
00283   void operator=(const vtkAbstractImageInterpolator&);  // Not implemented.
00284 };
00285 
00286 inline void vtkAbstractImageInterpolator::InterpolateIJK(
00287   const double point[3], double *value)
00288 {
00289   this->InterpolationFuncDouble(this->InterpolationInfo, point, value);
00290 }
00291 
00292 inline void vtkAbstractImageInterpolator::InterpolateIJK(
00293   const float point[3], float *value)
00294 {
00295   this->InterpolationFuncFloat(this->InterpolationInfo, point, value);
00296 }
00297 
00298 inline bool vtkAbstractImageInterpolator::CheckBoundsIJK(const double x[3])
00299 {
00300   double *bounds = this->StructuredBoundsDouble;
00301   return !((x[0] < bounds[0]) | (x[0] > bounds[1]) |
00302            (x[1] < bounds[2]) | (x[1] > bounds[3]) |
00303            (x[2] < bounds[4]) | (x[2] > bounds[5]));
00304 }
00305 
00306 inline bool vtkAbstractImageInterpolator::CheckBoundsIJK(const float x[3])
00307 {
00308   float *bounds = this->StructuredBoundsFloat;
00309   return !((x[0] < bounds[0]) | (x[0] > bounds[1]) |
00310            (x[1] < bounds[2]) | (x[1] > bounds[3]) |
00311            (x[2] < bounds[4]) | (x[2] > bounds[5]));
00312 }
00313 
00314 inline void vtkAbstractImageInterpolator::InterpolateRow(
00315   vtkInterpolationWeights *&weights, int xIdx, int yIdx, int zIdx,
00316   double *value, int n)
00317 {
00318   this->RowInterpolationFuncDouble(weights, xIdx, yIdx, zIdx, value, n);
00319 }
00320 
00321 inline void vtkAbstractImageInterpolator::InterpolateRow(
00322   vtkInterpolationWeights *&weights, int xIdx, int yIdx, int zIdx,
00323   float *value, int n)
00324 {
00325   this->RowInterpolationFuncFloat(weights, xIdx, yIdx, zIdx, value, n);
00326 }
00327 
00328 #endif