mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 20:21:24 -06:00
Fieldline and seedpoint color now in RGBA instead of RGB
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include <ghoul/filesystem/file.h>
|
||||
|
||||
namespace openspace {
|
||||
struct LinePoint;
|
||||
|
||||
class RenderableFieldlines : public Renderable {
|
||||
public:
|
||||
@@ -46,7 +47,7 @@ public:
|
||||
virtual void update();
|
||||
|
||||
private:
|
||||
std::vector<std::vector<glm::vec3> > getFieldlinesData(std::string filename, ghoul::Dictionary hintsDictionary);
|
||||
std::vector<std::vector<LinePoint> > getFieldlinesData(std::string filename, ghoul::Dictionary hintsDictionary);
|
||||
|
||||
std::vector<ghoul::Dictionary> _hintsDictionaries;
|
||||
std::vector<std::string> _filenames;
|
||||
|
||||
@@ -34,6 +34,16 @@ namespace ccmc {
|
||||
|
||||
namespace openspace {
|
||||
|
||||
struct LinePoint {
|
||||
glm::vec3 position;
|
||||
glm::vec4 color;
|
||||
|
||||
LinePoint(glm::vec3 pos, glm::vec4 col) {
|
||||
position = pos;
|
||||
color = col;
|
||||
}
|
||||
};
|
||||
|
||||
class KameleonWrapper {
|
||||
public:
|
||||
|
||||
@@ -59,16 +69,16 @@ public:
|
||||
float* getUniformSampledVectorValues(const std::string& xVar, const std::string& yVar,
|
||||
const std::string& zVar, glm::size3_t outDimensions);
|
||||
|
||||
std::vector<std::vector<glm::vec3> > getClassifiedFieldLines(const std::string& xVar,
|
||||
std::vector<std::vector<LinePoint> > getClassifiedFieldLines(const std::string& xVar,
|
||||
const std::string& yVar, const std::string& zVar,
|
||||
std::vector<glm::vec3> seedPoints, float stepSize);
|
||||
|
||||
std::vector<std::vector<glm::vec3> > getFieldLines(const std::string& xVar,
|
||||
std::vector<std::vector<LinePoint> > getFieldLines(const std::string& xVar,
|
||||
const std::string& yVar, const std::string& zVar,
|
||||
std::vector<glm::vec3> seedPoints, float stepSize, glm::vec3 color);
|
||||
std::vector<glm::vec3> seedPoints, float stepSize, glm::vec4 color);
|
||||
|
||||
std::vector<std::vector<glm::vec3> > getLorentzTrajectories(std::vector<glm::vec3> seedPoints,
|
||||
glm::vec3 color, float stepsize);
|
||||
std::vector<std::vector<LinePoint> > getLorentzTrajectories(std::vector<glm::vec3> seedPoints,
|
||||
glm::vec4 color, float stepsize);
|
||||
|
||||
private:
|
||||
std::vector<glm::vec3> traceCartesianFieldline(const std::string& xVar,
|
||||
@@ -80,7 +90,7 @@ private:
|
||||
|
||||
void getGridVariables(std::string& x, std::string& y, std::string& z);
|
||||
void progressBar(int current, int end);
|
||||
glm::vec3 classifyFieldline(FieldlineEnd fEnd, FieldlineEnd bEnd);
|
||||
glm::vec4 classifyFieldline(FieldlineEnd fEnd, FieldlineEnd bEnd);
|
||||
|
||||
ccmc::Model* _model;
|
||||
Model _type;
|
||||
|
||||
Submodule openspace-data updated: 8fa226790e...f858de10c6
@@ -53,10 +53,8 @@ RenderableFieldlines::RenderableFieldlines(const ghoul::Dictionary& dictionary)
|
||||
if(fieldline.hasKey("Hints"))
|
||||
fieldline.getValue("Hints", hintsDictionary);
|
||||
|
||||
// TODO Vectors of filenames and dictionaries
|
||||
_filenames.push_back(file);
|
||||
_hintsDictionaries.push_back(hintsDictionary);
|
||||
|
||||
} else
|
||||
LERROR("File not found!");
|
||||
}
|
||||
@@ -72,12 +70,11 @@ RenderableFieldlines::RenderableFieldlines(const ghoul::Dictionary& dictionary)
|
||||
if (dictionary.hasKey("Shaders")) {
|
||||
ghoul::Dictionary shaderDictionary;
|
||||
if(dictionary.getValue("Shaders", shaderDictionary)) {
|
||||
if (shaderDictionary.hasKey("VertexShader")) {
|
||||
if (shaderDictionary.hasKey("VertexShader"))
|
||||
shaderDictionary.getValue("VertexShader", vshaderpath);
|
||||
}
|
||||
if (shaderDictionary.hasKey("FragmentShader")) {
|
||||
|
||||
if (shaderDictionary.hasKey("FragmentShader"))
|
||||
shaderDictionary.getValue("FragmentShader", fshaderpath);
|
||||
}
|
||||
|
||||
vshaderpath = findPath(vshaderpath);
|
||||
fshaderpath = findPath(fshaderpath);
|
||||
@@ -97,11 +94,10 @@ RenderableFieldlines::RenderableFieldlines(const ghoul::Dictionary& dictionary)
|
||||
dictionary.getValue("UpdateOnSave", _programUpdateOnSave);
|
||||
}
|
||||
|
||||
setBoundingSphere(PowerScaledScalar::CreatePSS(5));
|
||||
setBoundingSphere(PowerScaledScalar::CreatePSS(5)); // FIXME a non-magic number perhaps
|
||||
}
|
||||
|
||||
RenderableFieldlines::~RenderableFieldlines() {
|
||||
|
||||
}
|
||||
|
||||
bool RenderableFieldlines::initialize() {
|
||||
@@ -109,28 +105,25 @@ bool RenderableFieldlines::initialize() {
|
||||
assert(_hintsDictionaries.size() != 0);
|
||||
|
||||
int prevEnd = 0;
|
||||
std::vector<glm::vec3> vertexData;
|
||||
std::vector<std::vector<glm::vec3> > fieldlinesData;
|
||||
std::vector<LinePoint> vertexData, seedPointsData;
|
||||
std::vector<std::vector<LinePoint> > fieldlinesData;
|
||||
glm::vec4 seedPointsColor = glm::vec4(1.0, 0.5, 0.0, 1.0);
|
||||
|
||||
for (int i = 0; i < _filenames.size(); ++i) {
|
||||
fieldlinesData = getFieldlinesData(_filenames[i], _hintsDictionaries[i]);
|
||||
|
||||
for (int j = 0; j < fieldlinesData.size(); j++) {
|
||||
for (int j = 0; j < fieldlinesData.size(); ++j) {
|
||||
_lineStart.push_back(prevEnd);
|
||||
_lineCount.push_back(fieldlinesData[j].size()/2.0);
|
||||
prevEnd = prevEnd + fieldlinesData[j].size()/2.0;
|
||||
|
||||
_lineCount.push_back(fieldlinesData[j].size());
|
||||
prevEnd = prevEnd + fieldlinesData[j].size();
|
||||
vertexData.insert( vertexData.end(), fieldlinesData[j].begin(), fieldlinesData[j].end());
|
||||
}
|
||||
// Give seedpoints a color for visualizing as GL_POINTS
|
||||
for (glm::vec3 seedPoint : _seedPoints) {
|
||||
seedPointsData.push_back(LinePoint(seedPoint, seedPointsColor));
|
||||
}
|
||||
}
|
||||
LDEBUG("Number of vertices : " << vertexData.size()/2.0);
|
||||
|
||||
// Give seedpoints a color for visualizing as GL_POINTS
|
||||
std::vector<glm::vec3> seedPointsData;
|
||||
for (int i = 0; i < _seedPoints.size(); ++i) {
|
||||
seedPointsData.push_back(_seedPoints[i]);
|
||||
seedPointsData.push_back(glm::vec3(1.0, 0.5, 0.0));
|
||||
}
|
||||
LDEBUG("Number of vertices : " << vertexData.size());
|
||||
|
||||
// ------ FIELDLINES -----------------
|
||||
GLuint vertexPositionBuffer;
|
||||
@@ -138,17 +131,17 @@ bool RenderableFieldlines::initialize() {
|
||||
glBindVertexArray(_VAO); // bind array
|
||||
glGenBuffers(1, &vertexPositionBuffer); // generate buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexPositionBuffer); // bind buffer
|
||||
glBufferData(GL_ARRAY_BUFFER, vertexData.size()*sizeof(glm::vec3), &vertexData.front(), GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertexData.size()*sizeof(LinePoint), &vertexData.front(), GL_STATIC_DRAW);
|
||||
|
||||
// Vertex positions
|
||||
GLuint vertexLocation = 0;
|
||||
glEnableVertexAttribArray(vertexLocation);
|
||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 2*sizeof(glm::vec3), reinterpret_cast<void*>(0));
|
||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(LinePoint), 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)));
|
||||
glVertexAttribPointer(texcoordLocation, 4, GL_FLOAT, GL_FALSE, sizeof(LinePoint), (void*)(sizeof(glm::vec3)));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind buffer
|
||||
glBindVertexArray(0); //unbind array
|
||||
@@ -159,15 +152,15 @@ bool RenderableFieldlines::initialize() {
|
||||
glBindVertexArray(_seedpointVAO); // bind array
|
||||
glGenBuffers(1, &seedpointPositionBuffer); // generate buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, seedpointPositionBuffer); // bind buffer
|
||||
glBufferData(GL_ARRAY_BUFFER, seedPointsData.size()*sizeof(glm::vec3), &seedPointsData.front(), GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, seedPointsData.size()*sizeof(LinePoint), &seedPointsData.front(), GL_STATIC_DRAW);
|
||||
|
||||
// Vertex positions
|
||||
glEnableVertexAttribArray(vertexLocation);
|
||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 2*sizeof(glm::vec3), reinterpret_cast<void*>(0));
|
||||
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(LinePoint), reinterpret_cast<void*>(0));
|
||||
|
||||
// Texture coordinates
|
||||
glEnableVertexAttribArray(texcoordLocation);
|
||||
glVertexAttribPointer(texcoordLocation, 3, GL_FLOAT, GL_FALSE, 2*sizeof(glm::vec3), (void*)(sizeof(glm::vec3)));
|
||||
glVertexAttribPointer(texcoordLocation, 4, GL_FLOAT, GL_FALSE, sizeof(LinePoint), (void*)(3*sizeof(float)));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind buffer
|
||||
glBindVertexArray(0); //unbind array
|
||||
@@ -194,7 +187,6 @@ bool RenderableFieldlines::deinitialize() {
|
||||
}
|
||||
|
||||
void RenderableFieldlines::render(const Camera* camera, const psc& thisPosition) {
|
||||
|
||||
if(_update) {
|
||||
_update = false;
|
||||
safeShaderCompilation();
|
||||
@@ -205,11 +197,8 @@ void RenderableFieldlines::render(const Camera* camera, const psc& thisPosition)
|
||||
psc relative = thisPosition-camera->position();
|
||||
|
||||
transform = transform*camTransform;
|
||||
//transform = glm::translate(transform, relative.vec3());
|
||||
transform = glm::mat4(1.0);
|
||||
// transform = glm::scale(transform, glm::vec3(0.036*0.5*0.5));
|
||||
transform = glm::scale(transform, glm::vec3(0.01));
|
||||
//transform = glm::scale(transform, glm::vec3(0.1)); // Scale to avoid depth buffer problems
|
||||
|
||||
psc currentPosition = thisPosition;
|
||||
psc campos = camera->position();
|
||||
@@ -218,7 +207,6 @@ void RenderableFieldlines::render(const Camera* camera, const psc& thisPosition)
|
||||
|
||||
// Activate shader
|
||||
_fieldlinesProgram->activate();
|
||||
//_fieldlinesProgram->setUniform("modelViewProjection", transform);
|
||||
|
||||
_fieldlinesProgram->setUniform("modelViewProjection", camera->viewProjectionMatrix());
|
||||
_fieldlinesProgram->setUniform("modelTransform", transform);
|
||||
@@ -249,15 +237,15 @@ void RenderableFieldlines::safeShaderCompilation() {
|
||||
_fieldlinesProgram->linkProgramObject();
|
||||
}
|
||||
|
||||
std::vector<std::vector<glm::vec3> > RenderableFieldlines::getFieldlinesData(std::string filename, ghoul::Dictionary hintsDictionary) {
|
||||
std::vector<std::vector<LinePoint> > RenderableFieldlines::getFieldlinesData(std::string filename, ghoul::Dictionary hintsDictionary) {
|
||||
std::string modelString;
|
||||
float stepSize = 0.5; // default if no stepsize is specified in hints
|
||||
std::string xVariable, yVariable, zVariable;
|
||||
KameleonWrapper::Model model;
|
||||
std::vector<std::vector<glm::vec3> > fieldlinesData;
|
||||
std::vector<std::vector<LinePoint> > fieldlinesData;
|
||||
|
||||
bool classification = false, lorentz = false;
|
||||
glm::vec3 fieldlineColor = glm::vec3(1.0, 1.0, 1.0); // default color if no color or classification is specified
|
||||
glm::vec4 fieldlineColor = glm::vec4(1.0, 1.0, 1.0, 1.0); // default color if no color or classification is specified
|
||||
|
||||
if (hintsDictionary.hasKey("Model") && hintsDictionary.getValue("Model", modelString)) {
|
||||
// ------ MODEL -----------------
|
||||
|
||||
@@ -269,7 +269,7 @@ float* KameleonWrapper::getUniformSampledVectorValues(const std::string& xVar, c
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<std::vector<glm::vec3> > KameleonWrapper::getClassifiedFieldLines(
|
||||
std::vector<std::vector<LinePoint> > KameleonWrapper::getClassifiedFieldLines(
|
||||
const std::string& xVar, const std::string& yVar,
|
||||
const std::string& zVar, std::vector<glm::vec3> seedPoints,
|
||||
float stepSize ) {
|
||||
@@ -278,8 +278,8 @@ std::vector<std::vector<glm::vec3> > KameleonWrapper::getClassifiedFieldLines(
|
||||
LINFO("Creating " << seedPoints.size() << " fieldlines from variables " << xVar << " " << yVar << " " << zVar);
|
||||
|
||||
std::vector<glm::vec3> fLine, bLine;
|
||||
std::vector<std::vector<glm::vec3> > fieldLines;
|
||||
glm::vec3 color;
|
||||
std::vector<std::vector<LinePoint> > fieldLines;
|
||||
glm::vec4 color;
|
||||
FieldlineEnd forwardEnd, backEnd;
|
||||
|
||||
if (_type == Model::BATSRUS) {
|
||||
@@ -293,10 +293,9 @@ std::vector<std::vector<glm::vec3> > KameleonWrapper::getClassifiedFieldLines(
|
||||
color = classifyFieldline(forwardEnd, backEnd);
|
||||
|
||||
// write colors
|
||||
std::vector<glm::vec3> line;
|
||||
std::vector<LinePoint> line;
|
||||
for (glm::vec3 position : bLine) {
|
||||
line.push_back(position);
|
||||
line.push_back(color);
|
||||
line.push_back(LinePoint(position, color));
|
||||
}
|
||||
|
||||
fieldLines.push_back(line);
|
||||
@@ -308,16 +307,16 @@ std::vector<std::vector<glm::vec3> > KameleonWrapper::getClassifiedFieldLines(
|
||||
return fieldLines;
|
||||
}
|
||||
|
||||
std::vector<std::vector<glm::vec3> > KameleonWrapper::getFieldLines(
|
||||
std::vector<std::vector<LinePoint> > KameleonWrapper::getFieldLines(
|
||||
const std::string& xVar, const std::string& yVar,
|
||||
const std::string& zVar, std::vector<glm::vec3> seedPoints,
|
||||
float stepSize, glm::vec3 color ) {
|
||||
float stepSize, glm::vec4 color ) {
|
||||
assert(_model && _interpolator);
|
||||
assert(_type == Model::ENLIL || _type == Model::BATSRUS);
|
||||
LINFO("Creating " << seedPoints.size() << " fieldlines from variables " << xVar << " " << yVar << " " << zVar);
|
||||
|
||||
std::vector<glm::vec3> fLine, bLine;
|
||||
std::vector<std::vector<glm::vec3> > fieldLines;
|
||||
std::vector<std::vector<LinePoint> > fieldLines;
|
||||
FieldlineEnd forwardEnd, backEnd;
|
||||
|
||||
if (_type == Model::BATSRUS) {
|
||||
@@ -328,10 +327,9 @@ std::vector<std::vector<glm::vec3> > KameleonWrapper::getFieldLines(
|
||||
bLine.insert(bLine.begin(), fLine.rbegin(), fLine.rend());
|
||||
|
||||
// write colors
|
||||
std::vector<glm::vec3> line;
|
||||
std::vector<LinePoint> line;
|
||||
for (glm::vec3 position : bLine) {
|
||||
line.push_back(position);
|
||||
line.push_back(color);
|
||||
line.push_back(LinePoint(position, color));
|
||||
}
|
||||
|
||||
fieldLines.push_back(line);
|
||||
@@ -343,11 +341,11 @@ std::vector<std::vector<glm::vec3> > KameleonWrapper::getFieldLines(
|
||||
return fieldLines;
|
||||
}
|
||||
|
||||
std::vector<std::vector<glm::vec3> > KameleonWrapper::getLorentzTrajectories(
|
||||
std::vector<glm::vec3> seedPoints, glm::vec3 color, float stepsize) {
|
||||
std::vector<std::vector<LinePoint> > KameleonWrapper::getLorentzTrajectories(
|
||||
std::vector<glm::vec3> seedPoints, glm::vec4 color, float stepsize) {
|
||||
LINFO("Creating " << seedPoints.size() << " Lorentz force trajectories");
|
||||
|
||||
std::vector<std::vector<glm::vec3> > trajectories;
|
||||
std::vector<std::vector<LinePoint> > trajectories;
|
||||
std::vector<glm::vec3> plusTraj, minusTraj;
|
||||
|
||||
for (auto seedPoint : seedPoints) {
|
||||
@@ -357,10 +355,9 @@ std::vector<std::vector<glm::vec3> > KameleonWrapper::getLorentzTrajectories(
|
||||
minusTraj.insert(minusTraj.begin(), plusTraj.rbegin(), plusTraj.rend());
|
||||
|
||||
// write colors
|
||||
std::vector<glm::vec3> trajectory;
|
||||
std::vector<LinePoint> trajectory;
|
||||
for (glm::vec3 position : minusTraj) {
|
||||
trajectory.push_back(position);
|
||||
trajectory.push_back(color);
|
||||
trajectory.push_back(LinePoint(position, color));
|
||||
}
|
||||
trajectories.push_back(trajectory);
|
||||
}
|
||||
@@ -567,23 +564,23 @@ void KameleonWrapper::progressBar(int current, int end) {
|
||||
_lastiProgress = iprogress;
|
||||
}
|
||||
|
||||
glm::vec3 KameleonWrapper::classifyFieldline(FieldlineEnd fEnd, FieldlineEnd bEnd) {
|
||||
glm::vec3 color;
|
||||
glm::vec4 KameleonWrapper::classifyFieldline(FieldlineEnd fEnd, FieldlineEnd bEnd) {
|
||||
glm::vec4 color;
|
||||
if ( (fEnd == FieldlineEnd::NORTH || fEnd == FieldlineEnd::SOUTH)
|
||||
&& (bEnd == FieldlineEnd::NORTH || bEnd == FieldlineEnd::SOUTH)) {
|
||||
// closed
|
||||
color = glm::vec3(1.0, 0.0, 0.0);
|
||||
color = glm::vec4(1.0, 0.0, 0.0, 1.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);
|
||||
color = glm::vec4(1.0, 1.0, 0.0, 1.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);
|
||||
color = glm::vec4(0.0, 1.0, 0.0, 1.0);
|
||||
} else if (fEnd == FieldlineEnd::OUT && bEnd == FieldlineEnd::OUT) {
|
||||
// solar wind
|
||||
color = glm::vec3(0.0, 0.0, 1.0);
|
||||
color = glm::vec4(0.0, 0.0, 1.0, 1.0);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user