Hello,
I neel get surface area of vtkUnstructuredGrid, and vtkTriangleFilter is used to process VTKUnstructuredgrid, and then vtkMassProperties is used to get the surface area, but the obtained area is 0.
Here is my code, The following is my code, after running the prompt
Input port 0 of algorithm vtkTriangleFilter(000002CF5EAEB670) has 0 connections but is not optional.
What went wrong, please?
std::vector<std::array<double, 3>> pointCoordinates;
// Face 1
pointCoordinates.push_back({ {0, 2, 0} }); // Node 0
pointCoordinates.push_back({ {0, 2, 3} }); // Node 1
pointCoordinates.push_back({ {0, 0, 3} }); // Node 2
pointCoordinates.push_back({ {0, 0, 0} }); // Node 3
// Face 2
pointCoordinates.push_back({ {0, 2, 0} }); // Node 4
pointCoordinates.push_back({ {0, 1, 0} }); // Node 5
pointCoordinates.push_back({ {0, 1, 3} }); // Node 6
pointCoordinates.push_back({ {0, 2, 3} }); // Node 7
// Create the points.
vtkNew<vtkPoints> points;
for (auto i = 0; i < pointCoordinates.size(); ++i)
{
points->InsertNextPoint(pointCoordinates[i].data());
}
vtkNew<vtkUnstructuredGrid> uGrid;
uGrid->SetPoints(points);
vtkIdType ptid[4] = { 0, 1, 2, 3};
uGrid->InsertNextCell(VTK_QUAD, 4, ptid);
vtkIdType ptid2[4] = { 4, 5, 6, 7};
uGrid->InsertNextCell(VTK_QUAD, 4, ptid2);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInputData(uGrid);
vtkSmartPointer<vtkPolyData> pd =
vtkPolyData::SafeDownCast(mapper->GetInput());
vtkSmartPointer<vtkTriangleFilter> filter = vtkSmartPointer<vtkTriangleFilter>::New();
filter->SetInputData(pd);
filter->Update();
vtkSmartPointer<vtkMassProperties> m_pvtkMassProperties =
vtkMassProperties::New();
m_pvtkMassProperties->SetInputData(filter->GetOutput());
m_pvtkMassProperties->Update();
double area = m_pvtkMassProperties->GetSurfaceArea();
std::cout << area << std::endl;