Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /**
0002 CSGDemoTest.cc
0003 ==================
0004 
0005 This executable creates and persists simple demo geometries, using the tests/DemoGeo.h struct. 
0006 Invoke the executable with::
0007 
0008     cd ~/opticks/CSG
0009     ./CSGDemoTest.sh    
0010 
0011 To apply the above script to all the demo geometries use ``./make_demos.sh`` 
0012 Render the geometries with::
0013 
0014     cd ~/opticks/CSGOptiX
0015     ./cxr_demo.sh 
0016 
0017 **/
0018 
0019 #include <csignal>
0020 #include "SSys.hh"
0021 #include "SPath.hh"
0022 #include "OPTICKS_LOG.hh"
0023 
0024 #include "scuda.h"
0025 #include "CSGFoundry.h"
0026 #include "DemoGeo.h"
0027 
0028 
0029 struct CSGDemoTest
0030 {
0031     static const char* BASE ; 
0032     const char* geom ; 
0033     CSGFoundry fd ;  
0034 
0035     CSGDemoTest(const char* geom); 
0036     void init(); 
0037     void save() const ; 
0038     void dump() const ; 
0039 };
0040 
0041 
0042 // IT IS EXPEDIENT FOR ALL TEST GEOMETRIES TO LIVE IN THE SAME TREE 
0043 #ifdef __APPLE__
0044 const char* CSGDemoTest::BASE = "$TMP/GeoChain_Darwin" ;
0045 #else
0046 const char* CSGDemoTest::BASE = "$TMP/GeoChain" ;
0047 #endif
0048 
0049 
0050 CSGDemoTest::CSGDemoTest(const char* geom_)
0051     :
0052     geom(strdup(geom_))
0053 {
0054     init();
0055 }
0056 
0057 void CSGDemoTest::init()
0058 {
0059     DemoGeo dg(&fd, geom) ;  
0060     LOG(info) << fd.desc(); 
0061     LOG(info) << fd.descSolids(); 
0062 }
0063 
0064 void CSGDemoTest::save() const 
0065 {
0066     const char* fold = SPath::Resolve(BASE, geom, DIRPATH );
0067     const char* cfbase = SSys::getenvvar("CFBASE", fold  );
0068     const char* rel = "CSGFoundry" ;
0069     fd.save(cfbase, rel );  
0070 
0071     CSGFoundry* lfd = CSGFoundry::Load(cfbase, rel);  // load foundary and check identical bytes
0072     bool lfd_expect = CSGFoundry::Compare(&fd, lfd ) == 0 ; 
0073     assert(lfd_expect);
0074     if(!lfd_expect) std::raise(SIGINT); 
0075 
0076 }
0077 
0078 
0079 void CSGDemoTest::dump() const
0080 {
0081     unsigned ias_idx = 0u ; 
0082     unsigned long long emm = 0ull ;
0083     LOG(info) << "descInst" << std::endl << fd.descInst(ias_idx, emm);  
0084 
0085     AABB bb = fd.iasBB(ias_idx, emm ); 
0086     float4 ce = bb.center_extent() ;  
0087 
0088     LOG(info) << "bb:" << bb.desc() ; 
0089     LOG(info) << "ce:" << ce ; 
0090 
0091     std::vector<float3> corners ; 
0092     AABB::cube_corners(corners, ce ); 
0093     for(int i=0 ; i < int(corners.size()) ; i++) LOG(info) << corners[i] ;  
0094 }
0095 
0096 
0097 int main(int argc, char** argv)
0098 {
0099     OPTICKS_LOG(argc, argv); 
0100 
0101     const char* geom = SSys::getenvvar("GEOM", "sphere" ); 
0102     CSGDemoTest dt(geom); 
0103     dt.save(); 
0104     dt.dump(); 
0105 
0106     return 0 ; 
0107 }