Exemplo n.º 1
0
def common_parts(array, shells):
    from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Common
    from OCC.Extend.TopologyUtils import TopologyExplorer
    d = {}
    for i, si in enumerate(array):
        for k in si.dico:
            named_shell = si.dico[k]
            for j, s in enumerate(shells):
                com = BRepAlgoAPI_Common(named_shell.Shape(), s)
                n_common_faces = TopologyExplorer(
                    com.Shape()).number_of_faces()
                if n_common_faces > 0:
                    d[k] = com.Shape()
                    break
    return d
Exemplo n.º 2
0
    def getDaoCaseSurface(self):

        r = self.aBaseRadius
        r2 = r * 2
        h = self.aCaseHeight
        h2 = h / 2
        offset = self.aOffset
        gap = self.aCaseGap
        rTop = r + offset + gap

        rSphere = gp_Vec(0, rTop, h2).Magnitude()
        sphere = BRepPrimAPI_MakeSphere(rSphere).Shape()

        limit = BRepPrimAPI_MakeBox(gp_Pnt(-r2, -r2, -h2), gp_Pnt(r2, r2, h2)).Shape()
        step01Surface = BRepAlgoAPI_Common(sphere, limit).Shape()

        step02Surface = getShapeTranslate(step01Surface, 0, 0, -h2)

        cutIngSurface = self.getCached('getDaoIngSurface', offset - gap)
        cutYangSurface = self.getCached('getDaoYangSurface', offset - gap)
        step03Surface = BRepAlgoAPI_Cut(step02Surface, cutIngSurface).Shape()
        step04Surface = BRepAlgoAPI_Cut(step03Surface, cutYangSurface).Shape()

        step05Surface = getShapeTranslate(step04Surface, 0, 0, -h2)

        return step05Surface
Exemplo n.º 3
0
def getDaoCase(r, offset, h):
    r2 = r*2
    h2 = h/2
    rTop = r + offset
    rSphere = gp_Vec(0,rTop,h2).Magnitude()
    sphere = BRepPrimAPI_MakeSphere(rSphere).Shape()
    limit = BRepPrimAPI_MakeBox( gp_Pnt(-r2, -r2, -h2), gp_Pnt(r2, r2, h2) ).Shape()
    case = BRepAlgoAPI_Common(sphere, limit).Shape()
    case = getShapeTranslate(case, 0,0,-h2)
    return case
Exemplo n.º 4
0
 def one_obj_with_all(self, name):
     mass = 0
     props = GProp_GProps()
     for body2 in self.modules:
         if name == body2: continue
         body_inter = BRepAlgoAPI_Common(self.modules[body2],
                                         self.modules[name]).Shape()
         # self.display.DisplayShape(body_inter, color='WHITE')
         brepgprop_VolumeProperties(body_inter, props)
         mass += props.Mass()
     return mass
Exemplo n.º 5
0
    def from_boolean_intersection(cls, A: 'BRep', B: 'BRep') -> 'BRep':
        """Construct a BRep from the boolean intersection of two other BReps.

        Parameters
        ----------
        A : :class:`~compas_occ.brep.BRep`
        B : :class:`~compas_occ.brep.BRep`

        Returns
        -------
        :class:`~compas_occ.brep.BRep`

        """
        common = BRepAlgoAPI_Common(A.shape, B.shape)
        if not common.IsDone():
            raise Exception(
                "Boolean intersection operation could not be completed.")
        brep = BRep()
        brep.shape = common.Shape()
        return brep
Exemplo n.º 6
0
def combine_faces(face1, face2, height_mm):
    assert isinstance(face1, TopoDS_Face)
    assert isinstance(face2, TopoDS_Face)

    face1_ = copy.deepcopy(face1)
    face2_ = copy.deepcopy(face2)

    # assuming both faces start in the XZ plane
    tf = gp_Trsf()
    # rotate from the XZ plane to the YZ plane
    tf.SetRotation(gp_Ax1(ORIGIN, DIR_Z), math.pi / 2)
    face2_ = BRepBuilderAPI_Transform(face2_, tf).Shape()

    # We assume characters are no wider than they are tall, but just in case
    # we extrude by twice the height to make sure to capture all features
    face1_extruded = make_extrusion(face1_, 2 * height_mm, gp_Vec(0, 1, 0))
    face2_extruded = make_extrusion(face2_, 2 * height_mm, gp_Vec(1, 0, 0))
    common = BRepAlgoAPI_Common(face1_extruded, face2_extruded)

    result = common.Shape()
    assert isinstance(result, TopoDS_Compound)
    return copy.deepcopy(result)
Exemplo n.º 7
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()

    rnd = JupyterRenderer()
    rnd.DisplayShape(Box, transparency = True, opacity =0.2)
    rnd.DisplayShape(Wedge, transparency = True, opacity =0.2)
    rnd.DisplayShape(CommonSurface, render_edges=True)
    rnd.Display()
Exemplo n.º 8
0
 def intersection(self):
     children = self.get_children()
     shapes = []
     debug("children: %s" % (children, ))
     for c in children:
         if c.shape != None:
             shapes.append(c.shape)
     u = None
     if len(shapes) > 0:
         u = shapes[0].get_shape()
         for s in shapes[1:]:
             u = BRepAlgoAPI_Common(u, s.get_shape()).Shape()
     self.shape = SCLShape(u)
     self.children = []
Exemplo n.º 9
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, True)
    display.Context.SetTransparency(ais_wedge, 0.8, True)
    display.DisplayShape(CommonSurface)
    display.FitAll()
Exemplo n.º 10
0
    def inter_with_frame(self):
        # print('Start_inter_analyse')
        all_result = 0
        props = GProp_GProps()
        # print(self.modules)
        for model in self.modules:
            # print('#')
            body_inter = BRepAlgoAPI_Common(self.frame,
                                            self.modules[model]).Shape()
            # self.display.DisplayShape(body_inter, color='YELLOW')
            brepgprop_VolumeProperties(body_inter, props)
            mass = props.Mass()
            if mass > 0:
                self.valume_inter[model] = props.Mass()
                all_result += mass

        return all_result
Exemplo n.º 11
0
def getDaoCase(r, bevel, decor, h):
    r2 = r * 2
    h2 = h / 2
    rTop = r + 2 * bevel + decor
    rSphere = gp_Vec(0, rTop, h2).Magnitude()
    sphere = BRepPrimAPI_MakeSphere(rSphere).Shape()
    limit = BRepPrimAPI_MakeBox(gp_Pnt(-r2, -r2, -h2), gp_Pnt(r2, r2,
                                                              h2)).Shape()
    case = BRepAlgoAPI_Common(sphere, limit).Shape()
    case = getShapeTranslate(case, 0, 0, -h2)
    cylOut = BRepPrimAPI_MakeCylinder(r + bevel + decor, decor * 2).Shape()
    #SceneDrawShape('out',cylOut)
    cylIn = BRepPrimAPI_MakeCylinder(r + bevel, decor * 3).Shape()
    #SceneDrawShape('in',cylIn)
    bevelTool = BRepAlgoAPI_Cut(cylOut, cylIn).Shape()
    bevelTool = getShapeTranslate(bevelTool, 0, 0, -bevel / 2)
    #SceneDrawShape('tool',bevelTool)
    case = BRepAlgoAPI_Cut(case, bevelTool).Shape()
    return case
Exemplo n.º 12
0
    def inter_with_frame2(self):
        from OCC.Core.GProp import GProp_GProps
        from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Fuse, BRepAlgoAPI_Common, BRepAlgoAPI_Section, BRepAlgoAPI_Cut
        from OCC.Core.BRepGProp import brepgprop_VolumeProperties, brepgprop_SurfaceProperties, \
            brepgprop_LinearProperties
        # print('Start_inter_analyse')
        all_result = 0
        props = GProp_GProps()
        # print(self.modules)
        for model in self.modules:
            # print('#')
            body_inter = BRepAlgoAPI_Common(self.frame,
                                            self.modules[model]).Shape()
            # self.display.DisplayShape(body_inter, color='YELLOW')
            brepgprop_VolumeProperties(body_inter, props)
            mass = props.Mass()
            # print(mass)
            if mass > 1e-6:
                # print(mass)
                all_result += 1

        return all_result
Exemplo n.º 13
0
    def inter_objects2(self):

        # print('Start_inter_analyse')
        self.inter_mass = 0
        props = GProp_GProps()

        for i in range(len(self.names_models) - 2):
            for j in range(i + 1, len(self.names_models) - 1):
                if self.names_models[i] == self.names_models[j]: continue
                body_inter = BRepAlgoAPI_Common(
                    self.modules[self.names_models[i]],
                    self.modules[self.names_models[j]]).Shape()
                # self.display.DisplayShape(body_inter, color='WHITE')
                brepgprop_VolumeProperties(body_inter, props)
                mass = props.Mass()
                # print(mass)
                if mass > 0:
                    self.inter_mass += mass
                    self.valume_inter_obj[self.names_models[i]][
                        self.names_models[j]] = mass

        return self.inter_mass
Exemplo n.º 14
0
def slice_and_move(obj, box, vec):
    """Cut, move, and join and object

    One object is cut by another object. Sliced part is moved by a vector.
    Moved part is joined with non-moved part.

    Args:
        obj (Solid): object to be cut
        box (Solid): object used for cutting
        vec (gp_Vec): vector defining the offset
    """
    print('Solids before slicing: {}'.format(len(obj)))
    newsol = []
    for solid in obj:
        cut = BRepAlgoAPI_Cut(solid, box).Shape()
        comm = BRepAlgoAPI_Common(solid, box).Shape()
        comm = translate_topods_from_vector(comm, vec)
        newsol.append(cut)
        texp = TopologyExplorer(comm)
        if list(texp.solids()):
            newsol.append(comm)
    print('Solids after slicing: {}'.format(len(newsol)))
    return newsol
Exemplo n.º 15
0
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeBox
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_GTransform
from OCC.Core.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()
if common.IsNull():
    raise AssertionError("common result is Null.")

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()
Exemplo n.º 16
0
def occ_pair_intersect(a, b):
    algo = BRepAlgoAPI_Common(a, b)
    algo.Build()
    if not algo.IsDone():
        raise Exception("warn: intersect algotithm failed\n")
    return algo.Shape()
Exemplo n.º 17
0
 def makeCommon(self,r,h,shape) :
     from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Common
     cyl = self.makeCylSection(r,h)
     common = BRepAlgoAPI_Common(cyl, shape).Shape()
     return common
yshift = 0
myBox11 = BRepPrimAPI_MakeBox(gp_Pnt(0, yshift, 0), 10, 10, 10).Shape()
myBox12 = BRepPrimAPI_MakeBox(gp_Pnt(5, yshift + 5, 5), 10, 10, 10).Shape()
myCut1 = BRepAlgoAPI_Cut(myBox11, myBox12).Shape()

# cut (L-Shape - box)
yshift += spacing
myBox21 = get_faceted_L_shape(0, yshift, 0)
myBox22 = BRepPrimAPI_MakeBox(gp_Pnt(15, yshift + 5, 5), 10, 10, 10).Shape()
myCut2 = BRepAlgoAPI_Cut(myBox21, myBox22).Shape()

# intersection  (L-Shape - box)
yshift += spacing
myBox23 = get_faceted_L_shape(0, yshift, 0)
myBox24 = BRepPrimAPI_MakeBox(gp_Pnt(15, yshift + 5, 5), 10, 10, 10).Shape()
myCut3 = BRepAlgoAPI_Common(myBox23, myBox24).Shape()

# Simple box CUT from LShape using MakeSolidFromShell
yshift += spacing
myBox31 = MakeSolidFromShell(get_faceted_L_shape(0, yshift, 0))
myBox32 = BRepPrimAPI_MakeBox(gp_Pnt(15, yshift + 5, 5), 10, 10, 10).Shape()
myCut4 = BRepAlgoAPI_Cut(myBox31, myBox32).Shape()

# Simple box FUSE from LShape using MakeSolidFromShell
yshift += spacing
myBox33 = MakeSolidFromShell(get_faceted_L_shape(0, yshift, 0))
myBox34 = BRepPrimAPI_MakeBox(gp_Pnt(15, yshift + 5, 5), 10, 10, 10).Shape()
myCut5 = BRepAlgoAPI_Fuse(myBox33, myBox34).Shape()

# Simple box COMMON with LShape using MakeSolidFromShell
yshift += spacing
Exemplo n.º 19
0
 def inter_one_object_frame(self, name):
     props = GProp_GProps()
     body_inter = BRepAlgoAPI_Common(self.frame, self.modules[name]).Shape()
     brepgprop_VolumeProperties(body_inter, props)
     # print(props.Mass())
     return props.Mass()
Exemplo n.º 20
0
from OCC.Core.gp import gp_Pnt, gp_XYZ, gp_Mat, gp_GTrsf
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeBox
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_GTransform
from OCC.Core.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()