VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataLocalGeometry.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkPolyDataLocalGeometry.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
23#include "vtkTriangleFilter.h"
25#include "vtkPointData.h"
26#include "vtkCellData.h"
27#include "vtkCell.h"
28#include "vtkMath.h"
29#include "vtkDoubleArray.h"
30#include "vtkInformation.h"
31#include "vtkInformationVector.h"
32#include "vtkObjectFactory.h"
33#include "vtkVersion.h"
34
35#include "vtkvmtkConstants.h"
36
37
39
41{
42 this->ComputePoleVectors = 0;
47 this->ComputeCellIds = 0;
48 this->ComputePCoords = 0;
49
50 this->AdjustBoundaryValues = 0;
51
52 this->PoleVectorsArrayName = NULL;
53 this->GeodesicDistanceArrayName = NULL;
55 this->EuclideanDistanceArrayName = NULL;
56 this->CenterlineVectorsArrayName = NULL;
57 this->CellIdsArrayName = NULL;
58 this->PCoordsArrayName = NULL;
59
62 this->VoronoiCellIdsArrayName = NULL;
63 this->VoronoiPCoordsArrayName = NULL;
64 this->VoronoiDiagram = NULL;
65 this->PoleIds = NULL;
66}
67
69{
70 if (this->VoronoiDiagram)
71 {
72 this->VoronoiDiagram->Delete();
73 this->VoronoiDiagram = NULL;
74 }
75
76 if (this->PoleIds)
77 {
78 this->PoleIds->Delete();
79 this->PoleIds = NULL;
80 }
81
82 if (this->PoleVectorsArrayName)
83 {
84 delete[] this->PoleVectorsArrayName;
85 }
86
88 {
89 delete[] this->GeodesicDistanceArrayName;
90 }
91
93 {
95 }
96
98 {
99 delete[] this->EuclideanDistanceArrayName;
100 }
101
103 {
104 delete[] this->CenterlineVectorsArrayName;
105 }
106
107 if (this->CellIdsArrayName)
108 {
109 delete[] this->CellIdsArrayName;
110 }
111
112 if (this->PCoordsArrayName)
113 {
114 delete[] this->PCoordsArrayName;
115 }
116}
117
119 vtkInformation *vtkNotUsed(request),
120 vtkInformationVector **inputVector,
121 vtkInformationVector *outputVector)
122{
123 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
124 vtkInformation *outInfo = outputVector->GetInformationObject(0);
125
126 vtkPolyData *input = vtkPolyData::SafeDownCast(
127 inInfo->Get(vtkDataObject::DATA_OBJECT()));
128 vtkPolyData *output = vtkPolyData::SafeDownCast(
129 outInfo->Get(vtkDataObject::DATA_OBJECT()));
130
131 vtkIdType i, poleId;
132 double surfacePoint[3], polePoint[3], poleVector[3], voronoiPoleVector[3], centerlinePoint[3], centerlineVector[3];
133 double voronoiRadius, voronoiGeodesicDistance;
134 double geodesicDistance, normalizedTangencyDeviation;
135 double euclideanDistance;
136 vtkDataArray* voronoiGeodesicDistanceArray = NULL;
137 vtkDataArray* voronoiPoleVectorsArray = NULL;
138 vtkDataArray* voronoiCellIdsArray = NULL;
139 vtkDataArray* voronoiPCoordsArray = NULL;
140 vtkDoubleArray* poleVectorsArray = NULL;
141 vtkDoubleArray* geodesicDistanceArray = NULL;
142 vtkDoubleArray* normalizedTangencyDeviationArray = NULL;
143 vtkDoubleArray* euclideanDistanceArray = NULL;
144 vtkDoubleArray* centerlineVectorsArray = NULL;
145 vtkIntArray* cellIdsArray = NULL;
146 vtkDoubleArray* pcoordsArray = NULL;
147
148 if (!this->VoronoiDiagram)
149 {
150 vtkErrorMacro(<< "No Voronoi diagram specified!");
151 return 1;
152 }
153
154 if (!this->PoleIds)
155 {
156 vtkErrorMacro(<< "No poleIds specified!");
157 return 1;
158 }
159
161 {
163 {
164 vtkErrorMacro(<< "No Voronoi geodesic distance array name specified!");
165 return 1;
166 }
167
168 voronoiGeodesicDistanceArray = this->VoronoiDiagram->GetPointData()->GetArray(this->VoronoiGeodesicDistanceArrayName);
169 if (!voronoiGeodesicDistanceArray)
170 {
171 vtkErrorMacro(<< "Voronoi geodesic distance array with name specified does not exist!");
172 return 1;
173 }
174 }
175
177 {
179 {
180 vtkErrorMacro(<< "No Voronoi pole vectors array name specified!");
181 return 1;
182 }
183
184 voronoiPoleVectorsArray = this->VoronoiDiagram->GetPointData()->GetArray(this->VoronoiPoleCenterlineVectorsArrayName);
185 if (!voronoiPoleVectorsArray)
186 {
187 vtkErrorMacro(<< "Voronoi pole vectors array with name specified does not exist!");
188 return 1;
189 }
190 }
191
192
193 if (this->ComputeCellIds)
194 {
195 if (!this->VoronoiCellIdsArrayName)
196 {
197 vtkErrorMacro(<< "No Voronoi cellIds array name specified!");
198 return 1;
199 }
200
201 voronoiCellIdsArray = this->VoronoiDiagram->GetPointData()->GetArray(this->VoronoiCellIdsArrayName);
202 if (!voronoiCellIdsArray)
203 {
204 vtkErrorMacro(<< "Voronoi cellIds array with name specified does not exist!");
205 return 1;
206 }
207 }
208
209 if (this->ComputePCoords)
210 {
211 if (!this->VoronoiPCoordsArrayName)
212 {
213 vtkErrorMacro(<< "No Voronoi pcoords array name specified!");
214 return 1;
215 }
216
217 voronoiPCoordsArray = this->VoronoiDiagram->GetPointData()->GetArray(this->VoronoiPCoordsArrayName);
218 if (!voronoiPCoordsArray)
219 {
220 vtkErrorMacro(<< "Voronoi pcoords array with name specified does not exist!");
221 return 1;
222 }
223 }
224
225
226 if (this->ComputeGeodesicDistance)
227 {
228 if (!this->GeodesicDistanceArrayName)
229 {
230 vtkErrorMacro(<< "No geodesic distance array name specified!");
231 return 1;
232 }
233 }
234
236 {
238 {
239 vtkErrorMacro(<< "No normalized tangency deviation array name specified!");
240 return 1;
241 }
242 }
243
245 {
247 {
248 vtkErrorMacro(<< "No Euclidean distance array name specified!");
249 return 1;
250 }
251 }
252
253 if (this->ComputeCellIds)
254 {
255 if (!this->CellIdsArrayName)
256 {
257 vtkErrorMacro(<< "No cellIds array name specified!");
258 return 1;
259 }
260 }
261
262 if (this->ComputePCoords)
263 {
264 if (!this->PCoordsArrayName)
265 {
266 vtkErrorMacro(<< "No pcoords array name specified!");
267 return 1;
268 }
269 }
270
271 if (this->ComputePoleVectors)
272 {
273 if (!this->PoleVectorsArrayName)
274 {
275 vtkErrorMacro(<< "No pole vectors array name specified!");
276 return 1;
277 }
278 }
279
280 if (this->ComputePoleVectors)
281 {
282 poleVectorsArray = vtkDoubleArray::New();
283 poleVectorsArray->SetName(this->PoleVectorsArrayName);
284 poleVectorsArray->SetNumberOfComponents(3);
285 poleVectorsArray->SetNumberOfTuples(input->GetNumberOfPoints());
286 poleVectorsArray->FillComponent(0,0.0);
287 poleVectorsArray->FillComponent(1,0.0);
288 poleVectorsArray->FillComponent(2,0.0);
289 }
290
291 if (this->ComputeGeodesicDistance)
292 {
293 geodesicDistanceArray = vtkDoubleArray::New();
294 geodesicDistanceArray->SetName(this->GeodesicDistanceArrayName);
295 geodesicDistanceArray->SetNumberOfTuples(input->GetNumberOfPoints());
296 geodesicDistanceArray->FillComponent(0,0.0);
297 }
298
300 {
301 normalizedTangencyDeviationArray = vtkDoubleArray::New();
302 normalizedTangencyDeviationArray->SetName(this->NormalizedTangencyDeviationArrayName);
303 normalizedTangencyDeviationArray->SetNumberOfTuples(input->GetNumberOfPoints());
304 normalizedTangencyDeviationArray->FillComponent(0,0.0);
305 }
306
307 if (this->ComputeEuclideanDistance)
308 {
309 euclideanDistanceArray = vtkDoubleArray::New();
310 euclideanDistanceArray->SetName(this->EuclideanDistanceArrayName);
311 euclideanDistanceArray->SetNumberOfTuples(input->GetNumberOfPoints());
312 euclideanDistanceArray->FillComponent(0,0.0);
313 }
314
315 if (this->ComputeCenterlineVectors)
316 {
317 centerlineVectorsArray = vtkDoubleArray::New();
318 centerlineVectorsArray->SetNumberOfComponents(3);
319 centerlineVectorsArray->SetName(this->CenterlineVectorsArrayName);
320 centerlineVectorsArray->SetNumberOfTuples(input->GetNumberOfPoints());
321 centerlineVectorsArray->FillComponent(0,0.0);
322 centerlineVectorsArray->FillComponent(1,0.0);
323 centerlineVectorsArray->FillComponent(2,0.0);
324
325 }
326
327 if (this->ComputeCellIds)
328 {
329 cellIdsArray = vtkIntArray::New();
330 cellIdsArray->SetNumberOfComponents(2);
331 cellIdsArray->SetName(this->CellIdsArrayName);
332 cellIdsArray->SetNumberOfTuples(input->GetNumberOfPoints());
333 cellIdsArray->FillComponent(0,0.0);
334 cellIdsArray->FillComponent(1,0.0);
335 }
336
337 if (this->ComputePCoords)
338 {
339 pcoordsArray = vtkDoubleArray::New();
340 pcoordsArray->SetName(this->PCoordsArrayName);
341 pcoordsArray->SetNumberOfTuples(input->GetNumberOfPoints());
342 pcoordsArray->FillComponent(0,0.0);
343 }
344
345 for (i=0; i<input->GetNumberOfPoints(); i++)
346 {
347 poleId = this->PoleIds->GetId(i);
348
349 if (poleId == -1)
350 {
351 vtkWarningMacro(<<"Invalid PoleId found");
352 }
353
354 if (this->ComputePoleVectors)
355 {
356 input->GetPoint(i,surfacePoint);
357 this->VoronoiDiagram->GetPoint(poleId,polePoint);
358 poleVector[0] = polePoint[0] - surfacePoint[0];
359 poleVector[1] = polePoint[1] - surfacePoint[1];
360 poleVector[2] = polePoint[2] - surfacePoint[2];
361 poleVectorsArray->SetTuple(i,poleVector);
362 }
363
365 {
366 input->GetPoint(i,surfacePoint);
367 this->VoronoiDiagram->GetPoint(poleId,polePoint);
368
369 voronoiRadius = sqrt(vtkMath::Distance2BetweenPoints(surfacePoint,polePoint));
370 voronoiGeodesicDistance = voronoiGeodesicDistanceArray->GetTuple1(poleId);
371
372 geodesicDistance = voronoiGeodesicDistance + voronoiRadius;
373 if (geodesicDistance > VTK_VMTK_DOUBLE_TOL)
374 {
375 normalizedTangencyDeviation = voronoiGeodesicDistance / geodesicDistance;
376 }
377 else
378 {
379 normalizedTangencyDeviation = 1.0;
380 }
381
382 if (this->ComputeGeodesicDistance)
383 {
384 geodesicDistanceArray->SetComponent(i,0,geodesicDistance);
385 }
386
388 {
389 normalizedTangencyDeviationArray->SetComponent(i,0,normalizedTangencyDeviation);
390 }
391 }
392
394 {
395 input->GetPoint(i,surfacePoint);
396 this->VoronoiDiagram->GetPoint(poleId,polePoint);
397 voronoiPoleVectorsArray->GetTuple(poleId,voronoiPoleVector);
398 centerlinePoint[0] = polePoint[0] + voronoiPoleVector[0];
399 centerlinePoint[1] = polePoint[1] + voronoiPoleVector[1];
400 centerlinePoint[2] = polePoint[2] + voronoiPoleVector[2];
401 centerlineVector[0] = centerlinePoint[0] - surfacePoint[0];
402 centerlineVector[1] = centerlinePoint[1] - surfacePoint[1];
403 centerlineVector[2] = centerlinePoint[2] - surfacePoint[2];
404 if (this->ComputeEuclideanDistance)
405 {
406 euclideanDistance = sqrt(vtkMath::Distance2BetweenPoints(surfacePoint,centerlinePoint));
407 euclideanDistanceArray->SetComponent(i,0,euclideanDistance);
408 }
409 if (this->ComputeCenterlineVectors)
410 {
411 centerlineVectorsArray->SetTuple(i,centerlineVector);
412 }
413 }
414
415 if (this->ComputeCellIds)
416 {
417 cellIdsArray->SetTuple(i,voronoiCellIdsArray->GetTuple(poleId));
418 }
419
420 if (this->ComputePCoords)
421 {
422 pcoordsArray->SetTuple(i,voronoiPCoordsArray->GetTuple(poleId));
423 }
424 }
425
426 output->CopyStructure(input);
427 output->GetPointData()->PassData(input->GetPointData());
428 output->GetCellData()->PassData(input->GetCellData());
429
430 if (this->ComputePoleVectors)
431 {
432 output->GetPointData()->AddArray(poleVectorsArray);
433 poleVectorsArray->Delete();
434 }
435
436 if (this->ComputeGeodesicDistance)
437 {
438 output->GetPointData()->AddArray(geodesicDistanceArray);
439 geodesicDistanceArray->Delete();
440 }
441
443 {
444 output->GetPointData()->AddArray(normalizedTangencyDeviationArray);
445 normalizedTangencyDeviationArray->Delete();
446 }
447
448 if (this->ComputeEuclideanDistance)
449 {
450 output->GetPointData()->AddArray(euclideanDistanceArray);
451 euclideanDistanceArray->Delete();
452 }
453
454 if (this->ComputeCenterlineVectors)
455 {
456 output->GetPointData()->AddArray(centerlineVectorsArray);
457 centerlineVectorsArray->Delete();
458 }
459
460 if (this->ComputeCellIds)
461 {
462 output->GetPointData()->AddArray(cellIdsArray);
463 cellIdsArray->Delete();
464 }
465
466 if (this->ComputePCoords)
467 {
468 output->GetPointData()->AddArray(pcoordsArray);
469 pcoordsArray->Delete();
470 }
471
472 if (this->AdjustBoundaryValues)
473 {
474 this->AdjustBoundaryQuantities(output);
475 }
476
477 return 1;
478}
479
481{
482 vtkDataArray* poleVectorsArray = NULL;
483 vtkDataArray* geodesicDistanceArray = NULL;
484 vtkDataArray* euclideanDistanceArray = NULL;
485 vtkDataArray* centerlineVectorsArray = NULL;
486
487 vtkTriangleFilter* triangleFilter = vtkTriangleFilter::New();
488 triangleFilter->SetInputData(output);
489 triangleFilter->Update();
490
492 boundaryExtractor->SetInputConnection(triangleFilter->GetOutputPort());
493 boundaryExtractor->Update();
494
495 vtkPolyData* boundaries = boundaryExtractor->GetOutput();
496
497 double point[3], barycenter[3];
498 int numberOfBoundaryPoints;
499
500 if (this->ComputePoleVectors)
501 {
502 poleVectorsArray = output->GetPointData()->GetArray(this->PoleVectorsArrayName);
503 }
504
505 if (this->ComputeGeodesicDistance)
506 {
507 geodesicDistanceArray = output->GetPointData()->GetArray(this->GeodesicDistanceArrayName);
508 }
509
510 if (this->ComputeEuclideanDistance)
511 {
512 euclideanDistanceArray = output->GetPointData()->GetArray(this->EuclideanDistanceArrayName);
513 }
514
515 if (this->ComputeCenterlineVectors)
516 {
517 centerlineVectorsArray = output->GetPointData()->GetArray(this->CenterlineVectorsArrayName);
518 }
519
520 double radialVector[3], radialVectorModulus;
521 vtkIdType boundaryPointId;
522
523 int i, j;
524 for (i=0; i<boundaries->GetNumberOfCells(); i++)
525 {
526 vtkCell* boundary = boundaries->GetCell(i);
527 numberOfBoundaryPoints = boundary->GetPoints()->GetNumberOfPoints();
528 barycenter[0] = barycenter[1] = barycenter[2] = 0.0;
529 for (j=0; j<numberOfBoundaryPoints; j++)
530 {
531 boundary->GetPoints()->GetPoint(j,point);
532 barycenter[0] += point[0];
533 barycenter[1] += point[1];
534 barycenter[2] += point[2];
535 }
536 barycenter[0] /= numberOfBoundaryPoints;
537 barycenter[1] /= numberOfBoundaryPoints;
538 barycenter[2] /= numberOfBoundaryPoints;
539
540 for (j=0; j<numberOfBoundaryPoints; j++)
541 {
542 boundaryPointId = static_cast<vtkIdType>(boundaries->GetPointData()->GetScalars()->GetTuple1(boundary->GetPointId(j)));
543 output->GetPoint(boundaryPointId,point);
544 radialVector[0] = barycenter[0] - point[0];
545 radialVector[1] = barycenter[1] - point[1];
546 radialVector[2] = barycenter[2] - point[2];
547 radialVectorModulus = vtkMath::Norm(radialVector);
548
549 if (this->ComputePoleVectors)
550 {
551 poleVectorsArray->SetTuple(boundaryPointId,radialVector);
552 }
553
554 if (this->ComputeGeodesicDistance)
555 {
556 geodesicDistanceArray->SetTuple1(boundaryPointId,radialVectorModulus);
557 }
558
559 if (this->ComputeEuclideanDistance)
560 {
561 euclideanDistanceArray->SetTuple1(boundaryPointId,radialVectorModulus);
562 }
563
564 if (this->ComputeCenterlineVectors)
565 {
566 centerlineVectorsArray->SetTuple(boundaryPointId,radialVector);
567 }
568 }
569 }
570
571 triangleFilter->Delete();
572 boundaryExtractor->Delete();
573}
574
575void vtkvmtkPolyDataLocalGeometry::PrintSelf(std::ostream& os, vtkIndent indent)
576{
577 this->Superclass::PrintSelf(os,indent);
578}
Extract boundary edges as poly lines.
static vtkvmtkPolyDataBoundaryExtractor * New()
Compute shape-related quantities over a surface.
void AdjustBoundaryQuantities(vtkPolyData *output)
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
#define VTK_VMTK_DOUBLE_TOL
vtkStandardNewMacro(vtkvmtkPolyDataLocalGeometry)