Пример #1
0
 def geom_to_data(self, name=None, divide=True):
     #TODO(mvk): if no color, get color from parent if any?
     g_id = self.get_geom(name)
     n = (name if name is not None else str(g_id)) + '.Geom'
     pd = PKDict(name=n, id=g_id, data=[])
     d = rs_utils.to_pkdict(radia.ObjDrwVTK(g_id, 'Axes->No'))
     n_verts = len(d.polygons.vertices)
     c = radia.ObjCntStuf(g_id)
     l = len(c)
     if not divide or l == 0:
         pd.data = [d]
     else:
         d_arr = []
         n_s_verts = 0
         # for g in get_geom_tree(g_id):
         for g in c:
             # for fully recursive array
             # for g in get_all_geom(geom):
             s_d = rs_utils.to_pkdict(radia.ObjDrwVTK(g, 'Axes->No'))
             n_s_verts += len(s_d.polygons.vertices)
             d_arr.append(s_d)
         # if the number of vertices of the container is more than the total
         # across its elements, a symmetry or other "additive" transformation has
         # been applied and we cannot get at the individual elements
         if n_verts > n_s_verts:
             d_arr = [d]
         pd.data = d_arr
     pd.bounds = radia.ObjGeoLim(g_id)
     return pd
Пример #2
0
def geom_to_data(g_id, name=None, divide=True):

    def _to_pkdict(d):
        if not isinstance(d, dict):
            return d
        rv = PKDict()
        for k, v in d.items():
            rv[k] = _to_pkdict(v)
        return rv

    n = (name if name is not None else str(g_id)) + '.Geom'
    pd = PKDict(name=n, id=g_id, data=[])
    d = _to_pkdict(radia.ObjDrwVTK(g_id, 'Axes->No'))
    d.update(_geom_bnds(g_id))
    n_verts = len(d.polygons.vertices)
    c = radia.ObjCntStuf(g_id)
    l = len(c)
    if not divide or l == 0:
        d.id = g_id
        pd.data = [d]
    else:
        d_arr = []
        n_s_verts = 0
        # for g in get_geom_tree(g_id):
        for g in c:
            # for fully recursive array
            # for g in get_all_geom(geom):
            s_d = _to_pkdict(radia.ObjDrwVTK(g, 'Axes->No'))
            s_d.update(_geom_bnds(g))
            n_s_verts += len(s_d.polygons.vertices)
            s_d.id = g
            d_arr.append(s_d)
        # if the number of vertices of the container is more than the total
        # across its elements, a symmetry or other "additive" transformation has
        # been applied and we cannot get at the individual elements
        if n_verts > n_s_verts:
            d.id = g_id
            d_arr = [d]
        pd.data = d_arr
    pd.bounds = radia.ObjGeoLim(g_id)
    return pd