Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:53

0001 // ./CSGNodeTest.sh 
0002 
0003 #include <csignal>
0004 #include <bitset>
0005 #include <vector>
0006 #include <iomanip>
0007 #include <iostream>
0008 #include <glm/glm.hpp>
0009 #include <glm/gtc/type_ptr.hpp>
0010 #include "scuda.h"
0011 #include "CSGNode.h"
0012 #include "Sys.h"
0013 
0014 #include "SBitSet.h"
0015 #include "CSGFoundry.h"
0016 #include "CSGCopy.h"
0017 
0018 #include "OPTICKS_LOG.hh"
0019 
0020 void test_copy()
0021 {
0022     LOG(info); 
0023     glm::mat4 m0(1.f); 
0024     glm::mat4 m1(2.f); 
0025     glm::mat4 m2(3.f); 
0026 
0027     m0[0][3] = Sys::int_as_float(42); 
0028     m1[0][3] = Sys::int_as_float(52); 
0029     m2[0][3] = Sys::int_as_float(62); 
0030 
0031     std::vector<glm::mat4> node ; 
0032     node.push_back(m0); 
0033     node.push_back(m1); 
0034     node.push_back(m2); 
0035 
0036     std::vector<CSGNode> node_(3) ; 
0037 
0038     memcpy( node_.data(), node.data(), sizeof(CSGNode)*node_.size() );  
0039 
0040     CSGNode* n_ = node_.data(); 
0041     CSGNode::Dump( n_, node_.size(), "CSGNodeTest" );  
0042 }
0043 
0044 void test_zero()
0045 {
0046     LOG(info); 
0047 
0048     CSGNode nd = {} ; 
0049     assert( nd.gtransformIdx() == 0u );  
0050     assert( nd.is_complement() == false );  
0051 
0052     unsigned tr = 42u ; 
0053     nd.setTransform( tr ); 
0054 
0055     assert( nd.gtransformIdx() == tr ); 
0056     assert( nd.is_complement() == false ); 
0057 
0058     nd.setComplement(true); 
0059     assert( nd.gtransformIdx() == tr ); 
0060     assert( nd.is_complement() == true ); 
0061 
0062     LOG(info) << nd.desc() ; 
0063 }
0064 
0065 void test_sphere()
0066 {
0067     LOG(info); 
0068     CSGNode nd = CSGNode::Sphere(100.f); 
0069     LOG(info) << nd.desc() ; 
0070 }
0071 
0072 void test_change_transform()
0073 {
0074     LOG(info); 
0075 
0076     CSGNode nd = {} ; 
0077     std::vector<unsigned> uu = {1001, 100, 10, 5, 6, 0, 20, 101, 206 } ; 
0078  
0079     // checking changing the transform whilst preserving the complement 
0080 
0081     for(int i=0 ; i < int(uu.size()-1) ; i++)
0082     {
0083         const unsigned& u0 = uu[i] ;  
0084         const unsigned& u1 = uu[i+1] ;  
0085 
0086         nd.setComplement( u0 % 2 == 0 ); 
0087         nd.setTransform(u0);   
0088 
0089         bool c0 = nd.is_complement(); 
0090 
0091         // nd.zeroTransformComplement();   <-- this is cheating, needs to work without it 
0092 
0093         nd.setComplement(c0) ; 
0094         nd.setTransform( u1 );   
0095 
0096         bool c1 = nd.is_complement(); 
0097         bool c_expect = c0 == c1 ; 
0098         assert( c_expect ); 
0099         if(!c_expect) std::raise(SIGINT); 
0100 
0101         unsigned u1_chk = nd.gtransformIdx();  
0102         bool u1_expect = u1_chk == u1 ;
0103         assert( u1_expect ); 
0104         if(!u1_expect) std::raise(SIGINT); 
0105 
0106     }
0107 }
0108 
0109 void test_Depth()
0110 {
0111     //LOG(info); 
0112     for(unsigned i=0 ; i < 32 ; i++)
0113     {
0114         unsigned partIdxRel = i ; 
0115         unsigned depth = CSGNode::Depth(partIdxRel) ; 
0116         unsigned levelIdx = partIdxRel + 1 ; 
0117 
0118         std::cout 
0119             << " partIdxRel " << std::setw(4) << partIdxRel 
0120             << " partIdxRel+1 (dec) " << std::setw(4) << levelIdx  
0121             << " (bin) " <<  std::bitset<32>(levelIdx)
0122             << " depth " << std::setw(4) << depth
0123             << std::endl 
0124             ;
0125     }
0126 }
0127 
0128 
0129 
0130 void test_Load()
0131 {
0132     CSGFoundry* fd = CSGFoundry::Load(); 
0133     LOG(info) << fd->desc() ;     
0134 }
0135 
0136 
0137 int main(int argc, char** argv)
0138 {
0139     OPTICKS_LOG(argc, argv);  
0140 
0141     /*
0142     test_zero(); 
0143     test_sphere(); 
0144     test_copy();  
0145     test_Depth();  
0146     test_Load(); 
0147 
0148     */
0149 
0150     test_change_transform();  
0151 
0152 
0153 
0154     return 0 ; 
0155 }