File indexing completed on 2026-04-09 07:49:30
0001 #pragma once
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <string>
0012 #include <sstream>
0013 #include <iomanip>
0014
0015 #include <glm/glm.hpp>
0016 #include "glm/gtx/string_cast.hpp"
0017 #include <glm/gtx/transform.hpp>
0018 #include <glm/gtc/type_ptr.hpp>
0019
0020 #include "s_pool.h"
0021
0022 struct _s_tv
0023 {
0024 static constexpr const char* ITEM = "2,4,4" ;
0025
0026 glm::tmat4x4<double> t ;
0027 glm::tmat4x4<double> v ;
0028 };
0029
0030 #include "SYSRAP_API_EXPORT.hh"
0031
0032 struct SYSRAP_API s_tv
0033 {
0034 static constexpr const bool LEAK = false ;
0035 static constexpr const char* NAME = "s_tv.npy" ;
0036
0037 typedef s_pool<s_tv,_s_tv> POOL ;
0038 static POOL* pool ;
0039 static void SetPOOL( POOL* pool_ );
0040 static int level() ;
0041 static void Serialize( _s_tv& p, const s_tv* o );
0042 static s_tv* Import( const _s_tv* p, const std::vector<_s_tv>& buf );
0043
0044 s_tv();
0045 ~s_tv();
0046 s_tv* copy() const ;
0047
0048 int pid ;
0049 glm::tmat4x4<double> t ;
0050 glm::tmat4x4<double> v ;
0051
0052 bool is_root() const { return true ; }
0053 std::string desc_full0() const ;
0054 std::string desc_full() const ;
0055 std::string desc() const ;
0056
0057 static std::string DescTranslate(const glm::tmat4x4<double>& tr);
0058 static std::string DescOffset4(const glm::tmat4x4<double>& tr, unsigned offset );
0059 static std::string Desc(const glm::tmat4x4<double>& tr);
0060 static std::string Desc(const glm::tvec4<double>& t);
0061 static std::string Desc(const double* tt, int num);
0062
0063
0064
0065 };
0066
0067 inline void s_tv::SetPOOL( POOL* pool_ ){ pool = pool_ ; }
0068 inline int s_tv::level() { return pool ? pool->level : ssys::getenvint("sn__level",-1) ; }
0069
0070 inline void s_tv::Serialize( _s_tv& p, const s_tv* o )
0071 {
0072 p.t = o->t ;
0073 p.v = o->v ;
0074 }
0075 inline s_tv* s_tv::Import( const _s_tv* p, const std::vector<_s_tv>& )
0076 {
0077 s_tv* o = new s_tv ;
0078 o->t = p->t ;
0079 o->v = p->v ;
0080 return o ;
0081 }
0082
0083
0084 inline s_tv::s_tv()
0085 :
0086 pid(pool ? pool->add(this) : -1),
0087 t(1.),
0088 v(1.)
0089 {
0090 if(level() > 1) std::cerr << "s_tv::s_tv pid " << pid << std::endl ;
0091 }
0092 inline s_tv::~s_tv()
0093 {
0094 if(level() > 1) std::cerr << "s_tv::~s_tv pid " << pid << std::endl ;
0095 if(pool) pool->remove(this);
0096 }
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107 inline s_tv* s_tv::copy() const
0108 {
0109 s_tv* n = new s_tv ;
0110 n->t = t ;
0111 n->v = v ;
0112 return n ;
0113 }
0114
0115
0116 inline std::string s_tv::desc_full0() const
0117 {
0118 std::stringstream ss ;
0119 ss
0120 << "t " << glm::to_string(t)
0121 << std::endl
0122 << "v " << glm::to_string(v)
0123 << std::endl
0124 ;
0125 std::string str = ss.str();
0126 return str ;
0127 }
0128
0129
0130 inline std::string s_tv::desc_full() const
0131 {
0132 glm::tmat4x4<double> tv = t*v ;
0133
0134 const char* al = "t" ;
0135 const char* bl = "v" ;
0136 const char* cl = "tv" ;
0137
0138 const double* aa = glm::value_ptr(t);
0139 const double* bb = glm::value_ptr(v);
0140 const double* cc = glm::value_ptr(tv);
0141
0142 std::stringstream ss ;
0143 ss << "\n" ;
0144
0145 if(al) ss << " " << std::setw(54) << std::left << al ;
0146 if(bl) ss << " " << std::setw(54) << std::left << bl ;
0147 if(cl) ss << " " << std::setw(54) << std::left << cl ;
0148
0149 for(int i=0 ; i < 4 ; i++)
0150 {
0151 ss << "\n" ;
0152 if(aa) for(int j=0 ; j < 4 ; j++) ss << " " << std::fixed << std::setw(10) << std::setprecision(4) << aa[i*4+j] ;
0153 ss << " " << std::setw(10) << " " ;
0154 if(bb) for(int j=0 ; j < 4 ; j++) ss << " " << std::fixed << std::setw(10) << std::setprecision(4) << bb[i*4+j] ;
0155 ss << " " << std::setw(10) << " " ;
0156 if(cc) for(int j=0 ; j < 4 ; j++) ss << " " << std::fixed << std::setw(10) << std::setprecision(4) << cc[i*4+j] ;
0157 }
0158 ss << "\n" ;
0159
0160 glm::tvec4<double> mn = {-100,-100,-100, 1} ;
0161 glm::tvec4<double> mx = { 100, 100, 100, 1} ;
0162
0163 glm::tvec4<double> t_mn = t * mn ;
0164 glm::tvec4<double> t_mx = t * mx ;
0165
0166 const double* _mn = glm::value_ptr(mn);
0167 const double* _mx = glm::value_ptr(mx);
0168 const double* _t_mn = glm::value_ptr(t_mn);
0169 const double* _t_mx = glm::value_ptr(t_mx);
0170
0171 ss << " mn " ;
0172 for(int j=0 ; j < 4 ; j++) ss << " " << std::fixed << std::setw(12) << std::setprecision(4) << _mn[j] ;
0173 ss << "\n" ;
0174
0175 ss << " mx " ;
0176 for(int j=0 ; j < 4 ; j++) ss << " " << std::fixed << std::setw(12) << std::setprecision(4) << _mx[j] ;
0177 ss << "\n" ;
0178
0179 ss << " t_mn " ;
0180 for(int j=0 ; j < 4 ; j++) ss << " " << std::fixed << std::setw(12) << std::setprecision(4) << _t_mn[j] ;
0181 ss << "\n" ;
0182
0183 ss << " t_mx " ;
0184 for(int j=0 ; j < 4 ; j++) ss << " " << std::fixed << std::setw(12) << std::setprecision(4) << _t_mx[j] ;
0185 ss << "\n" ;
0186
0187 std::string str = ss.str();
0188 return str ;
0189 }
0190
0191
0192
0193 inline std::string s_tv::desc() const
0194 {
0195 std::stringstream ss ;
0196 ss
0197 << " t " << DescTranslate(t)
0198 << " v " << DescTranslate(v)
0199 ;
0200 std::string str = ss.str();
0201 return str ;
0202 }
0203
0204
0205 inline std::string s_tv::DescTranslate(const glm::tmat4x4<double>& tr )
0206 {
0207 return DescOffset4(tr, 12);
0208 }
0209 inline std::string s_tv::DescOffset4(const glm::tmat4x4<double>& tr, unsigned offset )
0210 {
0211 const double* tt = glm::value_ptr(tr) ;
0212 return Desc(tt + offset, 4 );
0213 }
0214 inline std::string s_tv::Desc(const glm::tmat4x4<double>& tr)
0215 {
0216 const double* tt = glm::value_ptr(tr);
0217 return Desc(tt, 16 );
0218 }
0219 inline std::string s_tv::Desc(const glm::tvec4<double>& t)
0220 {
0221 const double* tt = glm::value_ptr(t);
0222 return Desc(tt, 4 );
0223 }
0224 inline std::string s_tv::Desc(const double* tt, int num)
0225 {
0226 std::stringstream ss ;
0227 for(int i=0 ; i < num ; i++)
0228 ss
0229 << ( i % 4 == 0 && num > 4 ? ".\n" : "" )
0230 << " " << std::fixed << std::setw(10) << std::setprecision(4) << tt[i]
0231 << ( i == num-1 && num > 4 ? ".\n" : "" )
0232 ;
0233
0234 std::string str = ss.str();
0235 return str ;
0236 }
0237
0238
0239
0240
0241
0242