VMTK
Loading...
Searching...
No Matches
vtkvmtkRBFInterpolation.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkRBFInterpolation.cxx,v $
5Language: C++
6Date: $Date: 2005/03/04 11:07:28 $
7Version: $Revision: 1.2 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
22#include "vtkvmtkConstants.h"
23#include "vtkPointData.h"
24#include "vtkMath.h"
25#include "vtkObjectFactory.h"
26#include "vtkVersion.h"
27
28
30
32{
33 this->Source = NULL;
35 this->Coefficients = NULL;
36 this->RBFInterpolationValue = 1.0;
37}
38
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}
53
54double vtkvmtkRBFInterpolation::EvaluateRBF(double c[3], double x[3])
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}
79
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}
145
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}
180
181void vtkvmtkRBFInterpolation::EvaluateGradient(double x[3], double n[3])
182{
183 vtkWarningMacro("RBF gradient computation not implemented.");
184}
185
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}
199
200void vtkvmtkRBFInterpolation::PrintSelf(std::ostream& os, vtkIndent indent)
201{
202 this->Superclass::PrintSelf(os,indent);
203
204}
Implements an implicit function that interpolates a scalar value at a scattered set of points using r...
double EvaluateFunction(double x[3]) override
double EvaluateRBF(double c[3], double x[3])
void PrintSelf(std::ostream &os, vtkIndent indent) override
vtkMTimeType GetMTime() override
void EvaluateGradient(double x[3], double n[3]) override
vtkStandardNewMacro(vtkvmtkRBFInterpolation)