Renamed methods in SpiceManager

Started change of Time class
This commit is contained in:
Alexander Bock
2014-09-13 18:02:39 +02:00
parent 1101b656b8
commit b6246f6538
8 changed files with 194 additions and 57 deletions
@@ -226,7 +226,7 @@ TEST_F(SpiceManagerTest, stringToEphemerisTime){
char *date = "Thu Mar 20 12:53:29 PST 1997";
str2et_c(date, &control_ephemerisTime);
ephemerisTime = openspace::SpiceManager::ref().stringToEphemerisTime(date);
ephemerisTime = openspace::SpiceManager::ref().convertStringToTdbSeconds(date);
EXPECT_EQ(ephemerisTime, control_ephemerisTime) << "Ephemeries times differ / not found";
unload_c(LSK.c_str());
+13 -1
View File
@@ -119,7 +119,19 @@ public:
* \param epochString, A string representing an epoch.
* \return Corresponding ephemeris time, equivalent value in seconds past J2000, TDB.
*/
double stringToEphemerisTime(const std::string& epochString) const;
double convertStringToTdbSeconds(const std::string& epochString) const;
/**
* Convert the number of TDB seconds past the J2000 epoch into a human readable
* string representation. Fur further details, please refer to 'timout_c' in SPICE
* Documentation
*
* \param seconds The number of seconds that have passed since the J2000 epoch
* \param format The output format of the string
* (see ftp://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/timout_c.html)
* \return The formatted date string
*/
std::string convertTdbSecondsToString(double seconds, const std::string& format) const;
// Computing Positions of Spacecraft and Natural Bodies(SPK) ---------------------------- //
+48 -16
View File
@@ -1,31 +1,63 @@
#ifndef ENGINETIME_H
#define ENGINETIME_H
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
namespace openspace
{
#ifndef __TIME_H__
#define __TIME_H__
#include <string>
namespace openspace {
class Time {
public:
virtual ~Time();
static void init();
static void deinit();
static bool initialize();
static void deinitialize();
static Time& ref();
static bool isInitialized();
double advanceTime(double tickTime);
void setTime(double value);
double currentTime() const;
void setTimeUTC(std::string time);
std::string currentTimeUTC() const;
void setTime(const char* stringTime);
double getTime();
void setDeltaTime(double deltaT);
double deltaTime() const;
private:
static Time* this_;
Time(void);
Time(const Time& src);
Time& operator=(const Time& rhs);
Time();
Time(const Time& src) = delete;
Time& operator=(const Time& rhs) = delete;
double time_;
static Time* _instance;
double _time;
double _deltaTimePerSecond;
};
} // namespace openspace
#endif
#endif // __TIME_H__
+7 -2
View File
@@ -36,6 +36,7 @@
#include <openspace/util/spice.h>
#include <openspace/util/factorymanager.h>
#include <openspace/util/constants.h>
#include <openspace/util/spicemanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
@@ -92,8 +93,9 @@ OpenSpaceEngine::~OpenSpaceEngine()
delete _commandlineParser;
_commandlineParser = nullptr;
SpiceManager::deinitialize();
Spice::deinit();
Time::deinit();
Time::deinitialize();
DeviceIdentifier::deinit();
FileSystem::deinitialize();
LogManager::deinitialize();
@@ -323,7 +325,8 @@ bool OpenSpaceEngine::initialize()
SysCap.logCapabilities();
// initialize OpenSpace helpers
Time::init();
SpiceManager::initialize();
Time::initialize();
Spice::init();
Spice::ref().loadDefaultKernels();
FactoryManager::initialize();
@@ -463,6 +466,8 @@ void OpenSpaceEngine::preSynchronization()
_interactionHandler->update(dt);
_interactionHandler->lockControls();
Time::ref().advanceTime(dt);
}
#ifdef FLARE_ONLY
_flare->preSync();
+20
View File
@@ -27,6 +27,7 @@
#include <openspace/engine/openspaceengine.h>
#include <openspace/scenegraph/scenegraph.h>
#include <openspace/util/camera.h>
#include <openspace/util/time.h>
#include "sgct.h"
@@ -203,6 +204,24 @@ void RenderEngine::render()
const psc origin = OsEng.interactionHandler().getOrigin();
const PowerScaledScalar pssl = (position - origin).length();
const std::string time = Time::ref().currentTimeUTC().c_str();
LINFO(time);
Freetype::print(
sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE),
FONT_SIZE, FONT_SIZE * 18, "Date: %s", time.c_str()
);
Freetype::print(
sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE),
FONT_SIZE, FONT_SIZE * 16, "Avg. Frametime: %.10f", sgct::Engine::instance()->getAvgDt()
);
Freetype::print(
sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE),
FONT_SIZE, FONT_SIZE * 14, "Drawtime: %.10f", sgct::Engine::instance()->getDrawTime()
);
Freetype::print(
sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE),
FONT_SIZE, FONT_SIZE * 12, "Frametime: %.10f", sgct::Engine::instance()->getDt()
);
Freetype::print(
sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE),
FONT_SIZE, FONT_SIZE * 10, "Origin: (%.5f, %.5f, %.5f, %.5f)", origin[0],
@@ -222,6 +241,7 @@ void RenderEngine::render()
Freetype::print(
sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE),
FONT_SIZE, FONT_SIZE * 2, "Scaling: (%.10f, %.2f)", scaling[0], scaling[1]);
}
#endif
+3 -3
View File
@@ -128,7 +128,7 @@ bool Spice::spk_getPosition(const std::string &target, const std::string &origin
assert(this_);
assert(Time::ref().isInitialized());
SpiceDouble et = Time::ref().getTime();
SpiceDouble et = Time::ref().currentTime();
SpiceDouble lt;
spkpos_c(target.c_str(), et, "J2000", "LT+S", origin.c_str(), state, &lt);
int failed = failed_c();
@@ -143,7 +143,7 @@ void Spice::spk_getPosition(int target, int origin, double state[3]) {
assert(this_);
assert(Time::ref().isInitialized());
SpiceDouble et = Time::ref().getTime();
SpiceDouble et = Time::ref().currentTime();
SpiceDouble lt;
spkezp_c (target, et, "J2000", "NONE", origin, state, &lt);
}
@@ -156,7 +156,7 @@ bool Spice::spk_getOrientation(const std::string &target, double state[3][3]) {
// ghoul logging
std::string _loggerCat = "Spice::spk_getOrientation";
SpiceDouble et = Time::ref().getTime();
SpiceDouble et = Time::ref().currentTime();
std::string newname = "IAU_";
newname += target;
pxform_c ( "J2000", newname.c_str(), et, state );
+21 -1
View File
@@ -207,12 +207,32 @@ bool SpiceManager::getValueFromID(const std::string& bodyname,
return true;
}
double SpiceManager::stringToEphemerisTime(const std::string& epochString) const{
double SpiceManager::convertStringToTdbSeconds(const std::string& epochString) const{
double et;
str2et_c(epochString.c_str(), &et);
return et;
}
std::string SpiceManager::convertTdbSecondsToString(double seconds,
const std::string& format) const
{
const int bufferSize = 128;
SpiceChar buffer[bufferSize];
timout_c(seconds, format.c_str(), bufferSize - 1, buffer);
int failed = failed_c();
if (failed) {
char msg[1024];
getmsg_c("LONG", 1024, msg);
//LERROR("Error retrieving position of target '" + target + "'");
LERROR("Spice reported: " + std::string(msg));
reset_c();
return "";
}
return std::string(buffer);
}
bool SpiceManager::getTargetPosition(const std::string& target,
double ephemerisTime,
const std::string& referenceFrame,
+81 -33
View File
@@ -1,62 +1,110 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
// open space includes
#include <openspace/util/time.h>
#include <openspace/interaction/interactionhandler.h>
// std includes
#include <openspace/interaction/interactionhandler.h>
#include <openspace/util/spicemanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <cassert>
// spice includes
#include "SpiceUsr.h"
#include <ghoul/filesystem/filesystem.h>
namespace {
const std::string _loggerCat = "Time";
}
namespace openspace {
Time* Time::this_ = nullptr;
Time::Time() {
time_ = 0.0;
Time* Time::_instance = nullptr;
Time::Time()
: _time(-1.0)
, _deltaTimePerSecond(1.0)
{
SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/naif0010.tls"), "leap");
// load spice time kernel
furnsh_c (absPath("${OPENSPACE_DATA}/spice/naif0010.tls").c_str());
//furnsh_c (absPath("${OPENSPACE_DATA}/spice/naif0010.tls").c_str());
// convert UTC to ET
str2et_c ( "2006 JAN 31 01:00", &time_ );
//str2et_c ( "2006 JAN 31 01:00", &_time );
}
Time::~Time() {
bool Time::initialize() {
assert( _instance == nullptr);
_instance = new Time();
return true;
}
void Time::init() {
assert( this_ == nullptr);
this_ = new Time();
}
void Time::deinit() {
assert(this_);
delete this_;
this_ = nullptr;
void Time::deinitialize() {
assert(_instance);
delete _instance;
_instance = nullptr;
}
Time& Time::ref() {
assert(this_);
return *this_;
assert(_instance);
return *_instance;
}
bool Time::isInitialized() {
return this_ != nullptr;
return _instance != nullptr;
}
void Time::setTime(const char* stringTime) {
assert(this_);
// convert UTC to ET
str2et_c ( stringTime, &time_ );
//void Time::setTime(const char* stringTime) {
// assert(_instance);
// // convert UTC to ET
// //str2et_c ( stringTime, &_time );
//}
void Time::setTime(double value) {
_time = std::move(value);
}
double Time::getTime() {
assert(this_);
return time_;
double Time::currentTime() const {
assert(_instance);
return _time;
}
double Time::advanceTime(double tickTime) {
return _time += _deltaTimePerSecond * tickTime;
}
void Time::setDeltaTime(double deltaT) {
_deltaTimePerSecond = std::move(deltaT);
}
double Time::deltaTime() const {
return _deltaTimePerSecond;
}
void Time::setTimeUTC(std::string time) {
_time = SpiceManager::ref().convertStringToTdbSeconds(std::move(time));
}
std::string Time::currentTimeUTC() const {
return SpiceManager::ref().convertTdbSecondsToString(_time, "MON DD,YYYY HR:MN:SC.#### (TDB) ::TDB");
}
} // namespace openspace