Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:41

0001 #!/usr/bin/env python
0002 """
0003 sn_check.py
0004 ============
0005 
0006 
0007 """
0008 
0009 import numpy as np
0010 
0011 class snd_check(object):
0012     def __init__(self, f, symbol="c"):
0013         lvn = f.soname_names
0014         snd = f.csg.node
0015         snd_fields = snd.shape[1]
0016         assert snd_fields == 17
0017         self.snd = snd
0018 
0019 
0020 class sn_check(object):
0021     def __init__(self, f, symbol="c"):
0022         lvn = f.soname_names
0023         sn = f._csg.sn
0024         sn_fields = sn.shape[1]
0025         assert sn_fields in [17,19]
0026         with_child = sn_fields == 19
0027 
0028         s_pa = f._csg.s_pa
0029         s_tv = f._csg.s_tv
0030         s_bb = f._csg.s_bb
0031 
0032         self.sn = sn
0033         self.sn_fields = sn_fields
0034         self.with_child = with_child
0035 
0036         self.s_pa = s_pa
0037         self.s_tv = s_tv
0038         self.s_bb = s_bb
0039 
0040 
0041         lv = sn[:,2]
0042         tv = sn[:,3]
0043         pa = sn[:,4]
0044         bb = sn[:,5]
0045         parent = sn[:,6]
0046 
0047         if with_child:
0048             pass
0049         else:
0050             left = sn[:,7]
0051             right = sn[:,8]
0052 
0053             self.left = left
0054             self.right = right
0055             self.ucheck("left")
0056             self.ucheck("right")
0057             self.check_left()
0058             self.check_right()
0059         pass
0060 
0061         self.lvn = lvn
0062         self.symbol = symbol
0063 
0064         self.lv = lv
0065         self.tv = tv
0066         self.pa = pa
0067         self.bb = bb
0068         self.parent = parent
0069 
0070         for field in "lv tv pa bb parent".split():
0071             self.ucheck(field)
0072         pass
0073         self.check_ulv()
0074         self.check_utv()
0075         self.check_upa()
0076         self.check_ubb()
0077         self.check_parent()
0078 
0079     def ucheck(self, field="lv"):
0080         uchk = np.unique(getattr(self,field), return_counts=True)
0081         setattr(self, "u%(field)s" % locals(), uchk[0] )
0082         setattr(self, "n%(field)s" % locals(), uchk[1] )
0083 
0084     def check_ulv(self):
0085         assert np.all( self.ulv == np.arange(len(self.ulv)) )
0086     def check_utv(self):
0087         assert self.utv.max() < len(self.s_tv), "integrity of transform refs"
0088     def check_upa(self):
0089         assert self.upa.max() < len(self.s_pa), "integrity of param refs"
0090     def check_ubb(self):
0091         assert self.ubb.max() < len(self.s_bb), "integrity of bbox refs"
0092     def check_parent(self):
0093         assert self.parent.max() < len(self.sn), "integrity of parent node refs"
0094         # assert np.all( self.nparent[1:] == 1 )
0095         # not fulfilled by the virtual mask polycone
0096 
0097     def check_left(self):
0098         assert self.left.max() < len(self.sn), "integrity of left node refs"
0099         assert np.all( self.nleft[1:] == 1 )
0100     def check_right(self):
0101         assert self.right.max() < len(self.sn), "integrity of right node refs"
0102         assert np.all( self.nright[1:] == 1 )
0103 
0104 
0105     def __repr__(self):
0106         sym = self.symbol
0107         #locals()[sym] = self   ## curious locals worked with older python, now need globals
0108         globals()[sym] = self
0109         expr = "np.c_[%(sym)s.ulv, %(sym)s.nlv, %(sym)s.lvn[%(sym)s.ulv]][np.where(%(sym)s.nlv>5)]" % locals()
0110         lines = []
0111         lines.append("opticks.sysrap.sn_check")
0112         lines.append(expr)
0113         lines.append(str(eval(expr)))
0114         lines.append("# NB raw nodes from G4VSolid, not complete binary tree counts")
0115         return "\n".join(lines)
0116 
0117 if __name__ == '__main__':
0118     print("klop")
0119 pass
0120 
0121