Commit 32045a8a authored by untereiner's avatar untereiner

Merge cgogn:~thery/CGoGN into HEAD

parents 64a8ae55 9276de25
......@@ -422,6 +422,12 @@ int main(int argc, char **argv)
prim.hexaGrid_topo(nb,nb,nb);
prim.embedHexaGrid(1.0f,1.0f,1.0f);
for (unsigned int i=position.begin(); i != position.end(); position.next(i))
{
PFP::VEC3 pert(float(double(rand())/RAND_MAX/20.0),float(double(rand())/RAND_MAX/20.0),float(double(rand())/RAND_MAX/20.0));
position[i]+= pert;
}
color = myMap.addAttribute<PFP::VEC3, VOLUME>("color");
TraversorW<PFP::MAP> tra(myMap);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
......
......@@ -56,16 +56,16 @@
</property>
</widget>
</item>
<item row="2" column="2" alignment="Qt::AlignRight">
<item row="2" column="2">
<widget class="QPushButton" name="button_refreshVBOs">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Refresh</string>
......@@ -75,11 +75,7 @@
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="Line" name="line"/>
</item>
<item>
<widget class="QCheckBox" name="check_renderVertices">
......
......@@ -32,6 +32,7 @@
#include "Topology/generic/attributeHandler.h"
#include "Topology/generic/functor.h"
#include "Utils/vbo_base.h"
#include "Utils/Shaders/shaderExplodeSmoothVolumes.h"
#include "Utils/Shaders/shaderExplodeVolumes.h"
#include "Utils/Shaders/shaderExplodeVolumesLines.h"
......@@ -54,16 +55,22 @@ protected:
Utils::ShaderExplodeVolumes* m_shader;
Utils::ShaderExplodeSmoothVolumes* m_shaderS;
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;
/**
......@@ -75,13 +82,20 @@ 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
* @param withColorPerFace affect a color per face
* @param withExplodeFace shrinj each face
*/
ExplodeVolumeRender(bool withColorPerFace = false, bool withExplodeFace = false) ;
ExplodeVolumeRender(bool withColorPerFace = false, bool withExplodeFace = false, bool withSmoothFaces = false) ;
/**
* Destructor
......@@ -117,6 +131,7 @@ public:
template<typename PFP>
void updateData(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
{
......@@ -41,8 +43,9 @@ namespace Render
namespace GL2
{
inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace, bool withExplodeFace):
m_cpf(withColorPerFace),m_ef(withExplodeFace),m_globalColor(0.7f,0.7f,0.7f)
inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace, bool withExplodeFace, bool withSmoothFaces):
m_cpf(withColorPerFace),m_ef(withExplodeFace),m_smooth(withSmoothFaces),
m_nbTris(0), m_nbLines(0),m_globalColor(0.7f,0.7f,0.7f)
{
m_vboPos = new Utils::VBO();
m_vboPos->setDataSize(3);
......@@ -50,19 +53,24 @@ 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);
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));
//m_shaderL->setColor(Geom::Vec4f(0.113f,0.337f,0.0f,0.113f));
if (m_smooth)
{
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();
m_shaderL->setColor(Geom::Vec4f(1.0f,1.0f,1.0f,0.0f));
}
......@@ -72,19 +80,133 @@ inline ExplodeVolumeRender::~ExplodeVolumeRender()
delete m_vboPos;
delete m_vboColors;
delete m_vboPosLine;
delete m_shader;
if (m_vboNormals != NULL)
delete m_vboNormals;
if (m_shader != NULL)
delete m_shader;
if (m_shaderS != NULL)
delete m_shaderS;
delete m_shaderL;
}
template<typename PFP>
void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const FunctorSelect& good)
void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const VolumeAttribute<typename PFP::VEC3>& colorPerXXX, const FunctorSelect& good)
{
if (m_cpf)
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())
{
CGoGNerr<< "ExplodeVolumeRender: problem wrong update fonction use the other" << CGoGNendl;
return;
// 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
{
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);
}
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())
{
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;
......@@ -94,67 +216,92 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu
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())
{
if (m_ef)
// compute normals
normals.clear();
VEC3 centerFace(0);
unsigned int nbs=0;
Dart a = d;
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]);
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
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
{
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);
}
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_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())
{
buffer.push_back(centerVolumes[d]);
buffer.push_back(positions[d]);
buffer.push_back(positions[map.phi1(d)]);
buffer.push_back(centerVolumes[d]);
buffer.push_back(positions[d]);
buffer.push_back(positions[map.phi1(d)]);
}
m_nbLines = buffer.size()/3;
......@@ -168,15 +315,25 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu
m_shaderL->setAttributePosition(m_vboPosLine);
}
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;
CGoGNerr<< "ExplodeVolumeRender: problem wrong update fonction use the other (without VolumeAttribute parameter)" << CGoGNendl;
return;
}
if (m_smooth)
{
updateSmooth<PFP>(map,positions,colorPerXXX,good);
return;
}
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
......@@ -188,10 +345,7 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu
std::vector<VEC3> bufferColors;
// bool withColors = (positions == colorPerXXX);
bool withColors = true;
if (withColors)
bufferColors.reserve(16384);
bufferColors.reserve(16384);
TraversorCell<typename PFP::MAP, PFP::MAP::FACE_OF_PARENT> traFace(map, good);
......@@ -208,23 +362,13 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu
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);
bufferColors.push_back(colorPerXXX[d]);
buffer.push_back(positions[b]);
if (m_cpf)
bufferColors.push_back(colorPerXXX[b]);
else
bufferColors.push_back(m_globalColor);
bufferColors.push_back(colorPerXXX[b]);
buffer.push_back(positions[c]);
if (m_cpf)
bufferColors.push_back(colorPerXXX[c]);
else
bufferColors.push_back(m_globalColor);
bufferColors.push_back(colorPerXXX[c]);
b = c;
c = map.phi1(b);
} while (c != d);
}
......@@ -236,15 +380,100 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu
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();
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())
{
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);
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]);
bufferColors.push_back(m_globalColor);
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_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();
......@@ -267,14 +496,22 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu
m_shaderL->setAttributePosition(m_vboPosLine);
}
inline void ExplodeVolumeRender::drawFaces()
{
m_shader->enableVertexAttribs();
// if (m_cpf)
// glDrawArrays(GL_TRIANGLES_ADJACENCY_EXT , 0 , m_nbTris*6 );
// else