VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataCenterlineAngularMetricFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataCenterlineAngularMetricFilter.cxx,v $
5 Language: C++
6 Date: $Date: 2006/04/06 16:46:43 $
7 Version: $Revision: 1.9 $
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 "vtkCellData.h"
25#include "vtkDoubleArray.h"
26#include "vtkvmtkPolyBallLine.h"
27#include "vtkPolyLine.h"
28#include "vtkCell.h"
29#include "vtkMath.h"
30#include "vtkPlane.h"
31#include "vtkvmtkConstants.h"
32#include "vtkvmtkMath.h"
33#include "vtkObjectFactory.h"
34
36
37
39
44
53
54void vtkvmtkPolyDataCenterlineAngularMetricFilter::EvaluateMetric(vtkIdType pointId, double point[3], vtkIdType groupId, vtkDataArray* metricArray)
55{
56 vtkDataArray* centerlineGroupIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineGroupIdsArrayName);
57 vtkDataArray* centerlineTractIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineTractIdsArrayName);
58 vtkDataArray* blankingArray = this->Centerlines->GetCellData()->GetArray(this->BlankingArrayName);
59 vtkDataArray* centerlineIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineIdsArrayName);
60
62 vtkIdList* centerlineGroupCellIds = vtkIdList::New();
63
64 tube->SetInput(this->Centerlines);
65 tube->SetInputCellIds(centerlineGroupCellIds);
68
69 double averagePoint[3];
70 averagePoint[0] = averagePoint[1] = averagePoint[2] = 0.0;
71 double averageNormal[3];
72 averageNormal[0] = averageNormal[1] = averageNormal[2] = 0.0;
73 double averageTangent[3];
74 averageTangent[0] = averageTangent[1] = averageTangent[2] = 0.0;
75 double weightSum = 0.0;
76
77 int numberOfCenterlineCells = this->Centerlines->GetNumberOfCells();
78 for (int i=0; i<numberOfCenterlineCells; i++)
79 {
80 int centerlineGroupId = static_cast<int>(centerlineGroupIdsArray->GetComponent(i,0));
81 if (centerlineGroupId != groupId)
82 {
83 continue;
84 }
85
86 centerlineGroupCellIds->Initialize();
87 centerlineGroupCellIds->InsertNextId(i);
88
89 if (this->IncludeBifurcations)
90 {
91 int centerlineId = static_cast<int>(centerlineIdsArray->GetComponent(i,0));
92 int centerlineTractId = static_cast<int>(centerlineTractIdsArray->GetComponent(i,0));
93
94 for (int j=0; j<numberOfCenterlineCells; j++)
95 {
96 if (j==i)
97 {
98 continue;
99 }
100
101 int adjacentCenterlineGroupId = static_cast<int>(centerlineGroupIdsArray->GetComponent(j,0));
102 int adjacentCenterlineId = static_cast<int>(centerlineIdsArray->GetComponent(j,0));
103 int adjacentCenterlineTractId = static_cast<int>(centerlineTractIdsArray->GetComponent(j,0));
104 int adjacentBlanking = static_cast<int>(blankingArray->GetComponent(j,0));
105
106 if (adjacentBlanking == 0)
107 {
108 continue;
109 }
110
111 if (adjacentCenterlineGroupId == centerlineGroupId)
112 {
113 continue;
114 }
115
116 if (adjacentCenterlineId != centerlineId)
117 {
118 continue;
119 }
120
121 if (!((adjacentCenterlineTractId == centerlineTractId - 1) ||
122 (adjacentCenterlineTractId == centerlineTractId + 1)))
123 {
124 continue;
125 }
126
127 centerlineGroupCellIds->InsertNextId(j);
128 }
129 }
130
131 tube->EvaluateFunction(point);
132
133 vtkIdType centerlineCellId = tube->GetLastPolyBallCellId();
134 vtkIdType centerlineSubId = tube->GetLastPolyBallCellSubId();
135 double centerlinePCoord = tube->GetLastPolyBallCellPCoord();
136
137 vtkCell* polyLine = this->Centerlines->GetCell(centerlineCellId);
138
139 if (polyLine->GetCellType() != VTK_LINE && polyLine->GetCellType() != VTK_POLY_LINE)
140 {
141 continue;
142 }
143
144 double radius = 0.0;
145 vtkvmtkCenterlineUtilities::InterpolateTuple1(this->Centerlines,this->RadiusArrayName,centerlineCellId,centerlineSubId,centerlinePCoord,radius);
146 double weight = radius * radius;
147 double centerlinePoint[3];
148 vtkvmtkCenterlineUtilities::InterpolatePoint(this->Centerlines,centerlineCellId,centerlineSubId,centerlinePCoord,centerlinePoint);
149
150 averagePoint[0] += weight * centerlinePoint[0];
151 averagePoint[1] += weight * centerlinePoint[1];
152 averagePoint[2] += weight * centerlinePoint[2];
153
154 double centerlinePoint0[3], centerlinePoint1[3];
155 polyLine->GetPoints()->GetPoint(centerlineSubId,centerlinePoint0);
156 polyLine->GetPoints()->GetPoint(centerlineSubId+1,centerlinePoint1);
157
158 if (vtkMath::Distance2BetweenPoints(centerlinePoint0,centerlinePoint1) < VTK_VMTK_DOUBLE_TOL)
159 {
160 if (centerlineSubId > 0)
161 {
162 polyLine->GetPoints()->GetPoint(centerlineSubId-1,centerlinePoint0);
163 }
164 else if (centerlineSubId+1 < polyLine->GetNumberOfPoints()-1)
165 {
166 polyLine->GetPoints()->GetPoint(centerlineSubId+2,centerlinePoint1);
167 }
168 }
169
170 double tangent[3];
171 tangent[0] = centerlinePoint1[0] - centerlinePoint0[0];
172 tangent[1] = centerlinePoint1[1] - centerlinePoint0[1];
173 tangent[2] = centerlinePoint1[2] - centerlinePoint0[2];
174
175 averageTangent[0] += weight * tangent[0];
176 averageTangent[1] += weight * tangent[1];
177 averageTangent[2] += weight * tangent[2];
178 double normal[3];
179 vtkvmtkCenterlineUtilities::InterpolateTuple3(this->Centerlines,this->CenterlineNormalsArrayName,centerlineCellId,centerlineSubId,centerlinePCoord,normal);
180
181 averageNormal[0] += weight * normal[0];
182 averageNormal[1] += weight * normal[1];
183 averageNormal[2] += weight * normal[2];
184
185 weightSum += weight;
186 }
187
188 averagePoint[0] /= weightSum;
189 averagePoint[1] /= weightSum;
190 averagePoint[2] /= weightSum;
191 vtkMath::Normalize(averageNormal);
192 vtkMath::Normalize(averageTangent);
193
194 double projectedPoint[3];
195 vtkPlane::ProjectPoint(point,averagePoint,averageTangent,projectedPoint);
196
197 double positionVector[3];
198 positionVector[0] = projectedPoint[0] - averagePoint[0];
199 positionVector[1] = projectedPoint[1] - averagePoint[1];
200 positionVector[2] = projectedPoint[2] - averagePoint[2];
201 vtkMath::Normalize(positionVector);
202
203 double normalPoint[3];
204 normalPoint[0] = averagePoint[0] + averageNormal[0];
205 normalPoint[1] = averagePoint[1] + averageNormal[1];
206 normalPoint[2] = averagePoint[2] + averageNormal[2];
207
208 double projectedNormalPoint[3];
209 vtkPlane::ProjectPoint(normalPoint,averagePoint,averageTangent,projectedNormalPoint);
210
211 double projectedNormal[3];
212 projectedNormal[0] = projectedNormalPoint[0] - averagePoint[0];
213 projectedNormal[1] = projectedNormalPoint[1] - averagePoint[1];
214 projectedNormal[2] = projectedNormalPoint[2] - averagePoint[2];
215 vtkMath::Normalize(projectedNormal);
216
217 double cross[3];
218 vtkMath::Cross(positionVector,projectedNormal,cross);
219
220 double tangentDot = vtkMath::Dot(averageTangent,cross);
221
222 double angle = vtkvmtkMath::AngleBetweenNormals(positionVector,projectedNormal);
223
224 if (tangentDot < 0.0)
225 {
226 angle *= -1.0;
227 }
228
229 metricArray->SetComponent(pointId,0,angle);
230
231 centerlineGroupCellIds->Delete();
232 tube->Delete();
233}
static void InterpolatePoint(vtkPolyData *centerlines, int cellId, int subId, double pcoord, double interpolatedPoint[3])
static void InterpolateTuple1(vtkPolyData *centerlines, const char *arrayName, int cellId, int subId, double pcoord, double &interpolatedTuple1)
static void InterpolateTuple3(vtkPolyData *centerlines, const char *arrayName, int cellId, int subId, double pcoord, double interpolatedTuple3[3])
static double AngleBetweenNormals(double normal0[3], double normal1[3])
Implements vtkImplicitFunction to evaluate the minimum sphere function for an envelope created by an ...
virtual double GetLastPolyBallCellPCoord()
virtual void SetInput(vtkPolyData *)
virtual void SetPolyBallRadiusArrayName(const char *)
virtual void SetInputCellIds(vtkIdList *)
virtual void SetUseRadiusInformation(int)
virtual vtkIdType GetLastPolyBallCellId()
static vtkvmtkPolyBallLine * New()
double EvaluateFunction(double x[3]) override
virtual vtkIdType GetLastPolyBallCellSubId()
Create an angular metric array on each branch of a split surface representing the periodic circumfere...
virtual void EvaluateMetric(vtkIdType pointId, double point[3], vtkIdType groupId, vtkDataArray *metricArray) override
#define VTK_VMTK_DOUBLE_TOL
vtkStandardNewMacro(vtkvmtkPolyDataCenterlineAngularMetricFilter)