Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /**
0002 CSGTargetTest
0003 ==============
0004 
0005 ::
0006 
0007     MOI=PMT_20inch:0:1 CSGTargetTest 
0008     MOI=Hama           CSGTargetTest 
0009     MOI=Hama:0:0       CSGTargetTest 
0010     MOI=Hama:0:1000    CSGTargetTest 
0011     MOI=104            CSGTargetTest
0012     MOI=105            CSGTargetTest
0013     MOI=sWorld         CSGTargetTest
0014     MOI=H              CSGTargetTest
0015     MOI=N              CSGTargetTest
0016     MOI=P              CSGTargetTest
0017     MOI=uni_acrylic3:0:100 CSGTargetTest 
0018 
0019 Check a few different iidx of midx 120::     
0020 
0021     MOI=120:0:0 CSGTargetTest 
0022     MOI=120:0:1 CSGTargetTest 
0023     MOI=120:0:2 CSGTargetTest 
0024 
0025 
0026 **/
0027 #include <csignal>
0028 #include "SSys.hh"
0029 #include "SStr.hh"
0030 #include "SSim.hh"
0031 
0032 #include "OPTICKS_LOG.hh"
0033 
0034 #include "scuda.h"
0035 #include "sqat4.h"
0036 #include "stran.h"
0037 #include "sframe.h"
0038 #include "CSGFoundry.h"
0039 
0040 
0041 struct CSGTargetTest
0042 {
0043     SSim*           sim ; 
0044     CSGFoundry*     fd ; 
0045     float4          ce ; 
0046 
0047     qat4 q0 ; 
0048     qat4 q1 ; 
0049 
0050     CSGTargetTest(); 
0051     void dumpMOI(const char* MOI); 
0052     void dumpALL(); 
0053 };
0054 
0055 
0056 CSGTargetTest::CSGTargetTest()
0057     :
0058     sim(SSim::Create()),
0059     fd(CSGFoundry::Load()),
0060     ce(make_float4( 0.f, 0.f, 0.f, 1000.f ))
0061 {
0062     //LOG(info) << fd->descBase() ; 
0063     //LOG(info) << fd->desc() ; 
0064     //fd->summary(); 
0065 
0066     q0.zero(); 
0067     q1.zero(); 
0068 }
0069 
0070 void CSGTargetTest::dumpMOI( const char* MOI )
0071 {
0072     std::vector<std::string> vmoi ; 
0073     SStr::Split(MOI, ',',  vmoi ); 
0074 
0075     LOG(info) << " MOI " << MOI << " vmoi.size " << vmoi.size() ; 
0076 
0077 
0078     for(unsigned pass=0 ; pass < 3 ; pass++)
0079     for(unsigned i=0 ; i < vmoi.size() ; i++)
0080     {
0081          const char* moi = vmoi[i].c_str() ; 
0082 
0083         int midx, mord, iidx ; 
0084         fd->parseMOI(midx, mord, iidx,  moi );  
0085 
0086         //std::cout << "------- after parseMOI " << std::endl ; 
0087 
0088         const char* name = midx > -1 ? fd->getName(midx) : nullptr ; 
0089 
0090         fd->getCenterExtent(ce, midx, mord, iidx, &q0 );  
0091         fd->getTransform(q1, midx, mord, iidx ); 
0092         bool q_match = qat4::compare(q0, q1, 0.f) == 0 ; 
0093         
0094 
0095         if( pass == 0 )
0096         {
0097             std::cout 
0098                 << " moi " << std::setw(15) << moi
0099                 << " midx " << std::setw(5) << midx 
0100                 << " mord " << std::setw(5) << mord 
0101                 << " iidx " << std::setw(6) << iidx
0102                 << " name " << std::setw(10) << ( name  ? name : "-" )
0103                 << std::endl 
0104                 ;
0105         } 
0106         else if( pass == 1 )
0107         {
0108             std::cout 
0109                 << " moi " << std::setw(15) << moi
0110                 << " ce " <<  ce 
0111                 << std::endl 
0112                 ;
0113         }
0114         else if( pass == 2 )
0115         {
0116             std::cout 
0117                 << " moi " << std::setw(15) << moi
0118                 << " q0 " << q0
0119                 << std::endl 
0120                 ;
0121         }
0122         assert( q_match ); 
0123         if(!q_match) std::raise(SIGINT); 
0124     }
0125 }
0126 
0127 void CSGTargetTest::dumpALL()
0128 {
0129     unsigned num_prim = fd->getNumPrim(); 
0130     LOG(info) 
0131          << " fd.getNumPrim " << num_prim 
0132          << " fd.meshname.size " << fd->meshname.size() 
0133          ; 
0134 
0135     for(unsigned primIdx=0 ; primIdx < num_prim ; primIdx++)
0136     {
0137         const CSGPrim* pr = fd->getPrim(primIdx); 
0138         unsigned meshIdx = pr->meshIdx();  
0139         float4 lce = pr->ce();
0140 
0141         std::cout 
0142             << " primIdx " << std::setw(4) << primIdx 
0143             << " lce ( "
0144             << " " << std::setw(10) << std::fixed << std::setprecision(2) << lce.x
0145             << " " << std::setw(10) << std::fixed << std::setprecision(2) << lce.y
0146             << " " << std::setw(10) << std::fixed << std::setprecision(2) << lce.z
0147             << " " << std::setw(10) << std::fixed << std::setprecision(2) << lce.w
0148             << " )" 
0149             << " lce.w/1000  "
0150             << " " << std::setw(10) << std::fixed << std::setprecision(2) << lce.w/1000.f
0151             << " meshIdx " << std::setw(4) << meshIdx 
0152             << " " << fd->meshname[meshIdx]
0153             << std::endl ; 
0154     }
0155 }
0156 
0157 
0158 
0159 
0160 
0161 int main(int argc, char** argv)
0162 {
0163     OPTICKS_LOG(argc, argv); 
0164 
0165     CSGTargetTest tt ; 
0166     CSGFoundry* fd = tt.fd ; 
0167 
0168     const char* METHOD = SSys::getenvvar("METHOD", "MOI"); 
0169 
0170     if( strcmp(METHOD, "MOI") == 0)
0171     {
0172         const char* MOI = SSys::getenvvar("MOI", nullptr ); 
0173         if(MOI) 
0174         {
0175             tt.dumpMOI(MOI); 
0176         }
0177         else
0178         {
0179             tt.dumpALL(); 
0180         }
0181     }
0182     else if( strcmp(METHOD, "descInst") == 0 )
0183     {
0184         unsigned ias_idx = 0 ; 
0185         unsigned long long emm = 0ull ;  
0186         std::cout << "fd.descInst" << std::endl << fd->descInst(ias_idx, emm) << std::endl ;          
0187     }
0188     else if( strcmp(METHOD, "descInstance") == 0 )
0189     {
0190         std::cout << fd->descInstance() ; // IDX=0,10,100 envvar           
0191     }
0192     else if( strcmp(METHOD, "getFrame") == 0 )
0193     {
0194         sframe fr = fd->getFrame() ;  // depends on MOI or its default -1  
0195         Tran<double>* tr = fr.getTransform(); 
0196         std::cout << tr->desc() << std::endl ; 
0197     }
0198 
0199 
0200     return 0 ; 
0201 }
0202 
0203 
0204