Mon, 08/01/2022 - 19:55
I'm reconstructing third party nurbs data using OpenCascade. I have managed to load the vast majority of surfaces despite having virtually no experience with graphics, but I still have many problematic surfaces.
An overview of the process would look something like this:
Surface* surface = GetNextSurface(); // 3rd party surface to convert
Handle_Geom_BSplineSurface bspSurf; // The converted surface
thirdPartySurfaceToOCC(surface, bspSurf) // Convert the surface
// Get all trim curves and make edges : convert each curve
TopoDS_Edge edge = TrimCurveToOCC(curve, bspSurf);
if (!edge.IsNull()) edges.push_back(edge);
// Build the wire
BRepBuilderAPI_MakeWire wireMaker;
wireCollector.Append(edges[i]); // In case first method fails
wireMaker.Add(edges[i]); // Wires need to be contiguous
if (wireMaker.IsDone()) wires.push_back(wireMaker.Wire());
// If above fails try second attempt to build wires
BRepBuilderAPI_MakeWire wireMaker2;
wireMaker2.Add(wireCollector); // Wires don't need to be contiguous
if (wireMaker2.IsDone()) wires.push_back(wireMaker2.Wire());
// If above fails, try third attempt to build wires
// Abbreviated...
Handle(TopTools_HSequenceOfShape) Wires = new TopTools_HSequenceOfShape(); // Wire container
ShapeAnalysis_FreeBounds::ConnectEdgesToWires(EdgeSeq, 0.1, Standard_False, Wires); // Build the best wire possible
// And so on... Is there a better way to handle this case?
// Now construct the face
BRepBuilderAPI_MakeFace faceMaker;
if (wires.size() > 0)
{
faceMaker.Init(bspSurf, Standard_False, 0.5); // Initialize face without bounding
for (int i = 0; i < wires.size(); i++)
{
BRepCheck_Analyzer bca(wires[i]);
if (!bca.IsValid())
{
// Do shape healing with ShapeFix_Wireframe and ShapeFix_Wire
faceMaker.Add(fixedWire);
}
}
}
else
{
faceMaker.Init(bspSurf, Standard_True, 0.5); // Initialize with bounding
}
ShapeFix_Face fixFace(faceMaker.Face());
// yada yada, get face
BRepCheck_Analyzer analyzer(fixedFace);
// FACE IS NOT VALID!
As you can see, many faces are invalid at this point. When I inquire about the state I get three common errors:
- Unorientable shape
- Self-Intersecting wires (despite having used ShapeFix_Wire to correct self-intersection)
- Bad orientation of sub shape
Despite many efforts and much googling, I haven't yet found the source of the problem. The vast majority of errors pertain to orientation which leads me to believe there are errors in the orientation of the wires. However, I use ShapeFix_Wire as well as ShapeFix_Face to work on orientation so that doesn't seem to solve the problem.
Perhaps a more targeted question might be, how do I know when I have to mess with wire/edge orientation or is it a complete loss because ShapeFix failed to correct the orientation issue?
As I mentioned, I am new-ish to graphics so any explicit advice ideally coupled with examples would be greatly appreciated.
Wed, 08/03/2022 - 17:33
A little more information, I'm trying different surfaces and it appears that every time the surface fails the code has fallen into the third attempt to construct the wire (shown above). So what does it mean when BRepBuilderAPI_MakeWire can't build a wire from appending edges or using TopTools_ListOfShape?