File indexing completed on 2026-04-09 07:48:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
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
0141
0142 print(ntc)
0143
0144
0145
0146
0147
0148