File indexing completed on 2026-04-09 07:49:22
0001 #include <iostream>
0002 #include <csignal>
0003
0004 #include "scuda.h"
0005 #include "squad.h"
0006 #include "sqat4.h"
0007 #include "stran.h"
0008
0009 #include "SPath.hh"
0010 #include "NP.hh"
0011
0012
0013 void test_make()
0014 {
0015 const Tran<float>* i = Tran<float>::make_translate( 0.f, 0.f, 0.f ) ;
0016 const Tran<float>* t = Tran<float>::make_translate( 1.f, 2.f, 3.f ) ;
0017 const Tran<float>* s = Tran<float>::make_scale( 1.f, 2.f, 3.f ) ;
0018 const Tran<float>* r = Tran<float>::make_rotate( 0.f, 0.f, 1.f, 45.f ) ;
0019
0020 const Tran<float>* ts0 = Tran<float>::product( t, s, false );
0021 const Tran<float>* ts1 = Tran<float>::product( t, s, true );
0022
0023 std::cout << "i " << i->brief() << std::endl ;
0024 std::cout << "t " << t->brief() << std::endl ;
0025 std::cout << "s " << s->brief() << std::endl ;
0026 std::cout << "r " << r->brief() << std::endl ;
0027 std::cout << "ts0 " << ts0->brief() << std::endl ;
0028 std::cout << "ts1 " << ts1->brief() << std::endl ;
0029 }
0030
0031
0032 void test_ctor()
0033 {
0034 const Tran<float>* s = Tran<float>::make_scale( 1.f, 2.f, 3.f ) ;
0035 const Tran<float>* s2 = new Tran<float>( s->tdata(), s->vdata() ) ;
0036
0037 std::cout << "s " << s->brief() << std::endl ;
0038 std::cout << "s2 " << s2->brief() << std::endl ;
0039 }
0040
0041 void test_Convert()
0042 {
0043 const char* t_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)" ;
0044 qat4* t = qat4::from_string(t_str);
0045 std::cout << *t << std::endl ;
0046
0047 Tran<double>* trd = Tran<double>::ConvertToTran(t);
0048 qat4* trd_t = Tran<double>::ConvertFrom(trd->t);
0049 qat4* trd_v = Tran<double>::ConvertFrom(trd->v);
0050 qat4* trd_i = Tran<double>::ConvertFrom(trd->i);
0051
0052 int rc = qat4::compare( *t, *trd_t, 1e-7 ) ;
0053 assert( rc == 0 );
0054 if(rc!=0) std::raise(SIGINT);
0055
0056
0057 std::cout << *trd << std::endl ;
0058 std::cout << "trd_t " << *trd_t << std::endl ;
0059 std::cout << "trd_v " << *trd_v << std::endl ;
0060 std::cout << "trd_i " << *trd_i << std::endl ;
0061
0062 Tran<float>* trf = Tran<float>::ConvertToTran(t);
0063 qat4* trf_t = Tran<double>::ConvertFrom(trf->t);
0064 qat4* trf_v = Tran<double>::ConvertFrom(trf->v);
0065 qat4* trf_i = Tran<double>::ConvertFrom(trf->i);
0066
0067 std::cout << *trf << std::endl ;
0068 std::cout << "trf_t " << *trf_t << std::endl ;
0069 std::cout << "trf_v " << *trf_v << std::endl ;
0070 std::cout << "trf_i " << *trf_i << std::endl ;
0071 }
0072
0073
0074 template<typename T>
0075 void test_write(const char* name)
0076 {
0077 const char* fold = SPath::Resolve("$TMP/sysrap/stranTest/test_write", DIRPATH);
0078
0079 const Tran<T>* tr = Tran<T>::make_rotate( 0.f, 0.f, 1.f, 45.f ) ;
0080
0081 NP* a = NP::Make<T>(3, 4, 4 );
0082 tr->write( a->values<T>() ) ;
0083
0084 a->dump();
0085 a->save(fold, name) ;
0086 }
0087
0088 template<typename T>
0089 void test_apply()
0090 {
0091 const Tran<T>* tr = Tran<T>::make_translate(0., 0., 100.) ;
0092
0093 T pos[8] ;
0094 pos[0] = 0. ;
0095 pos[1] = 0. ;
0096 pos[2] = 0. ;
0097 pos[3] = 0. ;
0098 pos[4] = 0. ;
0099 pos[5] = 0. ;
0100 pos[6] = 0. ;
0101 pos[7] = 0. ;
0102
0103 unsigned count = 2 ;
0104 unsigned stride = 4 ;
0105 unsigned offset = 0 ;
0106
0107 T w = 1. ;
0108
0109 tr->apply( &pos[0], w, count, stride, offset );
0110
0111 for(int i=0 ; i < 8 ; i++) std::cout << std::setw(1) << i << " : " << pos[i] << std::endl ;
0112 }
0113
0114 template<typename T>
0115 void test_PhotonTransform()
0116 {
0117 double data[16] = {
0118 1., 0., 0., 0.,
0119 0., 1., 0., 0.,
0120 0., 0.,-1., 0.,
0121 0., 0., 100., 1. } ;
0122
0123 const Tran<T>* t = Tran<T>::ConvertFromData(&data[0]) ;
0124
0125
0126
0127 const char* name = "RandomDisc100_f8.npy" ;
0128 const char* path = SPath::Resolve("$HOME/.opticks/InputPhotons" , name, NOOP );
0129
0130 NP* a = NP::Load(path);
0131 if(!a) return ;
0132
0133 bool inverse = false ;
0134
0135 NP* b0 = Tran<T>::PhotonTransform(a, false, t, inverse);
0136 NP* b1 = Tran<T>::PhotonTransform(a, true, t, inverse);
0137
0138
0139 const char* FOLD = SPath::Resolve("$TMP/stranTest", DIRPATH );
0140 std::cout << " FOLD " << FOLD << std::endl ;
0141
0142 a->save(FOLD, "a.npy");
0143 b0->save(FOLD, "b0.npy");
0144 b1->save(FOLD, "b1.npy");
0145 t->save(FOLD, "t.npy");
0146 }
0147
0148
0149
0150
0151
0152
0153 int main()
0154 {
0155
0156
0157
0158
0159
0160
0161
0162
0163 test_PhotonTransform<double>();
0164
0165
0166 return 0 ;
0167 }
0168
0169
0170