how to get nurbs surface and normalized knot vector?

R G W

Active CAD practitioner
hello sir,
I am a student at Dalian University of Technology. I am also learning your course about OCC in Youtube. Your courses are wonderful!

But an issue is confusing me. Hence, I need your help. I failed to convert a sphere geometry from a STEP file to a NURBS surface. At present, I have completed the reading of the step file,and obtained the model information through the Geom_BSplineSurface class, such as node vectors, control points, and weights.
The method I use is to extract a face in the model, convert it into a Geom_BSplineSurface, and then get the information. The code is as follows.

BRepBuilderAPI_NurbsConvert nurbs_convert;
nurbs_convert = BRepBuilderAPI_NurbsConvert(faceo);
nurbs_convert.Perform(faceo);
TopoDS_Shape face_shape = nurbs_convert.Shape();
Handle (Geom_Surface) h_geomface = BRep_Tool::Surface(TopoDS::Face(face_shape));
Handle(Geom_BSplineSurface)h_bsurface = GeomConvert::SurfaceToBSplineSurface(h_geomface);
Geom_BSplineSurface* bsurface = h_bsurface.get();


But I found that the knot range of this surface is not from 0 to 1 (not an open knot vector, from -15 to 15). I want to know which function can help me convert a surface geometry directly to a NUEBS but a B splines with irregular knot interval? Or how can I convert the node vector range of a surface into 0 to 1?
Thank you very much!

Regards,
Guangwu
 

Quaoar

Administrator
Staff member
Hello and welcome to the forum.

You may want to try to reparameterize your spline surface by reparameterizing its U and V knot vectors. Here's a code snippet I grabbed from some random place in OpenCascade:

Code:
static void GeomLib_ChangeUBounds(Handle(Geom_BSplineSurface)& aSurface,
                  const Standard_Real newU1,
                  const Standard_Real newU2)
{
  TColStd_Array1OfReal  knots(1,aSurface->NbUKnots()) ;
  aSurface->UKnots(knots) ;
  BSplCLib::Reparametrize(newU1,
              newU2,
              knots) ;
  aSurface->SetUKnots(knots) ;
}
static void GeomLib_ChangeVBounds(Handle(Geom_BSplineSurface)& aSurface,
                  const Standard_Real newV1,
                  const Standard_Real newV2)
{
  TColStd_Array1OfReal  knots(1,aSurface->NbVKnots()) ;
  aSurface->VKnots(knots) ;
  BSplCLib::Reparametrize(newV1,
              newV2,
              knots) ;
  aSurface->SetVKnots(knots) ;
}

Running these GeomLib_ChangeUBounds and GeomLib_ChangeVBounds functions one after another should do the trick.
 

R G W

Active CAD practitioner
Hello and welcome to the forum.

You may want to try to reparameterize your spline surface by reparameterizing its U and V knot vectors. Here's a code snippet I grabbed from some random place in OpenCascade:

Code:
static void GeomLib_ChangeUBounds(Handle(Geom_BSplineSurface)& aSurface,
                  const Standard_Real newU1,
                  const Standard_Real newU2)
{
  TColStd_Array1OfReal  knots(1,aSurface->NbUKnots()) ;
  aSurface->UKnots(knots) ;
  BSplCLib::Reparametrize(newU1,
              newU2,
              knots) ;
  aSurface->SetUKnots(knots) ;
}
static void GeomLib_ChangeVBounds(Handle(Geom_BSplineSurface)& aSurface,
                  const Standard_Real newV1,
                  const Standard_Real newV2)
{
  TColStd_Array1OfReal  knots(1,aSurface->NbVKnots()) ;
  aSurface->VKnots(knots) ;
  BSplCLib::Reparametrize(newV1,
              newV2,
              knots) ;
  aSurface->SetVKnots(knots) ;
}

Running these GeomLib_ChangeUBounds and GeomLib_ChangeVBounds functions one after another should do the trick.
Your reply is very helpful, very thanks!
Now I want to encrypt the model, how can I do this?
 

Quaoar

Administrator
Staff member
like to obtain node vectors with smaller intervals and a larger number of control points
Can you elaborate on why could that be necessary? Most people prefer reducing complexity instead of increasing it. Still, if you really want to do that, try inserting knots with Geom_BSplineSurface::InsertUKnots() and Geom_BSplineSurface::InsertVKnots() methods.
 

R G W

Active CAD practitioner
Ok, because I want to apply boundary conditions later, the encryption can be approximately processed.
And your reply is very helpful, thanks!!
 
Top