def points_to_bspline(pnts): ''' Points to bspline ''' pnts = point_list_to_TColgp_Array1OfPnt(pnts) crv = GeomAPI_PointsToBSpline(pnts) return crv.Curve()
def pipe(): # the bspline path, must be a wire array2 = TColgp_Array1OfPnt(1, 3) array2.SetValue(1, gp_Pnt(0, 0, 0)) array2.SetValue(2, gp_Pnt(0, 1, 2)) array2.SetValue(3, gp_Pnt(0, 2, 3)) bspline2 = GeomAPI_PointsToBSpline(array2).Curve() path_edge = BRepBuilderAPI_MakeEdge(bspline2).Edge() path_wire = BRepBuilderAPI_MakeWire(path_edge).Wire() # the bspline profile. Profile mist be a wire array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0, 0)) array.SetValue(2, gp_Pnt(1, 2, 0)) array.SetValue(3, gp_Pnt(2, 3, 0)) array.SetValue(4, gp_Pnt(4, 3, 0)) array.SetValue(5, gp_Pnt(5, 5, 0)) bspline = GeomAPI_PointsToBSpline(array).Curve() profile_edge = BRepBuilderAPI_MakeEdge(bspline).Edge() # pipe pipe = BRepOffsetAPI_MakePipe(path_wire, profile_edge).Shape() display.DisplayShape(profile_edge, update=False) display.DisplayShape(path_wire, update=False) display.DisplayShape(pipe, update=True)
def resample_curve_with_uniform_deflection(curve, deflection=0.5, degreeMin=3, degreeMax=8, continuity=GeomAbs_C2, tolerance=1e-4): ''' fits a bspline through the samples on `curve` @param curve: TopoDS_Wire, TopoDS_Edge, curve @param n_samples: ''' from OCCT.GCPnts import GCPnts_UniformDeflection crv = to_adaptor_3d(curve) defl = GCPnts_UniformDeflection(crv, deflection) with assert_isdone(defl, 'failed to compute UniformDeflection'): print("Number of points:", defl.NbPoints()) sampled_pnts = [defl.Value(i) for i in xrange(1, defl.NbPoints())] resampled_curve = GeomAPI_PointsToBSpline(point_list_to_TColgp_Array1OfPnt(sampled_pnts), degreeMin, degreeMax, continuity, tolerance) return resampled_curve.Curve().GetObject()
def prism(): # the bspline profile array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0, 0)) array.SetValue(2, gp_Pnt(1, 2, 0)) array.SetValue(3, gp_Pnt(2, 3, 0)) array.SetValue(4, gp_Pnt(4, 3, 0)) array.SetValue(5, gp_Pnt(5, 5, 0)) bspline = GeomAPI_PointsToBSpline(array).Curve() profile = BRepBuilderAPI_MakeEdge(bspline).Edge() # the linear path starting_point = gp_Pnt(0., 0., 0.) end_point = gp_Pnt(0., 0., 6.) vec = gp_Vec(starting_point, end_point) path = BRepBuilderAPI_MakeEdge(starting_point, end_point).Edge() # extrusion prism = BRepPrimAPI_MakePrism(profile, vec).Shape() display.DisplayShape(profile, update=False) display.DisplayShape(starting_point, update=False) display.DisplayShape(end_point, update=False) display.DisplayShape(path, update=False) display.DisplayShape(prism, update=True)
def surface_from_curves(): ''' @param display: ''' # First spline array = [] array.append(gp_Pnt(-4, 0, 2)) array.append(gp_Pnt(-7, 2, 2)) array.append(gp_Pnt(-6, 3, 1)) array.append(gp_Pnt(-4, 3, -1)) array.append(gp_Pnt(-3, 5, -2)) pt_list1 = point_list_to_TColgp_Array1OfPnt(array) SPL1 = GeomAPI_PointsToBSpline(pt_list1).Curve() # Second spline a2 = [] a2.append(gp_Pnt(-4, 0, 2)) a2.append(gp_Pnt(-2, 2, 0)) a2.append(gp_Pnt(2, 3, -1)) a2.append(gp_Pnt(3, 7, -2)) a2.append(gp_Pnt(4, 9, -1)) pt_list2 = point_list_to_TColgp_Array1OfPnt(a2) SPL2 = GeomAPI_PointsToBSpline(pt_list2).Curve() # Fill with StretchStyle aGeomFill1 = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_StretchStyle) SPL3 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(10, 0, 0))) SPL4 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(10, 0, 0))) # Fill with CoonsStyle aGeomFill2 = GeomFill_BSplineCurves(SPL3, SPL4, GeomFill_CoonsStyle) SPL5 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(20, 0, 0))) SPL6 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(20, 0, 0))) # Fill with CurvedStyle aGeomFill3 = GeomFill_BSplineCurves(SPL5, SPL6, GeomFill_CurvedStyle) aBSplineSurface1 = aGeomFill1.Surface() aBSplineSurface2 = aGeomFill2.Surface() aBSplineSurface3 = aGeomFill3.Surface() display.DisplayShape(make_face(aBSplineSurface1, 1e-6)) display.DisplayShape(make_face(aBSplineSurface2, 1e-6)) display.DisplayShape(make_face(aBSplineSurface3, 1e-6), update=True)
def create_shape(self): d = self.declaration if not d.points: raise ValueError("Must have at least two points") # Poles and weights points = self.get_transformed_points() pts = TColgp_Array1OfPnt(1, len(points)) set_value = pts.SetValue # TODO: Support weights for i, p in enumerate(points): set_value(i + 1, p) curve = self.curve = GeomAPI_PointsToBSpline(pts).Curve() self.shape = self.make_edge(curve)