Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #!/usr/bin/env python
0002 #
0003 # Copyright (c) 2019 Opticks Team. All Rights Reserved.
0004 #
0005 # This file is part of Opticks
0006 # (see https://bitbucket.org/simoncblyth/opticks).
0007 #
0008 # Licensed under the Apache License, Version 2.0 (the "License"); 
0009 # you may not use this file except in compliance with the License.  
0010 # You may obtain a copy of the License at
0011 #
0012 #   http://www.apache.org/licenses/LICENSE-2.0
0013 #
0014 # Unless required by applicable law or agreed to in writing, software 
0015 # distributed under the License is distributed on an "AS IS" BASIS, 
0016 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0017 # See the License for the specific language governing permissions and 
0018 # limitations under the License.
0019 #
0020 
0021 """
0022 Check analytic and triangulates LVNames, PVNames lists 
0023 
0024 ::
0025 
0026     simon:ana blyth$ ./nodelib.py 
0027     INFO:opticks.ana.base:translating
0028     INFO:opticks.ana.base:translating
0029     INFO:__main__:lv ItemLists names  12230 name2code    249 code2name  12230 offset     0 npath $IDPATH/GItemList/LVNames.txt  
0030     INFO:__main__:pv ItemLists names  12230 name2code   5643 code2name  12230 offset     0 npath $IDPATH/GItemList/PVNames.txt  
0031     INFO:__main__:lv ItemLists names   1660 name2code    171 code2name   1660 offset     0 npath $IDPATH/analytic/GScene/GNodeLib/LVNames.txt  
0032     INFO:__main__:pv ItemLists names   1660 name2code    704 code2name   1660 offset     0 npath $IDPATH/analytic/GScene/GNodeLib/PVNames.txt  
0033     INFO:__main__:ana is partial list tri.size 1660 ana.size 12230 
0034     INFO:__main__:tri indices of first ana PV : pv_f /dd/Geometry/Pool/lvNearPoolIWS#pvNearADE10xc2cf528 idx_f 3153 
0035     INFO:__main__:tri indices of last  ana PV : pv_l /dd/Geometry/AdDetails/lvMOOverflowTankE#pvMOFTTopCover0xc20cf40 idx_l 4804 
0036     simon:ana blyth$ 
0037 
0038 
0039 """
0040 
0041 import os, logging, numpy as np
0042 from opticks.ana.base import ItemList, translate_xml_identifier_, manual_mixin
0043 
0044 log = logging.getLogger(__name__)
0045 
0046 
0047 #class MyItemList(object):
0048 #    def find_index(self, name):
0049 #        return self.names.index(name)
0050 #
0051 #manual_mixin(ItemList, MyItemList)
0052 
0053 
0054 class VolumeNames(object):
0055     def __init__(self, reldir=None, offset=0, translate_=None):
0056         lv = ItemList(txt="LVNames", offset=offset, translate_=translate_ , reldir=reldir)
0057         pv = ItemList(txt="PVNames", offset=offset, translate_=translate_ , reldir=reldir)
0058         log.info( "lv %r " % lv )
0059         log.info( "pv %r " % pv )
0060 
0061         assert len(lv.names) == len(pv.names)
0062 
0063         self.size = len(lv.names)
0064         self.num_unique_pv = len(set(pv.names))
0065         self.lv = lv
0066         self.pv = pv
0067    
0068 
0069 
0070 class CfVolumeNames(object):
0071     """
0072     PV names are not unique, from instancing
0073 
0074         In [17]: len(cfv.tri.pv.names)
0075         Out[17]: 12230
0076 
0077         In [18]: len(set(cfv.tri.pv.names))
0078         Out[18]: 5643
0079 
0080     """
0081     def __init__(self):
0082         tri = VolumeNames(reldir=None, offset=0, translate_=translate_xml_identifier_ )
0083         ana = VolumeNames(reldir="analytic/GScene/GNodeLib", offset=0, translate_=None)
0084     
0085         if tri.size == ana.size:
0086             log.info("same size %s " % tri.size)
0087             assert tri.pv.names == ana.pv.names
0088             assert tri.lv.names == ana.lv.names
0089         else:
0090             assert ana.size < tri.size, (ana.size, tri.size)
0091             log.info("ana is partial list tri.size %s ana.size %s " % (ana.size, tri.size))
0092 
0093             # PV names are not unique for instances, so the below reconstruction of the offset index 
0094             # from the ana pv names will only work for cases where the first found name corresponds to 
0095             # the correct volume indes.
0096             #
0097             # This is handled C++ side with gltftarget (config) and NScene targetnode GLTF asset metadata
0098 
0099             pv_f = ana.pv.names[0]
0100             pv_l = ana.pv.names[-1]
0101             idx_f = tri.pv.find_index(pv_f) 
0102             idx_l = tri.pv.find_index(pv_l) 
0103             log.info("tri indices of first ana PV : pv_f %s idx_f %d " % (pv_f,idx_f))
0104             log.info("tri indices of last  ana PV : pv_l %s idx_l %d " % (pv_l, idx_l))
0105 
0106             assert tri.pv.names[idx_f:idx_f+len(ana.pv.names)] == ana.pv.names
0107             assert tri.lv.names[idx_f:idx_f+len(ana.lv.names)] == ana.lv.names
0108         pass
0109 
0110         self.tri = tri
0111         self.ana = ana
0112   
0113 
0114 
0115 
0116 
0117 
0118 
0119 if __name__ == '__main__':
0120     logging.basicConfig(level=logging.INFO)
0121 
0122     cfv = CfVolumeNames()
0123 
0124 
0125 
0126     
0127 
0128 
0129 
0130 
0131 
0132 
0133 
0134