VMTK
Loading...
Searching...
No Matches
vtkvmtkRBFInterpolation Class Reference

Implements an implicit function that interpolates a scalar value at a scattered set of points using radial basis functions. More...

#include <vtkvmtkRBFInterpolation.h>

Inheritance diagram for vtkvmtkRBFInterpolation:
[legend]
Collaboration diagram for vtkvmtkRBFInterpolation:
[legend]

Public Types

enum  { THIN_PLATE_SPLINE , BIHARMONIC , TRIHARMONIC }
typedef vtkImplicitFunction Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkRBFInterpolation * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
void EvaluateGradient (double x[3], double n[3]) override
void ComputeCoefficients ()
vtkMTimeType GetMTime () override
double EvaluateFunction (double x[3]) override
double EvaluateFunction (double x, double y, double z) override
virtual void SetSource (vtkPolyData *)
virtual vtkPolyData * GetSource ()
virtual void SetRBFType (int)
virtual int GetRBFType ()
void SetRBFTypeToThinPlateSpline ()
void SetRBFTypeToBiharmonic ()
void SetRBFTypeToTriharmonic ()

Static Public Member Functions

static int IsTypeOf (const char *type)
static vtkvmtkRBFInterpolation * SafeDownCast (vtkObjectBase *o)
static vtkvmtkRBFInterpolation * New ()

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkRBFInterpolation ()
 ~vtkvmtkRBFInterpolation ()
double EvaluateRBF (double c[3], double x[3])

Protected Attributes

vtkPolyData * Source
int RBFType
vtkDoubleArray * Coefficients
double RBFInterpolationValue

Detailed Description

Implements an implicit function that interpolates a scalar value at a scattered set of points using radial basis functions.

vtkvmtkRBFInterpolation builds a radial basis function (RBF) interpolant that takes the value RBFInterpolationValue at every point of Source, and evaluates that interpolant as an implicit function anywhere in space. The interpolation weights are found by solving the dense linear system obtained by requiring the RBF sum to match RBFInterpolationValue at each source point (see ComputeCoefficients); RBFType selects the radial kernel (thin-plate spline, biharmonic, or triharmonic). Since all source points share the same target value, this does not directly reconstruct a signed-distance-like implicit surface from on/off-surface samples; instead it is used to build a smooth scalar field seeded at a set of points, e.g. by vmtkrbfinterpolation to resample a set of seed points onto a regular image grid via vtkSampleFunction.

Definition at line 43 of file vtkvmtkRBFInterpolation.h.

Member Typedef Documentation

◆ Superclass

typedef vtkImplicitFunction vtkvmtkRBFInterpolation::Superclass

Definition at line 46 of file vtkvmtkRBFInterpolation.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
THIN_PLATE_SPLINE 
BIHARMONIC 
TRIHARMONIC 

Definition at line 98 of file vtkvmtkRBFInterpolation.h.

Constructor & Destructor Documentation

◆ vtkvmtkRBFInterpolation()

vtkvmtkRBFInterpolation::vtkvmtkRBFInterpolation ( )
protected

Definition at line 31 of file vtkvmtkRBFInterpolation.cxx.

◆ ~vtkvmtkRBFInterpolation()

vtkvmtkRBFInterpolation::~vtkvmtkRBFInterpolation ( )
protected

Definition at line 39 of file vtkvmtkRBFInterpolation.cxx.

40{
41 if (this->Source)
42 {
43 this->Source->Delete();
44 this->Source = NULL;
45 }
46
47 if (this->Coefficients)
48 {
49 this->Coefficients->Delete();
50 this->Coefficients = NULL;
51 }
52}

Member Function Documentation

◆ IsTypeOf()

int vtkvmtkRBFInterpolation::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkRBFInterpolation::IsA ( const char * type)
virtual

◆ SafeDownCast()

vtkvmtkRBFInterpolation * vtkvmtkRBFInterpolation::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkRBFInterpolation::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkRBFInterpolation * vtkvmtkRBFInterpolation::NewInstance ( ) const

◆ PrintSelf()

void vtkvmtkRBFInterpolation::PrintSelf ( std::ostream & os,
vtkIndent indent )
override

Definition at line 200 of file vtkvmtkRBFInterpolation.cxx.

201{
202 this->Superclass::PrintSelf(os,indent);
203
204}

◆ New()

vtkvmtkRBFInterpolation * vtkvmtkRBFInterpolation::New ( )
static

◆ EvaluateFunction() [1/2]

double vtkvmtkRBFInterpolation::EvaluateFunction ( double x[3])
override

Evaluate polyball.

Definition at line 146 of file vtkvmtkRBFInterpolation.cxx.

147{
148 if (!this->Source)
149 {
150 vtkErrorMacro("No Source specified!");
151 return 0.0;
152 }
153
154 int numberOfPoints = this->Source->GetNumberOfPoints();
155
156 if (!numberOfPoints)
157 {
158 vtkWarningMacro("Empty Source specified!");
159 return 0.0;
160 }
161
162 if (!this->Coefficients)
163 {
164 this->ComputeCoefficients();
165 }
166
167 double rbfValue = 0.0;
168 double center[3];
169 int i;
170 for (i=0; i<numberOfPoints; i++)
171 {
172 this->Source->GetPoint(i,center);
173 rbfValue += this->Coefficients->GetValue(i) * this->EvaluateRBF(center,x);
174 }
175
176 rbfValue -= this->RBFInterpolationValue;
177
178 return rbfValue;
179}
double EvaluateRBF(double c[3], double x[3])

◆ EvaluateFunction() [2/2]

double vtkvmtkRBFInterpolation::EvaluateFunction ( double x,
double y,
double z )
inlineoverride

Evaluate polyball.

Definition at line 56 of file vtkvmtkRBFInterpolation.h.

57 {return this->vtkImplicitFunction::EvaluateFunction(x, y, z); } ;

◆ EvaluateGradient()

void vtkvmtkRBFInterpolation::EvaluateGradient ( double x[3],
double n[3] )
override

Evaluate polyball gradient.

Definition at line 181 of file vtkvmtkRBFInterpolation.cxx.

182{
183 vtkWarningMacro("RBF gradient computation not implemented.");
184}

◆ ComputeCoefficients()

void vtkvmtkRBFInterpolation::ComputeCoefficients ( )

Solve for the RBF interpolation weights (Coefficients) so that the interpolant evaluates to RBFInterpolationValue at every point of Source, using the kernel selected by RBFType. Called automatically by EvaluateFunction the first time it runs if Coefficients has not been computed yet; can also be called explicitly beforehand.

Definition at line 80 of file vtkvmtkRBFInterpolation.cxx.

81{
82 if (this->Coefficients)
83 {
84 this->Coefficients->Delete();
85 this->Coefficients = NULL;
86 }
87
88 if (!this->Source)
89 {
90 vtkErrorMacro("No Source specified!");
91 return;
92 }
93
94 int numberOfPoints = this->Source->GetNumberOfPoints();
95 if (!numberOfPoints)
96 {
97 vtkWarningMacro("Empty Source specified!");
98 return;
99 }
100
101 this->Coefficients = vtkDoubleArray::New();
102 this->Coefficients->SetNumberOfValues(numberOfPoints);
103
104 double **A, *x;
105 x = new double[numberOfPoints];
106 A = new double* [numberOfPoints];
107
108 int i;
109 for (i=0; i<numberOfPoints; i++)
110 {
111 A[i] = new double[numberOfPoints];
112 x[i] = this->RBFInterpolationValue;
113 }
114
115 double center[3];
116 int j;
117 for (i=0; i<numberOfPoints; i++)
118 {
119 this->Source->GetPoint(i,center);
120 for (j=0; j<numberOfPoints; j++)
121 {
122 A[i][j] = this->EvaluateRBF(center,this->Source->GetPoint(j));
123 }
124 }
125
126 int ret = vtkMath::SolveLinearSystem(A,x,numberOfPoints);
127
128 if (!ret)
129 {
130 vtkErrorMacro(<<"Cannot compute coefficients: error during linear system solve");
131 }
132
133 for (i=0; i<numberOfPoints; i++)
134 {
135 this->Coefficients->SetValue(i,x[i]);
136 }
137
138 delete[] x;
139 for (i=0; i<numberOfPoints; i++)
140 {
141 delete[] A[i];
142 }
143 delete[] A;
144}

◆ SetSource()

virtual void vtkvmtkRBFInterpolation::SetSource ( vtkPolyData * )
virtual

Set / get source poly data.

◆ GetSource()

virtual vtkPolyData * vtkvmtkRBFInterpolation::GetSource ( )
virtual

Set / get source poly data.

◆ SetRBFType()

virtual void vtkvmtkRBFInterpolation::SetRBFType ( int )
virtual

Set/Get the radial basis kernel used to build the interpolant, one of the THIN_PLATE_SPLINE, BIHARMONIC, or TRIHARMONIC enum values (equivalently set through the SetRBFTypeTo... methods below). Default: THIN_PLATE_SPLINE.

◆ GetRBFType()

virtual int vtkvmtkRBFInterpolation::GetRBFType ( )
virtual

Set/Get the radial basis kernel used to build the interpolant, one of the THIN_PLATE_SPLINE, BIHARMONIC, or TRIHARMONIC enum values (equivalently set through the SetRBFTypeTo... methods below). Default: THIN_PLATE_SPLINE.

◆ SetRBFTypeToThinPlateSpline()

void vtkvmtkRBFInterpolation::SetRBFTypeToThinPlateSpline ( )
inline

Set/Get the radial basis kernel used to build the interpolant, one of the THIN_PLATE_SPLINE, BIHARMONIC, or TRIHARMONIC enum values (equivalently set through the SetRBFTypeTo... methods below). Default: THIN_PLATE_SPLINE.

Definition at line 89 of file vtkvmtkRBFInterpolation.h.

virtual void SetRBFType(int)

◆ SetRBFTypeToBiharmonic()

void vtkvmtkRBFInterpolation::SetRBFTypeToBiharmonic ( )
inline

Set/Get the radial basis kernel used to build the interpolant, one of the THIN_PLATE_SPLINE, BIHARMONIC, or TRIHARMONIC enum values (equivalently set through the SetRBFTypeTo... methods below). Default: THIN_PLATE_SPLINE.

Definition at line 91 of file vtkvmtkRBFInterpolation.h.

92 { this->SetRBFType(BIHARMONIC); }

◆ SetRBFTypeToTriharmonic()

void vtkvmtkRBFInterpolation::SetRBFTypeToTriharmonic ( )
inline

Set/Get the radial basis kernel used to build the interpolant, one of the THIN_PLATE_SPLINE, BIHARMONIC, or TRIHARMONIC enum values (equivalently set through the SetRBFTypeTo... methods below). Default: THIN_PLATE_SPLINE.

Definition at line 93 of file vtkvmtkRBFInterpolation.h.

94 { this->SetRBFType(TRIHARMONIC); }

◆ GetMTime()

vtkMTimeType vtkvmtkRBFInterpolation::GetMTime ( )
override

Definition at line 186 of file vtkvmtkRBFInterpolation.cxx.

187{
188 unsigned long mTime=this->Superclass::GetMTime();
189 unsigned long sourceMTime;
190
191 if (this->Source != NULL)
192 {
193 sourceMTime = this->Source->GetMTime();
194 mTime = ( sourceMTime > mTime ? sourceMTime : mTime );
195 }
196
197 return mTime;
198}

◆ EvaluateRBF()

double vtkvmtkRBFInterpolation::EvaluateRBF ( double c[3],
double x[3] )
protected

Definition at line 54 of file vtkvmtkRBFInterpolation.cxx.

55{
56 if (this->RBFType == THIN_PLATE_SPLINE)
57 {
58 double r2 = vtkMath::Distance2BetweenPoints(c,x);
59 if (!r2)
60 {
61 return 0.0;
62 }
63 return r2 * log(sqrt(r2));
64 }
65 else if (this->RBFType == BIHARMONIC)
66 {
67 return sqrt(vtkMath::Distance2BetweenPoints(c,x));
68 }
69 else if (this->RBFType == TRIHARMONIC)
70 {
71 return pow(vtkMath::Distance2BetweenPoints(c,x),1.5);
72 }
73 else
74 {
75 vtkErrorMacro(<<"Error: Unsupported RBFType!");
76 return 0.0;
77 }
78}

Member Data Documentation

◆ Source

vtkPolyData* vtkvmtkRBFInterpolation::Source
protected

Definition at line 114 of file vtkvmtkRBFInterpolation.h.

◆ RBFType

int vtkvmtkRBFInterpolation::RBFType
protected

Definition at line 115 of file vtkvmtkRBFInterpolation.h.

◆ Coefficients

vtkDoubleArray* vtkvmtkRBFInterpolation::Coefficients
protected

Definition at line 117 of file vtkvmtkRBFInterpolation.h.

◆ RBFInterpolationValue

double vtkvmtkRBFInterpolation::RBFInterpolationValue
protected

Definition at line 118 of file vtkvmtkRBFInterpolation.h.


The documentation for this class was generated from the following files: