Commit 95211aba authored by Sylvain Thery's avatar Sylvain Thery

finish ExplodeSmoothVolumes

parent 3f6ed5bb
...@@ -57,18 +57,20 @@ protected: ...@@ -57,18 +57,20 @@ protected:
Utils::ShaderExplodeSmoothVolumes* m_shaderS; Utils::ShaderExplodeSmoothVolumes* m_shaderS;
bool m_smooth;
bool m_cpf; bool m_cpf;
bool m_ef; bool m_ef;
bool m_smooth;
Utils::ShaderExplodeVolumesLines* m_shaderL; Utils::ShaderExplodeVolumesLines* m_shaderL;
Utils::VBO* m_vboPos; Utils::VBO* m_vboPos;
Utils::VBO* m_vboColors; Utils::VBO* m_vboColors;
Utils::VBO* m_vboNormals;
Utils::VBO* m_vboPosLine; Utils::VBO* m_vboPosLine;
/** /**
...@@ -80,6 +82,13 @@ protected: ...@@ -80,6 +82,13 @@ protected:
Geom::Vec3f m_globalColor; Geom::Vec3f m_globalColor;
template<typename PFP>
void updateSmooth(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const VolumeAttribute<typename PFP::VEC3>& colorPerFace, const FunctorSelect& good = allDarts) ;
template<typename PFP>
void updateSmooth(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const FunctorSelect& good = allDarts) ;
public: public:
/** /**
* Constructor * Constructor
...@@ -109,8 +118,8 @@ public: ...@@ -109,8 +118,8 @@ public:
* @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, const VertexAttribute<typename PFP::VEC3>& positions, const FunctorSelect& good = allDarts) ; void updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const FunctorSelect& good = allDarts) ;
/** /**
* update all drawing buffers * update all drawing buffers
...@@ -123,9 +132,6 @@ public: ...@@ -123,9 +132,6 @@ public:
void updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const VolumeAttribute<typename PFP::VEC3>& colorPerFace, const FunctorSelect& good = allDarts) ; void updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const VolumeAttribute<typename PFP::VEC3>& colorPerFace, const FunctorSelect& good = allDarts) ;
template<typename PFP>
void updateSmooth(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const VolumeAttribute<typename PFP::VEC3>& colorPerFace, const FunctorSelect& good = allDarts) ;
/** /**
* draw edges * draw edges
*/ */
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "Algo/Geometry/centroid.h" #include "Algo/Geometry/centroid.h"
#include "Topology/generic/autoAttributeHandler.h" #include "Topology/generic/autoAttributeHandler.h"
#include "Algo/Geometry/basic.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -51,7 +53,6 @@ inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace, bool with ...@@ -51,7 +53,6 @@ inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace, bool with
m_vboColors = new Utils::VBO(); m_vboColors = new Utils::VBO();
m_vboColors->setDataSize(3); m_vboColors->setDataSize(3);
m_vboPosLine = new Utils::VBO(); m_vboPosLine = new Utils::VBO();
m_vboPosLine->setDataSize(3); m_vboPosLine->setDataSize(3);
...@@ -59,11 +60,14 @@ inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace, bool with ...@@ -59,11 +60,14 @@ inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace, bool with
{ {
m_shaderS = new Utils::ShaderExplodeSmoothVolumes(withColorPerFace,withExplodeFace); m_shaderS = new Utils::ShaderExplodeSmoothVolumes(withColorPerFace,withExplodeFace);
m_shader = NULL; m_shader = NULL;
m_vboNormals = new Utils::VBO();
m_vboNormals->setDataSize(3);
} }
else else
{ {
m_shader = new Utils::ShaderExplodeVolumes(withColorPerFace,withExplodeFace); m_shader = new Utils::ShaderExplodeVolumes(withColorPerFace,withExplodeFace);
m_shaderS = NULL; m_shaderS = NULL;
m_vboNormals = NULL;
} }
m_shaderL = new Utils::ShaderExplodeVolumesLines(); m_shaderL = new Utils::ShaderExplodeVolumesLines();
...@@ -76,6 +80,9 @@ inline ExplodeVolumeRender::~ExplodeVolumeRender() ...@@ -76,6 +80,9 @@ inline ExplodeVolumeRender::~ExplodeVolumeRender()
delete m_vboPos; delete m_vboPos;
delete m_vboColors; delete m_vboColors;
delete m_vboPosLine; delete m_vboPosLine;
if (m_vboNormals != NULL)
delete m_vboNormals;
if (m_shader != NULL) if (m_shader != NULL)
delete m_shader; delete m_shader;
if (m_shaderS != NULL) if (m_shaderS != NULL)
...@@ -83,98 +90,6 @@ inline ExplodeVolumeRender::~ExplodeVolumeRender() ...@@ -83,98 +90,6 @@ inline ExplodeVolumeRender::~ExplodeVolumeRender()
delete m_shaderL; delete m_shaderL;
} }
//template<typename PFP>
//void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& 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;
//
// VolumeAutoAttribute<VEC3> centerVolumes(map, "centerVolumes");
// Algo::Volume::Geometry::Parallel::computeCentroidVolumes<PFP>(map, positions, centerVolumes, good);
//
// std::vector<VEC3> buffer;
// buffer.reserve(16384);
//
// TraversorCell<typename PFP::MAP, PFP::MAP::FACE_OF_PARENT> traFace(map, good);
//
// for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next())
// {
// if (m_ef)
// {
// VEC3 centerFace = Algo::Surface::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, PFP::MAP::EDGE_OF_PARENT> traEdge(map, 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> template<typename PFP>
...@@ -199,93 +114,185 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri ...@@ -199,93 +114,185 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri
TraversorCell<typename PFP::MAP, PFP::MAP::FACE_OF_PARENT> traFace(map, good); TraversorCell<typename PFP::MAP, PFP::MAP::FACE_OF_PARENT> traFace(map, good);
if (m_cpf) for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next())
{ {
for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next()) // compute normals
normals.clear();
VEC3 centerFace(0);
unsigned int nbs=0;
Dart a = d;
do
{
VEC3 v1 = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map,a,positions);
Dart e = map.phi1(a);
VEC3 v2 = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map,e,positions);
VEC3 N = v1^v2;
N.normalize();
normals.push_back(N);
a = e;
centerFace += positions[d];
nbs++;
} while (a != d);
centerFace /= float(nbs);
typename std::vector<VEC3>::iterator in = normals.begin();
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
{ {
// compute normals buffer.push_back(centerVolumes[d]);
normals.clear(); bufferColors.push_back(centerFace);
Dart a = d; bufferNormals.push_back(centerFace); // unsused just for fill
do buffer.push_back(positions[d]);
{ bufferColors.push_back(colorPerXXX[d]);
VEC3 v1 = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map,a,position); bufferNormals.push_back(normals.back());
Dart e = map.phi1(a); buffer.push_back(positions[b]);
VEC3 v2 = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map,e,position); bufferColors.push_back(colorPerXXX[b]);
VEC3 N = v1^v2; bufferNormals.push_back(*in++);
N.normalize(); buffer.push_back(positions[c]);
normals.push_back(N); bufferColors.push_back(colorPerXXX[c]);
} while (a != d); bufferNormals.push_back(*in);
b = c;
VEC3 centerFace = Algo::Surface::Geometry::faceCentroid<PFP>(map, d, positions); c = map.phi1(b);
} while (c != d);
std::vector<VEC3>::iterator in = normals.begin();
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);
bufferNormals.push_back(centerFace); // unsused just for fill
buffer.push_back(positions[d]);
bufferColors.push_back(colorPerXXX[d]);
bufferNormals.push_back(normals.back());
buffer.push_back(positions[b]);
bufferColors.push_back(colorPerXXX[b]);
bufferNormals.push_back(*in++);
buffer.push_back(positions[c]);
bufferColors.push_back(colorPerXXX[c]);
bufferNormals.push_back(*in++);
b = c;
c = map.phi1(b);
} while (c != d);
}
} }
else
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_shaderS->setAttributePosition(m_vboPos);
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_shaderS->setAttributeColor(m_vboColors);
m_vboNormals->allocate(bufferNormals.size());
VEC3* ptrNorm = reinterpret_cast<VEC3*>(m_vboNormals->lockPtr());
memcpy(ptrNorm,&bufferNormals[0],bufferNormals.size()*sizeof(VEC3));
m_vboNormals->releasePtr();
m_shaderS->setAttributeNormal(m_vboNormals);
buffer.clear();
TraversorCell<typename PFP::MAP, PFP::MAP::EDGE_OF_PARENT> traEdge(map, good);
for (Dart d = traEdge.begin(); d != traEdge.end(); d = traEdge.next())
{ {
for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.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::updateSmooth(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const FunctorSelect& good)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
VolumeAutoAttribute<VEC3> centerVolumes(map, "centerVolumes");
Algo::Volume::Geometry::Parallel::computeCentroidVolumes<PFP>(map, positions, centerVolumes, good);
std::vector<VEC3> buffer;
buffer.reserve(16384);
std::vector<VEC3> bufferColors;
bufferColors.reserve(16384);
std::vector<VEC3> bufferNormals;
bufferNormals.reserve(16384);
std::vector<VEC3> normals;
bufferNormals.reserve(20);
TraversorCell<typename PFP::MAP, PFP::MAP::FACE_OF_PARENT> traFace(map, good);
for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next())
{
// compute normals
normals.clear();
VEC3 centerFace(0);
unsigned int nbs=0;
Dart a = d;
do
{
VEC3 v1 = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map,a,positions);
Dart e = map.phi1(a);
VEC3 v2 = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map,e,positions);
VEC3 N = v1^v2;
N.normalize();
normals.push_back(N);
a = e;
centerFace += positions[d];
nbs++;
} while (a != d);
centerFace /= float(nbs);
typename std::vector<VEC3>::iterator in = normals.begin();
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
{ {
VEC3 centerFace = Algo::Surface::Geometry::faceCentroid<PFP>(map, d, positions); buffer.push_back(centerVolumes[d]);
Dart a = d; bufferColors.push_back(centerFace);
Dart b = map.phi1(a); bufferNormals.push_back(centerFace); // unsused just for fill
Dart c = map.phi1(b); buffer.push_back(positions[d]);
// loop to cut a polygon in triangle on the fly (works only with convex faces) bufferColors.push_back(m_globalColor);
do bufferNormals.push_back(normals.back());
{ buffer.push_back(positions[b]);
buffer.push_back(centerVolumes[d]); bufferColors.push_back(m_globalColor);
bufferColors.push_back(centerFace); bufferNormals.push_back(*in++);
bufferNormals.push_back(centerFace); buffer.push_back(positions[c]);
buffer.push_back(positions[d]); bufferColors.push_back(m_globalColor);
bufferColors.push_back(m_globalColor); bufferNormals.push_back(*in);
bufferNormals.push_back(); b = c;
buffer.push_back(positions[b]); c = map.phi1(b);
bufferColors.push_back(m_globalColor); } while (c != d);
bufferNormals.push_back();
buffer.push_back(positions[c]);
bufferColors.push_back(m_globalColor);
bufferNormals.push_back();
b = c;
c = map.phi1(b);
} while (c != d);
}
} }
m_nbTris = buffer.size()/4; m_nbTris = buffer.size()/4;
m_vboPos->allocate(buffer.size()); m_vboPos->allocate(buffer.size());
VEC3* ptrPos = reinterpret_cast<VEC3*>(m_vboPos->lockPtr()); VEC3* ptrPos = reinterpret_cast<VEC3*>(m_vboPos->lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3)); memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
m_vboPos->releasePtr(); m_vboPos->releasePtr();
m_shader->setAttributePosition(m_vboPos); m_shaderS->setAttributePosition(m_vboPos);
m_vboColors->allocate(bufferColors.size()); m_vboColors->allocate(bufferColors.size());
VEC3* ptrCol = reinterpret_cast<VEC3*>(m_vboColors->lockPtr()); VEC3* ptrCol = reinterpret_cast<VEC3*>(m_vboColors->lockPtr());
memcpy(ptrCol,&bufferColors[0],bufferColors.size()*sizeof(VEC3)); memcpy(ptrCol,&bufferColors[0],bufferColors.size()*sizeof(VEC3));
m_vboColors->releasePtr(); m_vboColors->releasePtr();
m_shader->setAttributeColor(m_vboColors); m_shaderS->setAttributeColor(m_vboColors);
m_vboNormals->allocate(bufferNormals.size());
VEC3* ptrNorm = reinterpret_cast<VEC3*>(m_vboNormals->lockPtr());
memcpy(ptrNorm,&bufferNormals[0],bufferNormals.size()*sizeof(VEC3));
m_vboNormals->releasePtr();
m_shaderS->setAttributeNormal(m_vboNormals);
buffer.clear(); buffer.clear();
...@@ -309,19 +316,21 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri ...@@ -309,19 +316,21 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri
} }
template<typename PFP> template<typename PFP>
void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const VolumeAttribute<typename PFP::VEC3>& colorPerXXX, const FunctorSelect& good) void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const VolumeAttribute<typename PFP::VEC3>& colorPerXXX, 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 (without VolumeAttribute parameter)" << CGoGNendl;
// return; return;
// } }
if (m_smooth) if (m_smooth)
{ {
updateSmooth<PFP>(map,positions,colorPerXXX,good);
return;
} }
...@@ -339,54 +348,117 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu ...@@ -339,54 +348,117 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu
bufferColors.reserve(16384); bufferColors.reserve(16384);
TraversorCell<typename PFP::MAP, PFP::MAP::FACE_OF_PARENT> traFace(map, good); TraversorCell<typename PFP::MAP, PFP::MAP::FACE_OF_PARENT> traFace(map, good);
if (m_cpf)
for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next())
{ {
for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next()) VEC3 centerFace = Algo::Surface::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
{ {
VEC3 centerFace = Algo::Surface::Geometry::faceCentroid<PFP>(map, d, positions); buffer.push_back(centerVolumes[d]);
bufferColors.push_back(centerFace);
Dart a = d; buffer.push_back(positions[d]);
Dart b = map.phi1(a); bufferColors.push_back(colorPerXXX[d]);
Dart c = map.phi1(b); buffer.push_back(positions[b]);
// loop to cut a polygon in triangle on the fly (works only with convex faces) bufferColors.push_back(colorPerXXX[b]);
do buffer.push_back(positions[c]);
{ bufferColors.push_back(colorPerXXX[c]);
buffer.push_back(centerVolumes[d]); b = c;
bufferColors.push_back(centerFace); c = map.phi1(b);
buffer.push_back(positions[d]); } while (c != d);
bufferColors.push_back(colorPerXXX[d]);
buffer.push_back(positions[b]);
bufferColors.push_back(colorPerXXX[b]);
buffer.push_back(positions[c]);
bufferColors.push_back(colorPerXXX[c]);
b = c;
c = map.phi1(b);
} while (c != d);
}
} }
else
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);
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();
TraversorCell<typename PFP::MAP, PFP::MAP::EDGE_OF_PARENT> traEdge(map, good);
</