Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:49:16

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 DAE
0023 =====
0024 
0025 Simple XML parsing of COLLADA, for debug access to XML elements.  
0026 
0027 
0028 """
0029 import os, sys, logging
0030 import numpy as np
0031 from StringIO import StringIO
0032 import lxml.etree as ET
0033 
0034 import opticks.ana.base
0035  
0036 log = logging.getLogger(__name__)
0037 
0038 COLLADA_NS='http://www.collada.org/2005/11/COLLADASchema'
0039 tag_ = lambda _:str(ET.QName(COLLADA_NS,_))
0040 xmlparse_ = lambda _:ET.parse(os.path.expandvars(_)).getroot()
0041 tostring_ = lambda _:ET.tostring(_)
0042 array_ = lambda e:np.loadtxt(StringIO(e.text))
0043 
0044 
0045 class DAE(object):
0046     @classmethod
0047     def iddir(cls):
0048         return os.path.dirname(os.path.expandvars("$IDPATH"))
0049 
0050     @classmethod
0051     def idfold(cls):
0052         return os.path.dirname(os.path.dirname(os.path.expandvars("$IDPATH")))
0053 
0054     @classmethod
0055     def standardpath(cls, name="g4_00.dae"):
0056         path_0 = os.path.join(cls.iddir(), name)
0057         return path_0
0058 
0059     @classmethod
0060     def path(cls, fold="dpib", name="cfg4.dae"):
0061         path_1 = os.path.join(cls.idfold(), fold, name)
0062         return path_1
0063 
0064     @classmethod
0065     def deref(cls, id_):
0066         ox = id_.find('0x')
0067         return id_[0:ox] if ox > -1 else id_
0068 
0069     def __init__(self, path):
0070         self.x = xmlparse_(path)
0071 
0072     def elem_(self, elem, id_):
0073         q = ".//%s[@id='%s']" % ((tag_(elem)), id_)
0074         e = self.x.find(q)
0075         return e
0076 
0077     def elems_(self, elem):
0078         q = ".//%s" % tag_(elem)
0079         es = self.x.findall(q)
0080         return es
0081 
0082     def float_array(self, id_):
0083         e = self.elem_("float_array", id_ )
0084         s = StringIO(e.text)
0085         a = np.loadtxt(s) 
0086         return a
0087 
0088     def material(self, id_):
0089         e = self.elem_("material", id_ )
0090         return e
0091 
0092 
0093 if __name__ == '__main__':
0094     pass
0095     logging.basicConfig(level=logging.INFO)
0096 
0097     
0098 
0099 
0100 
0101 
0102 
0103 
0104 
0105