作者:霹靂一頁書_629 | 来源:互联网 | 2023-10-12 14:14
这个demo 增加了 法线点在 vtkPolydata中。
#include
#include
#include
#include
#include
#include
#include int main(int, char*[])
{/ Set Point Normals ///// Create 3 pointsvtkNew points;points->InsertNextPoint(1.0, 0.0, 0.0);points->InsertNextPoint(0.0, 0.0, 0.0);points->InsertNextPoint(0.0, 1.0, 0.0);// Add the points to a polydatavtkNew polydata;polydata->SetPoints(points);// Set point normalsvtkNew pointNormalsArray;pointNormalsArray->SetNumberOfComponents(3); // 3d normals (ie x,y,z)pointNormalsArray->SetNumberOfTuples(polydata->GetNumberOfPoints());// Construct the normal vectorsdouble pN1[3] &#61; {1.0, 0.0, 0.0};double pN2[3] &#61; {0.0, 1.0, 0.0};double pN3[3] &#61; {0.0, 0.0, 1.0};// Add the data to the normals arraypointNormalsArray->SetTuple(0, pN1);pointNormalsArray->SetTuple(1, pN2);pointNormalsArray->SetTuple(2, pN3);// Add the normals to the points in the polydatapolydata->GetPointData()->SetNormals(pointNormalsArray);/ Get Point Normals ///auto pointNormalsRetrieved &#61;dynamic_cast(polydata->GetPointData()->GetNormals());if (pointNormalsRetrieved){std::cout <<"There are " <GetNumberOfTuples()<<" point normals." <GetNumberOfTuples(); i&#43;&#43;){double pN[3];pointNormalsRetrieved->GetTuple(i, pN);std::cout <<"Point normal " <}