mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-29 15:29:26 -05:00
Add member variables and function to read osfls files to FieldlinesState
This commit is contained in:
@@ -24,8 +24,88 @@
|
||||
|
||||
#include <modules/fieldlinessequence/util/fieldlinesstate.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
FieldlinesState::FieldlinesState() {}
|
||||
FieldlinesState::FieldlinesState(const std::string& PATH_TO_OSFLS_FILE, bool& loadSucessful) {
|
||||
loadSucessful = loadStateFromOsfls(PATH_TO_OSFLS_FILE);
|
||||
}
|
||||
|
||||
bool FieldlinesState::loadStateFromOsfls(const std::string& PATH_TO_OSFLS_FILE) {
|
||||
std::ifstream ifs(PATH_TO_OSFLS_FILE, std::ifstream::binary);
|
||||
if (!ifs.is_open()) {
|
||||
LERRORC("FieldlinesState", "Couldn't open file: " + PATH_TO_OSFLS_FILE);
|
||||
return false;
|
||||
}
|
||||
|
||||
int binFileVersion;
|
||||
ifs.read( reinterpret_cast<char*>(&binFileVersion), sizeof(int));
|
||||
|
||||
switch (binFileVersion) {
|
||||
case 0 : {
|
||||
// No need to put everything in this scope now, as only version 0 exists!
|
||||
}
|
||||
break;
|
||||
default :
|
||||
LERRORC("FieldlinesState","VERSION OF BINARY FILE WAS NOT RECOGNISED!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Define tmp variables to store meta data in
|
||||
size_t numLines;
|
||||
size_t numPoints;
|
||||
size_t numExtras;
|
||||
size_t byteSizeAllNames;
|
||||
|
||||
// Read single value variables
|
||||
ifs.read( reinterpret_cast<char*>(&_triggerTime), sizeof(double));
|
||||
ifs.read( reinterpret_cast<char*>(&_model), sizeof(int));
|
||||
ifs.read( reinterpret_cast<char*>(&_isMorphable), sizeof(bool));
|
||||
ifs.read( reinterpret_cast<char*>(&numLines), sizeof(size_t));
|
||||
ifs.read( reinterpret_cast<char*>(&numPoints), sizeof(size_t));
|
||||
ifs.read( reinterpret_cast<char*>(&numExtras), sizeof(size_t));
|
||||
ifs.read( reinterpret_cast<char*>(&byteSizeAllNames), sizeof(size_t));
|
||||
|
||||
// RESERVE/RESIZE vectors
|
||||
// TODO: Do this without initializing values? Resize is slower than just using reserve, due to initialization of all values
|
||||
_lineStart.resize(numLines);
|
||||
_lineCount.resize(numLines);
|
||||
_vertexPositions.resize(numPoints);
|
||||
_extraVariables.resize(numExtras);
|
||||
_extraVariableNames.reserve(numExtras);
|
||||
|
||||
// Read vertex position data
|
||||
ifs.read( reinterpret_cast<char*>(_lineStart.data()), sizeof(GLint)*numLines);
|
||||
ifs.read( reinterpret_cast<char*>(_lineCount.data()), sizeof(GLsizei)*numLines);
|
||||
ifs.read( reinterpret_cast<char*>(_vertexPositions.data()), sizeof(glm::vec3)*numPoints);
|
||||
|
||||
// Read all extra variables
|
||||
for (std::vector<float>& vec : _extraVariables) {
|
||||
vec.resize(numPoints);
|
||||
ifs.read( reinterpret_cast<char*>(vec.data()), sizeof(float) * numPoints);
|
||||
}
|
||||
|
||||
// Read all extra variables' names. Stored as multiple c-strings
|
||||
std::string allNamesInOne;
|
||||
char* s = new char[byteSizeAllNames];
|
||||
ifs.read(s, byteSizeAllNames);
|
||||
allNamesInOne.assign(s, byteSizeAllNames);
|
||||
delete[] s;
|
||||
|
||||
size_t offset = 0;
|
||||
for (size_t i = 0; i < numExtras; ++i) {
|
||||
auto endOfVarName = allNamesInOne.find('\0', offset);
|
||||
endOfVarName -= offset;
|
||||
std::string varName = allNamesInOne.substr(offset, endOfVarName);
|
||||
offset += varName.size() + 1;
|
||||
_extraVariableNames.push_back(varName);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -25,12 +25,45 @@
|
||||
#ifndef __OPENSPACE_MODULE_FIELDLINESSEQUENCE___FIELDLINESSTATE___H__
|
||||
#define __OPENSPACE_MODULE_FIELDLINESSEQUENCE___FIELDLINESSTATE___H__
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class FieldlinesState {
|
||||
public:
|
||||
enum Model : int {
|
||||
batsrus = 0,
|
||||
enlil = 1,
|
||||
pfss = 2
|
||||
};
|
||||
|
||||
FieldlinesState();
|
||||
FieldlinesState(const std::string& PATH_TO_OSFLS_FILE, bool& loadSucessful);
|
||||
|
||||
bool loadStateFromOsfls(const std::string& PATH_TO_OSFLS_FILE);
|
||||
|
||||
// Getters
|
||||
double triggerTime() { return _triggerTime; }
|
||||
Model model() { return _model; }
|
||||
const std::vector<glm::vec3>& vertexPositions() { return _vertexPositions; }
|
||||
const std::vector<GLint>& lineStart() { return _lineStart; }
|
||||
const std::vector<GLsizei>& lineCount() { return _lineCount; }
|
||||
|
||||
private:
|
||||
bool _isMorphable = false;
|
||||
double _triggerTime = -1.0;
|
||||
Model _model;
|
||||
|
||||
std::vector<glm::vec3> _vertexPositions;
|
||||
std::vector<GLint> _lineStart;
|
||||
std::vector<GLsizei> _lineCount;
|
||||
std::vector<std::vector<float>> _extraVariables;
|
||||
std::vector<std::string> _extraVariableNames;
|
||||
// TODO: Maybe introduce a vector containing seed point indices
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user