VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyBallLine.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkPolyBallLine.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:46:43 $
7Version: $Revision: 1.5 $
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=========================================================================*/
21#include "vtkvmtkPolyBallLine.h"
22#include "vtkvmtkConstants.h"
23#include "vtkPointData.h"
24#include "vtkPolyLine.h"
25#include "vtkObjectFactory.h"
26#include "vtkVersion.h"
27
28
30
32{
33 this->Input = NULL;
34 this->InputCellIds = NULL;
35 this->InputCellId = -1;
36 this->PolyBallRadiusArrayName = NULL;
37 this->LastPolyBallCellId = -1;
38 this->LastPolyBallCellSubId = -1;
39 this->LastPolyBallCellPCoord = 0.0;
40 this->LastPolyBallCenter[0] = this->LastPolyBallCenter[1] = this->LastPolyBallCenter[2] = 0.0;
41 this->LastPolyBallCenterRadius = 0.0;
42 this->UseRadiusInformation = 1;
43}
44
46{
47 if (this->Input)
48 {
49 this->Input->Delete();
50 this->Input = NULL;
51 }
52
53 if (this->InputCellIds)
54 {
55 this->InputCellIds->Delete();
56 this->InputCellIds = NULL;
57 }
58
60 {
61 delete[] this->PolyBallRadiusArrayName;
62 this->PolyBallRadiusArrayName = NULL;
63 }
64}
65
66double vtkvmtkPolyBallLine::ComplexDot(double x[4], double y[4])
67{
68 return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] - x[3]*y[3];
69}
70
72{
73 vtkIdType i, k;
74 vtkIdType npts;
75 const vtkIdType *pts;
76 double polyballFunctionValue, minPolyBallFunctionValue;
77 double point0[3], point1[3];
78 double radius0, radius1;
79 double vector0[4], vector1[4], closestPoint[4];
80 double t;
81 double num, den;
82 vtkDataArray *polyballRadiusArray = NULL;
83
84 if (!this->Input)
85 {
86 vtkErrorMacro(<<"No Input specified!");
87 return 0.0;
88 }
89
90 if (this->Input->GetNumberOfPoints()==0)
91 {
92 vtkWarningMacro(<<"Empty Input specified!");
93 return 0.0;
94 }
95
96 if (this->UseRadiusInformation)
97 {
98 if (!this->PolyBallRadiusArrayName)
99 {
100 vtkErrorMacro(<<"No PolyBallRadiusArrayName specified!");
101 return 0.0;
102 }
103
104 polyballRadiusArray = this->Input->GetPointData()->GetArray(this->PolyBallRadiusArrayName);
105
106 if (polyballRadiusArray==NULL)
107 {
108 vtkErrorMacro(<<"PolyBallRadiusArray with name specified does not exist!");
109 return 0.0;
110 }
111 }
112
113 if (this->Input->GetLines()==NULL)
114 {
115 vtkWarningMacro(<<"No lines in Input dataset.");
116 return 0.0;
117 }
118
119 this->Input->BuildCells();
120
121 minPolyBallFunctionValue = VTK_VMTK_LARGE_DOUBLE;
122
123 closestPoint[0] = closestPoint[1] = closestPoint[2] = closestPoint[2] = 0.0;
124
125 this->LastPolyBallCellId = -1;
126 this->LastPolyBallCellSubId = -1;
127 this->LastPolyBallCellPCoord = 0.0;
128 this->LastPolyBallCenter[0] = this->LastPolyBallCenter[1] = this->LastPolyBallCenter[2] = 0.0;
129 this->LastPolyBallCenterRadius = 0.0;
130
131 vtkIdList* cellIds = vtkIdList::New();
132
133 if (this->InputCellIds)
134 {
135 cellIds->DeepCopy(this->InputCellIds);
136 }
137 else if (this->InputCellId != -1)
138 {
139 cellIds->InsertNextId(this->InputCellId);
140 }
141 else
142 {
143 cellIds->SetNumberOfIds(this->Input->GetNumberOfCells());
144 for (k=0; k<this->Input->GetNumberOfCells(); k++)
145 {
146 cellIds->SetId(k,k);
147 }
148 }
149
150 for (k=0; k<cellIds->GetNumberOfIds(); k++)
151 {
152 vtkIdType cellId = cellIds->GetId(k);
153
154 if (this->Input->GetCellType(cellId)!=VTK_LINE && this->Input->GetCellType(cellId)!=VTK_POLY_LINE)
155 {
156 continue;
157 }
158
159 this->Input->GetCellPoints(cellId,npts,pts);
160
161 for (i=0; i<npts-1; i++)
162 {
163 this->Input->GetPoint(pts[i],point0);
164 this->Input->GetPoint(pts[i+1],point1);
165 if (this->UseRadiusInformation)
166 {
167 radius0 = polyballRadiusArray->GetComponent(pts[i],0);
168 radius1 = polyballRadiusArray->GetComponent(pts[i+1],0);
169 }
170 else
171 {
172 radius0 = 0.0;
173 radius1 = 0.0;
174 }
175 vector0[0] = point1[0] - point0[0];
176 vector0[1] = point1[1] - point0[1];
177 vector0[2] = point1[2] - point0[2];
178 vector0[3] = radius1 - radius0;
179 vector1[0] = x[0] - point0[0];
180 vector1[1] = x[1] - point0[1];
181 vector1[2] = x[2] - point0[2];
182 vector1[3] = 0.0 - radius0;
183
184// cout<<x[0]<<" "<<x[1]<<" "<<x[2]<<" "<<point0[0]<<" "<<point0[1]<<" "<<point0[2]<<" "<<point1[0]<<" "<<point1[1]<<" "<<point1[2]<<" "<<endl;
185
186 num = this->ComplexDot(vector0,vector1);
187 den = this->ComplexDot(vector0,vector0);
188
189 if (fabs(den)<VTK_VMTK_DOUBLE_TOL)
190 {
191 continue;
192 }
193
194 t = num / den;
195
197 {
198 t = 0.0;
199 closestPoint[0] = point0[0];
200 closestPoint[1] = point0[1];
201 closestPoint[2] = point0[2];
202 closestPoint[3] = radius0;
203 }
204 else if (1.0-t<VTK_VMTK_DOUBLE_TOL)
205 {
206 t = 1.0;
207 closestPoint[0] = point1[0];
208 closestPoint[1] = point1[1];
209 closestPoint[2] = point1[2];
210 closestPoint[3] = radius1;
211 }
212 else
213 {
214 closestPoint[0] = point0[0] + t * vector0[0];
215 closestPoint[1] = point0[1] + t * vector0[1];
216 closestPoint[2] = point0[2] + t * vector0[2];
217 closestPoint[3] = radius0 + t * vector0[3];
218 }
219
220 polyballFunctionValue = (x[0]-closestPoint[0])*(x[0]-closestPoint[0]) + (x[1]-closestPoint[1])*(x[1]-closestPoint[1]) + (x[2]-closestPoint[2])*(x[2]-closestPoint[2]) - closestPoint[3]*closestPoint[3];
221
222 if (polyballFunctionValue<minPolyBallFunctionValue)
223 {
224 minPolyBallFunctionValue = polyballFunctionValue;
225 this->LastPolyBallCellId = cellId;
226 this->LastPolyBallCellSubId = i;
227 this->LastPolyBallCellPCoord = t;
228 this->LastPolyBallCenter[0] = closestPoint[0];
229 this->LastPolyBallCenter[1] = closestPoint[1];
230 this->LastPolyBallCenter[2] = closestPoint[2];
231 this->LastPolyBallCenterRadius = closestPoint[3];
232 }
233 }
234 }
235
236 cellIds->Delete();
237
238 return minPolyBallFunctionValue;
239}
240
241void vtkvmtkPolyBallLine::EvaluateGradient(double x[3], double n[3])
242{
243 vtkWarningMacro("Poly ball gradient computation not yet implemented!");
244 // TODO
245}
246
247void vtkvmtkPolyBallLine::PrintSelf(std::ostream& os, vtkIndent indent)
248{
249 this->Superclass::PrintSelf(os,indent);
250
251}
Implements vtkImplicitFunction to evaluate the minimum sphere function for an envelope created by an ...
static double ComplexDot(double x[4], double y[4])
void EvaluateGradient(double x[3], double n[3]) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
double EvaluateFunction(double x[3]) override
#define VTK_VMTK_DOUBLE_TOL
#define VTK_VMTK_LARGE_DOUBLE
vtkStandardNewMacro(vtkvmtkPolyBallLine)