Exemplo n.º 1
0
def make_n_sided(edges, points, continuity=GeomAbs_C0):
    """
    builds an n-sided patch, respecting the constraints defined by *edges*
    and *points*

    a simplified call to the BRepFill_Filling class
    its simplified in the sense that to all constraining edges and points
    the same level of *continuity* will be applied

    *continuity* represents:

    GeomAbs_C0 : the surface has to pass by 3D representation of the edge
    GeomAbs_G1 : the surface has to pass by 3D representation of the edge
    and to respect tangency with the given face
    GeomAbs_G2 : the surface has to pass by 3D representation of the edge
    and to respect tangency and curvature with the given face.

    NOTE: it is not required to set constraining points.
    just leave the tuple or list empty

    :param edges: the constraining edges
    :param points: the constraining points
    :param continuity: GeomAbs_0, 1, 2
    :return: TopoDS_Face
    """
    from OCC.Core.BRepFill import BRepFill_Filling
    n_sided = BRepFill_Filling()
    for edg in edges:
        n_sided.Add(edg, continuity)
    for pt in points:
        n_sided.Add(pt)
    n_sided.Build()
    face = n_sided.Face()
    return face
Exemplo n.º 2
0
    def make_StarWire(self,
                      num=5,
                      radi=[2.0, 1.0],
                      shft=0.0,
                      axs=gp_Ax3(),
                      skin=None):
        lxy = radi
        pnts = []
        angl = 360 / num
        for i in range(num):
            a_thet = np.deg2rad(i * angl) + np.deg2rad(shft)
            ax, ay = radi[0] * np.sin(a_thet), radi[0] * np.cos(a_thet)
            pnts.append(gp_Pnt(ax, ay, 0))
            b_thet = a_thet + np.deg2rad(angl) / 2
            bx, by = radi[1] * np.sin(b_thet), radi[1] * np.cos(b_thet)
            pnts.append(gp_Pnt(bx, by, 0))
        pnts.append(pnts[0])
        poly = make_polygon(pnts)
        poly.Location(set_loc(gp_Ax3(), axs))

        n_sided = BRepFill_Filling()
        for e in Topo(poly).edges():
            n_sided.Add(e, GeomAbs_C0)
        n_sided.Build()
        face = n_sided.Face()
        if skin == None:
            return poly
        elif skin == 0:
            return face
        else:
            solid = BRepOffset_MakeOffset(face, skin, 1.0E-5, BRepOffset_Skin,
                                          False, True, GeomAbs_Arc, True, True)
            return solid.Shape()
Exemplo n.º 3
0
def make_n_sided(edges, continuity=GeomAbs_C0):
    n_sided = BRepFill_Filling()
    for edg in edges:
        n_sided.Add(edg, continuity)
    n_sided.Build()
    assert_isdone(n_sided, "failed to produce n_sided")
    face = n_sided.Face()
    return face
Exemplo n.º 4
0
def wire_to_face(edges: List[TopoDS_Edge]) -> TopoDS_Face:
    n_sided = BRepFill_Filling()
    for edg in edges:
        n_sided.Add(edg, GeomAbs_C0)
    try:
        n_sided.Build()
    except RuntimeError as e:
        raise UnableToBuildNSidedWires(e)
    face = n_sided.Face()
    return face
Exemplo n.º 5
0
    def __init__(self):
        plotocc.__init__(self)

        print(gxyz.shape)
        for i, xyz in enumerate(gxyz):
            print(i, *xyz)
            self.display.DisplayShape(gp_Pnt(*xyz))

        e_array = []
        for e in xyz_max:
            x, y, z = e
            e = gp_Pnt(float(x), float(y), float(z))
            e_array.append(e)
        e_array.append(e_array[0])
        poly = make_polygon(e_array)

        n_sided = BRepFill_Filling()
        for e in Topo(poly).edges():
            n_sided.Add(e, GeomAbs_C0)
        for pt in gxyz:
            x, y, z = pt
            if (x < xmax) and (x > xmin) and (y < ymax) and (y > ymin) and (
                    z < zmax) and (z > zmin):
                n_sided.Add(gp_Pnt(x, y, z))
        n_sided.Build()
        face = n_sided.Face()

        #face = make_n_sided(edges, p_array)

        # THICKEN SURFACE
        thickness = 0.15
        solid = BRepOffset_MakeOffset(face, thickness, 1.0E-5, BRepOffset_Skin,
                                      False, False, GeomAbs_Intersection, True)
        # The last True is important to make solid
        # solid.MakeOffsetShape()
        # solid.MakeThickSolid()
        #aShape = solid.Shape()

        self.display.DisplayShape(poly)
        self.display.DisplayShape(face)
        #display.DisplayShape(aShape, update=True)
        #write_step_file(aShape, "./tmp/gyroid.stp")

        self.export_stp(solid.Shape())
Exemplo n.º 6
0
    def make_FaceByOrder(self, pts=[]):
        pnt = []
        for p in pts:
            pnt.append([p.X(), p.Y(), p.Z()])

        pnt = np.array(pnt)
        cov = ConvexHull(pnt, qhull_options='QJ')

        #pts_ord = []
        # print(cov)
        # print(cov.simplices)
        # print(cov.vertices)
        # for idx in cov.vertices:
        #    print(idx, pnt[idx])
        #    pts_ord.append(gp_Pnt(*pnt[idx]))

        #poly = make_polygon(pts_ord)
        poly = make_polygon(pts)
        n_sided = BRepFill_Filling()
        for e in Topo(poly).edges():
            n_sided.Add(e, GeomAbs_C0)
        n_sided.Build()
        face = n_sided.Face()
        return face
Exemplo n.º 7
0
builder = BRep_Builder()
builder.MakeShell(shell)

points = tubemesh.vertices_attributes('xyz')

for face in tubemesh.faces():
    brep = BRepFill_Filling()

    for u, v in tubemesh.face_halfedges(face):
        edge = BRepBuilderAPI_MakeEdge(gp_Pnt(*points[u]),
                                       gp_Pnt(*points[v])).Edge()
        brep.Add(edge, GeomAbs_C0, True)

    brep.Build()

    face = BRepBuilderAPI_MakeFace(brep.Face()).Face()
    builder.Add(shell, face)

# ==============================================================================
# Tesselation
# ==============================================================================

tess = ShapeTesselator(shell)
tess.Compute()

vertices = []
triangles = []

for i in range(tess.ObjGetVertexCount()):
    xyz = tess.GetVertex(i)
    vertices.append(xyz)
Exemplo n.º 8
0
# 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))))
nsided.Build()

# ==============================================================================
# Surface from BRep Filling Face
# ==============================================================================

face = nsided.Face()
surface = OCCNurbsSurface.from_face(face)

# ==============================================================================
# BRep
# ==============================================================================

brep = BRep()
brep.shape = face

# mesh = brep.to_tesselation()

BRepMesh_IncrementalMesh(brep.shape, 0.1, False, 0.1, False)

bt = BRep_Tool()
ex = TopExp_Explorer(brep.shape, TopAbs_FACE)