VMTK
Loading...
Searching...
No Matches
vtkvmtkRBFInterpolation2.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkRBFInterpolation2.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 Note: this class was contributed by
21 Tangui Morvan
22 Kalkulo AS
23 Simula Research Laboratory
24=========================================================================*/
26#include "vtkvmtkConstants.h"
27#include "vtkPointData.h"
28#include "vtkMath.h"
29#include "vtkObjectFactory.h"
30
31
33
40
42{
43 if (this->Source)
44 {
45 this->Source->Delete();
46 this->Source = NULL;
47 }
48
49 if (this->Coefficients)
50 {
51 this->Coefficients->Delete();
52 this->Coefficients = NULL;
53 }
54}
55
56double vtkvmtkRBFInterpolation2::EvaluateRBF(double c[3], double x[3])
57{
58 if (this->RBFType == THIN_PLATE_SPLINE)
59 {
60 double r2 = vtkMath::Distance2BetweenPoints(c,x);
61 if (!r2)
62 {
63 return 0.0;
64 }
65 return r2 * log(sqrt(r2));
66 }
67 else if (this->RBFType == BIHARMONIC)
68 {
69 return sqrt(vtkMath::Distance2BetweenPoints(c,x));
70 }
71 else if (this->RBFType == TRIHARMONIC)
72 {
73 return pow(vtkMath::Distance2BetweenPoints(c,x),1.5);
74 }
75 else
76 {
77 vtkErrorMacro(<<"Error: Unsupported RBFType!");
78 return 0.0;
79 }
80}
81
83{
84 if (this->Coefficients)
85 {
86 this->Coefficients->Delete();
87 this->Coefficients = NULL;
88 }
89
90 if (!this->Source)
91 {
92 vtkErrorMacro("No Source specified!");
93 return;
94 }
95
96 vtkDataArray *sourceScalars = this->Source->GetPointData()->GetScalars();
97
98 if (!sourceScalars)
99 {
100 vtkErrorMacro("No scalars to interpolate!");
101 return;
102 }
103
104 int numberOfPoints = this->Source->GetNumberOfPoints();
105 if (!numberOfPoints)
106 {
107 vtkWarningMacro("Empty Source specified!");
108 return;
109 }
110
111 this->Coefficients = vtkDoubleArray::New();
112 this->Coefficients->SetNumberOfValues(numberOfPoints);
113
114 double **A, *x;
115 x = new double[numberOfPoints];
116 A = new double* [numberOfPoints];
117
118 int i;
119 for (i=0; i<numberOfPoints; i++)
120 {
121 A[i] = new double[numberOfPoints];
122 x[i] = sourceScalars->GetComponent(i,0);
123 }
124
125 double center[3];
126 int j;
127 for (i=0; i<numberOfPoints; i++)
128 {
129 this->Source->GetPoint(i,center);
130 for (j=0; j<numberOfPoints; j++)
131 {
132 A[i][j] = this->EvaluateRBF(center,this->Source->GetPoint(j));
133 }
134 }
135
136 int ret = vtkMath::SolveLinearSystem(A,x,numberOfPoints);
137
138 if (!ret)
139 {
140 vtkErrorMacro(<<"Cannot compute coefficients: error during linear system solve");
141 }
142
143 for (i=0; i<numberOfPoints; i++)
144 {
145 this->Coefficients->SetValue(i,x[i]);
146 }
147
148 delete[] x;
149 for (i=0; i<numberOfPoints; i++)
150 {
151 delete[] A[i];
152 }
153 delete[] A;
154
155}
156
158{
159 if (!this->Source)
160 {
161 vtkErrorMacro("No Source specified!");
162 return 0.0;
163 }
164
165 int numberOfPoints = this->Source->GetNumberOfPoints();
166
167 if (!numberOfPoints)
168 {
169 vtkWarningMacro("Empty Source specified!");
170 return 0.0;
171 }
172
173 if (!this->Coefficients)
174 {
175 this->ComputeCoefficients();
176 }
177
178 double rbfValue = 0.0;
179 double center[3];
180 int i;
181 for (i=0; i<numberOfPoints; i++)
182 {
183 this->Source->GetPoint(i,center);
184 rbfValue += this->Coefficients->GetValue(i) * this->EvaluateRBF(center,x);
185 }
186
187 return rbfValue;
188}
189
190void vtkvmtkRBFInterpolation2::EvaluateGradient(double x[3], double n[3])
191{
192 vtkWarningMacro("RBF gradient computation not implemented.");
193}
194
196{
197 unsigned long mTime=this->Superclass::GetMTime();
198 unsigned long sourceMTime;
199
200 if (this->Source != NULL)
201 {
202 sourceMTime = this->Source->GetMTime();
203 mTime = ( sourceMTime > mTime ? sourceMTime : mTime );
204 }
205
206 return mTime;
207}
208
209void vtkvmtkRBFInterpolation2::PrintSelf(std::ostream& os, vtkIndent indent)
210{
211 this->Superclass::PrintSelf(os,indent);
212
213}
Implicit function that interpolates scalar point data with a radial basis function.
double EvaluateRBF(double c[3], double x[3])
double EvaluateFunction(double x[3]) override
void EvaluateGradient(double x[3], double n[3]) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
vtkStandardNewMacro(vtkvmtkRBFInterpolation2)