Commit dd2af627 authored by Sylvain Thery's avatar Sylvain Thery
Browse files

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