Feature/filesystem cleanup (#1587)

* Adapting to the changes in Ghoul
* First step of moving filesystem functions to std
* Remove persistence flag from cachemanager
This commit is contained in:
Alexander Bock
2021-05-16 20:26:49 +02:00
committed by GitHub
parent 2ca7101b6c
commit ccdc5a5dc3
87 changed files with 648 additions and 711 deletions

View File

@@ -463,10 +463,10 @@ RenderableGaiaStars::RenderableGaiaStars(const ghoul::Dictionary& dictionary)
const Parameters p = codegen::bake<Parameters>(dictionary);
_filePath = absPath(p.file);
_dataFile = std::make_unique<File>(_filePath);
_dataFile->setCallback([&](const File&) { _dataIsDirty = true; });
_dataFile = std::make_unique<File>(_filePath.value());
_dataFile->setCallback([this]() { _dataIsDirty = true; });
_filePath.onChange([&]() { _dataIsDirty = true; });
_filePath.onChange([this]() { _dataIsDirty = true; });
addProperty(_filePath);
_fileReaderOption.addOptions({
@@ -569,17 +569,19 @@ RenderableGaiaStars::RenderableGaiaStars(const ghoul::Dictionary& dictionary)
_pointSpreadFunctionTexturePath = absPath(p.texture);
_pointSpreadFunctionTexturePath.onChange(
[&](){ _pointSpreadFunctionTextureIsDirty = true; }
[this](){ _pointSpreadFunctionTextureIsDirty = true; }
);
_pointSpreadFunctionFile = std::make_unique<File>(
_pointSpreadFunctionTexturePath.value()
);
_pointSpreadFunctionFile = std::make_unique<File>(_pointSpreadFunctionTexturePath);
_pointSpreadFunctionFile->setCallback(
[&](const File&) { _pointSpreadFunctionTextureIsDirty = true; }
[this]() { _pointSpreadFunctionTextureIsDirty = true; }
);
_colorTexturePath = absPath(p.colorMap);
_colorTextureFile = std::make_unique<File>(_colorTexturePath);
_colorTexturePath.onChange([&]() { _colorTextureIsDirty = true; });
_colorTextureFile->setCallback([&](const File&) { _colorTextureIsDirty = true; });
_colorTextureFile = std::make_unique<File>(_colorTexturePath.value());
_colorTexturePath.onChange([this]() { _colorTextureIsDirty = true; });
_colorTextureFile->setCallback([this]() { _colorTextureIsDirty = true; });
_luminosityMultiplier = p.luminosityMultiplier.value_or(_luminosityMultiplier);
_magnitudeBoost = p.magnitudeBoost.value_or(_magnitudeBoost);
@@ -2115,12 +2117,10 @@ void RenderableGaiaStars::update(const UpdateData&) {
);
_pointSpreadFunctionFile = std::make_unique<ghoul::filesystem::File>(
_pointSpreadFunctionTexturePath
_pointSpreadFunctionTexturePath.value()
);
_pointSpreadFunctionFile->setCallback(
[&](const ghoul::filesystem::File&) {
_pointSpreadFunctionTextureIsDirty = true;
}
[this]() { _pointSpreadFunctionTextureIsDirty = true; }
);
}
_pointSpreadFunctionTextureIsDirty = false;
@@ -2141,11 +2141,9 @@ void RenderableGaiaStars::update(const UpdateData&) {
}
_colorTextureFile = std::make_unique<ghoul::filesystem::File>(
_colorTexturePath
);
_colorTextureFile->setCallback(
[&](const ghoul::filesystem::File&) { _colorTextureIsDirty = true; }
_colorTexturePath.value()
);
_colorTextureFile->setCallback([this]() { _colorTextureIsDirty = true; });
}
_colorTextureIsDirty = false;
}

View File

@@ -28,9 +28,9 @@
#include <openspace/documentation/verifier.h>
#include <ghoul/fmt.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/directory.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/dictionary.h>
#include <filesystem>
#include <fstream>
#include <thread>
@@ -452,8 +452,16 @@ void ConstructOctreeTask::constructOctreeFromFolder(
//int starsOutside2000 = 0;
//int starsOutside5000 = 0;
ghoul::filesystem::Directory currentDir(_inFileOrFolderPath);
std::vector<std::string> allInputFiles = currentDir.readFiles();
std::vector<std::filesystem::path> allInputFiles;
if (std::filesystem::is_directory(_inFileOrFolderPath)) {
namespace fs = std::filesystem;
for (const fs::directory_entry& e : fs::directory_iterator(_inFileOrFolderPath)) {
if (!e.is_regular_file()) {
allInputFiles.push_back(e.path());
}
}
}
std::vector<float> filterValues;
auto writeThreads = std::vector<std::thread>(8);
@@ -467,10 +475,10 @@ void ConstructOctreeTask::constructOctreeFromFolder(
));
for (size_t idx = 0; idx < allInputFiles.size(); ++idx) {
std::string inFilePath = allInputFiles[idx];
std::filesystem::path inFilePath = allInputFiles[idx];
int nStarsInfile = 0;
LINFO("Reading data file: " + inFilePath);
LINFO(fmt::format("Reading data file: {}", inFilePath));
std::ifstream inFileStream(inFilePath, std::ifstream::binary);
if (inFileStream.good()) {
@@ -528,7 +536,7 @@ void ConstructOctreeTask::constructOctreeFromFolder(
}
else {
LERROR(fmt::format(
"Error opening file '{}' for loading preprocessed file!", inFilePath
"Error opening file {} for loading preprocessed file!", inFilePath
));
}

View File

@@ -30,10 +30,9 @@
#include <ghoul/misc/dictionary.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/directory.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/fmt.h>
#include <filesystem>
#include <fstream>
#include <set>
#include <optional>
@@ -185,8 +184,16 @@ void ReadFitsTask::readAllFitsFilesFromFolder(const Task::ProgressCallback&) {
ConcurrentJobManager<std::vector<std::vector<float>>> jobManager(threadPool);
// Get all files in specified folder.
ghoul::filesystem::Directory currentDir(_inFileOrFolderPath);
std::vector<std::string> allInputFiles = currentDir.readFiles();
std::vector<std::filesystem::path> allInputFiles;
if (std::filesystem::is_directory(_inFileOrFolderPath)) {
namespace fs = std::filesystem;
for (const fs::directory_entry& e : fs::directory_iterator(_inFileOrFolderPath)) {
if (e.is_regular_file()) {
allInputFiles.push_back(e.path());
}
}
}
size_t nInputFiles = allInputFiles.size();
LINFO("Files to read: " + std::to_string(nInputFiles));
@@ -238,12 +245,12 @@ void ReadFitsTask::readAllFitsFilesFromFolder(const Task::ProgressCallback&) {
// Divide all files into ReadFilejobs and then delegate them onto several threads!
while (!allInputFiles.empty()) {
std::string fileToRead = allInputFiles.back();
std::filesystem::path fileToRead = allInputFiles.back();
allInputFiles.erase(allInputFiles.end() - 1);
// Add reading of file to jobmanager, which will distribute it to our threadpool.
auto readFileJob = std::make_shared<gaia::ReadFileJob>(
fileToRead,
fileToRead.string(),
_allColumnNames,
_firstRow,
_lastRow,