mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-28 07:59:37 -06:00
Code cleanup of Ephemeris classes and SceneGraph
This commit is contained in:
Submodule ext/ghoul updated: c673a62b41...8a78a05ffd
@@ -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();
|
||||
|
||||
@@ -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 <vector>
|
||||
@@ -105,4 +105,4 @@ private:
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
#endif // __SCENEGRAPH_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 <openspace/rendering/renderable.h>
|
||||
@@ -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__
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -47,10 +47,8 @@
|
||||
#include <string>
|
||||
|
||||
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);
|
||||
|
||||
@@ -45,6 +45,8 @@ const std::string _loggerCat = "SceneGraphNode";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
std::string SceneGraphNode::RootNodeName = "Root";
|
||||
|
||||
SceneGraphNode* SceneGraphNode::createFromDictionary(const ghoul::Dictionary& dictionary)
|
||||
{
|
||||
|
||||
@@ -24,32 +24,49 @@
|
||||
|
||||
#include <openspace/scenegraph/spiceephemeris.h>
|
||||
|
||||
#include <openspace/util/constants.h>
|
||||
#include <openspace/util/spice.h>
|
||||
|
||||
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<std::string>(keyBody);
|
||||
if (hasBody)
|
||||
dictionary.getValue(keyBody, _targetName);
|
||||
else
|
||||
LERROR("SpiceEphemeris does not contain the key '" << keyBody << "'");
|
||||
|
||||
const bool hasObserver = dictionary.hasKeyAndValue<std::string>(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;
|
||||
|
||||
@@ -24,31 +24,27 @@
|
||||
|
||||
#include <openspace/scenegraph/staticephemeris.h>
|
||||
|
||||
#include <openspace/util/constants.h>
|
||||
|
||||
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<glm::vec4>(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
|
||||
Reference in New Issue
Block a user