Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #include <string>
0002 #include <sstream>
0003 #include <iostream>
0004 
0005 #include "SStr.hh"
0006 #include "scuda.h"
0007 #include "saabb.h"
0008 
0009 #include "DemoGrid.h"
0010 
0011 #include "SLOG.hh"
0012 #include "CSGFoundry.h"
0013 
0014 
0015 float4 DemoGrid::AddInstances( CSGFoundry* foundry_, unsigned ias_idx_, unsigned num_solid_ )  // static 
0016 {
0017     DemoGrid gr(foundry_, ias_idx_, num_solid_ ); 
0018     return gr.center_extent(); 
0019 } 
0020 
0021 DemoGrid::DemoGrid( CSGFoundry* foundry_, unsigned ias_idx_, unsigned num_solid_ )
0022     :
0023     foundry(foundry_),
0024     ias_idx(ias_idx_),
0025     num_solid(num_solid_),
0026     gridscale(SStr::GetEValue<float>("GRIDSCALE", 1.f))
0027 {
0028     std::string gridspec = SStr::GetEValue<std::string>("GRIDSPEC","-10:11,2,-10:11:2,-10:11,2") ; 
0029     SStr::ParseGridSpec(grid, gridspec.c_str());      // string parsed into array of 9 ints 
0030     SStr::GetEVector(solid_modulo, "GRIDMODULO", "0,1" ); 
0031     SStr::GetEVector(solid_single, "GRIDSINGLE", "2" ); 
0032 
0033     LOG(info) << "GRIDSPEC " << gridspec ; 
0034     LOG(info) << "GRIDSCALE " << gridscale ; 
0035     LOG(info) << "GRIDMODULO " << SStr::Present(solid_modulo) ; 
0036     LOG(info) << "GRIDSINGLE " << SStr::Present(solid_single) ; 
0037 
0038     init();   // add qat4 instances to foundry 
0039 }
0040 
0041 
0042 const float4 DemoGrid::center_extent() const 
0043 {
0044     glm::ivec3 imn(0,0,0); 
0045     glm::ivec3 imx(0,0,0); 
0046     SStr::GridMinMax(grid, imn, imx); 
0047 
0048     float3 mn = gridscale*make_float3( float(imn.x), float(imn.y), float(imn.z) ) ;
0049     float3 mx = gridscale*make_float3( float(imx.x), float(imx.y), float(imx.z) ) ;
0050 
0051     // hmm this does not accomodat the bbox of the item, just the grid centers of the items
0052     AABB bb = { mn, mx }; 
0053     float4 ce = bb.center_extent(); 
0054 
0055     return ce ; 
0056 }
0057 
0058 void DemoGrid::init()
0059 {
0060     unsigned num_solid_modulo = solid_modulo.size() ; 
0061     unsigned num_solid_single = solid_single.size() ; 
0062 
0063     LOG(info) 
0064         << "DemoGrid::init"
0065         << " num_solid_modulo " << num_solid_modulo
0066         << " num_solid_single " << num_solid_single
0067         << " num_solid " << num_solid
0068         ;
0069 
0070     // check the input solid_idx are valid 
0071     for(unsigned i=0 ; i < num_solid_modulo ; i++ ) assert(solid_modulo[i] < num_solid) ; 
0072     for(unsigned i=0 ; i < num_solid_single ; i++ ) assert(solid_single[i] < num_solid) ; 
0073 
0074     for(int i=0 ; i < int(num_solid_single) ; i++)
0075     {
0076         unsigned ins_idx = foundry->inst.size() ; // 0-based index within the DemoGrid
0077         unsigned gas_idx = solid_single[i] ;      // 0-based solid index
0078         unsigned sensor_identifier = 0 ; 
0079         unsigned sensor_index = 0 ; 
0080 
0081         qat4 instance  ; 
0082         instance.setIdentity( ins_idx, gas_idx, sensor_identifier, sensor_index  ); 
0083 
0084         foundry->inst.push_back( instance ); 
0085     }
0086 
0087     for(int i=grid[0] ; i < grid[1] ; i+=grid[2] ){
0088     for(int j=grid[3] ; j < grid[4] ; j+=grid[5] ){
0089     for(int k=grid[6] ; k < grid[7] ; k+=grid[8] ){
0090 
0091         qat4 instance  ; 
0092         instance.q3.f.x = float(i)*gridscale ; 
0093         instance.q3.f.y = float(j)*gridscale ; 
0094         instance.q3.f.z = float(k)*gridscale ; 
0095        
0096         unsigned ins_idx = foundry->inst.size() ;     
0097         unsigned solid_modulo_idx = ins_idx % num_solid_modulo ; 
0098         unsigned gas_idx = solid_modulo[solid_modulo_idx] ; 
0099         unsigned sensor_identifier = 0 ; 
0100         unsigned sensor_index = 0 ; 
0101 
0102         instance.setIdentity( ins_idx, gas_idx, sensor_identifier, sensor_index ); 
0103         foundry->inst.push_back( instance ); 
0104     }
0105     }
0106     }
0107 }
0108