Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:22

0001 // ./stran_test.sh 
0002 
0003 #include "scuda.h"
0004 #include "sqat4.h"
0005 #include "stran.h"
0006 #include "sphoton.h"
0007 
0008 
0009 void test_from_string()
0010 {
0011     const char* a_str = "(-0.585,-0.805, 0.098, 0.000) (-0.809, 0.588, 0.000, 0.000) (-0.057,-0.079,-0.995, 0.000) (1022.116,1406.822,17734.953, 1.000)"  ;
0012     //const char* a_str = "( 0.5, 0.0, 0.0, 0.0 ) ( 0.0, 0.5, 0.0, 0.0) ( 0.0, 0.0, 0.5, 0.000) (1000.0, 1000.0,1000.0, 1.000)"  ;
0013 
0014     qat4* a = qat4::from_string(a_str); 
0015 
0016     int id0[4] ;
0017     id0[0] = 1 ; 
0018     id0[1] = 10 ; 
0019     id0[2] = 100 ; 
0020     id0[3] = 1000 ; 
0021 
0022     a->setIdentity( id0[0], id0[1], id0[2], id0[3] );
0023 
0024     const qat4* i = Tran<double>::Invert( a ); 
0025 
0026     int id1[4] ; 
0027     i->getIdentity( id1[0], id1[1], id1[2], id1[3] ); 
0028 
0029 
0030     assert( id0[0] == id1[0] ); 
0031     assert( id0[1] == id1[1] ); 
0032     assert( id0[2] == id1[2] ); 
0033     assert( id0[3] == id1[3] ); 
0034 
0035     Tran<double>* chk = Tran<double>::FromPair( a, i, 1e-3 ); 
0036 
0037     std::cout << chk->desc() << std::endl ; 
0038 }
0039 
0040 
0041 void test_Translate()
0042 {
0043     glm::tvec3<double> tlate(1., 2., 3.);  
0044     glm::tmat4x4<double> tr = stra<double>::Translate( tlate ); 
0045     std::cout << stra<double>::Desc(tr) << std::endl ;    
0046 }
0047 
0048 
0049 void test_MakeRotateA2B()
0050 {
0051     glm::tvec3<double> a_(1., 0., 0.);
0052     glm::tvec3<double> b_(1., 1., 0.) ;
0053 
0054     glm::tvec3<double> a = glm::normalize(a_); 
0055     glm::tvec3<double> b = glm::normalize(b_); 
0056 
0057     std::cout << " a " << stra<double>::Desc(a) << std::endl ;    
0058     std::cout << " b " << stra<double>::Desc(b) << std::endl ;    
0059 
0060     glm::tmat4x4<double> tr0 = stra<double>::RotateA2B(a, b, false ); 
0061     std::cout << " stra<double>::Rotate(a,b,false) " << std::endl << stra<double>::Desc(tr0) << std::endl ;    
0062 
0063     glm::tmat4x4<double> tr1 = stra<double>::RotateA2B(a, b, true ); 
0064     std::cout << " stra<double>::Rotate(a,b,true) " << std::endl << stra<double>::Desc(tr1) << std::endl ;    
0065 
0066     glm::tvec4<double> a4(a, 0.); 
0067     glm::tvec4<double> b4(b, 0.); 
0068 
0069     std::cout << std::setw(20) << " a4 " << stra<double>::Desc(a4) << std::endl ;    
0070     std::cout << std::setw(20) << " b4 " << stra<double>::Desc(b4) << std::endl ;    
0071 
0072     glm::tvec4<double> tr0_a4 = tr0 * a4 ; 
0073     glm::tvec4<double> tr1_a4 = tr1 * a4 ; 
0074 
0075     glm::tvec4<double> a4_tr0 = a4 * tr0 ; 
0076     glm::tvec4<double> a4_tr1 = a4 * tr1 ; 
0077 
0078 
0079     std::cout << std::setw(20) << " tr0_a4 " << stra<double>::Desc(tr0_a4) << std::endl ;    
0080     std::cout << std::setw(20) << " tr1_a4 " << stra<double>::Desc(tr1_a4) << " (this matches b4) " << std::endl ;    
0081 
0082     std::cout << std::setw(20) << " a4_tr0 " << stra<double>::Desc(a4_tr0) << " (this matches b4) " << std::endl ;    
0083     std::cout << std::setw(20) << " a4_tr1 " << stra<double>::Desc(a4_tr1) << std::endl ;    
0084 }
0085 
0086 /**
0087  
0088 Place transform is intended to rotate and then translate 
0089 The rotation comes from RotateA2B where a and b are normalized vectors. 
0090 
0091 
0092              "(1,1)"
0093               /
0094            b /
0095             /
0096            /
0097           +-------->
0098                a
0099 **/
0100 
0101 void test_Place()
0102 {
0103     glm::tvec3<double> a_(1., 0., 0.);
0104     glm::tvec3<double> b_(1., 1., 0.) ;
0105     glm::tvec3<double> c( 1., 2., 3.) ;
0106 
0107     glm::tvec3<double> a = glm::normalize(a_); 
0108     glm::tvec3<double> b = glm::normalize(b_); 
0109 
0110     std::cout << " a " << stra<double>::Desc(a) << std::endl ;    
0111     std::cout << " b " << stra<double>::Desc(b) << std::endl ;    
0112     std::cout << " c " << stra<double>::Desc(c) << std::endl ;    
0113 
0114 
0115     glm::tmat4x4<double> tr0 = stra<double>::Place(a, b, c, false ); 
0116     std::cout << " tr0 = stra<double>::Place(a,b,c,false) " << std::endl << stra<double>::Desc(tr0) << std::endl ;    
0117 
0118     glm::tmat4x4<double> tr1 = stra<double>::Place(a, b, c, true ); 
0119     std::cout << " tr1 = stra<double>::Place(a,b,c,true) " << std::endl << stra<double>::Desc(tr1) << std::endl ;    
0120 
0121     glm::tvec4<double> a4(a, 1.); 
0122     glm::tvec4<double> b4(b, 1.); 
0123     glm::tvec4<double> c4(c, 1.); 
0124     glm::tvec4<double> e4(b+c, 1.); 
0125 
0126     std::cout << std::setw(20) << " a4 " << stra<double>::Desc(a4) << std::endl ;    
0127     std::cout << std::setw(20) << " b4 " << stra<double>::Desc(b4) << std::endl ;    
0128     std::cout << std::setw(20) << " c4 " << stra<double>::Desc(c4) << std::endl ;    
0129     std::cout << std::setw(20) << " e4 = b + c " << stra<double>::Desc(e4) << std::endl ;    
0130 
0131     glm::tvec4<double> tr0_a4 = tr0 * a4 ; 
0132     glm::tvec4<double> tr1_a4 = tr1 * a4 ; 
0133 
0134     glm::tvec4<double> a4_tr0 = a4 * tr0 ; 
0135     glm::tvec4<double> a4_tr1 = a4 * tr1 ; 
0136 
0137 
0138     std::cout << std::setw(20) << " tr0_a4 " << stra<double>::Desc(tr0_a4) << std::endl ;    
0139     std::cout << std::setw(20) << " tr1_a4 " << stra<double>::Desc(tr1_a4) << "(this gives expected e4)" << std::endl ;    
0140 
0141     std::cout << std::setw(20) << " a4_tr0 " << stra<double>::Desc(a4_tr0) << std::endl ;    
0142     std::cout << std::setw(20) << " a4_tr1 " << stra<double>::Desc(a4_tr1) << std::endl ;    
0143 
0144     std::cout << std::setw(20) << " e4 = b + c  " << stra<double>::Desc(e4) << std::endl ;    
0145 }
0146 
0147 
0148 
0149 template<typename T>
0150 glm::tmat4x4<T> make_translate(T tx, T ty, T tz)
0151 {
0152     std::array<T, 16> aa = 
0153          {{1., 0., 0., 0., 
0154            0., 1., 0., 0., 
0155            0., 0., 1., 0., 
0156            tx, ty, tz, 1. }} ; 
0157     glm::tmat4x4<T> tr = stra<T>::FromData(aa.data()) ; 
0158     return tr ; 
0159 }
0160 
0161 
0162 void init( sphoton& p )
0163 {
0164     p.pos = {0.f, 0.f, 0.f } ; 
0165     p.time = 0.f  ;
0166     p.mom = {0.f, 0.f, 1.f } ; 
0167     p.pol = {0.f, 1.f, 0.f } ; 
0168 }
0169 
0170 
0171 void test_photon_transform_0() 
0172 {
0173     double tx = 10. ; 
0174     double ty = 20. ; 
0175     double tz = 30. ; 
0176 
0177     const glm::tmat4x4<double> tr = make_translate<double>(tx, ty, tz); 
0178     
0179     sphoton p0 ; 
0180     init(p0); 
0181 
0182     sphoton p1(p0); 
0183     p1.transform(tr);  
0184 
0185     std::cout << " p0.descBase " << p0.descBase() << std::endl ;  
0186     std::cout << " p1.descBase " << p1.descBase() << std::endl ;  
0187 
0188     assert( p1.pos.x = p0.pos.x + tx );  
0189     assert( p1.pos.y = p0.pos.y + ty );  
0190     assert( p1.pos.z = p0.pos.z + tz );  
0191 }
0192 
0193 
0194 void test_TranConvert()
0195 {
0196     float tx = 10. ; 
0197     float ty = 20. ; 
0198     float tz = 30. ; 
0199     const glm::tmat4x4<float> tr0 = make_translate<float>(tx, ty, tz); 
0200 
0201     glm::tmat4x4<double> tr1 ;
0202 
0203     //TranConvert<double,float>(tr1, tr0);  
0204     TranConvert(tr1, tr0);  
0205 
0206     std::cout << " tr0\n" << tr0 << std::endl ; 
0207     std::cout << " tr1\n" << tr1 << std::endl ; 
0208 }
0209 
0210 
0211 int main()
0212 {
0213     /*
0214     test_from_string();  
0215     test_Translate(); 
0216     test_MakeRotateA2B(); 
0217     test_Place(); 
0218     test_photon_transform_0(); 
0219     */
0220 
0221     test_TranConvert(); 
0222 
0223 
0224     return 0 ; 
0225 }