diff --git a/src/openspaceengine.h b/include/openspace/engine/openspaceengine.h similarity index 94% rename from src/openspaceengine.h rename to include/openspace/engine/openspaceengine.h index dcfa6c486e..bfb9aa42dc 100644 --- a/src/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -25,8 +25,8 @@ #ifndef __OPENSPACEENGINE_H__ #define __OPENSPACEENGINE_H__ -#include "interaction/interactionhandler.h" -#include "rendering/renderengine.h" +#include +#include #include namespace openspace { @@ -39,7 +39,9 @@ public: static void destroy(); static OpenSpaceEngine& ref(); + static bool isInitialized(); bool initialize(); + static bool registerFilePaths(); ghoul::ConfigurationManager& configurationManager(); InteractionHandler& interactionHandler(); @@ -67,7 +69,7 @@ private: RenderEngine* _renderEngine; ScriptEngine* _scriptEngine; }; - + #define OsEng (openspace::OpenSpaceEngine::ref()) } // namespace openspace diff --git a/src/interaction/deviceidentifier.h b/include/openspace/interaction/deviceidentifier.h similarity index 100% rename from src/interaction/deviceidentifier.h rename to include/openspace/interaction/deviceidentifier.h diff --git a/src/interaction/externalcontrol/externalconnectioncontroller.h b/include/openspace/interaction/externalcontrol/externalconnectioncontroller.h similarity index 85% rename from src/interaction/externalcontrol/externalconnectioncontroller.h rename to include/openspace/interaction/externalcontrol/externalconnectioncontroller.h index 8eecd53f90..4d45937c59 100644 --- a/src/interaction/externalcontrol/externalconnectioncontroller.h +++ b/include/openspace/interaction/externalcontrol/externalconnectioncontroller.h @@ -1,7 +1,7 @@ #ifndef EXTERNALCONNECTIONCONTROLLER_H #define EXTERNALCONNECTIONCONTROLLER_H -#include "interaction/externalcontrol/externalcontrol.h" +#include #include namespace openspace { diff --git a/src/interaction/externalcontrol/externalcontrol.h b/include/openspace/interaction/externalcontrol/externalcontrol.h similarity index 93% rename from src/interaction/externalcontrol/externalcontrol.h rename to include/openspace/interaction/externalcontrol/externalcontrol.h index 6b12c3c75c..6a38aa0a29 100644 --- a/src/interaction/externalcontrol/externalcontrol.h +++ b/include/openspace/interaction/externalcontrol/externalcontrol.h @@ -1,7 +1,7 @@ #ifndef EXTERNALCONTROL_H #define EXTERNALCONTROL_H -#include "util/pss.h" +#include #include #include diff --git a/src/interaction/externalcontrol/joystickexternalcontrol.h b/include/openspace/interaction/externalcontrol/joystickexternalcontrol.h similarity index 100% rename from src/interaction/externalcontrol/joystickexternalcontrol.h rename to include/openspace/interaction/externalcontrol/joystickexternalcontrol.h diff --git a/src/interaction/externalcontrol/keyboardexternalcontrol.h b/include/openspace/interaction/externalcontrol/keyboardexternalcontrol.h similarity index 100% rename from src/interaction/externalcontrol/keyboardexternalcontrol.h rename to include/openspace/interaction/externalcontrol/keyboardexternalcontrol.h diff --git a/src/interaction/externalcontrol/mouseexternalcontrol.h b/include/openspace/interaction/externalcontrol/mouseexternalcontrol.h similarity index 100% rename from src/interaction/externalcontrol/mouseexternalcontrol.h rename to include/openspace/interaction/externalcontrol/mouseexternalcontrol.h diff --git a/src/interaction/externalcontrol/pythonexternalcontrol.h b/include/openspace/interaction/externalcontrol/pythonexternalcontrol.h similarity index 100% rename from src/interaction/externalcontrol/pythonexternalcontrol.h rename to include/openspace/interaction/externalcontrol/pythonexternalcontrol.h diff --git a/src/interaction/externalcontrol/randomexternalcontrol.h b/include/openspace/interaction/externalcontrol/randomexternalcontrol.h similarity index 85% rename from src/interaction/externalcontrol/randomexternalcontrol.h rename to include/openspace/interaction/externalcontrol/randomexternalcontrol.h index a552ff54ba..2cc189f4c5 100644 --- a/src/interaction/externalcontrol/randomexternalcontrol.h +++ b/include/openspace/interaction/externalcontrol/randomexternalcontrol.h @@ -4,7 +4,7 @@ #include #include -#include "interaction/externalcontrol/externalcontrol.h" +#include namespace openspace { diff --git a/src/interaction/interactionhandler.h b/include/openspace/interaction/interactionhandler.h similarity index 91% rename from src/interaction/interactionhandler.h rename to include/openspace/interaction/interactionhandler.h index dcb2598410..a27b27986d 100644 --- a/src/interaction/interactionhandler.h +++ b/include/openspace/interaction/interactionhandler.h @@ -2,9 +2,9 @@ #define INTERACTIONHANDLER_H // open space includes -#include "util/camera.h" -#include "externalcontrol/externalcontrol.h" -#include "scenegraph/scenegraphnode.h" +#include +#include +#include // std includes #include diff --git a/src/query/query.h b/include/openspace/query/query.h similarity index 100% rename from src/query/query.h rename to include/openspace/query/query.h diff --git a/src/rendering/renderable.h b/include/openspace/rendering/renderable.h similarity index 71% rename from src/rendering/renderable.h rename to include/openspace/rendering/renderable.h index 20a2b7037d..7bdf38c926 100644 --- a/src/rendering/renderable.h +++ b/include/openspace/rendering/renderable.h @@ -2,29 +2,30 @@ #define RENDERABLE_H // open space includes -#include "util/psc.h" -#include "util/pss.h" -#include "util/camera.h" +#include +#include +#include #include namespace openspace { class Renderable { public: - + // constructors & destructor - Renderable(); + Renderable(const ghoul::Dictionary& dictionary); virtual ~Renderable(); virtual bool initialize() = 0; - virtual bool initializeWithDictionary(ghoul::Dictionary* dictionary) = 0; + virtual bool deinitialize() = 0; void setBoundingSphere(const pss &boundingSphere); const pss &getBoundingSphere(); virtual void render(const Camera *camera, const psc &thisPosition) = 0; virtual void update(); - +protected: + Renderable(); private: pss boundingSphere_; diff --git a/src/rendering/renderablebody.h b/include/openspace/rendering/renderablebody.h similarity index 90% rename from src/rendering/renderablebody.h rename to include/openspace/rendering/renderablebody.h index 4585acd6b2..86562c9a2b 100644 --- a/src/rendering/renderablebody.h +++ b/include/openspace/rendering/renderablebody.h @@ -2,8 +2,8 @@ #define RENDERABLEBODY_H // open space includes -#include "renderable.h" -#include "util/sphere.h" +#include +#include // ghoul includes #include "ghoul/opengl/programobject.h" diff --git a/src/rendering/renderableplanet.h b/include/openspace/rendering/renderableplanet.h similarity index 66% rename from src/rendering/renderableplanet.h rename to include/openspace/rendering/renderableplanet.h index 9b4ea1a02e..e99aa4156d 100644 --- a/src/rendering/renderableplanet.h +++ b/include/openspace/rendering/renderableplanet.h @@ -2,8 +2,8 @@ #define RENDERABLEPLANET_H // open space includes -#include "renderable.h" -#include +#include +#include // ghoul includes #include @@ -15,21 +15,28 @@ class RenderablePlanet: public Renderable { public: // constructors & destructor - RenderablePlanet(); + RenderablePlanet(const ghoul::Dictionary& dictionary); ~RenderablePlanet(); bool initialize(); - bool initializeWithDictionary(ghoul::Dictionary* dictionary); + bool deinitialize(); - void setProgramObject(ghoul::opengl::ProgramObject *programObject); + void setProgramObject(ghoul::opengl::ProgramObject *programObject = nullptr); void setTexture(ghoul::opengl::Texture *texture); virtual void render(const Camera *camera, const psc &thisPosition); virtual void update(); private: - ghoul::opengl::ProgramObject *programObject_; + + // shader + ghoul::opengl::ProgramObject *programObject_; + + // texture + std::string _texturePath; ghoul::opengl::Texture *texture_; + + // Object PowerScaledSphere *planet_; }; diff --git a/src/rendering/renderengine.h b/include/openspace/rendering/renderengine.h similarity index 98% rename from src/rendering/renderengine.h rename to include/openspace/rendering/renderengine.h index a3849657ea..285282ce31 100644 --- a/src/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -25,7 +25,7 @@ #ifndef __RENDERENGINE_H__ #define __RENDERENGINE_H__ -#include "scenegraph/scenegraph.h" +#include #include diff --git a/src/scenegraph/constantpositioninformation.h b/include/openspace/scenegraph/constantpositioninformation.h similarity index 95% rename from src/scenegraph/constantpositioninformation.h rename to include/openspace/scenegraph/constantpositioninformation.h index 365afb6e67..6fbc86ca70 100644 --- a/src/scenegraph/constantpositioninformation.h +++ b/include/openspace/scenegraph/constantpositioninformation.h @@ -31,9 +31,9 @@ namespace openspace { class ConstantPositionInformation: public PositionInformation { public: - ConstantPositionInformation(); + ConstantPositionInformation(const ghoul::Dictionary& dictionary); virtual ~ConstantPositionInformation(); - virtual bool initializeWithDictionary(ghoul::Dictionary* dictionary); + virtual bool initialize(); virtual const psc& position() const; virtual void update(); protected: diff --git a/src/scenegraph/positioninformation.h b/include/openspace/scenegraph/positioninformation.h similarity index 95% rename from src/scenegraph/positioninformation.h rename to include/openspace/scenegraph/positioninformation.h index d4be1b610d..dc6ce11ff6 100644 --- a/src/scenegraph/positioninformation.h +++ b/include/openspace/scenegraph/positioninformation.h @@ -25,19 +25,20 @@ #ifndef __POSITIONINFORMATION_H__ #define __POSITIONINFORMATION_H__ -#include "util/psc.h" +#include #include namespace openspace { class PositionInformation { public: - PositionInformation(); + PositionInformation(const ghoul::Dictionary& dictionary); virtual ~PositionInformation(); - virtual bool initializeWithDictionary(ghoul::Dictionary* dictionary) = 0; + virtual bool initialize() = 0; virtual const psc& position() const = 0; virtual void update() = 0; protected: + PositionInformation(); private: }; diff --git a/src/scenegraph/scenegraph.h b/include/openspace/scenegraph/scenegraph.h similarity index 91% rename from src/scenegraph/scenegraph.h rename to include/openspace/scenegraph/scenegraph.h index 2b772af521..999372d888 100644 --- a/src/scenegraph/scenegraph.h +++ b/include/openspace/scenegraph/scenegraph.h @@ -26,7 +26,7 @@ #define SCENEGRAPH_H // open space includes -#include "scenegraph/scenegraphnode.h" +#include // std includes #include @@ -45,10 +45,20 @@ public: SceneGraph(); ~SceneGraph(); - /* + /** * Initalizes the SceneGraph by loading modules from the ${SCENEPATH} directory */ - void initialize(); + bool initialize(); + + /* + * Clean up everything + */ + bool deinitialize(); + + /* + * Load the scenegraph from the provided folder + */ + bool loadFromModulePath(const std::string& path); /* * Updates all SceneGraphNodes relative positions @@ -77,9 +87,10 @@ public: private: - void loadFromModulePath(); void loadModulesFromModulePath(const std::string& modulePath); + std::string _focus, _position; + // actual scenegraph SceneGraphNode *_root; std::vector _nodes; diff --git a/src/scenegraph/scenegraphnode.h b/include/openspace/scenegraph/scenegraphnode.h similarity index 80% rename from src/scenegraph/scenegraphnode.h rename to include/openspace/scenegraph/scenegraphnode.h index bbd0efe12a..a7480ec4e0 100644 --- a/src/scenegraph/scenegraphnode.h +++ b/include/openspace/scenegraph/scenegraphnode.h @@ -26,8 +26,8 @@ #define SCENEGRAPHNODE_H // open space includes -#include "rendering/renderable.h" -#include "positioninformation.h" +#include +#include #include @@ -42,13 +42,11 @@ class SceneGraphNode { public: // constructors & destructor - SceneGraphNode(); + SceneGraphNode(const ghoul::Dictionary& dictionary); ~SceneGraphNode(); - bool isInitialized(); - bool initialize(); - bool initializeWithDictionary(ghoul::Dictionary* dictionary); + bool deinitialize(); // essential void update(); @@ -62,29 +60,17 @@ public: void setParent(SceneGraphNode *parent); const psc& getPosition() const; psc getWorldPosition() const; - std::string nodeName() const { return _nodeName; } + std::string nodeName() const; - SceneGraphNode* parent() const { return _parent; } - const std::vector& children() const { return _children; } + SceneGraphNode* parent() const; + const std::vector& children() const; // bounding sphere pss calculateBoundingSphere(); - SceneGraphNode* get(const std::string& name) { - if (_nodeName == name) - return this; - else - for (auto it : _children) - return it->get(name); - return nullptr; - } + SceneGraphNode* get(const std::string& name); - void print() const { - std::cout << _nodeName << std::endl; - for (auto it : _children) { - it->print(); - } - } + void print() const; // renderable void setRenderable(Renderable *renderable); @@ -92,9 +78,6 @@ public: private: - // private initialize helper - bool _initialize(); - // essential std::vector _children; SceneGraphNode* _parent; @@ -115,6 +98,6 @@ private: } // namespace openspace -#include +#include #endif \ No newline at end of file diff --git a/src/scenegraph/scenegraphnode.inl b/include/openspace/scenegraph/scenegraphnode.inl similarity index 81% rename from src/scenegraph/scenegraphnode.inl rename to include/openspace/scenegraph/scenegraphnode.inl index 4edad4026f..4708f9fade 100644 --- a/src/scenegraph/scenegraphnode.inl +++ b/include/openspace/scenegraph/scenegraphnode.inl @@ -25,30 +25,29 @@ #ifndef SCENEGRAPHNODE_INL #define SCENEGRAPHNODE_INL -#include +#include namespace openspace { template -bool safeInitializeWithDictionary(T** object, const std::string& key, -ghoul::Dictionary* dictionary, const std::string& path = "") { +bool safeCreationWithDictionary( T** object, + const std::string& key, + 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); + T* tmp = factory->create(renderableType, tmpDictionary); if(tmp != nullptr) { - if ( ! tmpDictionary.hasKey("Path") && path != "") { - tmpDictionary.setValue("Path", path); - } - if(tmp->initializeWithDictionary(&tmpDictionary)) { - *object = tmp; - return true; - } else { - delete tmp; - } + *object = tmp; + return true; } } } diff --git a/src/scenegraph/spicepositioninformation.h b/include/openspace/scenegraph/spicepositioninformation.h similarity index 91% rename from src/scenegraph/spicepositioninformation.h rename to include/openspace/scenegraph/spicepositioninformation.h index b917b12e05..04108ba2c7 100644 --- a/src/scenegraph/spicepositioninformation.h +++ b/include/openspace/scenegraph/spicepositioninformation.h @@ -25,22 +25,23 @@ #ifndef __SPICEPOSITIONINFORMATION_H__ #define __SPICEPOSITIONINFORMATION_H__ -#include "positioninformation.h" +#include -#include +#include namespace openspace { class SpicePositionInformation: public PositionInformation { public: - SpicePositionInformation(); + SpicePositionInformation(const ghoul::Dictionary& dictionary); virtual ~SpicePositionInformation(); - virtual bool initializeWithDictionary(ghoul::Dictionary* dictionary); + virtual bool initialize(); virtual const psc& position() const; virtual void update(); protected: private: + std::string _targetName, _originName; int _target, _origin; psc _position; diff --git a/include/openspace/tests/test_common.inl b/include/openspace/tests/test_common.inl new file mode 100644 index 0000000000..1e0abd4b26 --- /dev/null +++ b/include/openspace/tests/test_common.inl @@ -0,0 +1,111 @@ +/***************************************************************************************** + * * + * GHOUL * + * General Helpful Open Utility Library * + * * + * Copyright (c) 2012-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. * + ****************************************************************************************/ + +#ifdef GHL_TIMING_TESTS + +#ifdef WIN32 +#define START_TIMER(__name__, __stream__, __num__) \ + __stream__ << #__name__; \ + double __name__##Total = 0.0; \ + unsigned int __name__##Num = 0; \ + for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \ + reset(); \ + LARGE_INTEGER __name__##Start; \ + LARGE_INTEGER __name__##End; \ + QueryPerformanceCounter(&__name__##Start) + +#define START_TIMER_NO_RESET(__name__, __stream__, __num__) \ + __stream__ << #__name__; \ + double __name__##Total = 0.0; \ + unsigned int __name__##Num = 0; \ + for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \ + LARGE_INTEGER __name__##Start; \ + LARGE_INTEGER __name__##End; \ + QueryPerformanceCounter(&__name__##Start) + +#define START_TIMER_PREPARE(__name__, __stream__, __num__, __prepare__) \ + __stream__ << #__name__; \ + double __name__##Total = 0.0; \ + unsigned int __name__##Num = 0; \ + for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \ + reset(); \ + __prepare__; \ + LARGE_INTEGER __name__##Start; \ + LARGE_INTEGER __name__##End; \ + QueryPerformanceCounter(&__name__##Start) + +#define FINISH_TIMER(__name__, __stream__) \ + QueryPerformanceCounter(&__name__##End); \ + LARGE_INTEGER freq; \ + QueryPerformanceFrequency(&freq); \ + const double freqD = double(freq.QuadPart) / 1000000.0; \ + const double res = ((__name__##End.QuadPart - __name__##Start.QuadPart) / freqD);\ + __name__##Total += res; \ + } \ + __stream__ << '\t' << __name__##Total / __name__##Num << "us\n"; + +#else + +#include + +#define START_TIMER(__name__, __stream__, __num__) \ + __stream__ << #__name__; \ + std::chrono::nanoseconds __name__##Total = std::chrono::nanoseconds(0); \ + unsigned int __name__##Num = 0; \ + for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \ + reset(); \ + std::chrono::high_resolution_clock::time_point __name__##End; \ + std::chrono::high_resolution_clock::time_point __name__##Start = \ + std::chrono::high_resolution_clock::now() + +#define START_TIMER_NO_RESET(__name__, __stream__, __num__) \ + __stream__ << #__name__; \ + std::chrono::nanoseconds __name__##Total = std::chrono::nanoseconds(0); \ + unsigned int __name__##Num = 0; \ + for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \ + std::chrono::high_resolution_clock::time_point __name__##End; \ + std::chrono::high_resolution_clock::time_point __name__##Start = \ + std::chrono::high_resolution_clock::now() + +#define START_TIMER_PREPARE(__name__, __stream__, __num__, __prepare__) \ + __stream__ << #__name__; \ + std::chrono::nanoseconds __name__##Total = std::chrono::nanoseconds(0); \ + unsigned int __name__##Num = 0; \ + for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \ + reset(); \ + __prepare__; \ + std::chrono::high_resolution_clock::time_point __name__##End; \ + std::chrono::high_resolution_clock::time_point __name__##Start = \ + std::chrono::high_resolution_clock::now() + +#define FINISH_TIMER(__name__, __stream__) \ + __name__##End = std::chrono::high_resolution_clock::now(); \ + const std::chrono::nanoseconds d = __name__##End - __name__##Start; \ + __name__##Total += d; \ + } \ + __stream__ << #__name__ << '\t' << __name__##Total.count() / 1000.0 << "us" << '\n'; +#endif + +#endif // GHL_TIMING_TESTS diff --git a/include/openspace/tests/test_powerscalecoordinates.inl b/include/openspace/tests/test_powerscalecoordinates.inl new file mode 100644 index 0000000000..454e61b7df --- /dev/null +++ b/include/openspace/tests/test_powerscalecoordinates.inl @@ -0,0 +1,83 @@ +/***************************************************************************************** + * * + * GHOUL * + * General Helpful Open Utility Library * + * * + * Copyright (c) 2012-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. * + ****************************************************************************************/ + +#include "gtest/gtest.h" + +#include +#include + +class PowerscaleCoordinatesTest : public testing::Test { +protected: + PowerscaleCoordinatesTest() { + } + + ~PowerscaleCoordinatesTest() { + } + + void reset() { + } + + openspace::SceneGraph* scenegraph; +}; + + +TEST_F(PowerscaleCoordinatesTest, psc) { + + openspace::psc reference(2.0, 1.0, 1.1, 1.0); + + openspace::psc first(1.0,0.0,1.0,0.0); + openspace::psc second(1.9,1.0,1.0,1.0); + + EXPECT_EQ(reference, first + second); + EXPECT_TRUE(reference == (first + second)); + + openspace::psc third = first; + first[0] = 0.0; + + EXPECT_TRUE(third != first); + + +} + +TEST_F(PowerscaleCoordinatesTest, pss) { + + openspace::pss first(1.0,1.0); + openspace::pss second(1.0,-1.0); + EXPECT_EQ(openspace::pss(1.01,1.0), first + second); + EXPECT_EQ(openspace::pss(1.01,1.0), second + first); + /* + EXPECT_TRUE(first < (first + second)); + bool retu =(second < (first + second)); + + std::cout << "retu: " << retu << std::endl; + EXPECT_TRUE(retu); + + EXPECT_FALSE(first > (first + second)); + EXPECT_FALSE(second > (first + second)); + + */ +} + + diff --git a/include/openspace/tests/test_scenegraph.inl b/include/openspace/tests/test_scenegraph.inl new file mode 100644 index 0000000000..50e08fc5d9 --- /dev/null +++ b/include/openspace/tests/test_scenegraph.inl @@ -0,0 +1,105 @@ +/***************************************************************************************** + * * + * GHOUL * + * General Helpful Open Utility Library * + * * + * Copyright (c) 2012-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. * + ****************************************************************************************/ + +#include "gtest/gtest.h" + +#include +#include +#include +#include +#include + +class SceneGraphTest : public testing::Test { +protected: + SceneGraphTest() { + _scenegraph = new openspace::SceneGraph; + } + + ~SceneGraphTest() { + _scenegraph = new openspace::SceneGraph; + } + + void reset() { + delete _scenegraph; + _scenegraph = new openspace::SceneGraph; + } + + openspace::SceneGraph* _scenegraph; +}; + +TEST_F(SceneGraphTest, SceneGraphNode) { + + + openspace::SceneGraphNode* node = new openspace::SceneGraphNode(ghoul::Dictionary()); + EXPECT_EQ(nullptr, node->getRenderable()); + EXPECT_EQ(openspace::psc(), node->getPosition()); + + delete node; + ghoul::Dictionary nodeDictionary; + ghoul::Dictionary positionDictionary; + //nodeDictionary.setValue("Renderable.Type", "RenderablePlanet"); + positionDictionary.setValue("Type", "Static"); + positionDictionary.setValue("Position.1", 1.0); + positionDictionary.setValue("Position.2", 1.0); + positionDictionary.setValue("Position.3", 1.0); + positionDictionary.setValue("Position.4", 1.0); + + nodeDictionary.setValue("Position", positionDictionary); + + node = new openspace::SceneGraphNode(nodeDictionary); + //EXPECT_TRUE(node->getRenderable()); + EXPECT_EQ(openspace::psc(1.0,1.0,1.0,1.0), node->getPosition()); + + delete node; +} + +TEST_F(SceneGraphTest, Loading) { + + + // Should not successfully load a non existing scenegraph + EXPECT_FALSE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTestNonExisting"))); + + // Existing scenegraph should load + EXPECT_TRUE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTest"))); + + // This loading should fail regardless of existing or not since the + // scenegraph is already loaded + EXPECT_FALSE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTest"))); +} + +TEST_F(SceneGraphTest, Reinitializing) { + + // Existing scenegraph should load + EXPECT_TRUE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTest"))); + + _scenegraph->deinitialize(); + + // Existing scenegraph should load + EXPECT_TRUE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTest"))); +} + + + + diff --git a/src/util/camera.h b/include/openspace/util/camera.h similarity index 97% rename from src/util/camera.h rename to include/openspace/util/camera.h index 1e94cce422..c9c945d505 100644 --- a/src/util/camera.h +++ b/include/openspace/util/camera.h @@ -2,7 +2,7 @@ #define CAMERA_H // open space includes -#include "util/psc.h" +#include // glm includes #include diff --git a/src/util/factorymanager.h b/include/openspace/util/factorymanager.h similarity index 97% rename from src/util/factorymanager.h rename to include/openspace/util/factorymanager.h index 06dda55c44..8cbc8dcfc5 100644 --- a/src/util/factorymanager.h +++ b/include/openspace/util/factorymanager.h @@ -29,8 +29,8 @@ #include #include -#include "scenegraph/positioninformation.h" -#include "rendering/renderable.h" +#include +#include namespace openspace { diff --git a/src/util/geometry.h b/include/openspace/util/geometry.h similarity index 97% rename from src/util/geometry.h rename to include/openspace/util/geometry.h index c76126cb98..fa29eed4d9 100644 --- a/src/util/geometry.h +++ b/include/openspace/util/geometry.h @@ -11,7 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #define GEOMETRY_H // open space includes -#include "util/vbo.h" +#include namespace gl4 { diff --git a/src/util/planet.h b/include/openspace/util/planet.h similarity index 95% rename from src/util/planet.h rename to include/openspace/util/planet.h index abcd16a2e1..b59d476419 100644 --- a/src/util/planet.h +++ b/include/openspace/util/planet.h @@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #define PLANET_H // open space includes -#include "util/pss.h" -#include "util/vbo_template.h" +#include +#include // std includes #include diff --git a/src/util/powerscaledsphere.h b/include/openspace/util/powerscaledsphere.h similarity index 94% rename from src/util/powerscaledsphere.h rename to include/openspace/util/powerscaledsphere.h index 6985e86d94..da4e2246ce 100644 --- a/src/util/powerscaledsphere.h +++ b/include/openspace/util/powerscaledsphere.h @@ -12,8 +12,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI // open space includes #include -#include -#include +#include +#include namespace openspace { @@ -37,6 +37,8 @@ namespace openspace { PowerScaledSphere(const pss radius, int segments = 8); ~PowerScaledSphere(); + bool initialize(); + void render(); private: diff --git a/src/util/psc.h b/include/openspace/util/psc.h similarity index 92% rename from src/util/psc.h rename to include/openspace/util/psc.h index 03e05bb64b..37abcf2ba8 100644 --- a/src/util/psc.h +++ b/include/openspace/util/psc.h @@ -6,6 +6,7 @@ #include #include #include +#include namespace openspace { @@ -64,7 +65,8 @@ public: const psc operator*(const pss &rhs) const; // comparasion - bool operator==(const psc &other) const; + bool operator==(const psc &other) const; + bool operator!=(const psc &other) const; bool operator<(const psc &other) const; bool operator>(const psc &other) const; bool operator<=(const psc &other) const; @@ -75,6 +77,8 @@ public: psc & operator=(const glm::vec3 &rhs); psc & operator=(const glm::dvec4 &rhs); psc & operator=(const glm::dvec3 &rhs); + + friend std::ostream& operator<<(::std::ostream& os, const psc& rhs); // allow the power scaled scalars to acces private members friend class pss; diff --git a/src/util/pss.h b/include/openspace/util/pss.h similarity index 95% rename from src/util/pss.h rename to include/openspace/util/pss.h index b47053fd3e..2fd263d7e1 100644 --- a/src/util/pss.h +++ b/include/openspace/util/pss.h @@ -6,6 +6,8 @@ #include #include +#include + namespace openspace { @@ -68,6 +70,8 @@ public: pss & operator=(const float &rhs); pss & operator=(const glm::dvec2 &rhs); pss & operator=(const double &rhs); + + friend std::ostream& operator<<(::std::ostream& os, const pss& rhs); // allow the power scaled coordinates to acces private members friend class psc; diff --git a/src/util/sphere.h b/include/openspace/util/sphere.h similarity index 97% rename from src/util/sphere.h rename to include/openspace/util/sphere.h index 95734e2c73..f231052574 100644 --- a/src/util/sphere.h +++ b/include/openspace/util/sphere.h @@ -11,7 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #define SPHERE_H // open space includes -#include "util/geometry.h" +#include namespace gl4 { diff --git a/src/util/spice.h b/include/openspace/util/spice.h similarity index 100% rename from src/util/spice.h rename to include/openspace/util/spice.h diff --git a/src/util/time.h b/include/openspace/util/time.h similarity index 100% rename from src/util/time.h rename to include/openspace/util/time.h diff --git a/src/util/vbo.h b/include/openspace/util/vbo.h similarity index 100% rename from src/util/vbo.h rename to include/openspace/util/vbo.h diff --git a/src/util/vbo_template.h b/include/openspace/util/vbo_template.h similarity index 100% rename from src/util/vbo_template.h rename to include/openspace/util/vbo_template.h diff --git a/openspace-data b/openspace-data index 707eb16fa6..b59ef502a9 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 707eb16fa66bf4121782fd0eecc0f0b383a64429 +Subproject commit b59ef502a993c8a656c838d445ebbd2e3a146114 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 93826b35a1..2d4f778496 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,60 +26,54 @@ #set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) set(SOURCE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -set(HEADER_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) - -file(GLOB MAIN_SOURCE ${SOURCE_ROOT_DIR}/*.cpp) -set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${MAIN_SOURCE}) -file(GLOB MAIN_HEADER ${SOURCE_ROOT_DIR}/*.h) -set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${MAIN_HEADER}) -source_group(Main FILES ${MAIN_SOURCE} ${MAIN_HEADER}) +set(HEADER_ROOT_DIR ${CMAKE_SOURCE_DIR}/include) file(GLOB CONFIGURATION_SOURCE ${SOURCE_ROOT_DIR}/configuration/*.cpp) set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${CONFIGURATION_SOURCE}) -file(GLOB CONFIGURATION_HEADER ${HEADER_ROOT_DIR}/configuration/*.h) +file(GLOB CONFIGURATION_HEADER ${HEADER_ROOT_DIR}/openspace/configuration/*.h) set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${CONFIGURATION_HEADER}) source_group(Configuration FILES ${CONFIGURATION_SOURCE} ${CONFIGURATION_HEADER}) file(GLOB ENGINE_SOURCE ${SOURCE_ROOT_DIR}/engine/*.cpp) set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${ENGINE_SOURCE}) -file(GLOB ENGINE_HEADER ${HEADER_ROOT_DIR}/engine/*.h) +file(GLOB ENGINE_HEADER ${HEADER_ROOT_DIR}/openspace/engine/*.h) set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${ENGINE_HEADER}) source_group(Engine FILES ${ENGINE_SOURCE} ${ENGINE_HEADER}) file(GLOB INTERACTION_SOURCE ${SOURCE_ROOT_DIR}/interaction/*.cpp) set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${INTERACTION_SOURCE}) -file(GLOB INTERACTION_HEADER ${HEADER_ROOT_DIR}/interaction/*.h) +file(GLOB INTERACTION_HEADER ${HEADER_ROOT_DIR}/openspace/interaction/*.h) set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${INTERACTION_HEADER}) source_group(Interaction FILES ${INTERACTION_SOURCE} ${INTERACTION_HEADER}) file(GLOB INTERACTION_EXTERNALCONTROL_SOURCE ${SOURCE_ROOT_DIR}/interaction/externalcontrol/*.cpp) set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${INTERACTION_EXTERNALCONTROL_SOURCE}) -file(GLOB INTERACTION_EXTERNALCONTROL_HEADER ${HEADER_ROOT_DIR}/interaction/externalcontrol/*.h) +file(GLOB INTERACTION_EXTERNALCONTROL_HEADER ${HEADER_ROOT_DIR}/openspace/interaction/externalcontrol/*.h) set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${INTERACTION_EXTERNALCONTROL_HEADER}) source_group(Interaction\\ExternalControl FILES ${INTERACTION_EXTERNALCONTROL_SOURCE} ${INTERACTION_EXTERNALCONTROL_HEADER}) file(GLOB QUERY_SOURCE_CPP ${SOURCE_ROOT_DIR}/query/*.cpp) file(GLOB QUERY_SOURCE_C ${SOURCE_ROOT_DIR}/query/*.c) set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${QUERY_SOURCE_CPP} ${QUERY_SOURCE_C}) -file(GLOB QUERY_HEADER ${HEADER_ROOT_DIR}/query/*.h) +file(GLOB QUERY_HEADER ${HEADER_ROOT_DIR}/openspace/query/*.h) set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${QUERY_HEADER}) source_group(Query FILES ${QUERY_SOURCE_CPP} ${QUERY_SOURCE_C} ${QUERY_HEADER}) file(GLOB RENDERING_SOURCE ${SOURCE_ROOT_DIR}/rendering/*.cpp) set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${RENDERING_SOURCE}) -file(GLOB RENDERING_HEADER ${HEADER_ROOT_DIR}/rendering/*.h) +file(GLOB RENDERING_HEADER ${HEADER_ROOT_DIR}/openspace/rendering/*.h) set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${RENDERING_HEADER}) source_group(Rendering FILES ${RENDERING_SOURCE} ${RENDERING_HEADER}) file(GLOB SCENEGRAPH_SOURCE ${SOURCE_ROOT_DIR}/scenegraph/*.cpp) set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${SCENEGRAPH_SOURCE}) -file(GLOB SCENEGRAPH_HEADER ${HEADER_ROOT_DIR}/scenegraph/*.h ${HEADER_ROOT_DIR}/scenegraph/*.inl) +file(GLOB SCENEGRAPH_HEADER ${HEADER_ROOT_DIR}/openspace/scenegraph/*.h ${HEADER_ROOT_DIR}/openspace/scenegraph/*.inl) set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${SCENEGRAPH_HEADER}) source_group(SceneGraph FILES ${SCENEGRAPH_SOURCE} ${SCENEGRAPH_HEADER}) file(GLOB UTIL_SOURCE ${SOURCE_ROOT_DIR}/util/*.cpp) set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${UTIL_SOURCE}) -file(GLOB UTIL_HEADER ${HEADER_ROOT_DIR}/util/*.h) +file(GLOB UTIL_HEADER ${HEADER_ROOT_DIR}/openspace/util/*.h) set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${UTIL_HEADER}) source_group(Util FILES ${UTIL_SOURCE} ${UTIL_HEADER}) @@ -89,27 +83,7 @@ include_directories(${HEADER_ROOT_DIR}) set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${OPENSPACE_EXT_DIR}/tinythread.cpp) include_directories(${GHOUL_ROOT_DIR}/ext/boost) -if (APPLE) - find_library(FRAMEWORK_IOKit - NAMES IOKit - PATHS ${CMAKE_OSX_SYSROOT}/System/Library - PATH_SUFFIXES Frameworks - NO_DEFAULT_PATH - ) - find_library(FRAMEWORK_CoreVideo - NAMES CoreVideo - PATHS ${CMAKE_OSX_SYSROOT}/System/Library - PATH_SUFFIXES Frameworks - NO_DEFAULT_PATH - ) - find_library(FRAMEWORK_Cocoa - NAMES Cocoa - PATHS ${CMAKE_OSX_SYSROOT}/System/Library - PATH_SUFFIXES Frameworks - NO_DEFAULT_PATH - ) - set(SGCT_DEPENDENCIES ${SGCT_DEPENDENCIES} ${FRAMEWORK_IOKit} ${FRAMEWORK_CoreVideo} ${FRAMEWORK_Cocoa}) -endif (APPLE) +add_definitions(-DBASE_PATH="${CMAKE_SOURCE_DIR}") if (APPLE) add_definitions(-D__APPLE__) @@ -124,5 +98,10 @@ if (UNIX AND NOT APPLE) endif (UNIX AND NOT APPLE) -add_executable(OpenSpace ${OPENSPACE_HEADER} ${OPENSPACE_SOURCE}) +include_directories("${HEADER_ROOT_DIR}") + +add_executable(OpenSpace ${SOURCE_ROOT_DIR}/main.cpp ${OPENSPACE_HEADER} ${OPENSPACE_SOURCE}) target_link_libraries(OpenSpace ${DEPENDENT_LIBS}) + +add_subdirectory(tests) + diff --git a/src/openspaceengine.cpp b/src/engine/openspaceengine.cpp similarity index 91% rename from src/openspaceengine.cpp rename to src/engine/openspaceengine.cpp index 7076f50965..db312f2fb0 100644 --- a/src/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -22,17 +22,17 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include "openspaceengine.h" +#include // sgct header has to be included before all others due to Windows header #include "sgct.h" -#include "interaction/deviceidentifier.h" -#include "interaction/interactionhandler.h" -#include "rendering/renderengine.h" -#include "util/time.h" -#include "util//spice.h" -#include +#include +#include +#include +#include +#include +#include #include #include @@ -55,9 +55,7 @@ OpenSpaceEngine::OpenSpaceEngine() , _interactionHandler(nullptr) , _renderEngine(nullptr) , _scriptEngine(nullptr) -{ - -} +{} OpenSpaceEngine::~OpenSpaceEngine() { delete _configurationManager; @@ -87,6 +85,7 @@ void OpenSpaceEngine::create(int argc, char** argv, int& newArgc, char**& newArg newArgv = new char*[3]; newArgv[0] = "prog"; newArgv[1] = "-config"; + newArgv[2] = "../../config/single.xml"; #ifdef __WIN32__ // Windows uses fixed path to OpenSpace data newArgv[2] = "../../config/single.xml"; @@ -109,29 +108,20 @@ void OpenSpaceEngine::destroy() { delete _engine; } +bool OpenSpaceEngine::isInitialized() { + return _engine != nullptr; +} + bool OpenSpaceEngine::initialize() { // initialize ghou logging LogManager::initialize(LogManager::LogLevel::Debug, true); LogMgr.addLog(new ConsoleLog); - // Initialize ghoul filesystem and set path variables + // Register the filepaths from static function enables easy testing ghoul::filesystem::FileSystem::initialize(); -#ifdef __WIN32__ - // Windows: Binary two folders down - FileSys.registerPathToken("${BASE_PATH}", "../.."); -#elif __APPLE__ - // OS X : Binary three folders down - FileSys.registerPathToken("${BASE_PATH}", "../../.."); -#else - // Linux : Binary three folders down - FileSys.registerPathToken("${BASE_PATH}", ".."); -#endif - FileSys.registerPathToken("${SCRIPTS}", "${BASE_PATH}/scripts"); - FileSys.registerPathToken("${OPENSPACE-DATA}", "${BASE_PATH}/openspace-data"); - FileSys.registerPathToken("${SCENEPATH}", "${OPENSPACE-DATA}/scene"); - FileSys.registerPathToken("${SHADERS}", "${BASE_PATH}/shaders"); - + registerFilePaths(); + // initialize the configurationmanager with the default configuration _configurationManager->initialize(); _configurationManager->loadConfiguration(absPath("${SCRIPTS}/DefaultConfig.lua")); @@ -162,6 +152,31 @@ bool OpenSpaceEngine::initialize() { return true; } +bool OpenSpaceEngine::registerFilePaths() { + +// Check if CMake have provided an base path. +#ifndef BASE_PATH +#ifdef __WIN32__ + // Windows: Binary two folders down + #define BASE_PATH "../.." +#elif __APPLE__ + // OS X : Binary three folders down + #define BASE_PATH "../../.." +#else + // Linux : Binary three folders down + #define BASE_PATH ".." +#endif +#endif + + FileSys.registerPathToken("${BASE_PATH}", BASE_PATH); + FileSys.registerPathToken("${SCRIPTS}", "${BASE_PATH}/scripts"); + FileSys.registerPathToken("${OPENSPACE-DATA}", "${BASE_PATH}/openspace-data"); + FileSys.registerPathToken("${SCENEPATH}", "${OPENSPACE-DATA}/scene"); + FileSys.registerPathToken("${SHADERS}", "${BASE_PATH}/shaders"); + + return true; +} + ghoul::ConfigurationManager& OpenSpaceEngine::configurationManager() { // TODO custom assert (ticket #5) assert(_configurationManager != nullptr); diff --git a/src/interaction/deviceidentifier.cpp b/src/interaction/deviceidentifier.cpp index dec0b14c79..408402129b 100644 --- a/src/interaction/deviceidentifier.cpp +++ b/src/interaction/deviceidentifier.cpp @@ -1,6 +1,6 @@ // open space includes -#include "deviceidentifier.h" +#include // sgct includes //#include "sgct.h" diff --git a/src/interaction/externalcontrol/externalconnectioncontroller.cpp b/src/interaction/externalcontrol/externalconnectioncontroller.cpp index 54ec5ebac3..4ea86f2fed 100644 --- a/src/interaction/externalcontrol/externalconnectioncontroller.cpp +++ b/src/interaction/externalcontrol/externalconnectioncontroller.cpp @@ -1,4 +1,4 @@ -#include "interaction/externalcontrol/externalconnectioncontroller.h" +#include namespace openspace { diff --git a/src/interaction/externalcontrol/externalcontrol.cpp b/src/interaction/externalcontrol/externalcontrol.cpp index c3cf9b93a2..81d0ec89b7 100644 --- a/src/interaction/externalcontrol/externalcontrol.cpp +++ b/src/interaction/externalcontrol/externalcontrol.cpp @@ -1,6 +1,6 @@ -#include "interaction/externalcontrol/externalcontrol.h" -#include "interaction/interactionhandler.h" -#include "openspaceengine.h" +#include +#include +#include #include namespace openspace { diff --git a/src/interaction/externalcontrol/randomexternalcontrol.cpp b/src/interaction/externalcontrol/randomexternalcontrol.cpp index feca3b9b7d..b15446fb24 100644 --- a/src/interaction/externalcontrol/randomexternalcontrol.cpp +++ b/src/interaction/externalcontrol/randomexternalcontrol.cpp @@ -1,4 +1,4 @@ -#include "interaction/externalcontrol/randomexternalcontrol.h" +#include #include #ifndef __WIN32__ diff --git a/src/interaction/interactionhandler.cpp b/src/interaction/interactionhandler.cpp index f77e8152b5..9290b56389 100644 --- a/src/interaction/interactionhandler.cpp +++ b/src/interaction/interactionhandler.cpp @@ -1,11 +1,11 @@ // open space includes -#include "interactionhandler.h" -#include "deviceidentifier.h" -#include "externalcontrol/randomexternalcontrol.h" -#include "externalcontrol/joystickexternalcontrol.h" -#include "query/query.h" -#include "openspaceengine.h" +#include +#include +#include +#include +#include +#include // std includes #include diff --git a/src/main.cpp b/src/main.cpp index fe48453136..9d57830264 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,7 +24,7 @@ // open space includes -#include "openspaceengine.h" +#include // sgct includes #include "sgct.h" diff --git a/src/query/query.cpp b/src/query/query.cpp index d905337d17..0fa249df59 100644 --- a/src/query/query.cpp +++ b/src/query/query.cpp @@ -22,9 +22,9 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include "query/query.h" +#include -#include "openspaceengine.h" +#include namespace openspace { diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index ca2a8c9e44..fcf07c5e43 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -1,12 +1,12 @@ // open space includes -#include "renderable.h" +#include namespace openspace { + +Renderable::Renderable() {} -Renderable::Renderable() { - -} +Renderable::Renderable(const ghoul::Dictionary& dictionary) {} Renderable::~Renderable() { diff --git a/src/rendering/renderablebody.cpp b/src/rendering/renderablebody.cpp index e61601648f..c35c3cebae 100644 --- a/src/rendering/renderablebody.cpp +++ b/src/rendering/renderablebody.cpp @@ -1,6 +1,6 @@ // open space includes -#include "renderablebody.h" +#include namespace openspace { /* diff --git a/src/rendering/renderableplanet.cpp b/src/rendering/renderableplanet.cpp index 64e50c3dc1..d9bff7dddc 100644 --- a/src/rendering/renderableplanet.cpp +++ b/src/rendering/renderableplanet.cpp @@ -1,11 +1,11 @@ // open space includes -#include "renderableplanet.h" +#include #include #include -#include +#include #include namespace { @@ -14,68 +14,81 @@ namespace { namespace openspace { -RenderablePlanet::RenderablePlanet(): programObject_(nullptr), texture_(nullptr), - planet_(nullptr) {} - -RenderablePlanet::~RenderablePlanet() { - delete planet_; -} - -bool RenderablePlanet::initialize() { - - if (programObject_ == nullptr) { - OsEng.ref().configurationManager().getValue("pscShader", programObject_); - } - if (programObject_ == nullptr) { - return false; - } - - return true; -} - -bool RenderablePlanet::initializeWithDictionary(ghoul::Dictionary* dictionary) { - - if ( ! initialize()) { - return false; - } - +RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary): programObject_(nullptr), + _texturePath(""), + texture_(nullptr), + planet_(nullptr) +{ double value = 1.0f, exponent= 0.0f; double segments = 20.0; - if(dictionary->hasKey("Geometry.Radius.1")) - dictionary->getValue("Geometry.Radius.1", value); + if(dictionary.hasKey("Geometry.Radius.1")) + dictionary.getValue("Geometry.Radius.1", value); - if(dictionary->hasKey("Geometry.Radius.2")) - dictionary->getValue("Geometry.Radius.2", exponent); + if(dictionary.hasKey("Geometry.Radius.2")) + dictionary.getValue("Geometry.Radius.2", exponent); - if(dictionary->hasKey("Geometry.Segments")) - dictionary->getValue("Geometry.Segments", segments); + if(dictionary.hasKey("Geometry.Segments")) + dictionary.getValue("Geometry.Segments", segments); // create the power scaled scalar pss planetSize(value, exponent); setBoundingSphere(planetSize); // get path if available - std::string path; - dictionary->getValue("Path", path); + std::string path = ""; + if(dictionary.hasKey("Path")) { + dictionary.getValue("Path", path); + path += "/"; + } - if(dictionary->hasKey("Textures.Color")) { + if(dictionary.hasKey("Textures.Color")) { std::string texturePath; - dictionary->getValue("Textures.Color", texturePath); - std::string fullpath = path + "/" + texturePath; - texture_ = ghoul::opengl::loadTexture(fullpath); - if (texture_) { - LDEBUG("Loaded texture from '" << fullpath <<"'"); - texture_->uploadTexture(); - } + dictionary.getValue("Textures.Color", texturePath); + _texturePath = path + texturePath; } planet_ = new PowerScaledSphere(pss(value, exponent), static_cast(segments)); +} + +RenderablePlanet::~RenderablePlanet() { + deinitialize(); +} + +bool RenderablePlanet::initialize() { + + bool completeSuccess = true; + if (programObject_ == nullptr) { + completeSuccess = OsEng.ref().configurationManager().getValue("pscShader", programObject_); + } + + if(_texturePath != "") { + texture_ = ghoul::opengl::loadTexture(_texturePath); + if (texture_) { + LDEBUG("Loaded texture from '" << _texturePath <<"'"); + texture_->uploadTexture(); + } else { + completeSuccess = false; + } + } + planet_->initialize(); + + return completeSuccess; +} + + + +bool RenderablePlanet::deinitialize() { + if(planet_) + delete planet_; + + if(texture_) + delete texture_; return true; } -void RenderablePlanet::setProgramObject(ghoul::opengl::ProgramObject *programObject = nullptr) { +void RenderablePlanet::setProgramObject(ghoul::opengl::ProgramObject *programObject) { assert(programObject); programObject_ = programObject; } diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 4ab0a88376..66f441b105 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -22,14 +22,16 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include "rendering/renderengine.h" +#include -#include "openspaceengine.h" -#include "scenegraph/scenegraph.h" -#include "util/camera.h" +#include +#include +#include #include "sgct.h" +#include + namespace { const std::string _loggerCat = "RenderEngine"; } @@ -56,6 +58,7 @@ bool RenderEngine::initialize() { // initialize scenegraph _sceneGraph = new SceneGraph; + _sceneGraph->loadFromModulePath(absPath("${SCENEPATH}")); _sceneGraph->initialize(); return true; diff --git a/src/scenegraph/constantpositioninformation.cpp b/src/scenegraph/constantpositioninformation.cpp index 69733de9d1..6581ddbb3e 100644 --- a/src/scenegraph/constantpositioninformation.cpp +++ b/src/scenegraph/constantpositioninformation.cpp @@ -22,30 +22,25 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include "constantpositioninformation.h" +#include namespace openspace { -ConstantPositionInformation::ConstantPositionInformation() {} +ConstantPositionInformation::ConstantPositionInformation(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); + } + _position = psc(x, y, z, e); +} ConstantPositionInformation::~ConstantPositionInformation() {} -bool ConstantPositionInformation::initializeWithDictionary(ghoul::Dictionary* dictionary) { - if ( dictionary == nullptr) { - _position = psc(0.0,0.0,0.0,0.0); - return true; - } - - if (dictionary->hasKey("Position.1")) { - double x, y, z, e; - - if (dictionary->getValue("Position.1", x) && dictionary->getValue("Position.2", y) && - dictionary->getValue("Position.3", z) && dictionary->getValue("Position.4", e)) { - _position = psc(x, y, z, e); - return true; - } - } - return false; +bool ConstantPositionInformation::initialize() { + return true; } const psc& ConstantPositionInformation::position() const { diff --git a/src/scenegraph/positioninformation.cpp b/src/scenegraph/positioninformation.cpp index dee277e66b..768a8140bb 100644 --- a/src/scenegraph/positioninformation.cpp +++ b/src/scenegraph/positioninformation.cpp @@ -22,11 +22,12 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include "positioninformation.h" +#include namespace openspace { - + PositionInformation::PositionInformation() {} +PositionInformation::PositionInformation(const ghoul::Dictionary& dictionary) {} PositionInformation::~PositionInformation() {} } // namespace openspace \ No newline at end of file diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index 93ef6accd0..eff994aaae 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -23,11 +23,11 @@ ****************************************************************************************/ // open space includes -#include "scenegraph/scenegraph.h" -#include "rendering/renderableplanet.h" -#include "interaction/interactionhandler.h" -#include "util/spice.h" -#include +#include +#include +#include +#include +#include // ghoul includes #include "ghoul/opengl/programobject.h" @@ -50,32 +50,115 @@ namespace { } namespace openspace { - -SceneGraph::SceneGraph() { - _root = nullptr; + +void printTree(SceneGraphNode* node, std::string pre = "") { + LDEBUGC("Tree", pre << node->nodeName()); + auto children = node->children(); + for(auto child: children) { + printTree(child, pre + " "); + } } + +SceneGraph::SceneGraph(): _focus("Root"), _position("Root"), _root(nullptr) {} SceneGraph::~SceneGraph() { - // deallocate the scene graph. Recursive deallocation will occur - // no need to remove from _nodes and _allNodes. - if(_root) - delete _root; + deinitialize(); } -void SceneGraph::initialize() { - // logger string - std::string _loggerCat = "SceneGraph::init"; +bool SceneGraph::initialize() { + LDEBUG("Initializing SceneGraph"); - // The ${SCENEPATH} variable needs to be set and the scene definition needs to exist - assert(FileSys.fileExists("${SCENEPATH}/default.scene")); + using ghoul::opengl::ShaderObject; + using ghoul::opengl::ProgramObject; + using ghoul::opengl::ShaderManager; - // load the scene - loadFromModulePath(); + ProgramObject* po = nullptr; + if ( OsEng.ref().configurationManager().hasKey("pscShader") && + OsEng.ref().configurationManager().getValue("pscShader", po)) { + LWARNING("pscShader already in ConfigurationManager, deleting."); + delete po; + po = nullptr; + } + + ShaderObject* powerscale_vs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeVertex, + absPath("${SHADERS}/pscstandard_vs.glsl"), + "PS Vertex" + ); + ShaderObject* powerscale_fs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeFragment, + absPath("${SHADERS}/pscstandard_fs.glsl"), + "PS Fragment" + ); + + po = new ProgramObject; + po->attachObject(powerscale_vs); + po->attachObject(powerscale_fs); + + if( ! po->compileShaderObjects()) + return false; + if( ! po->linkProgramObject()) + return false; + + OsEng.ref().configurationManager().setValue("pscShader", po); + + // Initialize all nodes + for(auto node: _nodes) { + bool success = node->initialize(); + if (success) { + LDEBUG(node->nodeName() << " initialized successfully!"); + } else { + LWARNING(node->nodeName() << " not initialized."); + } + } + + // update the position of all nodes + update(); // Calculate the bounding sphere for the scenegraph _root->calculateBoundingSphere(); + // set the camera position + auto focusIterator = _allNodes.find(_focus); + auto positionIterator = _allNodes.find(_position); + + if(focusIterator != _allNodes.end() && positionIterator != _allNodes.end()) { + LDEBUG("Camera position is '"<< _position <<"', camera focus is '" << _focus << "'"); + SceneGraphNode* focusNode = focusIterator->second; + SceneGraphNode* positionNode = positionIterator->second; + Camera* c = OsEng.interactionHandler().getCamera(); + + // TODO: Make distance depend on radius + // TODO: Set distance and camera direction in some more smart way + // TODO: Set scaling dependent on the position and distance + // set position for camera + psc cameraPosition = positionNode->getPosition(); + cameraPosition += psc(0.0,0.0,1.0,2.0); + c->setPosition(cameraPosition); + c->setCameraDirection(glm::vec3(0,0,-1)); + c->setScaling(glm::vec2(1.0,0.0)); + + // Set the focus node for the interactionhandler + OsEng.interactionHandler().setFocusNode(focusNode); + } + + + return true; +} + +bool SceneGraph::deinitialize() { + + // deallocate the scene graph. Recursive deallocation will occur + if(_root) + delete _root; + _root = nullptr; + + _nodes.erase(_nodes.begin(), _nodes.end()); + _allNodes.erase(_allNodes.begin(), _allNodes.end()); + + _focus = ""; + _position = ""; + + return true; } void SceneGraph::update() { @@ -92,26 +175,35 @@ void SceneGraph::render(Camera *camera) { _root->render(camera); } -void SceneGraph::loadFromModulePath() { - assert(_root == nullptr); +bool SceneGraph::loadFromModulePath(const std::string& path) { + + LDEBUG("Loading scenegraph nodes"); + if(_root != nullptr) { + LFATAL("Scenegraph already loaded"); + return false; + } + + std::string defaultScene = path + "/default.scene"; + if( ! FileSys.fileExists(defaultScene)) { + LFATAL("Could not find 'default.scene' in '" << path << "'"); + return false; + } ghoul::Dictionary dictionary; lua_State* state = luaL_newstate(); if (state == nullptr) { LFATAL("Error creating new Lua state: Memory allocation error"); - return; + return false; } luaL_openlibs(state); // initialize the root node - _root = new SceneGraphNode; - _root->initialize(); + _root = new SceneGraphNode(ghoul::Dictionary()); _root->setName("Root"); _nodes.push_back(_root); _allNodes.insert ( std::make_pair("Root", _root)); - - ghoul::lua::lua_loadIntoDictionary(state, &dictionary, absPath("${SCENEPATH}/default.scene")); + ghoul::lua::lua_loadIntoDictionary(state, &dictionary, defaultScene); ghoul::Dictionary moduleDictionary; if(dictionary.getValue("Modules", moduleDictionary)) { @@ -120,14 +212,11 @@ void SceneGraph::loadFromModulePath() { for (auto key: keys) { std::string moduleFolder; if(moduleDictionary.getValue(key, moduleFolder)) { - loadModulesFromModulePath(absPath("${SCENEPATH}/"+moduleFolder)); + loadModulesFromModulePath(path +"/"+moduleFolder); } } } - // update relative positions for all loaded objects. Necessary for Spice position modules - update(); - // TODO: Make it less hard-coded and more flexible when nodes are not found ghoul::Dictionary cameraDictionary; if(dictionary.getValue("Camera", cameraDictionary)) { @@ -135,37 +224,26 @@ void SceneGraph::loadFromModulePath() { std::string focus; std::string position; - if (cameraDictionary.getValue("Focus", focus) && - cameraDictionary.getValue("Position", position)) { - LDEBUG("focus & position found " << focus << " " << position); - + if(cameraDictionary.hasKey("Focus") && cameraDictionary.getValue("Focus", focus)) { auto focusIterator = _allNodes.find(focus); + if (focusIterator != _allNodes.end()) { + _focus = focus; + LDEBUG("Setting camera focus to '"<< _focus << "'"); + } + } + if(cameraDictionary.hasKey("Position") && cameraDictionary.getValue("Position", position)) { auto positionIterator = _allNodes.find(position); - - if(focusIterator != _allNodes.end() && positionIterator != _allNodes.end()) { - LDEBUG("Setting position and focus from config"); - SceneGraphNode* focusNode = focusIterator->second; - SceneGraphNode* positionNode = positionIterator->second; - Camera* c = OsEng.interactionHandler().getCamera(); - - // TODO: Make distance depend on radius - // TODO: Set distance and camera direction in some more smart way - // TODO: Set scaling dependent on the position and distance - // set position for camera - psc cameraPosition = positionNode->getPosition(); - cameraPosition += psc(0.0,0.0,1.0,2.0); - c->setPosition(cameraPosition); - c->setCameraDirection(glm::vec3(0,0,-1)); - c->setScaling(glm::vec2(1.0,0.0)); - - // Set the focus node for the interactionhandler - OsEng.interactionHandler().setFocusNode(focusNode); + if (positionIterator != _allNodes.end()) { + _position = position; + LDEBUG("Setting camera position to '"<< _position << "'"); } } } // Close the Lua state lua_close(state); + + return true; } void SceneGraph::loadModulesFromModulePath(const std::string& modulePath) { @@ -208,9 +286,10 @@ void SceneGraph::loadModulesFromModulePath(const std::string& modulePath) { } // allocate SceneGraphNode and initialize with Dictionary - SceneGraphNode* node = new SceneGraphNode; singleModuleDictionary.setValue("Path", modulePath); - if(node->initializeWithDictionary(&singleModuleDictionary)) { + SceneGraphNode* node = nullptr; + node = new SceneGraphNode(singleModuleDictionary); + if(node != nullptr) { // add to internal data structures _allNodes.insert(std::make_pair(moduleName, node)); _nodes.push_back(node); @@ -218,9 +297,6 @@ void SceneGraph::loadModulesFromModulePath(const std::string& modulePath) { // set child and parent SceneGraphNode* parentNode = parentIterator->second; parentNode->addNode(node); - } else { - LFATAL("Unable to initialize module '"<< moduleName <<"' using dictionary."); - delete node; } } } @@ -228,6 +304,9 @@ void SceneGraph::loadModulesFromModulePath(const std::string& modulePath) { // Close the Lua state lua_close(state); + + // Print the tree + printTree(_root); } void SceneGraph::printChildren() const { diff --git a/src/scenegraph/scenegraphnode.cpp b/src/scenegraph/scenegraphnode.cpp index e8f4483ecd..8643854621 100644 --- a/src/scenegraph/scenegraphnode.cpp +++ b/src/scenegraph/scenegraphnode.cpp @@ -23,8 +23,8 @@ ****************************************************************************************/ // open space includes -#include "scenegraph/scenegraphnode.h" -#include "util/spice.h" +#include +#include // ghoul includes #include @@ -34,8 +34,8 @@ #include #include -#include -#include +#include +#include namespace { std::string _loggerCat = "SceneGraphNode"; @@ -43,100 +43,81 @@ namespace { namespace openspace { -SceneGraphNode::SceneGraphNode(): _parent(nullptr), _nodeName("Unnamed OpenSpace SceneGraphNode"), - _position(nullptr), _renderable(nullptr), - _renderableVisible(false), _boundingSphereVisible(false) {} - -SceneGraphNode::~SceneGraphNode() { - LDEBUG("Deallocating: " << _nodeName); - - // deallocate the renderable - if(_renderable != nullptr) - delete _renderable; - - // deallocate the child nodes and delete them, iterate c++11 style - for( auto child: _children) - delete child; -} - -bool SceneGraphNode::_initialize() { - using ghoul::opengl::ShaderObject; - using ghoul::opengl::ProgramObject; - using ghoul::opengl::ShaderManager; - ShaderObject* powerscale_vs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeVertex, - absPath("${SHADERS}/pscstandard_vs.glsl"), - "PS Vertex" - ); - ShaderObject* powerscale_fs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeFragment, - absPath("${SHADERS}/pscstandard_fs.glsl"), - "PS Fragment" - ); - - ProgramObject* po = new ProgramObject; - po->attachObject(powerscale_vs); - po->attachObject(powerscale_fs); - - if( ! po->compileShaderObjects()) - return false; - if( ! po->linkProgramObject()) - return false; - - OsEng.ref().configurationManager().setValue("pscShader", po); - - return true; - -} - -bool SceneGraphNode::initialize() { - - if( ! _initialize()) { - return false; - } - - _position = new ConstantPositionInformation; - _position->initializeWithDictionary(nullptr); - - return true; -} - -bool SceneGraphNode::initializeWithDictionary(ghoul::Dictionary* dictionary) { - - if( ! _initialize()) { - return false; - } +SceneGraphNode::SceneGraphNode(const ghoul::Dictionary& dictionary): + _parent(nullptr), _nodeName("Unnamed OpenSpace SceneGraphNode"), _position(nullptr), + _renderable(nullptr), _renderableVisible(false), _boundingSphereVisible(false) +{ + ghoul::Dictionary localDictionary = dictionary; // set the _nodeName if available - dictionary->getValue("Name", _nodeName); + localDictionary.getValue("Name", _nodeName); - std::string path; - dictionary->getValue("Path", path); + std::string path = ""; + localDictionary.getValue("Path", path); - if(dictionary->hasKey("Renderable")) { - if(safeInitializeWithDictionary(&_renderable, "Renderable", dictionary, path)) { - LDEBUG("Successful initialization of renderable!"); - if ( ! _renderable) { - LFATAL("But the renderable is not initialized for " << _nodeName); - } + if(localDictionary.hasKey("Renderable")) { + if(safeCreationWithDictionary(&_renderable, "Renderable", &localDictionary, path)) { + LDEBUG(_nodeName << ": Successful creation of renderable!"); } else { - LDEBUG("Failed to initialize renderable!"); + LDEBUG(_nodeName << ": Failed to create renderable!"); } } - if(dictionary->hasKey("Position")) { - if(safeInitializeWithDictionary(&_position, "Position", dictionary, path)) { - LDEBUG("Successful initialization of position!"); - if ( ! _position) { - LFATAL("But the position is not initialized for " << _nodeName); - } + if(localDictionary.hasKey("Position")) { + if(safeCreationWithDictionary(&_position, "Position", &localDictionary, path)) { + LDEBUG(_nodeName << ": Successful creation of position!"); } else { - LDEBUG("Failed to initialize position!"); + LDEBUG(_nodeName << ": Failed to create position!"); } } if (_position == nullptr) { - _position = new ConstantPositionInformation; - _position->initializeWithDictionary(nullptr); + _position = new ConstantPositionInformation(ghoul::Dictionary()); + _position->initialize(); } +} +SceneGraphNode::~SceneGraphNode() { + deinitialize(); +} + +bool SceneGraphNode::initialize() { + if(_renderable != nullptr) + _renderable->initialize(); + + // deallocate position + if(_position != nullptr) + _position->initialize(); + return true; +} + + +bool SceneGraphNode::deinitialize() { + LDEBUG("Deinitialize: " << _nodeName); + + // deallocate the renderable + if(_renderable != nullptr) + delete _renderable; + + // deallocate position + if(_position != nullptr) + delete _position; + + // deallocate the child nodes and delete them, iterate c++11 style + for( auto child: _children) + delete child; + + // empty the children vector + _children.erase(_children.begin(), _children.end()); + + // reset variables + _parent = nullptr; + _renderable = nullptr; + _position = nullptr; + _nodeName = "Unnamed OpenSpace SceneGraphNode"; + _renderableVisible = false; + _boundingSphereVisible = false; + _boundingSphere = pss(0.0,0.0); + return true; } @@ -193,6 +174,7 @@ void SceneGraphNode::render(const Camera *camera, const psc & parentPosition) { return; } if(_renderableVisible) { + //LDEBUG("Render"); _renderable->render(camera,thisPosition); } @@ -234,6 +216,18 @@ psc SceneGraphNode::getWorldPosition() const { } } + +std::string SceneGraphNode::nodeName() const { + return _nodeName; +} + +SceneGraphNode* SceneGraphNode::parent() const { + return _parent; +} +const std::vector& SceneGraphNode::children() const { + return _children; +} + // bounding sphere pss SceneGraphNode::calculateBoundingSphere() { @@ -304,5 +298,25 @@ bool SceneGraphNode::sphereInsideFrustum(const psc s_pos, const pss & s_rad, con } } + +SceneGraphNode* SceneGraphNode::get(const std::string& name) { + if (_nodeName == name) + return this; + else + for (auto it : _children) { + SceneGraphNode* tmp = it->get(name); + if (tmp != nullptr) { + return tmp; + } + } + return nullptr; +} + +void SceneGraphNode::print() const { + std::cout << _nodeName << std::endl; + for (auto it : _children) { + it->print(); + } +} } // namespace openspace \ No newline at end of file diff --git a/src/scenegraph/spicepositioninformation.cpp b/src/scenegraph/spicepositioninformation.cpp index f03644be29..bce3cea116 100644 --- a/src/scenegraph/spicepositioninformation.cpp +++ b/src/scenegraph/spicepositioninformation.cpp @@ -22,30 +22,37 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include "spicepositioninformation.h" +#include -#include +#include namespace openspace { -SpicePositionInformation::SpicePositionInformation(): _target(0), _origin(0), _position() {} +SpicePositionInformation::SpicePositionInformation(const ghoul::Dictionary& dictionary): _targetName(""), + _originName(""), + _target(0), + _origin(0), + _position() +{ + dictionary.getValue("Body", _targetName); + dictionary.getValue("Observer", _originName); +} SpicePositionInformation::~SpicePositionInformation() {} -bool SpicePositionInformation::initializeWithDictionary(ghoul::Dictionary* dictionary) { +bool SpicePositionInformation::initialize() { - std::string body, observer; - if (dictionary->getValue("Body", body) && dictionary->getValue("Observer", observer)) { + if (_targetName != "" && _originName != "") { int bsuccess = 0; int osuccess = 0; - Spice::ref().bod_NameToInt(body, &_target, &bsuccess); - Spice::ref().bod_NameToInt(observer, &_origin, &osuccess); + Spice::ref().bod_NameToInt(_targetName, &_target, &bsuccess); + Spice::ref().bod_NameToInt(_originName, &_origin, &osuccess); if (bsuccess && osuccess) { return true; } } - return true; + return false; } const psc& SpicePositionInformation::position() const { diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt new file mode 100644 index 0000000000..23d2ace4b7 --- /dev/null +++ b/src/tests/CMakeLists.txt @@ -0,0 +1,38 @@ +######################################################################################### +# # +# 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. # +######################################################################################### + +option(OPENSPACE_HAVE_TESTS "Activate the OpenSpace unit tests" ON) +if (OPENSPACE_HAVE_TESTS) + add_definitions(-DOPENSPACE_HAVE_TESTS) + + include_directories("${GHOUL_ROOT_DIR}/ext/gtest/include") + include_directories("${GHOUL_ROOT_DIR}/include") + file(GLOB_RECURSE OPENSPACE_TEST_FILES ${HEADER_ROOT_DIR}/openspace/tests/*.inl) + + source_group(OpenSpaceSource FILES ${OPENSPACE_SOURCE} ${OPENSPACE_HEADER}) + + add_executable(OpenSpaceTest ${SOURCE_ROOT_DIR}/tests/main.cpp ${OPENSPACE_TEST_FILES} ${OPENSPACE_HEADER} ${OPENSPACE_SOURCE}) + target_link_libraries(OpenSpaceTest gtest ${DEPENDENT_LIBS}) + +endif (OPENSPACE_HAVE_TESTS) diff --git a/src/tests/ScenegraphTest/common/common.mod b/src/tests/ScenegraphTest/common/common.mod new file mode 100644 index 0000000000..908bdaf746 --- /dev/null +++ b/src/tests/ScenegraphTest/common/common.mod @@ -0,0 +1,11 @@ +{ + -- Solar System module + { + Name = "SolarSystem", + Parent = "Root", + Position = { + Type = "static", + Position = { 0, 0, 0, 0} + } + }, +} \ No newline at end of file diff --git a/src/tests/ScenegraphTest/default.scene b/src/tests/ScenegraphTest/default.scene new file mode 100644 index 0000000000..0839eb3f6c --- /dev/null +++ b/src/tests/ScenegraphTest/default.scene @@ -0,0 +1,12 @@ + + +{ + Camera = { + Focus = "Earth", + Position = "Earth" + }, + Modules = { + "common", + "earth" + } +} \ No newline at end of file diff --git a/src/tests/ScenegraphTest/earth/earth.mod b/src/tests/ScenegraphTest/earth/earth.mod new file mode 100644 index 0000000000..0b7fccf822 --- /dev/null +++ b/src/tests/ScenegraphTest/earth/earth.mod @@ -0,0 +1,83 @@ +{ + -- Earth barycenter module + { + Name = "EarthBarycenter", + Parent = "SolarSystem", + Static = "true", + Position = { + Type = "Kepler", + Inclination = 0.00041, + AscendingNode = 349.2, + Perihelion = 102.8517, + SemiMajorAxis = 1.00002, + DailyMotion = 0.9855796, + Eccentricity = 0.0166967, + MeanLongitude = 328.40353 + } + }, + + -- dummy earth module + --[[ + { + Name = "DummyEarth", + Parent = "Root", + Renderable = { + Type = "RenderablePlanet", + Geometry = { + Type = "SimpleSphere", + --Radius = { 1.0, 1 } -- not sure if correct; supposed 6371km in meters in pss + Radius = { 1.0, 1} -- not sure if correct; supposed 6371km in meters in pss + }, + Textures = { + Type = "simple", + Color = "textures/earth_nasa_lowres.png", + Depth = "textures/earth_depth.png" + }, + }, + Position = { + Type = "Static", + Position = { 0, 0, -1, 1} + } + }, + ]]-- + + -- Earth module + { + Name = "Earth", + Parent = "EarthBarycenter", + Renderable = { + Type = "RenderablePlanet", + Geometry = { + Type = "SimpleSphere", + --Radius = { 6.371, 6 }, + Radius = { 1.0, 1}, + Segments = 10 + }, + Textures = { + Type = "simple", + Color = "textures/earth_nasa_lowres.png", + Depth = "textures/earth_depth.png" + }, + Atmosphere = { + Type = "Nishita", -- for example, values missing etc etc + MieFactor = 1.0, + MieColor = {1.0, 1.0, 1.0} + } + }, + Position = { + Type = "Spice", + Body = "EARTH", + Reference = "ECLIPJ2000", + Observer = "EARTH BARYCENTER", + Kernels = { + "kernels/earth.bsp" + } + }, + Rotation = { + Type = "Spice", + Frame = "IAU_EARTH", + Reference = "ECLIPJ2000" + }, + GuiName = "/Solar/Planets/Earth" + } +} \ No newline at end of file diff --git a/src/tests/ScenegraphTest/earth/textures/earth_nasa_lowres.jpg b/src/tests/ScenegraphTest/earth/textures/earth_nasa_lowres.jpg new file mode 100644 index 0000000000..f888c06156 Binary files /dev/null and b/src/tests/ScenegraphTest/earth/textures/earth_nasa_lowres.jpg differ diff --git a/src/tests/ScenegraphTest/earth/textures/earth_nasa_lowres.png b/src/tests/ScenegraphTest/earth/textures/earth_nasa_lowres.png new file mode 100644 index 0000000000..4ab4d3cd4a Binary files /dev/null and b/src/tests/ScenegraphTest/earth/textures/earth_nasa_lowres.png differ diff --git a/src/tests/main.cpp b/src/tests/main.cpp new file mode 100644 index 0000000000..146cddfe66 --- /dev/null +++ b/src/tests/main.cpp @@ -0,0 +1,68 @@ +/***************************************************************************************** + * * + * GHOUL * + * General Helpful Open Utility Library * + * * + * Copyright (c) 2012-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. * + ****************************************************************************************/ + +#include "gtest/gtest.h" + +#include +#include +#include + +#include +#include +#include + +#include +#include + +using namespace ghoul::cmdparser; +using namespace ghoul::filesystem; +using namespace ghoul::logging; + +int main(int argc, char** argv) { + LogManager::initialize(LogManager::LogLevel::None); + LogMgr.addLog(new ConsoleLog); + + FileSystem::initialize(); + + const bool extDir = FileSys.directoryExists("../../../ext/ghoul/tests"); + if (extDir) { + FileSys.registerPathToken("${SCRIPTS_DIR}", "../../../ext/ghoul/scripts"); + FileSys.registerPathToken("${TEST_DIR}", "../../../ext/ghoul/tests"); + } + else { + LFATALC("main", "Fix me"); + } + + openspace::OpenSpaceEngine::registerFilePaths(); + FileSys.registerPathToken("${TESTDIR}", "${BASE_PATH}/src/tests"); + + openspace::Time::init(); + openspace::Spice::init(); + openspace::Spice::ref().loadDefaultKernels(); + openspace::FactoryManager::initialize(); + + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/src/util/camera.cpp b/src/util/camera.cpp index 217eae4f32..8fa0a2976b 100644 --- a/src/util/camera.cpp +++ b/src/util/camera.cpp @@ -1,6 +1,6 @@ // open space includes -#include "camera.h" +#include // sgct includes #include "sgct.h" diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index f286dcfb6b..bd708d7568 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -22,13 +22,13 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include "factorymanager.h" +#include #include -#include "rendering/renderableplanet.h" -#include "scenegraph/constantpositioninformation.h" -#include "scenegraph/spicepositioninformation.h" +#include +#include +#include namespace openspace { @@ -59,6 +59,7 @@ void FactoryManager::initialize() { registerClass("Static"); _manager->factoryByType()-> registerClass("Spice"); + } void FactoryManager::deinitialize() { diff --git a/src/util/geometry.cpp b/src/util/geometry.cpp index e6abbd9970..a4f3b8c5b5 100644 --- a/src/util/geometry.cpp +++ b/src/util/geometry.cpp @@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ // open space includes -#include "util/geometry.h" +#include gl4::Geometry::Geometry() { diff --git a/src/util/planet.cpp b/src/util/planet.cpp index 328faae25e..725605091b 100644 --- a/src/util/planet.cpp +++ b/src/util/planet.cpp @@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ // open space includes -#include "util/planet.h" +#include // sgct includes #include "sgct.h" diff --git a/src/util/powerscaledsphere.cpp b/src/util/powerscaledsphere.cpp index f92681e696..00558a8a57 100644 --- a/src/util/powerscaledsphere.cpp +++ b/src/util/powerscaledsphere.cpp @@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ // open space includes -#include +#include #include @@ -108,8 +108,32 @@ PowerScaledSphere::PowerScaledSphere(const pss radius, int segments) } } + +} + +PowerScaledSphere::~PowerScaledSphere() { + if(_varray) + delete[] _varray; + + if(_iarray) + delete[] _iarray; + + if(_vBufferID != 0) + glDeleteBuffers(1, &_vBufferID); + + if(_iBufferID != 0) + glDeleteBuffers(1, &_iBufferID); + + if(_vaoID != 0) + glDeleteVertexArrays(1, &_vaoID); +} + +bool PowerScaledSphere::initialize() { + + bool completeSuccess = true; + // Initialize and upload to graphics card - GLuint errorID = glGetError(); + GLuint errorID; glGenVertexArrays(1, &_vaoID); // First VAO setup @@ -134,10 +158,12 @@ PowerScaledSphere::PowerScaledSphere(const pss radius, int segments) if(_vBufferID == 0) { LERROR("Vertex buffer not initialized"); + completeSuccess = false; } if(_iBufferID == 0) { LERROR("Index buffer not initialized"); + completeSuccess = false; } glBindVertexArray(0); @@ -147,21 +173,12 @@ PowerScaledSphere::PowerScaledSphere(const pss radius, int segments) { LERROR("OpenGL error: " << glewGetErrorString(errorID)); LERROR("Attempting to proceed anyway. Expect rendering errors or a crash."); + completeSuccess = false; } -} - -PowerScaledSphere::~PowerScaledSphere() { - if(_varray) - delete[] _varray; - - if(_iarray) - delete[] _iarray; + return completeSuccess; } void PowerScaledSphere::render() { - - - //LDEBUGC("gogo","power renders"); glBindVertexArray(_vaoID); // select first VAO glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID); glDrawElements(_mode, _isize, GL_UNSIGNED_INT, BUFFER_OFFSET(0)); diff --git a/src/util/psc.cpp b/src/util/psc.cpp index 57b95cd903..9c6e95ffdb 100644 --- a/src/util/psc.cpp +++ b/src/util/psc.cpp @@ -1,7 +1,7 @@ // open space includes -#include "util/psc.h" -#include "util/pss.h" +#include +#include // std includes #include @@ -240,6 +240,10 @@ const double psc::angle(const psc &rhs) const { bool psc::operator==(const psc &other) const { return vec_ == other.vec_; } + +bool psc::operator!=(const psc &other) const { + return vec_ != other.vec_; +} bool psc::operator<(const psc &other) const { double ds = this->vec_[3] - other.vec_[3]; @@ -279,5 +283,11 @@ bool psc::operator>=(const psc &other) const { return *this > other || *this == other; } + +std::ostream& operator<<(::std::ostream& os, const psc& rhs) { + os << "(" << rhs[0] << ", " << rhs[1] << ", " << rhs[2] << ", " << rhs[3] << ")"; + return os; +} + } // namespace openspace diff --git a/src/util/pss.cpp b/src/util/pss.cpp index c64018ca21..e5ccd58f4e 100644 --- a/src/util/pss.cpp +++ b/src/util/pss.cpp @@ -1,6 +1,6 @@ // open space includes -#include "util/pss.h" +#include // std includes #include @@ -204,7 +204,12 @@ bool pss::operator<(const pss &other) const { double ds = this->vec_[1] - other.vec_[1]; if(ds >= 0) { double upscaled = other.vec_[0]*pow(k,-ds); - return vec_[0] < upscaled; + return vec_[0] < upscaled; + /* + bool retur =(vec_[0] < upscaled); + std::printf("this: %f, upscaled: %f, this upscaled; @@ -271,5 +276,9 @@ bool pss::operator>=(const double &other) const { return *this > other || *this == other; } +std::ostream& operator<<(::std::ostream& os, const pss& rhs) { + os << "(" << rhs[0] << ", " << rhs[1] << ")"; + return os; +} } // namespace openspace diff --git a/src/util/sphere.cpp b/src/util/sphere.cpp index 9d7da8857c..940fc2044e 100644 --- a/src/util/sphere.cpp +++ b/src/util/sphere.cpp @@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ // open space includes -#include "util/sphere.h" +#include gl4::Sphere::Sphere(float radius, int segments, bool tessellation) { diff --git a/src/util/spice.cpp b/src/util/spice.cpp index edffb5918d..fab456bd0d 100644 --- a/src/util/spice.cpp +++ b/src/util/spice.cpp @@ -1,9 +1,9 @@ // openspace stuff -#include "util/spice.h" -#include "util/time.h" -#include "util/psc.h" -#include "interaction/interactionhandler.h" +#include +#include +#include +#include // spice #include "SpiceUsr.h" diff --git a/src/util/time.cpp b/src/util/time.cpp index 15dac045e4..60fc173306 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -1,7 +1,7 @@ // open space includes -#include "util/time.h" -#include "interaction/interactionhandler.h" +#include +#include // std includes #include @@ -29,7 +29,7 @@ Time::~Time() { } void Time::init() { - assert( ! this_); + assert( this_ == nullptr); this_ = new Time(); } diff --git a/src/util/vbo.cpp b/src/util/vbo.cpp index 1f7051902f..604978dc1d 100644 --- a/src/util/vbo.cpp +++ b/src/util/vbo.cpp @@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ // open space includes -#include "util/vbo.h" +#include // ghoul includes #include "ghoul/logging/logmanager.h" @@ -122,7 +122,7 @@ void gl4::VBO::init() } - GLuint errorID = glGetError(); + GLuint errorID; glGenVertexArrays(1, &_vaoID); // First VAO setup