mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-08 12:39:49 -06:00
Fieldlines are now created with seedpoints from mod-file. Stepsize can be specified in mod-file aswell
This commit is contained in:
@@ -54,17 +54,14 @@ public:
|
||||
float* getUniformSampledVectorValues(const std::string& xVar, const std::string& yVar,
|
||||
const std::string& zVar, glm::size3_t outDimensions);
|
||||
|
||||
float* getVolumeFieldLines(const std::string& xVar, const std::string& yVar,
|
||||
const std::string& zVar, glm::size3_t outDimensions, std::vector<glm::vec3> seedPoints);
|
||||
|
||||
std::vector<std::vector<glm::vec3> > getFieldLines(const std::string& xVar,
|
||||
const std::string& yVar, const std::string& zVar,
|
||||
std::vector<glm::vec3> seedPoints);
|
||||
std::vector<glm::vec3> seedPoints, float stepSize);
|
||||
|
||||
private:
|
||||
std::vector<glm::vec3> traceCartesianFieldline(const std::string& xVar,
|
||||
const std::string& yVar, const std::string& zVar,
|
||||
glm::vec3 seedPoint, TraceDirection direction);
|
||||
const std::string& yVar, const std::string& zVar, glm::vec3 seedPoint,
|
||||
float stepSize, TraceDirection direction);
|
||||
|
||||
void getGridVariables(std::string& x, std::string& y, std::string& z);
|
||||
void progressBar(int current, int end);
|
||||
|
||||
Submodule openspace-data updated: 3b9a6e638b...a0e8d47b2d
@@ -118,20 +118,22 @@ bool RenderableFieldlines::initialize() {
|
||||
assert(_hintsDictionary.size() != 0);
|
||||
assert(_seedPoints.size() != 0);
|
||||
|
||||
// std::vector<glm::vec3> seedPoints;
|
||||
// for (int x = -6; x <= 6; x+=3) {
|
||||
// for (int y = -6; y <= 6; y+=3) {
|
||||
// for (int z = -6; z <= 6; z+=3) {
|
||||
// seedPoints.push_back(glm::vec3((float)x, (float)y, (float)z));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
std::vector<glm::vec3> seedPoints;
|
||||
for (int x = -6; x <= 6; x+=3) {
|
||||
for (int y = -6; y <= 6; y+=3) {
|
||||
for (int z = -6; z <= 6; z+=3) {
|
||||
seedPoints.push_back(glm::vec3((float)x, (float)y, (float)z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string modelString;
|
||||
std::vector<std::vector<glm::vec3> > fieldlinesData;
|
||||
float stepSize;
|
||||
std::string xVariable, yVariable, zVariable;
|
||||
KameleonWrapper::Model model;
|
||||
|
||||
if (_hintsDictionary.hasKey("Model") && _hintsDictionary.getValue("Model", modelString)) {
|
||||
KameleonWrapper::Model model;
|
||||
if (modelString == "BATSRUS") {
|
||||
model = KameleonWrapper::Model::BATSRUS;
|
||||
} else if (modelString == "ENLIL") {
|
||||
@@ -142,18 +144,13 @@ bool RenderableFieldlines::initialize() {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string xVariable, yVariable, zVariable;
|
||||
if (_hintsDictionary.hasKey("Variables")) {
|
||||
bool xVar, yVar, zVar;
|
||||
xVar = _hintsDictionary.getValue("Variables.1", xVariable);
|
||||
yVar = _hintsDictionary.getValue("Variables.2", yVariable);
|
||||
zVar = _hintsDictionary.getValue("Variables.3", zVariable);
|
||||
|
||||
if (xVar || yVar || zVar) {
|
||||
KameleonWrapper kw(_filename, model);
|
||||
fieldlinesData = kw.getFieldLines(xVariable, yVariable, zVariable, _seedPoints);
|
||||
|
||||
} else {
|
||||
if (!xVar || !yVar || !zVar) {
|
||||
LWARNING("Error reading variables! Must be 3 and must exist in CDF data");
|
||||
return false;
|
||||
}
|
||||
@@ -161,8 +158,16 @@ bool RenderableFieldlines::initialize() {
|
||||
LWARNING("Hints does not specify valid 'Variables'");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_hintsDictionary.hasKey("Stepsize") || !_hintsDictionary.getValue("Stepsize", stepSize)) {
|
||||
LDEBUG("No stepsize set for fieldlines. Setting to default value (0.5)");
|
||||
stepSize = 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
KameleonWrapper kw(_filename, model);
|
||||
fieldlinesData = kw.getFieldLines(xVariable, yVariable, zVariable, _seedPoints, stepSize);
|
||||
|
||||
std::vector<glm::vec3> vertexData;
|
||||
int prevEnd = 0;
|
||||
|
||||
@@ -215,6 +220,7 @@ void RenderableFieldlines::render(const Camera* camera, const psc& thisPosition)
|
||||
|
||||
transform = transform*camTransform;
|
||||
transform = glm::translate(transform, relative.vec3());
|
||||
transform = glm::rotate(transform, 90.0f, glm::vec3(1.0, 0.0, 0.0));
|
||||
transform = glm::scale(transform, glm::vec3(0.1));
|
||||
|
||||
_shaderMutex->lock();
|
||||
|
||||
@@ -136,27 +136,8 @@ ghoul::opengl::Texture* RenderableVolume::loadVolume(const std::string& filepath
|
||||
if (!xVar || !yVar || !zVar) {
|
||||
LERROR("Error reading variables! Must be 3 and must exist in CDF data");
|
||||
} else {
|
||||
|
||||
// Seed 'em all
|
||||
std::vector<glm::vec3> seedPoints;
|
||||
// seedPoints.push_back(glm::vec3(5.0, 0.0, 0.0));
|
||||
for (int z = -5; z <= 5; z+=5) {
|
||||
for (int y = -5; y <= 5; y+=5)
|
||||
seedPoints.push_back(glm::vec3(5.0, (float)y, (float)z));
|
||||
}
|
||||
|
||||
float* fieldlinesData = kw.getVolumeFieldLines(xVariable, yVariable, zVariable, dimensions, seedPoints);
|
||||
// float* rhoData = kw.getUniformSampledValues("rho", dimensions);
|
||||
//
|
||||
// // Combine fieldlines with rhoData, clamp to [0,1]
|
||||
// float* data = new float[dimensions.x*dimensions.y*dimensions.z];
|
||||
// for (int i = 0; i < dimensions.x*dimensions.y*dimensions.z; ++i)
|
||||
// data[i] = std::min(fieldlinesData[i]+rhoData[i], 1.0f);
|
||||
//
|
||||
// delete fieldlinesData;
|
||||
// delete rhoData;
|
||||
|
||||
return new ghoul::opengl::Texture(fieldlinesData, dimensions, ghoul::opengl::Texture::Format::Red, GL_RED, GL_FLOAT);
|
||||
float* data = kw.getUniformSampledVectorValues(xVariable, yVariable, zVariable, dimensions);
|
||||
return new ghoul::opengl::Texture(data, dimensions, ghoul::opengl::Texture::Format::RGBA, GL_RGBA, GL_FLOAT);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
@@ -237,48 +237,10 @@ float* KameleonWrapper::getUniformSampledVectorValues(const std::string& xVar, c
|
||||
return data;
|
||||
}
|
||||
|
||||
float* KameleonWrapper::getVolumeFieldLines(const std::string& xVar,
|
||||
const std::string& yVar, const std::string& zVar,
|
||||
glm::size3_t outDimensions, std::vector<glm::vec3> seedPoints) {
|
||||
assert(_model && _interpolator);
|
||||
assert(outDimensions.x > 0 && outDimensions.y > 0 && outDimensions.z > 0);
|
||||
assert(_type == Model::ENLIL || _type == Model::BATSRUS);
|
||||
LINFO("Creating " << seedPoints.size() << " fieldlines from variables " << xVar << " " << yVar << " " << zVar);
|
||||
|
||||
int size = outDimensions.x*outDimensions.y*outDimensions.z;
|
||||
float* data = new float[size];
|
||||
std::vector<glm::vec3> line;
|
||||
|
||||
if (_type == Model::BATSRUS) {
|
||||
for (glm::vec3 seedPoint : seedPoints) {
|
||||
line = traceCartesianFieldline(xVar, yVar, zVar, seedPoint, TraceDirection::FORWARD);
|
||||
for (glm::vec3 point : line) {
|
||||
int vPosX = std::floor(outDimensions.x*(point.x-_xMin)/(_xMax-_xMin));
|
||||
int vPosY = std::floor(outDimensions.y*(point.y-_yMin)/(_yMax-_yMin));
|
||||
int vPosZ = std::floor(outDimensions.z*(point.z-_zMin)/(_zMax-_zMin));
|
||||
int index = vPosX + vPosY*outDimensions.x + vPosZ*outDimensions.x*outDimensions.y;
|
||||
data[index] = 1.0;
|
||||
}
|
||||
|
||||
line = traceCartesianFieldline(xVar, yVar, zVar, seedPoint, TraceDirection::BACK);
|
||||
for (glm::vec3 point : line) {
|
||||
int vPosX = std::floor(outDimensions.x*(point.x-_xMin)/(_xMax-_xMin));
|
||||
int vPosY = std::floor(outDimensions.y*(point.y-_yMin)/(_yMax-_yMin));
|
||||
int vPosZ = std::floor(outDimensions.z*(point.z-_zMin)/(_zMax-_zMin));
|
||||
int index = vPosX + vPosY*outDimensions.x + vPosZ*outDimensions.x*outDimensions.y;
|
||||
data[index] = 1.0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LERROR("Fieldlines are only supported for BATSRUS model");
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<std::vector<glm::vec3> > KameleonWrapper::getFieldLines(
|
||||
const std::string& xVar, const std::string& yVar,
|
||||
const std::string& zVar, std::vector<glm::vec3> seedPoints) {
|
||||
const std::string& zVar, std::vector<glm::vec3> seedPoints,
|
||||
float stepSize ) {
|
||||
assert(_model && _interpolator);
|
||||
assert(_type == Model::ENLIL || _type == Model::BATSRUS);
|
||||
LINFO("Creating " << seedPoints.size() << " fieldlines from variables " << xVar << " " << yVar << " " << zVar);
|
||||
@@ -288,8 +250,8 @@ std::vector<std::vector<glm::vec3> > KameleonWrapper::getFieldLines(
|
||||
|
||||
if (_type == Model::BATSRUS) {
|
||||
for (glm::vec3 seedPoint : seedPoints) {
|
||||
fLine = traceCartesianFieldline(xVar, yVar, zVar, seedPoint, TraceDirection::FORWARD);
|
||||
bLine = traceCartesianFieldline(xVar, yVar, zVar, seedPoint, TraceDirection::BACK);
|
||||
fLine = traceCartesianFieldline(xVar, yVar, zVar, seedPoint, stepSize, TraceDirection::FORWARD);
|
||||
bLine = traceCartesianFieldline(xVar, yVar, zVar, seedPoint, stepSize, TraceDirection::BACK);
|
||||
bLine.insert(bLine.begin(), fLine.rbegin(), fLine.rend());
|
||||
fieldLines.push_back(bLine);
|
||||
}
|
||||
@@ -302,15 +264,16 @@ std::vector<std::vector<glm::vec3> > KameleonWrapper::getFieldLines(
|
||||
|
||||
std::vector<glm::vec3> KameleonWrapper::traceCartesianFieldline(
|
||||
const std::string& xVar, const std::string& yVar,
|
||||
const std::string& zVar, glm::vec3 seedPoint, TraceDirection direction) {
|
||||
const std::string& zVar, glm::vec3 seedPoint,
|
||||
float stepSize, TraceDirection direction) {
|
||||
|
||||
glm::vec3 pos, k1, k2, k3, k4;
|
||||
std::vector<glm::vec3> line;
|
||||
|
||||
float stepX = 0.5, stepY = 0.5, stepZ = 0.5;
|
||||
float stepX = stepSize, stepY = stepSize, stepZ = stepSize; // Should I do different stepsizes?
|
||||
|
||||
int numSteps = 0;
|
||||
int maxSteps = 1000;
|
||||
int maxSteps = 5000;
|
||||
pos = seedPoint;
|
||||
|
||||
// While we are inside the models boundries and not inside earth
|
||||
|
||||
Reference in New Issue
Block a user