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 beziercurve(): # the first bezier curve array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0, -5)) array.SetValue(2, gp_Pnt(1, 2, 1)) array.SetValue(3, gp_Pnt(2, 3, 2)) array.SetValue(4, gp_Pnt(4, 3, -2)) array.SetValue(5, gp_Pnt(10, 5, -2)) beziercurve = Geom_BezierCurve(array) # the first bezier curve array1 = TColgp_Array1OfPnt(1, 5) array1.SetValue(1, gp_Pnt(0, 0, -5)) array1.SetValue(2, gp_Pnt(2, -2, 1)) array1.SetValue(3, gp_Pnt(2, -3, 2)) array1.SetValue(4, gp_Pnt(-4, 1, -2)) array1.SetValue(5, gp_Pnt(1, 5, -2)) beziercurve1 = Geom_BezierCurve(array1) array2 = TColgp_Array1OfPnt(1, 5) array2.SetValue(1, gp_Pnt(0, 0, -5)) array2.SetValue(2, gp_Pnt(-2, 2, 1)) array2.SetValue(3, gp_Pnt(2, -2, 2)) array2.SetValue(4, gp_Pnt(-4, 8, -2)) array2.SetValue(5, gp_Pnt(1, 5, -9)) beziercurve2 = Geom_BezierCurve(array2) surface1 = GeomFill_BezierCurves(beziercurve, beziercurve1, beziercurve2, GeomFill_CurvedStyle) surface2 = GeomFill_BezierCurves(beziercurve, beziercurve1, GeomFill_StretchStyle) surface3 = GeomFill_BezierCurves(beziercurve, beziercurve1, GeomFill_CoonsStyle) display.DisplayShape(surface1.Surface(), color='RED')
def spl_curv_pts(pts=[gp_Pnt()]): num = len(pts) p_array = TColgp_Array1OfPnt(1, num) for idx, pnt in enumerate(pts): p_array.SetValue(idx + 1, pnt) api = GeomAPI_PointsToBSpline(p_array) return p_array, api.Curve()
def thicken_spline(event=None): # Creation of points for the spine array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(1, 4, 0)) array.SetValue(2, gp_Pnt(2, 2, 0)) array.SetValue(3, gp_Pnt(3, 3, 0)) array.SetValue(4, gp_Pnt(4, 3, 0)) array.SetValue(5, gp_Pnt(5, 5, 0)) # Creation of a Bezier Curve as the spine bz_curv = Geom_BezierCurve(array) bz_curv_edge = BRepBuilderAPI_MakeEdge(bz_curv).Edge() bz_curv_wire = BRepBuilderAPI_MakeWire(bz_curv_edge).Wire() display.DisplayShape(bz_curv_wire) # Creation of profile to sweep along the spine circle = gp_Circ(gp_ZOX(), 1) circle.SetLocation(array[0]) circle_edge = BRepBuilderAPI_MakeEdge(circle).Edge() circle_wire = BRepBuilderAPI_MakeWire(circle_edge).Wire() # Creation of the law to dictate the evolution of the profile brep1 = BRepOffsetAPI_MakePipeShell(bz_curv_wire) law_f = Law_Linear() law_f.Set(0, 0.5, 1, 1) brep1.SetLaw(circle_wire, law_f, False, True) return brep1.Shape()
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 convert_curve(curve): d1_feat = {"type": edge_map[curve.GetType()]} c_type = d1_feat["type"] if c_type == "Line": c = curve.Line() d1_feat["location"] = list(c.Location().Coord()) d1_feat["direction"] = list(c.Direction().Coord()) scale_factor = 1000.0 elif c_type == "Circle": c = curve.Circle() d1_feat["location"] = list(c.Location().Coord()) d1_feat["z_axis"] = list(c.Axis().Direction().Coord()) d1_feat["radius"] = c.Radius() d1_feat["x_axis"] = list(c.XAxis().Direction().Coord()) d1_feat["y_axis"] = list(c.YAxis().Direction().Coord()) scale_factor = 1.0 elif c_type == "Ellipse": c = curve.Ellipse() d1_feat["focus1"] = list(c.Focus1().Coord()) d1_feat["focus2"] = list(c.Focus2().Coord()) d1_feat["x_axis"] = list(c.XAxis().Direction().Coord()) d1_feat["y_axis"] = list(c.YAxis().Direction().Coord()) d1_feat["z_axis"] = list(c.Axis().Direction().Coord()) d1_feat["maj_radius"] = c.MajorRadius() d1_feat["min_radius"] = c.MinorRadius() scale_factor = 1.0 elif c_type == "BSpline": c = curve.BSpline() c.SetNotPeriodic() d1_feat["rational"] = c.IsRational() d1_feat["closed"] = c.IsClosed() d1_feat["continuity"] = c.Continuity() d1_feat["degree"] = c.Degree() p = TColgp_Array1OfPnt(1, c.NbPoles()) c.Poles(p) points = [] for pi in range(p.Length()): points.append(list(p.Value(pi + 1).Coord())) d1_feat["poles"] = points k = TColStd_Array1OfReal(1, c.NbPoles() + c.Degree() + 1) c.KnotSequence(k) knots = [] for ki in range(k.Length()): knots.append(k.Value(ki + 1)) d1_feat["knots"] = knots w = TColStd_Array1OfReal(1, c.NbPoles()) c.Weights(w) weights = [] for wi in range(w.Length()): weights.append(w.Value(wi + 1)) d1_feat["weights"] = weights scale_factor = 1.0 else: print("Unsupported type 3d", c_type) return d1_feat
def gen_data_spline(self, dat): num = dat.shape[0] pts = TColgp_Array1OfPnt(1, num) for i, xyz in enumerate(dat): pnt = gp_Pnt(*xyz) pts.SetValue(i+1, pnt) geo_spl = GeomAPI_PointsToBSpline(pts) return geo_spl
def beziercurve(): # the first bezier curve array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0,-5)) array.SetValue(2, gp_Pnt(1, 2,1)) array.SetValue(3, gp_Pnt(2, 3,2)) array.SetValue(4, gp_Pnt(4, 3,-2)) array.SetValue(5, gp_Pnt(10, 5,-2)) beziercurve = Geom_BezierCurve(array) # the first bezier curve array1 = TColgp_Array1OfPnt(1, 5) array1.SetValue(1, gp_Pnt(0, 0, -5)) array1.SetValue(2, gp_Pnt(2, -2, 1)) array1.SetValue(3, gp_Pnt(2, -3, 2)) array1.SetValue(4, gp_Pnt(-4, 1, -2)) array1.SetValue(5, gp_Pnt(1, 5, -2)) beziercurve1 = Geom_BezierCurve(array1) array2 = TColgp_Array1OfPnt(1, 5) array2.SetValue(1, gp_Pnt(0, 0, -5)) array2.SetValue(2, gp_Pnt(-2, 2, 1)) array2.SetValue(3, gp_Pnt(2, -2, 2)) array2.SetValue(4, gp_Pnt(-4, 8, -2)) array2.SetValue(5, gp_Pnt(1, 5, -9)) beziercurve2 = Geom_BezierCurve(array2) plane = Geom_Plane(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0, 1, 1)) display.DisplayShape(plane, color='RED') surface1=GeomFill_BezierCurves(beziercurve,beziercurve1,beziercurve2,GeomFill_CurvedStyle) surface2 = GeomFill_BezierCurves(beziercurve, beziercurve1, GeomFill_StretchStyle) surface3 = GeomFill_BezierCurves(beziercurve, beziercurve1, GeomFill_CoonsStyle) bounds = True toldegen = 1e-6 face = BRepBuilderAPI_MakeFace() face.Init(surface1.Surface(), bounds, toldegen) face.Build() shapes = face.Shape() fix=AIS_FixRelation(shapes,plane) display.Context.Display(fix, True) display.DisplayShape(shapes, color="RED")
def curv_spl(px, py, axs=gp_Ax3()): nx = px.shape[0] pts = TColgp_Array1OfPnt(1, nx) for idx in range(pts.Lower(), pts.Upper() + 1): pnt = gp_Pnt(px[idx - 1], py[idx - 1], 0) pts.SetValue(idx, pnt) curv = GeomAPI_PointsToBSpline(pts, 3, 8, GeomAbs_C2, 0.001).Curve() return curv
def makeBezierCurve(self, point_array, last_point=None): if last_point: array = TColgp_Array1OfPnt(1, len(point_array) + 1) for i, p in enumerate(point_array): array.SetValue(i + 1, p) array.SetValue(len(point_array) + 1, last_point) else: array = TColgp_Array1OfPnt(1, len(point_array)) for i, p in enumerate(point_array): array.SetValue(i + 1, p) bezier_curve = Geom_BezierCurve(array) if self._tmp_geometry: edge = BRepBuilderAPI_MakeEdge(bezier_curve) shapes = edge.Shape() self._tmp_geometry.SetShape(shapes) self._tmp_geometry.Redisplay(False) else: ais_bezier = self._display.DisplayShape(bezier_curve) self._tmp_geometry = ais_bezier
def beziercurve(): # the first bezier curve array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0, -5)) array.SetValue(2, gp_Pnt(1, 2, 1)) array.SetValue(3, gp_Pnt(2, 3, 2)) array.SetValue(4, gp_Pnt(4, 3, -2)) array.SetValue(5, gp_Pnt(5, 5, -2)) beziercurve = gce_MakeCirc(gp_Ax2(), 2).Value() display.Context.Display(beziercurve, update=True)
def spl_curv(px, py, pz): num = px.size pts = [] p_array = TColgp_Array1OfPnt(1, num) for idx, t in enumerate(px): x = px[idx] y = py[idx] z = pz[idx] pnt = gp_Pnt(x, y, z) pts.append(pnt) p_array.SetValue(idx + 1, pnt) api = GeomAPI_PointsToBSpline(p_array) return p_array, api.Curve()
def makeBSpline(self, point_array, last_point=None): if last_point: array = TColgp_Array1OfPnt(1, len(point_array) + 1) for i, p in enumerate(point_array): array.SetValue(i + 1, p) array.SetValue(len(point_array) + 1, last_point) else: array = TColgp_Array1OfPnt(1, len(point_array)) for i, p in enumerate(point_array): array.SetValue(i + 1, p) try: bspline = GeomAPI_PointsToBSpline(array).Curve() if self._tmp_geometry: edge = BRepBuilderAPI_MakeEdge(bspline) shapes = edge.Shape() self._tmp_geometry.SetShape(shapes) self._tmp_geometry.Redisplay(False) else: ais_bspline = self._display.DisplayShape(bspline) self._tmp_geometry = ais_bspline except: pass
def _create_edge_from_bezier_pts(cls, start, end, *control_pts): create_gp_pnt = cls._get_create_gp_pnt_func() arr = TColgp_Array1OfPnt(0, 1 + len(control_pts)) arr.SetValue(0, create_gp_pnt((start.real, start.imag))) index = 1 for cp in control_pts: arr.SetValue(index, create_gp_pnt((cp.real, cp.imag))) index += 1 arr.SetValue(index, create_gp_pnt((end.real, end.imag))) bcurve = Geom_BezierCurve(arr) bspline = g2dc.GeomConvert_CompCurveToBSplineCurve( bcurve).BSplineCurve() edge = BRepBuilderAPI_MakeEdge(bspline).Edge() return edge
def edge(event=None): # The blud edge BlueEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20), gp_Pnt(-30, -60, -60)) V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30)) V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25)) YellowEdge = BRepBuilderAPI_MakeEdge(V1.Vertex(), V2.Vertex()) #The white edge line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0))) WhiteEdge = BRepBuilderAPI_MakeEdge(line, -20, 10) #The red edge Elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30) RedEdge = BRepBuilderAPI_MakeEdge(Elips, 0, math.pi/2) # The green edge and the both extreme vertex P1 = gp_Pnt(-15, 200, 10) P2 = gp_Pnt(5, 204, 0) P3 = gp_Pnt(15, 200, 0) P4 = gp_Pnt(-15, 20, 15) P5 = gp_Pnt(-5, 20, 0) P6 = gp_Pnt(15, 20, 0) P7 = gp_Pnt(24, 120, 0) P8 = gp_Pnt(-24, 120, 12.5) array = TColgp_Array1OfPnt(1, 8) array.SetValue(1, P1) array.SetValue(2, P2) array.SetValue(3, P3) array.SetValue(4, P4) array.SetValue(5, P5) array.SetValue(6, P6) array.SetValue(7, P7) array.SetValue(8, P8) curve = Geom_BezierCurve(array) ME = BRepBuilderAPI_MakeEdge(curve) GreenEdge = ME V3 = ME.Vertex1() V4 = ME.Vertex2() display.DisplayColoredShape(BlueEdge.Edge(), 'BLUE') display.DisplayShape(V1.Vertex()) display.DisplayShape(V2.Vertex()) display.DisplayColoredShape(WhiteEdge.Edge(), 'WHITE') display.DisplayColoredShape(YellowEdge.Edge(), 'YELLOW') display.DisplayColoredShape(RedEdge.Edge(), 'RED') display.DisplayColoredShape(GreenEdge.Edge(), 'GREEN') display.DisplayShape(V3) display.DisplayShape(V4, update=True)
def array1_from_points1(points: List[Point]) -> TColgp_Array1OfPnt: """Construct a one-dimensional point array from a list of points. Parameters ---------- points : list[:class:`~compas.geometry.Point`] Returns ------- TColgp_Array1OfPnt """ array = TColgp_Array1OfPnt(1, len(points)) for index, point in enumerate(points): array.SetValue(index + 1, gp_Pnt(* point)) return array
def __init__(self): plotocc.__init__(self) self.axs = gp_Ax3() p_array = TColgp_Array1OfPnt(1, 100) for idx, pt in enumerate(np.linspace(-2.0, 2.0, 100)): pnt = gp_Pnt(300 * np.sin(pt), 100 * np.cos(3 * pt), 0) p_array.SetValue(idx + 1, pnt) api = GeomAPI_PointsToBSpline(p_array) self.curv = api.Curve() print(self.curv) api = BRepOffsetAPI_ThruSections() api.SetSmoothing(True) num_list = [ 3, 3, 3, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 4, 4, 4 ] p1, v1, v2 = gp_Pnt(), gp_Vec(), gp_Vec() for idx, pt in enumerate(np.linspace(0.0, 0.5, len(num_list))): GeomLProp_CurveTool.D2(self.curv, pt, p1, v1, v2) v3 = v1.Crossed(v2) axis = gp_Ax3(p1, vec_to_dir(v1), vec_to_dir(v2)) poly = self.make_PolyWire(num=num_list[idx], radi=20, axs=axis) api.AddWire(poly) self.show_axs_pln(axis, scale=10) self.display.DisplayShape(poly) api.Build() self.display.DisplayShape(api.Shape()) write_step_file(api.Shape(), "./tmp/ThruPipe_Hex.stp") api = BRepOffsetAPI_ThruSections() # api.SetSmoothing(True) p1, v1, v2 = gp_Pnt(), gp_Vec(), gp_Vec() for idx, pt in enumerate(np.linspace(0.55, 1.0, 20)): GeomLProp_CurveTool.D2(self.curv, pt, p1, v1, v2) v3 = v1.Crossed(v2) axis = gp_Ax3(p1, vec_to_dir(v1), vec_to_dir(v2)) shft = 90 * pt poly = self.make_Ellip(rxy=[15, 10], shft=shft, axs=axis) api.AddWire(poly) self.display.DisplayShape(poly) api.Build() self.display.DisplayShape(api.Shape()) write_step_file(api.Shape(), "./tmp/ThruPipe_Ellip.stp")
def beziercurve(): # the first bezier curve array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0,-5)) array.SetValue(2, gp_Pnt(1, 2,1)) array.SetValue(3, gp_Pnt(2, 3,2)) array.SetValue(4, gp_Pnt(4, 3,-2)) array.SetValue(5, gp_Pnt(5, 5,-2)) beziercurve = Geom_BezierCurve(array) surface=Geom_SurfaceOfRevolution(beziercurve,gp_Ax1(gp_Pnt(0.0,0.0,0.0),gp_Dir(1.0,1.0,0.0))) print(surface.Bounds()) poles=beziercurve.Poles() for j in range(array.Lower(), array.Upper()+1): p = array.Value(j) display.DisplayShape(p, update=False) display.DisplayShape(surface, update=True, color='Blue')
def beziercurve(): # the first bezier curve array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0,-5)) array.SetValue(2, gp_Pnt(1, 2,1)) array.SetValue(3, gp_Pnt(2, 3,2)) array.SetValue(4, gp_Pnt(4, 3,-2)) array.SetValue(5, gp_Pnt(100, 5,-2)) beziercurve = Geom_BezierCurve(array) poles=beziercurve.Poles() collection=TColStd_HSequenceOfTransient() collection.Append(beziercurve) collection.Append(beziercurve) collection.Append(beziercurve) collection.Append(beziercurve) for idx in range(1,collection.Length()+1): print(idx,Geom_BezierCurve.DownCast(collection.Value(idx))) display.DisplayShape(beziercurve, color='RED')
def test_array_iterator(self): P0 = gp_Pnt(1, 2, 3) list_of_points = TColgp_Array1OfPnt(5, 8) self.assertEqual(len(list_of_points), 4) # set item list_of_points[1] = P0 # then get item self.assertEqual(list_of_points[1].Coord(), (1.0, 2.0, 3.0)) with self.assertRaises(IndexError): list_of_points[4] # iterator creation it = iter(list_of_points) next(it) # test loop over iterable for pnt in list_of_points: self.assertTrue(isinstance(pnt, gp_Pnt))
def CloseBezierCurve(self): self.myContext.Remove(self.myRubberAIS_Shape, True) self.bezier_curve.Compute() self.bezierNode = BezierNode(self.bezier_curve.GetName(), self.rootNode) self.bezierNode.setSketchObject(self.bezier_curve) self.AddObject(self.bezier_curve.GetGeometry2d(), self.bezier_curve.GetAIS_Object(), Sketch_GeometryType.CurveSketchObject) # create new object curgp_Array1CurvePoles2d = TColgp_Array1OfPnt2d(1, 2) curgp_Array1CurvePoles2d.SetValue(1, gp.Origin2d()) curgp_Array1CurvePoles2d.SetValue(2, gp.Origin2d()) self.myGeom2d_BezierCurve = Geom2d_BezierCurve( curgp_Array1CurvePoles2d) curgp_Array1CurvePoles = TColgp_Array1OfPnt(1, 2) curgp_Array1CurvePoles.SetValue(1, gp.Origin()) curgp_Array1CurvePoles.SetValue(2, gp.Origin()) self.myGeom_BezierCurve = Geom_BezierCurve(curgp_Array1CurvePoles) self.IndexCounter = 1 self.myBezierCurveAction = BezierCurveAction.Input_1Point
def __init__(self): super(Sketch_CommandBezierCurve, self).__init__("BezierCurve.") self.IndexCounter = 1 self.tempPnt2d = gp.Origin2d() self.myFirstgp_Pnt = gp.Origin() self.tempPnt = gp.Origin() self.curEdge = TopoDS_Edge() self.myBezierCurveAction = BezierCurveAction.Nothing curgp_Array1CurvePoles2d = TColgp_Array1OfPnt2d(1, 2) curgp_Array1CurvePoles2d.SetValue(1, gp.Origin2d()) curgp_Array1CurvePoles2d.SetValue(2, gp.Origin2d()) self.myGeom2d_BezierCurve = Geom2d_BezierCurve( curgp_Array1CurvePoles2d) curgp_Array1CurvePoles = TColgp_Array1OfPnt(1, 2) curgp_Array1CurvePoles.SetValue(1, gp.Origin()) curgp_Array1CurvePoles.SetValue(2, gp.Origin()) self.myGeom_BezierCurve = Geom_BezierCurve(curgp_Array1CurvePoles) self.myRubberAIS_Shape = AIS_Shape(self.curEdge)
def beziercurve(): # the first bezier curve array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0, -5)) array.SetValue(2, gp_Pnt(1, 2, 1)) array.SetValue(3, gp_Pnt(2, 3, 2)) array.SetValue(4, gp_Pnt(4, 3, -2)) array.SetValue(5, gp_Pnt(100, 5, -2)) beziercurve = Geom_BezierCurve(array) poles = beziercurve.Poles() for p in poles: print(p.X(), p.Y(), p.Z()) beziercurve.Increase(5) poles = beziercurve.Poles() for p in poles: print(p.X(), p.Y(), p.Z()) print(beziercurve.Continuity(), beziercurve.Degree(), beziercurve.Continuity(), poles) for j in range(array.Lower(), array.Upper() + 1): p = array.Value(j) display.DisplayShape(p) ais_curve = display.DisplayShape(beziercurve, color='RED') start_pnt = gp_Trsf() start_pnt.SetValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0) end_pnt = gp_Trsf() end_pnt.SetValues(1, 0, 0, 100, 0, 1, 0, 100, 0, 0, 1, 100) animation = AIS_Animation(TCollection_AsciiString("obj1")) animation_obj = AIS_AnimationObject(TCollection_AsciiString("obj1"), display.Context, ais_curve, start_pnt, end_pnt) animation_obj.SetOwnDuration(2) animation_obj.SetStartPts(0) animation.Add(animation_obj) duration = animation.Duration() animation.StartTimer(0, 1.0, True) while not animation.IsStopped(): animation.UpdateTimer() display.Context.UpdateCurrentViewer()
def revolved_cut(base): # Define 7 points face_points = TColgp_Array1OfPnt(1, 7) face_inner_radius = 0.6 pts = [ gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05), gp_Pnt(face_inner_radius - 0.10, 0.0, -0.025), gp_Pnt(face_inner_radius - 0.10, 0.0, 0.025), gp_Pnt(face_inner_radius + 0.10, 0.0, 0.025), gp_Pnt(face_inner_radius + 0.10, 0.0, -0.025), gp_Pnt(face_inner_radius + 0.05, 0.0, -0.05), gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05), ] for n, i in enumerate(pts): face_points.SetValue(n + 1, i) # Use these points to create edges and add these edges to a wire hexwire = BRepBuilderAPI_MakeWire() for i in range(1, 7): hexedge = BRepBuilderAPI_MakeEdge(face_points.Value(i), face_points.Value(i + 1)).Edge() hexwire.Add(hexedge) # Turn the wire into a 6 sided face hexface = BRepBuilderAPI_MakeFace(hexwire.Wire()).Face() # Revolve the face around an axis revolve_axis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) revolved_shape = BRepPrimAPI_MakeRevol(hexface, revolve_axis).Shape() # Move the generated shape move = gp_Trsf() move.SetTranslation(gp_Pnt(0, 0, 0), gp_Pnt(0, 0, sin(0.5))) moved_shape = BRepBuilderAPI_Transform(revolved_shape, move, False).Shape() # Remove the revolved shape cut = BRepAlgoAPI_Cut(base, moved_shape).Shape() return cut
def to_tcolgp_array1_pnt(pnts): """ Convert the 1-D array of point_like entities to OCC data. :param array_like pnts: Array of points to convert. :return: OCC array of points. :rtype: TColgp_Array1OfPnt """ gp_pnts = [] for gp in pnts: gp = to_gp_pnt(gp) if not gp: continue gp_pnts.append(gp) n = len(gp_pnts) array = TColgp_Array1OfPnt(1, n) for i, gp in enumerate(gp_pnts, 1): array.SetValue(i, gp) return array
def beziercurve(): # the first bezier curve array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0, -5)) array.SetValue(2, gp_Pnt(1, 2, 1)) array.SetValue(3, gp_Pnt(2, 3, 2)) array.SetValue(4, gp_Pnt(4, 3, -2)) array.SetValue(5, gp_Pnt(100, 5, -2)) beziercurve = Geom_BezierCurve(array) poles = beziercurve.Poles() for p in poles: print(p.X(), p.Y(), p.Z()) beziercurve.Increase(5) poles = beziercurve.Poles() for p in poles: print(p.X(), p.Y(), p.Z()) print(beziercurve.Continuity(), beziercurve.Degree(), beziercurve.Continuity(), poles) for j in range(array.Lower(), array.Upper() + 1): p = array.Value(j) display.DisplayShape(p) display.DisplayShape(beziercurve, color='RED')
def np2occ_points(pts): """Converts numpy array of points into occ points array """ if len(pts.shape) == 2: n, m = pts.shape occ_array = TColgp_Array1OfPnt(1, n) for i in range(n): if m == 2: occ_array.SetValue(i + 1, gp_Pnt(pts[i, 0], pts[i, 1], 0.)) elif m == 3: occ_array.SetValue(i + 1, gp_Pnt(pts[i, 0], pts[i, 1], pts[i, 2])) return occ_array elif len(pts.shape) == 3: n, m, _ = pts.shape occ_array = TColgp_Array2OfPnt(1, n, 1, m) for i in range(n): for j in range(m): occ_array.SetValue( i + 1, j + 1, gp_Pnt(pts[i, j, 0], pts[i, j, 1], pts[i, j, 2])) return occ_array else: raise ValueError('Wrong points dimension')
def beziercurve(): # the first bezier curve array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0, -5)) array.SetValue(2, gp_Pnt(1, 2, 1)) array.SetValue(3, gp_Pnt(2, 3, 2)) array.SetValue(4, gp_Pnt(4, 3, -2)) array.SetValue(5, gp_Pnt(10, 5, -2)) beziercurve = Geom_BezierCurve(array) edge = BRepBuilderAPI_MakeEdge(beziercurve) shapes = edge.Shape() ais_shape = AIS_Shape(shapes) display.Context.Display(ais_shape, True) transform = gp_Trsf() transform.SetTranslation(gp_Vec(10, 10, -50)) transform.SetRotation(gp_Ax1(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 1.0, 0.0)), 180) curve_transform = BRepBuilderAPI_Transform(transform) curve_transform.Perform(shapes, False) shape2 = AIS_Shape(shapes) display.Context.Display(shape2, True) display.FitAll()
def point_list_to_TColgp_Array1OfPnt(li): pts = TColgp_Array1OfPnt(0, len(li) - 1) for n, i in enumerate(li): pts.SetValue(n, i) return pts
def points_to_bspline(pnts): pts = TColgp_Array1OfPnt(0, len(pnts) - 1) for n, i in enumerate(pnts): pts.SetValue(n, i) crv = GeomAPI_PointsToBSpline(pts) return crv.Curve()