|
|
#include "objectSystemAnchor.h"
#ifdef DEBUG
#include "../base/basicLogCollection.h"
#define LOG(X) basicLogCollection::getInstance()->Log("ANCHOR", this, X)
#define LOG_ERROR(X) \
{ \ char _tBfrErrMSG2w34[256]; \ sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \ basicLogCollection::getInstance()->Log("ANCHOR", this, _LOG_ERROR, _tBfrErrMSG2w34); \ }#endif
systemAnchor * systemAnchor::_instance = 0;
/**
* Returns the single instance of the object. */systemAnchor * systemAnchor::getInstance( C3D_WGS84_LOC * ptr, bool beJustLocal){ // check if the instance has been created yet
if (0 == _instance) { // if not, then create it
_instance = new systemAnchor( ptr, beJustLocal ); } // return the single instance
return _instance;}
systemAnchor::systemAnchor( C3D_WGS84_LOC *ptr, bool beJustLocal ) : m_SCC(), position3D(){ config_setting_t * pSetting; m_pSettings = NULL; m_bUseJustLocalDiffCoords = beJustLocal; if (ptr == NULL) { pSetting = basicSettingsProvider::getInstance()->getSubNode(NULL, "APPLICATION_GUI"); if (pSetting != NULL) { m_pSettings = basicSettingsProvider::getInstance()->getSubNode(pSetting, "SYSTEM_ANCHOR"); }; // Read Config
if (m_pSettings != NULL) { pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT); if (pSetting == NULL) { lat = 0.f; pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT); config_setting_set_float(pSetting, lat); basicSettingsProvider::getInstance()->compromise(); } else { lat = (float) config_setting_get_float(pSetting); }; pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON); if (pSetting == NULL) { lon = 0.f; pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT); config_setting_set_float(pSetting, lon); basicSettingsProvider::getInstance()->compromise(); } else { lon = config_setting_get_float(pSetting); }; pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT); if (pSetting == NULL) { z = 0.f; pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT); config_setting_set_float(pSetting, z); basicSettingsProvider::getInstance()->compromise(); } else { z = config_setting_get_float(pSetting); }; pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LOCAL); if (pSetting == NULL) { m_bUseJustLocalDiffCoords = false; pSetting = config_setting_add(m_pSettings, TAG_POSITION_LOCAL, CONFIG_TYPE_BOOL); config_setting_set_bool(pSetting, m_bUseJustLocalDiffCoords); basicSettingsProvider::getInstance()->compromise(); } else { m_bUseJustLocalDiffCoords = config_setting_get_bool(pSetting); };//#ifdef FLOAT_64
// double A, B;
// utmZone = CC.LatLonToUTMXY(lat, lon, 0, A, B);
// x = A;
// y = B;
//#else
// utmZone = m_SCC.LatLonToUTMXY(lat, lon, 0, x, y);
//#endif
position3D::setPositionWGS84( lat, lon, z ); basicSettingsProvider::getInstance()->validate(); }; } else { if (m_bUseJustLocalDiffCoords) { y = lat = ptr->lat; x = lon = ptr->lon; z = ptr->alt; } else { lat = ptr->lat; lon = ptr->lon; z = ptr->alt;//#ifdef FLOAT_64
// double A, B;
// utmZone = CC.LatLonToUTMXY(lat, lon, 0, A, B);
// x = A;
// y = B;
//#else
// utmZone = m_SCC.LatLonToUTMXY(lat, lon, 0, x, y);
//#endif
position3D::setPositionWGS84( lat, lon, z ); }; };#ifdef DEBUG
char tBuff[256]; if (m_bUseJustLocalDiffCoords) { sprintf(tBuff, "Anchor is LOCAL[x:%0.4f y:%0.4f z:%0.4f]", x, y, z); } else { sprintf(tBuff, "Anchor is WGS84[lat:%0.6f Lon:%0.6f Alt:%0.6f] UMTS[x:%0.4f y:%0.4f z:%0.4f] HS:%d", lat, lon, z, x, y, z, SouthHemisphere ); }; LOG(tBuff);#endif
}
systemAnchor::~systemAnchor(){ /*
config_setting_t *pSetting; C3D_FLOAT tVal; bool tBool;
m_pSettings = NULL; pSetting = basicSettingsProvider::getInstance()->getSubNode( NULL, "APPLICATION_GUI" ); if( pSetting != NULL ){ m_pSettings = basicSettingsProvider::getInstance()->getSubNode( pSetting, "SYSTEM_ANCHOR" ); }; // Read Config
if( m_pSettings != NULL ){ pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT); if (pSetting == NULL){ pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT ); config_setting_set_float(pSetting, lat ); basicSettingsProvider::getInstance()->compromise(); } else { tVal = config_setting_get_float(pSetting); if( lat != tVal ){ config_setting_set_float(pSetting, lat ); basicSettingsProvider::getInstance()->compromise(); }; }; pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON); if (pSetting == NULL){ pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT ); config_setting_set_float(pSetting, lon ); basicSettingsProvider::getInstance()->compromise(); } else { tVal = config_setting_get_float(pSetting); if( lon != tVal ){ config_setting_set_float(pSetting, lon ); basicSettingsProvider::getInstance()->compromise(); }; }; pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT); if (pSetting == NULL){ pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT ); config_setting_set_float(pSetting, z ); basicSettingsProvider::getInstance()->compromise(); } else { tVal = config_setting_get_float(pSetting); if( z != tVal ){ config_setting_set_float(pSetting, z ); basicSettingsProvider::getInstance()->compromise(); }; }; pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_SOUTH_HS); if (pSetting == NULL){ pSetting = config_setting_add(m_pSettings, TAG_POSITION_SOUTH_HS, CONFIG_TYPE_BOOL ); config_setting_set_bool(pSetting, m_bSouthHemisphere ); basicSettingsProvider::getInstance()->compromise(); } else { tBool = config_setting_get_bool(pSetting); if (m_bSouthHemisphere != tBool){ config_setting_set_bool(pSetting, m_bSouthHemisphere ); basicSettingsProvider::getInstance()->compromise(); }; }; basicSettingsProvider::getInstance()->validate(); }; */}
bool systemAnchor::convertToLocal( basicPosition * SP, C3D_WGS84_LOC POS, C3D_SPH_DEGREES & LOC){ if (SP == NULL) { return false; } transform_3 * pTF = SP->getTransform(); C3D_DECART tDec; vector_3 A, B; tDec.z = POS.alt; m_SCC.LatLonToUTMXY(POS.lat, POS.lon, SP->getUTMZone(), tDec.x, tDec.y); A[0] = tDec.x; A[1] = tDec.y; A[2] = tDec.z; pTF->get_vector_local(A, B); tDec.x = B[0]; tDec.y = B[1]; tDec.z = B[2]; decart2spherical(tDec, LOC); return true;}
bool systemAnchor::convertToLocal( basicPosition * SP, C3D_WGS84_LOC POS, C3D_SPH_RADIANS & LOC){ if (SP == NULL) { return false; } transform_3 * pTF = SP->getTransform(); C3D_DECART tDec; vector_3 A, B; tDec.z = POS.alt;#ifdef DEBUG_EXTRA
char tB[256]; sprintf(tB, "Global WGS: %.3f %.3f %.3f", POS.lat, POS.lon, POS.alt); LOG(tB);#endif
m_SCC.LatLonToUTMXY(POS.lat, POS.lon, getUTMZone(), tDec.x, tDec.y); A[0] = tDec.x; // - SP->getX();
A[1] = tDec.y; // - SP->getY();
A[2] = tDec.z; // - SP->getZ();
#ifdef DEBUG_EXTRA
sprintf(tB, "Global Decart: %.3f %.3f %.3f", A[0], A[1], A[2]); LOG(tB);#endif
pTF->get_vector_local(A, B);#ifdef DEBUG_EXTRA
sprintf(tB, "Local Decart: %.3f %.3f %.3f", B[0], B[1], B[2]); LOG(tB);#endif
tDec.x = B[0]; tDec.y = B[1]; tDec.z = B[2]; decart2spherical(tDec, LOC); return true;}
bool systemAnchor::convertToLocal(basicPosition * SP, C3D_DECART POS, C3D_SPH_DEGREES & LOC){ if (SP == NULL) { return false; } transform_3 * pTF = SP->getTransform(); C3D_DECART tDec; vector_3 A, B;#ifdef DEBUG_EXTRA
char tB[256]; LOG("C2L Dec. -> Sph.(deg)"); sprintf(tB, "System Decart: %.3f %.3f %.3f", POS.x, POS.y, POS.z); LOG(tB);#endif
// POS - is Relative to System Anchore!!
if (m_bUseJustLocalDiffCoords) { // LOG("JLO");
A[0] = POS.x; //+ getX();// - getX(); // in general getX() = 0 as other coords of anchore
A[1] = POS.y; // + getY();// - getY();
A[2] = POS.z; // + getZ();// - getZ();
} else { // LOG("NLO");
A[0] = POS.x + getX(); A[1] = POS.y + getY(); A[2] = POS.z + getZ(); };#ifdef DEBUG_EXTRA
sprintf(tB, "Prepared Global Decart: %.3f %.3f %.3f", A[0], A[1], A[2]); LOG(tB);#endif
// A[0] = getX() + POS.x;
// A[1] = getY() + POS.y;
// A[2] = getZ() + POS.z;
pTF->get_vector_local(A, B); // tDec.x = B[0] + getX() - SP->getX();
// tDec.y = B[1] + getY() - SP->getY();
// tDec.z = B[2] + getZ() - SP->getZ();
tDec.x = B[0]; // + getX() - SP->getX();
tDec.y = B[1]; //+ getY() - SP->getY();
tDec.z = B[2]; //+ getZ() - SP->getZ();
#ifdef DEBUG_EXTRA
sprintf(tB, "Local Decart: %.3f %.3f %.3f", B[0], B[1], B[2]); LOG(tB); // sprintf(tB, "Local Decart: %.3f %.3f %.3f", tDec.x, tDec.y, tDec.z );
// LOG( tB );
#endif
decart2spherical(tDec, LOC); return true;}
bool systemAnchor::convertToLocal(basicPosition * SP, C3D_DECART POS, C3D_SPH_RADIANS & LOC){ if (SP == NULL) { return false; } transform_3 * pTF = SP->getTransform(); C3D_DECART tDec; vector_3 A, B; // POS - is Relative to System Anchore!!
A[0] = getX() + POS.x; A[1] = getY() + POS.y; A[2] = getZ() + POS.z; pTF->get_vector_local(A, B); tDec.x = B[0]; tDec.y = B[1]; tDec.z = B[2]; decart2spherical(tDec, LOC); return true;}
bool systemAnchor::convertToSystem(basicPosition * SP, C3D_WGS84_LOC POS, C3D_DECART & LOC){ if (SP == NULL) { return false; } C3D_DECART tDec; tDec.z = POS.alt; m_SCC.LatLonToUTMXY(POS.lat, POS.lon, SP->getUTMZone(), tDec.x, tDec.y); LOC.x = tDec.x - getX(); LOC.y = tDec.y - getX(); LOC.z = tDec.z - getZ(); return true;}
bool systemAnchor::convertToSystem(basicPosition * SP, C3D_SPH_DEGREES POS, C3D_DECART & LOC){ if (SP == NULL) { return false; } transform_3 * pTF = SP->getTransform(); C3D_DECART tDec; vector_3 A, B; spherical2decart(POS, tDec); A[0] = tDec.x; A[1] = tDec.y; A[2] = tDec.z;#ifdef DEBUG_EXTRA
char tB[256]; LOG("C2S Sph.(deg) -> Dec."); sprintf(tB, "Local Decart: %.3f %.3f %.3f", A[0], A[1], A[2]); LOG(tB);#endif
pTF->get_vector_world(A, B);#ifdef DEBUG_EXTRA
sprintf(tB, "World Decart: %.3f %.3f %.3f", B[0], B[1], B[2]); LOG(tB);#endif
#ifdef DEBUG_EXTRA
sprintf(tB, "Systen Anchor Decart: %.3f %.3f %.3f", getX(), getY(), getZ()); LOG(tB);#endif
if (m_bUseJustLocalDiffCoords) { LOC.x = B[0]; LOC.y = B[1]; LOC.z = B[2]; } else { LOC.x = B[0] - getX(); LOC.y = B[1] - getY(); LOC.z = B[2] - getZ(); };#ifdef DEBUG_EXTRA
sprintf(tB, "Final System Decart: %.3f %.3f %.3f", LOC.x, LOC.y, LOC.z); LOG(tB);#endif
return true;}
bool systemAnchor::convertToSystem(basicPosition * SP, C3D_SPH_RADIANS POS, C3D_DECART & LOC){ if (SP == NULL) { return false; } transform_3 * pTF = SP->getTransform(); C3D_DECART tDec; vector_3 A, B; spherical2decart(POS, tDec); A[0] = tDec.x; A[1] = tDec.y; A[2] = tDec.z; pTF->get_vector_world(A, B); // LOC.x = B[0] + SP->getX() - getX();
LOC.x = B[0] - getX(); // LOC.y = B[1] + SP->getY() - getY();
LOC.y = B[1] - getY(); // LOC.z = B[2] + SP->getZ() - getZ();
LOC.z = B[2] - getZ(); return true;}
bool systemAnchor::convertToGlobal(basicPosition * SP, C3D_SPH_DEGREES POS, C3D_WGS84_LOC & LOC){ if (SP == NULL) { return false; } transform_3 * pTF = SP->getTransform(); C3D_DECART tDec; vector_3 A, B; spherical2decart(POS, tDec); A[0] = tDec.x; A[1] = tDec.y; A[2] = tDec.z; pTF->get_vector_world(A, B); // tDec.x = B[0] + SP->getX();
tDec.x = B[0] + SP->getX() - getX(); // tDec.y = B[1] + SP->getY();
tDec.y = B[1] + SP->getY() - getY(); // tDec.z = B[2] + SP->getZ();
tDec.z = B[2] + SP->getZ() - getZ(); m_SCC.UTMXYToLatLon(tDec.x, tDec.y, utmZone, SouthHemisphere, LOC.lat, LOC.lon); LOC.alt = tDec.z; return true;}
bool systemAnchor::convertToGlobal(basicPosition * SP, C3D_SPH_RADIANS POS, C3D_WGS84_LOC & LOC){ if (SP == NULL) { return false; } transform_3 * pTF = SP->getTransform(); C3D_DECART tDec; vector_3 A, B; spherical2decart(POS, tDec); A[0] = tDec.x; A[1] = tDec.y; A[2] = tDec.z; pTF->get_vector_world(A, B); // tDec.x = B[0] + SP->getX();
tDec.x = B[0] + SP->getX() - getX(); // tDec.y = B[1] + SP->getY();
tDec.y = B[1] + SP->getY() - getY(); // tDec.z = B[2] + SP->getZ();
tDec.z = B[2] + SP->getZ() - getZ(); m_SCC.UTMXYToLatLon(tDec.x, tDec.y, utmZone, SouthHemisphere, LOC.lat, LOC.lon); LOC.alt = tDec.z; return true;}
bool systemAnchor::convertToGlobal(basicPosition * SP, C3D_DECART POS, C3D_WGS84_LOC & LOC){ if (SP == NULL) { return false; } C3D_DECART tDec; tDec.x = POS.x + getX(); tDec.y = POS.y + getY(); tDec.z = POS.z + getZ(); m_SCC.UTMXYToLatLon(tDec.x, tDec.y, utmZone, SouthHemisphere, LOC.lat, LOC.lon); LOC.alt = tDec.z; return true;}
#ifdef DEBUG
#undef LOG
#undef LOG_ERROR
#endif
|