From 1996acf997fcb8465f96d167a5684470c5510f0c Mon Sep 17 00:00:00 2001 From: Hans-Christian Helltegen Date: Thu, 3 Jul 2014 14:42:43 -0400 Subject: [PATCH 1/2] Fieldline and seedpoint color now in RGBA instead of RGB --- .../rendering/renderablefieldlines.h | 3 +- include/openspace/util/kameleonwrapper.h | 22 +++++-- openspace-data | 2 +- src/rendering/renderablefieldlines.cpp | 60 ++++++++----------- src/util/kameleonwrapper.cpp | 45 +++++++------- 5 files changed, 64 insertions(+), 68 deletions(-) diff --git a/include/openspace/rendering/renderablefieldlines.h b/include/openspace/rendering/renderablefieldlines.h index c37f5649b6..e250a7e4d5 100644 --- a/include/openspace/rendering/renderablefieldlines.h +++ b/include/openspace/rendering/renderablefieldlines.h @@ -33,6 +33,7 @@ #include namespace openspace { + struct LinePoint; class RenderableFieldlines : public Renderable { public: @@ -46,7 +47,7 @@ public: virtual void update(); private: - std::vector > getFieldlinesData(std::string filename, ghoul::Dictionary hintsDictionary); + std::vector > getFieldlinesData(std::string filename, ghoul::Dictionary hintsDictionary); std::vector _hintsDictionaries; std::vector _filenames; diff --git a/include/openspace/util/kameleonwrapper.h b/include/openspace/util/kameleonwrapper.h index 6b85680231..fd8903f7a2 100644 --- a/include/openspace/util/kameleonwrapper.h +++ b/include/openspace/util/kameleonwrapper.h @@ -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 > getClassifiedFieldLines(const std::string& xVar, + std::vector > getClassifiedFieldLines(const std::string& xVar, const std::string& yVar, const std::string& zVar, std::vector seedPoints, float stepSize); - std::vector > getFieldLines(const std::string& xVar, + std::vector > getFieldLines(const std::string& xVar, const std::string& yVar, const std::string& zVar, - std::vector seedPoints, float stepSize, glm::vec3 color); + std::vector seedPoints, float stepSize, glm::vec4 color); - std::vector > getLorentzTrajectories(std::vector seedPoints, - glm::vec3 color, float stepsize); + std::vector > getLorentzTrajectories(std::vector seedPoints, + glm::vec4 color, float stepsize); private: std::vector 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; diff --git a/openspace-data b/openspace-data index 8fa226790e..f858de10c6 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 8fa226790e939667b31c0e2020ba42708e3de7e6 +Subproject commit f858de10c6b9b30df2aa855e337063ecee9d8ee9 diff --git a/src/rendering/renderablefieldlines.cpp b/src/rendering/renderablefieldlines.cpp index ff4e76c669..50314e5838 100644 --- a/src/rendering/renderablefieldlines.cpp +++ b/src/rendering/renderablefieldlines.cpp @@ -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 vertexData; - std::vector > fieldlinesData; + std::vector vertexData, seedPointsData; + std::vector > 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 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(0)); + glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(LinePoint), reinterpret_cast(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(0)); + glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(LinePoint), reinterpret_cast(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 > RenderableFieldlines::getFieldlinesData(std::string filename, ghoul::Dictionary hintsDictionary) { +std::vector > 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 > fieldlinesData; + std::vector > 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 ----------------- diff --git a/src/util/kameleonwrapper.cpp b/src/util/kameleonwrapper.cpp index 1fa2b423f6..0ca5a7d9b5 100644 --- a/src/util/kameleonwrapper.cpp +++ b/src/util/kameleonwrapper.cpp @@ -269,7 +269,7 @@ float* KameleonWrapper::getUniformSampledVectorValues(const std::string& xVar, c return data; } -std::vector > KameleonWrapper::getClassifiedFieldLines( +std::vector > KameleonWrapper::getClassifiedFieldLines( const std::string& xVar, const std::string& yVar, const std::string& zVar, std::vector seedPoints, float stepSize ) { @@ -278,8 +278,8 @@ std::vector > KameleonWrapper::getClassifiedFieldLines( LINFO("Creating " << seedPoints.size() << " fieldlines from variables " << xVar << " " << yVar << " " << zVar); std::vector fLine, bLine; - std::vector > fieldLines; - glm::vec3 color; + std::vector > fieldLines; + glm::vec4 color; FieldlineEnd forwardEnd, backEnd; if (_type == Model::BATSRUS) { @@ -293,10 +293,9 @@ std::vector > KameleonWrapper::getClassifiedFieldLines( color = classifyFieldline(forwardEnd, backEnd); // write colors - std::vector line; + std::vector 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 > KameleonWrapper::getClassifiedFieldLines( return fieldLines; } -std::vector > KameleonWrapper::getFieldLines( +std::vector > KameleonWrapper::getFieldLines( const std::string& xVar, const std::string& yVar, const std::string& zVar, std::vector 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 fLine, bLine; - std::vector > fieldLines; + std::vector > fieldLines; FieldlineEnd forwardEnd, backEnd; if (_type == Model::BATSRUS) { @@ -328,10 +327,9 @@ std::vector > KameleonWrapper::getFieldLines( bLine.insert(bLine.begin(), fLine.rbegin(), fLine.rend()); // write colors - std::vector line; + std::vector 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 > KameleonWrapper::getFieldLines( return fieldLines; } -std::vector > KameleonWrapper::getLorentzTrajectories( - std::vector seedPoints, glm::vec3 color, float stepsize) { +std::vector > KameleonWrapper::getLorentzTrajectories( + std::vector seedPoints, glm::vec4 color, float stepsize) { LINFO("Creating " << seedPoints.size() << " Lorentz force trajectories"); - std::vector > trajectories; + std::vector > trajectories; std::vector plusTraj, minusTraj; for (auto seedPoint : seedPoints) { @@ -357,10 +355,9 @@ std::vector > KameleonWrapper::getLorentzTrajectories( minusTraj.insert(minusTraj.begin(), plusTraj.rbegin(), plusTraj.rend()); // write colors - std::vector trajectory; + std::vector 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; } From aff61620c8d1b8d1b698f81dd830cdcb6fd722f7 Mon Sep 17 00:00:00 2001 From: Hans-Christian Helltegen Date: Mon, 7 Jul 2014 14:26:22 -0400 Subject: [PATCH 2/2] Added functionality for getting the model barycenter in kameleonwrapper and moving the raycasting box by an offset. Also cleaned up renderablevolumegl a bit --- .../openspace/rendering/renderablevolume.h | 1 + .../openspace/rendering/renderablevolumegl.h | 7 +--- src/rendering/renderablevolume.cpp | 32 +++++++++++++++++-- src/rendering/renderablevolumegl.cpp | 32 ++++--------------- src/util/kameleonwrapper.cpp | 21 ++++++++---- 5 files changed, 52 insertions(+), 41 deletions(-) diff --git a/include/openspace/rendering/renderablevolume.h b/include/openspace/rendering/renderablevolume.h index 870b8ee672..9c9c1c4b9c 100644 --- a/include/openspace/rendering/renderablevolume.h +++ b/include/openspace/rendering/renderablevolume.h @@ -42,6 +42,7 @@ public: protected: ghoul::opengl::Texture* loadVolume(const std::string& filepath, const ghoul::Dictionary& hintsDictionary); + glm::vec3 getVolumeOffset(const std::string& filepath, const ghoul::Dictionary& hintsDictionary); ghoul::RawVolumeReader::ReadHints readHints(const ghoul::Dictionary& dictionary); ghoul::opengl::Texture* loadTransferFunction(const std::string& filepath); diff --git a/include/openspace/rendering/renderablevolumegl.h b/include/openspace/rendering/renderablevolumegl.h index c368e41cfc..b13ed7cc5a 100644 --- a/include/openspace/rendering/renderablevolumegl.h +++ b/include/openspace/rendering/renderablevolumegl.h @@ -35,10 +35,6 @@ #include #include - namespace sgct_utils { - class SGCTBox; -} - namespace openspace { class RenderableVolumeGL: public RenderableVolume { @@ -67,8 +63,7 @@ private: GLuint _boxArray; ghoul::opengl::ProgramObject *_boxProgram; - sgct_utils::SGCTBox* _box; - glm::vec3 _boxScaling; + glm::vec3 _boxScaling, _boxOffset; GLint _MVPLocation, _modelTransformLocation, _typeLocation; bool _updateTransferfunction; diff --git a/src/rendering/renderablevolume.cpp b/src/rendering/renderablevolume.cpp index 7d6efbd93f..e21d6edde8 100644 --- a/src/rendering/renderablevolume.cpp +++ b/src/rendering/renderablevolume.cpp @@ -79,8 +79,8 @@ RenderableVolume::~RenderableVolume() { ghoul::opengl::Texture* RenderableVolume::loadVolume( const std::string& filepath, - const ghoul::Dictionary& hintsDictionary) -{ + const ghoul::Dictionary& hintsDictionary) { + if( ! FileSys.fileExists(filepath)) { LWARNING("Could not load volume, could not find '" << filepath << "'"); return nullptr; @@ -174,7 +174,6 @@ ghoul::opengl::Texture* RenderableVolume::loadVolume( } KameleonWrapper kw(filepath, model); - std::string variableString; if (hintsDictionary.hasKey("Variable") && hintsDictionary.getValue("Variable", variableString)) { float* data = kw.getUniformSampledValues(variableString, dimensions); @@ -220,6 +219,33 @@ ghoul::opengl::Texture* RenderableVolume::loadVolume( return nullptr; } +glm::vec3 RenderableVolume::getVolumeOffset( + const std::string& filepath, + const ghoul::Dictionary& hintsDictionary) { + + std::string modelString = ""; + if (hintsDictionary.hasKey("Model")) + hintsDictionary.getValue("Model", modelString); + + if(modelString == "") { + LWARNING("Model not specified."); + return glm::vec3(0); + } + KameleonWrapper::Model model; + if (modelString == "BATSRUS") { + model = KameleonWrapper::Model::BATSRUS; + } else if (modelString == "ENLIL") { + model = KameleonWrapper::Model::ENLIL; + } else { + LWARNING("Hints does not specify a valid 'Model'"); + return glm::vec3(0); + } + + KameleonWrapper kw(filepath, model); + + return kw.getModelBarycenterOffset(); +} + ghoul::RawVolumeReader::ReadHints RenderableVolume::readHints(const ghoul::Dictionary& dictionary) { ghoul::RawVolumeReader::ReadHints hints; hints._dimensions = glm::ivec3(1, 1, 1); diff --git a/src/rendering/renderablevolumegl.cpp b/src/rendering/renderablevolumegl.cpp index bdcdc9ae79..a888b241d4 100644 --- a/src/rendering/renderablevolumegl.cpp +++ b/src/rendering/renderablevolumegl.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -34,7 +35,6 @@ #include #include -#include namespace { std::string _loggerCat = "RenderableVolumeGL"; @@ -43,9 +43,8 @@ namespace { namespace openspace { RenderableVolumeGL::RenderableVolumeGL(const ghoul::Dictionary& dictionary): - RenderableVolume(dictionary), _box(nullptr), _boxScaling(1.0, 1.0, 1.0), + RenderableVolume(dictionary), _boxScaling(1.0, 1.0, 1.0), _updateTransferfunction(false), _id(-1) { - _filename = ""; if(dictionary.hasKey("Volume")) { @@ -80,8 +79,7 @@ RenderableVolumeGL::RenderableVolumeGL(const ghoul::Dictionary& dictionary): } if( _samplerFilename == "") { LERROR("No samplerfile!"); - } - + } double tempValue; if(dictionary.hasKey("BoxScaling.1") && dictionary.getValue("BoxScaling.1", tempValue)) { @@ -108,14 +106,13 @@ RenderableVolumeGL::~RenderableVolumeGL() { delete _transferFunctionFile; if(_transferFunction) delete _transferFunction; - if(_box) - delete _box; } bool RenderableVolumeGL::initialize() { assert(_filename != ""); // ------ VOLUME READING ---------------- _volume = loadVolume(_filename, _hintsDictionary); + _boxOffset = getVolumeOffset(_filename, _hintsDictionary); _volume->uploadTexture(); _transferFunction = loadTransferFunction(_transferFunctionPath); _transferFunction->uploadTexture(); @@ -130,7 +127,6 @@ bool RenderableVolumeGL::initialize() { }; _transferFunctionFile->setCallback(textureCallback); - _box = new sgct_utils::SGCTBox(1.0f, sgct_utils::SGCTBox::Regular); OsEng.configurationManager().getValue("RaycastProgram", _boxProgram); _MVPLocation = _boxProgram->uniformLocation("modelViewProjection"); _modelTransformLocation = _boxProgram->uniformLocation("modelTransform"); @@ -191,10 +187,7 @@ bool RenderableVolumeGL::initialize() { glBindBuffer(GL_ARRAY_BUFFER, vertexPositionBuffer); // bind buffer glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*4, reinterpret_cast(0)); - //glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*7, reinterpret_cast(0)); glEnableVertexAttribArray(0); - //glEnableVertexAttribArray(1); - return true; } @@ -220,12 +213,6 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition) { } } - //psc relative = thisPosition-camera->position(); - - // glm::mat4 transform = camera->viewRotationMatrix(); - // transform = glm::translate(transform, relative.vec3()); - // transform = glm::translate(transform, glm::vec3(-1.1,0.0,0.0)); - // transform = glm::scale(transform, _boxScaling); glm::mat4 transform = glm::mat4(1.0); transform = glm::scale(transform, _boxScaling); @@ -235,13 +222,11 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition) { glm::mat4 camrot = camera->viewRotationMatrix(); PowerScaledScalar scaling = camera->scaling(); - psc addon(-1.1,0.0,0.0,0.0); - currentPosition += addon; + psc addon(_boxOffset/100.0f); // TODO: Proper scaling/units + currentPosition += addon; // Move box to model barycenter // TODO: Use _id to identify this volume _boxProgram->activate(); - // _boxProgram->setUniform(_MVPLocation, camera->viewProjectionMatrix()); - // _boxProgram->setUniform(_modelTransformLocation, transform); _boxProgram->setUniform(_typeLocation, _id); _boxProgram->setUniform("modelViewProjection", camera->viewProjectionMatrix()); @@ -258,20 +243,15 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition) { glCullFace(GL_FRONT); glBindVertexArray(_boxArray); glDrawArrays(GL_TRIANGLES, 0, 6*6); - // _box->draw(); // Draw frontface (now the normal cull face is is set) glCullFace(GL_BACK); glDrawArrays(GL_TRIANGLES, 0, 6*6); - // _box->draw(); _boxProgram->deactivate(); - } void RenderableVolumeGL::update() { - } - } // namespace openspace diff --git a/src/util/kameleonwrapper.cpp b/src/util/kameleonwrapper.cpp index 0ca5a7d9b5..3d2918d84c 100644 --- a/src/util/kameleonwrapper.cpp +++ b/src/util/kameleonwrapper.cpp @@ -65,12 +65,12 @@ KameleonWrapper::KameleonWrapper(const std::string& filename, Model model): _typ } getGridVariables(_xCoordVar, _yCoordVar, _zCoordVar); - _xMin = _model->getVariableAttribute(_xCoordVar, "actual_min").getAttributeFloat(); - _xMax = _model->getVariableAttribute(_xCoordVar, "actual_max").getAttributeFloat(); - _yMin = _model->getVariableAttribute(_yCoordVar, "actual_min").getAttributeFloat(); - _yMax = _model->getVariableAttribute(_yCoordVar, "actual_max").getAttributeFloat(); - _zMin = _model->getVariableAttribute(_zCoordVar, "actual_min").getAttributeFloat(); - _zMax = _model->getVariableAttribute(_zCoordVar, "actual_max").getAttributeFloat(); + _xMin = _model->getVariableAttribute(_xCoordVar, "actual_min").getAttributeFloat(); + _xMax = _model->getVariableAttribute(_xCoordVar, "actual_max").getAttributeFloat(); + _yMin = _model->getVariableAttribute(_yCoordVar, "actual_min").getAttributeFloat(); + _yMax = _model->getVariableAttribute(_yCoordVar, "actual_max").getAttributeFloat(); + _zMin = _model->getVariableAttribute(_zCoordVar, "actual_min").getAttributeFloat(); + _zMax = _model->getVariableAttribute(_zCoordVar, "actual_max").getAttributeFloat(); _lastiProgress = -1; // For progressbar } @@ -259,6 +259,7 @@ float* KameleonWrapper::getUniformSampledVectorValues(const std::string& xVar, c data[index + 3] = 1.0; // GL_RGB refuses to work. Workaround by doing a GL_RGBA with hardcoded alpha } else { LERROR("Only BATSRUS supported for getUniformSampledVectorValues (for now)"); + return data; } } } @@ -365,6 +366,14 @@ std::vector > KameleonWrapper::getLorentzTrajectories( return trajectories; } +glm::vec3 KameleonWrapper::getModelBarycenterOffset() { + glm::vec3 offset; + offset.x = _xMin+(std::abs(_xMin)+std::abs(_xMax))/2.0f; + offset.y = _yMin+(std::abs(_yMin)+std::abs(_yMax))/2.0f; + offset.z = _zMin+(std::abs(_zMin)+std::abs(_zMax))/2.0f; + return offset; +} + std::vector KameleonWrapper::traceCartesianFieldline( const std::string& xVar, const std::string& yVar, const std::string& zVar, glm::vec3 seedPoint,