From ea5382c0285f2a5d62e0a30428b3787f988194fa Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Fri, 22 Sep 2017 12:03:23 +0200 Subject: [PATCH 01/13] Volume conversion and rendering (#350) Add volume rendering features - Improve task runner - Improve reading from CDF files - Basic time varying volume rendering - Fix scaling bug in RenderableToyVolume --- apps/TaskRunner/main.cpp | 110 +++- ext/ghoul | 2 +- .../openspace/engine/configurationmanager.h | 4 +- .../openspace/rendering/framebufferrenderer.h | 1 - include/openspace/util/timemanager.h | 3 + modules/globebrowsing/globebrowsingmodule.cpp | 9 + modules/kameleonvolume/CMakeLists.txt | 4 +- .../kameleonvolume/kameleonvolumemodule.cpp | 5 + .../kameleonvolume/kameleonvolumereader.cpp | 129 ++++- modules/kameleonvolume/kameleonvolumereader.h | 27 +- .../rendering/renderablekameleonvolume.cpp | 28 +- .../rendering/renderablekameleonvolume.h | 19 +- .../tasks/kameleondocumentationtask.cpp | 2 + .../tasks/kameleondocumentationtask.h | 2 + .../tasks/kameleonmetadatatojsontask.cpp | 2 + .../tasks/kameleonmetadatatojsontask.h | 2 + .../tasks/kameleonvolumetorawtask.cpp | 207 ++++++++ .../tasks/kameleonvolumetorawtask.h | 59 +++ .../rendering/renderabletoyvolume.cpp | 5 +- modules/volume/CMakeLists.txt | 5 + modules/volume/linearlrucache.h | 2 + modules/volume/lrucache.h | 2 + modules/volume/rawvolume.h | 2 + modules/volume/rawvolume.inl | 13 +- modules/volume/rawvolumereader.h | 2 + modules/volume/rawvolumereader.inl | 6 +- modules/volume/rawvolumewriter.h | 2 + modules/volume/rawvolumewriter.inl | 6 +- .../rendering/basicvolumeraycaster.cpp} | 175 +++++-- .../rendering/basicvolumeraycaster.h} | 37 +- .../rendering/renderabletimevaryingvolume.cpp | 473 ++++++++++++++++++ .../rendering/renderabletimevaryingvolume.h | 109 ++++ modules/volume/rendering/volumeclipplane.cpp | 3 +- modules/volume/rendering/volumeclipplane.h | 4 +- modules/volume/rendering/volumeclipplanes.cpp | 2 + modules/volume/rendering/volumeclipplanes.h | 4 +- .../shaders/boundsfs.glsl | 0 .../shaders/boundsvs.glsl | 0 .../shaders/helper.glsl | 7 +- .../shaders/raycast.glsl | 29 +- modules/volume/textureslicevolumereader.h | 2 + modules/volume/textureslicevolumereader.inl | 2 + modules/volume/volumegridtype.cpp | 48 ++ modules/volume/volumegridtype.h | 11 + modules/volume/volumemodule.cpp | 11 +- modules/volume/volumemodule.h | 1 + modules/volume/volumesampler.h | 2 + modules/volume/volumesampler.inl | 2 + modules/volume/volumeutils.cpp | 10 +- modules/volume/volumeutils.h | 6 +- openspace.cfg | 3 +- src/engine/configurationmanager.cpp | 2 +- src/engine/configurationmanager_doc.inl | 4 +- src/rendering/renderable.cpp | 4 +- src/rendering/transferfunction.cpp | 3 +- src/util/taskloader.cpp | 8 +- src/util/timemanager.cpp | 10 +- tests/main.cpp | 4 + tests/test_rawvolumeio.inl | 93 ++++ 59 files changed, 1553 insertions(+), 176 deletions(-) create mode 100644 modules/kameleonvolume/tasks/kameleonvolumetorawtask.cpp create mode 100644 modules/kameleonvolume/tasks/kameleonvolumetorawtask.h rename modules/{kameleonvolume/rendering/kameleonvolumeraycaster.cpp => volume/rendering/basicvolumeraycaster.cpp} (54%) rename modules/{kameleonvolume/rendering/kameleonvolumeraycaster.h => volume/rendering/basicvolumeraycaster.h} (79%) create mode 100644 modules/volume/rendering/renderabletimevaryingvolume.cpp create mode 100644 modules/volume/rendering/renderabletimevaryingvolume.h rename modules/{kameleonvolume => volume}/shaders/boundsfs.glsl (100%) rename modules/{kameleonvolume => volume}/shaders/boundsvs.glsl (100%) rename modules/{kameleonvolume => volume}/shaders/helper.glsl (93%) rename modules/{kameleonvolume => volume}/shaders/raycast.glsl (78%) create mode 100644 modules/volume/volumegridtype.cpp create mode 100644 tests/test_rawvolumeio.inl diff --git a/apps/TaskRunner/main.cpp b/apps/TaskRunner/main.cpp index 5edbd82b41..83d426cd23 100644 --- a/apps/TaskRunner/main.cpp +++ b/apps/TaskRunner/main.cpp @@ -31,12 +31,15 @@ #include #include #include +#include +#include +#include #include +#include +#include #include - #include - #include #include #include @@ -62,10 +65,54 @@ void initTextureReaders() { #endif // GHOUL_USE_FREEIMAGE } +void performTasks(const std::string& path) { + using namespace openspace; + + TaskLoader taskLoader; + std::vector> tasks = taskLoader.tasksFromFile(path); + + size_t nTasks = tasks.size(); + if (nTasks == 1) { + LINFO("Task queue has 1 item"); + } + else { + LINFO("Task queue has " << tasks.size() << " items"); + } + + for (size_t i = 0; i < tasks.size(); i++) { + Task& task = *tasks[i].get(); + LINFO("Performing task " << (i + 1) << " out of " << tasks.size() << ": " << task.description()); + ProgressBar progressBar(100); + auto onProgress = [&progressBar](float progress) { + progressBar.print(progress * 100); + }; + task.perform(onProgress); + } + std::cout << "Done performing tasks." << std::endl; +} + int main(int argc, char** argv) { using namespace openspace; ghoul::initialize(); + + ghoul::logging::LogManager::initialize( + ghoul::logging::LogLevel::Debug, + ghoul::logging::LogManager::ImmediateFlush::Yes + ); + LogMgr.addLog(std::make_unique< ghoul::logging::ConsoleLog>()); + + LDEBUG("Initialize FileSystem"); + + ghoul::filesystem::Directory launchDirectory = FileSys.currentDirectory(); + +#ifdef __APPLE__ + ghoul::filesystem::File app(argv[0]); + std::string dirName = app.directoryName(); + LINFO("Setting starting directory to '" << dirName << "'"); + FileSys.setCurrentDirectory(dirName); +#endif + initTextureReaders(); FactoryManager::initialize(); @@ -98,34 +145,49 @@ int main(int argc, char** argv) { ModuleEngine moduleEngine; moduleEngine.initialize(); - - std::string tasksPath; - configuration.getValue(ConfigurationManager::KeyConfigTask, tasksPath); - LINFO("Initialization done."); - TaskLoader taskLoader; - std::vector> tasks = taskLoader.tasksFromFile(tasksPath); - - size_t nTasks = tasks.size(); - if (nTasks == 1) { - LINFO("Task queue has 1 item"); - } else { - LINFO("Task queue has " << tasks.size() << " items"); + // Parse commandline arguments + std::vector args(argv, argv + argc); + + ghoul::cmdparser::CommandlineParser commandlineParser( + "OpenSpace TaskRunner", + ghoul::cmdparser::CommandlineParser::AllowUnknownCommands::Yes + ); + + std::string tasksPath = ""; + commandlineParser.addCommand( + std::make_unique>( + &tasksPath, + "--task", + "-t", + "Provides the path to a task file to execute" + ) + ); + + commandlineParser.setCommandLine(args); + commandlineParser.execute(); + + FileSys.setCurrentDirectory(launchDirectory); + + if (tasksPath != "") { + performTasks(tasksPath); + return 0; } - for (size_t i = 0; i < tasks.size(); i++) { - Task& task = *tasks[i].get(); - LINFO("Performing task " << (i+1) << " out of " << tasks.size() << ": " << task.description()); - ProgressBar progressBar(100); - auto onProgress = [&progressBar](float progress) { - progressBar.print(progress * 100); - }; - task.perform(onProgress); + // If no task file was specified in as argument, run in CLI mode. + + std::string tasksRoot; + if (configuration.getValue(ConfigurationManager::KeyConfigTasksRoot, tasksRoot)) { + LINFO("Task root: " << tasksRoot); + FileSys.setCurrentDirectory(ghoul::filesystem::Directory(absPath(tasksRoot))); } - std::cout << "Done performing tasks." << std::endl; + std::cout << "TASK >"; + while (std::cin >> tasksPath) { + performTasks(tasksPath); + std::cout << "TASK >"; + } - std::cin.get(); return 0; }; diff --git a/ext/ghoul b/ext/ghoul index 3fd891bcc8..620e4faf5f 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 3fd891bcc8a7b31eee4021033e9a1dbc72846f1d +Subproject commit 620e4faf5f948259d793c17634314a97fc9d5fe8 diff --git a/include/openspace/engine/configurationmanager.h b/include/openspace/engine/configurationmanager.h index 2f9c387251..75163f2c75 100644 --- a/include/openspace/engine/configurationmanager.h +++ b/include/openspace/engine/configurationmanager.h @@ -69,8 +69,8 @@ public: static const std::string KeyFactoryDocumentation; /// The key that stores the location of the scene file that is initially loaded static const std::string KeyConfigScene; - /// The key that stores the location of the tasks file that is initially loaded - static const std::string KeyConfigTask; + /// The key that stores the location of the tasks files + static const std::string KeyConfigTasksRoot; /// The key that stores the subdirectory containing a list of all startup scripts to /// be executed on application start before the scene file is loaded static const std::string KeyStartupScript; diff --git a/include/openspace/rendering/framebufferrenderer.h b/include/openspace/rendering/framebufferrenderer.h index 9a0d6c9799..c82be8e536 100644 --- a/include/openspace/rendering/framebufferrenderer.h +++ b/include/openspace/rendering/framebufferrenderer.h @@ -46,7 +46,6 @@ namespace ghoul::opengl { namespace openspace { -class RenderableVolume; class Camera; class Scene; diff --git a/include/openspace/util/timemanager.h b/include/openspace/util/timemanager.h index a499c2d400..2a7ef4d21b 100644 --- a/include/openspace/util/timemanager.h +++ b/include/openspace/util/timemanager.h @@ -42,8 +42,11 @@ public: void removeKeyframesBefore(double timestamp); void removeKeyframesAfter(double timestamp); void clearKeyframes(); + void setTimeNextFrame(Time t); size_t nKeyframes() const; private: + bool _shouldSetTime; + Time _timeNextFrame; Timeline