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

Method ComputeNormals

Common/DataModel/vtkPolyPlane.cxx:73–129  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

71
72//------------------------------------------------------------------------------
73void 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

Callers 1

EvaluateFunctionMethod · 0.95

Calls 13

GetMTimeMethod · 0.95
NormalizeFunction · 0.70
DeleteMethod · 0.65
NewFunction · 0.50
CrossFunction · 0.50
GetPointsMethod · 0.45
GetNumberOfPointsMethod · 0.45
SetNumberOfComponentsMethod · 0.45
AllocateMethod · 0.45
SetNameMethod · 0.45
SetNumberOfTuplesMethod · 0.45
GetPointMethod · 0.45

Tested by

no test coverage detected