Skip to content

Instantly share code, notes, and snippets.

@jirihnidek
Created August 29, 2016 07:30
Show Gist options
  • Save jirihnidek/6f433368198f86c594edc0a45027c62a to your computer and use it in GitHub Desktop.
Save jirihnidek/6f433368198f86c594edc0a45027c62a to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <TColgp_Array2OfPnt.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <gp_Pnt.hxx>
#include <TopoDS_Edge.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <TopoDS_Wire.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <TopoDS_Face.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <Geom_BSplineSurface.hxx>
#include <BRepBuilderAPI_Sewing.hxx>
#include <BRepAlgoAPI_Section.hxx>
int main(void)
{
int udeg = 2, vdeg = 2;
// Create Bezier surface
TColgp_Array2OfPnt poles(1, 3, 1, 3);
poles(1, 1) = gp_Pnt(0.0, 0.0, 0.0);
poles(2, 1) = gp_Pnt(0.5, 0.0, 0.0);
poles(3, 1) = gp_Pnt(1.0, 0.0, 0.0);
poles(1, 2) = gp_Pnt(0.0, 0.5, 0.5);
poles(2, 2) = gp_Pnt(0.5, 0.5, 0.5);
poles(3, 2) = gp_Pnt(1.0, 0.5, 0.2);
poles(1, 3) = gp_Pnt(0.0, 1.0, 0.0);
poles(2, 3) = gp_Pnt(0.5, 1.0, 0.0);
poles(3, 3) = gp_Pnt(1.0, 1.0, 0.0);
// Length of uknots and umults has to be same
// Same rule is for vknots and vmults
int uknot_len = 2, umult_len = 2;
int vknot_len = 2, vmult_len = 2;
// Create arrays of U and V knots ...
TColStd_Array1OfReal uknots(1, uknot_len);
TColStd_Array1OfReal vknots(1, uknot_len);
// ... and fill them with values
uknots.SetValue(1, 0.0);
uknots.SetValue(2, 1.0);
vknots.SetValue(1, 0.0);
vknots.SetValue(2, 1.0);
// Create array of U and V multiplicities
TColStd_Array1OfInteger umults(1, umult_len);
TColStd_Array1OfInteger vmults(1, vmult_len);
// First and last multiplicities are set to udeg + 1 (vdeg respectively),
// because we want main curves to start and finish on the first and
// the last points
umults.SetValue(1, udeg + 1);
umults.SetValue(2, udeg + 1);
vmults.SetValue(1, vdeg + 1);
vmults.SetValue(2, vdeg + 1);
Geom_BSplineSurface *surf= new Geom_BSplineSurface(poles, uknots, vknots, umults, vmults, udeg, vdeg, Standard_False, Standard_False);
// Create Sewing at the first time
BRepBuilderAPI_Sewing sewing;
// Create points
gp_Pnt point0 = gp_Pnt(0.25, 0.25, -1.0);
gp_Pnt point1 = gp_Pnt(0.75, 0.25, -1.0);
gp_Pnt point2 = gp_Pnt(0.75, 0.25, 1.0);
gp_Pnt point3 = gp_Pnt(0.25, 0.25, 1.0);
// Create edges
TopoDS_Edge edge0 = BRepBuilderAPI_MakeEdge(point0, point1);
TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge(point1, point2);
TopoDS_Edge edge2 = BRepBuilderAPI_MakeEdge(point2, point3);
TopoDS_Edge edge3 = BRepBuilderAPI_MakeEdge(point3, point0);
// Create Wire
TopoDS_Wire wire = BRepBuilderAPI_MakeWire(edge0, edge1, edge2, edge3);
// Create Face
TopoDS_Face face = BRepBuilderAPI_MakeFace(wire);
// Add face to sewing
sewing.Add(face);
BRepAlgoAPI_Section(surf, sewing.SewedShape());
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment