You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

429 lines
14 KiB

5 years ago
​
​
​
​
​
​
​
​
​
7 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
5 years ago
5 years ago
5 years ago
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
5 years ago
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
5 years ago
4 years ago
​
​
5 years ago
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
5 years ago
​
​
​
5 years ago
​
​
5 years ago
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectSystemAnchor.h"
  2. #ifdef DEBUG
  3. #include "../base/basicLogCollection.h"
  4. #define LOG( X ) basicLogCollection::getInstance()->Log( "ANCHOR", this, X )
  5. #define LOG_ERROR( X ) {\
  6. char _tBfrErrMSG2w34[256];\
  7. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  8. basicLogCollection::getInstance()->Log( "ANCHOR", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  9. }
  10. #endif
  11. systemAnchor* systemAnchor::_instance = 0;
  12. /**
  13. * Returns the single instance of the object.
  14. */
  15. systemAnchor* systemAnchor::getInstance( bool SOUTH, C3D_WGS84_LOC *ptr, bool jl ) {
  16. // check if the instance has been created yet
  17. if (0 == _instance) {
  18. // if not, then create it
  19. _instance = new systemAnchor( SOUTH, ptr, jl );
  20. }
  21. // return the single instance
  22. return _instance;
  23. };
  24. systemAnchor::systemAnchor( bool SOUTH, C3D_WGS84_LOC *ptr, bool beJustLocal ): m_SCC(){
  25. config_setting_t *pSetting;
  26. m_pSettings = NULL;
  27. m_bSouthHemisphere = 0;
  28. m_bUseJustLocalDiffCoords = beJustLocal;
  29. m_bSouthHemisphere = SOUTH;
  30. if( ptr == NULL ) {
  31. pSetting = basicSettingsProvider::getInstance()->getSubNode( NULL, "APPLICATION_GUI" );
  32. if( pSetting != NULL ){
  33. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( pSetting, "SYSTEM_ANCHOR" );
  34. };
  35. // Read Config
  36. if( m_pSettings != NULL ){
  37. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT );
  38. if (pSetting == NULL){
  39. lat = 0.f;
  40. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT );
  41. config_setting_set_float( pSetting, lat );
  42. basicSettingsProvider::getInstance()->compromise();
  43. } else {
  44. lat = (float)config_setting_get_float(pSetting);
  45. };
  46. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON );
  47. if (pSetting == NULL){
  48. lon = 0.f;
  49. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT );
  50. config_setting_set_float( pSetting, lon );
  51. basicSettingsProvider::getInstance()->compromise();
  52. } else {
  53. lon = config_setting_get_float(pSetting);
  54. };
  55. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT );
  56. if (pSetting == NULL){
  57. z = 0.f;
  58. pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT );
  59. config_setting_set_float( pSetting, z );
  60. basicSettingsProvider::getInstance()->compromise();
  61. } else {
  62. z = config_setting_get_float(pSetting);
  63. };
  64. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_SOUTH_HS);
  65. if (pSetting == NULL){
  66. m_bSouthHemisphere = false;
  67. pSetting = config_setting_add(m_pSettings, TAG_POSITION_SOUTH_HS, CONFIG_TYPE_BOOL );
  68. config_setting_set_bool(pSetting, m_bSouthHemisphere);
  69. basicSettingsProvider::getInstance()->compromise();
  70. } else {
  71. m_bSouthHemisphere = config_setting_get_bool(pSetting);
  72. };
  73. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LOCAL);
  74. if (pSetting == NULL){
  75. m_bUseJustLocalDiffCoords = false;
  76. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LOCAL, CONFIG_TYPE_BOOL );
  77. config_setting_set_bool(pSetting, m_bUseJustLocalDiffCoords);
  78. basicSettingsProvider::getInstance()->compromise();
  79. } else {
  80. m_bUseJustLocalDiffCoords = config_setting_get_bool(pSetting);
  81. };
  82. #ifdef FLOAT_64
  83. double A, B;
  84. utmZone = CC.LatLonToUTMXY( lat, lon, 0 , A, B );
  85. x = A;
  86. y = B;
  87. #else
  88. utmZone = m_SCC.LatLonToUTMXY(lat, lon, m_bSouthHemisphere, x, y);
  89. #endif
  90. basicSettingsProvider::getInstance()->validate();
  91. };
  92. } else {
  93. if ( m_bUseJustLocalDiffCoords ) {
  94. y = lat = ptr->lat;
  95. x = lon = ptr->lon;
  96. z = ptr->alt;
  97. } else {
  98. lat = ptr->lat;
  99. lon = ptr->lon;
  100. z = ptr->alt;
  101. #ifdef FLOAT_64
  102. double A, B;
  103. utmZone = CC.LatLonToUTMXY( lat, lon, 0 , A, B );
  104. x = A;
  105. y = B;
  106. #else
  107. utmZone = m_SCC.LatLonToUTMXY(lat, lon, m_bSouthHemisphere, x, y);
  108. #endif
  109. };
  110. };
  111. #ifdef DEBUG
  112. char tBuff[256];
  113. if ( m_bUseJustLocalDiffCoords ) {
  114. sprintf(tBuff, "Anchor is LOCAL[x:%0.4f y:%0.4f z:%0.4f]", x, y, z );
  115. } else {
  116. sprintf(tBuff, "Anchor is WGS84[lat:%0.6f Lon:%0.6f Alt:%0.6f] UMTS[x:%0.4f y:%0.4f z:%0.4f]", lat, lon, z, x, y, z );
  117. };
  118. LOG( tBuff );
  119. #endif
  120. };
  121. systemAnchor::~systemAnchor(){
  122. /*
  123. config_setting_t *pSetting;
  124. C3D_FLOAT tVal;
  125. bool tBool;
  126. m_pSettings = NULL;
  127. pSetting = basicSettingsProvider::getInstance()->getSubNode( NULL, "APPLICATION_GUI" );
  128. if( pSetting != NULL ){
  129. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( pSetting, "SYSTEM_ANCHOR" );
  130. };
  131. // Read Config
  132. if( m_pSettings != NULL ){
  133. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT);
  134. if (pSetting == NULL){
  135. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT );
  136. config_setting_set_float(pSetting, lat );
  137. basicSettingsProvider::getInstance()->compromise();
  138. } else {
  139. tVal = config_setting_get_float(pSetting);
  140. if( lat != tVal ){
  141. config_setting_set_float(pSetting, lat );
  142. basicSettingsProvider::getInstance()->compromise();
  143. };
  144. };
  145. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON);
  146. if (pSetting == NULL){
  147. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT );
  148. config_setting_set_float(pSetting, lon );
  149. basicSettingsProvider::getInstance()->compromise();
  150. } else {
  151. tVal = config_setting_get_float(pSetting);
  152. if( lon != tVal ){
  153. config_setting_set_float(pSetting, lon );
  154. basicSettingsProvider::getInstance()->compromise();
  155. };
  156. };
  157. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT);
  158. if (pSetting == NULL){
  159. pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT );
  160. config_setting_set_float(pSetting, z );
  161. basicSettingsProvider::getInstance()->compromise();
  162. } else {
  163. tVal = config_setting_get_float(pSetting);
  164. if( z != tVal ){
  165. config_setting_set_float(pSetting, z );
  166. basicSettingsProvider::getInstance()->compromise();
  167. };
  168. };
  169. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_SOUTH_HS);
  170. if (pSetting == NULL){
  171. pSetting = config_setting_add(m_pSettings, TAG_POSITION_SOUTH_HS, CONFIG_TYPE_BOOL );
  172. config_setting_set_bool(pSetting, m_bSouthHemisphere );
  173. basicSettingsProvider::getInstance()->compromise();
  174. } else {
  175. tBool = config_setting_get_bool(pSetting);
  176. if (m_bSouthHemisphere != tBool){
  177. config_setting_set_bool(pSetting, m_bSouthHemisphere );
  178. basicSettingsProvider::getInstance()->compromise();
  179. };
  180. };
  181. basicSettingsProvider::getInstance()->validate();
  182. };
  183. */
  184. };
  185. bool systemAnchor::convertToLocal(basicPosition *SP, C3D_WGS84_LOC POS, C3D_SPH_DEGREES& LOC) {
  186. if (SP == NULL) return false;
  187. transform_3* pTF = SP->getTransform();
  188. C3D_DECART tDec;
  189. vector_3 A, B;
  190. tDec.z = POS.alt;
  191. m_SCC.LatLonToUTMXY(POS.lat, POS.lon, SP->getUTMZone(), tDec.x, tDec.y);
  192. A[0] = tDec.x;
  193. A[1] = tDec.y;
  194. A[2] = tDec.z;
  195. pTF->get_vector_local(A, B);
  196. tDec.x = B[0];
  197. tDec.y = B[1];
  198. tDec.z = B[2];
  199. decart2spherical(tDec, LOC);
  200. return true;
  201. };
  202. bool systemAnchor::convertToLocal(basicPosition *SP, C3D_WGS84_LOC POS, C3D_SPH_RADIANS& LOC) {
  203. if (SP == NULL) return false;
  204. transform_3* pTF = SP->getTransform();
  205. C3D_DECART tDec;
  206. vector_3 A, B;
  207. tDec.z = POS.alt;
  208. #ifdef DEBUG_EXTRA
  209. char tB[256];
  210. sprintf(tB, "Global WGS: %.3f %.3f %.3f", POS.lat, POS.lon, POS.alt );
  211. LOG( tB );
  212. #endif
  213. m_SCC.LatLonToUTMXY(POS.lat, POS.lon, getUTMZone(), tDec.x, tDec.y);
  214. A[0] = tDec.x;// - SP->getX();
  215. A[1] = tDec.y;// - SP->getY();
  216. A[2] = tDec.z;// - SP->getZ();
  217. #ifdef DEBUG_EXTRA
  218. sprintf( tB, "Global Decart: %.3f %.3f %.3f", A[0], A[1], A[2] );
  219. LOG( tB );
  220. #endif
  221. pTF->get_vector_local( A, B );
  222. #ifdef DEBUG_EXTRA
  223. sprintf( tB, "Local Decart: %.3f %.3f %.3f", B[0], B[1], B[2] );
  224. LOG( tB );
  225. #endif
  226. tDec.x = B[0];
  227. tDec.y = B[1];
  228. tDec.z = B[2];
  229. decart2spherical(tDec, LOC);
  230. return true;
  231. };
  232. bool systemAnchor::convertToLocal( basicPosition *SP, C3D_DECART POS, C3D_SPH_DEGREES& LOC) {
  233. if (SP == NULL) return false;
  234. transform_3* pTF = SP->getTransform();
  235. C3D_DECART tDec;
  236. vector_3 A, B;
  237. #ifdef DEBUG_EXTRA
  238. char tB[256];
  239. LOG("C2L Dec. -> Sph.(deg)");
  240. sprintf(tB, "System Decart: %.3f %.3f %.3f", POS.x, POS.y, POS.z );
  241. LOG( tB );
  242. #endif
  243. // POS - is Relative to System Anchore!!
  244. if( m_bUseJustLocalDiffCoords ) {
  245. //LOG("JLO");
  246. A[0] = POS.x;//+ getX();// - getX(); // in general getX() = 0 as other coords of anchore
  247. A[1] = POS.y;// + getY();// - getY();
  248. A[2] = POS.z;// + getZ();// - getZ();
  249. } else {
  250. //LOG("NLO");
  251. A[0] = POS.x + getX();
  252. A[1] = POS.y + getY();
  253. A[2] = POS.z + getZ();
  254. };
  255. #ifdef DEBUG_EXTRA
  256. sprintf(tB, "Prepared Global Decart: %.3f %.3f %.3f", A[0], A[1], A[2] );
  257. LOG( tB );
  258. #endif
  259. //A[0] = getX() + POS.x;
  260. //A[1] = getY() + POS.y;
  261. //A[2] = getZ() + POS.z;
  262. pTF->get_vector_local( A, B );
  263. //tDec.x = B[0] + getX() - SP->getX();
  264. //tDec.y = B[1] + getY() - SP->getY();
  265. //tDec.z = B[2] + getZ() - SP->getZ();
  266. tDec.x = B[0];// + getX() - SP->getX();
  267. tDec.y = B[1]; //+ getY() - SP->getY();
  268. tDec.z = B[2]; //+ getZ() - SP->getZ();
  269. #ifdef DEBUG_EXTRA
  270. sprintf(tB, "Local Decart: %.3f %.3f %.3f", B[0], B[1], B[2] );
  271. LOG( tB );
  272. //sprintf(tB, "Local Decart: %.3f %.3f %.3f", tDec.x, tDec.y, tDec.z );
  273. //LOG( tB );
  274. #endif
  275. decart2spherical(tDec, LOC);
  276. return true;
  277. };
  278. bool systemAnchor::convertToLocal(basicPosition *SP, C3D_DECART POS, C3D_SPH_RADIANS& LOC) {
  279. if (SP == NULL) return false;
  280. transform_3* pTF = SP->getTransform();
  281. C3D_DECART tDec;
  282. vector_3 A, B;
  283. // POS - is Relative to System Anchore!!
  284. A[0] = getX() + POS.x;
  285. A[1] = getY() + POS.y;
  286. A[2] = getZ() + POS.z;
  287. pTF->get_vector_local(A, B);
  288. tDec.x = B[0];
  289. tDec.y = B[1];
  290. tDec.z = B[2];
  291. decart2spherical(tDec, LOC);
  292. return true;
  293. };
  294. bool systemAnchor::convertToSystem(basicPosition *SP, C3D_WGS84_LOC POS, C3D_DECART& LOC) {
  295. if (SP == NULL) return false;
  296. C3D_DECART tDec;
  297. tDec.z = POS.alt;
  298. m_SCC.LatLonToUTMXY( POS.lat, POS.lon, SP->getUTMZone(), tDec.x, tDec.y );
  299. LOC.x = tDec.x - getX();
  300. LOC.y = tDec.y - getX();
  301. LOC.z = tDec.z - getZ();
  302. return true;
  303. };
  304. bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_DECART& LOC) {
  305. if (SP == NULL) return false;
  306. transform_3* pTF = SP->getTransform();
  307. C3D_DECART tDec;
  308. vector_3 A, B;
  309. spherical2decart( POS, tDec );
  310. A[0] = tDec.x;
  311. A[1] = tDec.y;
  312. A[2] = tDec.z;
  313. #ifdef DEBUG_EXTRA
  314. char tB[256];
  315. LOG("C2S Sph.(deg) -> Dec.");
  316. sprintf( tB, "Local Decart: %.3f %.3f %.3f", A[0], A[1], A[2] );
  317. LOG( tB );
  318. #endif
  319. pTF->get_vector_world( A, B );
  320. #ifdef DEBUG_EXTRA
  321. sprintf( tB, "World Decart: %.3f %.3f %.3f", B[0], B[1], B[2] );
  322. LOG( tB );
  323. #endif
  324. #ifdef DEBUG_EXTRA
  325. sprintf( tB, "Systen Anchor Decart: %.3f %.3f %.3f", getX(), getY(), getZ() );
  326. LOG( tB );
  327. #endif
  328. if ( m_bUseJustLocalDiffCoords ) {
  329. LOC.x = B[0];
  330. LOC.y = B[1];
  331. LOC.z = B[2];
  332. } else {
  333. LOC.x = B[0] - getX();
  334. LOC.y = B[1] - getY();
  335. LOC.z = B[2] - getZ();
  336. };
  337. #ifdef DEBUG_EXTRA
  338. sprintf( tB, "Final System Decart: %.3f %.3f %.3f", LOC.x, LOC.y, LOC.z );
  339. LOG( tB );
  340. #endif
  341. return true;
  342. };
  343. bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_DECART& LOC) {
  344. if (SP == NULL) return false;
  345. transform_3* pTF = SP->getTransform();
  346. C3D_DECART tDec;
  347. vector_3 A, B;
  348. spherical2decart( POS, tDec );
  349. A[0] = tDec.x;
  350. A[1] = tDec.y;
  351. A[2] = tDec.z;
  352. pTF->get_vector_world(A, B);
  353. //LOC.x = B[0] + SP->getX() - getX();
  354. LOC.x = B[0] - getX();
  355. //LOC.y = B[1] + SP->getY() - getY();
  356. LOC.y = B[1] - getY();
  357. //LOC.z = B[2] + SP->getZ() - getZ();
  358. LOC.z = B[2] - getZ();
  359. return true;
  360. };
  361. bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_WGS84_LOC& LOC) {
  362. if (SP == NULL) return false;
  363. transform_3* pTF = SP->getTransform();
  364. C3D_DECART tDec;
  365. vector_3 A, B;
  366. spherical2decart( POS, tDec );
  367. A[0] = tDec.x;
  368. A[1] = tDec.y;
  369. A[2] = tDec.z;
  370. pTF->get_vector_world(A, B);
  371. //tDec.x = B[0] + SP->getX();
  372. tDec.x = B[0] + SP->getX() - getX();
  373. //tDec.y = B[1] + SP->getY();
  374. tDec.y = B[1] + SP->getY() - getY();
  375. //tDec.z = B[2] + SP->getZ();
  376. tDec.z = B[2] + SP->getZ() - getZ();
  377. m_SCC.UTMXYToLatLon( tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon);
  378. LOC.alt = tDec.z;
  379. return true;
  380. };
  381. bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_WGS84_LOC& LOC) {
  382. if (SP == NULL) return false;
  383. transform_3* pTF = SP->getTransform();
  384. C3D_DECART tDec;
  385. vector_3 A, B;
  386. spherical2decart(POS, tDec);
  387. A[0] = tDec.x;
  388. A[1] = tDec.y;
  389. A[2] = tDec.z;
  390. pTF->get_vector_world(A, B);
  391. //tDec.x = B[0] + SP->getX();
  392. tDec.x = B[0] + SP->getX() - getX();
  393. //tDec.y = B[1] + SP->getY();
  394. tDec.y = B[1] + SP->getY() - getY();
  395. //tDec.z = B[2] + SP->getZ();
  396. tDec.z = B[2] + SP->getZ() - getZ();
  397. m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon);
  398. LOC.alt = tDec.z;
  399. return true;
  400. };
  401. bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_DECART POS, C3D_WGS84_LOC& LOC) {
  402. C3D_DECART tDec;
  403. tDec.x = POS.x + getX();
  404. tDec.y = POS.y + getY();
  405. tDec.z = POS.z + getZ();
  406. m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon);
  407. LOC.alt = tDec.z;
  408. return true;
  409. };
  410. #ifdef DEBUG
  411. #undef LOG
  412. #undef LOG_ERROR
  413. #endif