VMTK
Loading...
Searching...
No Matches
vtkvmtkCenterlineSplitExtractor.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkCenterlineSplitExtractor.cxx,v $
5Language: C++
6Date: $Date: 2005/10/06 11:01:44 $
7Version: $Revision: 1.6 $
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
24#include "vtkvmtkPolyBallLine.h"
25#include "vtkPolyData.h"
26#include "vtkPolyLine.h"
27#include "vtkDoubleArray.h"
28#include "vtkMath.h"
29#include "vtkObjectFactory.h"
30
31
33
35{
36 this->SplitPoint[0] = 0.0;
37 this->SplitPoint[1] = 0.0;
38 this->SplitPoint[2] = 0.0;
39
40 this->SplitPoint2[0] = 0.0;
41 this->SplitPoint2[1] = 0.0;
42 this->SplitPoint2[2] = 0.0;
43
44 this->Tolerance = 1E-4;
45
46 this->GapLength = 1.0;
47
50}
51
55
57{
59 tube->SetInput(input);
60 tube->SetInputCellId(cellId);
62 double tubeFunctionValue = tube->EvaluateFunction(this->SplitPoint);
63
64 if (tubeFunctionValue > this->Tolerance)
65 {
67 return;
68 }
69
70 vtkIdType centerlineSubId = tube->GetLastPolyBallCellSubId();
71 double centerlinePCoord = tube->GetLastPolyBallCellPCoord();
72 double centerlinePoint[3];
73 tube->GetLastPolyBallCenter(centerlinePoint);
74
76
77 if (this->SubIds)
78 {
79 delete[] this->SubIds;
80 this->SubIds = NULL;
81 }
82
83 if (this->PCoords)
84 {
85 delete[] this->PCoords;
86 this->PCoords = NULL;
87 }
88
89 if (this->TractBlanking)
90 {
91 delete[] this->TractBlanking;
92 this->TractBlanking = NULL;
93 }
94
95 vtkCell* centerline = input->GetCell(cellId);
96
97 if (centerline->GetCellType() != VTK_LINE && centerline->GetCellType() != VTK_POLY_LINE)
98 {
99 return;
100 }
101
102 this->SubIds = new vtkIdType[this->NumberOfSplittingPoints];
103 this->PCoords = new double[this->NumberOfSplittingPoints];
104
105 int numberOfCenterlinePoints = centerline->GetNumberOfPoints();
106 int numberOfCenterlineSubIds = centerline->GetNumberOfPoints() - 1;
107
108 double currentAbscissa = 0.0;
109 vtkDoubleArray* abscissas = vtkDoubleArray::New();
110 abscissas->InsertNextValue(currentAbscissa);
111 double point[3], previousPoint[3];
112 centerline->GetPoints()->GetPoint(0,previousPoint);
113 int i;
114 for (i=1; i<numberOfCenterlinePoints; i++)
115 {
116 centerline->GetPoints()->GetPoint(i,point);
117 currentAbscissa += sqrt(vtkMath::Distance2BetweenPoints(previousPoint,point));
118 abscissas->InsertNextValue(currentAbscissa);
119 previousPoint[0] = point[0];
120 previousPoint[1] = point[1];
121 previousPoint[2] = point[2];
122 }
123
124 double halfGapLength = this->GapLength * 0.5;
125
126 double centerlinePointAbscissa = (1.0 - centerlinePCoord) * abscissas->GetValue(centerlineSubId) + centerlinePCoord * abscissas->GetValue(centerlineSubId+1);
127
128 double abscissa;
129 int lastSubId = numberOfCenterlineSubIds - 1;
130 for (i=centerlineSubId; i<numberOfCenterlineSubIds; i++)
131 {
132 abscissa = abscissas->GetValue(i+1);
133 if (abscissa - centerlinePointAbscissa > halfGapLength)
134 {
135 lastSubId = i;
136 break;
137 }
138 }
139 double lastPCoord = (centerlinePointAbscissa + halfGapLength - abscissas->GetValue(lastSubId)) / (abscissas->GetValue(lastSubId+1) - abscissas->GetValue(lastSubId));
140 if (lastPCoord > 1.0)
141 {
142 lastPCoord = 1.0 - 1E-1;
143 }
144
145 int firstSubId = 0;
146 for (i=centerlineSubId; i>=0; i--)
147 {
148 abscissa = abscissas->GetValue(i);
149 if (centerlinePointAbscissa - abscissa > halfGapLength)
150 {
151 firstSubId = i;
152 break;
153 }
154 }
155 double firstPCoord = (centerlinePointAbscissa - halfGapLength - abscissas->GetValue(firstSubId)) / (abscissas->GetValue(firstSubId+1) - abscissas->GetValue(firstSubId));
156 if (firstPCoord < 0.0)
157 {
158 firstPCoord = 0.0 + 1E-1;
159 }
160
161 this->SubIds[0] = firstSubId;
162 this->PCoords[0] = firstPCoord;
163
164 this->SubIds[1] = lastSubId;
165 this->PCoords[1] = lastPCoord;
166
167 this->TractBlanking = new int[this->NumberOfSplittingPoints+1];
168
169 this->TractBlanking[0] = 0;
170 this->TractBlanking[1] = 1;
171 this->TractBlanking[2] = 0;
172
173 abscissas->Delete();
174}
175
177{
179 tube->SetInput(input);
180 tube->SetInputCellId(cellId);
182 double tubeFunctionValue = tube->EvaluateFunction(this->SplitPoint);
183
184 if (tubeFunctionValue > this->Tolerance)
185 {
186 this->NumberOfSplittingPoints = 0;
187 return;
188 }
189
190 vtkIdType centerlineSubId = tube->GetLastPolyBallCellSubId();
191 double centerlinePCoord = tube->GetLastPolyBallCellPCoord();
192 double centerlinePoint[3];
193 tube->GetLastPolyBallCenter(centerlinePoint);
194
195 double tubeFunctionValue2 = tube->EvaluateFunction(this->SplitPoint2);
196
197 if (tubeFunctionValue2 > this->Tolerance)
198 {
199 this->NumberOfSplittingPoints = 0;
200 return;
201 }
202
203 vtkIdType centerlineSubId2 = tube->GetLastPolyBallCellSubId();
204 double centerlinePCoord2 = tube->GetLastPolyBallCellPCoord();
205 double centerlinePoint2[3];
206 tube->GetLastPolyBallCenter(centerlinePoint2);
207
208 this->NumberOfSplittingPoints = 2;
209
210 if (this->SubIds)
211 {
212 delete[] this->SubIds;
213 this->SubIds = NULL;
214 }
215
216 if (this->PCoords)
217 {
218 delete[] this->PCoords;
219 this->PCoords = NULL;
220 }
221
222 if (this->TractBlanking)
223 {
224 delete[] this->TractBlanking;
225 this->TractBlanking = NULL;
226 }
227
228 vtkCell* centerline = input->GetCell(cellId);
229
230 if (centerline->GetCellType() != VTK_LINE && centerline->GetCellType() != VTK_POLY_LINE)
231 {
232 return;
233 }
234
235 this->SubIds = new vtkIdType[this->NumberOfSplittingPoints];
236 this->PCoords = new double[this->NumberOfSplittingPoints];
237
238 if (centerlineSubId > centerlineSubId2 || (centerlineSubId == centerlineSubId2 && centerlinePCoord > centerlinePCoord2))
239 {
240 this->SubIds[0] = centerlineSubId;
241 this->PCoords[0] = centerlinePCoord;
242
243 this->SubIds[1] = centerlineSubId2;
244 this->PCoords[1] = centerlinePCoord2;
245 }
246 else
247 {
248 this->SubIds[0] = centerlineSubId2;
249 this->PCoords[0] = centerlinePCoord2;
250
251 this->SubIds[1] = centerlineSubId;
252 this->PCoords[1] = centerlinePCoord;
253 }
254
255 this->TractBlanking = new int[this->NumberOfSplittingPoints+1];
256
257 this->TractBlanking[0] = 0;
258 this->TractBlanking[1] = 1;
259 this->TractBlanking[2] = 0;
260}
261
262void vtkvmtkCenterlineSplitExtractor::ComputeCenterlineSplitting(vtkPolyData* input, vtkIdType cellId)
263{
264 if (this->SplittingMode == POINTANDGAP)
265 {
266 this->ComputePointAndGapCenterlineSplitting(input,cellId);
267 }
268 else if (this->SplittingMode == BETWEENPOINTS)
269 {
270 this->ComputeBetweenPointsCenterlineSplitting(input,cellId);
271 }
272 else
273 {
274 vtkErrorMacro("Error: unsupported splitting mode");
275 }
276}
277
278void vtkvmtkCenterlineSplitExtractor::PrintSelf(std::ostream& os, vtkIndent indent)
279{
280 this->Superclass::PrintSelf(os,indent);
281}
Split a centerline into three tracts with the middle (blanked) tract being initialized between any tw...
void PrintSelf(std::ostream &os, vtkIndent indent) override
virtual void ComputeCenterlineSplitting(vtkPolyData *input, vtkIdType cellId) override
virtual void ComputePointAndGapCenterlineSplitting(vtkPolyData *input, vtkIdType cellId)
virtual void ComputeBetweenPointsCenterlineSplitting(vtkPolyData *input, vtkIdType cellId)
void PrintSelf(std::ostream &os, vtkIndent indent) override
Implements vtkImplicitFunction to evaluate the minimum sphere function for an envelope created by an ...
virtual double * GetLastPolyBallCenter()
virtual void SetInputCellId(vtkIdType)
virtual double GetLastPolyBallCellPCoord()
virtual void SetInput(vtkPolyData *)
static vtkvmtkPolyBallLine * New()
double EvaluateFunction(double x[3]) override
virtual vtkIdType GetLastPolyBallCellSubId()
virtual void UseRadiusInformationOff()
vtkStandardNewMacro(vtkvmtkCenterlineSplitExtractor)