Merge branch 'develop' into release/ips

Conflicts:
	tests/main.cpp
This commit is contained in:
Alexander Bock
2016-06-17 11:31:11 +02:00
26 changed files with 594 additions and 346 deletions
+1
View File
@@ -191,6 +191,7 @@ void MainWindow::initialize() {
ghoul::logging::LogManager::initialize(ghoul::logging::LogManager::LogLevel::Debug);
LogMgr.addLog( std::make_unique< ghoul::logging::ConsoleLog >() );
// TODO: This can crash the system in cases where the logfile can't be created ---abock
LogMgr.addLog( std::make_unique< ghoul::logging::HTMLLog >("LauncherLog.html", ghoul::logging::HTMLLog::Append::No) );
LogMgr.addLog( std::make_unique< QLog >() );
@@ -53,6 +53,10 @@ public:
static const std::string KeyLuaDocumentationType;
/// The key that stores the save location of the Lua documentation
static const std::string KeyLuaDocumentationFile;
/// The key that stores the type of scripting log that should be stored
static const std::string KeyScriptLogType;
/// The key that stores the save location of the scripting log
static const std::string KeyScriptLogFile;
/// The key that stores the type of Property documentation that should be stored
static const std::string KeyPropertyDocumentationType;
/// The key that stores the save location of the Property documentation
+3 -1
View File
@@ -50,6 +50,7 @@ class RenderEngine;
class SyncBuffer;
class ModuleEngine;
class WindowWrapper;
class SettingsEngine;
namespace interaction { class InteractionHandler; }
namespace gui { class GUI; }
@@ -130,13 +131,14 @@ private:
std::unique_ptr<ghoul::cmdparser::CommandlineParser> _commandlineParser;
std::unique_ptr<LuaConsole> _console;
std::unique_ptr<ModuleEngine> _moduleEngine;
std::unique_ptr<SettingsEngine> _settingsEngine;
#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED
std::unique_ptr<gui::GUI> _gui;
#endif
std::unique_ptr<network::ParallelConnection> _parallelConnection;
std::unique_ptr<WindowWrapper> _windowWrapper;
std::unique_ptr<ghoul::fontrendering::FontManager> _fontManager;
// Others
std::unique_ptr<properties::PropertyOwner> _globalPropertyNamespace;
std::unique_ptr<SyncBuffer> _syncBuffer;
+44
View File
@@ -0,0 +1,44 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* 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. *
****************************************************************************************/
#ifndef __SETTINGSENGINE_H__
#define __SETTINGSENGINE_H__
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/scalarproperty.h>
namespace openspace {
class SettingsEngine : public properties::PropertyOwner {
public:
SettingsEngine();
private:
properties::FloatProperty _eyeSeparation;
};
} // namespace openspace
#endif //#ifndef __SETTINGSENGINE_H__
@@ -52,6 +52,7 @@ public:
glm::mat4 viewProjectionMatrix() const override;
void setNearFarClippingPlane(float near, float far) override;
void setEyeSeparationDistance(float distance) override;
glm::ivec4 viewportPixelCoordinates() const override;
@@ -140,6 +140,12 @@ public:
*/
virtual void setNearFarClippingPlane(float near, float far);
/**
* Sets the stereo eye separation distance for the render engine.
* \param distance The distance between eyes for stereo rendering.
*/
virtual void setEyeSeparationDistance(float distance);
/**
* Returns the location and size of the current viewport (<code>x</code>,
* <code>width</code>, <code>y</code>, and <code>height</code>). If there is only a
@@ -48,9 +48,9 @@ namespace properties {
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultMaximumValue<TYPE>(); \
\
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultSteppingValue<TYPE>(); \
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultSteppingValue<TYPE>(); \
\
template <> \
template <> \
@@ -133,12 +133,12 @@ namespace properties {
return DEFAULT_MAX_VALUE; \
} \
\
template <> \
template <> \
template <> \
template <> \
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultSteppingValue<TYPE>() \
{ \
{ \
return DEFAULT_STEPPING; \
} \
} \
\
template <> \
template <> \
@@ -283,16 +283,20 @@ template <typename T>
bool NumericalProperty<T>::setLuaValue(lua_State* state)
{
bool success = false;
T value = PropertyDelegate<NumericalProperty<T>>::template fromLuaValue<T>(state, success);
T value = PropertyDelegate<NumericalProperty<T>>::template fromLuaValue<T>(
state, success
);
if (success)
TemplateProperty<T>::setValue(value);
TemplateProperty<T>::setValue(std::move(value));
return success;
}
template <typename T>
bool NumericalProperty<T>::getLuaValue(lua_State* state) const
{
bool success = PropertyDelegate<NumericalProperty<T>>::template toLuaValue<T>(state, TemplateProperty<T>::_value);
bool success = PropertyDelegate<NumericalProperty<T>>::template toLuaValue<T>(
state, TemplateProperty<T>::_value
);
return success;
}
@@ -303,16 +307,20 @@ int NumericalProperty<T>::typeLua() const {
template <typename T>
bool NumericalProperty<T>::getStringValue(std::string& value) const {
bool success = PropertyDelegate<NumericalProperty<T>>::template toString<T>(value, TemplateProperty<T>::_value);
bool success = PropertyDelegate<NumericalProperty<T>>::template toString<T>(
value, TemplateProperty<T>::_value
);
return success;
}
template <typename T>
bool NumericalProperty<T>::setStringValue(std::string value) {
bool success = false;
T thisValue = PropertyDelegate<NumericalProperty<T>>::template fromString<T>(value, success);
T thisValue = PropertyDelegate<NumericalProperty<T>>::template fromString<T>(
value, success
);
if (success)
TemplateProperty<T>::set(ghoul::any(thisValue));
TemplateProperty<T>::set(ghoul::any(std::move(thisValue)));
return success;
}
@@ -32,7 +32,7 @@ namespace properties {
REGISTER_TEMPLATEPROPERTY_HEADER(BoolProperty, bool);
REGISTER_NUMERICALPROPERTY_HEADER(CharProperty, char);
REGISTER_NUMERICALPROPERTY_HEADER(WCharProperty, wchar_t);
//REGISTER_NUMERICALPROPERTY_HEADER(WCharProperty, wchar_t);
REGISTER_NUMERICALPROPERTY_HEADER(SignedCharProperty, signed char);
REGISTER_NUMERICALPROPERTY_HEADER(UCharProperty, unsigned char);
REGISTER_NUMERICALPROPERTY_HEADER(ShortProperty, short);
+14 -1
View File
@@ -102,6 +102,8 @@ public:
bool writeDocumentation(const std::string& filename, const std::string& type) const;
bool writeLog(const std::string& script);
void serialize(SyncBuffer* syncBuffer);
void deserialize(SyncBuffer* syncBuffer);
@@ -111,7 +113,9 @@ public:
void preSynchronization();
void queueScript(const std::string &script);
void setLogFile(const std::string& filename, const std::string& type);
std::vector<std::string> cachedScripts();
std::vector<std::string> allLuaFunctions() const;
@@ -122,6 +126,7 @@ public:
void cacheScript(const std::string &library, const std::string &function, const std::string &script);
private:
bool registerLuaLibrary(lua_State* state, const LuaLibrary& library);
void addLibraryFunctions(lua_State* state, const LuaLibrary& library, bool replace);
@@ -142,6 +147,14 @@ private:
//parallel variables
std::map<std::string, std::map<std::string, std::string>> _cachedScripts;
std::mutex _cachedScriptsMutex;
//logging variables
bool _logFileExists = false;
bool _logScripts = true;
std::string _logType;
std::string _logFilename;
};
} // namespace scripting
+1
View File
@@ -74,6 +74,7 @@ public:
GuiPropertyComponent _property;
// GuiPropertyComponent _iSWAproperty;
GuiPropertyComponent _screenSpaceProperty;
GuiPropertyComponent _globalProperty;
GuiTimeComponent _time;
GuiIswaComponent _iswa;
+6
View File
@@ -206,6 +206,7 @@ void GUI::initialize() {
_property.initialize();
_screenSpaceProperty.initialize();
_globalProperty.initialize();
_performance.initialize();
_help.initialize();
_iswa.initialize();
@@ -254,6 +255,7 @@ void GUI::initializeGL() {
_property.initializeGL();
_screenSpaceProperty.initializeGL();
_globalProperty.initializeGL();
_performance.initializeGL();
_help.initializeGL();
_iswa.initializeGL();
@@ -267,6 +269,7 @@ void GUI::deinitializeGL() {
_property.deinitializeGL();
_screenSpaceProperty.deinitializeGL();
_globalProperty.deinitializeGL();
_performance.deinitializeGL();
_help.deinitializeGL();
_iswa.deinitializeGL();
@@ -302,6 +305,8 @@ void GUI::endFrame() {
_property.render();
if (_screenSpaceProperty.isEnabled())
_screenSpaceProperty.render();
if (_globalProperty.isEnabled())
_globalProperty.render();
if (_performance.isEnabled())
_performance.render();
if (_help.isEnabled())
@@ -404,6 +409,7 @@ void GUI::renderMainWindow() {
ImGui::Checkbox("Scene Graph Properties", &_property._isEnabled);
ImGui::Checkbox("ScreenSpace Properties", &_screenSpaceProperty._isEnabled);
ImGui::Checkbox("Global Properties", &_globalProperty._isEnabled);
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
ImGui::Checkbox("iSWA", &_iswa._isEnabled);
#endif
+4
View File
@@ -53,6 +53,10 @@ return {
Type = "text",
File = "${BASE_PATH}/Properties.txt"
},
ScriptLogFile = {
Type = "text",
File = "${BASE_PATH}/ScriptLog.txt"
},
DownloadRequestURL = "http://openspace.itn.liu.se/request.cgi",
RenderingMethod = "Framebuffer"
--RenderingMethod = "ABuffer" -- alternative: "Framebuffer"
+1 -5
View File
@@ -53,11 +53,7 @@ float pscDepth(vec4 position) {
// For now: simply convert power scaled coordinates to a linear scale.
// TODO: get rid of power scaled coordinates and use scale graph instead.
// return (position.w + log(abs(position.z) + 1/pow(k, position.w))/log(k)) / 27.0;
if (position.z < 0) {
return safeLength(pscToLinear(position));
} else {
return -safeLength(pscToLinear(position));
}
return safeLength(pscToLinear(position));
}
+2
View File
@@ -30,6 +30,7 @@ set(OPENSPACE_SOURCE
${OPENSPACE_BASE_DIR}/src/engine/moduleengine.cpp
${OPENSPACE_BASE_DIR}/src/engine/moduleengine_lua.inl
${OPENSPACE_BASE_DIR}/src/engine/openspaceengine.cpp
${OPENSPACE_BASE_DIR}/src/engine/settingsengine.cpp
${OPENSPACE_BASE_DIR}/src/engine/wrapper/sgctwindowwrapper.cpp
${OPENSPACE_BASE_DIR}/src/engine/wrapper/windowwrapper.cpp
${OPENSPACE_BASE_DIR}/src/interaction/controller.cpp
@@ -104,6 +105,7 @@ set(OPENSPACE_HEADER
${OPENSPACE_BASE_DIR}/include/openspace/engine/logfactory.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/moduleengine.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/openspaceengine.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/settingsengine.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/wrapper/sgctwindowwrapper.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/wrapper/windowwrapper.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/controller.h
+2
View File
@@ -45,6 +45,8 @@ const string ConfigurationManager::KeyFonts = "Fonts";
const string ConfigurationManager::KeyConfigSgct = "SGCTConfig";
const string ConfigurationManager::KeyLuaDocumentationType = "LuaDocumentationFile.Type";
const string ConfigurationManager::KeyLuaDocumentationFile = "LuaDocumentationFile.File";
const string ConfigurationManager::KeyScriptLogType = "ScriptLogFile.Type";
const string ConfigurationManager::KeyScriptLogFile = "ScriptLogFile.File";
const string ConfigurationManager::KeyPropertyDocumentationType =
"PropertyDocumentationFile.Type";
const string ConfigurationManager::KeyPropertyDocumentationFile =
+10
View File
@@ -30,6 +30,7 @@
#include <openspace/engine/downloadmanager.h>
#include <openspace/engine/logfactory.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/engine/settingsengine.h>
#include <openspace/engine/wrapper/windowwrapper.h>
#include <openspace/interaction/interactionhandler.h>
#include <openspace/interaction/keyboardcontroller.h>
@@ -109,6 +110,10 @@ namespace {
namespace openspace {
namespace properties {
class Property;
}
OpenSpaceEngine* OpenSpaceEngine::_engine = nullptr;
OpenSpaceEngine::OpenSpaceEngine(std::string programName,
@@ -123,6 +128,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName,
))
, _console(new LuaConsole)
, _moduleEngine(new ModuleEngine)
, _settingsEngine(new SettingsEngine)
#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED
, _gui(new gui::GUI)
#endif
@@ -135,6 +141,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName,
{
_interactionHandler->setPropertyOwner(_globalPropertyNamespace.get());
_globalPropertyNamespace->addPropertySubOwner(_interactionHandler.get());
_globalPropertyNamespace->addPropertySubOwner(_settingsEngine.get());
FactoryManager::initialize();
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<Renderable>>()
@@ -165,6 +172,7 @@ OpenSpaceEngine::~OpenSpaceEngine() {
_commandlineParser = nullptr;
_console = nullptr;
_moduleEngine = nullptr;
_settingsEngine = nullptr;
#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED
_gui = nullptr;
#endif
@@ -429,6 +437,8 @@ bool OpenSpaceEngine::initialize() {
#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED
LINFO("Initializing GUI");
_gui->initialize();
for (properties::Property* p : _settingsEngine->propertiesRecursive())
_gui->_globalProperty.registerProperty(p);
#endif
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
+41
View File
@@ -0,0 +1,41 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* 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. *
****************************************************************************************/
#include <openspace/engine/settingsengine.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/wrapper/windowwrapper.h>
namespace openspace {
SettingsEngine::SettingsEngine() :
_eyeSeparation("eyeSeparation", "Eye Separation" , 0.f, 0.f, 10.f)
{
addProperty(_eyeSeparation);
setName("Global");
_eyeSeparation.onChange(
[this](){ OsEng.windowWrapper().setEyeSeparationDistance(_eyeSeparation); });
}
}
+5 -1
View File
@@ -119,7 +119,11 @@ glm::mat4 SGCTWindowWrapper::viewProjectionMatrix() const {
void SGCTWindowWrapper::setNearFarClippingPlane(float nearPlane, float farPlane) {
sgct::Engine::instance()->setNearAndFarClippingPlanes(nearPlane, farPlane);
}
void SGCTWindowWrapper::setEyeSeparationDistance(float distance) {
sgct::Engine::instance()->setEyeSeparation(distance);
}
glm::ivec4 SGCTWindowWrapper::viewportPixelCoordinates() const {
int x1, xSize, y1, ySize;
sgct::Engine::instance()->getCurrentWindowPtr()->getCurrentViewportPixelCoords(x1,
+2
View File
@@ -77,6 +77,8 @@ glm::mat4 WindowWrapper::viewProjectionMatrix() const {
}
void WindowWrapper::setNearFarClippingPlane(float near, float far) {}
void WindowWrapper::setEyeSeparationDistance(float distance) {}
glm::ivec4 WindowWrapper::viewportPixelCoordinates() const {
return glm::ivec4(
@@ -46,6 +46,7 @@ PerformanceMeasurement::PerformanceMeasurement(std::string identifier,
}
PerformanceMeasurement::~PerformanceMeasurement() {
glFinish();
auto endTime = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
endTime - _startTime).count();
+1 -1
View File
@@ -366,7 +366,7 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
}
}
// If a LuaDocumentationFile was specified, generate it now
// If a PropertyDocumentationFile was specified, generate it now
const bool hasType = OsEng.configurationManager().hasKey(ConfigurationManager::KeyPropertyDocumentationType);
const bool hasFile = OsEng.configurationManager().hasKey(ConfigurationManager::KeyPropertyDocumentationFile);
if (hasType && hasFile) {
+72 -4
View File
@@ -24,12 +24,15 @@
#include <openspace/scripting/scriptengine.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <openspace/util/syncbuffer.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/lua/lua_helper.h>
#include <openspace/engine/configurationmanager.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/network/parallelconnection.h>
#include <ghoul/lua/lua_helper.h>
#include <openspace/util/syncbuffer.h>
#include <fstream>
#include <iomanip>
@@ -140,7 +143,12 @@ bool ScriptEngine::runScript(const std::string& script) {
LWARNING("Script was empty");
return false;
}
if (_logScripts) {
// Write command to log before it's executed
writeLog(script);
}
try {
ghoul::lua::runScript(_state, script);
}
@@ -561,6 +569,66 @@ bool ScriptEngine::writeDocumentation(const std::string& filename, const std::st
}
}
bool ScriptEngine::writeLog(const std::string& script) {
// Check that logging is enabled and initialize if necessary
if (!_logFileExists) {
// If a ScriptLogFile was specified, generate it now
const bool hasType = OsEng.configurationManager()
.hasKey(ConfigurationManager::KeyScriptLogType);
const bool hasFile = OsEng.configurationManager()
.hasKey(ConfigurationManager::KeyScriptLogFile);
if (hasType && hasFile) {
OsEng.configurationManager()
.getValue(ConfigurationManager::KeyScriptLogType, _logType);
OsEng.configurationManager()
.getValue(ConfigurationManager::KeyScriptLogFile, _logFilename);
_logFilename = absPath(_logFilename);
_logFileExists = true;
LDEBUG("Using script log of type '" << _logType <<
"' to file '" << _logFilename << "'");
// Test file and clear previous input
std::ofstream file(_logFilename, std::ofstream::out | std::ofstream::trunc);
if (!file.good()) {
LERROR("Could not open file '" << _logFilename
<< "' for logging scripts");
return false;
}
} else {
LDEBUG("No script log specified in 'openspace.cfg.' To log, set '"
<< ConfigurationManager::KeyScriptLogType << " and "
<< ConfigurationManager::KeyScriptLogFile
<< " in configuration table.");
_logScripts = false;
return false;
}
}
if (_logType == "text") {
// Simple text output to logfile
std::ofstream file(_logFilename, std::ofstream::app);
if (!file.good()) {
LERROR("Could not open file '" << _logFilename << "' for logging scripts");
return false;
}
file << script << std::endl;
file.close();
}
else {
LERROR("Undefined type '" << _logType << "' for script documentation");
_logScripts = false;
return false;
}
return true;
}
void ScriptEngine::serialize(SyncBuffer* syncBuffer){
syncBuffer->encode(_currentSyncedScript);
_currentSyncedScript.clear();
+25 -8
View File
@@ -31,6 +31,7 @@
#include <ghoul/lua/ghoul_lua.h>
// test files
<<<<<<< HEAD
//#include <test_common.inl>
//#include <test_spicemanager.inl>
//#include <test_scenegraphloader.inl>
@@ -52,6 +53,15 @@
//#include <test_concurrentjobmanager.inl>
//#include <test_screenspaceimage.inl>
//#include <test_iswamanager.inl>
=======
#include <test_common.inl>
#include <test_spicemanager.inl>
#include <test_scenegraphloader.inl>
#include <test_luaconversions.inl>
#include <test_powerscalecoordinates.inl>
#include <test_screenspaceimage.inl>
#include <test_iswamanager.inl>
>>>>>>> develop
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/wrapper/windowwrapper.h>
@@ -66,19 +76,26 @@ using namespace ghoul::filesystem;
using namespace ghoul::logging;
namespace {
std::string _loggerCat = "OpenSpaceTest";
std::string _loggerCat = "OpenSpaceTest";
}
int main(int argc, char** argv) {
std::vector<std::string> args;
openspace::OpenSpaceEngine::create(argc, argv, std::make_unique<openspace::WindowWrapper>(), args);
std::vector<std::string> args;
openspace::OpenSpaceEngine::create(argc, argv, std::make_unique<openspace::WindowWrapper>(), args);
testing::InitGoogleTest(&argc, argv);
testing::InitGoogleTest(&argc, argv);
int returnVal = RUN_ALL_TESTS();
//testing::internal::CaptureStdout();
//testing::internal::CaptureStderr();
bool b = RUN_ALL_TESTS();
//std::string output = testing::internal::GetCapturedStdout();
//std::string error = testing::internal::GetCapturedStderr();
// keep console from closing down
int dummy; std::cin >> dummy;
//std::ofstream o("output.txt");
//o << output;
return returnVal;
//std::ofstream e("error.txt");
//e << error;
return b;
}
+28 -27
View File
@@ -21,13 +21,17 @@
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
#include "gtest/gtest.h"
#define private public
#include <modules/iswa/util/iswamanager.h>
#define private private
#include <openspace/engine/downloadmanager.h>
#include <openspace/util/time.h>
/*
* For each test the following is run:
* Constructor() -> setUp() -> test -> tearDown() -> Deconstructor()
@@ -35,49 +39,46 @@
namespace openspace {
class IswaManagerTest : public testing::Test{
class IswaManagerTest : public testing::Test {
protected:
IswaManagerTest()
{
IswaManager::initialize();
}
IswaManagerTest() {
DownloadManager::initialize("", 0);
IswaManager::initialize();
}
~IswaManagerTest(){
IswaManager::deinitialize();
}
~IswaManagerTest() {
IswaManager::deinitialize();
DownloadManager::deinitialize();
}
void reset() {}
//std::shared_ptr<ISWAManager> iSWAManager;
void reset() {}
};
TEST_F(IswaManagerTest, initialize){
IswaManager::deinitialize();
IswaManager::deinitialize();
ASSERT_FALSE(IswaManager::isInitialized()) << "IswaManager is initialized before initialize call";
ASSERT_TRUE(!IswaManager::isInitialized()) << "IswaManager is initialized before initialize call";
IswaManager::initialize();
IswaManager::initialize();
ASSERT_TRUE(IswaManager::isInitialized()) << "IswaManager is not initialized after initialize call";
ASSERT_TRUE(IswaManager::isInitialized()) << "IswaManager is not initialized after initialize call";
ASSERT_NE(&IswaManager::ref(), nullptr) << "IswaManager ref() is not a nullptr";
ASSERT_NE(&IswaManager::ref(), nullptr) << "IswaManager ref() is not a nullptr";
EXPECT_EQ(&IswaManager::ref(), &IswaManager::ref()) << "IswaManager ref() returns the same object twice";
EXPECT_EQ(&IswaManager::ref(), &IswaManager::ref()) << "IswaManager ref() returns the same object twice";
}
TEST_F(IswaManagerTest, iswaUrl){
//OsEng.loadSpiceKernels();
//Time::ref().setTime(double(100000.0));
//Time::ref().preSynchronization();
//Time::ref().postSynchronizationPreDraw();
//std::string url = ISWAManager::ref().iSWAurl(7);
//std::string expectedUrl = "http://iswa2.ccmc.gsfc.nasa.gov/IswaSystemWebApp/iSWACygnetStreamer?timestamp=2000-01-02%2015:45:35&window=-1&cygnetId=7";
//OsEng.loadSpiceKernels();
//Time::ref().setTime(double(100000.0));
//Time::ref().preSynchronization();
//Time::ref().postSynchronizationPreDraw();
//std::string url = ISWAManager::ref().iSWAurl(7);
//std::string expectedUrl = "http://iswa2.ccmc.gsfc.nasa.gov/IswaSystemWebApp/iSWACygnetStreamer?timestamp=2000-01-02%2015:45:35&window=-1&cygnetId=7";
//EXPECT_EQ(expectedUrl, url);
//EXPECT_EQ(expectedUrl, url);
}
}//namespace openspace
+24 -24
View File
@@ -33,27 +33,27 @@
class LuaConversionTest : public testing::Test {
protected:
lua_State* state;
lua_State* state;
LuaConversionTest() {
state = luaL_newstate();
luaL_openlibs(state);
LuaConversionTest() {
state = luaL_newstate();
luaL_openlibs(state);
}
~LuaConversionTest() {
lua_close(state);
~LuaConversionTest() {
lua_close(state);
}
void reset() {
lua_close(state);
state = luaL_newstate();
luaL_openlibs(state);
}
void reset() {
lua_close(state);
state = luaL_newstate();
luaL_openlibs(state);
}
};
TEST_F(LuaConversionTest, LuaExecution) {
int status = luaL_loadstring(state, "");
EXPECT_EQ(status, LUA_OK);
int status = luaL_loadstring(state, "");
EXPECT_EQ(status, LUA_OK);
}
#define CONVERSION_TEST_TEMPLATE(__NAME__, __TYPE__, __VALUE__) \
@@ -89,7 +89,7 @@ TEST_F(LuaConversionTest, LuaExecution) {
CONVERSION_TEST_TEMPLATE(Bool, bool, true);
CONVERSION_TEST_NUMERICAL(Char, char, 1);
CONVERSION_TEST_NUMERICAL(WChar, wchar_t, 1);
//CONVERSION_TEST_NUMERICAL(WChar, wchar_t, 1);
CONVERSION_TEST_NUMERICAL(SignedChar, signed char, 1);
CONVERSION_TEST_NUMERICAL(UnsignedChar, unsigned char, 1);
CONVERSION_TEST_NUMERICAL(Short, short, 1);
@@ -138,14 +138,14 @@ CONVERSION_TEST_NUMERICAL(DMat4x4, glm::dmat4x4, glm::dmat4x4(1.f));
TEST_F(LuaConversionTest, String)
{
using namespace openspace::properties;
bool success
= PropertyDelegate<TemplateProperty<std::string>>::toLuaValue<std::string>(
state, "value");
EXPECT_TRUE(success) << "toLuaValue";
std::string value = "";
value = PropertyDelegate<TemplateProperty<std::string>>::fromLuaValue<std::string>(
state, success);
EXPECT_TRUE(success) << "fromLuaValue";
EXPECT_EQ(value, "value") << "fromLuaValue";
using namespace openspace::properties;
bool success
= PropertyDelegate<TemplateProperty<std::string>>::toLuaValue<std::string>(
state, "value");
EXPECT_TRUE(success) << "toLuaValue";
std::string value = "";
value = PropertyDelegate<TemplateProperty<std::string>>::fromLuaValue<std::string>(
state, success);
EXPECT_TRUE(success) << "fromLuaValue";
EXPECT_EQ(value, "value") << "fromLuaValue";
}
+274 -260
View File
@@ -28,17 +28,17 @@
class SpiceManagerTest : public testing::Test{
protected:
SpiceManagerTest(){
openspace::SpiceManager::initialize();
}
~SpiceManagerTest(){
openspace::SpiceManager::deinitialize();
}
SpiceManagerTest() {
//openspace::SpiceManager::initialize();
}
~SpiceManagerTest() {
//openspace::SpiceManager::deinitialize();
}
void reset() {
openspace::SpiceManager::deinitialize();
openspace::SpiceManager::initialize();
}
void reset() {
openspace::SpiceManager::deinitialize();
openspace::SpiceManager::initialize();
}
};
//global constants
@@ -60,330 +60,344 @@ double abs_error = 0.00001;
// In this testclass only a handset of the testfunctions require a single kernel.
// The remaining methods rely on multiple kernels, loaded as a SPICE 'meta-kernel'.
#define KERNEL(param) int kernelID = -1; \
kernelID = openspace::SpiceManager::ref().loadKernel(param); \
EXPECT_TRUE(kernelID != -1) << "loadKernel did not return proper id"; \
return kernelID; \
kernelID = openspace::SpiceManager::ref().loadKernel(param); \
EXPECT_TRUE(kernelID != -1) << "loadKernel did not return proper id"; \
return kernelID; \
int loadMetaKernel() { KERNEL(META); }
int loadLSKKernel() { KERNEL(LSK); }
int loadPCKKernel() { KERNEL(PCK); }
std::string fileType(char type[]){
std::string str(type);
return str;
std::string str(type);
return str;
}
// Try loading single kernel
TEST_F(SpiceManagerTest, loadSingleKernel){
loadLSKKernel();
//naif0008.tls is a text file, check if loaded.
SpiceBoolean found;
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
ASSERT_TRUE(found == SPICETRUE) << "Kernel not loaded";
unload_c(LSK.c_str());
TEST_F(SpiceManagerTest, loadSingleKernel) {
loadLSKKernel();
// naif0008.tls is a text file, check if loaded.
SpiceBoolean found;
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
ASSERT_TRUE(found == SPICETRUE) << "Kernel not loaded";
unload_c(LSK.c_str());
}
// Try loading multiple kernels via META file
TEST_F(SpiceManagerTest, loadMetaKernel){
loadMetaKernel();
// typeArr[] has values ordered to match each type of kernel
// as specified in the 'metaKernel.tm' file
std::string typeArr[nrMetaKernels] = { "META", "TEXT", "TEXT",
"SPK", "SPK", "SPK",
"TEXT", "CK", "TEXT" };
// If one of the kernels does not load we expect a mismatch
for (int i = 0; i < nrMetaKernels; i++){
SpiceBoolean found;
kdata_c(i, "all", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
EXPECT_EQ(fileType(filtyp), typeArr[i]) << "One or more kernels did not load properly";
}
unload_c(META.c_str());
TEST_F(SpiceManagerTest, loadMetaKernel) {
loadMetaKernel();
// typeArr[] has values ordered to match each type of kernel
// as specified in the 'metaKernel.tm' file
std::string typeArr[nrMetaKernels] = { "META", "TEXT", "TEXT",
"SPK", "SPK", "SPK",
"TEXT", "CK", "TEXT" };
// If one of the kernels does not load we expect a mismatch
for (int i = 0; i < nrMetaKernels; i++){
SpiceBoolean found;
kdata_c(i, "all", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
EXPECT_EQ(fileType(filtyp), typeArr[i]) << "One or more kernels did not load properly";
}
unload_c(META.c_str());
}
// Try unloading kernel using user assigned keyword
TEST_F(SpiceManagerTest, unloadKernelString){
loadLSKKernel();
//naif0008.tls is a text file, check if loaded.
SpiceBoolean found;
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
ASSERT_TRUE(found == SPICETRUE);
TEST_F(SpiceManagerTest, unloadKernelString) {
loadLSKKernel();
// naif0008.tls is a text file, check if loaded.
SpiceBoolean found;
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
ASSERT_TRUE(found == SPICETRUE);
//unload using string keyword
openspace::SpiceManager::ref().unloadKernel(LSK);
// unload using string keyword
openspace::SpiceManager::ref().unloadKernel(LSK);
found = SPICEFALSE;
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
EXPECT_FALSE(found == SPICETRUE);
found = SPICEFALSE;
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
EXPECT_FALSE(found == SPICETRUE);
}
// Try unloading kernel using integer as ID
TEST_F(SpiceManagerTest, unloadKernelInteger){
int kernelID = loadLSKKernel();
//naif0008.tls is a text file, check if loaded.
SpiceBoolean found;
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
ASSERT_TRUE(found == SPICETRUE);
TEST_F(SpiceManagerTest, unloadKernelInteger) {
int kernelID = loadLSKKernel();
// naif0008.tls is a text file, check if loaded.
SpiceBoolean found;
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
ASSERT_TRUE(found == SPICETRUE);
//unload using unique int ID
openspace::SpiceManager::ref().unloadKernel(kernelID);
// unload using unique int ID
openspace::SpiceManager::ref().unloadKernel(kernelID);
found = SPICEFALSE;
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
EXPECT_FALSE(found == SPICETRUE) << "One or more kernels still present in kernel-pool";
found = SPICEFALSE;
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
EXPECT_FALSE(found == SPICETRUE) << "One or more kernels still present in kernel-pool";
}
// Try unloading multiple kernels
TEST_F(SpiceManagerTest, unloadMetaKernel){
loadMetaKernel();
// The metakernel loads these kerneltypes in the exact order as in typeArr
std::string typeArr[nrMetaKernels] = { "META", "TEXT", "TEXT",
"SPK", "SPK", "SPK",
"TEXT", "CK", "TEXT" };
TEST_F(SpiceManagerTest, unloadMetaKernel) {
loadMetaKernel();
// The metakernel loads these kerneltypes in the exact order as in typeArr
std::string typeArr[nrMetaKernels] = { "META", "TEXT", "TEXT",
"SPK", "SPK", "SPK",
"TEXT", "CK", "TEXT" };
for (int i = 0; i < nrMetaKernels; i++){
// check kernelpool against typeArr
SpiceBoolean found;
kdata_c(i, "all", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
EXPECT_EQ(fileType(filtyp), typeArr[i]) << "One or more kernels did not load properly";
}
openspace::SpiceManager::ref().unloadKernel(META);
for (int i = 0; i < nrMetaKernels; i++) {
// check kernelpool against typeArr
SpiceBoolean found;
kdata_c(i, "all", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
EXPECT_EQ(fileType(filtyp), typeArr[i]) << "One or more kernels did not load properly";
}
openspace::SpiceManager::ref().unloadKernel(META);
for (int i = 0; i < nrMetaKernels; i++){
// the values should by now be unloaded
SpiceBoolean found;
kdata_c(i, "all", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
EXPECT_FALSE(found == SPICETRUE) << "Failed unloading kernel";
}
unload_c(META.c_str());
for (int i = 0; i < nrMetaKernels; i++) {
// the values should by now be unloaded
SpiceBoolean found;
kdata_c(i, "all", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
EXPECT_FALSE(found == SPICETRUE) << "Failed unloading kernel";
}
unload_c(META.c_str());
}
// Attempt finding a value in kernelpool
TEST_F(SpiceManagerTest, hasValue){
loadPCKKernel();
TEST_F(SpiceManagerTest, hasValue) {
loadPCKKernel();
int naifId = 399; //Earth
int naifId = 399; // Earth
std::string kernelPoolValue = "RADII";
std::string kernelPoolValue = "RADII";
bool found = openspace::SpiceManager::ref().hasValue(naifId, kernelPoolValue);
ASSERT_TRUE(found) << "Could not find value for specified kernel";
unload_c(PCK.c_str());
bool found = openspace::SpiceManager::ref().hasValue(naifId, kernelPoolValue);
ASSERT_TRUE(found) << "Could not find value for specified kernel";
unload_c(PCK.c_str());
}
// Get 1dim value from kernelpool
TEST_F(SpiceManagerTest, getValueFromID_1D){
loadPCKKernel();
TEST_F(SpiceManagerTest, getValueFromID_1D) {
loadPCKKernel();
std::string target = "EARTH";
std::string value1D = "MAG_NORTH_POLE_LAT";
std::string target = "EARTH";
std::string value1D = "MAG_NORTH_POLE_LAT";
double return1D;
bool found = openspace::SpiceManager::ref().getValue(target, value1D, return1D);
ASSERT_TRUE(found) << "Could not retrieve value";
EXPECT_EQ(return1D, 78.565) << "Value not found / differs from expected return";
unload_c(PCK.c_str());
double return1D;
ASSERT_NO_THROW(openspace::SpiceManager::ref().getValue(target, value1D, return1D));
EXPECT_EQ(return1D, 78.565) << "Value not found / differs from expected return";
unload_c(PCK.c_str());
}
// Get 2dim value from kernelpool
TEST_F(SpiceManagerTest, getValueFromID_3D){
loadPCKKernel();
TEST_F(SpiceManagerTest, getValueFromID_3D) {
loadPCKKernel();
std::string target = "EARTH";
std::string value3D = "RADII";
std::string target = "EARTH";
std::string value3D = "RADII";
glm::dvec3 return3D;
openspace::SpiceManager::ref().getValue(target, value3D, return3D);
glm::dvec3 return3D;
ASSERT_NO_THROW(openspace::SpiceManager::ref().getValue(target, value3D, return3D));
EXPECT_EQ(return3D.x, 6378.14) << "Value not found / differs from expected return";
EXPECT_EQ(return3D.y, 6378.14) << "Value not found / differs from expected return";
EXPECT_EQ(return3D.z, 6356.75) << "Value not found / differs from expected return";
unload_c(PCK.c_str());
EXPECT_EQ(return3D.x, 6378.14) << "Value not found / differs from expected return";
EXPECT_EQ(return3D.y, 6378.14) << "Value not found / differs from expected return";
EXPECT_EQ(return3D.z, 6356.75) << "Value not found / differs from expected return";
unload_c(PCK.c_str());
}
// Get Ndim value from kernelpool
TEST_F(SpiceManagerTest, getValueFromID_ND){
loadPCKKernel();
TEST_F(SpiceManagerTest, getValueFromID_ND) {
loadPCKKernel();
std::string target = "SATURN";
std::string valueND = "RING6_A";
std::string target = "SATURN";
std::string valueND = "RING6_A";
std::vector<double> returnND(5);
bool found = openspace::SpiceManager::ref().getValue(target, valueND, returnND);
ASSERT_TRUE(found) << "Could not retrieve value for specified kernel";
std::vector<double> returnND(5);
ASSERT_NO_THROW(openspace::SpiceManager::ref().getValue(target, valueND, returnND));
std::vector<double> controlVec{ 189870.0, 256900.0, 9000.0, 9000.0, 0.000003 };
ASSERT_EQ(controlVec.size(), returnND.size()) << "Vectors differ in size";
std::vector<double> controlVec{ 189870.0, 256900.0, 9000.0, 9000.0, 0.000003 };
ASSERT_EQ(controlVec.size(), returnND.size()) << "Vectors differ in size";
for (unsigned int i = 0; i < returnND.size(); ++i){
EXPECT_EQ(controlVec[i], returnND[i]) << "Vector value not equal";
}
unload_c(PCK.c_str());
for (unsigned int i = 0; i < returnND.size(); ++i){
EXPECT_EQ(controlVec[i], returnND[i]) << "Vector value not equal";
}
unload_c(PCK.c_str());
}
// Try converting string to Ephemeris time
TEST_F(SpiceManagerTest, stringToEphemerisTime){
loadLSKKernel();
TEST_F(SpiceManagerTest, stringToEphemerisTime) {
loadLSKKernel();
double ephemerisTime;
double control_ephemerisTime;
char date[SRCLEN] = "Thu Mar 20 12:53:29 PST 1997";
str2et_c(date, &control_ephemerisTime);
double ephemerisTime;
double control_ephemerisTime;
char date[SRCLEN] = "Thu Mar 20 12:53:29 PST 1997";
str2et_c(date, &control_ephemerisTime);
bool success = openspace::SpiceManager::ref().getETfromDate(date, ephemerisTime);
EXPECT_EQ(success, true);
EXPECT_EQ(ephemerisTime, control_ephemerisTime) << "Ephemeries times differ / not found";
unload_c(LSK.c_str());
ASSERT_NO_THROW(ephemerisTime = openspace::SpiceManager::ref().ephemerisTimeFromDate(date));
EXPECT_EQ(ephemerisTime, control_ephemerisTime) << "Ephemeries times differ / not found";
unload_c(LSK.c_str());
}
// Try getting positional vector of target
TEST_F(SpiceManagerTest, getTargetPosition){
loadMetaKernel();
TEST_F(SpiceManagerTest, getTargetPosition) {
using openspace::SpiceManager;
loadMetaKernel();
double et;
double pos[3];
double lt;
char utctime[SRCLEN] = "2004 jun 11 19:32:00";
double et;
double pos[3];
double lt;
char utctime[SRCLEN] = "2004 jun 11 19:32:00";
str2et_c(utctime, &et);
spkpos_c("EARTH", et, "J2000", "LT+S", "CASSINI", pos, &lt);
str2et_c(utctime, &et);
spkpos_c("EARTH", et, "J2000", "LT+S", "CASSINI", pos, &lt);
glm::dvec3 targetPosition;
double lightTime = 0.0;
bool found = openspace::SpiceManager::ref().getTargetPosition("EARTH", "CASSINI", "J2000", "LT+S", et,
targetPosition, lightTime);
ASSERT_TRUE(found);
EXPECT_DOUBLE_EQ(pos[0], targetPosition[0]) << "Position not found or differs from expected return";
EXPECT_DOUBLE_EQ(pos[1], targetPosition[1]) << "Position not found or differs from expected return";
EXPECT_DOUBLE_EQ(pos[2], targetPosition[2]) << "Position not found or differs from expected return";
unload_c(META.c_str());
glm::dvec3 targetPosition;
double lightTime = 0.0;
SpiceManager::AberrationCorrection corr = {
SpiceManager::AberrationCorrection::Type::LightTimeStellar,
SpiceManager::AberrationCorrection::Direction::Reception
};
ASSERT_NO_THROW(targetPosition = SpiceManager::ref().targetPosition(
"EARTH", "CASSINI", "J2000", corr, et, lightTime)
);
EXPECT_DOUBLE_EQ(pos[0], targetPosition[0]) << "Position not found or differs from expected return";
EXPECT_DOUBLE_EQ(pos[1], targetPosition[1]) << "Position not found or differs from expected return";
EXPECT_DOUBLE_EQ(pos[2], targetPosition[2]) << "Position not found or differs from expected return";
unload_c(META.c_str());
}
// Try getting position & velocity vectors of target
TEST_F(SpiceManagerTest, getTargetState){
loadMetaKernel();
TEST_F(SpiceManagerTest, getTargetState) {
using openspace::SpiceManager;
loadMetaKernel();
double et;
double state[6];
double lt;
char utctime[SRCLEN] = "2004 jun 11 19:32:00";
double et;
double state[6];
double lt;
char utctime[SRCLEN] = "2004 jun 11 19:32:00";
str2et_c(utctime, &et);
spkezr_c("EARTH", et, "J2000", "LT+S", "CASSINI", state, &lt);
str2et_c(utctime, &et);
spkezr_c("EARTH", et, "J2000", "LT+S", "CASSINI", state, &lt);
glm::dvec3 targetPosition;
glm::dvec3 targetVelocity;
double lightTime = 0.0;
bool found = openspace::SpiceManager::ref().getTargetState("EARTH", "CASSINI", "J2000", "LT+S", et,
targetPosition, targetVelocity, lightTime);
ASSERT_TRUE(found);
//x,y,z
for (int i = 0; i < 3; i++){
EXPECT_DOUBLE_EQ(state[i], targetPosition[i]) << "Position not found or differs from expected return";
EXPECT_DOUBLE_EQ(state[i+3], targetVelocity[i]) << "Velocity not found or differs from expected return";
}
unload_c(META.c_str());
SpiceManager::AberrationCorrection corr = {
SpiceManager::AberrationCorrection::Type::LightTimeStellar,
SpiceManager::AberrationCorrection::Direction::Reception
};
SpiceManager::TargetStateResult res;
ASSERT_NO_THROW(res = SpiceManager::ref().targetState("EARTH", "CASSINI", "J2000", corr, et));
// x,y,z
for (int i = 0; i < 3; i++){
EXPECT_DOUBLE_EQ(state[i], res.position[i]) << "Position not found or differs from expected return";
EXPECT_DOUBLE_EQ(state[i+3], res.velocity[i]) << "Velocity not found or differs from expected return";
}
unload_c(META.c_str());
}
// Try getting transformation matrix and transform position and velocity into new reference frame
TEST_F(SpiceManagerTest, getStateTransformMatrix){
loadMetaKernel();
TEST_F(SpiceManagerTest, getStateTransformMatrix) {
loadMetaKernel();
double et;
double state[6];
double state_t[6];
double lt;
double referenceMatrix[6][6];
double et;
double state[6];
double state_t[6];
double lt;
double referenceMatrix[6][6];
str2et_c("2004 jun 11 19:32:00", &et);
spkezr_c("PHOEBE", et, "J2000", "LT+S", "CASSINI", state, &lt);
sxform_c("J2000", "IAU_PHOEBE", et, referenceMatrix);
str2et_c("2004 jun 11 19:32:00", &et);
spkezr_c("PHOEBE", et, "J2000", "LT+S", "CASSINI", state, &lt);
sxform_c("J2000", "IAU_PHOEBE", et, referenceMatrix);
glm::dvec3 position(state[0], state[1], state[2]);
glm::dvec3 velocity(state[3], state[4], state[5]);
glm::dvec3 position(state[0], state[1], state[2]);
glm::dvec3 velocity(state[3], state[4], state[5]);
openspace::SpiceManager::TransformMatrix stateMatrix;
bool found = openspace::SpiceManager::ref().getStateTransformMatrix("J2000",
"IAU_PHOEBE",
et,
stateMatrix);
ASSERT_TRUE(found);
//check for matrix consistency
for (int i = 0; i < 6; i++){
for (int j = 0; j < 6; j++){
EXPECT_DOUBLE_EQ(referenceMatrix[i][j], stateMatrix[i * 6 + j]) << "State-matrix not set or has wrong values";
}
}
mxvg_c(referenceMatrix, state, 6, 6, state_t);
openspace::SpiceManager::TransformMatrix stateMatrix;
ASSERT_NO_THROW(stateMatrix = openspace::SpiceManager::ref().stateTransformMatrix(
"J2000", "IAU_PHOEBE", et));
// check for matrix consistency
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
EXPECT_DOUBLE_EQ(referenceMatrix[i][j], stateMatrix[i * 6 + j]) << "State-matrix not set or has wrong values";
}
}
mxvg_c(referenceMatrix, state, 6, 6, state_t);
for (int i = 0; i < 3; i++){
EXPECT_DOUBLE_EQ(position[i], state_t[i]) << "Position vector differs from its reference";
EXPECT_DOUBLE_EQ(velocity[i], state_t[i + 3]) << "Velocity vector differs from its reference";
}
unload_c(META.c_str());
for (int i = 0; i < 3; i++) {
EXPECT_DOUBLE_EQ(position[i], state_t[i]) << "Position vector differs from its reference";
EXPECT_DOUBLE_EQ(velocity[i], state_t[i + 3]) << "Velocity vector differs from its reference";
}
unload_c(META.c_str());
}
// Try getting transformation matrix and transform the position only into new reference frame
TEST_F(SpiceManagerTest, getPositionTransformMatrix){
loadMetaKernel();
TEST_F(SpiceManagerTest, getPositionTransformMatrix) {
using openspace::SpiceManager;
loadMetaKernel();
double et;
double state[3] = { 1.0, 1.0, 1.0 };
double state_t[3];
double referenceMatrix[3][3];
double et;
double state[3] = { 1.0, 1.0, 1.0 };
double state_t[3];
double referenceMatrix[3][3];
str2et_c("2004 jun 11 19:32:00", &et);
pxform_c("CASSINI_HGA", "J2000", et, referenceMatrix);
str2et_c("2004 jun 11 19:32:00", &et);
pxform_c("CASSINI_HGA", "J2000", et, referenceMatrix);
glm::dmat3 positionMatrix;
glm::dvec3 position(state[0], state[1], state[2]);
bool found = openspace::SpiceManager::ref().getPositionTransformMatrix("CASSINI_HGA",
"J2000",
et,
positionMatrix);
ASSERT_TRUE(found);
//check for matrix consistency
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
EXPECT_DOUBLE_EQ(referenceMatrix[i][j], positionMatrix[j][i]) << "Position-matrix not set or has wrong values";
}
}
//transform reference position into new frame
mxvg_c(referenceMatrix, state, 3, 3, state_t);
glm::dmat3 positionMatrix;
glm::dvec3 position(state[0], state[1], state[2]);
ASSERT_NO_THROW(positionMatrix = SpiceManager::ref().positionTransformMatrix(
"CASSINI_HGA", "J2000", et)
);
position = positionMatrix * position;
//check transformed values match
for (int i = 0; i < 3; i++){
EXPECT_DOUBLE_EQ(position[i], state_t[i]) << "Position vector differs from its reference";
}
unload_c(META.c_str());
// check for matrix consistency
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
EXPECT_DOUBLE_EQ(referenceMatrix[i][j], positionMatrix[j][i]) << "Position-matrix not set or has wrong values";
}
}
// transform reference position into new frame
mxvg_c(referenceMatrix, state, 3, 3, state_t);
position = positionMatrix * position;
// check transformed values match
for (int i = 0; i < 3; i++) {
EXPECT_DOUBLE_EQ(position[i], state_t[i]) << "Position vector differs from its reference";
}
unload_c(META.c_str());
}
// Try to get boresight vector and instrument field of view boundary vectors
TEST_F(SpiceManagerTest, getFieldOfView){
loadMetaKernel();
SpiceInt n;
SpiceInt cassini_ID;
double et;
glm::dvec3 boresight;
double bounds_ref[5][3];
char shape_ref[TYPLEN];
char name_ref[FILLEN];
double boresightVec[3];
TEST_F(SpiceManagerTest, getFieldOfView) {
using openspace::SpiceManager;
loadMetaKernel();
SpiceInt n;
SpiceInt cassini_ID;
double et;
glm::dvec3 boresight;
double bounds_ref[5][3];
char shape_ref[TYPLEN];
char name_ref[FILLEN];
double boresightVec[3];
str2et_c("2004 jun 11 19:32:00", &et);
SpiceBoolean found;
bodn2c_c("CASSINI_ISS_NAC", &cassini_ID, &found);
ASSERT_TRUE(found == SPICETRUE) << "Cannot locate ID for Cassini";
str2et_c("2004 jun 11 19:32:00", &et);
SpiceBoolean found;
bodn2c_c("CASSINI_ISS_NAC", &cassini_ID, &found);
ASSERT_TRUE(found == SPICETRUE) << "Cannot locate ID for Cassini";
getfov_c(cassini_ID, 5, TYPLEN, TYPLEN, shape_ref, name_ref, boresightVec, &n, bounds_ref);
getfov_c(cassini_ID, 5, TYPLEN, TYPLEN, shape_ref, name_ref, boresightVec, &n, bounds_ref);
std::string shape, name;
shape.resize(32);
name.resize(32);
std::vector<glm::dvec3> bounds;
found = openspace::SpiceManager::ref().getFieldOfView("CASSINI_ISS_NAC",
shape,
name,
boresight,
bounds);
ASSERT_TRUE(found == SPICETRUE);
//check vectors have correct values
for (int i = 0; i < bounds.size(); i++){
for (int j = 0; j < 3; j++){
EXPECT_DOUBLE_EQ(bounds_ref[i][j], bounds[i][j]) << "One or more Field of View Boundary vectors \
differ from expected output";
}
}
unload_c(META.c_str());
SpiceManager::FieldOfViewResult res;
ASSERT_NO_THROW(res = SpiceManager::ref().fieldOfView("CASSINI_ISS_NAC"));
ASSERT_TRUE(found == SPICETRUE);
//check vectors have correct values
for (int i = 0; i < res.bounds.size(); i++){
for (int j = 0; j < 3; j++){
EXPECT_DOUBLE_EQ(bounds_ref[i][j], res.bounds[i][j]) << "One or more Field of View Boundary vectors \
differ from expected output";
}
}
unload_c(META.c_str());
}