File indexing completed on 2026-04-09 07:48:53
0001
0002 #include <iostream>
0003 #include <csignal>
0004
0005 #include "OPTICKS_LOG.hh"
0006 #include "scuda.h"
0007 #include "CSGSolid.h"
0008 #include "NP.hh"
0009
0010 void test_Make_Write(const char* path)
0011 {
0012 LOG(info) << path ;
0013
0014 CSGSolid r = CSGSolid::Make("red" , 1, 0 ) ; r.center_extent = {1.f, 1.f, 1.f, 1.f } ;
0015 CSGSolid g = CSGSolid::Make("green", 1, 1 ) ; g.center_extent = {2.f, 2.f, 2.f, 2.f } ;
0016 CSGSolid b = CSGSolid::Make("blue", 1, 2 ) ; b.center_extent = {2.f, 2.f, 2.f, 2.f } ;
0017 CSGSolid c = CSGSolid::Make("cyan", 1, 3 ) ; c.center_extent = {3.f, 3.f, 3.f, 3.f } ;
0018 CSGSolid m = CSGSolid::Make("magenta", 1, 4 ) ; m.center_extent = {4.f, 4.f, 4.f, 4.f } ;
0019 CSGSolid y = CSGSolid::Make("yellow", 1, 5 ) ; y.center_extent = {5.f, 5.f, 5.f, 5.f } ;
0020
0021 std::vector<CSGSolid> so ;
0022
0023 so.push_back(r);
0024 so.push_back(g);
0025 so.push_back(b);
0026 so.push_back(c);
0027 so.push_back(m);
0028 so.push_back(y);
0029
0030 for(int i=0 ; i < int(so.size()); i++) std::cout << so[i].desc() << std::endl ;
0031
0032
0033 std::cout << "sizeof(CSGSolid)" << sizeof(CSGSolid) << std::endl ;
0034 assert( sizeof(float) == sizeof(int));
0035
0036 unsigned num_quad = 3 ;
0037 assert( sizeof(CSGSolid) == num_quad*4*sizeof(float) );
0038 unsigned num_items = so.size();
0039 assert( num_items == 6 );
0040 unsigned num_values = sizeof(CSGSolid)/sizeof(int) ;
0041
0042 bool num_values_expect = num_values == num_quad*4 ;
0043 assert( num_values_expect );
0044 if(!num_values_expect) std::raise(SIGINT);
0045
0046 NP::Write( path, (int*)so.data(), num_items, num_values ) ;
0047 }
0048
0049 void test_labelMatch()
0050 {
0051 LOG(info);
0052
0053 CSGSolid r = CSGSolid::Make("red" , 1, 0 ) ; r.center_extent = {1.f, 1.f, 1.f, 1.f } ;
0054
0055 bool match_red = r.labelMatch("red") ;
0056 bool match_green = r.labelMatch("green") ;
0057
0058 std::cout << " r.label " << r.label << std::endl ;
0059 std::cout << " r.label " << r.label << " match_red " << match_red << std::endl ;
0060 std::cout << " r.label " << r.label << " match_green " << match_green << std::endl ;
0061 }
0062
0063 void test_ParseLabel()
0064 {
0065 LOG(info);
0066
0067 char t0 = 'r' ;
0068 unsigned idx0 = 8 ;
0069 std::string label = CSGSolid::MakeLabel(t0, idx0);
0070
0071 char t1 ;
0072 unsigned idx1 ;
0073 int rc = CSGSolid::ParseLabel(label.c_str(), t1, idx1 );
0074 assert( rc == 0 );
0075 if(rc!=0) std::raise(SIGINT);
0076
0077 assert( t0 == t1 );
0078 assert( idx0 == idx1 );
0079 }
0080
0081 void test_get_ridx()
0082 {
0083 LOG(info);
0084
0085 char t0 = 'r' ;
0086 unsigned idx0 = 8 ;
0087 std::string label = CSGSolid::MakeLabel(t0, idx0);
0088
0089 unsigned numPrim = 1 ;
0090 unsigned primOffset = 0 ;
0091 CSGSolid so = CSGSolid::Make(label.c_str(), numPrim, primOffset );
0092
0093 bool ridx_expect = so.get_ridx() == int(idx0) ;
0094 assert(ridx_expect );
0095 if(!ridx_expect) std::raise(SIGINT);
0096 }
0097
0098
0099
0100 int main(int argc, char** argv)
0101 {
0102 OPTICKS_LOG(argc, argv);
0103
0104 const char* path = argc > 1 ? argv[1] : "$TMP/CSGSolidTest/CSGSolidTest.npy" ;
0105 test_Make_Write(path);
0106 test_labelMatch();
0107 test_ParseLabel();
0108 test_get_ridx();
0109
0110 return 0 ;
0111 }