Пример #1
0
def makeSVGedge(e):
    """

    """

    cs = StringIO.StringIO()

    curve = e._geomAdaptor()  # adapt the edge into curve
    start = curve.FirstParameter()
    end = curve.LastParameter()

    points = GCPnts_QuasiUniformDeflection(curve,
                                           DISCRETIZATION_TOLERANCE,
                                           start,
                                           end)

    if points.IsDone():
        point_it = (points.Value(i + 1) for i in
                    range(points.NbPoints()))

        p = next(point_it)
        cs.write('M{},{} '.format(p.X(), p.Y()))

        for p in point_it:
            cs.write('L{},{} '.format(p.X(), p.Y()))

    return cs.getvalue()
Пример #2
0
def discretize_edge(a_topods_edge, deflection=0.2, algorithm="QuasiUniformDeflection"):
    """ 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
    algorithm: to choose in ["UniformAbscissa", "QuasiUniformDeflection"]
    """
    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()

    if algorithm == "QuasiUniformDeflection":
        discretizer = GCPnts_QuasiUniformDeflection()
    elif algorithm == "UniformAbscissa":
        discretizer = GCPnts_UniformAbscissa()
    elif algorithm == "UniformDeflection":
        discretizer = GCPnts_UniformDeflection()
    else:
        raise AssertionError("Unknown algorithm")
    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
Пример #3
0
def _reloft_wing_surface(srf, tol):
    """
    Attempt to reloft an OpenVSP wing surface which was not split to achieve
    higher continuity.
    """
    logger.info('\tAttempting to reloft the surface...')
    # Gather isocurves at each section, tessellate, and approximate
    crvs = []
    for u in srf.uknots:
        c0 = srf.u_iso(u)
        adp_crv = AdaptorCurve.to_adaptor(c0)
        tool = GCPnts_QuasiUniformDeflection(adp_crv.object, tol)
        if not tool.IsDone():
            logger.info('\tTessellation failed. Using original surface.')
            return srf
        pnts = [
            c0.eval(tool.Parameter(i)) for i in range(1,
                                                      tool.NbPoints() + 1)
        ]
        c = NurbsCurveByApprox(pnts, tol=tol, continuity=Geometry.C1).curve
        crvs.append(c)
    return NurbsSurfaceByInterp(crvs, 1).surface