Geom_BSplineSurface to TopoDS_Face

Hi,

I am trying to create Spline surface and then convert it to a Face but the following code doesn't work. BRepBuilderAPI_MakeFace doesn't take Geom_BSplineSurface as input as it only takes Geom_Surface and I am not sure how to convert Geom_BSplineSurface into Geom_Surface. Can anyone pleas help ?

TopoDS_Face XYZ2Face(const TColgp_Array2OfPnt& points, int degMin = 4, int degMax = 4)
{
GeomAPI_PointsToBSplineSurface aPTBS;
aPTBS.Init(points, degMin, degMax, GeomAbs_C2, 1.e-9);
Handle(Geom_BSplineSurface) aSurface = aPTBS.Surface();
TopoDS_Face face = BRepBuilderAPI_MakeFace(aSurface, 1e-9).Face(); // This line fails.
return face;
}

Dmitrii Pasukhin's picture

This code should work.

I think, you need to make #include <Geom_BSplineSurface.hxx>

Best regards, Dmitrii.

SAMYAK JAIN's picture

Hi Dmitrii,

Thanks for your reply. I already have included that header file. I know it should work but it still doesn't with the latest OpenCASCADE version 7.7. BRepBuilderAPI_MakeFace is not able to resolve Handle(Geom_BSplineSurface) as input as it expects Handle(Geom_Surface) based on the supported constructor. Is there a way to cast Handle(Geom_BSplineSurface) -> Handle(Geom_Surface) ?

Best Regards
Samyak

gkv311 n's picture

Some compilers might have issues with resolving ambuguities (BRepBuilderAPI_MakeFace has several overloaded constructors). Try putting a Handle upcast to a separate line:

Handle(Geom_BSplineSurface) aBSurface = aPTBS.Surface();
Handle(Geom_Surface) aSurf = aBSurface; // to avoid ambuguity
TopoDS_Face face = BRepBuilderAPI_MakeFace(aSurf, 1e-9).Face()
SAMYAK JAIN's picture

Hi,

Thanks for your reply. I have tried that already. It says no suitable conversion from opencascade::handle<Geom_BSplineSurface> to opencascade::handle<Geom_Surface> exists. This is so strange. This should obviously work straightaway. I am using OpenCASCADE-7.7.0-vc14-64 and my IDE is Visual Studio 2019. Any other suggestions ?

Regards
Samyak

gkv311 n's picture

I guess you need sharing a complete code sample to be able to reproduce and understand what might be wrong.

gkv311 n's picture

Compiles just fine for me.

#include <BRepBuilderAPI_MakeFace.hxx>
#include <Geom_BSplineSurface.hxx>
#include <GeomAPI_PointsToBSplineSurface.hxx>
#include <TopoDS_Face.hxx>

TopoDS_Face XYZ2Face(const TColgp_Array2OfPnt& points, int degMin = 4, int degMax = 4)
{
  GeomAPI_PointsToBSplineSurface aPTBS;
  aPTBS.Init(points, degMin, degMax, GeomAbs_C2, 1.e-9);
  Handle(Geom_BSplineSurface) aBSurface = aPTBS.Surface();
  Handle(Geom_Surface) aSurf = aBSurface;
  TopoDS_Face face = BRepBuilderAPI_MakeFace(aSurf, 1e-9).Face();
  return face;
}
Dmitrii Pasukhin's picture

A casting from child to father is a basic dinamic casting. You need to have the correct definitions (header files included) in order to process it.

VS 2019 has no problem with this task. I have pasted your code in VS15, VS17, VS19, VS22 and last gcc and clang and there is no problem if header is defined.

Please add "#include <Geom_Surface.hxx>" too.

Handle(Geom_BSplineSurface) aBSurface = aPTBS.Surface();
Handle(Geom_Surface) aSurf = aBSurface; // to avoid ambuguity
TopoDS_Face face = BRepBuilderAPI_MakeFace(aSurf, 1e-9).Face()

Best regards, Dmitrii.