File indexing completed on 2026-04-09 07:48:58
0001 #ifdef DEBUG_RECORD
0002
0003 #include <sstream>
0004 #include <string>
0005
0006 #include "SSys.hh"
0007 #include "NP.hh"
0008 #include "SLOG.hh"
0009 #include "scuda.h"
0010 #include "squad.h"
0011
0012 #include "sc4u.h"
0013 #include "sbibit.h"
0014 #include "sbit_.h"
0015
0016 #include "OpticksCSG.h"
0017 #include "csg_classify.h"
0018
0019 #include "CSGRecord.h"
0020
0021 std::vector<quad6> CSGRecord::record = {} ;
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 CSGRecord::CSGRecord( const quad6& r_ )
0033 :
0034 r(r_),
0035 typecode(CSG_ZERO),
0036 l_state(State_Miss),
0037 r_state(State_Miss),
0038 leftIsCloser(false),
0039 l_promote_miss(false),
0040 l_complement(false),
0041 l_unbounded(false),
0042 l_false(false),
0043 r_promote_miss(false),
0044 r_complement(false),
0045 r_unbounded(false),
0046 r_false(false),
0047 tloop(0),
0048 nodeIdx(0),
0049 ctrl(0),
0050 tmin(0.f),
0051 t_min(0.f),
0052 tminAdvanced(0.f)
0053 {
0054 unpack(r.q2.u.x);
0055
0056 ctrl = r.q2.u.y ;
0057
0058 tmin = r.q3.f.x ;
0059 t_min = r.q3.f.y ;
0060 tminAdvanced = r.q3.f.z ;
0061 }
0062
0063 void CSGRecord::unpack(unsigned packed )
0064 {
0065 U4U uu ;
0066 uu.u = packed ;
0067
0068 typecode = sbibit_UNPACK4_0( uu.u4.x );
0069 l_state = (IntersectionState_t)sbibit_UNPACK4_1( uu.u4.x );
0070 r_state = (IntersectionState_t)sbibit_UNPACK4_2( uu.u4.x );
0071 leftIsCloser = sbibit_UNPACK4_3( uu.u4.x );
0072
0073 l_promote_miss = sbit_rUNPACK8_0( uu.u4.y );
0074 l_complement = sbit_rUNPACK8_1( uu.u4.y );
0075 l_unbounded = sbit_rUNPACK8_2( uu.u4.y );
0076 l_false = sbit_rUNPACK8_3( uu.u4.y );
0077
0078 r_promote_miss = sbit_rUNPACK8_4( uu.u4.y );
0079 r_complement = sbit_rUNPACK8_5( uu.u4.y );
0080 r_unbounded = sbit_rUNPACK8_6( uu.u4.y );
0081 r_false = sbit_rUNPACK8_7( uu.u4.y );
0082
0083 assert( l_false == false );
0084 assert( r_false == false );
0085
0086 tloop = uu.u4.z ;
0087 nodeIdx = uu.u4.w ;
0088 }
0089
0090
0091 bool CSGRecord::ENABLED = SSys::getenvbool("CSGRecord_ENABLED") ;
0092 void CSGRecord::SetEnabled(bool enabled)
0093 {
0094 ENABLED = enabled ;
0095 }
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132 void CSGRecord::Dump(const char* msg)
0133 {
0134 LOG(info) << msg << " CSGRecord::record.size " << record.size() << "IsEnabled " << ENABLED ;
0135 for(unsigned i=0 ; i < record.size() ; i++) std::cout << Desc(record[i], i, "rec");
0136 }
0137
0138 std::string CSGRecord::Desc(const quad6& r, unsigned irec, const char* label )
0139 {
0140 CSGRecord rec(r);
0141 return rec.desc(irec, label);
0142 }
0143
0144 std::string CSGRecord::desc(unsigned irec, const char* label ) const
0145 {
0146 std::stringstream ss ;
0147 ss
0148 << " tloop " << std::setw(4) << tloop
0149 << " nodeIdx " << std::setw(4) << nodeIdx
0150 << " irec " << std::setw(10) << irec << " label " << std::setw(90) << label << " " << CSG::Name(typecode)
0151 << std::endl
0152 << std::setw(30) << " r.q0.f left "
0153 << "("
0154 << std::setw(10) << std::fixed << std::setprecision(4) << r.q0.f.x
0155 << std::setw(10) << std::fixed << std::setprecision(4) << r.q0.f.y
0156 << std::setw(10) << std::fixed << std::setprecision(4) << r.q0.f.z
0157 << std::setw(10) << std::fixed << std::setprecision(4) << r.q0.f.w
0158 << ") "
0159 << IntersectionState::Name(l_state)
0160 << " "
0161 << " " << ( l_promote_miss ? "l_promote_miss" : "-" )
0162 << " " << ( l_complement ? "l_complement" : "-" )
0163 << " " << ( l_unbounded ? "l_unbounded" : "-" )
0164 << " "
0165 << ( leftIsCloser ? "leftIsCloser" : " " )
0166 << std::endl
0167 << std::setw(30) << " r.q1.f right "
0168 << "("
0169 << std::setw(10) << std::fixed << std::setprecision(4) << r.q1.f.x
0170 << std::setw(10) << std::fixed << std::setprecision(4) << r.q1.f.y
0171 << std::setw(10) << std::fixed << std::setprecision(4) << r.q1.f.z
0172 << std::setw(10) << std::fixed << std::setprecision(4) << r.q1.f.w
0173 << ") "
0174 << IntersectionState::Name(r_state)
0175 << " "
0176 << " " << ( r_promote_miss ? "r_promote_miss" : "-" )
0177 << " " << ( r_complement ? "r_complement" : "-" )
0178 << " " << ( r_unbounded ? "r_unbounded" : "-" )
0179 << " "
0180 << ( leftIsCloser ? " " : "rightIsCloser" )
0181 << " ctrl " << CTRL::Name(ctrl)
0182 << std::endl
0183 << std::setw(30) << " r.q3.f tmin/t_min "
0184 << "("
0185 << std::setw(10) << std::fixed << std::setprecision(4) << r.q3.f.x
0186 << std::setw(10) << std::fixed << std::setprecision(4) << r.q3.f.y
0187 << std::setw(10) << std::fixed << std::setprecision(4) << r.q3.f.z
0188 << std::setw(10) << std::fixed << std::setprecision(4) << r.q3.f.w
0189 << ") "
0190 << " tmin "
0191 << std::setw(10) << std::fixed << std::setprecision(4) << tmin
0192 << " t_min "
0193 << std::setw(10) << std::fixed << std::setprecision(4) << t_min
0194 << " tminAdvanced "
0195 << std::setw(10) << std::fixed << std::setprecision(4) << tminAdvanced
0196 << std::endl
0197 << std::setw(30) << " r.q4.f result "
0198 << "("
0199 << std::setw(10) << std::fixed << std::setprecision(4) << r.q4.f.x
0200 << std::setw(10) << std::fixed << std::setprecision(4) << r.q4.f.y
0201 << std::setw(10) << std::fixed << std::setprecision(4) << r.q4.f.z
0202 << std::setw(10) << std::fixed << std::setprecision(4) << r.q4.f.w
0203 << ") "
0204 << std::endl
0205 ;
0206
0207 std::string s = ss.str() ;
0208 return s ;
0209 }
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240 void CSGRecord::Clear()
0241 {
0242 record.clear();
0243 }
0244 void CSGRecord::Save(const char* dir)
0245 {
0246 unsigned num_record = record.size() ;
0247 LOG(info) << " dir " << dir << " num_record " << num_record ;
0248
0249 if( num_record > 0)
0250 {
0251 NP::Write<float>(dir, "CSGRecord.npy", (float*)record.data(), num_record, 6, 4 );
0252 }
0253 else
0254 {
0255 LOG(error) << "not writing as no records" ;
0256 }
0257 }
0258
0259 #endif