Okay, so I think what I should do is this:
Use a TopExp_Explorer on the Compound to iterate over all faces (TopAbs_Face):
TopExp_Explorer exp;
for (exp.Init(shape, TopAbs_FACE); exp.More(); exp.Next())
{
ProcessSingleFace(exp.Current());
}Then use BRepBuilderAPI_MakeFace:
void ProcessSingleFace(const TopoDS_Shape& shape)
{
if (!shape.IsNull())
{
TopoDS_Face face = TopoDS::Face(shape);
TopLoc_Location loc;
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(face, loc);
aSurf = Handle(Geom_Surface) { static_cast<Geom_Surface*>(aSurf->Transformed(loc.Transformation()).get()) };
Standard_Real u0, u1, v0, v1;
BRepTools::UVBounds(face, u0, u1, v0, v1);
if (!aSurf.IsNull())
{
// Make face. Result is NURBS surface(s) (right?)
TopoDS_Wire outerWire = BRepTools::OuterWire(face);
BRepBuilderAPI_MakeFace faceMaker{face, outerWire};
// Add other wires
TopExp_Explorer exp;
for (exp.Init(shape, TopAbs_WIRE); exp.More(); exp.Next())
{
TopoDS_Wire wire = TopoDS::Wire(exp.Current());
if(wire != outerWire)
{
faceMaker.Add(wire);
}
}
const TopoDS_Shape& result = faceMaker.Shape();
if(result.IsNull())
{
return;
}
Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(result));
Handle(Geom_BSplineSurface) bsSurf { static_cast<Geom_BSplineSurface*>(surf.get()) };
if(bsSurf.IsNull())
{
return;
}
int uKnots = bsSurf->NbUKnots(); // -> CRASH
}
}
}The problem is, that when I try to access the bsSurf after it gets created, my application crashes.
For example, even some simple like bsSurf->NbUKnots() already crashes my application. I haven't set breakpoints to check the variables, because I'm compiling this to a DLL which I use indirectly on another thread, and I don't really want to set that up if I don't need to.
Is there anything I'm doing wrong here? Or misunderstand?