VTK
dox/Imaging/Core/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 "vtkImagingCoreModule.h" // For export macro
00033 #include "vtkObject.h"
00034 
00035 #define VTK_IMAGE_BORDER_CLAMP 0
00036 #define VTK_IMAGE_BORDER_REPEAT 1
00037 #define VTK_IMAGE_BORDER_MIRROR 2
00038 
00039 class vtkDataObject;
00040 class vtkImageData;
00041 class vtkDataArray;
00042 struct vtkInterpolationInfo;
00043 struct vtkInterpolationWeights;
00044 
00045 class VTKIMAGINGCORE_EXPORT vtkAbstractImageInterpolator : public vtkObject
00046 {
00047 public:
00048   vtkTypeMacro(vtkAbstractImageInterpolator, vtkObject);
00049   virtual void PrintSelf(ostream& os, vtkIndent indent);
00050 
00053   virtual void Initialize(vtkDataObject *data);
00054 
00056   virtual void ReleaseData();
00057 
00060   void DeepCopy(vtkAbstractImageInterpolator *obj);
00061 
00065   void Update();
00066 
00072   double Interpolate(double x, double y, double z, int component);
00073 
00079   bool Interpolate(const double point[3], double *value);
00080 
00082 
00083   void SetOutValue(double outValue);
00084   double GetOutValue() { return this->OutValue; }
00086 
00088 
00091   void SetTolerance(double tol);
00092   double GetTolerance() { return this->Tolerance; }
00094 
00096 
00100   void SetComponentOffset(int offset);
00101   int GetComponentOffset() { return this->ComponentOffset; }
00103 
00105 
00109   void SetComponentCount(int count);
00110   int GetComponentCount() { return this->ComponentCount; }
00112 
00115   int ComputeNumberOfComponents(int inputComponents);
00116 
00120   int GetNumberOfComponents();
00121 
00123 
00126   void InterpolateIJK(const double point[3], double *value);
00127   void InterpolateIJK(const float point[3], float *value);
00129 
00131 
00135   bool CheckBoundsIJK(const double x[3]);
00136   bool CheckBoundsIJK(const float x[3]);
00138 
00140 
00145   void SetBorderMode(int mode);
00146   void SetBorderModeToClamp() {
00147     this->SetBorderMode(VTK_IMAGE_BORDER_CLAMP); }
00148   void SetBorderModeToRepeat() {
00149     this->SetBorderMode(VTK_IMAGE_BORDER_REPEAT); }
00150   void SetBorderModeToMirror() {
00151     this->SetBorderMode(VTK_IMAGE_BORDER_MIRROR); }
00152   int GetBorderMode() { return this->BorderMode; }
00153   const char *GetBorderModeAsString();
00155 
00161   virtual void ComputeSupportSize(const double matrix[16], int support[3]) = 0;
00162 
00167   virtual bool IsSeparable() = 0;
00168 
00170 
00178   virtual void PrecomputeWeightsForExtent(
00179     const double matrix[16], const int extent[6], int checkExtent[6],
00180     vtkInterpolationWeights *&weights);
00181   virtual void PrecomputeWeightsForExtent(
00182     const float matrix[16], const int extent[6], int checkExtent[6],
00183     vtkInterpolationWeights *&weights);
00185 
00187   virtual void FreePrecomputedWeights(vtkInterpolationWeights *&weights);
00188 
00190 
00194   void InterpolateRow(
00195     vtkInterpolationWeights *&weights, int xIdx, int yIdx, int zIdx,
00196     double *value, int n);
00197   void InterpolateRow(
00198     vtkInterpolationWeights *&weights, int xIdx, int yIdx, int zIdx,
00199     float *value, int n);
00201 
00203 
00204   vtkGetVector3Macro(Spacing, double);
00206 
00208 
00209   vtkGetVector3Macro(Origin, double);
00211 
00213 
00214   vtkGetVector6Macro(Extent, int);
00216 
00218 
00220   vtkGetVector6Macro(WholeExtent, int);
00222 
00223 protected:
00224   vtkAbstractImageInterpolator();
00225   ~vtkAbstractImageInterpolator();
00226 
00228   virtual void InternalUpdate() = 0;
00229 
00231   virtual void InternalDeepCopy(vtkAbstractImageInterpolator *obj) = 0;
00232 
00234 
00235   virtual void GetInterpolationFunc(
00236     void (**doublefunc)(
00237       vtkInterpolationInfo *, const double [3], double *));
00238   virtual void GetInterpolationFunc(
00239     void (**floatfunc)(
00240       vtkInterpolationInfo *, const float [3], float *));
00242 
00244 
00245   virtual void GetRowInterpolationFunc(
00246     void (**doublefunc)(
00247       vtkInterpolationWeights *, int, int, int, double *, int));
00248   virtual void GetRowInterpolationFunc(
00249     void (**floatfunc)(
00250       vtkInterpolationWeights *, int, int, int, float *, int));
00252 
00253   vtkDataArray *Scalars;
00254   double StructuredBoundsDouble[6];
00255   float StructuredBoundsFloat[6];
00256   int WholeExtent[6];
00257   int Extent[6];
00258   double Spacing[3];
00259   double Origin[3];
00260   double OutValue;
00261   double Tolerance;
00262   int BorderMode;
00263   int ComponentOffset;
00264   int ComponentCount;
00265 
00266   // information needed by the interpolator funcs
00267   vtkInterpolationInfo *InterpolationInfo;
00268 
00269   void (*InterpolationFuncDouble)(
00270     vtkInterpolationInfo *info, const double point[3], double *outPtr);
00271   void (*InterpolationFuncFloat)(
00272     vtkInterpolationInfo *info, const float point[3], float *outPtr);
00273 
00274   void (*RowInterpolationFuncDouble)(
00275     vtkInterpolationWeights *weights, int idX, int idY, int idZ,
00276     double *outPtr, int n);
00277   void (*RowInterpolationFuncFloat)(
00278     vtkInterpolationWeights *weights, int idX, int idY, int idZ,
00279     float *outPtr, int n);
00280 
00281 private:
00282 
00283   vtkAbstractImageInterpolator(const vtkAbstractImageInterpolator&);  // Not implemented.
00284   void operator=(const vtkAbstractImageInterpolator&);  // Not implemented.
00285 };
00286 
00287 inline void vtkAbstractImageInterpolator::InterpolateIJK(
00288   const double point[3], double *value)
00289 {
00290   this->InterpolationFuncDouble(this->InterpolationInfo, point, value);
00291 }
00292 
00293 inline void vtkAbstractImageInterpolator::InterpolateIJK(
00294   const float point[3], float *value)
00295 {
00296   this->InterpolationFuncFloat(this->InterpolationInfo, point, value);
00297 }
00298 
00299 inline bool vtkAbstractImageInterpolator::CheckBoundsIJK(const double x[3])
00300 {
00301   double *bounds = this->StructuredBoundsDouble;
00302   return !((x[0] < bounds[0]) | (x[0] > bounds[1]) |
00303            (x[1] < bounds[2]) | (x[1] > bounds[3]) |
00304            (x[2] < bounds[4]) | (x[2] > bounds[5]));
00305 }
00306 
00307 inline bool vtkAbstractImageInterpolator::CheckBoundsIJK(const float x[3])
00308 {
00309   float *bounds = this->StructuredBoundsFloat;
00310   return !((x[0] < bounds[0]) | (x[0] > bounds[1]) |
00311            (x[1] < bounds[2]) | (x[1] > bounds[3]) |
00312            (x[2] < bounds[4]) | (x[2] > bounds[5]));
00313 }
00314 
00315 inline void vtkAbstractImageInterpolator::InterpolateRow(
00316   vtkInterpolationWeights *&weights, int xIdx, int yIdx, int zIdx,
00317   double *value, int n)
00318 {
00319   this->RowInterpolationFuncDouble(weights, xIdx, yIdx, zIdx, value, n);
00320 }
00321 
00322 inline void vtkAbstractImageInterpolator::InterpolateRow(
00323   vtkInterpolationWeights *&weights, int xIdx, int yIdx, int zIdx,
00324   float *value, int n)
00325 {
00326   this->RowInterpolationFuncFloat(weights, xIdx, yIdx, zIdx, value, n);
00327 }
00328 
00329 #endif