File indexing completed on 2026-04-09 07:49:16
0001 #include <algorithm>
0002
0003 #include "SCenterExtentFrame.hh"
0004 #include "SCenterExtentFrameTest.hh"
0005 #include "SPresent.hh"
0006
0007 template<typename T>
0008 SCenterExtentFrameTest<T>::SCenterExtentFrameTest( const SCenterExtentFrame<T>& _cef )
0009 :
0010 cef(_cef),
0011 ce(_cef.ce)
0012 {
0013 const glm::tmat4x4<T>& scale = cef.scale ;
0014 const glm::tmat4x4<T>& iscale = cef.iscale ;
0015 const glm::tmat4x4<T>& translate = cef.translate ;
0016 const glm::tmat4x4<T>& itranslate = cef.itranslate ;
0017 const glm::tmat4x4<T>& rotate = cef.rotate ;
0018 const glm::tmat4x4<T>& irotate = cef.irotate ;
0019
0020 _world2model["0"] = irotate * iscale * itranslate ;
0021 _model2world["0"] = translate * scale * rotate ;
0022 modes.push_back("0"); pref_modes.push_back("0") ;
0023
0024 _world2model["SRT"] = iscale * irotate * itranslate ; modes.push_back("SRT"); pref_modes.push_back("SRT") ;
0025 _world2model["RST"] = irotate * iscale * itranslate ; modes.push_back("RST"); pref_modes.push_back("RST") ;
0026 _world2model["RTS"] = irotate * itranslate * iscale ; modes.push_back("RTS");
0027 _world2model["TRS"] = itranslate * irotate * iscale ; modes.push_back("TRS");
0028 _world2model["TSR"] = itranslate * iscale * irotate ; modes.push_back("TSR");
0029 _world2model["STR"] = iscale * itranslate * irotate ; modes.push_back("STR");
0030
0031 _model2world["SRT"] = scale * rotate * translate ;
0032 _model2world["RST"] = rotate * scale * translate ;
0033 _model2world["RTS"] = rotate * translate * scale ;
0034 _model2world["TRS"] = translate * rotate * scale ;
0035 _model2world["TSR"] = translate * scale * rotate ;
0036 _model2world["STR"] = scale * translate * rotate ;
0037 }
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 template<typename T>
0049 void SCenterExtentFrameTest<T>::dump(char m)
0050 {
0051 cef.dump("SCenterExtentFrameTest::dump");
0052
0053 const std::vector<std::string>& mds = m == 'P' ? pref_modes : modes ;
0054
0055 for(unsigned pass=0 ; pass < 2 ; pass++)
0056 {
0057 std::cout << std::endl << std::endl ;
0058 for(unsigned i=0 ; i < mds.size() ; i++)
0059 {
0060 const std::string& mode = mds[i] ;
0061 std::string rmode(mode);
0062 std::reverse(rmode.begin(), rmode.end());
0063 const char* w2m_mode = mode.c_str() ;
0064 const char* m2w_mode = rmode.c_str() ;
0065 switch(pass)
0066 {
0067 case 0: std::cout << SPresent( _world2model[w2m_mode], " world2model", w2m_mode ) << std::endl ; break ;
0068 case 1: std::cout << SPresent( _model2world[m2w_mode], " model2world", m2w_mode ) << std::endl ; break ;
0069 }
0070 }
0071 }
0072 }
0073
0074 template<typename T>
0075 void SCenterExtentFrameTest<T>::check(const std::vector<glm::vec4>& world, const std::vector<std::string>& label, const char* title, const char* w2m_mode, const char* m2w_mode )
0076 {
0077 const glm::tmat4x4<T>& w2m = _world2model[w2m_mode] ;
0078 const glm::tmat4x4<T>& m2w = _model2world[m2w_mode] ;
0079
0080 std::cout << std::endl << title << " w2m_mode " << w2m_mode << " m2w_mode " << m2w_mode << std::endl ;
0081 for(unsigned i=0 ; i < world.size() ; i++)
0082 {
0083 const glm::vec4& world_pos = world[i] ;
0084 glm::vec4 model_pos = w2m * world_pos ;
0085 glm::vec4 world_pos2 = m2w * model_pos ;
0086
0087 std::cout
0088 << std::setw(10) << label[i]
0089 << SPresent( world_pos, "world_pos")
0090 << SPresent( model_pos, "model_pos")
0091 << SPresent( world_pos2, "world_pos2")
0092 << std::endl
0093 ;
0094 }
0095 }
0096
0097 template<typename T>
0098 void SCenterExtentFrameTest<T>::check(char m)
0099 {
0100 dump();
0101 std::vector<glm::vec4> world ;
0102 std::vector<std::string> label ;
0103
0104 world.push_back( { ce.x , ce.y , ce.z , 1.0 } ); label.push_back("origin") ;
0105 world.push_back( { ce.x + ce.w, ce.y , ce.z , 1.0 } ); label.push_back("+X") ;
0106 world.push_back( { ce.x - ce.w, ce.y , ce.z , 1.0 } ); label.push_back("-X") ;
0107 world.push_back( { ce.x , ce.y+ce.w , ce.z , 1.0 } ); label.push_back("+Y") ;
0108 world.push_back( { ce.x , ce.y-ce.w , ce.z , 1.0 } ); label.push_back("-Y") ;
0109 world.push_back( { ce.x , ce.y , ce.z+ce.w , 1.0 } ); label.push_back("+Z") ;
0110 world.push_back( { ce.x , ce.y , ce.z-ce.w , 1.0 } ); label.push_back("-Z") ;
0111 world.push_back( { ce.x + ce.w, ce.y + ce.w , ce.z , 1.0 } ); label.push_back("+X+Y") ;
0112 world.push_back( { ce.x - ce.w, ce.y - ce.w , ce.z , 1.0 } ); label.push_back("-X-Y") ;
0113 world.push_back( { ce.x - ce.w, ce.y - ce.w , ce.z - ce.w, 1.0 } ); label.push_back("-X-Y-Z") ;
0114 world.push_back( { ce.x + ce.w, ce.y + ce.w , ce.z + ce.w, 1.0 } ); label.push_back("+X+Y+Z") ;
0115
0116 const std::vector<std::string>& mds = m == 'P' ? pref_modes : modes ;
0117
0118 for(unsigned i=0 ; i < mds.size() ; i++)
0119 {
0120 const std::string& mode = mds[i] ;
0121 std::string rmode(mode);
0122 std::reverse(rmode.begin(), rmode.end());
0123
0124 const char* w2m_mode = mode.c_str() ;
0125 const char* m2w_mode = rmode.c_str() ;
0126
0127 check(world, label, " world->model->world ", w2m_mode, m2w_mode );
0128 }
0129 }
0130
0131
0132
0133 void test_Narrow()
0134 {
0135
0136
0137
0138 }
0139
0140
0141 int main(int argc, char** argv)
0142 {
0143 double cx = 100. ;
0144 double cy = 100. ;
0145 double cz = 100. ;
0146 double extent = 5. ;
0147 bool rtp_tangential = true ;
0148
0149 SCenterExtentFrame<double> f(cx,cy,cz,extent,rtp_tangential);
0150 SCenterExtentFrameTest<double> ft(f);
0151 ft.check('P');
0152
0153 return 0 ;
0154 }
0155