Commit 775f81c2 authored by Maire Nicolas's avatar Maire Nicolas

Implémentation de l'affichage des plans de clipping.

parent 10afca5c
......@@ -77,8 +77,9 @@ void StageShader::slot_explodTopoPhi3(double c)
void StageShader::slot_pushButton_addPlane()
{
m_shader->setClippingPlanesCount(dock.comboBox_PlaneIndex->count() + 1);
m_shader->setPlaneClipping(dock.comboBox_PlaneIndex->count() + 1);
m_shader->setClippingPlaneOrigin(m_bb.center(), dock.comboBox_PlaneIndex->count() + 1 - 1);
std::string indexStr;
std::stringstream ss;
......@@ -97,7 +98,7 @@ void StageShader::slot_pushButton_addPlane()
void StageShader::slot_pushButton_deletePlane()
{
m_shader->setPlaneClipping(dock.comboBox_PlaneIndex->count() - 1);
m_shader->setClippingPlanesCount(dock.comboBox_PlaneIndex->count() - 1);
dock.comboBox_PlaneIndex->removeItem(dock.comboBox_PlaneIndex->count() - 1);
......@@ -111,23 +112,55 @@ void StageShader::slot_comboBox_PlaneIndexChanged(int newIndex)
{
if (newIndex >= 0)
{
Geom::Vec4f currPlaneEquation = m_shader->getClippingPlaneEquation(newIndex);
dock.doubleSpinBox_aPlane->setValue(currPlaneEquation[0]);
dock.doubleSpinBox_bPlane->setValue(currPlaneEquation[1]);
dock.doubleSpinBox_cPlane->setValue(currPlaneEquation[2]);
dock.doubleSpinBox_dPlane->setValue(currPlaneEquation[3]);
Geom::Vec3f currPlaneVec1 = m_shader->getClippingPlaneFirstVec(newIndex);
dock.doubleSpinBox_PlaneVec1x->setValue(currPlaneVec1[0]);
dock.doubleSpinBox_PlaneVec1y->setValue(currPlaneVec1[1]);
dock.doubleSpinBox_PlaneVec1z->setValue(currPlaneVec1[2]);
Geom::Vec3f currPlaneVec2 = m_shader->getClippingPlaneSecondVec(newIndex);
dock.doubleSpinBox_PlaneVec2x->setValue(currPlaneVec2[0]);
dock.doubleSpinBox_PlaneVec2y->setValue(currPlaneVec2[1]);
dock.doubleSpinBox_PlaneVec2z->setValue(currPlaneVec2[2]);
Geom::Vec3f currPlaneOrigin = m_shader->getClippingPlaneOrigin(newIndex);
dock.doubleSpinBox_PlaneOriginx->setValue(currPlaneOrigin[0]);
dock.doubleSpinBox_PlaneOriginy->setValue(currPlaneOrigin[1]);
dock.doubleSpinBox_PlaneOriginz->setValue(currPlaneOrigin[2]);
}
}
void StageShader::slot_doubleSpinBox_Plane(double c)
void StageShader::slot_doubleSpinBox_PlaneVec1(double c)
{
if (dock.comboBox_PlaneIndex->currentIndex() >= 0)
{
float aPlane = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_aPlane->value();
float bPlane = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_bPlane->value();
float cPlane = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_cPlane->value();
float dPlane = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_dPlane->value();
m_shader->setClippingPlaneEquation(Geom::Vec4f(aPlane, bPlane, cPlane, dPlane), dock.comboBox_PlaneIndex->currentIndex());
float x = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec1x->value();
float y = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec1y->value();
float z = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec1z->value();
m_shader->setClippingPlaneFirstVec(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex());
updateGL();
}
}
void StageShader::slot_doubleSpinBox_PlaneVec2(double c)
{
if (dock.comboBox_PlaneIndex->currentIndex() >= 0)
{
float x = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec2x->value();
float y = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec2y->value();
float z = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec2z->value();
m_shader->setClippingPlaneSecondVec(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex());
updateGL();
}
}
void StageShader::slot_doubleSpinBox_PlaneOrigin(double c)
{
if (dock.comboBox_PlaneIndex->currentIndex() >= 0)
{
float x = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneOriginx->value();
float y = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneOriginy->value();
float z = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneOriginz->value();
m_shader->setClippingPlaneOrigin(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex());
updateGL();
}
}
......@@ -190,10 +223,17 @@ void StageShader::initGUI()
setCallBack(dock.comboBox_PlaneIndex, SIGNAL(currentIndexChanged(int)), SLOT(slot_comboBox_PlaneIndexChanged(int)));
setCallBack(dock.doubleSpinBox_aPlane, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_Plane(double)));
setCallBack(dock.doubleSpinBox_bPlane, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_Plane(double)));
setCallBack(dock.doubleSpinBox_cPlane, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_Plane(double)));
setCallBack(dock.doubleSpinBox_dPlane, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_Plane(double)));
setCallBack(dock.doubleSpinBox_PlaneVec1x, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_PlaneVec1(double)));
setCallBack(dock.doubleSpinBox_PlaneVec1y, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_PlaneVec1(double)));
setCallBack(dock.doubleSpinBox_PlaneVec1z, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_PlaneVec1(double)));
setCallBack(dock.doubleSpinBox_PlaneVec2x, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_PlaneVec2(double)));
setCallBack(dock.doubleSpinBox_PlaneVec2y, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_PlaneVec2(double)));
setCallBack(dock.doubleSpinBox_PlaneVec2z, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_PlaneVec2(double)));
setCallBack(dock.doubleSpinBox_PlaneOriginx, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_PlaneOrigin(double)));
setCallBack(dock.doubleSpinBox_PlaneOriginy, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_PlaneOrigin(double)));
setCallBack(dock.doubleSpinBox_PlaneOriginz, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_PlaneOrigin(double)));
setCallBack(dock.doubleSpinBox_ColorAttenuationFactor, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_ColorAttenuationFactor(double)));
......@@ -248,11 +288,11 @@ void StageShader::importMesh(std::string& filename)
m_render_topo->updateData<PFP>(myMap, allDarts, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2]);
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
gPosObj = bb.center() ;
float tailleX = bb.size(0) ;
float tailleY = bb.size(1) ;
float tailleZ = bb.size(2) ;
m_bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
gPosObj = m_bb.center() ;
float tailleX = m_bb.size(0) ;
float tailleY = m_bb.size(1) ;
float tailleZ = m_bb.size(2) ;
gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ) ;
m_positionVBO->updateData(position) ;
......@@ -260,6 +300,8 @@ void StageShader::importMesh(std::string& filename)
setParamObject(gWidthObj, gPosObj.data()) ;
updateGLMatrices() ;
m_shader->setPlaneDisplaySize((m_bb.maxSize())*1.2f);
}
/*******************************************************************************
......@@ -333,6 +375,8 @@ void StageShader::cb_redraw()
if (m_drawTopo)
m_render_topo->drawTopo();
m_shader->displayClippingPlanes();
}
void StageShader::cb_keyPress(int code)
......
......@@ -87,6 +87,8 @@ public:
Algo::Render::GL2::MapRender* m_render;
Algo::Render::GL2::Topo3RenderMapD* m_render_topo;
Geom::BoundingBox<PFP::VEC3> m_bb;
Utils::VBO* m_positionVBO;
Utils::ShaderSimpleColor* m_shader;
......@@ -127,7 +129,9 @@ public slots:
void slot_comboBox_PlaneIndexChanged(int newIndex);
void slot_doubleSpinBox_Plane(double c);
void slot_doubleSpinBox_PlaneVec1(double c);
void slot_doubleSpinBox_PlaneVec2(double c);
void slot_doubleSpinBox_PlaneOrigin(double c);
void slot_doubleSpinBox_ColorAttenuationFactor(double c);
......
This diff is collapsed.
......@@ -123,7 +123,7 @@ void Stage_shader_number_two::cb_initGL()
registerShader(m_simpleColorShader) ;
registerShader(m_pointSprite) ;
m_phongShader->setPlaneClipping(1);
m_phongShader->setClippingPlanesCount(1);
}
void Stage_shader_number_two::cb_redraw()
......@@ -170,7 +170,7 @@ void Stage_shader_number_two::cb_redraw()
glDisable(GL_POLYGON_OFFSET_FILL) ;
}
m_phongShader->displayClippingPlane();
m_phongShader->displayClippingPlanes();
}
void Stage_shader_number_two::cb_Open()
......@@ -199,11 +199,15 @@ void Stage_shader_number_two::cb_mouseMove(int button, int x, int y)
{
if (button == Qt::LeftButton)
{
Geom::Vec4f clipPlane = m_phongShader->getClippingPlaneEquation();
clipPlane[0] += (m_mouseLastX - x)/40.0;
clipPlane[1] += (m_mouseLastY - y)/40.0;
Geom::Vec3f clipPlaneVec1 = m_phongShader->getClippingPlaneFirstVec();
Geom::Vec3f clipPlaneVec2 = m_phongShader->getClippingPlaneSecondVec();
clipPlaneVec1[0] += (m_mouseLastX - x)/40.0;
clipPlaneVec1[1] += (m_mouseLastY - y)/40.0;
clipPlaneVec2[1] += (m_mouseLastX - x)/40.0;
clipPlaneVec2[2] += (m_mouseLastY - y)/40.0;
m_phongShader->setClippingPlaneEquation(clipPlane);
m_phongShader->setClippingPlaneFirstVec(clipPlaneVec1);
m_phongShader->setClippingPlaneSecondVec(clipPlaneVec2);
updateGL();
}
......@@ -241,6 +245,9 @@ void Stage_shader_number_two::importMesh(std::string& filename)
setParamObject(bb.maxSize(), bb.center().data()) ;
updateGLMatrices() ;
m_phongShader->setPlaneDisplaySize(bb.maxSize()*1.2f);
m_phongShader->setClippingPlaneOrigin(bb.center());
}
void Stage_shader_number_two::slot_drawVertices(bool b)
......@@ -291,7 +298,7 @@ void Stage_shader_number_two::slot_doubleSpinBox_Plane(double c)
float bPlane = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_plane_b->value();
float cPlane = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_plane_c->value();
float dPlane = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_plane_d->value();
m_phongShader->setClippingPlaneEquation(Geom::Vec4f(aPlane, bPlane, cPlane, dPlane));
//m_phongShader->setClippingPlaneEquation(Geom::Vec4f(aPlane, bPlane, cPlane, dPlane));
updateGL();
}
......
......@@ -61,6 +61,9 @@
</item>
<item>
<widget class="QComboBox" name="combo_faceLighting">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<item>
<property name="text">
<string>FLAT</string>
......
......@@ -55,30 +55,59 @@ public:
~ClippingShader();
/**
* set the plane equation for plane clipping
* set all parameters for one clipping plane
* @warning planeIndex starts at 0
* @param clipPlane plane equation
* @param planeIndex index of plane to modify
* @param vec1 first basis vector
* @param vec2 second basis vector
* @param origin point of the plane that will be used as origin to display it
* @param planeIndex index of the plane to modify
*/
void setClippingPlaneEquation(Geom::Vec4f clipPlane, int planeIndex = 0);
void setClippingPlane(Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin, int planeIndex = 0);
/**
* get the plane equation for plane clipping
* set first vector parameter for one clipping plane
* @warning planeIndex starts at 0
* @param planeIndex index of plane to get
* @param vec1 first basis vector
* @param planeIndex index of the plane to modify
*/
Geom::Vec4f getClippingPlaneEquation(int planeIndex = 0);
void setClippingPlaneFirstVec(Geom::Vec3f vec1, int planeIndex = 0);
/**
* set the plane quaternion for plane clipping
* @param quat plane quaternion
* set second vector parameter for one clipping plane
* @warning planeIndex starts at 0
* @param vec2 second basis vector
* @param planeIndex index of the plane to modify
*/
void setClippingPlaneSecondVec(Geom::Vec3f vec2, int planeIndex = 0);
/**
* set origin parameter for one clipping plane
* @warning planeIndex starts at 0
* @param origin point of the plane that will be used as origin to display it
* @param planeIndex index of the plane to modify
*/
void setClippingPlaneOrigin(Geom::Vec3f origin, int planeIndex = 0);
/**
* get first parameter for one clipping plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify
*/
Geom::Vec3f getClippingPlaneFirstVec(int planeIndex = 0);
/**
* get second vector parameter for one clipping plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify
*/
//void setClippingPlaneQuaternion(float quat[4]);
Geom::Vec3f getClippingPlaneSecondVec(int planeIndex = 0);
/**
* get the plane quaternion for plane clipping
* get origin parameter for one clipping plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify
*/
//Geom::Vec4f getClippingPlaneQuaternion();
Geom::Vec3f getClippingPlaneOrigin(int planeIndex = 0);
/**
* set the color attenuation factor for clipping
......@@ -89,34 +118,54 @@ public:
/**
* get the color attenuation factor for clipping
*/
float getClippingColorAttenuationFactor();
float getClippingColorAttenuationFactor() { return m_colorAttenuationFactor; }
/**
* insert plane clipping instructions into vertex and fragment shader source code
* - does not modify the geometry shader source code
* set the clipping planes count used for plane clipping
* - insert plane clipping instructions into vertex and fragment shader source code
* but does not modify the geometry shader source code
* @param planesCount the clipping planes count to use
* @warning this function is designed for shaders which *do not* use a geometry shader
*/
void setPlaneClipping(int planesCount);
void setClippingPlanesCount(int planesCount);
/**
* get the clipping planes count used for plane clipping
*/
int getClippingPlanesCount() { return (int)m_clipPlanesEquations.size() / 4; }
int getClippingPlanesCount() { return (int)m_clipPlanes.size(); }
/**
* update uniforms (get their locations and resend their values) for clipping
* update uniforms (get their locations and send their values again) for clipping
*/
void updateClippingUniforms();
/**
* displays a quad corresponding to the current clipping plane position and orientation
* display all clipping planes
*/
void displayClippingPlane();
void displayClippingPlanes();
/**
* set the plane display size
* @param size the new size
*/
void setPlaneDisplaySize(float size) { m_planeDisplaySize = size; }
/**
* get the plane display size
*/
float getPlaneDisplaySize() { return m_planeDisplaySize; }
private:
/**
* clipping planes structure
*/
struct clipPlane
{
Geom::Vec3f firstVec, secondVec, origin;
};
/**
* sends the clipping planes uniform to shader
*/
......@@ -128,29 +177,36 @@ private:
void sendColorAttenuationFactorUniform();
/**
* stored original vertex shader source code (without clipping)
* update VBO for one plane(recalculate quad)
* @param planeIndex index of the plane
*/
void updateClippingPlaneVBO(int planeIndex);
/**
* original vertex shader source code (without clipping)
*/
std::string originalVertShaderSrc;
/**
* stored original fragment shader source code (without clipping)
* original fragment shader source code (without clipping)
*/
std::string originalFragShaderSrc;
/**
* clip planes equations (a, b, c, d)*planes count
* clip planes array
*/
std::vector<float> m_clipPlanesEquations;
std::vector<clipPlane> m_clipPlanes;
/**
* clip plane quaternion
* clip planes equations array (size = 4*(planes count))
* - used only for sending planes data to shader
*/
//float m_clipPlaneQuaternion[4];
std::vector<float> m_clipPlanesEquations;
/**
* clip planes vector uniform id
* clip planes equations vector uniform id
*/
GLint m_unif_clipPlanes;
GLint m_unif_clipPlanesEquations;
/**
* color attenuation factor
......@@ -163,9 +219,14 @@ private:
GLint m_unif_colorAttenuationFactor;
/**
* plane drawer
* clip planes drawers array
*/
std::vector<Drawer*> m_clipPlanesDrawers;
/**
* plane display size
*/
Drawer* m_planeDrawer;
float m_planeDisplaySize;
};
......
......@@ -42,7 +42,7 @@ class ShaderMutator
public:
/**
* enums used to choose which shader src to modify
* enums used to choose which shader src type to modify
*/
enum shaderSrcType { VERTEX_SHADER, FRAGMENT_SHADER, GEOMETRY_SHADER };
......
This diff is collapsed.
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