Ejemplo n.º 1
0
def evolved_shape():
    P = BRepBuilderAPI_MakePolygon()
    P.Add(gp_Pnt(0., 0., 0.))
    P.Add(gp_Pnt(200., 0., 0.))
    P.Add(gp_Pnt(200., 200., 0.))
    P.Add(gp_Pnt(0., 200., 0.))
    P.Add(gp_Pnt(0., 0., 0.))
    wprof = BRepBuilderAPI_MakePolygon(gp_Pnt(0., 0., 0.),
                                       gp_Pnt(-60., -60., -200.))
    S = BRepOffsetAPI_MakeEvolved(P.Wire(), wprof.Wire(), GeomAbs_Arc, True,
                                  False, True, 0.0001)
    S.Build()
    display.DisplayShape(S.Shape(), update=True)
def get_faceted_L_shape(x, y, z):
    pnt_A = gp_Pnt(x + 0, y + 0, z + 0)
    pnt_B = gp_Pnt(x + 20, y + 0, z + 0)
    pnt_C = gp_Pnt(x + 20, y + 10, z + 0)
    pnt_D = gp_Pnt(x + 0, y + 10, z + 0)
    pnt_E = gp_Pnt(x + 0, y + 0, z + 20)
    pnt_F = gp_Pnt(x + 10, y + 0, z + 20)
    pnt_G = gp_Pnt(x + 10, y + 10, z + 20)
    pnt_H = gp_Pnt(x + 0, y + 10, z + 20)
    pnt_I = gp_Pnt(x + 10, y + 0, z + 10)
    pnt_J = gp_Pnt(x + 10, y + 10, z + 10)
    pnt_K = gp_Pnt(x + 20, y + 0, z + 10)
    pnt_L = gp_Pnt(x + 20, y + 10, z + 10)

    face_1 = make_face_from_4_points(pnt_A, pnt_B, pnt_C, pnt_D)
    face_2 = make_face_from_4_points(pnt_B, pnt_C, pnt_L, pnt_K)
    face_3 = make_face_from_4_points(pnt_E, pnt_F, pnt_G, pnt_H)
    face_4 = make_face_from_4_points(pnt_A, pnt_E, pnt_H, pnt_D)
    face_5 = make_face_from_4_points(pnt_G, pnt_F, pnt_I, pnt_J)
    face_6 = make_face_from_4_points(pnt_I, pnt_K, pnt_L, pnt_J)

    polygon_1 = BRepBuilderAPI_MakePolygon()
    polygon_1.Add(pnt_A)
    polygon_1.Add(pnt_B)
    polygon_1.Add(pnt_K)
    polygon_1.Add(pnt_I)
    polygon_1.Add(pnt_F)
    polygon_1.Add(pnt_E)
    polygon_1.Close()

    face_7 = BRepBuilderAPI_MakeFace(polygon_1.Wire()).Face()
    polygon_2 = BRepBuilderAPI_MakePolygon()
    polygon_2.Add(pnt_D)
    polygon_2.Add(pnt_H)
    polygon_2.Add(pnt_G)
    polygon_2.Add(pnt_J)
    polygon_2.Add(pnt_L)
    polygon_2.Add(pnt_C)
    polygon_2.Close()
    face_8 = BRepBuilderAPI_MakeFace(polygon_2.Wire()).Face()

    sew = BRepBuilderAPI_Sewing()
    for face in [
            face_1, face_2, face_3, face_4, face_5, face_6, face_7, face_8
    ]:
        sew.Add(face)
    sew.Perform()

    return sew.SewedShape()
Ejemplo n.º 3
0
def ngon_to_face(points: NGon) -> TopoDS_Face:
    """Convert a Ngon to a BRep face with an underlying best-fit surface.

    Parameters
    ----------
    points : sequence[point]
        Points defining a polygon.

    Returns
    -------
    TopoDS_Face

    """
    points = [gp_Pnt(*point) for point in points]
    poly = BRepBuilderAPI_MakePolygon()
    for point in points:
        poly.Add(point)
    poly.Build()
    poly.Close()
    edges = TopologyExplorer(poly.Wire()).edges()
    nsided = BRepFill_Filling()
    for edge in edges:
        nsided.Add(edge, GeomAbs_C0)
    nsided.Build()
    return nsided.Face()
Ejemplo n.º 4
0
def triangle_to_face(points: Triangle) -> TopoDS_Face:
    """Convert a triangle to a BRep face.

    Parameters
    ----------
    points : [point, point, point]
        Three points defining a triangle.

    Returns
    -------
    TopoDS_Face

    Raises
    ------
    AssertionError
        If the number of points is not 3.

    """
    assert len(points) == 3, "The number of input points should be three."

    polygon = BRepBuilderAPI_MakePolygon()
    for point in points:
        polygon.Add(gp_Pnt(*point))
    polygon.Close()
    wire = polygon.Wire()
    return BRepBuilderAPI_MakeFace(wire).Face()
Ejemplo n.º 5
0
def getTestFace():

    P1 = gp_Pnt(0., 0., 0.)
    P12 = gp_Pnt(0., 2., 2.)
    P2 = gp_Pnt(0., 10., 0.)
    P3 = gp_Pnt(0., 10., 10.)
    P4 = gp_Pnt(0., 0., 10.)
    P5 = gp_Pnt(5., 5., 5.)
    SceneDrawPoint('p1', P1)
    SceneDrawPoint('p12', P12)
    SceneDrawPoint('p2', P2)
    SceneDrawPoint('p3', P3)
    SceneDrawPoint('p4', P4)
    SceneDrawPoint('p5', P5)
    W = BRepBuilderAPI_MakePolygon()
    W.Add(P1)
    W.Add(P12)
    W.Add(P2)
    W.Add(P3)
    W.Add(P4)
    W.Add(P1)

    SceneDrawShape('w', W.Shape())

    # Initialize a BuildPlateSurface
    BPSurf = GeomPlate_BuildPlateSurface(3, 15, 2)

    # Create the curve constraints
    anExp = BRepTools_WireExplorer()
    anExp.Init(W.Wire())

    while anExp.More():
        E = anExp.Current()
        C = BRepAdaptor_HCurve()
        C.ChangeCurve().Initialize(E)
        Cont = BRepFill_CurveConstraint(C, 0)
        BPSurf.Add(Cont)
        anExp.Next()

    # Point constraint
    PCont = GeomPlate_PointConstraint(P5, 0)
    BPSurf.Add(PCont)

    # Compute the Plate surface
    BPSurf.Perform()

    # Approximation of the Plate surface
    MaxSeg = 9
    MaxDegree = 8
    CritOrder = 0
    PSurf = BPSurf.Surface()
    dmax = max(0.0001, 10 * BPSurf.G0Error())
    Tol = 0.0001
    Mapp = GeomPlate_MakeApprox(PSurf, Tol, MaxSeg, MaxDegree, dmax, CritOrder)
    Surf = Mapp.Surface()
    # create a face corresponding to the approximated Plate Surface
    Umin, Umax, Vmin, Vmax = PSurf.Bounds()
    #MF = BRepBuilderAPI_MakeFace (Surf, Umin, Umax, Vmin, Vmax, Tol)
    MF = BRepBuilderAPI_MakeFace(Surf, Tol)
    return MF
Ejemplo n.º 6
0
 def __init__(self, pnts, close=False):
     builder = BRepBuilderAPI_MakePolygon()
     for p in pnts:
         p = CheckGeom.to_point(p)
         builder.Add(p)
     if close:
         builder.Close()
     self._w = Wire(builder.Wire())
Ejemplo n.º 7
0
def makeFace(pntList) :

    from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakePolygon
    from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeFace

    wire = BRepBuilderAPI_MakePolygon()
    for i in pntList :
        wire.Add(i)
    wire.Close()    
    face = BRepBuilderAPI_MakeFace(wire.Wire()).Face()
    return face
Ejemplo n.º 8
0
def make_closed_polygon(*args):
    poly = 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()
    result = poly.Wire()
    return result
Ejemplo n.º 9
0
def make_closed_polygon(*args):
    poly = 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 assert_isdone(poly, 'failed to produce wire'):
        result = poly.Wire()
        return result
Ejemplo n.º 10
0
def _polygon(pnts, wire=False):
    pnts = points(pnts)

    if wire:
        return wire_module._polysegment(pnts, closed=True)

    mk = BRepBuilderAPI_MakePolygon()

    for i in range(len(pnts)):
        mk.Add(pnts[i].Pnt())

    mk.Close()
    return Shape(BRepBuilderAPI_MakeFace(mk.Shape()).Face())
Ejemplo n.º 11
0
def make_polygon(args, closed=False):
    poly = 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()

    result = poly.Wire()
    return result
Ejemplo n.º 12
0
def make_polygon(args, closed=False):
    poly = 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 assert_isdone(poly, 'failed to produce wire'):
        result = poly.Wire()
        return result
Ejemplo n.º 13
0
    def by_points(pnts, close=False):
        """
        Create polygonal wire by connecting points.

        :param collections.Sequence(point_like) pnts: The ordered points.
        :param bool close: Option to close the wire.

        :return: The new wire.
        :rtype: afem.topology.entities.Wire
        """
        builder = BRepBuilderAPI_MakePolygon()
        for p in pnts:
            p = CheckGeom.to_point(p)
            builder.Add(p)
        if close:
            builder.Close()
        return Wire(builder.Wire())
def make_face_from_4_points(pnt1, pnt2, pnt3, pnt4):
    # first create a closed polygon
    poly = BRepBuilderAPI_MakePolygon(pnt1, pnt2, pnt3, pnt4, True).Wire()
    # then build the face from the closed wire
    return BRepBuilderAPI_MakeFace(poly).Face()
Ejemplo n.º 15
0
# ==============================================================================
# Input polygon
# ==============================================================================

R = Rotation.from_axis_and_angle([1, 1, 0], math.radians(30))

polygon = Polygon.from_sides_and_radius_xy(5, 2)
polygon.transform(R)

# ==============================================================================
# BRep Polygon
# ==============================================================================

points = [gp_Pnt(*point) for point in polygon]

poly = BRepBuilderAPI_MakePolygon()
for point in points:
    poly.Add(point)
poly.Build()
poly.Close()

# ==============================================================================
# BRep Filling
# ==============================================================================

edges = list(TopologyExplorer(poly.Wire()).edges())

nsided = BRepFill_Filling()
for edge in edges:
    nsided.Add(edge, GeomAbs_C0)
nsided.Add(gp_Pnt(*(polygon.centroid + normal_polygon(polygon))))