------------------------------------------------------------------------------
| 71 | |
| 72 | //------------------------------------------------------------------------------ |
| 73 | void vtkPolyPlane::ComputeNormals() |
| 74 | { |
| 75 | if (!this->PolyLine) |
| 76 | { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | if (this->GetMTime() > this->NormalComputeTime.GetMTime()) |
| 81 | { |
| 82 | // Recompute the normal array. |
| 83 | |
| 84 | if (this->Normals) |
| 85 | { |
| 86 | // Delete the array if it already exists. We will reallocate later. |
| 87 | this->Normals->Delete(); |
| 88 | this->Normals = nullptr; |
| 89 | } |
| 90 | |
| 91 | vtkPoints* points = this->PolyLine->GetPoints(); |
| 92 | const vtkIdType nPoints = points->GetNumberOfPoints(); |
| 93 | const vtkIdType nLines = nPoints - 1; |
| 94 | |
| 95 | // Allocate an array to store the normals |
| 96 | |
| 97 | this->Normals = vtkDoubleArray::New(); |
| 98 | this->Normals->SetNumberOfComponents(3); |
| 99 | this->Normals->Allocate(3 * nLines); |
| 100 | this->Normals->SetName("Normals"); |
| 101 | this->Normals->SetNumberOfTuples(nLines); |
| 102 | |
| 103 | // Now iterate through all the lines and compute normal of each plane |
| 104 | // in the polyplane. |
| 105 | |
| 106 | double v1[3], p[3], n[3]; |
| 107 | |
| 108 | for (int pIdx = 0; pIdx < nLines; ++pIdx) |
| 109 | { |
| 110 | // Compute the plane normal for this segment by taking the cross product |
| 111 | // of the line direction and the extrusion direction. |
| 112 | |
| 113 | points->GetPoint(pIdx, p); |
| 114 | points->GetPoint(pIdx + 1, v1); |
| 115 | |
| 116 | // The line direction vector |
| 117 | v1[0] -= p[0]; |
| 118 | v1[1] -= p[1]; |
| 119 | v1[2] -= p[2]; |
| 120 | |
| 121 | // 'n' is the computed normal. |
| 122 | vtkMath::Cross(v1, this->ExtrusionDirection, n); |
| 123 | vtkMath::Normalize(n); |
| 124 | |
| 125 | // Store the normal in our array. |
| 126 | this->Normals->SetTuple(pIdx, n); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 |
no test coverage detected