def split_compound(compound):
    all_faces = get_faces(compound)
    planar_faces = list(filter(lambda x: Face(x).is_planar(), all_faces))

    p1, v1 = gp_Pnt(50, 50, 25), gp_Vec(0, 0, -1)
    fc1 = make_face(gp_Pln(p1, vec_to_dir(v1)), -1000, 1000, -1000,
                    1000)  # limited, not infinite plane

    bo = BOPAlgo_Builder()
    bo.AddArgument(copy.deepcopy(compound))
    # bo.AddArgument(fc1)

    # display.DisplayShape(fc1, transparency=0.7)
    for f in planar_faces:
        gprop = BRepGProp_Face(f)
        normal_point = gp_Pnt(0, 0, 0)
        normal_vec = gp_Vec(0, 0, 0)
        gprop.Normal(0, 0, normal_point, normal_vec)
        big_face = make_face(gp_Pln(normal_point,
                                    vec_to_dir(normal_vec)), -1000, 1000,
                             -1000, 1000)  # limited, not infinite plane
        bo.AddArgument(big_face)
        # display.DisplayShape(big_face, transparency=0.7)

    bo.Perform()
    # print("error status: {}".format(bo.ErrorStatus()))

    top = Topo(bo.Shape())
    result = [s for s in top.solids()]
    return result
def build_geom_plate(edges):
    bpSrf = GeomPlate_BuildPlateSurface(3, 9, 12)

    # add curve constraints
    for edg in edges:
        c = BRepAdaptor_HCurve()
        print('edge:', edg)
        c.ChangeCurve().Initialize(edg)
        constraint = BRepFill_CurveConstraint(c.GetHandle(), 0)
        bpSrf.Add(constraint.GetHandle())

    # add point constraint
    try:
        bpSrf.Perform()
    except RuntimeError:
        print('Failed to build the geom plate surface')

    maxSeg, maxDeg, critOrder = 9, 8, 0

    srf = bpSrf.Surface()
    plate = GeomPlate_MakeApprox(srf, 1e-04, 100, 9, 1e-03, 0)

    uMin, uMax, vMin, vMax = srf.GetObject().Bounds()
    face = make_face(plate.Surface(), uMin, uMax, vMin, vMax, 1e-6)
    return face
def build_plate(polygon, points):
    '''
    build a surface from a constraining polygon(s) and point(s)
    @param polygon:     list of polygons ( TopoDS_Shape)
    @param points:      list of points ( gp_Pnt )
    '''
    # plate surface
    bpSrf = GeomPlate_BuildPlateSurface(3, 15, 2)

    # add curve constraints
    for poly in polygon:
        for edg in WireExplorer(poly).ordered_edges():
            c = BRepAdaptor_HCurve()
            c.ChangeCurve().Initialize(edg)
            constraint = BRepFill_CurveConstraint(c.GetHandle(), 0)
            bpSrf.Add(constraint.GetHandle())

    # add point constraint
    for pt in points:
        bpSrf.Add(GeomPlate_PointConstraint(pt, 0).GetHandle())
        bpSrf.Perform()

    maxSeg, maxDeg, critOrder = 9, 8, 0
    tol = 1e-4
    dmax = max([tol, 10 * bpSrf.G0Error()])

    srf = bpSrf.Surface()
    plate = GeomPlate_MakeApprox(srf, tol, maxSeg, maxDeg, dmax, critOrder)
    uMin, uMax, vMin, vMax = srf.GetObject().Bounds()

    return make_face(plate.Surface(), uMin, uMax, vMin, vMax, 1e-4)
def build_geom_plate(edges):
    bpSrf = GeomPlate_BuildPlateSurface(3, 9, 12)

    # add curve constraints
    for edg in edges:
        c = BRepAdaptor_HCurve()
        print('edge:', edg)
        c.ChangeCurve().Initialize(edg)
        constraint = BRepFill_CurveConstraint(c.GetHandle(), 0)
        bpSrf.Add(constraint.GetHandle())

    # add point constraint
    try:
        bpSrf.Perform()
    except RuntimeError:
        print('Failed to build the geom plate surface')

    maxSeg, maxDeg, critOrder = 9, 8, 0

    srf = bpSrf.Surface()
    plate = GeomPlate_MakeApprox(srf, 1e-04, 100, 9, 1e-03, 0)

    uMin, uMax, vMin, vMax = srf.GetObject().Bounds()
    face = make_face(plate.Surface(), uMin, uMax, vMin, vMax, 1e-6)
    return face
def build_plate(polygon, points):
    '''
    build a surface from a constraining polygon(s) and point(s)
    @param polygon:     list of polygons ( TopoDS_Shape)
    @param points:      list of points ( gp_Pnt )
    '''
    # plate surface
    bpSrf = GeomPlate_BuildPlateSurface(3, 15, 2)

    # add curve constraints
    for poly in polygon:
        for edg in WireExplorer(poly).ordered_edges():
            c = BRepAdaptor_HCurve()
            c.ChangeCurve().Initialize(edg)
            constraint = BRepFill_CurveConstraint(c.GetHandle(), 0)
            bpSrf.Add(constraint.GetHandle())

    # add point constraint
    for pt in points:
        bpSrf.Add(GeomPlate_PointConstraint(pt, 0).GetHandle())
        bpSrf.Perform()

    maxSeg, maxDeg, critOrder = 9, 8, 0
    tol = 1e-4
    dmax = max([tol, 10*bpSrf.G0Error()])

    srf = bpSrf.Surface()
    plate = GeomPlate_MakeApprox(srf, tol, maxSeg, maxDeg, dmax, critOrder)
    uMin, uMax, vMin, vMax = srf.GetObject().Bounds()

    return make_face(plate.Surface(), uMin, uMax, vMin, vMax, 1e-4)
Exemple #6
0
 def make_torus(self, axs=gp_Ax3(), r0=6000, r1=1500):
     tok_surf = Geom_ToroidalSurface(axs, r0, r1)
     return make_face(tok_surf, 1.0E-9)
Exemple #7
0
from OCC.Core.gp import gp_Pln
from OCC.Core.gp import gp_Pnt, gp_Vec
from OCC.Core.TopoDS import TopoDS_Compound
from OCC.Core.BOPAlgo import BOPAlgo_MakerVolume, BOPAlgo_Builder
from OCC.Core.BRep import BRep_Builder
from OCCUtils.Topology import Topo
from OCCUtils.Construct import make_box, make_face
from OCCUtils.Construct import vec_to_dir

if __name__ == "__main__":
    display, start_display, add_menu, add_function_to_menu = init_display()

    box = make_box(200, 200, 200)

    p1, v1 = gp_Pnt(50, 50, 50), gp_Vec(0, 0, -1)
    fc1 = make_face(gp_Pln(p1, vec_to_dir(v1)), -1000, 1000, -1000,
                    1000)  # limited, not infinite plane

    p2, v2 = gp_Pnt(50, 50, 50), gp_Vec(0, 1, -1)
    fc2 = make_face(gp_Pln(p2, vec_to_dir(v2)), -1000, 1000, -1000,
                    1000)  # limited, not infinite plane

    p3, v3 = gp_Pnt(50, 50, 25), gp_Vec(1, 1, -1)
    fc3 = make_face(gp_Pln(p3, vec_to_dir(v3)), -1000, 1000, -1000,
                    1000)  # limited, not infinite plane

    bo = BOPAlgo_Builder()
    bo.AddArgument(box)
    bo.AddArgument(fc1)
    bo.AddArgument(fc2)
    bo.AddArgument(fc3)
Exemple #8
0
if __name__ == "__main__":
    num = 0
    box = make_box(100, 100, 100)

    stpname = "{}/shp_{:04d}.stp".format("./shp/", num)
    write_step_file(box, stpname)

    splitter = BOPAlgo_Splitter()
    splitter.AddArgument(box)

    for i in range(7):
        pnt = gp_Pnt(*np.random.rand(3) * 100)
        vec = gp_Vec(*np.random.randn(3))
        pln = gp_Pln(pnt, vec_to_dir(vec))
        fce = make_face(pln, -1000, 1000, -1000, 1000)
        splitter.AddTool(fce)

    splitter.Perform()
    #shp_list = splitter.Generated()

    exp = TopExp_Explorer(splitter.Shape(), TopAbs_SOLID)
    shp = []
    while exp.More():
        num += 1

        props = GProp_GProps()
        brepgprop_LinearProperties(exp.Current(), props)
        vol = props.Mass()
        print(vol)
Exemple #9
0
                        default=[0.0, 0.0, 0.0],
                        type=float,
                        nargs=3)
    opt = parser.parse_args()
    print(opt, argvs)

    px = np.linspace(-1, 1, 100) * 100 + 50
    py = np.linspace(-1, 1, 200) * 100 - 50
    mesh = np.meshgrid(px, py)

    p2d = plot2d(aspect="auto")
    p2d.contourf_sub2(mesh, mesh[0], pngname=p2d.tempname + "_plot2d")

    obj = dispocc(touch=True)

    surf1 = make_face(gp_Torus(gp_Ax3(), 1000, 500), 0, 2 * np.pi, -np.pi,
                      np.pi)

    surf2 = make_face(gp_Torus(gp_Ax3(), 1500, 750), 0, 2 * np.pi,
                      np.pi * 1 / 20, np.pi * 21 / 20)

    surf3 = make_face(gp_Torus(gp_Ax3(), 2000, 1000), 0, 2 * np.pi,
                      -np.pi * 15 / 20, -np.pi * 7 / 20)

    obj.display.DisplayShape(surf1, transparency=0.9)
    obj.display.DisplayShape(surf2, transparency=0.9)
    obj.display.DisplayShape(surf3, transparency=0.9)

    obj.show_axs_pln()
    obj.show()