mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-28 07:59:37 -06:00
Cleanup of ImageSequencer
Added caching to playbook loading Increased performance of playbook loading Added default placeholder image
This commit is contained in:
@@ -88,7 +88,7 @@ private:
|
||||
glm::mat4 _projectorMatrix;
|
||||
|
||||
// spice
|
||||
std::string _sequenceDir;
|
||||
std::string _sequenceFile;
|
||||
std::string _instrumentID;
|
||||
std::string _projectorID;
|
||||
std::string _projecteeID;
|
||||
|
||||
@@ -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
|
||||
|
||||
Submodule openspace-data updated: d8bc6ea847...c7ab5a3f7d
@@ -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();
|
||||
|
||||
@@ -138,16 +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");
|
||||
|
||||
}
|
||||
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(){
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/filesystem/directory.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <ghoul/filesystem/cachemanager.h>
|
||||
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <fstream>
|
||||
@@ -61,7 +62,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 +82,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;
|
||||
}
|
||||
@@ -160,80 +164,123 @@ 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<std::string> dirlist = playbookDir.read(true, false);
|
||||
for (auto path : dirlist){
|
||||
if (size_t position = path.find_last_of(".") + 1){
|
||||
if (position != std::string::npos){
|
||||
ghoul::filesystem::File currentFile(path);
|
||||
std::string extension = currentFile.fileExtension();
|
||||
for (auto path : dirlist) {
|
||||
bool success = parsePlaybookFile(path, year);
|
||||
if (!success)
|
||||
return false;
|
||||
}
|
||||
return true; // add check
|
||||
}
|
||||
|
||||
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() << "'");
|
||||
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();
|
||||
|
||||
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(","));
|
||||
if (extension == "csv"){ // comma separated playbook
|
||||
std::cout << "USING COMMA SEPARATED TIMELINE V9F" << std::endl;
|
||||
|
||||
replace(timestr, " ", "::");
|
||||
timestr = year + " " + timestr;
|
||||
|
||||
openspace::SpiceManager::ref().getETfromDate(timestr, et);
|
||||
std::string defaultImagePath = dir + "/placeholder.png";
|
||||
createImage(et, et + shutter, defaultImagePath);
|
||||
}
|
||||
} while (!file.eof());
|
||||
}
|
||||
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 == 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() << "'");
|
||||
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;
|
||||
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 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);
|
||||
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;
|
||||
*/
|
||||
std::string defaultImagePath = dir + "/placeholder.png";
|
||||
createImage(et, et + shutter, defaultImagePath);
|
||||
diff = abs(met - metRef);
|
||||
if (met > metRef){
|
||||
et += diff;
|
||||
}
|
||||
} while (!file.eof());
|
||||
}
|
||||
|
||||
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; // add check
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImageSequencer::loadSequence(const std::string dir){
|
||||
@@ -272,6 +319,7 @@ bool ImageSequencer::loadSequence(const std::string dir){
|
||||
std::vector<std::string>::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);
|
||||
|
||||
Reference in New Issue
Block a user