Commit dd2af627 authored by Sylvain Thery's avatar Sylvain Thery

Enhancement of explode volume rendering

- color per vertex of face of volume
  -> can be used in per volume/face/vertex
some minor bugs & modifs
parent 5c8a97cf
......@@ -29,10 +29,12 @@
#include "Algo/Modelisation/primitives3d.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Import/import.h"
#include "Algo/Geometry/volume.h"
PFP::MAP myMap;
PFP::TVEC3 position ;
PFP::TVEC3 color ;
void MyQT::volumes_onoff(bool x)
{
......@@ -52,7 +54,7 @@ void MyQT::topo_onoff(bool x)
if (render_topo)
{
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, 0.8f, m_explode_factor, nb);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, m_explode_factorf-0.05f, m_explode_factor, nb);
}
updateGL();
......@@ -92,11 +94,18 @@ void MyQT::hide_onoff(bool x)
void MyQT::slider_explode(int x)
{
m_explode_factor = 0.01f*(x+1);
m_explode_factor = 0.01f*(x+1)-0.0001f;
m_explode_render->setExplodeVolumes(m_explode_factor);
updateGL();
}
void MyQT::slider_explodeF(int x)
{
m_explode_factorf = 0.01f*(x+1);
m_explode_render->setExplodeFaces(m_explode_factorf);
updateGL();
}
void MyQT::slider_pressed()
{
......@@ -113,7 +122,7 @@ void MyQT::slider_released()
if (render_topo)
{
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, 0.8f, m_explode_factor, nb);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, m_explode_factorf-0.05f, m_explode_factor, nb);
}
updateGL();
}
......@@ -126,14 +135,15 @@ void MyQT::cb_initGL()
// create the renders
m_topo_render = new Algo::Render::GL2::Topo3Render();
m_explode_render = new Algo::Render::GL2::ExplodeVolumeRender();
m_explode_render = new Algo::Render::GL2::ExplodeVolumeRender(true,true);
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, 0.8f, 0.8f, nb);
m_explode_render->updateData<PFP>(myMap,position);
m_explode_render->updateData<PFP>(myMap,position,color);
m_explode_render->setExplodeVolumes(0.8f);
m_explode_render->setExplodeFaces(0.9f);
m_explode_render->setAmbiant(Geom::Vec4f(0.2f,0.2f,0.2f,1.0f));
m_explode_render->setDiffuse(Geom::Vec4f(0.6f,0.6f,0.9f,1.0f));
m_explode_render->setBackColor(Geom::Vec4f(0.9f,0.9f,0.9f,1.0f));
m_explode_render->setColorLine(Geom::Vec4f(0.8f,0.2f,0.2f,1.0f));
registerShader(m_explode_render->shaderFaces());
......@@ -214,8 +224,6 @@ void MyQT::cb_mousePress(int button, int x, int y)
if (fr_picked != 0)
{
m_pickedAxis=fr_picked;
std::cout << "PICKED:"<< m_pickedAxis << std::endl;
m_frame->highlight(m_pickedAxis);
m_frame->storeProjection(m_pickedAxis);
updateGL();
......@@ -311,14 +319,36 @@ int main(int argc, char **argv)
else
position = myMap.getAttribute<PFP::VEC3>(VERTEX , attrNames[0]) ;
}
color = myMap.addAttribute<PFP::VEC3>(VOLUME, "color");
TraversorCell<PFP::MAP> tra(myMap,VOLUME);
float maxV=0.0f;
for (Dart d = tra.begin(); d != tra.end(); d=tra.next())
{
float v = Algo::Geometry::tetrahedronVolume<PFP>(myMap,d,position);
color[d] = PFP::VEC3(v,0,0);
if (v>maxV)
maxV=v;
}
for (unsigned int i = color.begin(); i!=color.end(); color.next(i))
{
color[i][0] /= maxV;
color[i][2] = 1.0f -color[i][0];
}
}
else
{
position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
Algo::Modelisation::Primitive3D<PFP> prim(myMap, position);
int nb = 10;
int nb = 32;
prim.hexaGrid_topo(nb,nb,nb);
prim.embedHexaGrid(1.0f,1.0f,1.0f);
color = myMap.addAttribute<PFP::VEC3>(VOLUME, "color");
TraversorCell<PFP::MAP> tra(myMap,VOLUME);
for (Dart d = tra.begin(); d != tra.end(); d=tra.next())
color[d] = position[d] + PFP::VEC3(0.5,0.5,0.5);
}
// un peu d'interface
QApplication app(argc, argv);
......@@ -348,9 +378,16 @@ int main(int argc, char **argv)
sqt.setCallBack( dock.slider_explode, SIGNAL(sliderPressed()), SLOT(slider_pressed()) );
sqt.setCallBack( dock.slider_explode, SIGNAL(sliderReleased()), SLOT(slider_released()) );
sqt.setCallBack( dock.slider_explode_face, SIGNAL(valueChanged(int)), SLOT(slider_explodeF(int)) );
sqt.setCallBack( dock.slider_explode_face, SIGNAL(sliderPressed()), SLOT(slider_pressed()) );
sqt.setCallBack( dock.slider_explode_face, SIGNAL(sliderReleased()), SLOT(slider_released()) );
sqt.show();
dock.slider_explode->setValue(80);
dock.slider_explode_face->setValue(80);
sqt.clipping_onoff(true);
// et on attend la fin.
......
......@@ -87,6 +87,7 @@ class MyQT: public Utils::QT::SimpleQT
Algo::Render::GL2::ExplodeVolumeRender* m_explode_render;
float m_explode_factor;
float m_explode_factorf;
// for clipping plane manipulation
Utils::Pickable* m_PlanePick;
......@@ -132,6 +133,7 @@ public slots:
void slider_explode(int x);
void slider_pressed();
void slider_released();
void slider_explodeF(int x);
};
#endif
......@@ -84,6 +84,13 @@
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="slider_explode_face">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
......@@ -133,5 +140,22 @@
</widget>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>checkBox_plane</sender>
<signal>clicked(bool)</signal>
<receiver>checkBox_hide</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>74</x>
<y>174</y>
</hint>
<hint type="destinationlabel">
<x>74</x>
<y>200</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -34,19 +34,19 @@ namespace Modelisation
namespace Tetrahedralization
{
template <typename PFP>
void hexahedronToTetrahedron(typename PFP::MAP& map, Dart d)
{
Dart d1 = d;
Dart d2 = map.phi1(map.phi1(d));
Dart d3 = map.phi_1(map.phi2(d));
Dart d4 = map.phi1(map.phi1(map.phi2(map.phi_1(d3))));
cut3Ear<PFP>(map,d1);
cut3Ear<PFP>(map,d2);
cut3Ear<PFP>(map,d3);
cut3Ear<PFP>(map,d4);
}
//template <typename PFP>
//void hexahedronToTetrahedron(typename PFP::MAP& map, Dart d)
//{
// Dart d1 = d;
// Dart d2 = map.phi1(map.phi1(d));
// Dart d3 = map.phi_1(map.phi2(d));
// Dart d4 = map.phi1(map.phi1(map.phi2(map.phi_1(d3))));
//
// cut3Ear<PFP>(map,d1);
// cut3Ear<PFP>(map,d2);
// cut3Ear<PFP>(map,d3);
// cut3Ear<PFP>(map,d4);
//}
/************************************************************************************************
* Tetrahedron functions *
......
......@@ -58,10 +58,14 @@ protected:
bool m_cpf;
bool m_ef;
Utils::ShaderExplodeVolumesLines* m_shaderL;
Utils::VBO* m_vboPos;
Utils::VBO* m_vboColors;
Utils::VBO* m_vboPosLine;
/**
......@@ -71,23 +75,23 @@ protected:
GLuint m_nbLines;
Geom::Vec3f m_globalColor;
public:
/**
* Constructor
* @param map the map to draw
* @param good functor that return true for darts of part to draw
* @param type_vbo vbo to alloc ( VBO_P, VBO_PN, VBO_PNC, VBO_PC ..)
* @param withColorPerFace affect a color per face
* @param withExplodeFace shrinj each face
*/
ExplodeVolumeRender(bool withColorPerFace=false) ;
ExplodeVolumeRender(bool withColorPerFace=false, bool withExplodeFace=false) ;
/**
* Destructor
*/
~ExplodeVolumeRender() ;
/**
* return a ptr on used shader do not forgot to register
*/
......@@ -98,15 +102,14 @@ public:
*/
Utils::GLSLShader* shaderLines() ;
/**
* update all drawing buffers
* @param map the map
* @param positions attribute of position vertices
* @param good selector
*/
template<typename PFP>
void updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, const FunctorSelect& good = allDarts) ;
// template<typename PFP>
// void updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, const FunctorSelect& good = allDarts) ;
/**
* update all drawing buffers
......@@ -133,6 +136,11 @@ public:
*/
void setExplodeVolumes(float explode) ;
/**
* set exploding volume coefficient parameter
*/
void setExplodeFaces(float explode) ;
/**
* set clipping plane
*/
......@@ -149,9 +157,9 @@ public:
void setAmbiant(const Geom::Vec4f& ambiant) ;
/**
* set diffuse color parameter
* set back color parameter
*/
void setDiffuse(const Geom::Vec4f& diffuse) ;
void setBackColor(const Geom::Vec4f& color) ;
/**
* set light position parameter
......
......@@ -40,20 +40,22 @@ namespace Render
namespace GL2
{
inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace):
m_cpf(withColorPerFace)
inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace, bool withExplodeFace):
m_cpf(withColorPerFace),m_ef(withExplodeFace),m_globalColor(0.7f,0.7f,0.7f)
{
m_vboPos = new Utils::VBO();
m_vboPos->setDataSize(3);
m_vboColors = new Utils::VBO();
m_vboColors->setDataSize(3);
m_vboPosLine = new Utils::VBO();
m_vboPosLine->setDataSize(3);
m_shader = new Utils::ShaderExplodeVolumes(withColorPerFace);
m_shader = new Utils::ShaderExplodeVolumes(withColorPerFace,withExplodeFace);
m_shaderL = new Utils::ShaderExplodeVolumesLines();
// m_shader->setAmbiant(Geom::Vec4f(0.1f,0.1f,0.1f,0.0f));
// m_shader->setDiffuse(Geom::Vec4f(1.0f,1.0f,0.1f,0.0f));
m_shaderL->setColor(Geom::Vec4f(1.0f,1.0f,1.0f,0.0f));
......@@ -62,90 +64,113 @@ inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace):
inline ExplodeVolumeRender::~ExplodeVolumeRender()
{
delete m_vboPos;
delete m_vboColors;
delete m_vboPosLine;
delete m_shader;
delete m_shaderL;
}
template<typename PFP>
void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, const FunctorSelect& good)
{
if (m_cpf)
{
CGoGNerr<< "ExplodeVolumeRender: problem wrong update fonction use the other" << CGoGNendl;
return;
}
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
CellMarker cmv(map,VOLUME);
AutoAttributeHandler<VEC3> centerVolumes(map,VOLUME,"centerVolumes");
TraversorW<typename PFP::MAP> traVol(map,good);
for (Dart d=traVol.begin(); d!=traVol.end(); d=traVol.next())
{
centerVolumes[d] = Algo::Geometry::volumeCentroid<PFP>(map, d, positions);
}
std::vector<VEC3> buffer;
buffer.reserve(16384);
TraversorCell<typename PFP::MAP> traFace(map, PFP::MAP::ORBIT_IN_PARENT(FACE),good);
for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next())
{
Dart a = d;
Dart b = map.phi1(a);
Dart c = map.phi1(b);
// loop to cut a polygon in triangle on the fly (works only with convex faces)
do
{
buffer.push_back(centerVolumes[d]);
buffer.push_back(positions[d]);
buffer.push_back(positions[b]);
buffer.push_back(positions[c]);
b = c;
c = map.phi1(b);
} while (c != d);
}
m_nbTris = buffer.size()/4;
m_vboPos->allocate(buffer.size());
VEC3* ptrPos = reinterpret_cast<VEC3*>(m_vboPos->lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
m_vboPos->releasePtr();
m_shader->setAttributePosition(m_vboPos);
buffer.clear();
TraversorCell<typename PFP::MAP> traEdge(map, PFP::MAP::ORBIT_IN_PARENT(EDGE),good);
for (Dart d=traEdge.begin(); d!=traEdge.end(); d=traEdge.next())
{
buffer.push_back(centerVolumes[d]);
buffer.push_back(positions[d]);
buffer.push_back(positions[ map.phi1(d)]);
}
m_nbLines = buffer.size()/3;
m_vboPosLine->allocate(buffer.size());
ptrPos = reinterpret_cast<VEC3*>(m_vboPosLine->lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
m_vboPosLine->releasePtr();
m_shaderL->setAttributePosition(m_vboPosLine);
}
//template<typename PFP>
//void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, const FunctorSelect& good)
//{
// if (m_cpf)
// {
// CGoGNerr<< "ExplodeVolumeRender: problem wrong update fonction use the other" << CGoGNendl;
// return;
// }
//
// typedef typename PFP::VEC3 VEC3;
// typedef typename PFP::REAL REAL;
//
// CellMarker cmv(map,VOLUME);
// AutoAttributeHandler<VEC3> centerVolumes(map,VOLUME,"centerVolumes");
// TraversorW<typename PFP::MAP> traVol(map,good);
// for (Dart d=traVol.begin(); d!=traVol.end(); d=traVol.next())
// {
// centerVolumes[d] = Algo::Geometry::volumeCentroid<PFP>(map, d, positions);
// }
//
// std::vector<VEC3> buffer;
// buffer.reserve(16384);
//
//
// TraversorCell<typename PFP::MAP> traFace(map, PFP::MAP::ORBIT_IN_PARENT(FACE),good);
//
// for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next())
// {
// if (m_ef)
// {
// VEC3 centerFace = Algo::Geometry::faceCentroid<PFP>(map,d,positions);
// Dart a = d;
// Dart b = map.phi1(a);
// Dart c = map.phi1(b);
//
// // loop to cut a polygon in triangle on the fly (works only with convex faces)
// do
// {
// buffer.push_back(centerVolumes[d]);
// buffer.push_back(positions[d]);
// buffer.push_back(positions[b]);
// buffer.push_back(positions[c]);
// buffer.push_back(centerFace); // not used
// buffer.push_back(centerFace);
// b = c;
// c = map.phi1(b);
//
// } while (c != d);
// }
// else
// {
// Dart a = d;
// Dart b = map.phi1(a);
// Dart c = map.phi1(b);
//
// // loop to cut a polygon in triangle on the fly (works only with convex faces)
// do
// {
// buffer.push_back(centerVolumes[d]);
// buffer.push_back(positions[d]);
// buffer.push_back(positions[b]);
// buffer.push_back(positions[c]);
// b = c;
// c = map.phi1(b);
//
// } while (c != d);
// }
// }
//
// m_nbTris = buffer.size()/4;
//
// m_vboPos->allocate(buffer.size());
// VEC3* ptrPos = reinterpret_cast<VEC3*>(m_vboPos->lockPtr());
// memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
// m_vboPos->releasePtr();
// m_shader->setAttributePosition(m_vboPos);
//
// buffer.clear();
//
// TraversorCell<typename PFP::MAP> traEdge(map, PFP::MAP::ORBIT_IN_PARENT(EDGE),good);
// for (Dart d=traEdge.begin(); d!=traEdge.end(); d=traEdge.next())
// {
// buffer.push_back(centerVolumes[d]);
// buffer.push_back(positions[d]);
// buffer.push_back(positions[ map.phi1(d)]);
// }
//
// m_nbLines = buffer.size()/3;
//
// m_vboPosLine->allocate(buffer.size());
//
// ptrPos = reinterpret_cast<VEC3*>(m_vboPosLine->lockPtr());
// memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
//
// m_vboPosLine->releasePtr();
// m_shaderL->setAttributePosition(m_vboPosLine);
//}
template<typename PFP>
void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, typename PFP::TVEC3& colorPerFace, const FunctorSelect& good)
void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, typename PFP::TVEC3& colorPerXXX, const FunctorSelect& good)
{
if (!m_cpf)
{
......@@ -167,23 +192,43 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3
std::vector<VEC3> buffer;
buffer.reserve(16384);
std::vector<VEC3> bufferColors;
// bool withColors = (positions == colorPerXXX);
bool withColors = true;
if (withColors)
bufferColors.reserve(16384);
TraversorCell<typename PFP::MAP> traFace(map, PFP::MAP::ORBIT_IN_PARENT(FACE),good);
for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next())
{
VEC3 centerFace = Algo::Geometry::faceCentroid<PFP>(map,d,positions);
Dart a = d;
Dart b = map.phi1(a);
Dart c = map.phi1(b);
// loop to cut a polygon in triangle on the fly (works only with convex faces)
do
{
buffer.push_back(centerVolumes[d]);
bufferColors.push_back(centerFace);
buffer.push_back(positions[d]);
if (m_cpf)
bufferColors.push_back(colorPerXXX[d]);
else
bufferColors.push_back(m_globalColor);
buffer.push_back(positions[b]);
if (m_cpf)
bufferColors.push_back(colorPerXXX[b]);
else
bufferColors.push_back(m_globalColor);
buffer.push_back(positions[c]);
buffer.push_back(colorPerFace[d]);
buffer.push_back(VEC3(0.,0.,0.)); // TODO use this place for center of face
if (m_cpf)
bufferColors.push_back(colorPerXXX[c]);
else
bufferColors.push_back(m_globalColor);
b = c;
c = map.phi1(b);
......@@ -193,13 +238,20 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3
m_nbTris = buffer.size()/4;
m_vboPos->allocate(buffer.size());
VEC3* ptrPos = reinterpret_cast<VEC3*>(m_vboPos->lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
m_vboPos->releasePtr();
m_shader->setAttributePosition(m_vboPos);
if (withColors)
{
m_vboColors->allocate(bufferColors.size());
VEC3* ptrCol = reinterpret_cast<VEC3*>(m_vboColors->lockPtr());
memcpy(ptrCol,&bufferColors[0],bufferColors.size()*sizeof(VEC3));
m_vboColors->releasePtr();
m_shader->setAttributeColor(m_vboColors);
}
buffer.clear();
......@@ -228,9 +280,9 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3
inline void ExplodeVolumeRender::drawFaces()
{
m_shader->enableVertexAttribs();
if (m_cpf)
glDrawArrays(GL_TRIANGLES_ADJACENCY_EXT , 0 , m_nbTris*6 );
else
// if (m_cpf)
// glDrawArrays(GL_TRIANGLES_ADJACENCY_EXT , 0 , m_nbTris*6 );
// else
glDrawArrays(GL_LINES_ADJACENCY_EXT , 0 , m_nbTris*4 );
m_shader->disableVertexAttribs();
}
......@@ -251,6 +303,12 @@ inline void ExplodeVolumeRender::setExplodeVolumes(float explode)
m_shaderL->setExplodeVolumes(explode);
}
inline void ExplodeVolumeRender::setExplodeFaces(float explode)
{
m_shader->setExplodeFaces(explode);
}
inline void ExplodeVolumeRender::setClippingPlane(const Geom::Vec4f& p)
{
m_shader->setClippingPlane(p);
......@@ -269,9 +327,9 @@ inline void ExplodeVolumeRender::setAmbiant(const Geom::Vec4f& ambiant)
m_shader->setAmbiant(ambiant);
}
inline void ExplodeVolumeRender::setDiffuse(const Geom::Vec4f& diffuse)
inline void ExplodeVolumeRender::setBackColor(const Geom::Vec4f& color)
{
m_shader->setDiffuse(diffuse);
m_shader->setBackColor(color);
}
inline void ExplodeVolumeRender::setLightPosition(const Geom::Vec3f& lp)
......
......@@ -68,7 +68,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;