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 Regenerate the cpp for each mesh with::
0024 
0025     gdml2gltf.py   # writes .gltf and extras beside the .gdml in standard IDFOLD location
0026 
0027 See::
0028 
0029     opticks-nnt LVID
0030     opticks-nnt-vi LVID
0031 
0032 
0033 """
0034 import logging, os
0035 log = logging.getLogger(__name__)
0036 
0037 template_head = r"""
0038 
0039 // regenerate with gdml2gltf.py 
0040 
0041 #include <vector>
0042 #include "SSys.hh"
0043 #include "NGLMExt.hpp"
0044 #include "NCSG.hpp"
0045 #include "NSceneConfig.hpp"
0046 #include "NBBox.hpp"
0047 #include "NNode.hpp"
0048 #include "NPrimitives.hpp"
0049 #include "PLOG.hh"
0050 #include "NPY_LOG.hh"
0051 
0052 int main(int argc, char** argv)
0053 {
0054     PLOG_(argc, argv);
0055     NPY_LOG__ ; 
0056 """
0057 
0058 
0059 template_tail = r"""
0060 
0061     %(root)s.update_gtransforms();
0062 
0063     unsigned verbosity = SSys::getenvint("VERBOSITY", 1) ; 
0064     %(root)s.verbosity = verbosity ; 
0065     //%(root)s.dump() ; 
0066 
0067     const char* boundary = "Rock//perfectAbsorbSurface/Vacuum" ;
0068 
0069     %(root)s.set_boundary(boundary); 
0070     const char* gltfconfig = "" ;  
0071     const NSceneConfig* config = new NSceneConfig(gltfconfig);
0072     NCSG* csg = NCSG::FromNode(&%(root)s, config);
0073     csg->dump();
0074     csg->dump_surface_points("dsp", verbosity > 2 ? 500 : 20 );
0075 
0076 
0077     return 0 ;        
0078 }
0079 """
0080 
0081 template_body = r"""%(body)s"""
0082 
0083 test_body = r"""
0084 nsphere a = make_nsphere(0,0,0,100) ;
0085 """
0086 
0087 
0088 from opticks.ana.base import now_
0089 
0090 
0091 def indent_(s):
0092     lines = s.split("\n")
0093     return "\n".join(map(lambda _:"    %s" % _, lines))
0094 
0095 def trim_(s):
0096     lines = filter(None, s.split("\n"))
0097     return "\n".join(lines)
0098     
0099 
0100 
0101 class NNodeTestCPP(dict):
0102      def __init__(self, *args, **kwa):
0103          dict.__init__(self, *args, **kwa)
0104 
0105      def _get_stamp(self):
0106          return "// generated by nnode_test_cpp.py : %s " % ( now_() )
0107      stamp = property(_get_stamp)
0108 
0109      def _get_runline(self):
0110          return "\n".join([
0111                    "// opticks-;opticks-nnt %(name)s " % self,
0112                    "// opticks-;opticks-nnt-vi %(name)s " % self,""])
0113      runline = property(_get_runline)
0114 
0115      head = property(lambda self:template_head % self)
0116      body = property(lambda self:template_body % self)
0117      tail = property(lambda self:template_tail % self)
0118 
0119      path = property(lambda self:os.path.expandvars("$TMP/tbool%(name)s.cc" % self))
0120 
0121      def save(self):
0122          log.info("saving to %s " % self.path) 
0123          file(self.path,"w").write(str(self))
0124 
0125      def test(self):
0126          print(self.stamp)
0127          print(self.head)
0128          print(self.body)
0129          print(self.tail)
0130 
0131      def __str__(self):
0132          return "\n".join([self.stamp, self.runline, self.head, indent_("\n".join([self.stamp,self.runline])), indent_(self.body), self.tail])  
0133 
0134 
0135 if __name__ == '__main__':
0136 
0137      logging.basicConfig(level=logging.INFO)
0138 
0139      ntc = NNodeTestCPP(name="0", root="a", body=test_body)
0140      #ntc.test()
0141 
0142      print(ntc) 
0143 
0144      #ntc.save()
0145 
0146      
0147 
0148