示例#1
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:
            #import ipdb; ipdb.set_trace()
            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
def Uniform_Points_on_Curve(curve, NPoints):
    """Returns a list of uniformly spaced points on a curve
    Parameters
    ----------
    crv : OCC.Geom curve type
    NPoints : int
        number of sampling points along the curve"""
    try:
        adapt = GeomAdaptor_Curve(curve)
    except:
        # Allow the algorithm to deal with TopoDS_Edge and Wire shapes:
        adapt = BRepAdaptor_Curve(curve)
    absc = GCPnts_UniformAbscissa(adapt, NPoints)
    return [adapt.Value(absc.Parameter(i)) for i in range(1, NPoints + 1)]
示例#3
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
     npts = GCPnts_UniformAbscissa(self.adaptor, n_pts, _lbound, _ubound)
     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
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
示例#5
0
def points_from_curve():
    radius = 5.
    abscissa = 3.
    circle = Geom2d_Circle(gp_OX2d(), radius, True)
    gac = Geom2dAdaptor_Curve(circle.GetHandle())
    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 += 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)