Example #1
0
def get_vertex_normal(vertex, shape):
    #a vertex belongs to multiple faces on the shape
    #can only choose one face when calculating vertex normal
    #preference tells which face is preferred (preferred direction, x+,y-,z+)
    distance = sweeper.get_nearest(vertex, shape)
    #always use the first solution
    show_log("get_vertex_normal", "0010")
    #SupportOnShape1, 2 is 1 based, not 0 based
    nearest_shape = distance.SupportOnShape2(1)
    topo_nearest_shape = Topo(nearest_shape)
    topo_shape = Topo(shape)
    face = None
    show_log("get_vertex_normal", "0020")
    if nearest_shape.ShapeType() == TopAbs_VERTEX:
        face = topo_shape.faces_from_vertex(nearest_shape).next()
    if nearest_shape.ShapeType() == TopAbs_EDGE:
        face = topo_shape.faces_from_edge(nearest_shape).next()
    if nearest_shape.ShapeType() == TopAbs_WIRE:
        face = topo_shape.faces_from_wire(nearest_shape).next()
    if nearest_shape.ShapeType() == TopAbs_FACE:
        wire = topo_shape.wires_from_face(nearest_shape).next()
        face = topo_shape.faces_from_wire(wire).next()
    assert face, "unhandled nearest_shape type"
    n = sweeper.get_face_normal(face)
    return n
Example #2
0
    def Shape(self):
        ball_vecs = []
        for i in self.balls:
            ball_vecs.append(gp_Vec(i.getPnt().XYZ()))
        v_ball_to_ball = ball_vecs[1] - ball_vecs[0]
        ax = gp_Ax2(gp_Pnt(ball_vecs[0].XYZ()), gp_Dir(v_ball_to_ball.XYZ()))
        mcyl = BRepPrimAPI_MakeCylinder(ax, self.d_o / 2.0,
                                        v_ball_to_ball.Magnitude())
        cyl = mcyl.Shape()
        mch = BRepFilletAPI_MakeChamfer(cyl)

        endFaces = []
        for face in Topo(cyl).faces():
            adaptor = BRepAdaptor_Surface(face)
            if adaptor.GetType() == GeomAbs_Plane:
                endFaces.append(face)
                for edge in Topo(face).edges():
                    mch.Add(self.chamfer_distance, edge, face)
        try:
            chamferedCyl = mch.Shape()
        except:
            chamferedCyl = cyl
            print("chamfer on ForceTransferCylinder failed!")
        mc = BRepAlgoAPI_Cut(chamferedCyl, self.balls[0].Shape())
        mc = BRepAlgoAPI_Cut(mc.Shape(), self.balls[1].Shape())
        return mc.Shape()
Example #3
0
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
Example #4
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)
OCCUtils.Topology.dumpTopology(front_face)
wires = t_face.wires()
Example #5
0
from __future__ import print_function

from random import random

from OCC.AIS import AIS_ColoredShape
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Display.OCCViewer import color
from OCC.Display.SimpleGui import init_display

from OCCUtils import Topo

display, start_display, add_menu, add_function_to_menu = init_display()

my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()

ais = AIS_ColoredShape(my_box)

for fc in Topo(my_box).faces():
    # set a custom color per-face
    ais.SetCustomColor(fc, color(random(), random(), random()))

display.Context.Display(ais.GetHandle())
display.FitAll()

start_display()
Example #6
0
        trsf.SetTransformation(ax_final, gp_Ax3())

        mt = BRepBuilderAPI_Transform(self.shape, trsf)
        return mt.Shape()


def loadBRep(filename):
    builder = BRep_Builder()
    shape = TopoDS_Shape()
    breptools_Read(shape, filename, builder)
    return shape


profile = loadBRep("inputGeom/5_segment_wire.brep")

for i in Topo(profile).wires():
    wire = i

profile = loadBRep("inputGeom/circ.brep")
for i in Topo(profile).wires():
    wire_1 = i

body = makeEllipticalAnnularSolid(70, 55, 40, 25, 0, 30)
cavityCutter = makeEllipticalAnnularSolid(65, 50, 45, 30, 5, 31)
mc = BRepAlgoAPI_Cut(body, cavityCutter)
part = mc.Shape()

pieSlice = makePieSlice(100, 0, pi / 4.0, -1, 31)

ball = makeBall(10)
stringer = makeStringerWithContinuousSlot()