示例#1
0
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()
示例#2
0
def points_to_bspline(pnts):
    '''
    Points to bspline
    '''
    pnts = point_list_to_TColgp_Array1OfPnt(pnts)
    crv = GeomAPI_PointsToBSpline(pnts)
    return crv.Curve()
示例#3
0
def gen_data_spline(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, 4)
    return geo_spl.Curve()
示例#4
0
def spline_from_polyline(pol):
    from OCC.Extend.ShapeFactory import point_list_to_TColgp_Array1OfPnt, make_face
    from OCC.Core.GeomAPI import GeomAPI_PointsToBSpline
    array = []
    for p in pol:
        array.append(gp_Pnt(p[0], p[1], p[2]))
    pt_list1 = point_list_to_TColgp_Array1OfPnt(array)
    SPL1 = GeomAPI_PointsToBSpline(pt_list1).Curve()
    SPL1 = GeomAPI_PointsToBSpline(pt_list1)
    edge = BRepBuilderAPI_MakeEdge(SPL1.Curve())
    wire = BRepBuilderAPI_MakeWire(edge.Edge())
    return edge.Shape(), wire
示例#5
0
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()
示例#6
0
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 OCC.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()
示例#7
0
    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 InterpolatePoints(self):
     curgp_Array1CurvePoles2d = point_list_to_TColgp_Array1OfPnt2d(self.Poles2d)
     curgp_Array1CurvePoles = point_list_to_TColgp_Array1OfPnt(self.Poles)
     # self.FindPoints(self.Poles2d)
     # self.FindPoints(self.Poles)
     try:
         myGeom2d_BSplineCurve = Geom2dAPI_PointsToBSpline(curgp_Array1CurvePoles2d)
         if myGeom2d_BSplineCurve.IsDone():
             self.myGeom2d_BSplineCurve = myGeom2d_BSplineCurve.Curve()
     except Exception as e:
         print(e)
     try:
         myGeom_BSplineCurve = GeomAPI_PointsToBSpline(curgp_Array1CurvePoles)
         if myGeom_BSplineCurve.IsDone():
             self.myGeom_BSplineCurve = myGeom_BSplineCurve.Curve()
     except Exception as e:
         print(e)
def approx_points_by_piecewise_bezier(points_3d, degree, tol):
    if degree not in (2, 3):
        raise RuntimeError(
            "SVG files only support Bezier curves of degree 2 or 3")

    points_3d_occ = [gp_Pnt(*p) for p in points_3d]
    approx_spline = GeomAPI_PointsToBSpline(
        point_list_to_TColgp_Array1OfPnt(points_3d_occ), degree, degree,
        GeomAbs_C1, tol)
    # TO DO:
    # why the following string doesn't yield a spline of degree < 3
    # approx_spline = GeomConvert_ApproxCurve(spline, tol, order, max_segments, max_degree)

    if not approx_spline.IsDone():
        raise RuntimeError(
            "Could not approximate points within a given tolerance")

    return GeomConvert_BSplineCurveToBezierCurve(approx_spline.Curve())
示例#10
0
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()
示例#11
0
    py = np.linspace(-1, 1, 15) * 120 / 2
    mesh = np.meshgrid(px, py)
    surf = mesh[0]**2 / 100 + mesh[1]**2 / 1000
    surf[7, 5] = 50
    obj.display.DisplayShape(spl_face(*mesh, surf))

    p0 = gp_Pnt(mesh[0][0, 0], mesh[1][0, 0], surf[0, 0])
    p1 = gp_Pnt(mesh[0][0, -1], mesh[1][0, -1], surf[0, -1])
    p2 = gp_Pnt(mesh[0][-1, 0], mesh[1][-1, 0], surf[-1, 0])
    p3 = gp_Pnt(mesh[0][-1, 1], mesh[1][-1, -1], surf[-1, -1])

    pt = np.linspace(0, 2 * np.pi, 100)
    pts = []
    p_array = TColgp_Array1OfPnt(1, 100 - 1)
    for idx, t in enumerate(pt[:-1]):
        x = 75.0 * np.cos(t)
        y = 75.0 * np.sin(t)
        z = 50 * np.cos(2 * t)
        pnt = gp_Pnt(x, y, z)
        pts.append(pnt)
        p_array.SetValue(idx + 1, pnt)
    api = GeomAPI_PointsToBSpline(p_array)
    #curve = geomapi.To3d(api.Curve())

    for idx, t in enumerate(pts):
        obj.display.DisplayShape(t)
    obj.display.DisplayShape(api.Curve())

    obj.show_axs_pln(axs, scale=20)
    obj.show()