Back to home page

EIC code displayed by LXR

 
 

    


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

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 
0023     run tgltf_gdml.py
0024 
0025     In [22]: tree.root.lv.solid.as_ncsg().transform
0026     [2017-05-19 13:25:49,429] p94731 {/Users/blyth/opticks/analytic/glm.py:175} WARNING - supressing identity transform
0027 
0028     In [29]: tree.get(1).lv.solid.as_ncsg()
0029     Out[29]: un(in(in(sp,sp),sp),cy)
0030 
0031     In [30]: cn = tree.get(1).lv.solid.as_ncsg()
0032 
0033     In [31]: cn.analyse()
0034 
0035     In [32]: cn.txt
0036     Out[32]: <opticks.analytic.textgrid.TextGrid at 0x10d01c450>
0037 
0038     In [33]: print cn.txt           union (of 3-sphere intersection and cylinder)
0039                          un    
0040                  in          cy
0041          in          sp        
0042      sp      sp                
0043 
0044 
0045 Better way, use the prexisting::
0046 
0047     In [13]: sc.get_node(1).mesh
0048     Out[13]: Mh    0 :              pmt-hemi0xc0fed90 /dd/Geometry/PMT/lvPmtHemi0xc133740 
0049 
0050     In [14]: sc.get_node(1).mesh.csg
0051     Out[14]: un(in(in(sp,sp),sp),cy)height:3 totnodes:15 
0052 
0053     In [15]: print sc.get_node(1).mesh.csg.txt
0054                          un    
0055                  in          cy
0056          in          sp        
0057      sp      sp                
0058 
0059 
0060 
0061 
0062 
0063 """
0064 import os, logging, sys, numpy as np
0065 
0066 log = logging.getLogger(__name__)
0067 
0068 from opticks.ana.base import opticks_main
0069 from opticks.analytic.treebase import Tree, Node
0070 from opticks.analytic.gdml import GDML
0071 from opticks.analytic.gdml_builder import make_gdml, tostring_
0072 from opticks.analytic.sc import Sc, Nd
0073 
0074 
0075 if __name__ == '__main__':
0076 
0077     args = opticks_main()
0078 
0079     pmt = "/dd/Geometry/PMT/lvPmtHemi0xc133740"
0080     oil = "/dd/Geometry/AD/lvOIL0xbf5e0b8"
0081 
0082     skey = "pmt1"
0083 #skey = "pmt2"
0084 #skey = "pmt5"
0085 #skey = "collar"
0086 #skey = "collar2"
0087 
0088     gg = make_gdml(worldref=oil, structure_key=skey )
0089     wgg = GDML.wrap(gg) 
0090 
0091     tree = Tree(wgg.world)
0092     assert type(tree.root) is Node
0093 
0094     sc = Sc()
0095     sc.extras["verbosity"] = 3
0096     tg = sc.add_tree_gdml( tree.root, maxdepth=0 )
0097     assert type(tg) is Nd
0098 
0099 
0100     path = "$TMP/tgltf/%s.gltf" % (os.path.basename(sys.argv[0]))
0101     gltf = sc.save(path)