I have a step file object. It includes a 3D shape. I want to triangulate the surfaces of the shape with opencascade. First I am sampling points on each surface as follows:
STEPControl_Reader reader;
reader.ReadFile(file_path);
if (reader.TransferRoots() != IFSelect_RetDone) {
std::cerr << "Error: Unable to read file." << std::endl;
return 1;
}
TopoDS_Shape shape = reader.Shape(1); // the file includes only 1 shape
for (TopExp_Explorer exp(shape, TopAbs_FACE); exp.More(); exp.Next()) {
TopoDS_Face face = TopoDS::Face(exp.Current());
TopLoc_Location location;
Handle(Geom_Surface) surface = BRep_Tool::Surface(face, location);
vector<gp_Pnt> sampled_points;
// sample the surface
for (double u = 0.0; u <= 1.0; u += 0.1) {
for (double v = 0.0; v <= 1.0; v += 0.1) {
gp_Pnt point(u, v, 0.0);
// Get the U and V parameter ranges of the surface.
Standard_Real UMin, UMax, VMin, VMax;
surface->Bounds(UMin, UMax, VMin, VMax);
// Create a GeomAPI_ProjectPointOnSurf object.
GeomAPI_ProjectPointOnSurf myProj;
myProj.Init(point, surface, UMin, UMax, VMin, VMax, Extrema_ExtAlgo::Extrema_ExtAlgo_Grad);
// Get the closest point on the surface to the projected point.
gp_Pnt projectedPoint = myProj.NearestPoint();
sampled_points.push_back(projectedPoint);
}
}
// NOW CREATE A TRIANGULATION FROM sampled_points
}
That may be a delaunay triangulation or something else. How can I create a valid surface triangulation with 3d points?