コード例 #1
0
ファイル: intersect.py プロジェクト: buguen/aoc-utils
def _intersect_shape_by_line(topods_shape,
                             line,
                             low_parameter=0.0,
                             hi_parameter=float("+inf")):
    r"""Finds the intersection of a shape and a line

    Parameters
    ----------
    topods_shape : any TopoDS_*
    line : gp_Lin
    low_parameter : float, optional
        (the default value is 0.0)
    hi_parameter : float, optional
        (the default value is infinity)

    Returns
    -------
    a list of gp_Pnt

    """
    shape_inter = IntCurvesFace_ShapeIntersector()
    shape_inter.Load(topods_shape, OCCUTILS_DEFAULT_TOLERANCE)
    # shape_inter.PerformNearest(line, low_parameter, hi_parameter)
    shape_inter.Perform(line, low_parameter, hi_parameter)

    with AssertIsDone(shape_inter, "failed to computer shape / line "
                                   "intersection"):
        points = list()

        # Bug correction (some intersection points were missed)
        # for i in range(1, shape_inter.NbPnt()):
        for i in range(1, shape_inter.NbPnt() + 1):
            points.append(shape_inter.Pnt(i))

    return points
コード例 #2
0
ファイル: wire_make.py プロジェクト: buguen/aoc-utils
def polygon(args, closed=False):
    r"""Make a polygon

    Parameters
    ----------
    args
    closed : bool

    Returns
    -------
    OCC.TopoDS.TopoDS_Wire

    """
    poly = OCC.BRepBuilderAPI.BRepBuilderAPI_MakePolygon()
    for pt in args:
        # support nested lists
        if isinstance(pt, list) or isinstance(pt, tuple):
            for i in pt:
                poly.Add(i)
        else:
            poly.Add(pt)
    if closed:
        poly.Close()
    poly.Build()

    with AssertIsDone(poly, 'failed to produce wire'):
        result = poly.Wire()
        return result
コード例 #3
0
ファイル: intersect.py プロジェクト: buguen/aoc-utils
def shape_by_line(topods_shape,
                  line,
                  low_parameter=0.0,
                  hi_parameter=float("+inf")):
    r"""Finds the intersection of a shape and a line

    Parameters
    ----------
    topods_shape : any TopoDS_*
    line : gp_Lin
    low_parameter : float, optional
        (the default value is 0.0)
    hi_parameter : float, optional
        (the default value is infinity)

    Returns
    -------
    a list with a number of tuples that corresponds to the
    number of intersections found.
    the tuple contains ( OCC.gp.gp_Pnt, TopoDS_Face, u,v,w ),
    respectively the intersection point, the intersecting face
    and the u,v,w parameters of the intersection point

    """
    shape_inter = IntCurvesFace_ShapeIntersector()
    shape_inter.Load(topods_shape, OCCUTILS_DEFAULT_TOLERANCE)
    shape_inter.PerformNearest(line, low_parameter, hi_parameter)

    with AssertIsDone(shape_inter,
                      "failed to computer shape / line intersection"):
        return (shape_inter.Pnt(1),
                shape_inter.Face(1),
                shape_inter.UParameter(1),
                shape_inter.VParameter(1),
                shape_inter.WParameter(1))
コード例 #4
0
ファイル: wire_make.py プロジェクト: buguen/aoc-utils
def wire(*args):
    r"""Make a OCC.TopoDS.TopoDS_Wire

    Parameters
    ----------
    args

    Returns
    -------
    OCC.TopoDS.TopoDS_Wire

    """
    # if we get an iterable, than add all edges to wire builder
    if isinstance(args[0], list) or isinstance(args[0], tuple):
        a_wire = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeWire()
        for i in args[0]:
            a_wire.Add(i)
        a_wire.Build()
        return a_wire.Wire()

    a_wire = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeWire(*args)
    a_wire.Build()
    with AssertIsDone(a_wire, 'failed to produce wire'):
        result = a_wire.Wire()
        return result
コード例 #5
0
def solid(*args):
    r"""Make a OCC.TopoDS.TopoDS_Solid

    Parameters
    ----------
    args

    Returns
    -------
    OCC.TopoDS.TopoDS_Solid

    Notes
    -----
    BRepBuilderAPI_MakeSolid ()
    BRepBuilderAPI_MakeSolid (const TopoDS_CompSolid &S)
    BRepBuilderAPI_MakeSolid (const TopoDS_Shell &S)
    BRepBuilderAPI_MakeSolid (const TopoDS_Shell &S1, const TopoDS_Shell &S2)
    BRepBuilderAPI_MakeSolid (const TopoDS_Shell &S1,
                              const TopoDS_Shell &S2,
                              const TopoDS_Shell &S3)
    BRepBuilderAPI_MakeSolid (const TopoDS_Solid &So)
    BRepBuilderAPI_MakeSolid (const TopoDS_Solid &So, const TopoDS_Shell &S)

    """
    sld = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeSolid(*args)
    with AssertIsDone(sld, 'failed to produce solid'):
        result = sld.Solid()
        sld.Delete()
        return result
コード例 #6
0
    def __init__(self, shape_1, shape_2):
        dist_shape_shape = BRepExtrema_DistShapeShape(shape_1, shape_2)
        dist_shape_shape.Perform()

        with AssertIsDone(dist_shape_shape,
                          'Failed computing minimum distances'):
            self._min_dist = dist_shape_shape.Value()
            self._points_pairs = list()
            self._nb_solutions = dist_shape_shape.NbSolution()
            for i in range(1, dist_shape_shape.NbSolution() + 1):
                self._points_pairs.append((dist_shape_shape.PointOnShape1(i),
                                           dist_shape_shape.PointOnShape2(i)))
コード例 #7
0
ファイル: vertex_make.py プロジェクト: buguen/aoc-utils
def vertex(*args):
    r"""Make a OCC.TopoDS.TopoDS_Vertex

    Parameters
    ----------
    args

    Returns
    -------
    OCC.TopoDS.TopoDS_Vertex

    """
    vert = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeVertex(*args)
    with AssertIsDone(vert, 'failed to produce vertex'):
        result = vert.Vertex()
        vert.Delete()
        return result
コード例 #8
0
ファイル: extrude.py プロジェクト: buguen/aoc-utils
def extrude(profile, vec):
    r"""Makes a finite prism

    Parameters
    ----------
    profile : OCC.TopoDS.TopoDS_Wire
    vec : OCC.gp.gp_Vec

    Returns
    -------
    OCC.TopoDS.TopoDS_Shape

    """
    pri = OCC.BRepPrimAPI.BRepPrimAPI_MakePrism(profile, vec, True)
    with AssertIsDone(pri, 'failed building prism'):
        pri.Build()
        return pri.Shape()
コード例 #9
0
ファイル: pipe.py プロジェクト: buguen/aoc-utils
def pipe(spine, profile):
    r"""Make a pipe

    Parameters
    ----------
    spine : OCC.TopoDS.TopoDS_Wire
    profile : OCC.TopoDS.TopoDS_Wire

    Returns
    -------
    OCC.TopoDS.TopoDS_Shape

    """
    a_pipe = OCC.BRepOffsetAPI.BRepOffsetAPI_MakePipe(spine, profile)
    with AssertIsDone(a_pipe, 'failed building pipe'):
        a_pipe.Build()
        return a_pipe.Shape()
コード例 #10
0
def evolved(spine, profile):
    r"""Make an evolved shape

    Parameters
    ----------
    spine : OCC.TopoDS.TopoDS_Wire
    profile : OCC.TopoDS.TopoDS_Wire

    Returns
    -------
    BRepFill_Evolved

    """
    evol = OCC.BRepOffsetAPI.BRepOffsetAPI_MakeEvolved(spine, profile)
    with AssertIsDone(evol, 'failed building evolved'):
        evol.Build()
        return evol.Evolved()
コード例 #11
0
ファイル: loft.py プロジェクト: buguen/aoc-utils
def loft(elements,
         ruled=False,
         tolerance=OCCUTILS_DEFAULT_TOLERANCE,
         continuity=OCC.GeomAbs.GeomAbs_C2,
         check_compatibility=True):
    r"""Loft

    Parameters
    ----------
    elements
    ruled : bool
    tolerance : float
    continuity : OCC.GeomAbs.GeomAbs_C*, optional
        (the default is OCC.GeomAbs.GeomAbs_C2)
    check_compatibility : bool

    Returns
    -------
    OCC.TopoDS.TopoDS_*

    """
    sections = OCC.BRepOffsetAPI.BRepOffsetAPI_ThruSections(
        False, ruled, tolerance)
    for i in elements:
        if isinstance(i, OCC.TopoDS.TopoDS_Wire):
            sections.AddWire(i)
        elif isinstance(i, OCC.TopoDS.TopoDS_Vertex):
            sections.AddVertex(i)
        else:
            msg = "elements is a list of OCC.TopoDS.TopoDS_Wire or OCC.TopoDS.TopoDS_Vertex, found a %s " % i.__class__
            logger.error(msg)
            raise TypeError(msg)

    sections.CheckCompatibility(check_compatibility)
    sections.SetContinuity(continuity)
    sections.Build()
    with AssertIsDone(sections, 'failed lofting'):
        # te = occutils.topology.shape_to_topology()
        return shape_to_topology(sections.Shape())
コード例 #12
0
ファイル: wire_make.py プロジェクト: buguen/aoc-utils
def closed_polygon(*args):
    r"""Make a closed polygon

    Parameters
    ----------
    args

    Returns
    -------
    OCC.TopoDS.TopoDS_Wire

    """
    poly = OCC.BRepBuilderAPI.BRepBuilderAPI_MakePolygon()
    for pt in args:
        if isinstance(pt, list) or isinstance(pt, tuple):
            for i in pt:
                poly.Add(i)
        else:
            poly.Add(pt)
    poly.Build()
    poly.Close()
    with AssertIsDone(poly, 'failed to produce wire'):
        result = poly.Wire()
        return result