diff --git a/include/openspace/rendering/planets/renderableplanetprojection.h b/include/openspace/rendering/planets/renderableplanetprojection.h index c0d18c084c..b35013b02f 100644 --- a/include/openspace/rendering/planets/renderableplanetprojection.h +++ b/include/openspace/rendering/planets/renderableplanetprojection.h @@ -88,7 +88,7 @@ private: glm::mat4 _projectorMatrix; // spice - std::string _sequenceDir; + std::string _sequenceFile; std::string _instrumentID; std::string _projectorID; std::string _projecteeID; diff --git a/include/openspace/util/imagesequencer.h b/include/openspace/util/imagesequencer.h index d71b8dac19..007d7f1343 100644 --- a/include/openspace/util/imagesequencer.h +++ b/include/openspace/util/imagesequencer.h @@ -39,7 +39,8 @@ public: static ImageSequencer& ref(); bool loadSequence(const std::string dir); - bool parsePlaybook(const std::string& dir, const std::string& type, std::string year = "2015"); + bool parsePlaybook(const std::string& dir, const std::string& type, std::string year = "2015"); + bool parsePlaybookFile(const std::string& fileName, std::string year = "2015"); void testStartTimeMap(); @@ -61,6 +62,8 @@ private: double _nextCapture; double _intervalLength; + + std::string _defaultCaptureImage; }; } // namespace openspace diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 4b929c4782..d8cc0f531f 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -95,7 +95,6 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName) , _syncBuffer(nullptr) { SpiceManager::initialize(); - ImageSequencer::initialize(); Time::initialize(); FactoryManager::initialize(); ghoul::systemcapabilities::SystemCapabilities::initialize(); @@ -197,6 +196,8 @@ bool OpenSpaceEngine::create(int argc, char** argv, } } + ImageSequencer::initialize(); + // Create the cachemanager FileSys.createCacheManager(absPath("${" + constants::configurationmanager::keyCache + "}")); _engine->_console->initialize(); diff --git a/src/rendering/planets/renderableplanetprojection.cpp b/src/rendering/planets/renderableplanetprojection.cpp index 8321472426..5246eb7574 100644 --- a/src/rendering/planets/renderableplanetprojection.cpp +++ b/src/rendering/planets/renderableplanetprojection.cpp @@ -138,17 +138,12 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& addProperty(_projectionTexturePath); _projectionTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadProjectionTexture, this)); - bool found = dictionary.getValue(keySequenceDir, _sequenceDir); - if (found){ - /* - bool loaded = openspace::ImageSequencer::ref().loadSequence(_sequenceDir); - if (!loaded) LDEBUG(name + " did not load sequence " + _sequenceDir + " check mod file path"); - */ - //openspace::ImageSequencer::ref().parsePlaybook("C:/Users/michal/playbook", "txt"); - //openspace::ImageSequencer::ref().parsePlaybook("C:/Users/joaki56/Desktop/ProjectionsOfInterest/playbook", "txt"); - openspace::ImageSequencer::ref().parsePlaybook(absPath("${OPENSPACE_DATA}/playbook.csv"), "csv"); - - } + bool found = dictionary.getValue(keySequenceDir, _sequenceFile); + _sequenceFile = path + ghoul::filesystem::FileSystem::PathSeparator + _sequenceFile; + if (found) + openspace::ImageSequencer::ref().parsePlaybookFile(_sequenceFile); + else + LERROR("Sequence description file was not specified in module description"); } RenderablePlanetProjection::~RenderablePlanetProjection(){ diff --git a/src/util/imagesequencer.cpp b/src/util/imagesequencer.cpp index 4ddd24905c..a32519cd3f 100644 --- a/src/util/imagesequencer.cpp +++ b/src/util/imagesequencer.cpp @@ -28,10 +28,13 @@ #include #include #include +#include #include #include #include +#include +#include namespace { const std::string _loggerCat = "ImageSequencer"; @@ -61,7 +64,10 @@ ImageSequencer& ImageSequencer::ref() { void ImageSequencer::initialize(){ assert(_sequencer == nullptr); _sequencer = new ImageSequencer; + + _sequencer->_defaultCaptureImage = absPath("${OPENSPACE_DATA}/scene/common/textures/placeholder.png"); } + void ImageSequencer::deinitialize(){ delete _sequencer; _sequencer = nullptr; @@ -78,8 +84,8 @@ void ImageSequencer::createImage(double t1, double t2, std::string path){ _timeStamps.push_back(image); // sort - std::sort(_timeStamps.begin(), _timeStamps.end(), cmp); } + double ImageSequencer::getNextCaptureTime(){ return _nextCapture; } @@ -158,81 +164,128 @@ bool replace(std::string& str, const std::string& from, const std::string& to) { } bool ImageSequencer::parsePlaybook(const std::string& dir, const std::string& type, std::string year){ - //ghoul::filesystem::Directory playbookDir(dir, true); - //std::vector dirlist = playbookDir.read(true, false); - //for (auto path : dirlist){ - std::string path = dir; - if (size_t position = path.find_last_of(".") + 1){ - if (position != std::string::npos){ - ghoul::filesystem::File currentFile(path); - std::string extension = currentFile.fileExtension(); - - if (extension == type && extension == "csv"){ // comma separated playbook - std::cout << "USING COMMA SEPARATED TIMELINE V9F" << std::endl; - std::ifstream file(currentFile.path()); - if (!file.good()) LERROR("Failed to open csv file '" << currentFile.path() << "'"); - - std::string timestr = ""; - double shutter = 0.01; - double et; - do{ - std::getline(file, timestr); - auto pos = timestr.find("LORRI image started"); - if (pos != std::string::npos){ - timestr = timestr.substr(timestr.find_first_of(",")+1); - timestr = timestr.substr(0, timestr.find_first_of(",")); - - replace(timestr, " ", "::"); - timestr = year + " " + timestr; - - openspace::SpiceManager::ref().getETfromDate(timestr, et); - std::string defaultImagePath = absPath("${OPENSPACE_DATA}/placeholder.png"); - createImage(et, et + shutter, defaultImagePath); - } - } while (!file.eof()); - } - /* - if (extension == type && extension == "txt"){// Hong Kang. pre-parsed playbook - std::cout << "USING PREPARSED PLAYBOOK V9H" << std::endl; - std::ifstream file(currentFile.path()); - if (!file.good()) LERROR("Failed to open txt file '" << currentFile.path() << "'"); - - std::string timestr = ""; - double shutter = 0.01; - double et; - - double metRef = 299180517; - do{ - std::getline(file, timestr); - auto pos = timestr.find("LORRI Image Started"); - if (pos != std::string::npos){ - timestr = timestr.substr(24, 9); - std::string::size_type sz; // alias of size_t - - double met = std::stod(timestr, &sz); - double diff; - openspace::SpiceManager::ref().getETfromDate("2015-07-14T11:50:00.00", et); - - diff = abs(met - metRef); - if (met > metRef){ - et += diff; - } - else if (met < metRef){ - et -= diff; - } - - std::string defaultImagePath = absPath("${OPENSPACE_DATA}/placeholder.png"); - createImage(et, et + shutter, defaultImagePath); - } - } while (!file.eof()); - } - */ - } - } - //} + ghoul::filesystem::Directory playbookDir(dir, true); + std::vector dirlist = playbookDir.read(true, false); + for (auto path : dirlist) { + bool success = parsePlaybookFile(path, year); + if (!success) + return false; + } return true; // add check } +bool ImageSequencer::parsePlaybookFile(const std::string& fileName, std::string year) { + if (size_t position = fileName.find_last_of(".") + 1){ + if (position != std::string::npos){ + std::string extension = ghoul::filesystem::File(fileName).fileExtension(); + + if (extension == "csv"){ // comma separated playbook + std::cout << "USING COMMA SEPARATED TIMELINE V9F" << std::endl; + + std::string cachedFile = ""; + FileSys.cacheManager()->getCachedFile(fileName, cachedFile, true); + + bool hasCachedFile = FileSys.fileExists(cachedFile); + if (hasCachedFile) { + std::ifstream file(cachedFile); + if (!file.good()) + LERROR("Error loading cached playbook '" << cachedFile << "'"); + else { + do { + std::string line; + std::getline(file, line); + + std::stringstream s(line); + + double start, end; + std::string path; + + s >> start; + s >> end; + + std::getline(s, path); + createImage(start, end, _defaultCaptureImage); + } while (!file.eof()); + } + } else { + std::ifstream file(fileName); + if (!file.good()) LERROR("Failed to open csv file '" << fileName << "'"); + + std::string timestr = ""; + double shutter = 0.01; + double et; + do{ + std::getline(file, timestr); + auto pos = timestr.find("LORRI image started"); + if (pos != std::string::npos){ + timestr = timestr.substr(timestr.find_first_of(",") + 1); + timestr = timestr.substr(0, timestr.find_first_of(",")); + + replace(timestr, " ", "::"); + timestr = year + " " + timestr; + + openspace::SpiceManager::ref().getETfromDate(timestr, et); + createImage(et, et + shutter, _defaultCaptureImage); + } + } while (!file.eof()); + + std::sort(_timeStamps.begin(), _timeStamps.end(), cmp); + + std::ofstream cachedFileStream(cachedFile); + cachedFileStream << std::setprecision(64); + if (cachedFileStream.good()) { + for (const ImageParams& i : _timeStamps) + cachedFileStream << i.startTime << "\t" << i.stopTime << "\t" << i.path << std::endl; + } + + } + } + + + if (extension == "txt"){// Hong Kang. pre-parsed playbook + std::cout << "USING PREPARSED PLAYBOOK V9H" << std::endl; + std::ifstream file(fileName); + if (!file.good()) LERROR("Failed to open txt file '" << fileName << "'"); + + std::string timestr = ""; + double shutter = 0.01; + double et; + + double metRef = 299180517; + do{ + std::getline(file, timestr); + auto pos = timestr.find("LORRI Image Started"); + if (pos != std::string::npos){ + timestr = timestr.substr(24, 9); + std::string::size_type sz; // alias of size_t + + double met = std::stod(timestr, &sz); + double diff; + openspace::SpiceManager::ref().getETfromDate("2015-07-14T11:50:00.00", et); + + diff = abs(met - metRef); + if (met > metRef){ + et += diff; + } + else if (met < metRef){ + et -= diff; + } + /* + std::string str; + openspace::SpiceManager::ref().getDateFromET(et, str); + std::cout << str << std::endl; + */ + createImage(et, et + shutter, _defaultCaptureImage); + } + } while (!file.eof()); + std::sort(_timeStamps.begin(), _timeStamps.end(), cmp); + } + + } + } + return true; +} + bool ImageSequencer::loadSequence(const std::string dir){ ghoul::filesystem::Directory sequenceDir(dir, true); std::vector sequencePaths = sequenceDir.read(true, false); // check inputs @@ -269,6 +322,7 @@ bool ImageSequencer::loadSequence(const std::string dir){ std::vector::const_iterator it = std::find(sequencePaths.begin(), sequencePaths.end(), path); if ( it != sequencePaths.end()){ createImage(timestamps[0], timestamps[1], path); + std::sort(_timeStamps.begin(), _timeStamps.end(), cmp); } std::string timestr; openspace::SpiceManager::ref().getDateFromET(timestamps[0], timestr);