def import_as_multiple_shapes(event=None):
    compound = read_step_file(os.path.join('.', 'models', 'as1_pe_203.stp'))
    t = TopologyExplorer(compound)
    display.EraseAll()
    for solid in t.solids():
        color = Quantity_Color(random.random(),
                               random.random(),
                               random.random(),
                               Quantity_TOC_RGB)
        display.DisplayColoredShape(solid, color)
    display.FitAll()
Пример #2
0
from OCC.Display.SimpleGui import init_display
from OCC.Graphic3d import Graphic3d_Camera
from OCC.TopoDS import topods_Vertex
from OCC.BRep import BRep_Tool
from OCC.DataExchange import read_step_file


def vertex_clicked(shp, *kwargs):
    """ This function is called whenever a vertex is selected
    """
    for shape in shp:  # this should be a TopoDS_Vertex
        print("Face selected: ", shape)
        v = topods_Vertex(shape)
        pnt = BRep_Tool.Pnt(v)
        print("3d gp_Pnt selected coordinates : X=", pnt.X(), "Y=", pnt.Y(),
              "Z=", pnt.Z())
        # then convert to screen coordinates
        screen_coord = display.View.Convert(pnt.X(), pnt.Y(), pnt.Z())
        print("2d screen coordinates : ", screen_coord)


display, start_display, add_menu, add_function_to_menu = init_display()
# loads  and displays a step file
the_shape = read_step_file('./models/as1_pe_203.stp')

display.SetSelectionModeVertex()  # switch to Vertex selection mode
display.register_select_callback(vertex_clicked)
display.DisplayShape(the_shape, update=True)
start_display()
def import_as_one_shape(event=None):
    shp = read_step_file(os.path.join('.', 'models', 'as1_pe_203.stp'))
    display.EraseAll()
    display.DisplayShape(shp, update=True)
def build_curve_network(event=None, enforce_tangency=True):
    '''
    mimic the curve network surfacing command from rhino
    '''
    root_compound_shape = read_step_file("./models/splinecage.stp")
    topology_explorer = TopologyExplorer(root_compound_shape)

    # approximate the hell out of all surfaces and curves
    # I wanna see it in its full glory
    display.Context.SetDeviationAngle(0.00001)  # 0.001 -> default
    display.Context.SetDeviationCoefficient(0.0001)  # 0.001 -> default

    tangent_constraint_faces = [f for f in topology_explorer.faces()]

    # loop through the imported faces
    # associate the length of each of the faces edges to the corresponding face
    _edge_length_to_face, _edge_length_to_edge = hash_edge_lenght_to_face(
        tangent_constraint_faces)

    # loop through the imported curves, avoiding the imported faces
    # when we've got these filtered out, we retrieved the geometry to build the surface from
    filtered_edges = [
        e for e in topology_explorer._loop_topo(
            TopAbs_EDGE, root_compound_shape, TopAbs_FACE)
    ]

    filtered_length = {}
    for e in filtered_edges:
        l = round(length_from_edge(e), 3)
        filtered_length[l] = e

    input_edge_face_pairs, edges_no_adjacent_face = [], []
    for l, edg in filtered_length.items():
        if l in _edge_length_to_edge:
            edge_face_pair = (_edge_length_to_edge[l], _edge_length_to_face[l])
            input_edge_face_pairs.append(edge_face_pair)
        else:
            edges_no_adjacent_face.append(edg)

    brep_plate_builder = BRepOffsetAPI_MakeFilling()

    if enforce_tangency:
        print("going for surface quality")
        brep_plate_builder.SetConstrParam(
            0.0001, 0.001, 0.01,
            0.01)  # ?!!! Tol2d=1.0, Tol3d=1.0, TolAng=1.0, TolCurv=1.0
        brep_plate_builder.SetApproxParam(8, 240)  # MaxDeg=8, MaxSegments=9
        brep_plate_builder.SetResolParam(
            3, 64, 3)  # Degree=3, NbPtsOnCur=15, NbIter=2, Anisotropie=0
    else:
        print("quick and dirty")

    # illegal instruction 4???
    for i in input_edge_face_pairs:
        display.DisplayShape(i, color=random_color())
        constraint_edg, support_face = i
        if constraint_edg.IsNull() or support_face.IsNull():
            print("OMG null")
        brep_plate_builder.Add(constraint_edg, support_face, GeomAbs_G1)

    # not entirely sure why this fails... how is that different from adding from points?
    # for e in edges_no_adjacent_face:
    #     brep_plate_builder.Add(e, GeomAbs_C0)

    # libc++abi.dylib: terminating with uncaught exception of type Standard_OutOfRange
    for e in edges_no_adjacent_face:
        display.DisplayShape(e)
        for pt in divide_edge_by_nr_of_points(e, 12)[2:-2]:
            brep_plate_builder.Add(pt[1])

    brep_plate_builder.Build()
    if brep_plate_builder.IsDone():
        face = brep_plate_builder.Shape()
        display.DisplayColoredShape(face, "ORANGE")
    else:
        print("constructing the surface failed")