예제 #1
0
def slicer(event=None):
    # Param
    Zmin, Zmax, deltaZ = -100, 100, 5
    # Note: the shape can also come from a shape selected from InteractiveViewer
    if 'display' in dir():
        shape = display.GetSelectedShape()
    else:
        # Create the shape to slice
        shape = BRepPrimAPI_MakeSphere(60.).Shape()
    # Define the direction
    D = gp_Dir(0., 0., 1.)  # the z direction
    # Perform slice
    sections = []
    init_time = time.time()  # for total time computation
    for z in range(Zmin, Zmax, deltaZ):
        # Create Plane defined by a point and the perpendicular direction
        P = gp_Pnt(0, 0, z)
        Pln = gp_Pln(P, D)
        face = BRepBuilderAPI_MakeFace(Pln).Shape()
        # Computes Shape/Plane intersection
        section_shp = BRepAlgoAPI_Section(shape, face)
        if section_shp.IsDone():
            sections.append(section_shp)
    total_time = time.time() - init_time
    print("%.3fs necessary to perform slice." % total_time)

    display.EraseAll()
    display.DisplayShape(shape)
    for section_ in sections:
        display.DisplayShape(section_.Shape())
    display.FitAll()
예제 #2
0
파일: boolops.py 프로젝트: mirmik/zencad
def _section(a, b, pretty):
    algo = BRepAlgoAPI_Section(a.Shape(), b.Shape())

    if pretty:
        algo.ComputePCurveOn1(True)
        algo.Approximation(True)

    algo.Build()
    if not algo.IsDone():
        printf("warn: section algotithm failed\n")

    return Shape(algo.Shape())
예제 #3
0
def GetSectionShape(z, shapes): # the mid z value of the storey, list of the storey shapes
    if isinstance(shapes, list):
        shapes_compound, if_all_compound = list_of_shapes_to_compound(shapes)

        plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.))
        face = BRepBuilderAPI_MakeFace(plane).Shape()
        # Computes Shape/Plane intersection
        section = BRepAlgoAPI_Section(shapes_compound, face)
        section.Build()
        if section.IsDone():
            print("Successfully get the section shape")
            return section.Shape()
        else:
            print("ERROR, the section shape cannot be built")
    else:
        plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.))
        face = BRepBuilderAPI_MakeFace(plane).Shape()
        # Computes Shape/Plane intersection
        section = BRepAlgoAPI_Section(shapes, face)
        section.Build()
        if section.IsDone():
            print("Successfully get the section shape")
            return section.Shape()
def vectorized_slicer(li):
    # Create Plane defined by a point and the perpendicular direction
    z_values, shape = li
    _slices = []
    for z in z_values:
        #print 'slicing index:', z, 'sliced by process:', os.getpid()
        plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.))
        face = BRepBuilderAPI_MakeFace(plane).Shape()
        # Computes Shape/Plane intersection
        section = BRepAlgoAPI_Section(shape, face)
        section.Build()
        if section.IsDone():
            _slices.append(section.Shape())
    return _slices
예제 #5
0
    builder = BRep_Builder()
    breptools_Read(cylinder_head, './core_example/cylinder_head.brep', builder)
    return cylinder_head


if __name__ == '__main__':
    shp = get_brep()
    xyz_min_max = get_boundingbox(shp)
    p1 = gp_Pnt(*xyz_min_max[0:3])
    p2 = gp_Pnt(*xyz_min_max[3:])
    box = make_box(p1, p2)

    obj = plotocc()
    obj.display.DisplayShape(box, transparency=0.9)
    obj.display.DisplayShape(shp)

    z_delta = abs(xyz_min_max[2] - xyz_min_max[5])
    for z in np.linspace(xyz_min_max[2], xyz_min_max[5], 5):
        print(z)
        plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0.0, 1.))
        face = BRepBuilderAPI_MakeFace(plane).Shape()
        # Computes Shape/Plane intersection
        section = BRepAlgoAPI_Section(shp, face)
        section.Build()
        if section.IsDone():
            obj.display.DisplayShape(section.Shape(), color="BLUE")
            obj.export_stp(section.Shape())

    obj.show_axs_pln(scale=75)
    obj.show()