File indexing completed on 2026-04-09 07:48:54
0001 #include <iostream>
0002 #include <iomanip>
0003 #include <cstring>
0004 #include <array>
0005
0006
0007
0008
0009 #include "SStr.hh"
0010 #include "ssys.h"
0011 #include "NP.hh"
0012 #include "SLOG.hh"
0013
0014 #include "scuda.h"
0015 #include "CSGFoundry.h"
0016 #include "CSGMaker.h"
0017 #include "CSGPrim.h"
0018
0019 #include "DemoGeo.h"
0020 #include "DemoGrid.h"
0021
0022 DemoGeo::DemoGeo(CSGFoundry* foundry_, const char* geom)
0023 :
0024 foundry(foundry_),
0025 maker(foundry->maker)
0026 {
0027 init(geom);
0028 }
0029
0030 void DemoGeo::init(const char* geom)
0031 {
0032 LOG(info) << "[" ;
0033
0034 float outer = ssys::getenvint("OUTER", 100.f ) ;
0035 int layers = ssys::getenvint("LAYERS", 1) ;
0036 int numgas = ssys::getenvint("NUMGAS", 1) ;
0037
0038 LOG(info) << " geom " << geom << " layers " << layers ;
0039
0040 if(strcmp(geom, "sphere_containing_grid_of_spheres") == 0)
0041 {
0042 init_sphere_containing_grid_of_spheres(layers );
0043 }
0044 else if(strcmp(geom, "parade") == 0)
0045 {
0046 init_parade();
0047 }
0048 else if(SStr::StartsWith(geom, "clustered_"))
0049 {
0050 init_clustered( geom + strlen("clustered_"));
0051 }
0052 else if(SStr::StartsWith(geom, "scaled_"))
0053 {
0054 init_scaled( geom, geom + strlen("scaled_"), outer, layers, numgas );
0055 }
0056 else if(SStr::StartsWith(geom, "layered_"))
0057 {
0058 init_layered( geom + strlen("layered_"), outer, layers );
0059 }
0060 else
0061 {
0062 init_maker(geom);
0063 }
0064
0065 LOG(info) << "]" ;
0066 }
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 void DemoGeo::init_sphere_containing_grid_of_spheres(unsigned layers )
0079 {
0080 LOG(info) << "layers " << layers ;
0081 maker->makeDemoSolids();
0082 unsigned num_solid = foundry->getNumSolid() ;
0083
0084 unsigned ias_idx = 0 ;
0085 const float4 ce = DemoGrid::AddInstances(foundry, ias_idx, num_solid) ;
0086
0087 float big_radius = float(ce.w)*sqrtf(3.f) ;
0088 LOG(info) << " big_radius " << big_radius ;
0089
0090
0091 maker->makeLayered("sphere", 0.7f, layers );
0092 maker->makeLayered("sphere", 1.0f, layers );
0093 maker->makeLayered("sphere", big_radius, 1 );
0094 }
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 void DemoGeo::init_parade()
0110 {
0111 LOG(info) << "[" ;
0112
0113 maker->makeDemoSolids();
0114 unsigned num_solid = foundry->getNumSolid() ;
0115
0116 unsigned ias_idx = 0 ;
0117 DemoGrid::AddInstances( foundry, ias_idx, num_solid );
0118
0119 LOG(info) << "]" ;
0120 }
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132 void DemoGeo::init_clustered(const char* name)
0133 {
0134 float unit = ssys::getenvfloat("CLUSTERUNIT", 200.f );
0135 const char* clusterspec = ssys::getenvvar("CLUSTERSPEC","-1:2:1,-1:2:1,-1:2:1") ;
0136
0137 LOG(info)
0138 << " name " << name
0139 << " clusterspec " << clusterspec
0140 << " unit " << unit
0141 ;
0142
0143 bool inbox = false ;
0144 std::array<int,9> cl ;
0145 SStr::ParseGridSpec(cl, clusterspec);
0146 CSGSolid* so = maker->makeClustered(name, cl[0],cl[1],cl[2],cl[3],cl[4],cl[5],cl[6],cl[7],cl[8], unit, inbox );
0147 std::cout << "DemoGeo::init_layered" << name << " so.center_extent " << so->center_extent << std::endl ;
0148
0149 unsigned gas_idx = 0 ;
0150 addInstance(gas_idx);
0151 }
0152
0153
0154
0155 void DemoGeo::init_scaled(const char* solid_label_base, const char* demo_node_type, float outer, unsigned layers, unsigned num_gas )
0156 {
0157 for(unsigned gas_idx=0 ; gas_idx < num_gas ; gas_idx++)
0158 {
0159 std::string label = CSGSolid::MakeLabel( solid_label_base, gas_idx );
0160
0161 CSGSolid* so = maker->makeScaled(label.c_str(), demo_node_type, outer, layers );
0162 LOG(info)
0163 << " gas_idx " << gas_idx
0164 << " label " << label
0165 << " demo_node_type " << demo_node_type
0166 << " so.center_extent " << so->center_extent
0167 << " num_gas " << num_gas
0168 ;
0169
0170 float4 ce = so->center_extent ;
0171
0172 float tx = 0.f ;
0173 float ty = 3.f*ce.w*gas_idx ;
0174 float tz = 0.f ;
0175
0176 addInstance(gas_idx, tx, ty, tz);
0177 }
0178 }
0179
0180 void DemoGeo::init_layered(const char* name, float outer, unsigned layers)
0181 {
0182 CSGSolid* so = maker->makeLayered(name, outer, layers );
0183 LOG(info) << " name " << name << " so.center_extent " << so->center_extent ;
0184
0185 unsigned gas_idx = 0 ;
0186 addInstance(gas_idx);
0187 }
0188
0189 void DemoGeo::init_maker(const char* name)
0190 {
0191 CSGSolid* so = maker->make(name) ;
0192 LOG(info) << " name " << name << " so.center_extent " << so->center_extent ;
0193
0194 unsigned gas_idx = 0 ;
0195 addInstance(gas_idx);
0196 }
0197
0198 void DemoGeo::addInstance(unsigned gas_idx, float tx, float ty, float tz)
0199 {
0200 unsigned ins_idx = foundry->inst.size() ;
0201 unsigned sensor_identifier = 0 ;
0202 unsigned sensor_index = 0 ;
0203
0204 qat4 q ;
0205 q.setIdentity( ins_idx, gas_idx, sensor_identifier, sensor_index );
0206
0207 q.q3.f.x = tx ;
0208 q.q3.f.y = ty ;
0209 q.q3.f.z = tz ;
0210
0211 foundry->inst.push_back( q );
0212 }
0213
0214 std::string DemoGeo::desc() const
0215 {
0216 std::stringstream ss ;
0217 ss << "DemoGeo " ;
0218 std::string s = ss.str();
0219 return s ;
0220 }
0221