File indexing completed on 2026-04-09 07:48:49
0001
0002 """
0003
0004
0005 In [80]: trpo[trpo[:,1] == 5]
0006 Out[80]:
0007 array([[83886080, 5, 0, 0],
0008 [83886081, 5, 0, 1],
0009 [83886082, 5, 0, 2],
0010 ...,
0011 [84057858, 5, 671, 2],
0012 [84057859, 5, 671, 3],
0013 [84057860, 5, 671, 4]], dtype=uint32)
0014
0015
0016 """
0017 import numpy as np
0018
0019 class OpticksIdentity(object):
0020 """
0021 cf okc/OpticksIdentity.cc
0022 """
0023 @classmethod
0024 def Encode(cls, ridx, pidx, oidx):
0025 if ridx > 0:
0026 assert (ridx & 0xff) == ridx
0027 assert (pidx & 0xffff) == pidx
0028 assert (oidx & 0xff) == oidx
0029 return (ridx << 24) | (pidx << 8) | (oidx << 0)
0030 else:
0031 assert (ridx & 0xff) == ridx
0032 assert pidx == 0
0033 assert (oidx & 0xffffff) == oidx
0034 return (ridx << 24) | (oidx << 0)
0035 pass
0036 @classmethod
0037 def Decode(cls, tid):
0038 ridx = ( tid >> 24 ) & 0xff
0039 pidx = np.where( ridx == 0, 0, ( tid >> 8 ) & 0xffff )
0040 oidx = np.where( ridx == 0, ( tid >> 0 ) & 0xffffff, ( tid >> 0 ) & 0xff )
0041 return ridx,pidx,oidx
0042
0043 @classmethod
0044 def NRPO(cls, tid):
0045 """
0046 Decode the triplet identifier to show nidx/ridx/pidx/oidx (node/repeat/placement/offset-idx)
0047 of all volumes, see okc/OpticksIdentity::Decode::
0048 In [44]: nrpo[nrpo[:,1] == 5]
0049 Out[44]:
0050 array([[ 3199, 5, 0, 0],
0051 [ 3200, 5, 0, 1],
0052 [ 3201, 5, 0, 2],
0053 ...,
0054 [11410, 5, 671, 2],
0055 [11411, 5, 671, 3],
0056 [11412, 5, 671, 4]], dtype=uint32)
0057
0058 """
0059 nidx = np.arange(len(tid), dtype=np.uint32)
0060 ridx,pidx,oidx = cls.Decode(tid)
0061 nrpo = np.zeros( (len(tid),4), dtype=np.uint32 )
0062 nrpo[:,0] = nidx
0063 nrpo[:,1] = ridx
0064 nrpo[:,2] = pidx
0065 nrpo[:,3] = oidx
0066 return nrpo
0067
0068
0069 if __name__ == '__main__':
0070 import os, numpy as np
0071 from opticks.ana.key import keydir
0072 avi = np.load(os.path.join(keydir(),"GNodeLib/all_volume_identity.npy"))
0073 tid = avi[:,1]
0074 nrpo = OpticksIdentity.NRPO(tid)
0075
0076
0077