diff --git a/CMakeLists.txt b/CMakeLists.txt index 9066fd76bc..16f5700ee0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,7 +145,7 @@ endif () ######################################################################################### add_subdirectory(src) - +#add_subdirectory(tests) #add_subdirectory(gui) ######################################################################################### diff --git a/ext/ghoul b/ext/ghoul index a41ea37b6b..3c444b9a99 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit a41ea37b6bdeda6775e8f95b49134bf8a309569f +Subproject commit 3c444b9a993846cd1eaac1b8f3c33f3f294eecfb diff --git a/include/openspace/interaction/controller.h b/include/openspace/interaction/controller.h index d7578f4d22..0ddd97c67a 100644 --- a/include/openspace/interaction/controller.h +++ b/include/openspace/interaction/controller.h @@ -25,7 +25,7 @@ #ifndef __CONTROLLER_H__ #define __CONTROLLER_H__ -#include +#include #include #include diff --git a/include/openspace/query/query.h b/include/openspace/query/query.h index 49e0b34643..8e8096e34b 100644 --- a/include/openspace/query/query.h +++ b/include/openspace/query/query.h @@ -33,10 +33,10 @@ namespace properties { class Property; } class Renderable; -class SceneGraph; +class Scene; class SceneGraphNode; -SceneGraph* sceneGraph(); +Scene* sceneGraph(); SceneGraphNode* sceneGraphNode(const std::string& name); Renderable* renderable(const std::string& name); properties::Property* property(const std::string& uri); diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index b5db036f27..99ff18684a 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -39,7 +39,7 @@ namespace openspace { // Forward declare to minimize dependencies class Camera; class SyncBuffer; -class SceneGraph; +class Scene; class ABuffer; class ABufferVisualizer; class ScreenLog; @@ -53,8 +53,8 @@ public: bool initialize(); - void setSceneGraph(SceneGraph* sceneGraph); - SceneGraph* sceneGraph(); + void setSceneGraph(Scene* sceneGraph); + Scene* scene(); Camera* camera() const; ABuffer* abuffer() const; @@ -111,7 +111,7 @@ private: void storePerformanceMeasurements(); Camera* _mainCamera; - SceneGraph* _sceneGraph; + Scene* _sceneGraph; ABuffer* _abuffer; ScreenLog* _log; diff --git a/include/openspace/scenegraph/dynamicephemeris.h b/include/openspace/scene/dynamicephemeris.h similarity index 100% rename from include/openspace/scenegraph/dynamicephemeris.h rename to include/openspace/scene/dynamicephemeris.h diff --git a/include/openspace/scenegraph/ephemeris.h b/include/openspace/scene/ephemeris.h similarity index 100% rename from include/openspace/scenegraph/ephemeris.h rename to include/openspace/scene/ephemeris.h diff --git a/include/openspace/scenegraph/scenegraph.h b/include/openspace/scene/scene.h similarity index 93% rename from include/openspace/scenegraph/scenegraph.h rename to include/openspace/scene/scene.h index 1e09b38f65..8c1fa224d0 100644 --- a/include/openspace/scenegraph/scenegraph.h +++ b/include/openspace/scene/scene.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __SCENEGRAPH_H__ -#define __SCENEGRAPH_H__ +#ifndef __SCENE_H__ +#define __SCENE_H__ // std includes #include @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -45,11 +46,11 @@ class SceneGraphNode; // Notifications: // SceneGraphFinishedLoading -class SceneGraph { +class Scene { public: // constructors & destructor - SceneGraph(); - ~SceneGraph(); + Scene(); + ~Scene(); /** * Initalizes the SceneGraph by loading modules from the ${SCENEPATH} directory @@ -95,7 +96,7 @@ public: */ SceneGraphNode* sceneGraphNode(const std::string& name) const; - std::vector allSceneGraphNodes() const; + std::vector allSceneGraphNodes(); /** * Returns the Lua library that contains all Lua functions available to change the @@ -115,9 +116,10 @@ private: std::string _focus; // actual scenegraph - SceneGraphNode* _root; - std::vector _nodes; - std::map _allNodes; + SceneGraph _graph; + //SceneGraphNode* _root; + //std::vector _nodes; + //std::map _allNodes; std::string _sceneGraphToLoad; @@ -143,4 +145,4 @@ private: } // namespace openspace -#endif // __SCENEGRAPH_H__ +#endif // __SCENE_H__ diff --git a/include/openspace/scene/scenegraph.h b/include/openspace/scene/scenegraph.h new file mode 100644 index 0000000000..d8a49cf15d --- /dev/null +++ b/include/openspace/scene/scenegraph.h @@ -0,0 +1,74 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __SCENEGRAPH_H__ +#define __SCENEGRAPH_H__ + +#include + +#include +#include + +namespace openspace { + +class SceneGraphNode; + +class SceneGraph { +public: + SceneGraph(); + + void clear(); + bool loadFromFile(const std::string& sceneDescription); + + // Returns if addition was successful + bool addSceneGraphNode(SceneGraphNode* node); + bool removeSceneGraphNode(SceneGraphNode* node); + + const std::vector& nodes(); + + SceneGraphNode* rootNode() const; + SceneGraphNode* sceneGraphNode(const std::string& name) const; + +private: + struct SceneGraphNodeInternal { + SceneGraphNode* node; + // From nodes that are dependent on this one + std::vector incomingEdges; + // To nodes that this node depends on + std::vector outgoingEdges; + }; + + bool nodeIsDependentOnRoot(SceneGraphNodeInternal* node); + bool sortTopologially(); + + SceneGraphNodeInternal* nodeByName(const std::string& name); + + SceneGraphNode* _rootNode; + std::vector _nodes; + std::vector _topologicalSortedNodes; +}; + +} // namespace openspace + +#endif // __SCENEGRAPH_H__ diff --git a/include/openspace/scenegraph/scenegraphnode.h b/include/openspace/scene/scenegraphnode.h similarity index 98% rename from include/openspace/scenegraph/scenegraphnode.h rename to include/openspace/scene/scenegraphnode.h index c1443a94ee..c06b4b0c3c 100644 --- a/include/openspace/scenegraph/scenegraphnode.h +++ b/include/openspace/scene/scenegraphnode.h @@ -27,10 +27,10 @@ // open space includes #include -#include +#include #include -#include +#include #include #include diff --git a/include/openspace/scenegraph/spiceephemeris.h b/include/openspace/scene/spiceephemeris.h similarity index 98% rename from include/openspace/scenegraph/spiceephemeris.h rename to include/openspace/scene/spiceephemeris.h index 0db7eaba84..c01ea527f7 100644 --- a/include/openspace/scenegraph/spiceephemeris.h +++ b/include/openspace/scene/spiceephemeris.h @@ -25,7 +25,7 @@ #ifndef __SPICEEPHEMERIS_H__ #define __SPICEEPHEMERIS_H__ -#include +#include #include diff --git a/include/openspace/scenegraph/staticephemeris.h b/include/openspace/scene/staticephemeris.h similarity index 100% rename from include/openspace/scenegraph/staticephemeris.h rename to include/openspace/scene/staticephemeris.h diff --git a/include/openspace/tests/test_scenegraph.inl b/include/openspace/tests/test_scenegraph.inl deleted file mode 100644 index 9165fa8cc5..0000000000 --- a/include/openspace/tests/test_scenegraph.inl +++ /dev/null @@ -1,122 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2015 * - * * - * 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 = - openspace::SceneGraphNode::createFromDictionary(ghoul::Dictionary()); - - // Should not have a renderable and position should be 0,0,0,0 (undefined). - EXPECT_EQ(nullptr, node->renderable()); - EXPECT_EQ(openspace::psc(), node->position()); - - delete node; - ghoul::Dictionary nodeDictionary; - - ghoul::Dictionary positionDictionary; - ghoul::Dictionary positionPositionArrayDictionary; - - ghoul::Dictionary renderableDictionary; - - renderableDictionary.setValue("Type", std::string("RenderablePlanet")); - - positionPositionArrayDictionary.setValue("1", 1.0); - positionPositionArrayDictionary.setValue("2", 1.0); - positionPositionArrayDictionary.setValue("3", 1.0); - positionPositionArrayDictionary.setValue("4", 1.0); - - positionDictionary.setValue("Type", std::string("Static")); - positionDictionary.setValue("Position", positionPositionArrayDictionary); - - nodeDictionary.setValue("Position", positionDictionary); - nodeDictionary.setValue("Renderable", renderableDictionary); - - node = - openspace::SceneGraphNode::createFromDictionary(nodeDictionary); - - // This node should have a renderable (probably no good values but an existing one) - EXPECT_TRUE(node->renderable()); - - // position should be initialized - EXPECT_EQ(openspace::psc(1.0,1.0,1.0,1.0), node->position()); - - delete node; -} - -TEST_F(SceneGraphTest, Loading) { - - - // Should not successfully load a non existing scenegraph - EXPECT_FALSE(_scenegraph->loadScene(absPath("${TESTDIR}/ScenegraphTestNonExisting"), absPath("${TESTDIR}"))); - - // Existing scenegraph should load - EXPECT_TRUE(_scenegraph->loadScene(absPath("${TESTDIR}/ScenegraphTest"), absPath("${TESTDIR}"))); - // TODO need to check for correctness - - // This loading should fail regardless of existing or not since the - // scenegraph is already loaded - EXPECT_FALSE(_scenegraph->loadScene(absPath("${TESTDIR}/ScenegraphTest"), absPath("${TESTDIR}"))); -} - -TEST_F(SceneGraphTest, Reinitializing) { - - // Existing scenegraph should load - EXPECT_TRUE(_scenegraph->loadScene(absPath("${TESTDIR}/ScenegraphTest"), absPath("${TESTDIR}"))); - - _scenegraph->deinitialize(); - - // Existing scenegraph should load - EXPECT_TRUE(_scenegraph->loadScene(absPath("${TESTDIR}/ScenegraphTest"), absPath("${TESTDIR}"))); - // TODO need to check for correctness -} - - - - diff --git a/include/openspace/util/constants.h b/include/openspace/util/constants.h index b779716d4e..1ed613a4af 100644 --- a/include/openspace/util/constants.h +++ b/include/openspace/util/constants.h @@ -72,6 +72,7 @@ namespace scenegraph { namespace scenegraphnode { const std::string keyName = "Name"; const std::string keyParentName = "Parent"; + const std::string keyDependencies = "Dependencies"; const std::string keyRenderable = "Renderable"; const std::string keyEphemeris = "Ephemeris"; } // namespace scenegraphnode diff --git a/openspace.cfg b/openspace.cfg index f00d192734..343d031e85 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -5,7 +5,7 @@ return { SHADERS = "${BASE_PATH}/shaders", SHADERS_GENERATED = "${SHADERS}/generated", OPENSPACE_DATA = "${BASE_PATH}/openspace-data", - TESTDIR = "${BASE_PATH}/src/tests", + TESTDIR = "${BASE_PATH}/tests", CONFIG = "${BASE_PATH}/config", CACHE = "${BASE_PATH}/cache", FONTS = "${OPENSPACE_DATA}/fonts", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6976e276c2..774c40dc8d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -104,11 +104,11 @@ file(GLOB RENDERING_MODEL_HEADER ${HEADER_ROOT_DIR}/openspace/rendering/model/*. set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${RENDERING_MODEL_HEADER}) source_group(Rendering\\Model FILES ${RENDERING_MODEL_SOURCE} ${RENDERING_MODEL_HEADER}) -file(GLOB SCENEGRAPH_SOURCE ${SOURCE_ROOT_DIR}/scenegraph/*.cpp) -set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${SCENEGRAPH_SOURCE}) -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 SCENE_SOURCE ${SOURCE_ROOT_DIR}/scene/*.cpp) +set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${SCENE_SOURCE}) +file(GLOB SCENE_HEADER ${HEADER_ROOT_DIR}/openspace/scene/*.h ${HEADER_ROOT_DIR}/openspace/scene/*.inl) +set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${SCENE_HEADER}) +source_group(Scene FILES ${SCENE_SOURCE} ${SCENE_HEADER}) file(GLOB SCRIPTING_SOURCE ${SOURCE_ROOT_DIR}/scripting/*.cpp) set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${SCRIPTING_SOURCE}) @@ -150,10 +150,25 @@ include_directories("${HEADER_ROOT_DIR}") add_executable(OpenSpace ${SOURCE_ROOT_DIR}/main.cpp ${OPENSPACE_HEADER} ${OPENSPACE_SOURCE}) target_link_libraries(OpenSpace ${DEPENDENT_LIBS}) +option(OPENSPACE_HAVE_TESTS "Activate the OpenSpace unit tests" ON) +if (OPENSPACE_HAVE_TESTS) + add_definitions(-DOPENSPACE_HAVE_TESTS) + + set(OPENSPACE_TEST_DIR ${OPENSPACE_BASE_DIR}/tests) + + include_directories("${GHOUL_ROOT_DIR}/ext/gtest/include") + include_directories("${GHOUL_ROOT_DIR}/include") + include_directories("${OPENSPACE_TEST_DIR}") + file(GLOB_RECURSE OPENSPACE_TEST_FILES ${OPENSPACE_BASE_DIR}/tests/*.inl) + + source_group(Tests FILES ${OPENSPACE_TEST_FILES}) + + add_executable(OpenSpaceTest ${OPENSPACE_BASE_DIR}/tests/main.cpp ${OPENSPACE_TEST_FILES} ${OPENSPACE_HEADER} ${OPENSPACE_SOURCE}) + target_link_libraries(OpenSpaceTest gtest ${DEPENDENT_LIBS}) + +endif (OPENSPACE_HAVE_TESTS) + #if (NOT UNIX) #cotire(OpenSpace) #endif () GhoulCopySharedLibraries(OpenSpace) - -add_subdirectory(tests) - diff --git a/src/abuffer/abuffer.cpp b/src/abuffer/abuffer.cpp index 655830b789..52ced2a1ce 100644 --- a/src/abuffer/abuffer.cpp +++ b/src/abuffer/abuffer.cpp @@ -147,12 +147,12 @@ void ABuffer::resolve() { // Decrease stepsize in volumes if right click is pressed // TODO: Let the interactionhandler handle this - int val = sgct::Engine::getMouseButton(0, SGCT_MOUSE_BUTTON_RIGHT); - float volumeStepFactor = (val) ? 0.2f: 1.0f; - if(volumeStepFactor != _volumeStepFactor) { - _volumeStepFactor = volumeStepFactor; + //int val = sgct::Engine::getMouseButton(0, SGCT_MOUSE_BUTTON_RIGHT); + //float volumeStepFactor = (val) ? 0.2f: 1.0f; + //if(volumeStepFactor != _volumeStepFactor) { + // _volumeStepFactor = volumeStepFactor; // _resolveShader->setUniform("volumeStepFactor", _volumeStepFactor); - } + //} glBindVertexArray(_screenQuad); glDrawArrays(GL_TRIANGLES, 0, 6); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index d0943d82bc..3be2c8c61a 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include #include @@ -121,7 +121,7 @@ OpenSpaceEngine::~OpenSpaceEngine() { } OpenSpaceEngine& OpenSpaceEngine::ref() { - assert(_engine); + ghoul_assert(_engine, "OpenSpaceEngine not created"); return *_engine; } @@ -130,7 +130,7 @@ bool OpenSpaceEngine::create( std::vector& sgctArguments, std::string& openGlVersion) { - assert(_engine == nullptr); + ghoul_assert(!_engine, "OpenSpaceEngine was already created"); // Initialize the LogManager and add the console log as this will be used every time // and we need a fall back if something goes wrong between here and when we add the @@ -272,7 +272,7 @@ bool OpenSpaceEngine::initialize() { // Register Lua script functions LDEBUG("Registering Lua libraries"); _scriptEngine->addLibrary(RenderEngine::luaLibrary()); - _scriptEngine->addLibrary(SceneGraph::luaLibrary()); + _scriptEngine->addLibrary(Scene::luaLibrary()); _scriptEngine->addLibrary(Time::luaLibrary()); _scriptEngine->addLibrary(interaction::InteractionHandler::luaLibrary()); _scriptEngine->addLibrary(LuaConsole::luaLibrary()); @@ -303,7 +303,7 @@ bool OpenSpaceEngine::initialize() { // Load scenegraph - SceneGraph* sceneGraph = new SceneGraph; + Scene* sceneGraph = new Scene; _renderEngine->setSceneGraph(sceneGraph); // initialize the RenderEngine diff --git a/src/gui/guiorigincomponent.cpp b/src/gui/guiorigincomponent.cpp index 5c3225154c..7925161d8f 100644 --- a/src/gui/guiorigincomponent.cpp +++ b/src/gui/guiorigincomponent.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include "imgui.h" @@ -41,7 +41,7 @@ namespace gui { void GuiOriginComponent::render() { const SceneGraphNode* currentFocus = OsEng.interactionHandler()->focusNode(); - std::vector nodes = OsEng.renderEngine()->sceneGraph()->allSceneGraphNodes(); + std::vector nodes = OsEng.renderEngine()->scene()->allSceneGraphNodes(); std::sort(nodes.begin(), nodes.end(), [](SceneGraphNode* lhs, SceneGraphNode* rhs) { return lhs->name() < rhs->name(); }); auto it = std::find(nodes.begin(), nodes.end(), currentFocus); ghoul_assert(it != nodes.end(), "Focus node not found"); diff --git a/src/query/query.cpp b/src/query/query.cpp index 6d5fcf0d33..4aa8003eb4 100644 --- a/src/query/query.cpp +++ b/src/query/query.cpp @@ -27,8 +27,8 @@ #include #include #include -#include -#include +#include +#include namespace openspace { @@ -36,14 +36,14 @@ namespace { const std::string _loggerCat = "Query"; } -SceneGraph* sceneGraph() +Scene* sceneGraph() { - return OsEng.renderEngine()->sceneGraph(); + return OsEng.renderEngine()->scene(); } SceneGraphNode* sceneGraphNode(const std::string& name) { - const SceneGraph* graph = sceneGraph(); + const Scene* graph = sceneGraph(); return graph->sceneGraphNode(name); } diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index bc7ce663fb..0c7a5e5e8b 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include #include @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -58,8 +58,8 @@ #include // These are temporary ---abock -#include -#include +#include +#include // ABuffer defines #define ABUFFER_FRAMEBUFFER 0 @@ -726,14 +726,14 @@ namespace openspace { _showInfo = b; } - SceneGraph* RenderEngine::sceneGraph() + Scene* RenderEngine::scene() { // TODO custom assert (ticket #5) assert(_sceneGraph); return _sceneGraph; } - void RenderEngine::setSceneGraph(SceneGraph* sceneGraph) + void RenderEngine::setSceneGraph(Scene* sceneGraph) { _sceneGraph = sceneGraph; } @@ -910,7 +910,7 @@ namespace openspace { PerformanceLayoutEntry entries[maxValues]; }; - const int nNodes = static_cast(sceneGraph()->allSceneGraphNodes().size()); + const int nNodes = static_cast(scene()->allSceneGraphNodes().size()); if (!_performanceMemory) { // Compute the total size @@ -931,7 +931,7 @@ namespace openspace { memset(layout->entries, 0, maxValues * sizeof(PerformanceLayout::PerformanceLayoutEntry)); for (int i = 0; i < nNodes; ++i) { - SceneGraphNode* node = sceneGraph()->allSceneGraphNodes()[i]; + SceneGraphNode* node = scene()->allSceneGraphNodes()[i]; memset(layout->entries[i].name, 0, lengthName); strcpy(layout->entries[i].name, node->name().c_str()); @@ -945,7 +945,7 @@ namespace openspace { PerformanceLayout* layout = reinterpret_cast(_performanceMemory->pointer()); _performanceMemory->acquireLock(); for (int i = 0; i < nNodes; ++i) { - SceneGraphNode* node = sceneGraph()->allSceneGraphNodes()[i]; + SceneGraphNode* node = scene()->allSceneGraphNodes()[i]; SceneGraphNode::PerformanceRecord r = node->performanceRecord(); PerformanceLayout::PerformanceLayoutEntry& entry = layout->entries[i]; @@ -962,12 +962,12 @@ namespace openspace { // This method is temporary and will be removed once the scalegraph is in effect ---abock void RenderEngine::changeViewPoint(std::string origin) { - SceneGraphNode* solarSystemBarycenterNode = sceneGraph()->sceneGraphNode("SolarSystemBarycenter"); - SceneGraphNode* plutoBarycenterNode = sceneGraph()->sceneGraphNode("PlutoBarycenter"); - SceneGraphNode* newHorizonsNode = sceneGraph()->sceneGraphNode("NewHorizons"); - SceneGraphNode* jupiterBarycenterNode = sceneGraph()->sceneGraphNode("JupiterBarycenter"); - //SceneGraphNode* dawnNode = sceneGraph()->sceneGraphNode("Dawn"); - //SceneGraphNode* vestaNode = sceneGraph()->sceneGraphNode("Vesta"); + SceneGraphNode* solarSystemBarycenterNode = scene()->sceneGraphNode("SolarSystemBarycenter"); + SceneGraphNode* plutoBarycenterNode = scene()->sceneGraphNode("PlutoBarycenter"); + SceneGraphNode* newHorizonsNode = scene()->sceneGraphNode("NewHorizons"); + SceneGraphNode* jupiterBarycenterNode = scene()->sceneGraphNode("JupiterBarycenter"); + //SceneGraphNode* dawnNode = scene()->sceneGraphNode("Dawn"); + //SceneGraphNode* vestaNode = scene()->sceneGraphNode("Vesta"); if (solarSystemBarycenterNode == nullptr || plutoBarycenterNode == nullptr || newHorizonsNode == nullptr || jupiterBarycenterNode == nullptr diff --git a/src/scenegraph/dynamicephemeris.cpp b/src/scene/dynamicephemeris.cpp similarity index 100% rename from src/scenegraph/dynamicephemeris.cpp rename to src/scene/dynamicephemeris.cpp diff --git a/src/scenegraph/ephemeris.cpp b/src/scene/ephemeris.cpp similarity index 98% rename from src/scenegraph/ephemeris.cpp rename to src/scene/ephemeris.cpp index 517c025821..ccb2acea24 100644 --- a/src/scenegraph/ephemeris.cpp +++ b/src/scene/ephemeris.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include #include diff --git a/src/scenegraph/scenegraph.cpp b/src/scene/scene.cpp similarity index 66% rename from src/scenegraph/scenegraph.cpp rename to src/scene/scene.cpp index e503064fe9..ef4c1c9913 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scene/scene.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include #include @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -140,24 +140,23 @@ int loadScene(lua_State* L) { std::string sceneFile = luaL_checkstring(L, -1); - OsEng.renderEngine()->sceneGraph()->scheduleLoadSceneFile(sceneFile); + OsEng.renderEngine()->scene()->scheduleLoadSceneFile(sceneFile); return 0; } } // namespace luascriptfunctions -SceneGraph::SceneGraph() +Scene::Scene() : _focus(SceneGraphNode::RootNodeName) - , _root(nullptr) { } -SceneGraph::~SceneGraph() { +Scene::~Scene() { deinitialize(); } -bool SceneGraph::initialize() { +bool Scene::initialize() { LDEBUG("Initializing SceneGraph"); using ghoul::opengl::ShaderObject; @@ -238,7 +237,7 @@ bool SceneGraph::initialize() { return true; } -bool SceneGraph::deinitialize() { +bool Scene::deinitialize() { clearSceneGraph(); // clean up all programs @@ -249,9 +248,9 @@ bool SceneGraph::deinitialize() { return true; } -void SceneGraph::update(const UpdateData& data) { +void Scene::update(const UpdateData& data) { if (!_sceneGraphToLoad.empty()) { - OsEng.renderEngine()->sceneGraph()->clearSceneGraph(); + OsEng.renderEngine()->scene()->clearSceneGraph(); bool success = loadSceneInternal(_sceneGraphToLoad); _sceneGraphToLoad = ""; if (!success) @@ -260,16 +259,17 @@ void SceneGraph::update(const UpdateData& data) { OsEng.renderEngine()->abuffer()->invalidateABuffer(); #endif } - for (SceneGraphNode* node : _nodes) + for (SceneGraphNode* node : _graph.nodes()) node->update(data); } -void SceneGraph::evaluate(Camera* camera) { - if (_root) - _root->evaluate(camera); +void Scene::evaluate(Camera* camera) { + for (SceneGraphNode* node : _graph.nodes()) + node->evaluate(camera); + //_root->evaluate(camera); } -void SceneGraph::render(const RenderData& data) { +void Scene::render(const RenderData& data) { bool emptyProgramsToUpdate = _programsToUpdate.empty(); _programUpdateLock.lock(); @@ -287,91 +287,106 @@ void SceneGraph::render(const RenderData& data) { program->setIgnoreSubroutineUniformLocationError(true); } - if (_root) - _root->render(data); + for (SceneGraphNode* node : _graph.nodes()) + node->render(data); + //if (_root) + // _root->render(data); } -void SceneGraph::scheduleLoadSceneFile(const std::string& sceneDescriptionFilePath) { +void Scene::scheduleLoadSceneFile(const std::string& sceneDescriptionFilePath) { _sceneGraphToLoad = sceneDescriptionFilePath; } -void SceneGraph::clearSceneGraph() { +void Scene::clearSceneGraph() { // deallocate the scene graph. Recursive deallocation will occur - if (_root) { - _root->deinitialize(); - delete _root; - _root = nullptr; - } + _graph.clear(); + //if (_root) { + // _root->deinitialize(); + // delete _root; + // _root = nullptr; + //} - _nodes.erase(_nodes.begin(), _nodes.end()); - _allNodes.erase(_allNodes.begin(), _allNodes.end()); + // _nodes.erase(_nodes.begin(), _nodes.end()); + // _allNodes.erase(_allNodes.begin(), _allNodes.end()); _focus.clear(); } -bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath) { - using ghoul::Dictionary; - using ghoul::lua::loadDictionaryFromFile; +bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) { + // using ghoul::Dictionary; + // using ghoul::lua::loadDictionaryFromFile; - if (!FileSys.fileExists(sceneDescriptionFilePath)) { - LFATAL("Scene description file '" << sceneDescriptionFilePath << "' not found"); - return false; - } + //if (!FileSys.fileExists(sceneDescriptionFilePath)) { + // LFATAL("Scene description file '" << sceneDescriptionFilePath << "' not found"); + // return false; + //} - LDEBUG("Loading scenegraph nodes"); - if (_root != nullptr) { - LFATAL("Scenegraph already loaded"); - return false; - } + // LDEBUG("Loading scenegraph nodes"); + // if (_root != nullptr) { + // LFATAL("Scenegraph already loaded"); + // return false; + // } - OsEng.disableBarrier(); + // OsEng.disableBarrier(); - // initialize the root node - _root = new SceneGraphNode(); - _root->setName(SceneGraphNode::RootNodeName); - _nodes.push_back(_root); - _allNodes.emplace(SceneGraphNode::RootNodeName, _root); - _focus = SceneGraphNode::RootNodeName; + // _root = new SceneGraphNode(); + // _root->setName(SceneGraphNode::RootNodeName); + // _nodes.push_back(_root); + // _allNodes.emplace(SceneGraphNode::RootNodeName, _root); + // _focus = SceneGraphNode::RootNodeName; - Dictionary dictionary; - //load default.scene - loadDictionaryFromFile(sceneDescriptionFilePath, dictionary); + // bool success = SceneGraphLoader::load(sceneDescriptionFilePath, _nodes); - std::string&& sceneDescriptionDirectory = - ghoul::filesystem::File(sceneDescriptionFilePath).directoryName(); - std::string moduleDirectory("."); - dictionary.getValue(constants::scenegraph::keyPathScene, moduleDirectory); - // The scene path could either be an absolute or relative path to the description - // paths directory - std::string&& relativeCandidate = sceneDescriptionDirectory + - ghoul::filesystem::FileSystem::PathSeparator + moduleDirectory; - std::string&& absoluteCandidate = absPath(moduleDirectory); + ghoul::Dictionary dictionary; + ////load default.scene + ghoul::lua::loadDictionaryFromFile(sceneDescriptionFilePath, dictionary); - if (FileSys.directoryExists(relativeCandidate)) - moduleDirectory = relativeCandidate; - else if (FileSys.directoryExists(absoluteCandidate)) - moduleDirectory = absoluteCandidate; - else { - LFATAL("The '" << constants::scenegraph::keyPathScene << "' pointed to a " - "path '" << moduleDirectory << "' that did not exist"); - OsEng.enableBarrier(); - return false; - } + //std::string&& sceneDescriptionDirectory = + // ghoul::filesystem::File(sceneDescriptionFilePath).directoryName(); + //std::string moduleDirectory("."); + //dictionary.getValue(constants::scenegraph::keyPathScene, moduleDirectory); - // Load the modules/scenegraph nodes - loadModules(moduleDirectory, dictionary); + //// The scene path could either be an absolute or relative path to the description + //// paths directory + //std::string&& relativeCandidate = sceneDescriptionDirectory + + // ghoul::filesystem::FileSystem::PathSeparator + moduleDirectory; + //std::string&& absoluteCandidate = absPath(moduleDirectory); + + //if (FileSys.directoryExists(relativeCandidate)) + // moduleDirectory = relativeCandidate; + //else if (FileSys.directoryExists(absoluteCandidate)) + // moduleDirectory = absoluteCandidate; + //else { + // LFATAL("The '" << constants::scenegraph::keyPathScene << "' pointed to a " + // "path '" << moduleDirectory << "' that did not exist"); + // OsEng.enableBarrier(); + // return false; + //} + + //// Load the modules/scenegraph nodes + //loadModules(moduleDirectory, dictionary); + + _graph.loadFromFile(sceneDescriptionFilePath); // TODO: Make it less hard-coded and more flexible when nodes are not found - Dictionary cameraDictionary; + ghoul::Dictionary cameraDictionary; if (dictionary.getValue(constants::scenegraph::keyCamera, cameraDictionary)) { LDEBUG("Camera dictionary found"); std::string focus; if (cameraDictionary.hasKey(constants::scenegraph::keyFocusObject) - && cameraDictionary.getValue(constants::scenegraph::keyFocusObject, focus)) { - auto focusIterator = _allNodes.find(focus); - if (focusIterator != _allNodes.end()) { + && cameraDictionary.getValue(constants::scenegraph::keyFocusObject, focus)) + { + auto focusIterator = std::find_if( + _graph.nodes().begin(), + _graph.nodes().end(), + [focus](SceneGraphNode* node) { + return node->name() == focus; + } + ); + + if (focusIterator != _graph.nodes().end()) { _focus = focus; LDEBUG("Setting camera focus to '" << _focus << "'"); } @@ -381,7 +396,7 @@ bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath) } // Initialize all nodes - for (SceneGraphNode* node : _nodes) { + for (SceneGraphNode* node : _graph.nodes()) { bool success = node->initialize(); if (success) LDEBUG(node->name() << " initialized successfully!"); @@ -391,23 +406,36 @@ bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath) // update the position of all nodes // TODO need to check this; unnecessary? (ab) - for (SceneGraphNode* node : _nodes) + for (SceneGraphNode* node : _graph.nodes()) { node->update({ Time::ref().currentTime() }); + } + + for (auto it = _graph.nodes().rbegin(); it != _graph.nodes().rend(); ++it) + (*it)->calculateBoundingSphere(); + // Calculate the bounding sphere for the scenegraph - _root->calculateBoundingSphere(); + //_root->calculateBoundingSphere(); // set the camera position Camera* c = OsEng.ref().renderEngine()->camera(); - auto focusIterator = _allNodes.find(_focus); + //auto focusIterator = _allNodes.find(_focus); + auto focusIterator = std::find_if( + _graph.nodes().begin(), + _graph.nodes().end(), + [&](SceneGraphNode* node) { + return node->name() == _focus; + } + ); glm::vec2 cameraScaling(1); psc cameraPosition(0,0,1,0); glm::vec3 cameraDirection = glm::vec3(0, 0, -1); - if (focusIterator != _allNodes.end()) { + //if (_focus->) + if (focusIterator != _graph.nodes().end()) { LDEBUG("Camera focus is '" << _focus << "'"); - SceneGraphNode* focusNode = focusIterator->second; + SceneGraphNode* focusNode = *focusIterator; //Camera* c = OsEng.interactionHandler().getCamera(); // TODO: Make distance depend on radius @@ -440,6 +468,8 @@ bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath) // Set the focus node for the interactionhandler OsEng.interactionHandler()->setFocusNode(focusNode); } + else + OsEng.interactionHandler()->setFocusNode(_graph.rootNode()); glm::vec4 position; if (cameraDictionary.hasKey(constants::scenegraph::keyPositionObject) @@ -474,7 +504,7 @@ bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath) } - for (SceneGraphNode* node : _nodes) { + for (SceneGraphNode* node : _graph.nodes()) { std::vector properties = node->propertiesRecursive(); for (properties::Property* p : properties) { OsEng.gui()->_property.registerProperty(p); @@ -504,111 +534,111 @@ bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath) return true; } -void SceneGraph::loadModules( - const std::string& directory, - const ghoul::Dictionary& dictionary) -{ - // Struct containing dependencies and nodes - LoadMaps m; +//void Scene::loadModules( +// const std::string& directory, +// const ghoul::Dictionary& dictionary) +//{ +// // Struct containing dependencies and nodes +// LoadMaps m; +// +// // Get the common directory +// std::string commonDirectory(_defaultCommonDirectory); +// dictionary.getValue(constants::scenegraph::keyCommonFolder, commonDirectory); +// FileSys.registerPathToken(_commonModuleToken, commonDirectory); +// +// lua_State* state = ghoul::lua::createNewLuaState(); +// OsEng.scriptEngine()->initializeLuaState(state); +// +// LDEBUG("Loading common module folder '" << commonDirectory << "'"); +// // Load common modules into LoadMaps struct +// loadModule(m, FileSys.pathByAppendingComponent(directory, commonDirectory), state); +// +// // Load the rest of the modules into LoadMaps struct +// ghoul::Dictionary moduleDictionary; +// if (dictionary.getValue(constants::scenegraph::keyModules, moduleDictionary)) { +// std::vector keys = moduleDictionary.keys(); +// std::sort(keys.begin(), keys.end()); +// for (const std::string& key : keys) { +// std::string moduleFolder; +// if (moduleDictionary.getValue(key, moduleFolder)) { +// loadModule(m, FileSys.pathByAppendingComponent(directory, moduleFolder), state); +// } +// } +// } +// +// // Load and construct scenegraphnodes from LoadMaps struct +// loadNodes(SceneGraphNode::RootNodeName, m); +// +// // Remove loaded nodes from dependency list +// for(const auto& name: m.loadedNodes) { +// m.dependencies.erase(name); +// } +// +// // Check to see what dependencies are not resolved. +// for(auto& node: m.dependencies) { +// LWARNING( +// "'" << node.second << "'' not loaded, parent '" +// << node.first << "' not defined!"); +// } +//} - // Get the common directory - std::string commonDirectory(_defaultCommonDirectory); - dictionary.getValue(constants::scenegraph::keyCommonFolder, commonDirectory); - FileSys.registerPathToken(_commonModuleToken, commonDirectory); +//void Scene::loadModule(LoadMaps& m,const std::string& modulePath, lua_State* state) { +// auto pos = modulePath.find_last_of(ghoul::filesystem::FileSystem::PathSeparator); +// if (pos == modulePath.npos) { +// LERROR("Bad format for module path: " << modulePath); +// return; +// } +// +// std::string fullModule = modulePath + modulePath.substr(pos) + _moduleExtension; +// LDEBUG("Loading nodes from: " << fullModule); +// +// ghoul::filesystem::Directory oldDirectory = FileSys.currentDirectory(); +// FileSys.setCurrentDirectory(modulePath); +// +// ghoul::Dictionary moduleDictionary; +// ghoul::lua::loadDictionaryFromFile(fullModule, moduleDictionary, state); +// std::vector keys = moduleDictionary.keys(); +// for (const std::string& key : keys) { +// if (!moduleDictionary.hasValue(key)) { +// LERROR("SceneGraphElement '" << key << "' is not a table in module '" +// << fullModule << "'"); +// continue; +// } +// +// ghoul::Dictionary element; +// std::string nodeName; +// std::string parentName; +// +// moduleDictionary.getValue(key, element); +// element.setValue(constants::scenegraph::keyPathModule, modulePath); +// +// element.getValue(constants::scenegraphnode::keyName, nodeName); +// element.getValue(constants::scenegraphnode::keyParentName, parentName); +// +// m.nodes[nodeName] = element; +// m.dependencies.emplace(parentName,nodeName); +// } +// +// FileSys.setCurrentDirectory(oldDirectory); +//} - lua_State* state = ghoul::lua::createNewLuaState(); - OsEng.scriptEngine()->initializeLuaState(state); - - LDEBUG("Loading common module folder '" << commonDirectory << "'"); - // Load common modules into LoadMaps struct - loadModule(m, FileSys.pathByAppendingComponent(directory, commonDirectory), state); - - // Load the rest of the modules into LoadMaps struct - ghoul::Dictionary moduleDictionary; - if (dictionary.getValue(constants::scenegraph::keyModules, moduleDictionary)) { - std::vector keys = moduleDictionary.keys(); - std::sort(keys.begin(), keys.end()); - for (const std::string& key : keys) { - std::string moduleFolder; - if (moduleDictionary.getValue(key, moduleFolder)) { - loadModule(m, FileSys.pathByAppendingComponent(directory, moduleFolder), state); - } - } - } - - // Load and construct scenegraphnodes from LoadMaps struct - loadNodes(SceneGraphNode::RootNodeName, m); - - // Remove loaded nodes from dependency list - for(const auto& name: m.loadedNodes) { - m.dependencies.erase(name); - } - - // Check to see what dependencies are not resolved. - for(auto& node: m.dependencies) { - LWARNING( - "'" << node.second << "'' not loaded, parent '" - << node.first << "' not defined!"); - } -} - -void SceneGraph::loadModule(LoadMaps& m,const std::string& modulePath, lua_State* state) { - auto pos = modulePath.find_last_of(ghoul::filesystem::FileSystem::PathSeparator); - if (pos == modulePath.npos) { - LERROR("Bad format for module path: " << modulePath); - return; - } - - std::string fullModule = modulePath + modulePath.substr(pos) + _moduleExtension; - LDEBUG("Loading nodes from: " << fullModule); - - ghoul::filesystem::Directory oldDirectory = FileSys.currentDirectory(); - FileSys.setCurrentDirectory(modulePath); - - ghoul::Dictionary moduleDictionary; - ghoul::lua::loadDictionaryFromFile(fullModule, moduleDictionary, state); - std::vector keys = moduleDictionary.keys(); - for (const std::string& key : keys) { - if (!moduleDictionary.hasValue(key)) { - LERROR("SceneGraphElement '" << key << "' is not a table in module '" - << fullModule << "'"); - continue; - } - - ghoul::Dictionary element; - std::string nodeName; - std::string parentName; - - moduleDictionary.getValue(key, element); - element.setValue(constants::scenegraph::keyPathModule, modulePath); - - element.getValue(constants::scenegraphnode::keyName, nodeName); - element.getValue(constants::scenegraphnode::keyParentName, parentName); - - m.nodes[nodeName] = element; - m.dependencies.emplace(parentName,nodeName); - } - - FileSys.setCurrentDirectory(oldDirectory); -} - -void SceneGraph::loadNodes(const std::string& parentName, LoadMaps& m) { - auto eqRange = m.dependencies.equal_range(parentName); - for (auto it = eqRange.first; it != eqRange.second; ++it) { - auto node = m.nodes.find((*it).second); - loadNode(node->second); - loadNodes((*it).second, m); - } - m.loadedNodes.emplace_back(parentName); -} - -void SceneGraph::loadNode(const ghoul::Dictionary& dictionary) { - SceneGraphNode* node = SceneGraphNode::createFromDictionary(dictionary); - if(node) { - _allNodes.emplace(node->name(), node); - _nodes.push_back(node); - } -} +//void Scene::loadNodes(const std::string& parentName, LoadMaps& m) { +// auto eqRange = m.dependencies.equal_range(parentName); +// for (auto it = eqRange.first; it != eqRange.second; ++it) { +// auto node = m.nodes.find((*it).second); +// loadNode(node->second); +// loadNodes((*it).second, m); +// } +// m.loadedNodes.emplace_back(parentName); +//} +// +//void Scene::loadNode(const ghoul::Dictionary& dictionary) { +// SceneGraphNode* node = SceneGraphNode::createFromDictionary(dictionary); +// if(node) { +// _allNodes.emplace(node->name(), node); +// _nodes.push_back(node); +// } +//} //void SceneGraph::loadModule(const std::string& modulePath) { // auto pos = modulePath.find_last_of(ghoul::filesystem::FileSystem::PathSeparator); @@ -651,23 +681,19 @@ void SceneGraph::loadNode(const ghoul::Dictionary& dictionary) { // //printTree(_root); //} -SceneGraphNode* SceneGraph::root() const { - return _root; +SceneGraphNode* Scene::root() const { + return _graph.rootNode(); } -SceneGraphNode* SceneGraph::sceneGraphNode(const std::string& name) const { - for (auto it : _allNodes){ - if (boost::iequals(name, it.first)) - return it.second; - } - return nullptr; +SceneGraphNode* Scene::sceneGraphNode(const std::string& name) const { + return _graph.sceneGraphNode(name); } -std::vector SceneGraph::allSceneGraphNodes() const { - return _nodes; +std::vector Scene::allSceneGraphNodes() { + return _graph.nodes(); } -void SceneGraph::writePropertyDocumentation(const std::string& filename, const std::string& type) { +void Scene::writePropertyDocumentation(const std::string& filename, const std::string& type) { if (type == "text") { LDEBUG("Writing documentation for properties"); std::ofstream file(filename); @@ -677,7 +703,7 @@ void SceneGraph::writePropertyDocumentation(const std::string& filename, const s } using properties::Property; - for (SceneGraphNode* node : _nodes) { + for (SceneGraphNode* node : _graph.nodes()) { std::vector properties = node->propertiesRecursive(); if (!properties.empty()) { file << node->name() << std::endl; @@ -694,7 +720,7 @@ void SceneGraph::writePropertyDocumentation(const std::string& filename, const s LERROR("Undefined type '" << type << "' for Property documentation"); } -scripting::ScriptEngine::LuaLibrary SceneGraph::luaLibrary() { +scripting::ScriptEngine::LuaLibrary Scene::luaLibrary() { return { "", { diff --git a/src/scene/scenegraph.cpp b/src/scene/scenegraph.cpp new file mode 100644 index 0000000000..fdc5819c97 --- /dev/null +++ b/src/scene/scenegraph.cpp @@ -0,0 +1,367 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * 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 + +#include +#include +#include + +#include +#include +#include + +#include + +namespace { + const std::string _loggerCat = "SceneGraph"; + const std::string _moduleExtension = ".mod"; + const std::string _defaultCommonDirectory = "common"; + const std::string _commonModuleToken = "${COMMON_MODULE}"; +} + +namespace openspace { + +SceneGraph::SceneGraph() { + + +} + +void SceneGraph::clear() { + // Untested ---abock + for (SceneGraphNodeInternal* n : _nodes) { + delete n->node; + delete n; + } + + _nodes.clear(); +} + +bool SceneGraph::loadFromFile(const std::string& sceneDescription) { + clear(); // Move this to a later stage to retain a proper scenegraph when the loading fails ---abock + + std::string absSceneFile = absPath(sceneDescription); + + // See if scene file exists + if (!FileSys.fileExists(absSceneFile, true)) { + LERROR("Could not load scene file '" << absSceneFile << "'. " << + "File not found"); + return false; + } + LINFO("Loading SceneGraph from file '" << absSceneFile << "'"); + + // Load dictionary + ghoul::Dictionary sceneDictionary; + bool success = ghoul::lua::loadDictionaryFromFile(absSceneFile, sceneDictionary); + if (!success) + return false; + + std::string sceneDescriptionDirectory = + ghoul::filesystem::File(absSceneFile, true).directoryName(); + std::string sceneDirectory("."); + sceneDictionary.getValue(constants::scenegraph::keyPathScene, sceneDirectory); + + // The scene path could either be an absolute or relative path to the description + // paths directory + std::string relativeCandidate = sceneDescriptionDirectory + + ghoul::filesystem::FileSystem::PathSeparator + sceneDirectory; + std::string absoluteCandidate = absPath(sceneDirectory); + + if (FileSys.directoryExists(relativeCandidate)) + sceneDirectory = relativeCandidate; + else if (FileSys.directoryExists(absoluteCandidate)) + sceneDirectory = absoluteCandidate; + else { + LERROR("The '" << constants::scenegraph::keyPathScene << "' pointed to a " + "path '" << sceneDirectory << "' that did not exist"); + return false; + } + + using constants::scenegraph::keyModules; + ghoul::Dictionary moduleDictionary; + success = sceneDictionary.getValue(keyModules, moduleDictionary); + if (!success) + // There are no modules that are loaded + return true; + + lua_State* state = ghoul::lua::createNewLuaState(); + OsEng.scriptEngine()->initializeLuaState(state); + + // Get the common directory + using constants::scenegraph::keyCommonFolder; + bool commonFolderSpecified = sceneDictionary.hasKey(keyCommonFolder); + bool commonFolderCorrectType = sceneDictionary.hasKeyAndValue(keyCommonFolder); + + if (commonFolderSpecified) { + if (commonFolderCorrectType) { + std::string commonFolder = sceneDictionary.value(keyCommonFolder); + std::string fullCommonFolder = FileSys.pathByAppendingComponent( + sceneDirectory, + commonFolder + ); + if (!FileSys.directoryExists(fullCommonFolder)) + LERROR("Specified common folder '" << fullCommonFolder << "' did not exist"); + else { + if (!commonFolder.empty()) { + FileSys.registerPathToken(_commonModuleToken, commonFolder); + size_t nKeys = moduleDictionary.size(); + moduleDictionary.setValue(std::to_string(nKeys + 1), commonFolder); + } + } + } + else + LERROR("Specification for 'common' folder has invalid type"); + } + + std::vector keys = moduleDictionary.keys(); + + std::map> dependencies; + std::map parents; + + _rootNode = new SceneGraphNode; + _rootNode->setName(SceneGraphNode::RootNodeName); + SceneGraphNodeInternal* internalRoot = new SceneGraphNodeInternal; + internalRoot->node = _rootNode; + _nodes.push_back(internalRoot); + + std::sort(keys.begin(), keys.end()); + ghoul::filesystem::Directory oldDirectory = FileSys.currentDirectory(); + for (const std::string& key : keys) { + std::string moduleName = moduleDictionary.value(key); + std::string modulePath = FileSys.pathByAppendingComponent(sceneDirectory, moduleName); + + if (!FileSys.directoryExists(modulePath)) { + LERROR("Could not load module '" << moduleName << "'. Directory did not exist"); + continue; + } + + std::string moduleFile = FileSys.pathByAppendingComponent( + modulePath, + moduleName + _moduleExtension + ); + + if (!FileSys.fileExists(moduleFile)) { + LERROR("Could not load module file '" << moduleFile << "'. File did not exist"); + continue; + } + + ghoul::Dictionary moduleDictionary; + bool s = ghoul::lua::loadDictionaryFromFile(moduleFile, moduleDictionary, state); + if (!s) + continue; + + std::vector keys = moduleDictionary.keys(); + for (const std::string& key : keys) { + if (!moduleDictionary.hasValue(key)) { + LERROR("SceneGraphNode '" << key << "' is not a table in module '" + << moduleFile << "'"); + continue; + } + + ghoul::Dictionary element; + std::string nodeName; + std::string parentName; + + moduleDictionary.getValue(key, element); + element.setValue(constants::scenegraph::keyPathModule, modulePath); + + element.getValue(constants::scenegraphnode::keyName, nodeName); + element.getValue(constants::scenegraphnode::keyParentName, parentName); + + FileSys.setCurrentDirectory(modulePath); + SceneGraphNode* node = SceneGraphNode::createFromDictionary(element); + if (node == nullptr) { + LERROR("Error loading SceneGraphNode '" << nodeName << "' in module '" << moduleName << "'"); + clear(); + return false; + } + + dependencies[nodeName].push_back(parentName); + parents[nodeName] = parentName; + // Also include loaded dependencies + + using constants::scenegraphnode::keyDependencies; + if (element.hasKey(keyDependencies)) { + if (element.hasValue(keyDependencies)) { + ghoul::Dictionary nodeDependencies; + element.getValue(constants::scenegraphnode::keyDependencies, nodeDependencies); + + std::vector keys = nodeDependencies.keys(); + for (const std::string& key : keys) { + std::string value = nodeDependencies.value(key); + dependencies[nodeName].push_back(value); + } + } + else { + LERROR("Dependencies did not have the corrent type"); + } + } + + + SceneGraphNodeInternal* internalNode = new SceneGraphNodeInternal; + internalNode->node = node; + _nodes.push_back(internalNode); + } + } + FileSys.setCurrentDirectory(oldDirectory); + + for (SceneGraphNodeInternal* node : _nodes) { + if (node->node == _rootNode) + continue; + std::string parent = parents[node->node->name()]; + SceneGraphNode* parentNode = sceneGraphNode(parent); + if (parentNode == nullptr) { + LERROR("Could not find parent '" << parent << "' for '" << node->node->name() << "'"); + } + + node->node->setParent(parentNode); + } + + // Setup dependencies + for (SceneGraphNodeInternal* node : _nodes) { + std::vector nodeDependencies = dependencies[node->node->name()]; + + for (const std::string& dep : nodeDependencies) { + SceneGraphNodeInternal* n = nodeByName(dep); + if (n == nullptr) { + LERROR("Dependent node '" << dep << "' was not loaded for '" <node->name() << "'"); + continue; + } + node->outgoingEdges.push_back(n); + n->incomingEdges.push_back(node); + } + } + + for (SceneGraphNodeInternal* node : _nodes) { + if (!nodeIsDependentOnRoot(node)) { + LERROR("Node '" << node->node->name() << "' has no direct connection to Root."); + //clear(); + return false; + } + } + + bool s = sortTopologially(); + if (!s) { + LERROR("Topological sort failed"); + return false; + } + + return true; +} + +bool SceneGraph::nodeIsDependentOnRoot(SceneGraphNodeInternal* node) { + if (node->node->name() == SceneGraphNode::RootNodeName) + return true; + else { + for (SceneGraphNodeInternal* n : node->outgoingEdges) { + bool dep = nodeIsDependentOnRoot(n); + if (dep) + return true; + } + return false; + } +} + +bool SceneGraph::sortTopologially() { + if (_nodes.empty()) + return true; + + // Only the Root node can have an in-degree of 0 + SceneGraphNodeInternal* root = nodeByName(SceneGraphNode::RootNodeName); + ghoul_assert(root != nullptr, "Could not find Root node"); + + std::stack zeroInDegreeNodes; + zeroInDegreeNodes.push(root); + + std::unordered_map inDegrees; + for (SceneGraphNodeInternal* node : _nodes) + inDegrees[node] = node->outgoingEdges.size(); + //inDegrees[node] = node->incomingEdges.size(); + + _topologicalSortedNodes.clear(); + _topologicalSortedNodes.reserve(_nodes.size()); + while (!zeroInDegreeNodes.empty()) { + SceneGraphNodeInternal* node = zeroInDegreeNodes.top(); + + _topologicalSortedNodes.push_back(node->node); + zeroInDegreeNodes.pop(); + + //for (SceneGraphNodeInternal* n : node->outgoingEdges) { + for (SceneGraphNodeInternal* n : node->incomingEdges) { + inDegrees[n] -= 1; + if (inDegrees[n] == 0) + zeroInDegreeNodes.push(n); + } + + } + return true; +} + +bool SceneGraph::addSceneGraphNode(SceneGraphNode* node) { + return true; +} + +bool SceneGraph::removeSceneGraphNode(SceneGraphNode* node) { + // How to handle orphaned nodes? (reparent to root?) --- abock + return true; +} + +SceneGraph::SceneGraphNodeInternal* SceneGraph::nodeByName(const std::string& name) { + auto it = std::find_if( + _nodes.begin(), + _nodes.end(), + [name](SceneGraphNodeInternal* node) { + return node->node->name() == name; + } + ); + + if (it == _nodes.end()) + return nullptr; + else + return *it; +} + +const std::vector& SceneGraph::nodes() { + return _topologicalSortedNodes; +} + +SceneGraphNode* SceneGraph::rootNode() const { + return _rootNode; +} + +SceneGraphNode* SceneGraph::sceneGraphNode(const std::string& name) const { + auto it = std::find_if( + _nodes.begin(), + _nodes.end(), + [name](SceneGraphNodeInternal* node) { + return node->node->name() == name; + } + ); + if (it != _nodes.end()) + return (*it)->node; + else + return nullptr; +} + +} // namespace openspace diff --git a/src/scenegraph/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp similarity index 95% rename from src/scenegraph/scenegraphnode.cpp rename to src/scene/scenegraphnode.cpp index 22e828fe05..84154f01ef 100644 --- a/src/scenegraph/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -23,7 +23,7 @@ ****************************************************************************************/ // open space includes -#include +#include #include #include @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include @@ -109,14 +109,14 @@ SceneGraphNode* SceneGraphNode::createFromDictionary(const ghoul::Dictionary& di parentName = "Root"; } - SceneGraphNode* parentNode = sceneGraphNode(parentName); - if (parentNode == nullptr) { - LFATAL("Could not find parent named '" - << parentName << "' for '" << result->name() << "'." - << " Check module definition order. Skipping module."); - } + //SceneGraphNode* parentNode = sceneGraphNode(parentName); + //if (parentNode == nullptr) { + // LFATAL("Could not find parent named '" + // << parentName << "' for '" << result->name() << "'." + // << " Check module definition order. Skipping module."); + //} - parentNode->addNode(result); + //parentNode->addNode(result); LDEBUG("Successfully created SceneGraphNode '" << result->name() << "'"); @@ -247,8 +247,8 @@ void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition) { } // evaluate all the children, tail-recursive function(?) - for (SceneGraphNode* child : _children) - child->evaluate(camera, psc()); + //for (SceneGraphNode* child : _children) + // child->evaluate(camera, psc()); } void SceneGraphNode::render(const RenderData& data) { @@ -274,8 +274,8 @@ void SceneGraphNode::render(const RenderData& data) { // evaluate all the children, tail-recursive function(?) - for (SceneGraphNode* child : _children) - child->render(newData); + //for (SceneGraphNode* child : _children) + // child->render(newData); } // set & get diff --git a/src/scenegraph/spiceephemeris.cpp b/src/scene/spiceephemeris.cpp similarity index 98% rename from src/scenegraph/spiceephemeris.cpp rename to src/scene/spiceephemeris.cpp index baea6ad361..e794521e8a 100644 --- a/src/scenegraph/spiceephemeris.cpp +++ b/src/scene/spiceephemeris.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include #include diff --git a/src/scenegraph/staticephemeris.cpp b/src/scene/staticephemeris.cpp similarity index 98% rename from src/scenegraph/staticephemeris.cpp rename to src/scene/staticephemeris.cpp index 5c2d3d6650..a87f75b897 100644 --- a/src/scenegraph/staticephemeris.cpp +++ b/src/scene/staticephemeris.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include diff --git a/src/tests/ScenegraphTest/common/common.mod b/src/tests/ScenegraphTest/common/common.mod deleted file mode 100644 index 908bdaf746..0000000000 --- a/src/tests/ScenegraphTest/common/common.mod +++ /dev/null @@ -1,11 +0,0 @@ -{ - -- 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 deleted file mode 100644 index 0839eb3f6c..0000000000 --- a/src/tests/ScenegraphTest/default.scene +++ /dev/null @@ -1,12 +0,0 @@ - - -{ - 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 deleted file mode 100644 index 0b7fccf822..0000000000 --- a/src/tests/ScenegraphTest/earth/earth.mod +++ /dev/null @@ -1,83 +0,0 @@ -{ - -- 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 deleted file mode 100644 index f888c06156..0000000000 Binary files a/src/tests/ScenegraphTest/earth/textures/earth_nasa_lowres.jpg and /dev/null differ diff --git a/src/tests/ScenegraphTest/earth/textures/earth_nasa_lowres.png b/src/tests/ScenegraphTest/earth/textures/earth_nasa_lowres.png deleted file mode 100644 index 4ab4d3cd4a..0000000000 Binary files a/src/tests/ScenegraphTest/earth/textures/earth_nasa_lowres.png and /dev/null differ diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index 55819b1fad..7dd0145a17 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -44,9 +44,9 @@ #include // positioninformation -#include -#include -#include +#include +#include +#include // projection #include diff --git a/src/tests/CMakeLists.txt b/tests/CMakeLists.txt similarity index 86% rename from src/tests/CMakeLists.txt rename to tests/CMakeLists.txt index 23d2ace4b7..957e6bdd15 100644 --- a/src/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -28,11 +28,13 @@ if (OPENSPACE_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) + include_directories("${OPENSPACE_BASE_DIR}/tests") + include_directories("${OPENSPACE_BASE_DIR}/include") + file(GLOB_RECURSE OPENSPACE_TEST_FILES ${OPENSPACE_BASE_DIR}/tests/*.inl) - source_group(OpenSpaceSource FILES ${OPENSPACE_SOURCE} ${OPENSPACE_HEADER}) + source_group(Tests FILES ${OPENSPACE_TEST_FILES}) - add_executable(OpenSpaceTest ${SOURCE_ROOT_DIR}/tests/main.cpp ${OPENSPACE_TEST_FILES} ${OPENSPACE_HEADER} ${OPENSPACE_SOURCE}) + add_executable(OpenSpaceTest ${OPENSPACE_BASE_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/tests/ScenegraphLoaderTest/circular-dependency/circular-dependency.mod b/tests/ScenegraphLoaderTest/circular-dependency/circular-dependency.mod new file mode 100644 index 0000000000..901da062d3 --- /dev/null +++ b/tests/ScenegraphLoaderTest/circular-dependency/circular-dependency.mod @@ -0,0 +1,10 @@ +return { + { + Name = "CircularDependency1", + Parent = "CircularDependency2" + }, + { + Name = "CircularDependency2", + Parent = "CircularDependency1" + } +} diff --git a/tests/ScenegraphLoaderTest/common-dependency/common-dependency.mod b/tests/ScenegraphLoaderTest/common-dependency/common-dependency.mod new file mode 100644 index 0000000000..313ebbd599 --- /dev/null +++ b/tests/ScenegraphLoaderTest/common-dependency/common-dependency.mod @@ -0,0 +1,6 @@ +return { + { + Name = "CommonDependency", + Parent = "Common" + } +} diff --git a/tests/ScenegraphLoaderTest/common/common.mod b/tests/ScenegraphLoaderTest/common/common.mod new file mode 100644 index 0000000000..3e9ef8146d --- /dev/null +++ b/tests/ScenegraphLoaderTest/common/common.mod @@ -0,0 +1,6 @@ +return { + { + Name = "Common", + Parent = "Root", + }, +} \ No newline at end of file diff --git a/tests/ScenegraphLoaderTest/direct-dependency/direct-dependency.mod b/tests/ScenegraphLoaderTest/direct-dependency/direct-dependency.mod new file mode 100644 index 0000000000..75f2243918 --- /dev/null +++ b/tests/ScenegraphLoaderTest/direct-dependency/direct-dependency.mod @@ -0,0 +1,6 @@ +return { + { + Name = "DirectDependency", + Parent = "NoDependency" + } +} diff --git a/tests/ScenegraphLoaderTest/illformed.scene b/tests/ScenegraphLoaderTest/illformed.scene new file mode 100644 index 0000000000..8872119271 --- /dev/null +++ b/tests/ScenegraphLoaderTest/illformed.scene @@ -0,0 +1,2 @@ +-- Malformed script +a diff --git a/tests/ScenegraphLoaderTest/illformedInvalidScene.scene b/tests/ScenegraphLoaderTest/illformedInvalidScene.scene new file mode 100644 index 0000000000..6ac24028f9 --- /dev/null +++ b/tests/ScenegraphLoaderTest/illformedInvalidScene.scene @@ -0,0 +1,8 @@ +-- Malformed script +return { + ScenePath = "foobar", + CommonFolder = "", + Modules = { + } +} + diff --git a/tests/ScenegraphLoaderTest/illformedNonExistingCommon.scene b/tests/ScenegraphLoaderTest/illformedNonExistingCommon.scene new file mode 100644 index 0000000000..7d7f367e42 --- /dev/null +++ b/tests/ScenegraphLoaderTest/illformedNonExistingCommon.scene @@ -0,0 +1,7 @@ +-- Malformed script +return { + ScenePath = ".", + Modules = { + } +} + diff --git a/tests/ScenegraphLoaderTest/illformedWrongCommon.scene b/tests/ScenegraphLoaderTest/illformedWrongCommon.scene new file mode 100644 index 0000000000..f46e3d9b57 --- /dev/null +++ b/tests/ScenegraphLoaderTest/illformedWrongCommon.scene @@ -0,0 +1,8 @@ +-- Malformed script +return { + ScenePath = ".", + CommonFolder = "nonexisting", + Modules = { + } +} + diff --git a/tests/ScenegraphLoaderTest/illformedWrongType.scene b/tests/ScenegraphLoaderTest/illformedWrongType.scene new file mode 100644 index 0000000000..2ab37b2a58 --- /dev/null +++ b/tests/ScenegraphLoaderTest/illformedWrongType.scene @@ -0,0 +1,8 @@ +-- Malformed script +return { + ScenePath = ".", + CommonFolder = 2, + Modules = { + } +} + diff --git a/tests/ScenegraphLoaderTest/multiple-dependencies/multiple-dependencies.mod b/tests/ScenegraphLoaderTest/multiple-dependencies/multiple-dependencies.mod new file mode 100644 index 0000000000..aee4427a42 --- /dev/null +++ b/tests/ScenegraphLoaderTest/multiple-dependencies/multiple-dependencies.mod @@ -0,0 +1,9 @@ +return { + { + Name = "MultipleDependencies", + Parent = "NoDependency", + Dependency = { + "DirectDependency" + } + } +} diff --git a/tests/ScenegraphLoaderTest/no-dependency/no-dependency.mod b/tests/ScenegraphLoaderTest/no-dependency/no-dependency.mod new file mode 100644 index 0000000000..6556b048b0 --- /dev/null +++ b/tests/ScenegraphLoaderTest/no-dependency/no-dependency.mod @@ -0,0 +1,6 @@ +return { + { + Name = "NoDependency", + Parent = "Root" + } +} diff --git a/tests/ScenegraphLoaderTest/scene-folder/common-dependency/common-dependency.mod b/tests/ScenegraphLoaderTest/scene-folder/common-dependency/common-dependency.mod new file mode 100644 index 0000000000..313ebbd599 --- /dev/null +++ b/tests/ScenegraphLoaderTest/scene-folder/common-dependency/common-dependency.mod @@ -0,0 +1,6 @@ +return { + { + Name = "CommonDependency", + Parent = "Common" + } +} diff --git a/tests/ScenegraphLoaderTest/scene-folder/common/common.mod b/tests/ScenegraphLoaderTest/scene-folder/common/common.mod new file mode 100644 index 0000000000..3e9ef8146d --- /dev/null +++ b/tests/ScenegraphLoaderTest/scene-folder/common/common.mod @@ -0,0 +1,6 @@ +return { + { + Name = "Common", + Parent = "Root", + }, +} \ No newline at end of file diff --git a/tests/ScenegraphLoaderTest/scene-folder/direct-dependency/direct-dependency.mod b/tests/ScenegraphLoaderTest/scene-folder/direct-dependency/direct-dependency.mod new file mode 100644 index 0000000000..75f2243918 --- /dev/null +++ b/tests/ScenegraphLoaderTest/scene-folder/direct-dependency/direct-dependency.mod @@ -0,0 +1,6 @@ +return { + { + Name = "DirectDependency", + Parent = "NoDependency" + } +} diff --git a/tests/ScenegraphLoaderTest/scene-folder/multiple-dependencies/multiple-dependencies.mod b/tests/ScenegraphLoaderTest/scene-folder/multiple-dependencies/multiple-dependencies.mod new file mode 100644 index 0000000000..aee4427a42 --- /dev/null +++ b/tests/ScenegraphLoaderTest/scene-folder/multiple-dependencies/multiple-dependencies.mod @@ -0,0 +1,9 @@ +return { + { + Name = "MultipleDependencies", + Parent = "NoDependency", + Dependency = { + "DirectDependency" + } + } +} diff --git a/tests/ScenegraphLoaderTest/scene-folder/no-dependency/no-dependency.mod b/tests/ScenegraphLoaderTest/scene-folder/no-dependency/no-dependency.mod new file mode 100644 index 0000000000..6556b048b0 --- /dev/null +++ b/tests/ScenegraphLoaderTest/scene-folder/no-dependency/no-dependency.mod @@ -0,0 +1,6 @@ +return { + { + Name = "NoDependency", + Parent = "Root" + } +} diff --git a/tests/ScenegraphLoaderTest/test00-location.scene b/tests/ScenegraphLoaderTest/test00-location.scene new file mode 100644 index 0000000000..b67e0be095 --- /dev/null +++ b/tests/ScenegraphLoaderTest/test00-location.scene @@ -0,0 +1,8 @@ +-- Loading an empty common and module dictionary in a different folder +return { + ScenePath = "scene-folder", + CommonFolder = "", + Modules = { + } +} + diff --git a/tests/ScenegraphLoaderTest/test00.scene b/tests/ScenegraphLoaderTest/test00.scene new file mode 100644 index 0000000000..3f8a3f419e --- /dev/null +++ b/tests/ScenegraphLoaderTest/test00.scene @@ -0,0 +1,8 @@ +-- Loading an empty common and module dictionary +return { + ScenePath = ".", + CommonFolder = "", + Modules = { + } +} + diff --git a/tests/ScenegraphLoaderTest/test01-location.scene b/tests/ScenegraphLoaderTest/test01-location.scene new file mode 100644 index 0000000000..ee76285169 --- /dev/null +++ b/tests/ScenegraphLoaderTest/test01-location.scene @@ -0,0 +1,8 @@ +-- Loading an empty module dictionary in a different folder +return { + ScenePath = "scene-folder", + CommonFolder = "common", + Modules = { + } +} + diff --git a/tests/ScenegraphLoaderTest/test01.scene b/tests/ScenegraphLoaderTest/test01.scene new file mode 100644 index 0000000000..4bcc23b96b --- /dev/null +++ b/tests/ScenegraphLoaderTest/test01.scene @@ -0,0 +1,8 @@ +-- Loading an empty module dictionary +return { + ScenePath = ".", + CommonFolder = "common", + Modules = { + } +} + diff --git a/tests/ScenegraphLoaderTest/test02-location.scene b/tests/ScenegraphLoaderTest/test02-location.scene new file mode 100644 index 0000000000..1c2122cd76 --- /dev/null +++ b/tests/ScenegraphLoaderTest/test02-location.scene @@ -0,0 +1,9 @@ +-- Loading a module without dependencies in a different folder +return { + ScenePath = "scene-folder", + CommonFolder = "common", + Modules = { + "no-dependency" + } +} + diff --git a/tests/ScenegraphLoaderTest/test02.scene b/tests/ScenegraphLoaderTest/test02.scene new file mode 100644 index 0000000000..7493bb998f --- /dev/null +++ b/tests/ScenegraphLoaderTest/test02.scene @@ -0,0 +1,9 @@ +-- Loading a module without dependencies +return { + ScenePath = ".", + CommonFolder = "common", + Modules = { + "no-dependency" + } +} + diff --git a/tests/ScenegraphLoaderTest/test03-location.scene b/tests/ScenegraphLoaderTest/test03-location.scene new file mode 100644 index 0000000000..b91e9a8cb5 --- /dev/null +++ b/tests/ScenegraphLoaderTest/test03-location.scene @@ -0,0 +1,9 @@ +-- Loading a module with a dependency on the common module in a different folder +return { + ScenePath = "scene-folder", + CommonFolder = "common", + Modules = { + "common-dependency" + } +} + diff --git a/tests/ScenegraphLoaderTest/test03.scene b/tests/ScenegraphLoaderTest/test03.scene new file mode 100644 index 0000000000..8af305f661 --- /dev/null +++ b/tests/ScenegraphLoaderTest/test03.scene @@ -0,0 +1,9 @@ +-- Loading a module with a dependency on the common module +return { + ScenePath = ".", + CommonFolder = "common", + Modules = { + "common-dependency" + } +} + diff --git a/tests/ScenegraphLoaderTest/test04-location.scene b/tests/ScenegraphLoaderTest/test04-location.scene new file mode 100644 index 0000000000..0859e85505 --- /dev/null +++ b/tests/ScenegraphLoaderTest/test04-location.scene @@ -0,0 +1,10 @@ +-- Loading a module with a direct dependency in a different folder +return { + ScenePath = "scene-folder", + CommonFolder = "common", + Modules = { + "no-dependency", + "direct-dependency" + } +} + diff --git a/tests/ScenegraphLoaderTest/test04.scene b/tests/ScenegraphLoaderTest/test04.scene new file mode 100644 index 0000000000..43acf7474d --- /dev/null +++ b/tests/ScenegraphLoaderTest/test04.scene @@ -0,0 +1,10 @@ +-- Loading a module with a direct dependency +return { + ScenePath = ".", + CommonFolder = "common", + Modules = { + "no-dependency", + "direct-dependency" + } +} + diff --git a/tests/ScenegraphLoaderTest/test05-location.scene b/tests/ScenegraphLoaderTest/test05-location.scene new file mode 100644 index 0000000000..2e069d79d3 --- /dev/null +++ b/tests/ScenegraphLoaderTest/test05-location.scene @@ -0,0 +1,11 @@ +-- Multiple Dependencies in a different folder +return { + ScenePath = "scene-folder", + CommonFolder = "common", + Modules = { + "multiple-dependencies", + "no-dependency", + "direct-dependency" + } +} + diff --git a/tests/ScenegraphLoaderTest/test05.scene b/tests/ScenegraphLoaderTest/test05.scene new file mode 100644 index 0000000000..b1605fe364 --- /dev/null +++ b/tests/ScenegraphLoaderTest/test05.scene @@ -0,0 +1,11 @@ +-- Multiple Dependencies +return { + ScenePath = ".", + CommonFolder = "common", + Modules = { + "multiple-dependencies", + "no-dependency", + "direct-dependency" + } +} + diff --git a/tests/ScenegraphLoaderTest/test06-location.scene b/tests/ScenegraphLoaderTest/test06-location.scene new file mode 100644 index 0000000000..f3af92d9de --- /dev/null +++ b/tests/ScenegraphLoaderTest/test06-location.scene @@ -0,0 +1,9 @@ +-- Circular Dependencies in a different folder +return { + ScenePath = "scene-folder", + Modules = { + "common", + "circular-dependency" + } +} + diff --git a/tests/ScenegraphLoaderTest/test06.scene b/tests/ScenegraphLoaderTest/test06.scene new file mode 100644 index 0000000000..524a44010e --- /dev/null +++ b/tests/ScenegraphLoaderTest/test06.scene @@ -0,0 +1,9 @@ +-- Circular Dependencies +return { + ScenePath = ".", + Modules = { + "common", + "circular-dependency" + } +} + diff --git a/src/tests/SpiceTest/spicekernels/020514_SE_SAT105.bsp b/tests/SpiceTest/spicekernels/020514_SE_SAT105.bsp similarity index 100% rename from src/tests/SpiceTest/spicekernels/020514_SE_SAT105.bsp rename to tests/SpiceTest/spicekernels/020514_SE_SAT105.bsp diff --git a/src/tests/SpiceTest/spicekernels/030201AP_SK_SM546_T45.bsp b/tests/SpiceTest/spicekernels/030201AP_SK_SM546_T45.bsp similarity index 100% rename from src/tests/SpiceTest/spicekernels/030201AP_SK_SM546_T45.bsp rename to tests/SpiceTest/spicekernels/030201AP_SK_SM546_T45.bsp diff --git a/src/tests/SpiceTest/spicekernels/04135_04171pc_psiv2.bc b/tests/SpiceTest/spicekernels/04135_04171pc_psiv2.bc similarity index 100% rename from src/tests/SpiceTest/spicekernels/04135_04171pc_psiv2.bc rename to tests/SpiceTest/spicekernels/04135_04171pc_psiv2.bc diff --git a/src/tests/SpiceTest/spicekernels/981005_PLTEPH-DE405S.bsp b/tests/SpiceTest/spicekernels/981005_PLTEPH-DE405S.bsp similarity index 100% rename from src/tests/SpiceTest/spicekernels/981005_PLTEPH-DE405S.bsp rename to tests/SpiceTest/spicekernels/981005_PLTEPH-DE405S.bsp diff --git a/src/tests/SpiceTest/spicekernels/cas00084.tsc b/tests/SpiceTest/spicekernels/cas00084.tsc similarity index 100% rename from src/tests/SpiceTest/spicekernels/cas00084.tsc rename to tests/SpiceTest/spicekernels/cas00084.tsc diff --git a/src/tests/SpiceTest/spicekernels/cas_iss_v09.ti b/tests/SpiceTest/spicekernels/cas_iss_v09.ti similarity index 100% rename from src/tests/SpiceTest/spicekernels/cas_iss_v09.ti rename to tests/SpiceTest/spicekernels/cas_iss_v09.ti diff --git a/src/tests/SpiceTest/spicekernels/cas_v37.tf b/tests/SpiceTest/spicekernels/cas_v37.tf similarity index 100% rename from src/tests/SpiceTest/spicekernels/cas_v37.tf rename to tests/SpiceTest/spicekernels/cas_v37.tf diff --git a/src/tests/SpiceTest/spicekernels/cpck05Mar2004.tpc b/tests/SpiceTest/spicekernels/cpck05Mar2004.tpc similarity index 100% rename from src/tests/SpiceTest/spicekernels/cpck05Mar2004.tpc rename to tests/SpiceTest/spicekernels/cpck05Mar2004.tpc diff --git a/src/tests/SpiceTest/spicekernels/metaKernel.tm b/tests/SpiceTest/spicekernels/metaKernel.tm similarity index 100% rename from src/tests/SpiceTest/spicekernels/metaKernel.tm rename to tests/SpiceTest/spicekernels/metaKernel.tm diff --git a/src/tests/SpiceTest/spicekernels/naif0008.tls b/tests/SpiceTest/spicekernels/naif0008.tls similarity index 100% rename from src/tests/SpiceTest/spicekernels/naif0008.tls rename to tests/SpiceTest/spicekernels/naif0008.tls diff --git a/src/tests/main.cpp b/tests/main.cpp similarity index 75% rename from src/tests/main.cpp rename to tests/main.cpp index 11ad40c34e..ede4213fc6 100644 --- a/src/tests/main.cpp +++ b/tests/main.cpp @@ -30,11 +30,11 @@ #include #include -#include -#include -//#include -#include -#include +#include +//#include +#include +//#include +//#include #include #include #include @@ -52,22 +52,28 @@ namespace { } int main(int argc, char** argv) { - LogManager::initialize(LogManager::LogLevel::Debug); - LogMgr.addLog(new ConsoleLog); + std::vector args; + std::string glVersion; + openspace::OpenSpaceEngine::create(argc, argv, args, glVersion); - FileSystem::initialize(); - std::string configurationFilePath = ""; - LDEBUG("Finding configuration"); - if( ! openspace::OpenSpaceEngine::findConfiguration(configurationFilePath)) { - LFATAL("Could not find OpenSpace configuration file!"); - assert(false); - } - LINFO("Configuration file found: " << FileSys.absolutePath(configurationFilePath)); - openspace::ConfigurationManager manager; - manager.loadFromFile(configurationFilePath); + //LogManager::initialize(LogManager::LogLevel::Debug); + //LogMgr.addLog(new ConsoleLog); + + //FileSystem::initialize(); + //std::string configurationFilePath = ""; + //LDEBUG("Finding configuration"); + //if (!openspace::OpenSpaceEngine::findConfiguration(configurationFilePath)) { + // LFATAL("Could not find OpenSpace configuration file!"); + // assert(false); + //} + ////LINFO("Configuration file found: " << FileSys.absolutePath(configurationFilePath)); + + //openspace::ConfigurationManager manager; + //manager.loadFromFile(configurationFilePath); + - openspace::FactoryManager::initialize(); + //openspace::FactoryManager::initialize(); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/include/openspace/tests/test_common.inl b/tests/test_common.inl similarity index 100% rename from include/openspace/tests/test_common.inl rename to tests/test_common.inl diff --git a/include/openspace/tests/test_luaconversions.inl b/tests/test_luaconversions.inl similarity index 100% rename from include/openspace/tests/test_luaconversions.inl rename to tests/test_luaconversions.inl diff --git a/include/openspace/tests/test_powerscalecoordinates.inl b/tests/test_powerscalecoordinates.inl similarity index 97% rename from include/openspace/tests/test_powerscalecoordinates.inl rename to tests/test_powerscalecoordinates.inl index f5a99248f6..837f92e7a8 100644 --- a/include/openspace/tests/test_powerscalecoordinates.inl +++ b/tests/test_powerscalecoordinates.inl @@ -24,7 +24,7 @@ #include "gtest/gtest.h" -#include +#include #include #include @@ -40,7 +40,7 @@ protected: void reset() { } - openspace::SceneGraph* scenegraph; + openspace::Scene* scenegraph; }; diff --git a/tests/test_scenegraphloader.inl b/tests/test_scenegraphloader.inl new file mode 100644 index 0000000000..27c957e459 --- /dev/null +++ b/tests/test_scenegraphloader.inl @@ -0,0 +1,381 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * 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 SceneGraphLoaderTest : public testing::Test {}; + +//TEST_F(SceneGraphLoaderTest, NonExistingFileTest) { +// const std::string file = "NonExistingFile"; +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// EXPECT_FALSE(success) << "Unsuccessful loading"; +// EXPECT_TRUE(nodes.empty()) << "Empty scenegraph nodes list"; +//} +// +//TEST_F(SceneGraphLoaderTest, IllformedFileTest) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/illformed.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// EXPECT_FALSE(success) << "Unsuccessful loading"; +// EXPECT_TRUE(nodes.empty()) << "Empty scenegraph nodes list"; +//} +// +//TEST_F(SceneGraphLoaderTest, IllformedFileTestWrongCommonFolderType) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/illformedWrongType.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// EXPECT_FALSE(success) << "Unsuccessful loading"; +// EXPECT_TRUE(nodes.empty()) << "Empty scenegraph nodes list"; +//} +// +//TEST_F(SceneGraphLoaderTest, IllformedFileTestInvalidSceneFolder) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/illformedInvalidScene.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// EXPECT_FALSE(success) << "Unsuccessful loading"; +// EXPECT_TRUE(nodes.empty()) << "Empty scenegraph nodes list"; +//} +// +//TEST_F(SceneGraphLoaderTest, IllformedFileTestWrongCommonFolder) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/illformedWrongCommon.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// EXPECT_FALSE(success) << "Unsuccessful loading"; +// EXPECT_TRUE(nodes.empty()) << "Empty scenegraph nodes list"; +//} +// +//TEST_F(SceneGraphLoaderTest, IllformedFileTestNonExistingCommonFolder) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/illformedNonExistingCommon.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// EXPECT_FALSE(success) << "Unsuccessful loading"; +// EXPECT_TRUE(nodes.empty()) << "Empty scenegraph nodes list"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test00) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test00.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// EXPECT_TRUE(nodes.empty()) << "No scenegraph nodes loaded"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test00Location) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test00-location.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// EXPECT_TRUE(nodes.empty()) << "No scenegraph nodes loaded"; +//} +// +//TEST_F(SceneGraphLoaderTest, AbsoluteScenePath) { +// const std::string scenePath = absPath("${TEMPORARY}/tmp.scene"); +// std::ofstream scene(scenePath.c_str()); +// +// scene << "return {" << std::endl << +// " ScenePath = \"" << absPath("${TESTDIR}/SceneGraphLoaderTest/scene-folder") << +// "\"," << std::endl << +// " CommonFolder = \"\"," << std::endl << +// " Modules = {}}" << std::endl; +// scene.close(); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(scenePath, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// EXPECT_TRUE(nodes.empty()) << "No scenegraph nodes loaded"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test01) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test01.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// ASSERT_TRUE(nodes.size() == 1) << "Correct number of nodes"; +// EXPECT_TRUE(nodes[0]->name() == "Common") << "Correct node loaded"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test01Location) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test01-location.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// ASSERT_TRUE(nodes.size() == 1) << "Correct number of nodes"; +// EXPECT_TRUE(nodes[0]->name() == "Common") << "Correct node loaded"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test02) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test02.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// ASSERT_TRUE(nodes.size() == 2) << "Correct number of nodes"; +// bool found = false; +// for (openspace::SceneGraphNode* n : nodes) +// if (n->name() == "NoDependency") +// found = true; +// +// EXPECT_TRUE(found) << "Correct node loaded"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test02Location) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test02-location.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// ASSERT_TRUE(nodes.size() == 2) << "Correct number of nodes"; +// bool found = false; +// for (openspace::SceneGraphNode* n : nodes) +// if (n->name() == "NoDependency") +// found = true; +// +// EXPECT_TRUE(found) << "Correct node loaded"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test03) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test03.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// ASSERT_TRUE(nodes.size() == 2) << "Correct number of nodes"; +// bool found = false; +// for (openspace::SceneGraphNode* n : nodes) +// if (n->name() == "CommonDependency") +// found = true; +// +// EXPECT_TRUE(found) << "Correct node loaded"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test03Location) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test03-location.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// ASSERT_TRUE(nodes.size() == 2) << "Correct number of nodes"; +// bool found = false; +// for (openspace::SceneGraphNode* n : nodes) +// if (n->name() == "CommonDependency") +// found = true; +// +// EXPECT_TRUE(found) << "Correct node loaded"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test04) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test04.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// ASSERT_TRUE(nodes.size() == 3) << "Correct number of nodes"; +// bool found = false; +// for (openspace::SceneGraphNode* n : nodes) +// if (n->name() == "DirectDependency") +// found = true; +// +// EXPECT_TRUE(found) << "Correct node loaded"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test04Location) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test04-location.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// ASSERT_TRUE(nodes.size() == 3) << "Correct number of nodes"; +// bool found = false; +// for (openspace::SceneGraphNode* n : nodes) +// if (n->name() == "DirectDependency") +// found = true; +// +// EXPECT_TRUE(found) << "Correct node loaded"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test05) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test05.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// ASSERT_TRUE(nodes.size() == 4) << "Correct number of nodes"; +// bool found = false; +// for (openspace::SceneGraphNode* n : nodes) +// if (n->name() == "MultipleDependencies") +// found = true; +// +// EXPECT_TRUE(found) << "Correct node loaded"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test05Location) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test05-location.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// ASSERT_TRUE(nodes.size() == 4) << "Correct number of nodes"; +// bool found = false; +// for (openspace::SceneGraphNode* n : nodes) +// if (n->name() == "MultipleDependencies") +// found = true; +// +// EXPECT_TRUE(found) << "Correct node loaded"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test06) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test06.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_FALSE(success) << "Successful loading"; +// ASSERT_TRUE(nodes.empty()) << "Correct number of nodes"; +//} +// +//TEST_F(SceneGraphLoaderTest, Test06Location) { +// const std::string file = absPath("${TESTDIR}/SceneGraphLoaderTest/test06-location.scene"); +// +// std::vector nodes; +// bool success = openspace::SceneGraphLoader::load(file, nodes); +// +// ASSERT_TRUE(success) << "Successful loading"; +// ASSERT_TRUE(nodes.size() == 4) << "Correct number of nodes"; +// bool found = false; +// for (openspace::SceneGraphNode* n : nodes) +// if (n->name() == "MultipleDependencies") +// found = true; +// +// EXPECT_TRUE(found) << "No scenegraph nodes loaded"; +//} +// +//// +//// +//// +////TEST_F(SceneGraphTest, SceneGraphNode) { +//// +//// openspace::SceneGraphNode *node = +//// openspace::SceneGraphNode::createFromDictionary(ghoul::Dictionary()); +//// +//// // Should not have a renderable and position should be 0,0,0,0 (undefined). +//// EXPECT_EQ(nullptr, node->renderable()); +//// EXPECT_EQ(openspace::psc(), node->position()); +//// +//// delete node; +//// ghoul::Dictionary nodeDictionary; +//// +//// ghoul::Dictionary positionDictionary; +//// ghoul::Dictionary positionPositionArrayDictionary; +//// +//// ghoul::Dictionary renderableDictionary; +//// +//// renderableDictionary.setValue("Type", std::string("RenderablePlanet")); +//// +//// positionPositionArrayDictionary.setValue("1", 1.0); +//// positionPositionArrayDictionary.setValue("2", 1.0); +//// positionPositionArrayDictionary.setValue("3", 1.0); +//// positionPositionArrayDictionary.setValue("4", 1.0); +//// +//// positionDictionary.setValue("Type", std::string("Static")); +//// positionDictionary.setValue("Position", positionPositionArrayDictionary); +//// +//// nodeDictionary.setValue("Position", positionDictionary); +//// nodeDictionary.setValue("Renderable", renderableDictionary); +//// +//// node = +//// openspace::SceneGraphNode::createFromDictionary(nodeDictionary); +//// +//// // This node should have a renderable (probably no good values but an existing one) +//// EXPECT_TRUE(node->renderable()); +//// +//// // position should be initialized +//// EXPECT_EQ(openspace::psc(1.0,1.0,1.0,1.0), node->position()); +//// +//// delete node; +////} +//// +////TEST_F(SceneGraphTest, Loading) { +//// +//// +//// // Should not successfully load a non existing scenegraph +//// EXPECT_FALSE(_scenegraph->loadScene(absPath("${TESTDIR}/ScenegraphTestNonExisting"), absPath("${TESTDIR}"))); +//// +//// // Existing scenegraph should load +//// EXPECT_TRUE(_scenegraph->loadScene(absPath("${TESTDIR}/ScenegraphTest"), absPath("${TESTDIR}"))); +//// // TODO need to check for correctness +//// +//// // This loading should fail regardless of existing or not since the +//// // scenegraph is already loaded +//// EXPECT_FALSE(_scenegraph->loadScene(absPath("${TESTDIR}/ScenegraphTest"), absPath("${TESTDIR}"))); +////} +//// +////TEST_F(SceneGraphTest, Reinitializing) { +//// +//// // Existing scenegraph should load +//// EXPECT_TRUE(_scenegraph->loadScene(absPath("${TESTDIR}/ScenegraphTest"), absPath("${TESTDIR}"))); +//// +//// _scenegraph->deinitialize(); +//// +//// // Existing scenegraph should load +//// EXPECT_TRUE(_scenegraph->loadScene(absPath("${TESTDIR}/ScenegraphTest"), absPath("${TESTDIR}"))); +//// // TODO need to check for correctness +////} +// + + + diff --git a/include/openspace/tests/test_spicemanager.inl b/tests/test_spicemanager.inl similarity index 99% rename from include/openspace/tests/test_spicemanager.inl rename to tests/test_spicemanager.inl index 12b1dd116c..7be7a8f5d6 100644 --- a/include/openspace/tests/test_spicemanager.inl +++ b/tests/test_spicemanager.inl @@ -24,7 +24,7 @@ #include #include "gtest/gtest.h" -#include "openspace/util/spicemanager.h" +#include class SpiceManagerTest : public testing::Test{ protected: