mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
Added classification of fieldlines (closed, open from north, open from south, solar wind) and coloring after classification
This commit is contained in:
@@ -56,16 +56,16 @@ private:
|
||||
std::string _filename;
|
||||
std::vector<glm::vec3> _seedPoints;
|
||||
|
||||
ghoul::opengl::ProgramObject* _fieldlinesProgram;
|
||||
GLuint _VAO;
|
||||
ghoul::opengl::ProgramObject *_fieldlinesProgram, *_seedpointsProgram;
|
||||
GLuint _VAO, _seedpointVAO;
|
||||
|
||||
std::mutex* _shaderMutex;
|
||||
|
||||
ghoul::filesystem::File* _vertexSourceFile;
|
||||
ghoul::filesystem::File* _fragmentSourceFile;
|
||||
|
||||
std::vector<GLint> _lineStart;
|
||||
std::vector<GLsizei> _lineCount;
|
||||
std::vector<GLint> _lineStart, _seedpointStart;
|
||||
std::vector<GLsizei> _lineCount, _seedpointCount;
|
||||
|
||||
bool _programUpdateOnSave;
|
||||
void safeShaderCompilation();
|
||||
|
||||
@@ -48,6 +48,12 @@ public:
|
||||
BACK = -1
|
||||
};
|
||||
|
||||
enum FieldlineEnd {
|
||||
NORTH,
|
||||
SOUTH,
|
||||
OUT
|
||||
};
|
||||
|
||||
KameleonWrapper(const std::string& filename, Model model);
|
||||
~KameleonWrapper();
|
||||
float* getUniformSampledValues(const std::string& var, glm::size3_t outDimensions);
|
||||
@@ -61,10 +67,11 @@ public:
|
||||
private:
|
||||
std::vector<glm::vec3> traceCartesianFieldline(const std::string& xVar,
|
||||
const std::string& yVar, const std::string& zVar, glm::vec3 seedPoint,
|
||||
float stepSize, TraceDirection direction);
|
||||
float stepSize, TraceDirection direction, FieldlineEnd& end);
|
||||
|
||||
void getGridVariables(std::string& x, std::string& y, std::string& z);
|
||||
void progressBar(int current, int end);
|
||||
glm::vec3 classifyFieldline(FieldlineEnd fEnd, FieldlineEnd bEnd);
|
||||
|
||||
ccmc::Model* _model;
|
||||
Model _type;
|
||||
|
||||
Submodule openspace-data updated: a0e8d47b2d...4d83eac48d
@@ -102,6 +102,14 @@ RenderableFieldlines::RenderableFieldlines(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
}
|
||||
|
||||
_seedpointsProgram = new ghoul::opengl::ProgramObject("SeedpointsProgram");
|
||||
ghoul::opengl::ShaderObject* seedpointVertexShader = new ghoul::opengl::ShaderObject(ghoul::opengl::ShaderObject::ShaderTypeVertex,
|
||||
"/home/hhellteg/openspace/openspace-data/scene/fieldlines/seedPoints.vert");
|
||||
ghoul::opengl::ShaderObject* seedpointFragmentShader = new ghoul::opengl::ShaderObject(ghoul::opengl::ShaderObject::ShaderTypeFragment,
|
||||
"/home/hhellteg/openspace/openspace-data/scene/fieldlines/seedPoints.frag");
|
||||
_seedpointsProgram->attachObject(seedpointVertexShader);
|
||||
_seedpointsProgram->attachObject(seedpointFragmentShader);
|
||||
|
||||
if(dictionary.hasKey("UpdateOnSave")) {
|
||||
dictionary.getValue("UpdateOnSave", _programUpdateOnSave);
|
||||
}
|
||||
@@ -118,15 +126,6 @@ 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::string modelString;
|
||||
std::vector<std::vector<glm::vec3> > fieldlinesData;
|
||||
float stepSize;
|
||||
@@ -173,12 +172,16 @@ bool RenderableFieldlines::initialize() {
|
||||
|
||||
for (int i = 0; i < fieldlinesData.size(); i++) {
|
||||
_lineStart.push_back(prevEnd);
|
||||
_lineCount.push_back(fieldlinesData[i].size());
|
||||
prevEnd = prevEnd + fieldlinesData[i].size();
|
||||
_lineCount.push_back(fieldlinesData[i].size()/2.0);
|
||||
prevEnd = prevEnd + fieldlinesData[i].size()/2.0;
|
||||
|
||||
_seedpointStart.push_back(i);
|
||||
_seedpointCount.push_back(1);
|
||||
|
||||
vertexData.insert( vertexData.end(), fieldlinesData[i].begin(), fieldlinesData[i].end());
|
||||
}
|
||||
|
||||
// ------ FIELDLINES -----------------
|
||||
GLuint vertexPositionBuffer;
|
||||
glGenVertexArrays(1, &_VAO); // generate array
|
||||
glBindVertexArray(_VAO); // bind array
|
||||
@@ -189,11 +192,32 @@ bool RenderableFieldlines::initialize() {
|
||||
// Vertex positions
|
||||
GLuint vertexLocation = 0;
|
||||
glEnableVertexAttribArray(vertexLocation);
|
||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), reinterpret_cast<void*>(0));
|
||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 2*sizeof(glm::vec3), reinterpret_cast<void*>(0));
|
||||
|
||||
// Texture coordinates
|
||||
GLuint texcoordLocation = 1;
|
||||
glEnableVertexAttribArray(texcoordLocation);
|
||||
glVertexAttribPointer(texcoordLocation, 3, GL_FLOAT, GL_FALSE, 2*sizeof(glm::vec3), (void*)(sizeof(glm::vec3)));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind buffer
|
||||
glBindVertexArray(0); //unbind array
|
||||
|
||||
// // ------ SEEDPOINTS -----------------
|
||||
// GLuint seedpointPositionBuffer;
|
||||
// glGenVertexArrays(1, &_seedpointVAO); // generate array
|
||||
// glBindVertexArray(_seedpointVAO); // bind array
|
||||
// glGenBuffers(1, &seedpointPositionBuffer); // generate buffer
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, seedpointPositionBuffer); // bind buffer
|
||||
// glBufferData(GL_ARRAY_BUFFER, _seedPoints.size()*sizeof(glm::vec3), &_seedPoints.front(), GL_STATIC_DRAW);
|
||||
//
|
||||
// // Vertex positions
|
||||
// GLuint seedpointLocation = 0;
|
||||
// glEnableVertexAttribArray(seedpointLocation);
|
||||
// glVertexAttribPointer(seedpointLocation, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), reinterpret_cast<void*>(0));
|
||||
//
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind buffer
|
||||
// glBindVertexArray(0); //unbind array
|
||||
|
||||
// ------ SETUP SHADERS -----------------
|
||||
auto privateCallback = [this](const ghoul::filesystem::File& file) {
|
||||
safeShaderCompilation();
|
||||
@@ -206,6 +230,9 @@ bool RenderableFieldlines::initialize() {
|
||||
_fieldlinesProgram->compileShaderObjects();
|
||||
_fieldlinesProgram->linkProgramObject();
|
||||
|
||||
_seedpointsProgram->compileShaderObjects();
|
||||
_seedpointsProgram->linkProgramObject();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -220,20 +247,33 @@ 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::rotate(transform, -90.0f, glm::vec3(1.0, 0.0, 0.0));
|
||||
transform = glm::scale(transform, glm::vec3(0.1));
|
||||
|
||||
// ------ FIELDLINES -----------------
|
||||
_shaderMutex->lock();
|
||||
_fieldlinesProgram->activate();
|
||||
_fieldlinesProgram->setUniform("modelViewProjection", transform);
|
||||
|
||||
|
||||
glBindVertexArray(_VAO);
|
||||
glMultiDrawArrays(GL_LINE_STRIP, &_lineStart[0], &_lineCount[0], _lineStart.size());
|
||||
glBindVertexArray(0);
|
||||
|
||||
_fieldlinesProgram->deactivate();
|
||||
_shaderMutex->unlock();
|
||||
|
||||
// // ------ SEEDPOINTS -----------------
|
||||
// _shaderMutex->lock();
|
||||
// _seedpointsProgram->activate();
|
||||
// _seedpointsProgram->setUniform("modelViewProjection", transform);
|
||||
//
|
||||
// glBindVertexArray(_seedpointVAO);
|
||||
// glPointSize(3);
|
||||
// glMultiDrawArrays(GL_POINTS, &_seedpointStart[0], &_seedpointCount[0], _seedPoints.size());
|
||||
// glBindVertexArray(0);
|
||||
//
|
||||
// _seedpointsProgram->deactivate();
|
||||
// _shaderMutex->unlock();
|
||||
}
|
||||
|
||||
void RenderableFieldlines::update() {
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <iomanip>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -247,13 +248,26 @@ std::vector<std::vector<glm::vec3> > KameleonWrapper::getFieldLines(
|
||||
|
||||
std::vector<glm::vec3> fLine, bLine;
|
||||
std::vector<std::vector<glm::vec3> > fieldLines;
|
||||
glm::vec3 color;
|
||||
FieldlineEnd forwardEnd, backEnd;
|
||||
|
||||
if (_type == Model::BATSRUS) {
|
||||
for (glm::vec3 seedPoint : seedPoints) {
|
||||
fLine = traceCartesianFieldline(xVar, yVar, zVar, seedPoint, stepSize, TraceDirection::FORWARD);
|
||||
bLine = traceCartesianFieldline(xVar, yVar, zVar, seedPoint, stepSize, TraceDirection::BACK);
|
||||
fLine = traceCartesianFieldline(xVar, yVar, zVar, seedPoint, stepSize, TraceDirection::FORWARD, forwardEnd);
|
||||
bLine = traceCartesianFieldline(xVar, yVar, zVar, seedPoint, stepSize, TraceDirection::BACK, backEnd);
|
||||
bLine.insert(bLine.begin(), fLine.rbegin(), fLine.rend());
|
||||
fieldLines.push_back(bLine);
|
||||
|
||||
// classify
|
||||
color = classifyFieldline(forwardEnd, backEnd);
|
||||
|
||||
// write colors
|
||||
std::vector<glm::vec3> line;
|
||||
for (glm::vec3 position : bLine) {
|
||||
line.push_back(position);
|
||||
line.push_back(color);
|
||||
}
|
||||
|
||||
fieldLines.push_back(line);
|
||||
}
|
||||
} else {
|
||||
LERROR("Fieldlines are only supported for BATSRUS model");
|
||||
@@ -265,9 +279,9 @@ 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,
|
||||
float stepSize, TraceDirection direction) {
|
||||
float stepSize, TraceDirection direction, FieldlineEnd& end) {
|
||||
|
||||
glm::vec3 pos, k1, k2, k3, k4;
|
||||
glm::vec3 color, pos, k1, k2, k3, k4;
|
||||
std::vector<glm::vec3> line;
|
||||
|
||||
float stepX = stepSize, stepY = stepSize, stepZ = stepSize; // Should I do different stepsizes?
|
||||
@@ -311,6 +325,14 @@ std::vector<glm::vec3> KameleonWrapper::traceCartesianFieldline(
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos.z > 0.0 && pos.x < 1.0 && pos.x > -1.0 && pos.y < 1.0 && pos.y > -1.0)
|
||||
end = FieldlineEnd::NORTH;
|
||||
else if (pos.z < 0.0 && pos.x < 1.0 && pos.x > -1.0 && pos.y < 1.0 && pos.y > -1.0)
|
||||
end = FieldlineEnd::SOUTH;
|
||||
else
|
||||
end = FieldlineEnd::OUT;
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
@@ -354,4 +376,25 @@ void KameleonWrapper::progressBar(int current, int end) {
|
||||
_lastiProgress = iprogress;
|
||||
}
|
||||
|
||||
glm::vec3 KameleonWrapper::classifyFieldline(FieldlineEnd fEnd, FieldlineEnd bEnd) {
|
||||
glm::vec3 color;
|
||||
if ( (fEnd == FieldlineEnd::NORTH || fEnd == FieldlineEnd::SOUTH)
|
||||
&& (bEnd == FieldlineEnd::NORTH || bEnd == FieldlineEnd::SOUTH)) {
|
||||
// closed
|
||||
color = glm::vec3(1.0, 0.0, 0.0);
|
||||
} else if ((fEnd == FieldlineEnd::OUT && bEnd == FieldlineEnd::NORTH)
|
||||
|| (bEnd == FieldlineEnd::OUT && fEnd == FieldlineEnd::NORTH)) {
|
||||
// north
|
||||
color = glm::vec3(1.0, 1.0, 0.0);
|
||||
} else if ((fEnd == FieldlineEnd::OUT && bEnd == FieldlineEnd::SOUTH)
|
||||
|| (bEnd == FieldlineEnd::OUT && fEnd == FieldlineEnd::SOUTH)) {
|
||||
// south
|
||||
color = glm::vec3(0.0, 1.0, 0.0);
|
||||
} else if (fEnd == FieldlineEnd::OUT && bEnd == FieldlineEnd::OUT) {
|
||||
// solar wind
|
||||
color = glm::vec3(0.0, 0.0, 1.0);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user