Ejemplo 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
Ejemplo n.º 2
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
Ejemplo n.º 3
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)
Ejemplo n.º 4
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()