File indexing completed on 2026-04-09 07:49:37
0001 #pragma once
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "NP.hh"
0011
0012 #include "spath.h"
0013 #include "scerenkov.h"
0014 #include "sstr.h"
0015 #include "scuda.h"
0016
0017 struct SGen
0018 {
0019 static constexpr const char* NAME = "genstep.npy" ;
0020 static constexpr const char* RPOS_SPEC = "4,GL_FLOAT,GL_FALSE,96,16,false";
0021 static constexpr const char* RDEL_SPEC = "4,GL_FLOAT,GL_FALSE,96,32,false";
0022 static constexpr const char* _level = "SGen__level" ;
0023
0024 int level ;
0025 NP* genstep ;
0026 int genstep_first ;
0027 int genstep_count ;
0028
0029 float4 mn = {} ;
0030 float4 mx = {} ;
0031 float4 ce = {} ;
0032
0033 static NP* LoadArray( const char* _fold, const char* _slice );
0034 static SGen* Load( const char* _fold, const char* _slice=nullptr );
0035
0036 SGen(NP* genstep);
0037 void init() ;
0038
0039 const float* get_mn() const ;
0040 const float* get_mx() const ;
0041 const float* get_ce() const ;
0042
0043 const float get_t0() const ;
0044 const float get_t1() const ;
0045
0046 std::string desc() const ;
0047 };
0048
0049
0050
0051
0052
0053
0054
0055
0056 inline NP* SGen::LoadArray(const char* _fold, const char* _slice )
0057 {
0058 const char* path = spath::Resolve(_fold, NAME);
0059
0060 bool looks_unresolved = spath::LooksUnresolved(path, _fold);
0061 if(looks_unresolved)
0062 {
0063 std::cout
0064 << "SGen::LoadArray"
0065 << " FAILED : DUE TO MISSING ENVVAR\n"
0066 << " _fold [" << ( _fold ? _fold : "-" ) << "]\n"
0067 << " path [" << ( path ? path : "-" ) << "]\n"
0068 << " looks_unresolved " << ( looks_unresolved ? "YES" : "NO " )
0069 << "\n"
0070 ;
0071 return nullptr ;
0072 }
0073
0074
0075 NP* a = nullptr ;
0076
0077 if( _slice == nullptr )
0078 {
0079 a = NP::Load(path);
0080 a->set_meta<std::string>("SGen__LoadArray", "NP::Load");
0081 }
0082 else if(NP::LooksLikeWhereSelection(_slice))
0083 {
0084 a = NP::LoadThenSlice<float>(path, _slice);
0085 a->set_meta<std::string>("SGen__LoadArray_METHOD", "NP::LoadThenSlice");
0086 a->set_meta<std::string>("SGen__LoadArray_SLICE", _slice );
0087 }
0088 else
0089 {
0090 a = NP::LoadSlice(path, _slice);
0091 a->set_meta<std::string>("SGen__LoadArray_METHOD", "NP::LoadSlice");
0092 a->set_meta<std::string>("SGen__LoadArray_SLICE", _slice );
0093 }
0094 return a ;
0095 }
0096
0097
0098 inline SGen* SGen::Load(const char* _fold, const char* _slice )
0099 {
0100 NP* _genstep = LoadArray(_fold, _slice);
0101 return _genstep ? new SGen(_genstep) : nullptr ;
0102 }
0103
0104
0105 inline SGen::SGen(NP* _genstep)
0106 :
0107 level(ssys::getenvint(_level,0)),
0108 genstep(_genstep),
0109 genstep_first(0),
0110 genstep_count(0)
0111 {
0112 init();
0113 }
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124 inline void SGen::init()
0125 {
0126 assert(genstep->shape.size() == 3);
0127 genstep_count = genstep->shape[0];
0128
0129
0130 scerenkov::MinMaxPost(&mn.x, &mx.x, genstep );
0131
0132 genstep->set_meta<float>("x0", mn.x );
0133 genstep->set_meta<float>("x1", mx.x );
0134
0135 genstep->set_meta<float>("y0", mn.y );
0136 genstep->set_meta<float>("y1", mx.y );
0137
0138 genstep->set_meta<float>("z0", mn.z );
0139 genstep->set_meta<float>("z1", mx.z );
0140
0141 genstep->set_meta<float>("t0", mn.w );
0142 genstep->set_meta<float>("t1", mx.w );
0143
0144 ce = scuda::center_extent( mn, mx );
0145
0146 genstep->set_meta<float>("cx", ce.x );
0147 genstep->set_meta<float>("cy", ce.y );
0148 genstep->set_meta<float>("cz", ce.z );
0149 genstep->set_meta<float>("ce", ce.w );
0150
0151 if(level > 0 ) std::cout
0152 << "[SGen::init\n"
0153 << desc()
0154 << "]SGen::init\n"
0155 ;
0156 }
0157
0158
0159
0160 inline const float* SGen::get_mn() const
0161 {
0162 return &mn.x ;
0163 }
0164 inline const float* SGen::get_mx() const
0165 {
0166 return &mx.x ;
0167 }
0168 inline const float* SGen::get_ce() const
0169 {
0170 return &ce.x ;
0171 }
0172
0173 inline const float SGen::get_t0() const
0174 {
0175 return mn.w ;
0176 }
0177 inline const float SGen::get_t1() const
0178 {
0179 return mx.w ;
0180 }
0181
0182
0183 inline std::string SGen::desc() const
0184 {
0185 const char* lpath = genstep ? genstep->lpath.c_str() : nullptr ;
0186
0187 std::stringstream ss ;
0188 ss
0189 << "[SGen.desc\n"
0190 << " [" << _level << "] level " << level << "\n"
0191 << " lpath [" << ( lpath ? lpath : "-" ) << "]\n"
0192 << std::setw(20) << " mn " << mn
0193 << std::endl
0194 << std::setw(20) << " mx " << mx
0195 << std::endl
0196 << std::setw(20) << " ce " << ce
0197 << std::endl
0198 << std::setw(20) << " genstep.sstr " << genstep->sstr()
0199 << std::endl
0200 << std::setw(20) << " genstep_first " << genstep_first
0201 << std::endl
0202 << std::setw(20) << " genstep_count " << genstep_count
0203 << std::endl
0204 << ( genstep ? genstep->descMeta() : "-" )
0205 << std::endl
0206 << "]SGen.desc\n"
0207 ;
0208 std::string str = ss.str() ;
0209 return str ;
0210 }
0211