VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataDijkstraDistanceToPoints.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataDijkstraDistanceToPoints.cxx,v $
5 Language: C++
6 Date: $$
7 Version: $$
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=========================================================================*/
25
27
28#include "vtkVersion.h"
29#include "vtkPointData.h"
30#include "vtkDoubleArray.h"
31#include "vtkFloatArray.h"
32#include "vtkMath.h"
33#include "vtkInformation.h"
34#include "vtkInformationVector.h"
35#include "vtkObjectFactory.h"
36#include "vtkIOStream.h"
37
38#include "vtkvmtkConstants.h"
39
40#include "vtkDijkstraGraphGeodesicPath.h"
41
43
45{
47
48 this->SeedIds = NULL;
49
50 this->DistanceOffset = 0.;
51 this->DistanceScale = 1.;
52 this->MinDistance = 0.;
53 this->MaxDistance = -1.;
54}
55
57{
59 {
62 }
63
64 if (this->SeedIds)
65 {
66 this->SeedIds->Delete();
67 this->SeedIds = NULL;
68 }
69}
70
72 vtkInformation *vtkNotUsed(request),
73 vtkInformationVector **inputVector,
74 vtkInformationVector *outputVector)
75{
76 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
77 vtkInformation *outInfo = outputVector->GetInformationObject(0);
78
79 vtkPolyData *input = vtkPolyData::SafeDownCast(
80 inInfo->Get(vtkDataObject::DATA_OBJECT()));
81 vtkPolyData *output = vtkPolyData::SafeDownCast(
82 outInfo->Get(vtkDataObject::DATA_OBJECT()));
83
85 {
86 vtkErrorMacro(<<"DijkstraDistanceToPointsArrayName not set.");
87 return 1;
88 }
89
90 if (!this->SeedIds)
91 {
92 vtkErrorMacro(<<"SeedIds not set");
93 return 1;
94 }
95
96 int numberOfInputPoints = input->GetNumberOfPoints();
97
98 output->DeepCopy(input);
99
100
101 vtkDataArray* distanceToPointsArray = output->GetPointData()->GetArray(this->DijkstraDistanceToPointsArrayName);
102
103 bool createArray = !distanceToPointsArray;
104
105 if (createArray)
106 {
107 distanceToPointsArray = vtkDoubleArray::New();
108 distanceToPointsArray->SetName(this->DijkstraDistanceToPointsArrayName);
109 distanceToPointsArray->SetNumberOfComponents(1);
110 distanceToPointsArray->SetNumberOfTuples(numberOfInputPoints);
111 distanceToPointsArray->FillComponent(0, VTK_VMTK_LARGE_DOUBLE);
112
113 output->GetPointData()->AddArray(distanceToPointsArray);
114 }
115
116 int numberOfSeeds = this->SeedIds->GetNumberOfIds();
117
118 vtkDijkstraGraphGeodesicPath *dijkstraAlgo = vtkDijkstraGraphGeodesicPath::New();
119 dijkstraAlgo->SetInputData(input);
120 dijkstraAlgo->StopWhenEndReachedOff();
121 dijkstraAlgo->UseScalarWeightsOff();
122
123 double maxd = this->MaxDistance > 0 ? this->MaxDistance : VTK_VMTK_LARGE_DOUBLE;
124
125 for (int i=0; i<numberOfSeeds; i++)
126 {
127 dijkstraAlgo->SetStartVertex(SeedIds->GetId(i));
128 dijkstraAlgo->Update();
129 vtkDoubleArray *seedDistances = vtkDoubleArray::New();
130 dijkstraAlgo->GetCumulativeWeights(seedDistances);
131 for (int i=0;i<numberOfInputPoints;i++)
132 {
133 double newDist = this->DistanceOffset + this->DistanceScale*seedDistances->GetValue(i);
134 if (newDist<this->MinDistance) newDist = this->MinDistance;
135 if (newDist>maxd) newDist = maxd;
136 if (newDist<distanceToPointsArray->GetComponent(i,0)) distanceToPointsArray->SetComponent(i,0,newDist);
137 }
138 seedDistances->Delete();
139 }
140
141
142 if (createArray) distanceToPointsArray->Delete();
143
144 return 1;
145}
Compute the geodesic (graph) distance from a set of seed points over a surface mesh using Dijkstra's ...
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
#define VTK_VMTK_LARGE_DOUBLE
vtkStandardNewMacro(vtkvmtkPolyDataDijkstraDistanceToPoints)