| 59 | { // anonymous namespace supporting sliding normal generation |
| 60 | |
| 61 | void 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) |
no test coverage detected