Esempio n. 1
0
def discretize_edge(a_topods_edge, deflection=0.5):
    """ Take a TopoDS_Edge and returns a list of points
    The more deflection is small, the more the discretization is precise,
    i.e. the more points you get in the returned points
    """
    if not is_edge(a_topods_edge):
        raise AssertionError(
            "You must provide a TopoDS_Edge to the discretize_edge function.")
    if a_topods_edge.IsNull():
        print(
            "Warning : TopoDS_Edge is null. discretize_edge will return an empty list of points."
        )
        return []
    curve_adaptator = BRepAdaptor_Curve(a_topods_edge)
    first = curve_adaptator.FirstParameter()
    last = curve_adaptator.LastParameter()

    discretizer = GCPnts_UniformAbscissa()
    discretizer.Initialize(curve_adaptator, deflection, first, last)

    if not discretizer.IsDone():
        raise AssertionError("Discretizer not done.")
    if not discretizer.NbPoints() > 0:
        raise AssertionError("Discretizer nb points not > 0.")

    points = []
    for i in range(1, discretizer.NbPoints() + 1):
        p = curve_adaptator.Value(discretizer.Parameter(i))
        points.append(p.Coord())
    return points
Esempio n. 2
0
    def divide_by_number_of_points(self, n_pts, lbound=None, ubound=None):
        '''returns a nested list of parameters and points on the edge
        at the requested interval [(param, gp_Pnt),...]
        '''
        _lbound, _ubound = self.domain()
        if lbound:
            _lbound = lbound
        elif ubound:
            _ubound = ubound

        # minimally two points or a Standard_ConstructionError is raised
        if n_pts <= 1:
            n_pts = 2

        try:
            npts = GCPnts_UniformAbscissa(self.adaptor, n_pts, _lbound, _ubound)
        except:
            print("Warning : GCPnts_UniformAbscissa failed")
        if npts.IsDone():
            tmp = []
            for i in xrange(1, npts.NbPoints()+1):
                param = npts.Parameter(i)
                pnt = self.adaptor.Value(param)
                tmp.append((param, pnt))
            return tmp
        else:
            return None
Esempio n. 3
0
    def test_point_from_curve(self):
        '''Test: point from curve'''
        radius, abscissa = 5., 3.
        C = Geom2d_Circle(gp_OX2d(), radius, True)
        GAC = Geom2dAdaptor_Curve(C)
        UA = GCPnts_UniformAbscissa(GAC, abscissa)

        aSequence = []
        if UA.IsDone():
            N = UA.NbPoints()
            for count in range(1, N + 1):
                P = gp_Pnt2d()
                C.D0(UA.Parameter(count), P)
                Parameter = UA.Parameter(count)
                self.assertIsInstance(Parameter, float)
                aSequence.append(P)

        Abscissa = UA.Abscissa()
        self.assertEqual(Abscissa, abscissa)
Esempio n. 4
0
def divide_edge_by_nr_of_points(edg, n_pts):
    '''returns a nested list of parameters and points on the edge
    at the requested interval [(param, gp_Pnt),...]
    '''
    curve_adapt = BRepAdaptor_Curve(edg)
    _lbound, _ubound = curve_adapt.FirstParameter(), curve_adapt.LastParameter(
    )

    if n_pts <= 1:
        # minimally two points or a Standard_ConstructionError is raised
        raise AssertionError("minimally 2 points required")

    npts = GCPnts_UniformAbscissa(curve_adapt, n_pts, _lbound, _ubound)
    if npts.IsDone():
        tmp = []
        for i in range(1, npts.NbPoints() + 1):
            param = npts.Parameter(i)
            pnt = curve_adapt.Value(param)
            tmp.append((param, pnt))
        return tmp
Esempio n. 5
0
def points_from_curve():
    radius = 5.
    abscissa = 3.
    circle = Geom2d_Circle(gp_OX2d(), radius, True)
    gac = Geom2dAdaptor_Curve(circle)
    ua = GCPnts_UniformAbscissa(gac, abscissa)
    a_sequence = []
    if ua.IsDone():
        n = ua.NbPoints()
        for count in range(1, n + 1):
            p = gp_Pnt2d()
            circle.D0(ua.Parameter(count), p)
            a_sequence.append(p)
    # convert analytic to bspline
    display.DisplayShape(circle, update=True)
    i = 0
    for p in a_sequence:
        i = i + 1
        pstring = 'P%i : parameter %f' % (i, ua.Parameter(i))
        pnt = gp_Pnt(p.X(), p.Y(), 0)
        # display points
        display.DisplayShape(pnt, update=True)
        display.DisplayMessage(pnt, pstring)