From 16518dbc965f46b436ea58af1b1dd911fa9e6132 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 20 Jan 2015 21:32:46 +0100 Subject: [PATCH] Allow renderablefieldlines to load a passed file instead of requiring loading through Lua --- openspace-data | 2 +- src/rendering/renderablefieldlines.cpp | 42 +++++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/openspace-data b/openspace-data index 38e21a1957..dc638c66fd 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 38e21a195794d96bd88453190f15d6b731f4a72f +Subproject commit dc638c66fdaf8ff3ed6a6f87eb66778093035833 diff --git a/src/rendering/renderablefieldlines.cpp b/src/rendering/renderablefieldlines.cpp index 7bd1c3d9ca..ee2c8298ba 100644 --- a/src/rendering/renderablefieldlines.cpp +++ b/src/rendering/renderablefieldlines.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -99,7 +100,7 @@ bool RenderableFieldlines::initialize() { return false; } - ghoul_assert(_hintsDictionaries.size() != _filenames.size(), + ghoul_assert(_hintsDictionaries.size() == _filenames.size(), "The dictionary sizes should match, " << _hintsDictionaries.size() << " != " << _filenames.size()); @@ -218,15 +219,42 @@ std::vector > RenderableFieldlines::getFieldlinesData(std } // ------ SEEDPOINTS --------------- - ghoul::Dictionary seedpointsDictionary; _seedPoints.clear(); - if (hintsDictionary.hasKey("Seedpoints") && hintsDictionary.getValue("Seedpoints", seedpointsDictionary)) { - glm::vec3 seedPos; - for (const std::string& index : seedpointsDictionary.keys()) { - hintsDictionary.getValue("Seedpoints."+index, seedPos); - _seedPoints.push_back(seedPos); + if (hintsDictionary.hasKey("Seedpoints")) { + if (hintsDictionary.hasKeyAndValue("Seedpoints")) { + LINFO("Loading provided list of seed points"); + ghoul::Dictionary seedpointsDictionary; + hintsDictionary.getValue("Seedpoints", seedpointsDictionary); + glm::vec3 seedPos; + for (const std::string& index : seedpointsDictionary.keys()) { + hintsDictionary.getValue("Seedpoints." + index, seedPos); + _seedPoints.push_back(seedPos); + } + } + else if (hintsDictionary.hasKeyAndValue("Seedpoints")) { + std::string seedPointsFile; + hintsDictionary.getValue("Seedpoints", seedPointsFile); + seedPointsFile = absPath(seedPointsFile); + LINFO("Reading seed points from file '" << seedPointsFile << "'"); + + std::ifstream seedFile(seedPointsFile); + if (!seedFile.good()) + LERROR("Could not open seed points file '" << seedPointsFile << "'"); + else { + std::string line; + glm::vec3 point; + while (std::getline(seedFile, line)) { + std::stringstream s(line); + s >> point.x; + s >> point.y; + s >> point.z; + _seedPoints.push_back(std::move(point)); + } + } } } + else + LERROR("Fieldlines did not provide seed points"); // ------ CLASSIFICATION & COLOR ----------- hintsDictionary.getValue("Color", fieldlineColor);