VMTK
Loading...
Searching...
No Matches
vtkvmtkCardinalSpline.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkCardinalSpline.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:48:25 $
7Version: $Revision: 1.0 $
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 Portions of this code are covered under the ITK copyright.
17 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm
18 for details.
19
20 This software is distributed WITHOUT ANY WARRANTY; without even
21 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
22 PURPOSE. See the above copyright notices for more information.
23
24=========================================================================*/
25
26
28#include "vtkPiecewiseFunction.h"
29
30#include "vtkObjectFactory.h"
31
32
34
38
40{
41 int index;
42 double *intervals;
43 double *coefficients;
44
45 if (this->ComputeTime < this->GetMTime())
46 {
47 this->Compute();
48 }
49
50 int size = this->PiecewiseFunction->GetSize();
51 if (size < 2)
52 {
53 return 0.0;
54 }
55
56 intervals = this->Intervals;
57 coefficients = this->Coefficients;
58
59 if (this->Closed)
60 {
61 size = size + 1;
62 }
63
64 if (t < intervals[0])
65 {
66 t = intervals[0];
67 }
68 if (t > intervals[size - 1])
69 {
70 t = intervals[size - 1];
71 }
72
73 index = this->FindIndex(size,t);
74
75 t = (t - intervals[index]);
76
77 return 3 * t * t * *(coefficients + index * 4 + 3) +
78 2 * t * *(coefficients + index * 4 + 2) +
79 + *(coefficients + index * 4 + 1);
80}
81
83{
84 int index;
85 double *intervals;
86 double *coefficients;
87
88 if (this->ComputeTime < this->GetMTime())
89 {
90 this->Compute();
91 }
92
93 int size = this->PiecewiseFunction->GetSize();
94 if (size < 2)
95 {
96 return 0.0;
97 }
98
99 intervals = this->Intervals;
100 coefficients = this->Coefficients;
101
102 if (this->Closed)
103 {
104 size = size + 1;
105 }
106
107 if (t < intervals[0])
108 {
109 t = intervals[0];
110 }
111 if (t > intervals[size - 1])
112 {
113 t = intervals[size - 1];
114 }
115
116 index = this->FindIndex(size,t);
117
118 t = (t - intervals[index]);
119
120 return 6 * t * *(coefficients + index * 4 + 3) +
121 2 * *(coefficients + index * 4 + 2);
122}
123
124void vtkvmtkCardinalSpline::EvaluateValueAndDerivatives(double t, double valueAndDerivatives[3])
125{
126 int index;
127 double *intervals;
128 double *coefficients;
129
130 if (this->ComputeTime < this->GetMTime())
131 {
132 this->Compute();
133 }
134
135 int size = this->PiecewiseFunction->GetSize();
136 if (size < 2)
137 {
138 valueAndDerivatives[0] = 0.0;
139 valueAndDerivatives[1] = 0.0;
140 valueAndDerivatives[2] = 0.0;
141 return;
142 }
143
144 intervals = this->Intervals;
145 coefficients = this->Coefficients;
146
147 if (this->Closed)
148 {
149 size = size + 1;
150 }
151
152 if (t < intervals[0])
153 {
154 t = intervals[0];
155 }
156 if (t > intervals[size - 1])
157 {
158 t = intervals[size - 1];
159 }
160
161 index = this->FindIndex(size,t);
162
163 t = (t - intervals[index]);
164
165 valueAndDerivatives[0] = (t * (t * (t * *(coefficients + index * 4 + 3)
166 + *(coefficients + index * 4 + 2))
167 + *(coefficients + index * 4 + 1))
168 + *(coefficients + index * 4));
169
170 valueAndDerivatives[1] = 3 * t * t * *(coefficients + index * 4 + 3) +
171 2 * t * *(coefficients + index * 4 + 2) +
172 + *(coefficients + index * 4 + 1);
173
174 valueAndDerivatives[2] = 6 * t * *(coefficients + index * 4 + 3) +
175 2 * *(coefficients + index * 4 + 2);
176}
177
178void vtkvmtkCardinalSpline::PrintSelf(std::ostream& os, vtkIndent indent)
179{
180 this->Superclass::PrintSelf(os,indent);
181}
182
Extends vtkCardinalSpline with methods to evaluate the spline's first derivative, second derivative,...
void PrintSelf(std::ostream &os, vtkIndent indent) override
virtual double EvaluateDerivative(double t)
virtual double EvaluateSecondDerivative(double t)
virtual void EvaluateValueAndDerivatives(double t, double valueAndDerivatives[3])
vtkStandardNewMacro(vtkvmtkCardinalSpline)