VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataDistanceToCenterlines.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataDistanceToCenterlines.cxx,v $
5 Language: C++
6 Date: $Date: 2005/03/31 15:07:48 $
7 Version: $Revision: 1.3 $
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 "vtkPointData.h"
24#include "vtkDoubleArray.h"
25#include "vtkvmtkPolyBallLine.h"
26#include "vtkCell.h"
27#include "vtkMath.h"
28#include "vtkInformation.h"
29#include "vtkInformationVector.h"
30#include "vtkObjectFactory.h"
31
32
34
47
49{
51 {
52 delete[] this->DistanceToCenterlinesArrayName;
54 }
55
56 if (this->Centerlines)
57 {
58 this->Centerlines->Delete();
59 this->Centerlines = NULL;
60 }
61
63 {
64 delete[] this->CenterlineRadiusArrayName;
65 this->CenterlineRadiusArrayName = NULL;
66 }
67}
68
70 vtkInformation *vtkNotUsed(request),
71 vtkInformationVector **inputVector,
72 vtkInformationVector *outputVector)
73{
74 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
75 vtkInformation *outInfo = outputVector->GetInformationObject(0);
76
77 vtkPolyData *input = vtkPolyData::SafeDownCast(
78 inInfo->Get(vtkDataObject::DATA_OBJECT()));
79 vtkPolyData *output = vtkPolyData::SafeDownCast(
80 outInfo->Get(vtkDataObject::DATA_OBJECT()));
81
83 {
84 vtkErrorMacro(<<"DistanceToCenterlinesArrayName not set.");
85 return 1;
86 }
87
88 if (!this->Centerlines)
89 {
90 vtkErrorMacro(<<"Centerlines not set");
91 return 1;
92 }
93
95 {
96 this->UseRadiusInformation = 1;
97 }
98
99 if (this->UseRadiusInformation)
100 {
101 if (!this->CenterlineRadiusArrayName)
102 {
103 vtkErrorMacro(<<"CenterlineRadiusArrayName not set.");
104 return 1;
105 }
106
107 vtkDataArray* centerlineRadiusArray = this->Centerlines->GetPointData()->GetArray(this->CenterlineRadiusArrayName);
108
109 if (!centerlineRadiusArray)
110 {
111 vtkErrorMacro(<<"CenterlineRadiusArrayName with name specified does not exist.");
112 return 1;
113 }
114 }
115
116 int numberOfInputPoints = input->GetNumberOfPoints();
117
118 output->DeepCopy(input);
119
120 vtkDoubleArray* distanceToCenterlinesArray = vtkDoubleArray::New();
121 distanceToCenterlinesArray->SetName(this->DistanceToCenterlinesArrayName);
122 distanceToCenterlinesArray->SetNumberOfComponents(1);
123 distanceToCenterlinesArray->SetNumberOfTuples(numberOfInputPoints);
124 distanceToCenterlinesArray->FillComponent(0,0.0);
125
126 output->GetPointData()->AddArray(distanceToCenterlinesArray);
127
128 vtkDoubleArray* surfaceCenterlineRadiusArray = NULL;
129 if (this->EvaluateCenterlineRadius)
130 {
131 surfaceCenterlineRadiusArray = vtkDoubleArray::New();
132 surfaceCenterlineRadiusArray->SetName(this->CenterlineRadiusArrayName);
133 surfaceCenterlineRadiusArray->SetNumberOfComponents(1);
134 surfaceCenterlineRadiusArray->SetNumberOfTuples(numberOfInputPoints);
135 surfaceCenterlineRadiusArray->FillComponent(0,0.0);
136
137 output->GetPointData()->AddArray(surfaceCenterlineRadiusArray);
138 }
139
141 tube->SetInput(this->Centerlines);
143 if (this->UseRadiusInformation)
144 {
146 }
147
148 if (this->ProjectPointArrays)
149 {
150 output->GetPointData()->InterpolateAllocate(this->Centerlines->GetPointData(),numberOfInputPoints);
151 }
152
153 double point[3], centerlinePoint[3];
154 double distanceToCenterlines = 0.0;
155 for (int i=0; i<numberOfInputPoints; i++)
156 {
157 input->GetPoint(i,point);
158 double tubeFunctionValue = tube->EvaluateFunction(point);
159 if (this->EvaluateTubeFunction)
160 {
161 distanceToCenterlines = tubeFunctionValue;
162 }
163 else
164 {
165 tube->GetLastPolyBallCenter(centerlinePoint);
166 distanceToCenterlines = sqrt(vtkMath::Distance2BetweenPoints(point,centerlinePoint));
167 }
168 distanceToCenterlinesArray->SetComponent(i,0,distanceToCenterlines);
169 if (this->EvaluateCenterlineRadius)
170 {
171 surfaceCenterlineRadiusArray->SetComponent(i,0,tube->GetLastPolyBallCenterRadius());
172 }
173
174 if (this->ProjectPointArrays)
175 {
176 vtkIdType cellId = tube->GetLastPolyBallCellId();
177 vtkIdType subId = tube->GetLastPolyBallCellSubId();
178 vtkIdType pcoord = tube->GetLastPolyBallCellPCoord();
179 vtkCell* cell = this->Centerlines->GetCell(cellId);
180 vtkIdType pointId0 = cell->GetPointId(subId);
181 vtkIdType pointId1 = cell->GetPointId(subId+1);
182 output->GetPointData()->InterpolateEdge(this->Centerlines->GetPointData(),i,pointId0,pointId1,pcoord);
183 }
184 }
185
186 tube->Delete();
187 distanceToCenterlinesArray->Delete();
188 if (surfaceCenterlineRadiusArray)
189 {
190 surfaceCenterlineRadiusArray->Delete();
191 }
192
193 return 1;
194}
Implements vtkImplicitFunction to evaluate the minimum sphere function for an envelope created by an ...
virtual double * GetLastPolyBallCenter()
virtual double GetLastPolyBallCenterRadius()
virtual double GetLastPolyBallCellPCoord()
virtual void SetInput(vtkPolyData *)
virtual void SetPolyBallRadiusArrayName(const char *)
virtual void SetUseRadiusInformation(int)
virtual vtkIdType GetLastPolyBallCellId()
static vtkvmtkPolyBallLine * New()
double EvaluateFunction(double x[3]) override
virtual vtkIdType GetLastPolyBallCellSubId()
Calculate the minimum Euclidean distance from surface points to a centerline.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
vtkStandardNewMacro(vtkvmtkPolyDataDistanceToCenterlines)