MCPcopy Create free account
hub / github.com/Kitware/VTK / SlidingNormalsOnLine

Function SlidingNormalsOnLine

Common/DataModel/vtkPolyLine.cxx:61–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59{ // anonymous namespace supporting sliding normal generation
60
61void SlidingNormalsOnLine(vtkPoints* pts, vtkIdType npts, const vtkIdType* linePts,
62 vtkDataArray* normals, double* firstNormal, vtkVector3d& normal)
63{
64 if (npts <= 0)
65 {
66 return;
67 }
68 if (npts == 1) // return arbitrary
69 {
70 normals->InsertTuple(linePts[0], normal.GetData());
71 return;
72 }
73
74 vtkIdType sNextId = 0;
75 vtkVector3d sPrev, sNext;
76
77 sNextId = FindNextValidSegment(pts, npts, linePts, 0);
78 if (sNextId != npts) // at least one valid segment
79 {
80 vtkVector3d pt1, pt2;
81 pts->GetPoint(linePts[sNextId], pt1.GetData());
82 pts->GetPoint(linePts[sNextId + 1], pt2.GetData());
83 sPrev = (pt2 - pt1).Normalized();
84 }
85 else // no valid segments
86 {
87 for (vtkIdType i = 0; i < npts; ++i)
88 {
89 normals->InsertTuple(linePts[i], normal.GetData());
90 }
91 return;
92 }
93
94 // compute first normal
95 if (firstNormal)
96 {
97 normal = vtkVector3d(firstNormal);
98 }
99 else
100 {
101 // find the next valid, non-parallel segment
102 while (++sNextId < npts)
103 {
104 sNextId = FindNextValidSegment(pts, npts, linePts, sNextId);
105 if (sNextId != npts)
106 {
107 vtkVector3d pt1, pt2;
108 pts->GetPoint(linePts[sNextId], pt1.GetData());
109 pts->GetPoint(linePts[sNextId + 1], pt2.GetData());
110 sNext = (pt2 - pt1).Normalized();
111
112 // now the starting normal should simply be the cross product
113 // in the following if statement we check for the case where
114 // the two segments are parallel, in which case, continue searching
115 // for the next valid segment
116 vtkVector3d n;
117 n = sPrev.Cross(sNext);
118 if (n.Norm() > 1.0E-3)

Callers 1

Calls 10

FindNextValidSegmentFunction · 0.85
NormMethod · 0.80
vtkVector3dClass · 0.70
sqrtFunction · 0.50
InsertTupleMethod · 0.45
GetDataMethod · 0.45
GetPointMethod · 0.45
CrossMethod · 0.45
NormalizeMethod · 0.45
DotMethod · 0.45

Tested by

no test coverage detected