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

Interpolate a point-based array over a surface using a radial basis function of the mesh geodesic distance. More...

#include <vtkvmtkPolyDataGeodesicRBFInterpolation.h>

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

Public Types

enum  { THIN_PLATE_SPLINE , BIHARMONIC , TRIHARMONIC }
typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkPolyDataGeodesicRBFInterpolation * NewInstance () const
virtual void SetSeedIds (vtkIdList *)
virtual vtkIdList * GetSeedIds ()
virtual void SetSeedValues (vtkDataArray *)
virtual vtkDataArray * GetSeedValues ()
virtual void SetInterpolatedArrayName (const char *)
virtual char * GetInterpolatedArrayName ()
virtual void SetRBFType (int)
virtual int GetRBFType ()
void SetRBFTypeToThinPlateSpline ()
void SetRBFTypeToBiharmonic ()
void SetRBFTypeToTriharmonic ()

Static Public Member Functions

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

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkPolyDataGeodesicRBFInterpolation ()
 ~vtkvmtkPolyDataGeodesicRBFInterpolation ()
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
double EvaluateRBF (double r)

Protected Attributes

char * InterpolatedArrayName
vtkIdList * SeedIds
vtkDataArray * SeedValues
int RBFType

Detailed Description

Interpolate a point-based array over a surface using a radial basis function of the mesh geodesic distance.

vtkvmtkPolyDataGeodesicRBFInterpolation solves for a set of per-seed coefficients such that a sum of radial basis functions, evaluated on the Dijkstra graph-geodesic distance (rather than Euclidean distance) between mesh points, exactly reproduces the seed values (SeedValues) at the seed points (SeedIds). It then evaluates that sum at every point of the input surface and writes the result to a point data array named InterpolatedArrayName. At least two seed points are required.

See also
vtkvmtkRBFInterpolation2

Definition at line 49 of file vtkvmtkPolyDataGeodesicRBFInterpolation.h.

Member Typedef Documentation

◆ Superclass

Member Enumeration Documentation

◆ anonymous enum

Constructor & Destructor Documentation

◆ vtkvmtkPolyDataGeodesicRBFInterpolation()

vtkvmtkPolyDataGeodesicRBFInterpolation::vtkvmtkPolyDataGeodesicRBFInterpolation ( )
protected

◆ ~vtkvmtkPolyDataGeodesicRBFInterpolation()

vtkvmtkPolyDataGeodesicRBFInterpolation::~vtkvmtkPolyDataGeodesicRBFInterpolation ( )
protected

Definition at line 57 of file vtkvmtkPolyDataGeodesicRBFInterpolation.cxx.

58{
59 if (this->InterpolatedArrayName)
60 {
61 delete[] this->InterpolatedArrayName;
62 this->InterpolatedArrayName = NULL;
63 }
64
65 if (this->SeedIds)
66 {
67 this->SeedIds->Delete();
68 this->SeedIds = NULL;
69 }
70
71 if (this->SeedValues)
72 {
73 this->SeedValues->Delete();
74 this->SeedValues = NULL;
75 }
76}

Member Function Documentation

◆ New()

vtkvmtkPolyDataGeodesicRBFInterpolation * vtkvmtkPolyDataGeodesicRBFInterpolation::New ( )
static

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkPolyDataGeodesicRBFInterpolation::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkPolyDataGeodesicRBFInterpolation * vtkvmtkPolyDataGeodesicRBFInterpolation::NewInstance ( ) const

◆ SetSeedIds()

virtual void vtkvmtkPolyDataGeodesicRBFInterpolation::SetSeedIds ( vtkIdList * )
virtual

Set/get the ids of the input surface points to use as interpolation seeds; must have the same number of entries as SeedValues, at least 2.

◆ GetSeedIds()

virtual vtkIdList * vtkvmtkPolyDataGeodesicRBFInterpolation::GetSeedIds ( )
virtual

Set/get the ids of the input surface points to use as interpolation seeds; must have the same number of entries as SeedValues, at least 2.

◆ SetSeedValues()

virtual void vtkvmtkPolyDataGeodesicRBFInterpolation::SetSeedValues ( vtkDataArray * )
virtual

Set/get the known values at the seed points (one value per entry of SeedIds, in the same order) that the interpolant must reproduce.

◆ GetSeedValues()

virtual vtkDataArray * vtkvmtkPolyDataGeodesicRBFInterpolation::GetSeedValues ( )
virtual

Set/get the known values at the seed points (one value per entry of SeedIds, in the same order) that the interpolant must reproduce.

◆ SetInterpolatedArrayName()

virtual void vtkvmtkPolyDataGeodesicRBFInterpolation::SetInterpolatedArrayName ( const char * )
virtual

Set/get the name of the output point data array holding the interpolated values. Commonly named "InterpolatedRadius" or "ResolutionArray", depending on context.

◆ GetInterpolatedArrayName()

virtual char * vtkvmtkPolyDataGeodesicRBFInterpolation::GetInterpolatedArrayName ( )
virtual

Set/get the name of the output point data array holding the interpolated values. Commonly named "InterpolatedRadius" or "ResolutionArray", depending on context.

◆ SetRBFType()

virtual void vtkvmtkPolyDataGeodesicRBFInterpolation::SetRBFType ( int )
virtual

Set/get the type of radial basis function used, one of THIN_PLATE_SPLINE (r^2 log r, the default), BIHARMONIC (r), or TRIHARMONIC (r^3), where r is the mesh geodesic distance to a seed.

◆ GetRBFType()

virtual int vtkvmtkPolyDataGeodesicRBFInterpolation::GetRBFType ( )
virtual

Set/get the type of radial basis function used, one of THIN_PLATE_SPLINE (r^2 log r, the default), BIHARMONIC (r), or TRIHARMONIC (r^3), where r is the mesh geodesic distance to a seed.

◆ SetRBFTypeToThinPlateSpline()

void vtkvmtkPolyDataGeodesicRBFInterpolation::SetRBFTypeToThinPlateSpline ( )
inline

Set/get the type of radial basis function used, one of THIN_PLATE_SPLINE (r^2 log r, the default), BIHARMONIC (r), or TRIHARMONIC (r^3), where r is the mesh geodesic distance to a seed.

Definition at line 91 of file vtkvmtkPolyDataGeodesicRBFInterpolation.h.

◆ SetRBFTypeToBiharmonic()

void vtkvmtkPolyDataGeodesicRBFInterpolation::SetRBFTypeToBiharmonic ( )
inline

Set/get the type of radial basis function used, one of THIN_PLATE_SPLINE (r^2 log r, the default), BIHARMONIC (r), or TRIHARMONIC (r^3), where r is the mesh geodesic distance to a seed.

Definition at line 93 of file vtkvmtkPolyDataGeodesicRBFInterpolation.h.

94 { this->SetRBFType(BIHARMONIC); }

◆ SetRBFTypeToTriharmonic()

void vtkvmtkPolyDataGeodesicRBFInterpolation::SetRBFTypeToTriharmonic ( )
inline

Set/get the type of radial basis function used, one of THIN_PLATE_SPLINE (r^2 log r, the default), BIHARMONIC (r), or TRIHARMONIC (r^3), where r is the mesh geodesic distance to a seed.

Definition at line 95 of file vtkvmtkPolyDataGeodesicRBFInterpolation.h.

96 { this->SetRBFType(TRIHARMONIC); }

◆ RequestData()

int vtkvmtkPolyDataGeodesicRBFInterpolation::RequestData ( vtkInformation * ,
vtkInformationVector ** ,
vtkInformationVector *  )
overrideprotectedvirtual

Definition at line 105 of file vtkvmtkPolyDataGeodesicRBFInterpolation.cxx.

109{
110 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
111 vtkInformation *outInfo = outputVector->GetInformationObject(0);
112
113 vtkPolyData *input = vtkPolyData::SafeDownCast(
114 inInfo->Get(vtkDataObject::DATA_OBJECT()));
115 vtkPolyData *output = vtkPolyData::SafeDownCast(
116 outInfo->Get(vtkDataObject::DATA_OBJECT()));
117
118 if (!this->InterpolatedArrayName)
119 {
120 vtkErrorMacro(<<"InterpolatedArrayName not set.");
121 return 1;
122 }
123
124 if (!this->SeedIds)
125 {
126 vtkErrorMacro(<<"SeedIds not set");
127 return 1;
128 }
129
130 if (!this->SeedValues)
131 {
132 vtkErrorMacro(<<"SeedValues not set");
133 return 1;
134 }
135
136
137 int numberOfSeeds = this->SeedIds->GetNumberOfIds();
138
139 int numberOfInputPoints = input->GetNumberOfPoints();
140
141 if ((numberOfSeeds != this->SeedValues->GetNumberOfTuples()) || (numberOfSeeds>numberOfInputPoints) || (numberOfSeeds<2))
142 {
143 vtkErrorMacro(<<"Incorrect number of seed values");
144 return 1;
145 }
146
147 output->DeepCopy(input);
148
149
150 vtkDataArray* interpolatedArray = output->GetPointData()->GetArray(this->InterpolatedArrayName);
151
152 bool createArray = !interpolatedArray;
153
154 if (createArray)
155 {
156 interpolatedArray = vtkDoubleArray::New();
157 interpolatedArray->SetName(this->InterpolatedArrayName);
158 interpolatedArray->SetNumberOfComponents(1);
159 interpolatedArray->SetNumberOfTuples(numberOfInputPoints);
160
161 output->GetPointData()->AddArray(interpolatedArray);
162 }
163
164
165
166 vtkDijkstraGraphGeodesicPath *dijkstraAlgo = vtkDijkstraGraphGeodesicPath::New();
167 dijkstraAlgo->SetInputData(input);
168 dijkstraAlgo->StopWhenEndReachedOff();
169 dijkstraAlgo->UseScalarWeightsOff();
170
171 std::vector<vtkDoubleArray *> geodesicDistances;
172
173
174 //Compute the geodesic distances
175 for (int i=0; i<numberOfSeeds; i++)
176 {
177 dijkstraAlgo->SetStartVertex(SeedIds->GetId(i));
178 dijkstraAlgo->Update();
179 vtkDoubleArray *seedDistances = vtkDoubleArray::New();
180 dijkstraAlgo->GetCumulativeWeights(seedDistances);
181 geodesicDistances.push_back(seedDistances);
182 }
183
184 //Compute the coefficients
185 double **A, *x;
186 x = new double[numberOfSeeds];
187 A = new double* [numberOfSeeds];
188
189 int i;
190 for (i=0; i<numberOfSeeds; i++)
191 {
192 A[i] = new double[numberOfSeeds];
193 x[i] = this->SeedValues->GetComponent(i,0);
194 }
195
196 int j;
197 for (i=0; i<numberOfSeeds; i++)
198 {
199 for (j=0; j<numberOfSeeds; j++)
200 {
201 double dist = geodesicDistances[i]->GetValue(this->SeedIds->GetId(j));
202 A[i][j] = this->EvaluateRBF(dist);
203 }
204 }
205
206 std::cout << "A " << std::endl;
207 for (int i=0;i<numberOfSeeds;i++) {
208 for (int j=0;j<numberOfSeeds;j++) {
209 std::cout << A[i][j] << " ";
210 }
211 std::cout << std::endl;
212 }
213
214 std::cout << "b " << std::endl;
215 for (int i=0;i<numberOfSeeds;i++) {
216 std::cout << x[i] << std::endl;
217 }
218
219 int ret = vtkMath::SolveLinearSystem(A,x,numberOfSeeds);
220
221 std::cout << "x " << std::endl;
222 for (int i=0;i<numberOfSeeds;i++) {
223 std::cout << x[i] << std::endl;
224 }
225
226 if (!ret)
227 {
228 vtkErrorMacro(<<"Cannot compute coefficients: error during linear system solve");
229 }
230
231
232 for (i=0; i<numberOfSeeds; i++)
233 {
234 delete[] A[i];
235 }
236 delete[] A;
237
238
239 //Interpolate the values at all points using the coefficients
240 for (int i=0;i<numberOfInputPoints;i++)
241 {
242 double rbfValue = 0.;
243 for (int j=0;j<numberOfSeeds;j++) {
244 double dist = geodesicDistances[j]->GetValue(i);
245 rbfValue += x[j]*this->EvaluateRBF(dist);
246 }
247 interpolatedArray->SetComponent(i,0,rbfValue);
248 }
249
250 delete[] x;
251 for (int i=0;i<numberOfSeeds;i++)
252 {
253 geodesicDistances[i]->Delete();
254 }
255
256 geodesicDistances.clear();
257
258
259 if (createArray) interpolatedArray->Delete();
260
261 return 1;
262}

◆ EvaluateRBF()

double vtkvmtkPolyDataGeodesicRBFInterpolation::EvaluateRBF ( double r)
protected

Definition at line 78 of file vtkvmtkPolyDataGeodesicRBFInterpolation.cxx.

79{
80 if (this->RBFType == THIN_PLATE_SPLINE)
81 {
82 double r2 = r*r;
83 if (!r2)
84 {
85 return 0.0;
86 }
87 return r2 * log(sqrt(r2));
88 }
89 else if (this->RBFType == BIHARMONIC)
90 {
91 return r;
92 }
93 else if (this->RBFType == TRIHARMONIC)
94 {
95 return r*r*r;
96 }
97 else
98 {
99 vtkErrorMacro(<<"Error: Unsupported RBFType!");
100 return 0.0;
101 }
102}

Member Data Documentation

◆ InterpolatedArrayName

char* vtkvmtkPolyDataGeodesicRBFInterpolation::InterpolatedArrayName
protected

Definition at line 116 of file vtkvmtkPolyDataGeodesicRBFInterpolation.h.

◆ SeedIds

vtkIdList* vtkvmtkPolyDataGeodesicRBFInterpolation::SeedIds
protected

Definition at line 118 of file vtkvmtkPolyDataGeodesicRBFInterpolation.h.

◆ SeedValues

vtkDataArray* vtkvmtkPolyDataGeodesicRBFInterpolation::SeedValues
protected

Definition at line 119 of file vtkvmtkPolyDataGeodesicRBFInterpolation.h.

◆ RBFType

int vtkvmtkPolyDataGeodesicRBFInterpolation::RBFType
protected

Definition at line 121 of file vtkvmtkPolyDataGeodesicRBFInterpolation.h.


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