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

finish ExplodeSmoothVolumes

parent 3f6ed5bb
......@@ -57,18 +57,20 @@ protected:
Utils::ShaderExplodeSmoothVolumes* m_shaderS;
bool m_smooth;
bool m_cpf;
bool m_ef;
bool m_smooth;
Utils::ShaderExplodeVolumesLines* m_shaderL;
Utils::VBO* m_vboPos;
Utils::VBO* m_vboColors;
Utils::VBO* m_vboNormals;
Utils::VBO* m_vboPosLine;
/**
......@@ -80,6 +82,13 @@ protected:
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:
/**
* Constructor
......@@ -109,8 +118,8 @@ public:
* @param positions attribute of position vertices
* @param good selector
*/
// template<typename PFP>
// void updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const FunctorSelect& good = allDarts) ;
template<typename PFP>
void updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const FunctorSelect& good = allDarts) ;
/**
* update all drawing buffers
......@@ -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) ;
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
*/
......
......@@ -29,6 +29,8 @@
#include "Algo/Geometry/centroid.h"
#include "Topology/generic/autoAttributeHandler.h"
#include "Algo/Geometry/basic.h"
namespace CGoGN
{
......@@ -51,7 +53,6 @@ inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace, bool with
m_vboColors = new Utils::VBO();
m_vboColors->setDataSize(3);
m_vboPosLine = new Utils::VBO();
m_vboPosLine->setDataSize(3);
......@@ -59,11 +60,14 @@ inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace, bool with
{
m_shaderS = new Utils::ShaderExplodeSmoothVolumes(withColorPerFace,withExplodeFace);
m_shader = NULL;
m_vboNormals = new Utils::VBO();
m_vboNormals->setDataSize(3);
}
else
{
m_shader = new Utils::ShaderExplodeVolumes(withColorPerFace,withExplodeFace);
m_shaderS = NULL;
m_vboNormals = NULL;
}
m_shaderL = new Utils::ShaderExplodeVolumesLines();
......@@ -76,6 +80,9 @@ inline ExplodeVolumeRender::~ExplodeVolumeRender()
delete m_vboPos;
delete m_vboColors;
delete m_vboPosLine;
if (m_vboNormals != NULL)
delete m_vboNormals;
if (m_shader != NULL)
delete m_shader;
if (m_shaderS != NULL)
......@@ -83,98 +90,6 @@ inline ExplodeVolumeRender::~ExplodeVolumeRender()
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>
......@@ -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);
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
normals.clear();
Dart a = d;
do
{
VEC3 v1 = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map,a,position);
Dart e = map.phi1(a);
VEC3 v2 = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map,e,position);
VEC3 N = v1^v2;
N.normalize();
normals.push_back(N);
} while (a != d);
VEC3 centerFace = Algo::Surface::Geometry::faceCentroid<PFP>(map, d, positions);
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);
}
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);
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);
bufferNormals.push_back(centerFace);
buffer.push_back(positions[d]);
bufferColors.push_back(m_globalColor);
bufferNormals.push_back();
buffer.push_back(positions[b]);
bufferColors.push_back(m_globalColor);
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);
}
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(m_globalColor);
bufferNormals.push_back(normals.back());
buffer.push_back(positions[b]);
bufferColors.push_back(m_globalColor);
bufferNormals.push_back(*in++);
buffer.push_back(positions[c]);
bufferColors.push_back(m_globalColor);
bufferNormals.push_back(*in);
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);
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_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();
......@@ -309,19 +316,21 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri
}
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)
{
// if (!m_cpf)
// {
// CGoGNerr<< "ExplodeVolumeRender: problem wrong update fonction use the other" << CGoGNendl;
// return;
// }
if (!m_cpf)
{
CGoGNerr<< "ExplodeVolumeRender: problem wrong update fonction use the other (without VolumeAttribute parameter)" << CGoGNendl;
return;
}
if (m_smooth)
{
updateSmooth<PFP>(map,positions,colorPerXXX,good);
return;
}
......@@ -339,54 +348,117 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu
bufferColors.reserve(16384);
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);
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]);
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);
}
buffer.push_back(centerVolumes[d]);
bufferColors.push_back(centerFace);
buffer.push_back(positions[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);
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, const VertexAttribute<typename PFP::VEC3>& positions, const FunctorSelect& good)
{
if (m_cpf)
{
CGoGNerr<< "ExplodeVolumeRender: problem wrong update fonction use the other (without VolumeAttribute parameter)" << CGoGNendl;
return;
}
if (m_smooth)
{
updateSmooth<PFP>(map,positions,good);
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);
std::vector<VEC3> bufferColors;
bufferColors.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())
{
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);
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]);
bufferColors.push_back(m_globalColor);
buffer.push_back(positions[b]);
bufferColors.push_back(m_globalColor);
buffer.push_back(positions[c]);