Пример #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
Пример #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()
Пример #3
0
 def make_EllipWire(self,
                    rxy=[1.0, 1.0],
                    shft=0.0,
                    skin=None,
                    axs=gp_Ax3()):
     rx, ry = rxy
     if rx > ry:
         major_radi = rx
         minor_radi = ry
         axis = gp_Ax2()
         axis.SetXDirection(axis.XDirection())
     else:
         major_radi = ry
         minor_radi = rx
         axis = gp_Ax2()
         axis.SetXDirection(axis.YDirection())
     axis.Rotate(axis.Axis(), np.deg2rad(shft))
     elip = make_edge(gp_Elips(axis, major_radi, minor_radi))
     poly = make_wire(elip)
     poly.Location(set_loc(gp_Ax3(), axs))
     if skin == None:
         return poly
     else:
         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 == 0:
             return face
         else:
             solid = BRepOffset_MakeOffset(face, skin, 1.0E-5,
                                           BRepOffset_Skin, False, True,
                                           GeomAbs_Arc, True, True)
             return solid.Shape()
Пример #4
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()
    face = n_sided.Face()
    return face
Пример #5
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()
Пример #6
0
def make_n_sided(edges, continuity=GeomAbs_C0):
    n_sided = BRepFill_Filling()  # TODO Checck optional NbIter=6)
    for edg in edges:
        n_sided.Add(edg, continuity)
    n_sided.Build()
    face = n_sided.Face()
    return face
Пример #7
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
Пример #8
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())
Пример #9
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
Пример #10
0
def fill_surface():
    n_sided = BRepFill_Filling()

    n_sided.SetResolParam(4, 30, 5, True)
    # Sets the parameters used for resolution.
    # The default values of these parameters have been chosen for a good ratio quality/performance.
    #
    # Degree: it is the order of energy criterion to minimize for computing the deformation of the surface.
    #   The default value is 3.
    #   The recommanded value is i+2
    #   where i is the maximum order of the constraints.
    #
    # NbPtsOnCur: it is the average number of points for discretisation of the edges.
    #
    # NbIter: it is the maximum number of iterations of the process.
    #   For each iteration the number of discretisation points is increased.
    #
    # Anisotropie:

    n_sided.SetConstrParam()
    # Sets the values of Tolerances used to control the constraint.
    # Tol2d:
    # Tol3d:
    #   it is the maximum distance allowed between the support surface and the constraints
    # TolAng: it is the maximum angle allowed between the normal of the surface and the constraints
    # TolCurv: it is the maximum difference of curvature allowed between the surface and the constraint

    p0 = gp_Pnt(-20, -20, 0)
    p1 = gp_Pnt(+20, -20, 10)
    p2 = gp_Pnt(+20, +20, 0)
    p3 = gp_Pnt(-20, +20, 0)
    p4 = gp_Pnt(-10, -10, +5)
    p5 = gp_Pnt(-10, +10, -5)
    p6 = gp_Pnt(+10, -10, -10)
    p7 = gp_Pnt(+10, +10, +10)
    p8 = gp_Pnt(-15, -15, +2)
    p9 = gp_Pnt(-15, +15, -15)
    p10 = gp_Pnt(+15, -15, -2)
    p11 = gp_Pnt(+15, +15, +50)

    n_sided.Add(make_edge(p0, p1), GeomAbs_C0)
    n_sided.Add(make_edge(p1, p2), GeomAbs_C0)
    n_sided.Add(make_edge(p2, p3), GeomAbs_C0)
    n_sided.Add(make_edge(p3, p0), GeomAbs_C0)
    n_sided.Add(p4)
    n_sided.Add(p5)
    n_sided.Add(p6)
    n_sided.Add(p7)
    n_sided.Add(p8)
    n_sided.Add(p9)
    n_sided.Add(p10)
    n_sided.Add(p11)
    n_sided.Build()
    write_step_file(n_sided.Face(), "./tmp/FillSurf.stp")
    return n_sided.Face()
Пример #11
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
Пример #12
0
# To OCC
# ==============================================================================

shell = TopoDS_Shell()
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 = []
Пример #13
0
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))))
nsided.Build()

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

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

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

brep = BRep()