示例#1
0
    def system(self):
        r"""Initialise the GProp_GProps depending on the topological type

        Notes
        -----
        geom_type could be abstracted with TopoDS... instead of using _topo_type

        Returns
        -------
        OCC.GProp.GProp_GProps

        """
        self._system = GProp_GProps()

        if self._topo_type in GlobalProperties.surfacic_types:
            brepgprop_SurfaceProperties(self.shape, self._system)
        elif self._topo_type in GlobalProperties.linear_types:
            brepgprop_LinearProperties(self.shape, self._system)
        elif self._topo_type in GlobalProperties.volumic_types:
            brepgprop_VolumeProperties(self.shape, self._system)
        else:
            msg = "ShapeType is not linear, surfacic or volumic"
            logger.error(msg)
            raise WrongTopologicalType(msg)
        return self._system
示例#2
0
def point_in_solid(shape, pnt, tolerance=OCCUTILS_DEFAULT_TOLERANCE):
    r"""Is pnt inside solid?

    Parameters
    ----------
    shape : TopoDS_*
    pnt : OCC.gp.gp_Pnt
    tolerance : float

    Returns
    -------
    bool
        True if pnt lies in solid, False otherwise

    """
    if topo_lut[shape.ShapeType()] not in [
            "compound", "compsolid", "solid", "shell"
    ]:
        msg = "Cannot evaluate in/out position of a point in a 2D or less shape"
        logger.error(msg)
        raise WrongTopologicalType(msg)

    _in_solid = BRepClass3d_SolidClassifier(shape, pnt, tolerance)
    logger.info('State : %s' % str(_in_solid.State()))
    if _in_solid.State() == TopAbs_ON:
        return None
    if _in_solid.State() == TopAbs_OUT:
        return False
    if _in_solid.State() == TopAbs_IN:
        return True
示例#3
0
文件: solid.py 项目: buguen/aoc-utils
 def __init__(self, topods_solid):
     if not isinstance(topods_solid, OCC.TopoDS.TopoDS_Solid):
         msg = 'need a TopoDS_Solid, got a %s' % topods_solid.__class__
         logger.critical(msg)
         raise WrongTopologicalType(msg)
     assert not topods_solid.IsNull()
     BaseObject.__init__(self, topods_solid, 'solid')
示例#4
0
 def length(self):
     r"""length of a wire or edge"""
     if self.topo_type not in GlobalProperties.linear_types:
         msg = "length is only defined for linear topological types"
         logger.error(msg)
         raise WrongTopologicalType(msg)
     return self.system.Mass()
示例#5
0
    def __init__(self, topods_wire):
        if not isinstance(topods_wire, OCC.TopoDS.TopoDS_Wire):
            msg = 'Wire.__init__() needs a TopoDS_Wire, got a %s' % topods_wire.__class__
            logger.critical(msg)
            raise WrongTopologicalType(msg)
        assert not topods_wire.IsNull()

        BaseObject.__init__(self, topods_wire, name='topods_wire')
示例#6
0
 def __init__(self, wire):
     # assert isinstance(wire, OCC.TopoDS.TopoDS_Wire), 'not a TopoDS_Wire'
     if not isinstance(wire, OCC.TopoDS.TopoDS_Wire):
         msg = 'Need a TopoDS_Wire, got a %s' % wire.__class__
         logger.critical(msg)
         raise WrongTopologicalType(msg)
     self.wire = wire
     self.wire_explorer = OCC.BRepTools.BRepTools_WireExplorer(self.wire)
     self.done = False
示例#7
0
    def __init__(self, topods_shell):
        if not isinstance(topods_shell, OCC.TopoDS.TopoDS_Shell):
            msg = 'need a TopoDS_Shell, got a %s' % topods_shell.__class__
            logger.critical(msg)
            raise WrongTopologicalType(msg)

        assert not topods_shell.IsNull()

        BaseObject.__init__(self, topods_shell, 'shell')

        Shell._n += 1
示例#8
0
 def volume(self):
     r"""Volume"""
     if self.topo_type not in GlobalProperties.volumic_types:
         if self.topo_type != "compound":
             msg = "volume is only defined for linear volumic types"
             logger.error(msg)
             raise WrongTopologicalType(msg)
         else:
             import aocutils.topology
             solids = aocutils.topology.Topo(self.shape).solids
             return sum([GlobalProperties(solid).volume for solid in solids])
     return self._mass()
示例#9
0
 def area(self):
     r"""Area of the surface"""
     if self.topo_type not in GlobalProperties.surfacic_types:
         if self.topo_type != "compound":
             msg = "area is only defined for linear surfacic types"
             logger.error(msg)
             raise WrongTopologicalType(msg)
         else:
             import aocutils.topology
             faces = aocutils.topology.Topo(self.shape).faces
             return sum([GlobalProperties(face).area for face in faces])
     return self._mass()
示例#10
0
    def __init__(self, topods_edge):
        if not isinstance(topods_edge, OCC.TopoDS.TopoDS_Edge):
            msg = 'Need a OCC.TopoDS.TopoDS_Edge, got a %s' % topods_edge.__class__
            logger.critical(msg)
            raise WrongTopologicalType(msg)

        if topods_edge.IsNull():
            raise ValueError("topods_edge should no be Null")

        BaseObject.__init__(self, topods_edge, name='edge')

        self._adaptor = None
        self._brep_local_props = None
示例#11
0
    def __init__(self, topods_face):
        if not isinstance(topods_face, OCC.TopoDS.TopoDS_Face):
            msg = 'need a TopoDS_Face, got a %s' % topods_face.__class__
            logger.critical(msg)
            raise WrongTopologicalType(msg)

        if topods_face.IsNull():
            raise ValueError("topods_face should not be Null")

        BaseObject.__init__(self, topods_face, 'face')

        self._surface_handle = None
        self._adaptor = None
        self._adaptor_handle = None
        self._classify_uv = None
示例#12
0
 def __init__(self, shape, tol=OCCUTILS_DEFAULT_TOLERANCE):
     if isinstance(shape, TopoDS_Shape) or issubclass(shape.__class__,
                                                      TopoDS_Shape):
         self._shape = shape
     else:
         msg = "Expecting a TopoDS_Shape (or a subclass), " \
               "got a %s" % str(shape.__class__)
         logger.error(msg)
         raise WrongTopologicalType(msg)
     # self._shape = shape
     self._tol = tol
     self._bbox = Bnd_Box()
     self._bbox.SetGap(tol)
     brepbndlib_Add(self._shape, self._bbox)
     self._x_min, self._y_min, self._z_min, self._x_max, self._y_max, self._z_max = self._bbox.Get()
示例#13
0
 def __init__(self, shape, tol=0.01):
     if isinstance(shape, TopoDS_Shape) or issubclass(shape.__class__,
                                                      TopoDS_Shape):
         self._shape = shape
     else:
         msg = "Expecting a TopoDS_Shape (or a subclass), " \
               "got a %s" % str(shape.__class__)
         logger.error(msg)
         raise WrongTopologicalType(msg)
     # self._shape = shape
     bb = BoundingBox(self._shape)
     self._x_min = real_bb_position("X",
                                    "MIN",
                                    bb.x_min,
                                    self._shape,
                                    increment=tol)
     self._x_max = real_bb_position("X",
                                    "MAX",
                                    bb.x_max,
                                    self._shape,
                                    increment=tol)
     self._y_min = real_bb_position("Y",
                                    "MIN",
                                    bb.y_min,
                                    self._shape,
                                    increment=tol)
     self._y_max = real_bb_position("Y",
                                    "MAX",
                                    bb.y_max,
                                    self._shape,
                                    increment=tol)
     self._z_min = real_bb_position("Z",
                                    "MIN",
                                    bb.z_min,
                                    self._shape,
                                    increment=tol)
     self._z_max = real_bb_position("Z",
                                    "MAX",
                                    bb.z_max,
                                    self._shape,
                                    increment=tol)
示例#14
0
文件: curve.py 项目: buguen/aoc-utils
 def __init__(self, curve):
     if not issubclass(curve.__class__, OCC.Geom.Geom_Curve):
         msg = 'Curve.__init__() needs a Geom_Curve or a subclass, got a %s' % curve.__class__
         logger.critical(msg)
         raise WrongTopologicalType(msg)
     self._curve = curve
示例#15
0
    def _loop_topo(self,
                   topology_type,
                   topological_entity=None,
                   topology_type_to_avoid=None):
        """Iterating over shape topology

        Notes
        -----
        this could be a faces generator for a python TopoShape class
        that way you can just do:
        for face in srf.faces:
            processFace(face)

        Parameters
        ----------
        topology_type
        topological_entity
        topology_type_to_avoid

        Returns
        -------
        list of TopoDS_*
            Depending on the topology_type input

        """
        # topo_types = {OCC.TopAbs.TopAbs_VERTEX: OCC.TopoDS.TopoDS_Vertex,
        #               OCC.TopAbs.TopAbs_EDGE: OCC.TopoDS.TopoDS_Edge,
        #               OCC.TopAbs.TopAbs_FACE: OCC.TopoDS.TopoDS_Face,
        #               OCC.TopAbs.TopAbs_WIRE: OCC.TopoDS.TopoDS_Wire,
        #               OCC.TopAbs.TopAbs_SHELL: OCC.TopoDS.TopoDS_Shell,
        #               OCC.TopAbs.TopAbs_SOLID: OCC.TopoDS.TopoDS_Solid,
        #               OCC.TopAbs.TopAbs_COMPOUND: OCC.TopoDS.TopoDS_Compound,
        #               OCC.TopAbs.TopAbs_COMPSOLID: OCC.TopoDS.TopoDS_CompSolid
        # }

        # assert topology_type in topo_types.keys(),
        # '%s not one of %s' % (topology_type, topo_types.keys())
        if topology_type not in topo_type_class.keys():
            msg = '%s not one of %s' % (topology_type, topo_type_class.keys())
            logger.critical(msg)
            raise WrongTopologicalType(msg)

        self.topexp_explorer = OCC.TopExp.TopExp_Explorer()
        # use self._my_shape if nothing is specified
        if topological_entity is None and topology_type_to_avoid is None:
            self.topexp_explorer.Init(self._my_shape, topology_type)

        elif topological_entity is None and topology_type_to_avoid is not None:
            self.topexp_explorer.Init(self._my_shape, topology_type,
                                      topology_type_to_avoid)

        elif topology_type_to_avoid is None:
            self.topexp_explorer.Init(topological_entity, topology_type)

        elif topology_type_to_avoid:
            self.topexp_explorer.Init(topological_entity, topology_type,
                                      topology_type_to_avoid)

        seq = list()
        hashes = list()  # list that stores hashes to avoid redundancy
        occ_seq = OCC.TopTools.TopTools_ListOfShape()
        while self.topexp_explorer.More():
            current_item = self.topexp_explorer.Current()
            current_item_hash = current_item.__hash__()

            if current_item_hash not in hashes:
                hashes.append(current_item_hash)
                occ_seq.Append(current_item)

            self.topexp_explorer.Next()
        # Convert occ_seq to python list
        occ_iterator = OCC.TopTools.TopTools_ListIteratorOfListOfShape(occ_seq)
        while occ_iterator.More():
            topo_to_add = topo_factory[topology_type](occ_iterator.Value())
            seq.append(topo_to_add)
            occ_iterator.Next()

        if self._ignore_orientation:
            # filter out those entities that share the same TShape
            # but do *not* share the same orientation
            filter_orientation_seq = list()
            for i in seq:
                _present = False
                for j in filter_orientation_seq:
                    if i.IsSame(j):
                        _present = True
                        break
                if _present is False:
                    filter_orientation_seq.append(i)
            return filter_orientation_seq
        else:
            if self._return_iter:
                return iter(seq)  # iterator
            else:
                return seq  # list