From 7f7e25fd8bd6a136f2e7d7d7722725395c3a43ed Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sun, 4 May 2014 16:50:20 +0200 Subject: [PATCH] More work on ephemerides --- include/openspace/scenegraph/scenegraphnode.h | 2 +- include/openspace/util/constants.h | 4 + openspace-data | 2 +- src/main.cpp | 2 +- src/rendering/renderable.cpp | 11 ++- src/scenegraph/scenegraphnode.cpp | 75 +++++++------------ src/util/factorymanager.cpp | 4 +- 7 files changed, 43 insertions(+), 57 deletions(-) diff --git a/include/openspace/scenegraph/scenegraphnode.h b/include/openspace/scenegraph/scenegraphnode.h index 352cf7e351..aefd6fbb65 100644 --- a/include/openspace/scenegraph/scenegraphnode.h +++ b/include/openspace/scenegraph/scenegraphnode.h @@ -84,7 +84,7 @@ private: std::vector _children; SceneGraphNode* _parent; std::string _nodeName; - Ephemeris* _position; + Ephemeris* _ephemeris; // renderable Renderable* _renderable; diff --git a/include/openspace/util/constants.h b/include/openspace/util/constants.h index 9352b5224f..af92c53337 100644 --- a/include/openspace/util/constants.h +++ b/include/openspace/util/constants.h @@ -53,6 +53,10 @@ namespace scenegraphnode { namespace renderable { const std::string keyType = "Type"; +} // namespace renderable + +namespace ephemeris { + const std::string keyType = "Type"; } } // namespace constants diff --git a/openspace-data b/openspace-data index 66675512a7..ac3546b474 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 66675512a721c631def106e0f013ae6473c08f0f +Subproject commit ac3546b47438b802bd810708c085388b805f83c9 diff --git a/src/main.cpp b/src/main.cpp index 759cce831f..cf97ebe9ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,7 @@ int main(int argc, char** argv) openspace::OpenSpaceEngine::create(argc, argv, sgctArguments); // create sgct engine c arguments - int newArgc = sgctArguments.size(); + int newArgc = static_cast(sgctArguments.size()); char** newArgv = new char* [newArgc]; for (int i = 0; i < newArgc; ++i) { // newArgv[i] = new char[sgctArguments.at(i).length()]; diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index d603b30373..53b8cd734c 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -39,21 +39,24 @@ namespace openspace { Renderable* Renderable::createFromDictionary(const ghoul::Dictionary& dictionary) { + std::string name; + dictionary.getValue(constants::scenegraphnode::keyName, name); + if (!dictionary.hasValue(constants::renderable::keyType)) { - LERROR("Renderable did not have key '" << constants::renderable::keyType << "'"); + LERROR("Renderable '" << name << "' did not have key '" + << constants::renderable::keyType << "'"); return nullptr; } std::string renderableType; dictionary.getValue(constants::renderable::keyType, renderableType); - ghoul::TemplateFactory* factory = FactoryManager::ref().factoryByType(); + ghoul::TemplateFactory* factory + = FactoryManager::ref().factoryByType(); Renderable* result = factory->create(renderableType, dictionary); if (result == nullptr) { LERROR("Failed creating Renderable object of type '" << renderableType << "'"); return nullptr; } - std::string name; - dictionary.getValue(constants::scenegraphnode::keyName, name); result->setName(name); return result; diff --git a/src/scenegraph/scenegraphnode.cpp b/src/scenegraph/scenegraphnode.cpp index 7bebd4be80..78dedf9510 100644 --- a/src/scenegraph/scenegraphnode.cpp +++ b/src/scenegraph/scenegraphnode.cpp @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include @@ -46,32 +46,6 @@ const std::string _loggerCat = "SceneGraphNode"; namespace openspace { -template -bool safeCreationWithDictionary(T** object, const std::string& key, - const ghoul::Dictionary& dictionary, - const std::string& path = "") -{ - if (dictionary.hasKey(key)) { - ghoul::Dictionary tmpDictionary; - if (dictionary.getValue(key, tmpDictionary)) { - if (!tmpDictionary.hasKey("Path") && path != "") { - tmpDictionary.setValue("Path", path); - } - std::string renderableType; - if (tmpDictionary.getValue("Type", renderableType)) { - ghoul::TemplateFactory* factory - = FactoryManager::ref().factoryByType(); - T* tmp = factory->create(renderableType, tmpDictionary); - if (tmp != nullptr) { - *object = tmp; - return true; - } - } - } - } - return false; -} - SceneGraphNode* SceneGraphNode::createFromDictionary(const ghoul::Dictionary& dictionary) { using namespace constants::scenegraph; @@ -91,26 +65,29 @@ SceneGraphNode* SceneGraphNode::createFromDictionary(const ghoul::Dictionary& di if (dictionary.hasValue(keyRenderable)) { ghoul::Dictionary renderableDictionary; - dictionary.getValue(keyRenderable, - renderableDictionary); + dictionary.getValue(keyRenderable, renderableDictionary); renderableDictionary.setValue(keyPathModule, path); renderableDictionary.setValue(keyName, result->_nodeName); result->_renderable = Renderable::createFromDictionary(renderableDictionary); if (result->_renderable == nullptr) { LERROR("Failed to create renderable for SceneGraphNode '" - << result->_nodeName); + << result->_nodeName << "'"); return nullptr; } + LDEBUG("Successfully create renderable for '" << result->_nodeName << "'"); } if (dictionary.hasKey(keyEphemeris)) { - if (safeCreationWithDictionary( - &result->_position, keyEphemeris, dictionary, - path)) { - LDEBUG(result->_nodeName << ": Successful creation of position"); - } else { - LDEBUG(result->_nodeName << ": Failed to create position"); + ghoul::Dictionary ephemerisDictionary; + dictionary.getValue(keyEphemeris, ephemerisDictionary); + ephemerisDictionary.setValue(keyPathModule, path); + result->_ephemeris = Ephemeris::createFromDictionary(ephemerisDictionary); + if (result->_ephemeris == nullptr) { + LERROR("Failed to create ephemeris for SceneGraphNode '" + << result->_nodeName << "'"); + return nullptr; } + LDEBUG("Successfully create ephemeris for '" << result->_nodeName << "'"); } std::string parentName; @@ -128,13 +105,15 @@ SceneGraphNode* SceneGraphNode::createFromDictionary(const ghoul::Dictionary& di parentNode->addNode(result); + LDEBUG("Successfully created SceneGraphNode '" + << result->_nodeName << "'"); return result; } SceneGraphNode::SceneGraphNode() : _parent(nullptr) , _nodeName("") - , _position(new ConstantEphemeris) + , _ephemeris(new StaticEphemeris) , _renderable(nullptr) , _renderableVisible(false) , _boundingSphereVisible(false) @@ -152,8 +131,8 @@ bool SceneGraphNode::initialize() _renderable->initialize(); // deallocate position - if (_position != nullptr) - _position->initialize(); + if (_ephemeris != nullptr) + _ephemeris->initialize(); return true; } @@ -166,8 +145,8 @@ bool SceneGraphNode::deinitialize() delete _renderable; // deallocate position - if (_position != nullptr) - delete _position; + if (_ephemeris != nullptr) + delete _ephemeris; // deallocate the child nodes and delete them, iterate c++11 style for (auto child : _children) @@ -179,7 +158,7 @@ bool SceneGraphNode::deinitialize() // reset variables _parent = nullptr; _renderable = nullptr; - _position = nullptr; + _ephemeris = nullptr; _nodeName = "Unnamed OpenSpace SceneGraphNode"; _renderableVisible = false; _boundingSphereVisible = false; @@ -191,12 +170,12 @@ bool SceneGraphNode::deinitialize() // essential void SceneGraphNode::update() { - _position->update(); + _ephemeris->update(); } void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition) { - const psc thisPosition = parentPosition + _position->position(); + const psc thisPosition = parentPosition + _ephemeris->position(); const psc camPos = camera->getPosition(); const psc toCamera = thisPosition - camPos; @@ -233,7 +212,7 @@ void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition) void SceneGraphNode::render(const Camera* camera, const psc& parentPosition) { - const psc thisPosition = parentPosition + _position->position(); + const psc thisPosition = parentPosition + _ephemeris->position(); // check if camera is outside the node boundingsphere if (!_boundingSphereVisible) { @@ -272,16 +251,16 @@ void SceneGraphNode::setParent(SceneGraphNode* parent) const psc& SceneGraphNode::getPosition() const { - return _position->position(); + return _ephemeris->position(); } psc SceneGraphNode::getWorldPosition() const { // recursive up the hierarchy if there are parents available if (_parent) { - return _position->position() + _parent->getWorldPosition(); + return _ephemeris->position() + _parent->getWorldPosition(); } else { - return _position->position(); + return _ephemeris->position(); } } diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index bd36056692..2a553a5dc9 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -34,7 +34,7 @@ #include // positioninformation -#include +#include #include namespace openspace { @@ -71,7 +71,7 @@ void FactoryManager::initialize() { // Add PositionInformations _manager->factoryByType()-> - registerClass("Static"); + registerClass("Static"); _manager->factoryByType()-> registerClass("Spice");