Exemple #1
0
def get_front_surface(stl_file, p1, p2):
    show_log("get_front_surface", "001")

    stl_reader = StlAPI_Reader()
    stl_shape = TopoDS_Shape()
    show_log("get_front_surface", "005")
    #    Read takes 5 minutes
    stl_reader.Read(stl_shape, stl_file)
    #pickle.dump(stl_shape, open( "get_front_surface 001.tmp", "wb" ) )
    #    stl_shape = pickle.load( open( "./get_front_surface 001.tmp", "rb" ) )
    #    t = Topo(stl_shape)
    #    print("number of faces: %i" % (t.number_of_faces()))
    #OCC.RWStl.rwstl().ReadFile(stl_file)
    #time.sleep(10)
    #cos theta should be less than 0.5, theta is the angle between 1,0,0 and the face normal
    show_log("get_front_surface", "010")
    box = BRepPrimAPI_MakeBox(p1, p2).Shape()
    show_log("get_front_surface", "012")
    #   BRepAlgoAPI_Common takes 3 minutes
    CommonSurface = BRepAlgoAPI_Common(box, stl_shape).Shape()
    ais_stl_shape = display.DisplayShape(stl_shape)
    #    ais_box = display.DisplayShape(box)
    #    ais_common = display.DisplayShape(CommonSurface)
    #    display.Context.SetTransparency(ais_box, 0.8)
    display.Context.SetTransparency(ais_stl_shape, 0.8)
    #    orig = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp_Pnt(0,0,0))
    #    display.DisplayShape(orig.Shape())

    return CommonSurface
Exemple #2
0
def booleanIntersection(shp1, shp2):
    """ THis doesnt f****n work"""
    from OCC.BRepAlgoAPI import BRepAlgoAPI_Common
    intrs = BRepAlgoAPI_Common(shp1, shp2)

    # print(intrs.BuilderCanWork())
    if intrs.BuilderCanWork() is True:
        intrs.Build()
        intrs.RefineEdges()
        intrs.FuseEdges()
        # cut.SetOperation()
        # assert_isdone()
        # print(intrs.IsDone())
        shp = intrs.Shape()
        intrs.Destroy()
        return shp
Exemple #3
0
def common(event=None):
    # Create Box
    axe = gp_Ax2(gp_Pnt(10, 10, 10), gp_Dir(1, 2, 1))
    Box = BRepPrimAPI_MakeBox(axe, 60, 80, 100).Shape()
    # Create wedge
    Wedge = BRepPrimAPI_MakeWedge(60., 100., 80., 20.).Shape()
    # Common surface
    CommonSurface = BRepAlgoAPI_Common(Box, Wedge).Shape()

    display.EraseAll()
    ais_box = display.DisplayShape(Box)
    ais_wedge = display.DisplayShape(Wedge)
    display.Context.SetTransparency(ais_box, 0.8)
    display.Context.SetTransparency(ais_wedge, 0.8)
    display.DisplayShape(CommonSurface)
    display.FitAll()
Exemple #4
0
def grid_face(occ_face, udim, vdim):
    #returns a series of polygons
    pt_list = []
    face_list = []
    fc = face.Face(occ_face)
    umin, umax, vmin, vmax = fc.domain()
    u_div = int(math.ceil((umax - umin) / udim))
    v_div = int(math.ceil((vmax - vmin) / vdim))
    for ucnt in range(u_div + 1):
        for vcnt in range(v_div + 1):
            u = umin + (ucnt * udim)
            v = vmin + (vcnt * vdim)
            occpt = fc.parameter_to_point(u, v)
            pt = [occpt.X(), occpt.Y(), occpt.Z()]
            pt_list.append(pt)

    for pucnt in range(u_div):
        for pvcnt in range(v_div):
            pcnt = pucnt * (v_div + 1) + pvcnt
            #print pcnt
            pt1 = pt_list[pcnt]
            pt2 = pt_list[pcnt + v_div + 1]
            pt3 = pt_list[pcnt + v_div + 2]
            pt4 = pt_list[pcnt + 1]
            occface = make_polygon([pt1, pt2, pt3, pt4])
            face_list.append(occface)

    #intersect the grids and the face so that those grids that are not in the face will be erase
    intersection_list = []
    for f in face_list:
        intersection = BRepAlgoAPI_Common(f, occ_face).Shape()
        compound = fetch.shape2shapetype(intersection)
        inter_face_list = fetch.topos_frm_compound(compound)["face"]
        if inter_face_list:
            for inter_face in inter_face_list:
                intersection_list.append(inter_face)
    return intersection_list
Exemple #5
0
from OCC.gp import gp_Pnt, gp_XYZ, gp_Mat, gp_GTrsf
from OCC.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeBox
from OCC.BRepBuilderAPI import BRepBuilderAPI_GTransform
from OCC.BRepAlgoAPI import BRepAlgoAPI_Common

from OCC.Display.SimpleGui import init_display

display, start_display, add_menu, add_function_to_menu = init_display()
orig = gp_Pnt(0., 0., 0.)
sphere = BRepPrimAPI_MakeSphere(orig, 50.).Solid()

# be careful that the following scale numbers are "not too big",
# otherwise boolean operations can be buggy
# see isue 
a1 = 17.1
a2 = 17.1
a3 = 3.5
gTrsf = gp_GTrsf(gp_Mat(a1, 0, 0, 0, a2, 0, 0, 0, a3), gp_XYZ(0., 112.2, 0.))
ellipsoid = BRepBuilderAPI_GTransform(sphere, gTrsf).Shape()

# then perform a boolean intersection with a box
box = BRepPrimAPI_MakeBox(gp_Pnt(-1000, -1000, -1000), gp_Pnt(1000, 112.2, 1000)).Shape()
common = BRepAlgoAPI_Common(box, ellipsoid).Shape()
assert not common.IsNull()

display.DisplayShape(box, color = "BLACK", transparency = 0.8)
display.DisplayShape(ellipsoid, color = "BLACK", transparency = 0.8)
display.DisplayShape(common, color = "BLACK", transparency = 0.8, update=True)
start_display() 
Exemple #6
0
 def _do_operation(self,shape1,shape2):
     d = self.declaration
     args = [shape1,shape2]
     if d.pave_filler:
         args.append(d.pave_filler)
     return BRepAlgoAPI_Common(*args)
Exemple #7
0
 def intersect(self, toIntersect):
     """
     Construct shape intersection
     """
     return Shape.cast(
         BRepAlgoAPI_Common(self.wrapped, toIntersect.wrapped).Shape())
Exemple #8
0
p1 = gp_Pnt(0, 0, 0)
p2 = gp_Pnt(0, 10, 0)
p3 = gp_Pnt(10, 10, 0)
p4 = gp_Pnt(10, 0, 0)
rect = make_closed_polygon(p1, p2, p3, p3)

display, start_display, add_menu, add_function_to_menu = init_display()
#my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()

stl_reader = StlAPI_Reader()
stl_box = TopoDS_Shape()
stl_reader.Read(stl_box, './models/box.stl')

axe = gp_Ax2(gp_Pnt(-10, 1, 1), gp_Dir(0, 0, 1))
box = BRepPrimAPI_MakeBox(axe, 50, 15, 15).Shape()
CommonSurface = BRepAlgoAPI_Common(box, stl_box).Shape()

topo = Topo(CommonSurface)
display.EraseAll()
x_mid_max = -100
front_face = None
for face in topo.faces():
    bbox = Bnd_Box()
    OCC.BRepBndLib.brepbndlib_Add(face, bbox)
    xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
    x_mid = (xmin + xmax) / 2
    if x_mid > x_mid_max:
        x_mid_max = x_mid
        front_face = face

t_face = Topo(front_face)
Exemple #9
0
def boolean_common(occ_shape1, occ_shape2):
    intersection = BRepAlgoAPI_Common(occ_shape1, occ_shape2).Shape()
    compound = fetch.shape2shapetype(intersection)
    return compound
Exemple #10
0
def intersection_solid(shp1: tds.TopoDS_Shape, shp2: TopoDS_Shape) -> TopoDS_Shape:
    """ Solid Solid intersection
    :param: shp1 - TopoDS_Shape1
    :param: shp2 - TopoDS_Shape1
    """
    return _bool_op(BRepAlgoAPI_Common(shp1, shp2))