Commit d22f598c authored by Stefan Pfeifer's avatar Stefan Pfeifer

Implement symmetric viewing of both limbs

parent 2399d9ec
Pipeline #41168842 passed with stage
in 9 minutes and 10 seconds
......@@ -151,6 +151,8 @@ add_library(
source/gui/input/editors/TreeEditor.cpp
source/gui/input/editors/TreeEditor.hpp
source/gui/input/editors/TreeItem.hpp
source/gui/input/views/AABB.cpp
source/gui/input/views/AABB.hpp
source/gui/input/views/LayerLegend.cpp
source/gui/input/views/LayerLegend.hpp
source/gui/input/views/LimbView.cpp
......
#pragma once
#include <QVector3D>
class AABB
{
public:
AABB(): AABB(max_inf(), min_inf())
{
}
AABB(const QVector3D& vec_min, const QVector3D& vec_max)
: vec_min(vec_min), vec_max(vec_max)
{
}
AABB extend(const AABB& other) const
{
return {
min(vec_min, other.vec_min),
max(vec_max, other.vec_max)
};
}
AABB extend(const QVector3D& point) const
{
return {
min(vec_min, point),
max(vec_max, point)
};
}
QVector3D center() const
{
return (vec_min + vec_max)/2.0f;
}
float diagonal() const
{
return (vec_max - vec_min).length();
}
private:
QVector3D vec_min;
QVector3D vec_max;
QVector3D min(const QVector3D& vec1, const QVector3D& vec2) const
{
return {
std::min(vec1.x(), vec2.x()),
std::min(vec1.y(), vec2.y()),
std::min(vec1.z(), vec2.z())
};
}
QVector3D max(const QVector3D& vec1, const QVector3D& vec2) const
{
return {
std::max(vec1.x(), vec2.x()),
std::max(vec1.y(), vec2.y()),
std::max(vec1.z(), vec2.z())
};
}
QVector3D min_inf() const
{
return {
-std::numeric_limits<float>::infinity(),
-std::numeric_limits<float>::infinity(),
-std::numeric_limits<float>::infinity()
};
}
QVector3D max_inf() const
{
return {
std::numeric_limits<float>::infinity(),
std::numeric_limits<float>::infinity(),
std::numeric_limits<float>::infinity()
};
}
};
......@@ -5,7 +5,8 @@
#include "numerics/CubicSpline.hpp"
LimbMesh::LimbMesh(bool inverted)
: inverted(inverted)
: visible(true),
inverted(inverted)
{
}
......@@ -13,8 +14,7 @@ LimbMesh::LimbMesh(bool inverted)
void LimbMesh::setData(const InputData& data)
{
vertex_data.clear();
aabb_min = QVector3D();
aabb_max = QVector3D();
bounding_box = AABB();
// Todo: Abstract away the conversion data -> profile curve
std::vector<double> lengths = getEvalLengths(data, 100);
......@@ -168,14 +168,19 @@ size_t LimbMesh::vertexCount() const
return vertex_data.size()/9;
}
QVector3D LimbMesh::aabbCenter() const
const AABB LimbMesh::aabb() const
{
return (aabb_min + aabb_max)/2.0f;
return bounding_box;
}
float LimbMesh::aabbDiagonal() const
bool LimbMesh::isVisible() const
{
return (aabb_max - aabb_min).length();
return visible;
}
void LimbMesh::setVisible(bool value)
{
visible = value;
}
void LimbMesh::addQuad(QVector3D p0, QVector3D p1, QVector3D p2, QVector3D p3, const QColor& color)
......@@ -217,13 +222,5 @@ void LimbMesh::addVertex(const QVector3D& position, const QVector3D& normal, con
vertex_data.push_back(color.greenF());
vertex_data.push_back(color.blueF());
// Todo: Is there a vector operation for this in Eigen?
aabb_min.setX(std::min(aabb_min.x(), position.x()));
aabb_min.setY(std::min(aabb_min.y(), position.y()));
aabb_min.setZ(std::min(aabb_min.z(), position.z()));
// Todo: Is there a vector operation for this in Eigen?
aabb_max.setX(std::max(aabb_max.x(), position.x()));
aabb_max.setY(std::max(aabb_max.y(), position.y()));
aabb_max.setZ(std::max(aabb_max.z(), position.z()));
bounding_box = bounding_box.extend(position);
}
#pragma once
#include "bow/input/InputData.hpp"
#include "numerics/Eigen.hpp"
#include "AABB.hpp"
#include <qopengl.h>
#include <QVector3D>
#include <QColor>
......@@ -13,17 +14,18 @@ public:
const std::vector<GLfloat>& vertexData() const;
size_t vertexCount() const;
const AABB aabb() const;
QVector3D aabbCenter() const;
float aabbDiagonal() const;
bool isVisible() const;
void setVisible(bool value);
private:
void addQuad(QVector3D p0, QVector3D p1, QVector3D p2, QVector3D p3, const QColor& color);
void addVertex(const QVector3D& position, const QVector3D& normal, const QColor& color);
std::vector<double> getEvalLengths(const InputData& data, unsigned n);
bool visible;
bool inverted;
std::vector<GLfloat> vertex_data;
QVector3D aabb_min;
QVector3D aabb_max;
AABB bounding_box;
};
......@@ -4,7 +4,6 @@
#include <QMouseEvent>
#include <QOpenGLShaderProgram>
#include <QCoreApplication>
#include <math.h>
LimbView::LimbView()
: legend(new LayerLegend()),
......@@ -64,6 +63,7 @@ LimbView::LimbView()
vbox->addStretch();
vbox->addLayout(hbox);
viewSymmetric(false);
view3D();
}
......@@ -78,8 +78,8 @@ void LimbView::setData(const InputData& data)
limb_mesh_left.setData(data);
limb_mesh_right.setData(data);
//limb_mesh_left_vbo.bind();
//limb_mesh_left_vbo.allocate(limb_mesh_left.vertexData().data(), limb_mesh_left.vertexData().size()*sizeof(GLfloat));
limb_mesh_left_vbo.bind();
limb_mesh_left_vbo.allocate(limb_mesh_left.vertexData().data(), limb_mesh_left.vertexData().size()*sizeof(GLfloat));
limb_mesh_right_vbo.bind();
limb_mesh_right_vbo.allocate(limb_mesh_right.vertexData().data(), limb_mesh_right.vertexData().size()*sizeof(GLfloat));
......@@ -110,7 +110,9 @@ void LimbView::view3D()
void LimbView::viewSymmetric(bool checked)
{
limb_mesh_left.setVisible(checked);
limb_mesh_right.setVisible(true);
update();
}
void LimbView::viewFit()
......@@ -127,7 +129,7 @@ void LimbView::cleanup()
return;
makeCurrent();
//limb_mesh_left_vbo.destroy();
limb_mesh_left_vbo.destroy();
limb_mesh_right_vbo.destroy();
delete shader_program;
shader_program = nullptr;
......@@ -193,34 +195,40 @@ void LimbView::initializeGL()
loc_normalMatrix = shader_program->uniformLocation("normalMatrix");
loc_lightPosition = shader_program->uniformLocation("lightPosition");
// Setup vertex buffer object.
// limb_mesh_left_vbo.create();
// limb_mesh_left_vbo.bind();
// limb_mesh_left_vbo.allocate(limb_mesh_left.vertexData().data(), limb_mesh_left.vertexData().size()*sizeof(GLfloat));
// Store the vertex attribute bindings for the program.
// limb_mesh_left_vbo.bind();
// glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(0*sizeof(GLfloat)));
// glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(3*sizeof(GLfloat)));
// glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(6*sizeof(GLfloat)));
// glEnableVertexAttribArray(0);
// glEnableVertexAttribArray(1);
// glEnableVertexAttribArray(2);
// limb_mesh_left_vbo.release();
// Setup vertex buffer object.
// Create a vertex array object. In OpenGL ES 2.0 and OpenGL 2.x
// implementations this is optional and support may not be present
// at all. Nonetheless the below code works in all cases and makes
// sure there is a VAO when one is needed.
m_vao.create();
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
// Setup vertex buffer object and vertex attributes for right limb
limb_mesh_left_vbo.create();
limb_mesh_left_vbo.bind();
limb_mesh_left_vbo.allocate(limb_mesh_left.vertexData().data(), limb_mesh_left.vertexData().size()*sizeof(GLfloat));
/*
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(0*sizeof(GLfloat)));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(3*sizeof(GLfloat)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(6*sizeof(GLfloat)));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
*/
limb_mesh_left_vbo.release();
// Setup vertex buffer object and vertex attributes for right limb
limb_mesh_right_vbo.create();
limb_mesh_right_vbo.bind();
limb_mesh_right_vbo.allocate(limb_mesh_right.vertexData().data(), limb_mesh_right.vertexData().size()*sizeof(GLfloat));
// Store the vertex attribute bindings for the program.
limb_mesh_right_vbo.bind();
/*
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(0*sizeof(GLfloat)));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(3*sizeof(GLfloat)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(6*sizeof(GLfloat)));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
*/
limb_mesh_right_vbo.release();
// Set fixed light position
......@@ -235,12 +243,17 @@ void LimbView::paintGL()
glEnable(GL_CULL_FACE);
glEnable(GL_MULTISAMPLE);
AABB content_bounds;
if(limb_mesh_left.isVisible())
content_bounds = content_bounds.extend(limb_mesh_left.aabb());
if(limb_mesh_right.isVisible())
content_bounds = content_bounds.extend(limb_mesh_right.aabb());
m_world.setToIdentity();
m_world.rotate(rot_x, 1.0f, 0.0f, 0.0f);
m_world.rotate(rot_y, 0.0f, 1.0f, 0.0f);
m_world.scale(1.0f/limb_mesh_right.aabbDiagonal());
m_world.translate(-limb_mesh_right.aabbCenter());
m_world.scale(1.0f/content_bounds.diagonal());
m_world.translate(-content_bounds.center());
m_camera.setToIdentity();
m_camera.translate(0.0f, 0.0f, -1.0f);
......@@ -252,13 +265,39 @@ void LimbView::paintGL()
( 0.5f*zoom + shift_y)*aspect_ratio,
0.001f, 100.0f);
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
shader_program->bind();
shader_program->setUniformValue(loc_projectionMatrix, m_projection);
shader_program->setUniformValue(loc_modelViewMatrix, m_camera*m_world);
shader_program->setUniformValue(loc_normalMatrix, m_world.normalMatrix());
// glDrawArrays(GL_TRIANGLES, 0, limb_mesh_left.vertexCount());
glDrawArrays(GL_TRIANGLES, 0, limb_mesh_right.vertexCount());
if(limb_mesh_left.isVisible())
{
limb_mesh_left_vbo.bind();
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(0*sizeof(GLfloat)));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(3*sizeof(GLfloat)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(6*sizeof(GLfloat)));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glDrawArrays(GL_TRIANGLES, 0, limb_mesh_left.vertexCount());
limb_mesh_left_vbo.release();
}
if(limb_mesh_right.isVisible())
{
limb_mesh_right_vbo.bind();
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(0*sizeof(GLfloat)));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(3*sizeof(GLfloat)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(6*sizeof(GLfloat)));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glDrawArrays(GL_TRIANGLES, 0, limb_mesh_right.vertexCount());
limb_mesh_right_vbo.release();
}
shader_program->release();
}
......
......@@ -46,7 +46,8 @@ private:
LayerLegend* legend;
LimbMesh limb_mesh_left;
LimbMesh limb_mesh_right;
//QOpenGLBuffer limb_mesh_left_vbo;
QOpenGLVertexArrayObject m_vao;
QOpenGLBuffer limb_mesh_left_vbo;
QOpenGLBuffer limb_mesh_right_vbo;
QOpenGLShaderProgram* shader_program;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment