Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /**
0002 CSGOptiXRenderTest
0003 ====================
0004 
0005 For a simpler alternative see CSGOptiXRMTest.cc
0006 
0007 This executable is typically run via cxr_*.sh specialized bash scripts 
0008 each dedicated to different types of renders. 
0009 The scripts control what this executable does and where it writes via envvars.  
0010 See CSGOptiX/index.rst for details on the scripts. 
0011 
0012 With option --arglist /path/to/arglist.txt each line of the arglist file 
0013 is taken as an MOI specifying the center_extent box to target. 
0014 Without an --arglist option the MOI envvar or default value  "sWorld:0:0" 
0015 is used to set the viewpoint target box.
0016 
0017 important envvars
0018 
0019 MOI 
0020     specifies the viewpoint target box, default "sWorld:0:0" 
0021 TOP
0022     selects the part of the geometry to use, default i0 
0023 CFBASE
0024     directory to load the CSGFoundry geometry from, default "$TMP/CSG_GGeo" 
0025 
0026     NB CFBASE is now only used as an override (eg for demo geometry) 
0027     when not rendering the standard OPTICKS_KEY geometry which is now located inside geocache.
0028 **/
0029 
0030 #include <algorithm>
0031 #include <iterator>
0032 #include <cstdlib>
0033 #include <csignal>
0034 
0035 #include "ssys.h"
0036 
0037 #include "SSim.hh"
0038 #include "SOpticks.hh"
0039 #include "SEventConfig.hh"
0040 #include "SBitSet.h"
0041 #include "SGeoConfig.hh"
0042 
0043 #include "OPTICKS_LOG.hh"
0044 #include "scuda.h"
0045 #include "sqat4.h"
0046 
0047 #include "SGLM.h"
0048 #include "CSGFoundry.h"
0049 #include "CSGCopy.h"
0050 #include "CSGOptiX.h"
0051 
0052 
0053 const plog::Severity LEVEL = debug ; 
0054 
0055 
0056 struct CSGOptiXRenderTest
0057 {
0058     CSGOptiXRenderTest() ; 
0059 
0060     const char* solid_selection ; 
0061 
0062     CSGFoundry* fd ;  // possibly with selection applied
0063     CSGOptiX*   cx ; 
0064 
0065     const char* flight ; 
0066     float4      ce ; 
0067 
0068     const char* default_arg ; 
0069     std::vector<std::string> args ; 
0070 
0071     void initSolidSelection(); 
0072     void initArgs(); 
0073 
0074     void setFrame_solid_selection(); 
0075 
0076 };
0077 
0078 
0079 CSGOptiXRenderTest::CSGOptiXRenderTest()
0080     : 
0081     solid_selection(SGeoConfig::SolidSelection()),   //  formerly from --solid_label option used for selecting solids from the geometry 
0082     fd(CSGFoundry::Load()), 
0083     cx(CSGOptiX::Create(fd)),   // uploads fd and then instanciates 
0084     flight(SGeoConfig::FlightConfig()),
0085     ce(make_float4(0.f, 0.f, 0.f, 1000.f )),
0086     default_arg(ssys::getenvvar("MOI", "sWorld:0:0"))  
0087 {
0088     initSolidSelection(); 
0089     initArgs(); 
0090 }
0091 
0092 
0093 /**
0094 CSGOptiXRenderTest::initSolidSelection
0095 ---------------------------------------
0096 
0097 MAYBE : remove this solid selection approach, as EMM does similar but more cleanly ? 
0098 
0099 **/
0100 
0101 void CSGOptiXRenderTest::initSolidSelection()
0102 {
0103     if( solid_selection == nullptr  ) return ; 
0104 
0105     fd->findSolidIdx(cx->solid_selection, solid_selection); 
0106     std::string solsel = fd->descSolidIdx(cx->solid_selection); 
0107     LOG(error) 
0108         << " solid_selection " << solid_selection
0109         << " cx.solid_selection.size  " << cx->solid_selection.size() 
0110         << " solsel " << solsel 
0111         ;
0112 
0113 }
0114 
0115 void CSGOptiXRenderTest::initArgs()
0116 {
0117     unsigned num_select = cx->solid_selection.size();  
0118     if( solid_selection )
0119     {
0120         bool num_select_expect = num_select > 0 ;
0121         assert( num_select_expect ); 
0122         if(!num_select_expect) std::raise(SIGINT); 
0123     }
0124 
0125     std::vector<std::string>* arglist = SGeoConfig::Arglist() ;
0126 
0127     if( arglist && arglist->size() > 0 )
0128     {    
0129         std::copy(arglist->begin(), arglist->end(), std::back_inserter(args));
0130         LOG(LEVEL) << " using arglist from SGeoConfig::Arglist " ; 
0131     }
0132     else
0133     {
0134         args.push_back(default_arg);   
0135         //LOG(LEVEL) << " using default_arg from MOI envvar " ; 
0136     }
0137 }
0138 
0139 void CSGOptiXRenderTest::setFrame_solid_selection()
0140 {
0141     assert( solid_selection ); 
0142     fd->gasCE(ce, cx->solid_selection );    
0143 
0144     LOG(LEVEL) 
0145         << " solid_selection " << solid_selection
0146         << " cx.solid_selection.size " << cx->solid_selection.size()
0147         << " ce (" << ce.x << " " << ce.y << " " << ce.z << " " << ce.w << ") " 
0148        ; 
0149 
0150     cx->setFrame(ce); 
0151 }
0152 
0153 
0154 
0155 int main(int argc, char** argv)
0156 {
0157     OPTICKS_LOG(argc, argv); 
0158 
0159     SEventConfig::SetRGModeRender(); 
0160 
0161     SSim::Create(); 
0162 
0163     CSGOptiXRenderTest t; 
0164 
0165     if( t.solid_selection )
0166     {
0167         const char* arg = ssys::getenvvar("NAMESTEM", "") ; 
0168         LOG(LEVEL) << " t.solid_selection " << t.solid_selection << " arg " << arg ; 
0169         t.setFrame_solid_selection(); 
0170         t.cx->render(); 
0171     }
0172     else if( t.flight )
0173     {
0174         const char* arg = t.args[0].c_str(); 
0175         LOG(LEVEL) << " t.flight arg " << arg  ; 
0176         t.cx->setFrame(arg); 
0177         t.cx->render_flightpath(); 
0178     }
0179     else
0180     {
0181         //LOG(LEVEL) << " t.args.size " << t.args.size()  ; 
0182         for(unsigned i=0 ; i < t.args.size() ; i++)
0183         {
0184             const char* arg = t.args[i].c_str(); 
0185             //LOG(LEVEL) << " arg:" << ( arg ? arg : "-" ) ; 
0186             t.cx->setFrame(arg); 
0187             t.cx->render(); 
0188         }
0189     }
0190     return 0 ; 
0191 }
0192