Hi,
I want to create a mesh vtkPolyData from points and triangles. Here’s my mesh topology.
Given the topology, I can create vtkPolyData from the points and triangles.
suedocode:
auto points = vtkSmartPointer<vtkPoints>::New();
for(const auto& point: inputPoints)
points->InsertNextPoint(point.GetData());
auto cells = vtkSmartPointer<vtkCellArray>::New();
cells->InsertNextCell(GetTriangle(0, 1, 2));
cells->InsertNextCell(GetTriangle(2, 1, 3));
cells->InsertNextCell(GetTriangle(3, 1, 4));
cells->InsertNextCell(GetTriangle(4, 2, 3));
cells->InsertNextCell(GetTriangle(4, 0, 2));
auto mesh = vtkSmartPointer<vtkPolyData>::New();
mesh->SetPoints(points);
mesh->SetPolys(cells);
where GetTriangle(int, int, int) returns a vtkSmartPointer<vtkTriangle>
.
When I run the program and export the result vtkPolyData to a .stl file, it looks like this
the 2 pink triangles are the ones with reversed normal.
Initially I thought this is because the vertices order of these triangles are wrong, but even if I changed the vertices order, the result is still the same.
Then I thought maybe my code is wrong. I checked the code by keeping the vertices the same, and get rid of triangle (4,2,3) and (4,0,2), as shown in picture
the result would be a valid mesh without any reversed triangles
Why in the first case, there are reversed triangles?
Thanks