mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-06 19:49:36 -06:00
reader wip
This commit is contained in:
@@ -234,34 +234,60 @@ void RenderableTimeVaryingVolume::initializeGL() {
|
||||
}
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
double timestep = 0.0;
|
||||
for (const fs::directory_entry& e : fs::recursive_directory_iterator(sequenceDir)) {
|
||||
if (e.is_regular_file() && e.path().extension() == ".dictionary") {
|
||||
loadTimestepMetadata(e.path());
|
||||
}
|
||||
if (e.is_regular_file() && e.path().extension() == ".vti") {
|
||||
readVTIFile(e.path());
|
||||
const auto [metadata, scalars] = readVTIFile(e.path(), timestep++);
|
||||
|
||||
Timestep t;
|
||||
t.metadata = metadata;
|
||||
t.baseName = "";
|
||||
t.inRam = false;
|
||||
t.onGpu = false;
|
||||
t.rawData = scalars;
|
||||
|
||||
_volumeTimesteps[t.metadata.time] = std::move(t);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: defer loading of data to later (separate thread or at least not when loading)
|
||||
for (std::pair<const double, Timestep>& p : _volumeTimesteps) {
|
||||
Timestep& t = p.second;
|
||||
const std::string path = std::format(
|
||||
"{}/{}.rawvolume", _sourceDirectory.value(), t.baseName
|
||||
);
|
||||
RawVolumeReader<float> reader(path, t.metadata.dimensions);
|
||||
t.rawVolume = reader.read(_invertDataAtZ);
|
||||
|
||||
// Read volume from file if it exists
|
||||
if (t.baseName != "") {
|
||||
const std::string path = std::format(
|
||||
"{}/{}.rawvolume", _sourceDirectory.value(), t.baseName
|
||||
);
|
||||
RawVolumeReader<float> reader(path, t.metadata.dimensions);
|
||||
t.rawVolume = reader.read(_invertDataAtZ);
|
||||
}
|
||||
|
||||
const float min = t.metadata.minValue;
|
||||
const float diff = t.metadata.maxValue - t.metadata.minValue;
|
||||
float* data = t.rawVolume->data();
|
||||
for (size_t i = 0; i < t.rawVolume->nCells(); i++) {
|
||||
data[i] = glm::clamp((data[i] - min) / diff, 0.f, 1.f);
|
||||
}
|
||||
|
||||
t.histogram = std::make_shared<Histogram>(0.f, 1.f, 100);
|
||||
for (size_t i = 0; i < t.rawVolume->nCells(); i++) {
|
||||
t.histogram->add(data[i]);
|
||||
float* data;
|
||||
// We've read data from binary file
|
||||
if (t.rawVolume) {
|
||||
data = t.rawVolume->data();
|
||||
for (size_t i = 0; i < t.rawVolume->nCells(); i++) {
|
||||
data[i] = glm::clamp((data[i] - min) / diff, 0.f, 1.f);
|
||||
}
|
||||
|
||||
t.histogram = std::make_shared<Histogram>(0.f, 1.f, 100);
|
||||
for (size_t i = 0; i < t.rawVolume->nCells(); i++) {
|
||||
t.histogram->add(data[i]);
|
||||
}
|
||||
}
|
||||
// Data came from xml file
|
||||
else {
|
||||
data = t.rawData.data();
|
||||
for (size_t i = 0; i < t.rawData.size(); i++) {
|
||||
data[i] = glm::clamp((data[i] - min) / diff, 0.f, 1.f);
|
||||
}
|
||||
}
|
||||
// TODO: handle normalization properly for different timesteps + transfer function
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ private:
|
||||
std::shared_ptr<RawVolume<float>> rawVolume;
|
||||
std::shared_ptr<ghoul::opengl::Texture> texture;
|
||||
std::shared_ptr<Histogram> histogram;
|
||||
std::vector<float> rawData;
|
||||
};
|
||||
|
||||
Timestep* currentTimestep();
|
||||
|
||||
@@ -23,12 +23,12 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/volume/xmlreader.h>
|
||||
#include <fstream>
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <ghoul/misc/stringhelper.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <tinyxml2.h>
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ std::string getAttribute(const std::string& line, const std::string& attribute)
|
||||
|
||||
}
|
||||
|
||||
void readVTIFile(const std::filesystem::path& path) {
|
||||
std::pair<volume::RawVolumeMetadata, std::vector<float>> readVTIFile(const std::filesystem::path& path, double timestep) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
|
||||
if (doc.LoadFile(path.string().c_str()) != tinyxml2::XML_SUCCESS) {
|
||||
@@ -86,49 +86,32 @@ void readVTIFile(const std::filesystem::path& path) {
|
||||
ss.clear();
|
||||
|
||||
float value;
|
||||
float minValue = std::numeric_limits<float>::max();
|
||||
float maxValue = std::numeric_limits<float>::lowest();
|
||||
|
||||
while (ss >> value) {
|
||||
scalars.push_back(value);
|
||||
minValue = std::min(minValue, value);
|
||||
maxValue = std::max(maxValue, value);
|
||||
}
|
||||
|
||||
std::cout << scalars.size();
|
||||
|
||||
volume::RawVolumeMetadata metadata;
|
||||
|
||||
//std::ifstream file;
|
||||
//file.open(path);
|
||||
//ghoul_assert(file.good(), "File handle should be good");
|
||||
metadata.dimensions = extents;
|
||||
|
||||
//std::stringstream ss;
|
||||
//std::string line;
|
||||
//while (ghoul::getline(file, line)) {
|
||||
// std::cout << line << std::endl;
|
||||
metadata.hasDomainBounds = true;
|
||||
metadata.lowerDomainBound = minExtent;
|
||||
metadata.upperDomainBound = maxExtent;
|
||||
|
||||
// if (line.find("<ImageData") != std::string::npos) {
|
||||
// const std::string wholeExtent = getAttribute(line, "WholeExtent");
|
||||
// const std::string origin = getAttribute(line, "Origin");
|
||||
// const std::string spacing = getAttribute(line, "Spacing");
|
||||
metadata.hasValueRange = true;
|
||||
metadata.minValue = minValue;
|
||||
metadata.maxValue = maxValue;
|
||||
|
||||
// std::cout << "Whole extent '" << wholeExtent << "'\n"
|
||||
// << "origin '" << origin << "'\n"
|
||||
// << "spacing '" << spacing << "'\n";
|
||||
// }
|
||||
// else if (line.find("<Piece") != std::string::npos) {
|
||||
// const std::string extent = getAttribute(line, "Extent");
|
||||
// std::cout << "Extent: " << extent << std::endl;
|
||||
// }
|
||||
metadata.hasTime = true;
|
||||
metadata.time = timestep;
|
||||
|
||||
// else if (line.find("<DataArray") != std::string::npos) {
|
||||
// ghoul::getline(file, line);
|
||||
// ss << line << " ";
|
||||
// }
|
||||
//}
|
||||
|
||||
//float value = 0.f;
|
||||
//std::vector<float> dataValues;
|
||||
//while (ss >> value) {
|
||||
// dataValues.push_back(value);
|
||||
//}
|
||||
|
||||
//file.close();
|
||||
return std::make_pair(metadata, scalars);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -23,9 +23,11 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <modules/volume/rawvolumemetadata.h>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
void readVTIFile(const std::filesystem::path& path);
|
||||
std::pair<volume::RawVolumeMetadata, std::vector<float>> readVTIFile(const std::filesystem::path& path, double timestep);
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user