From 26a7fbe47e7dc5fb823b7446263785131cc0d27a Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Wed, 20 Aug 2014 16:55:07 +0200 Subject: [PATCH] Code cleanup of Ephemeris classes and SceneGraph --- ext/ghoul | 2 +- include/openspace/scenegraph/ephemeris.h | 4 +- include/openspace/scenegraph/scenegraph.h | 6 +-- include/openspace/scenegraph/scenegraphnode.h | 8 ++-- include/openspace/scenegraph/spiceephemeris.h | 12 +++--- .../openspace/scenegraph/staticephemeris.h | 9 ++-- include/openspace/util/constants.h | 11 ++++- src/scenegraph/ephemeris.cpp | 8 ++++ src/scenegraph/scenegraph.cpp | 18 ++++---- src/scenegraph/scenegraphnode.cpp | 2 + src/scenegraph/spiceephemeris.cpp | 41 +++++++++++++------ src/scenegraph/staticephemeris.cpp | 30 ++++++-------- 12 files changed, 89 insertions(+), 62 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index c673a62b41..8a78a05ffd 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit c673a62b417a24feb61039df08d1406fc99fac7e +Subproject commit 8a78a05ffd85a046d276d55e2328cb495c98a398 diff --git a/include/openspace/scenegraph/ephemeris.h b/include/openspace/scenegraph/ephemeris.h index c73b14e692..b8e13e8b8d 100644 --- a/include/openspace/scenegraph/ephemeris.h +++ b/include/openspace/scenegraph/ephemeris.h @@ -36,9 +36,9 @@ public: Ephemeris(const ghoul::Dictionary& dictionary); virtual ~Ephemeris(); - virtual bool initialize() = 0; + virtual bool initialize(); virtual const psc& position() const = 0; - virtual void update() = 0; + virtual void update(); protected: Ephemeris(); diff --git a/include/openspace/scenegraph/scenegraph.h b/include/openspace/scenegraph/scenegraph.h index 56249fe426..6ccdc4feb7 100644 --- a/include/openspace/scenegraph/scenegraph.h +++ b/include/openspace/scenegraph/scenegraph.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef SCENEGRAPH_H -#define SCENEGRAPH_H +#ifndef __SCENEGRAPH_H__ +#define __SCENEGRAPH_H__ // std includes #include @@ -105,4 +105,4 @@ private: } // namespace openspace -#endif \ No newline at end of file +#endif // __SCENEGRAPH_H__ \ No newline at end of file diff --git a/include/openspace/scenegraph/scenegraphnode.h b/include/openspace/scenegraph/scenegraphnode.h index 2269d7d7cf..25bbd3e2c3 100644 --- a/include/openspace/scenegraph/scenegraphnode.h +++ b/include/openspace/scenegraph/scenegraphnode.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef SCENEGRAPHNODE_H -#define SCENEGRAPHNODE_H +#ifndef __SCENEGRAPHNODE_H__ +#define __SCENEGRAPHNODE_H__ // open space includes #include @@ -42,6 +42,8 @@ namespace openspace { class SceneGraphNode { public: + static std::string RootNodeName; + // constructors & destructor SceneGraphNode(); ~SceneGraphNode(); @@ -100,4 +102,4 @@ private: } // namespace openspace -#endif +#endif // __SCENEGRAPHNODE_H__ diff --git a/include/openspace/scenegraph/spiceephemeris.h b/include/openspace/scenegraph/spiceephemeris.h index 70c404e10c..3229b09428 100644 --- a/include/openspace/scenegraph/spiceephemeris.h +++ b/include/openspace/scenegraph/spiceephemeris.h @@ -31,20 +31,20 @@ namespace openspace { -class SpiceEphemeris: public Ephemeris { +class SpiceEphemeris : public Ephemeris { public: SpiceEphemeris(const ghoul::Dictionary& dictionary); virtual ~SpiceEphemeris(); virtual bool initialize(); virtual const psc& position() const; virtual void update(); -protected: -private: - std::string _targetName, _originName; - int _target, _origin; +private: + std::string _targetName; + std::string _originName; + int _target; + int _origin; psc _position; - }; } // namespace openspace diff --git a/include/openspace/scenegraph/staticephemeris.h b/include/openspace/scenegraph/staticephemeris.h index e5d8001db8..71b5d02a5b 100644 --- a/include/openspace/scenegraph/staticephemeris.h +++ b/include/openspace/scenegraph/staticephemeris.h @@ -33,14 +33,11 @@ class StaticEphemeris: public Ephemeris { public: StaticEphemeris(const ghoul::Dictionary& dictionary = ghoul::Dictionary()); - virtual ~StaticEphemeris(); - virtual bool initialize(); - virtual const psc& position() const; - virtual void update(); -protected: + ~StaticEphemeris(); + const psc& position() const; + private: psc _position; - }; } // namespace openspace diff --git a/include/openspace/util/constants.h b/include/openspace/util/constants.h index 5327fb8357..6c004dbda2 100644 --- a/include/openspace/util/constants.h +++ b/include/openspace/util/constants.h @@ -63,12 +63,19 @@ namespace planetgeometry { const std::string keyType = "Type"; } // namespace planetgeometry - - namespace ephemeris { const std::string keyType = "Type"; } // namespace ephemeris +namespace staticephemeris { + const std::string keyPosition = "Position"; +} // namespace staticephemeris + +namespace spiceephemeris { + const std::string keyBody = "Body"; + const std::string keyOrigin = "Observer"; +} // namespace spiceephemeris + } // namespace constants } // namespace openspace diff --git a/src/scenegraph/ephemeris.cpp b/src/scenegraph/ephemeris.cpp index dc7e2a5833..ae2d5080d8 100644 --- a/src/scenegraph/ephemeris.cpp +++ b/src/scenegraph/ephemeris.cpp @@ -55,11 +55,19 @@ Ephemeris* Ephemeris::createFromDictionary(const ghoul::Dictionary& dictionary) Ephemeris::Ephemeris() { } + Ephemeris::Ephemeris(const ghoul::Dictionary& dictionary) { } + Ephemeris::~Ephemeris() { } + +bool Ephemeris::initialize() { + return true; +} + +void Ephemeris::update() {} } // namespace openspace \ No newline at end of file diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index 17a55e4158..1e5276ccbb 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -47,10 +47,8 @@ #include namespace { -const std::string _loggerCat = "SceneGraph"; -const std::string _rootNodeName = "Root"; -const std::string _moduleExtension = ".mod"; - + const std::string _loggerCat = "SceneGraph"; + const std::string _moduleExtension = ".mod"; } namespace openspace { @@ -64,8 +62,8 @@ void printTree(SceneGraphNode* node, std::string pre = "") } SceneGraph::SceneGraph() - : _focus("Root") - , _position("Root") + : _focus(SceneGraphNode::RootNodeName) + , _position(SceneGraphNode::RootNodeName) , _root(nullptr) { } @@ -206,8 +204,8 @@ bool SceneGraph::deinitialize() _nodes.erase(_nodes.begin(), _nodes.end()); _allNodes.erase(_allNodes.begin(), _allNodes.end()); - _focus = ""; - _position = ""; + _focus.clear(); + _position.clear(); return true; } @@ -243,9 +241,9 @@ bool SceneGraph::loadScene(const std::string& sceneDescriptionFilePath, // initialize the root node _root = new SceneGraphNode(); - _root->setName(_rootNodeName); + _root->setName(SceneGraphNode::RootNodeName); _nodes.push_back(_root); - _allNodes.emplace(_rootNodeName, _root); + _allNodes.emplace(SceneGraphNode::RootNodeName, _root); Dictionary dictionary; loadDictionaryFromFile(sceneDescriptionFilePath, dictionary); diff --git a/src/scenegraph/scenegraphnode.cpp b/src/scenegraph/scenegraphnode.cpp index b0b3e752df..b6488bd38e 100644 --- a/src/scenegraph/scenegraphnode.cpp +++ b/src/scenegraph/scenegraphnode.cpp @@ -45,6 +45,8 @@ const std::string _loggerCat = "SceneGraphNode"; } namespace openspace { + +std::string SceneGraphNode::RootNodeName = "Root"; SceneGraphNode* SceneGraphNode::createFromDictionary(const ghoul::Dictionary& dictionary) { diff --git a/src/scenegraph/spiceephemeris.cpp b/src/scenegraph/spiceephemeris.cpp index 69dc501e17..482a60d61e 100644 --- a/src/scenegraph/spiceephemeris.cpp +++ b/src/scenegraph/spiceephemeris.cpp @@ -24,32 +24,49 @@ #include +#include #include +namespace { + const std::string _loggerCat = "SpiceEphemeris"; +} + namespace openspace { -SpiceEphemeris::SpiceEphemeris(const ghoul::Dictionary& dictionary): _targetName(""), - _originName(""), - _target(0), - _origin(0), - _position() +using namespace constants::spiceephemeris; + +SpiceEphemeris::SpiceEphemeris(const ghoul::Dictionary& dictionary) + : _targetName("") + , _originName("") + , _target(0) + , _origin(0) + , _position() { - dictionary.getValue("Body", _targetName); - dictionary.getValue("Observer", _originName); + const bool hasBody = dictionary.hasKeyAndValue(keyBody); + if (hasBody) + dictionary.getValue(keyBody, _targetName); + else + LERROR("SpiceEphemeris does not contain the key '" << keyBody << "'"); + + const bool hasObserver = dictionary.hasKeyAndValue(keyOrigin); + if (hasObserver) + dictionary.getValue(keyOrigin, _originName); + else + LERROR("SpiceEphemeris does not contain the key '" << keyOrigin << "'"); } + SpiceEphemeris::~SpiceEphemeris() {} -bool SpiceEphemeris::initialize() { - - if (_targetName != "" && _originName != "") { +bool SpiceEphemeris::initialize() +{ + if (!_targetName.empty() && !_originName.empty()) { int bsuccess = 0; int osuccess = 0; Spice::ref().bod_NameToInt(_targetName, &_target, &bsuccess); Spice::ref().bod_NameToInt(_originName, &_origin, &osuccess); - if (bsuccess && osuccess) { + if (bsuccess && osuccess) return true; - } } return false; diff --git a/src/scenegraph/staticephemeris.cpp b/src/scenegraph/staticephemeris.cpp index f87e737c0e..fc1cc8ea18 100644 --- a/src/scenegraph/staticephemeris.cpp +++ b/src/scenegraph/staticephemeris.cpp @@ -24,31 +24,27 @@ #include +#include + namespace openspace { -StaticEphemeris::StaticEphemeris(const ghoul::Dictionary& dictionary) { - double x = 0.0, y = 0.0, z = 0.0, e = 0.0; - if (dictionary.hasKey("Position.1")) { - dictionary.getValue("Position.1", x); - dictionary.getValue("Position.2", y); - dictionary.getValue("Position.3", z); - dictionary.getValue("Position.4", e); +using namespace constants::staticephemeris; + +StaticEphemeris::StaticEphemeris(const ghoul::Dictionary& dictionary) + : _position(0.f, 0.f, 0.f, 0.f) +{ + const bool hasPosition = dictionary.hasKeyAndValue(keyPosition); + if (hasPosition) { + glm::vec4 tmp; + dictionary.getValue(keyPosition, tmp); + _position = tmp; } - _position = psc(x, y, z, e); } StaticEphemeris::~StaticEphemeris() {} -bool StaticEphemeris::initialize() { - return true; -} - -const psc& StaticEphemeris::position() const { +const psc& StaticEphemeris::position() const { return _position; } -void StaticEphemeris::update() { - -} - } // namespace openspace \ No newline at end of file