Removing polygons based on edge length after running Delaunay2D

Hello!

I’m completely new to VTK. I have written some code that loads a PCD file with PCL and converts, converts it to VTK points, and runs the Delaunay2D algorigthm on the points to create a mesh. Afterwards I want to remove any triangles in the mesh that have an edge length larger than a limit that I specify. Afterwards I save the mesh as an STL file. How can remove the triangles? So far my code looks like this:

pcl::PointCloud<pcl::PointXYZ>::Ptr pCloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PCDReader PCDReader;

PCDReader.read("H:/Scan/shape.pcd", *pCloud);

vtkSmartPointer<vtkPoints> pVTKPoints = vtkSmartPointer<vtkPoints>::New();
vtkPoints& VTKPointsReference = *(pVTKPoints.GetPointer());

// Move points into VTK data type.
for (auto Point : *pCloud)
{
	pVTKPoints->InsertNextPoint(Point.x, Point.y, Point.z);
}
pVTKPoints->ComputeBounds();

// Add the grid points to a polydata object
vtkSmartPointer<vtkPolyData> pPolyData = vtkSmartPointer<vtkPolyData>::New();
pPolyData->SetPoints(pVTKPoints);

// Triangulate the grid points
vtkSmartPointer<vtkDelaunay2D> pDelaunay = vtkSmartPointer<vtkDelaunay2D>::New();
pDelaunay->SetInputData(pPolyData);
pDelaunay->Update();

    // Remove "large" triangles, how do I do this?

vtkSmartPointer<vtkSTLWriter> pStlWriter = vtkSmartPointer<vtkSTLWriter>::New();
pStlWriter->SetFileName("H:/Scan/result.stl");
pStlWriter->SetInputConnection(pDelaunay->GetOutputPort());
pStlWriter->SetFileTypeToBinary();
pStlWriter->Write();

Thanks in advance!

If your goal is to reconstruct a surface from a point cloud then I would recommend to use VTK’s surface reconstruction filters. See this post for more information:

Thanks, I’ll have a look.
What I want to do is basically to reconstruct a 2.5D surface from a point cloud, and the Delaunay algorithm should not connect any points that are more than 5 mm apart. In CloudCompare I can specify this distance threshold, but that does not seem to be an option in VTK, as far as I can see. So I am looking for a way to remove the “big” triangles after triangulation.

You can control this parameter (or very similar ones) in VTK surface reconstruction filters, too. I would recommend to try all of the applicable filters and experiment with different parameter settings to find what works the best for you.

If you want to compare surface reconstruction results with a simple Delaunay + removal of “large” triangles then you can compute the filtering criteria using vtkMeshQuality (or compute it yourself: add a cell data array, iterate through all the cells, and fill values in this array, e.g., set to 1 to keep, set to 0 to remove) then remove the outlier triangles by using vtkThreshold.

Thanks for the answer, that was helpful. I see there are several metrics for mesh quality of triangles in vtkMeshQuality:

VTK_QUALITY_ASPECT_RATIO, VTK_QUALITY_ASPECT_FROBENIUS, and VTK_QUALITY_EDGE_RATIO, VTK_QUALITY_MIN_ANGLE, VTK_QUALITY_MAX_ANGLE, VTK_QUALITY_CONDITION, VTK_QUALITY_SCALED_JACOBIAN, VTK_QUALITY_RELATIVE_SIZE_SQUARED, VTK_QUALITY_SHAPE, VTK_QUALITY_SHAPE_AND_SIZE, and VTK_QUALITY_DISTORTION.

Where can I find information about what they do? Some are pretty obvious, like min angle, but what about VTK_QUALITY_SHAPE_AND_SIZE, how is that calculated?

Thanks in advance!

To find out what exactly a VTK class does you can have a look at its source code. See vtkMeshQuality.cxx.