Added functionality for getting the model barycenter in kameleonwrapper and moving the raycasting box by an offset. Also cleaned up renderablevolumegl a bit

This commit is contained in:
Hans-Christian Helltegen
2014-07-07 14:26:22 -04:00
parent 1996acf997
commit aff61620c8
5 changed files with 52 additions and 41 deletions

View File

@@ -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);

View File

@@ -35,10 +35,6 @@
#include <ghoul/io/rawvolumereader.h>
#include <ghoul/filesystem/file.h>
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;

View File

@@ -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);

View File

@@ -26,6 +26,7 @@
#include <openspace/rendering/renderablevolumegl.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/util/powerscaledcoordinate.h>
#include <openspace/util/kameleonwrapper.h>
#include <ghoul/opengl/texturereader.h>
#include <ghoul/opencl/clworksize.h>
@@ -34,7 +35,6 @@
#include <algorithm>
#include <openspace/engine/openspaceengine.h>
#include <sgct.h>
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<void*>(0));
//glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*7, reinterpret_cast<void*>(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

View File

@@ -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<std::vector<LinePoint> > 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<glm::vec3> KameleonWrapper::traceCartesianFieldline(
const std::string& xVar, const std::string& yVar,
const std::string& zVar, glm::vec3 seedPoint,