Commit eadfb56d authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'develop' into 'develop'

Develop

See merge request !63
parents acfee411 b5f3f45d
......@@ -40,7 +40,7 @@ qt_wrap_cpp( viewer_moc viewer.h )
add_executable( viewer viewer.cpp ${viewer_moc} ${viewer_ui} )
target_link_libraries( viewer ${CGoGN_LIBS} ${NUMERICAL_LIBS} ${CGoGN_EXT_LIBS} )
IF (CGoGN_GCC_4_9)
IF (HAS_CPP11_REGEX)
qt_wrap_ui( clipping_ui clipping.ui )
qt_wrap_cpp( clipping_moc clipping.h )
add_executable( clipping clipping.cpp ${clipping_ui} ${clipping_moc} )
......
......@@ -94,6 +94,12 @@ void quadranguleFaces(typename PFP::MAP& map, EMBV& attributs) ;
template <typename PFP, typename EMBV>
void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs) ;
/**
* Interpolant Catmull-Clark subdivision scheme
*/
template <typename PFP, typename EMBV>
void CatmullClarkInterpolSubdivision(typename PFP::MAP& map, EMBV& attributs);
/**
* Loop subdivision scheme
*/
......
......@@ -180,9 +180,142 @@ void quadranguleFaces(typename PFP::MAP& map, EMBV& attributs)
// quadranguleFaces<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, position) ;
//}
// ORIGINALE
//template <typename PFP, typename EMBV>
//void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs)
//{
// typedef typename PFP::MAP MAP;
// typedef typename EMBV::DATA_TYPE EMB;
//
// std::vector<Dart> l_middles;
// std::vector<Dart> l_verts;
//
// CellMarkerNoUnmark<MAP, VERTEX> m0(map);
// DartMarkerNoUnmark<MAP> mf(map);
// DartMarkerNoUnmark<MAP> me(map);
//
// // first pass: cut edges
// for (Dart d = map.begin(); d != map.end(); map.next(d))
// {
// if ( !map.template isBoundaryMarked<2>(d) && !me.isMarked(d))
// {
// if (!m0.isMarked(d))
// {
// m0.mark(d);
// l_verts.push_back(d);
// }
// Dart d2 = map.phi2(d);
// if (!m0.isMarked(d2))
// {
// m0.mark(d2);
// l_verts.push_back(d2);
// }
//
// Dart f = map.phi1(d);
// Dart e = map.cutEdge(d);
//
// attributs[e] = attributs[d];
// attributs[e] += attributs[f];
// attributs[e] *= 0.5;
//
// me.template markOrbit<EDGE>(d);
// me.template markOrbit<EDGE>(e);
//
// mf.mark(d) ;
// mf.mark(map.phi2(e)) ;
//
// l_middles.push_back(e);
// }
// }
//
// // second pass: quandrangule faces
// for (Dart d = map.begin(); d != map.end(); map.next(d))
// {
// if ( !map.template isBoundaryMarked<2>(d) && mf.isMarked(d)) // for each face not subdivided
// {
// // compute center skip darts of new vertices non embedded
//// EMB center = AttribOps::zero<EMB,PFP>();
// EMB center(0.0);
// unsigned int count = 0 ;
// mf.template unmarkOrbit<FACE>(d) ;
// Dart it = d;
// do
// {
// center += attributs[it];
// ++count ;
// me.template unmarkOrbit<PFP::MAP::EDGE_OF_PARENT>(it);
//
// it = map.phi1(it) ;
// me.template unmarkOrbit<PFP::MAP::EDGE_OF_PARENT>(it);
// it = map.phi1(it) ;
// } while(it != d) ;
// center /= float(count);
// Dart cf = quadranguleFace<PFP>(map, d); // quadrangule the face
// attributs[cf] = center; // affect the data to the central vertex
// }
// }
//
// // Compute edge points
// for(typename std::vector<Dart>::iterator mid = l_middles.begin(); mid != l_middles.end(); ++mid)
// {
// Dart x = *mid;
// // other side of the edge
// if (!map.isBoundaryEdge(x))
// {
// Dart f1 = map.phi_1(x);
// Dart f2 = map.phi2(map.phi1(map.phi2(x)));
//// EMB temp = AttribOps::zero<EMB,PFP>();
//// temp = attributs[f1];
// EMB temp = attributs[f1];
// temp += attributs[f2]; // E' = (V0+V1+F1+F2)/4
// temp *= 0.25;
// attributs[x] *= 0.5;
// attributs[x] += temp;
// }
// // else nothing to do point already in the middle of segment
// }
//
// // Compute vertex points
// for(typename std::vector<Dart>::iterator vert = l_verts.begin(); vert != l_verts.end(); ++vert)
// {
// m0.unmark(*vert);
//
//// EMB temp = AttribOps::zero<EMB,PFP>();
//// EMB temp2 = AttribOps::zero<EMB,PFP>();
// EMB temp(0.0);
// EMB temp2(0.0);
//
// unsigned int n = 0;
// Dart x = *vert;
// do
// {
// Dart m = map.phi1(x);
// Dart f = map.phi2(m);
// Dart v = map.template phi<11>(f);
//
// temp += attributs[f];
// temp2 += attributs[v];
//
// ++n;
// x = map.phi2_1(x);
// } while (x != *vert);
//
// EMB emcp = attributs[*vert];
// emcp *= float((n-2)*n); // V' = (n-2)/n*V + 1/n2 *(F+E)
// emcp += temp;
// emcp += temp2;
// emcp /= float(n*n);
//
// attributs[*vert] = emcp ;
// }
//}
template <typename PFP, typename EMBV>
void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs)
{
typedef typename PFP::MAP MAP;
typedef typename EMBV::DATA_TYPE EMB;
......@@ -233,7 +366,6 @@ void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs)
if ( !map.template isBoundaryMarked<2>(d) && mf.isMarked(d)) // for each face not subdivided
{
// compute center skip darts of new vertices non embedded
// EMB center = AttribOps::zero<EMB,PFP>();
EMB center(0.0);
unsigned int count = 0 ;
mf.template unmarkOrbit<FACE>(d) ;
......@@ -251,11 +383,12 @@ void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs)
center /= float(count);
Dart cf = quadranguleFace<PFP>(map, d); // quadrangule the face
attributs[cf] = center; // affect the data to the central vertex
}
}
// Compute edge points
for(typename std::vector<Dart>::iterator mid = l_middles.begin(); mid != l_middles.end(); ++mid)
for (typename std::vector<Dart>::iterator mid = l_middles.begin(); mid != l_middles.end(); ++mid)
{
Dart x = *mid;
// other side of the edge
......@@ -263,52 +396,195 @@ void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs)
{
Dart f1 = map.phi_1(x);
Dart f2 = map.phi2(map.phi1(map.phi2(x)));
// EMB temp = AttribOps::zero<EMB,PFP>();
// temp = attributs[f1];
EMB temp = attributs[f1];
temp += attributs[f2]; // E' = (V0+V1+F1+F2)/4
temp *= 0.25;
attributs[x] *= 0.5;
attributs[x] += temp;
attributs[x] += (attributs[f1] + attributs[f2]) / 4.0 - (attributs[x] / 2.0);
}
// else nothing to do point already in the middle of segment
}
// Compute vertex points
for(typename std::vector<Dart>::iterator vert = l_verts.begin(); vert != l_verts.end(); ++vert)
for (typename std::vector<Dart>::iterator vert = l_verts.begin(); vert != l_verts.end(); ++vert)
{
m0.unmark(*vert);
// EMB temp = AttribOps::zero<EMB,PFP>();
// EMB temp2 = AttribOps::zero<EMB,PFP>();
EMB temp(0.0);
EMB temp2(0.0);
EMB sumFace(0.0); // Sum_F
EMB sumEdge(0.0);// Sum_E
unsigned int n = 0;
int n = 0;
Dart x = *vert;
do
{
Dart m = map.phi1(x);
Dart f = map.phi2(m);
Dart v = map.template phi<11>(f);
temp += attributs[f];
temp2 += attributs[v];
sumFace += attributs[f];
sumEdge += attributs[m];
++n;
x = map.phi2_1(x);
} while (x != *vert);
EMB emcp = attributs[*vert];
emcp *= float((n-2)*n); // V' = (n-2)/n*V + 1/n2 *(F+E)
emcp += temp;
emcp += temp2;
emcp /= float(n*n);
EMB deltaV = attributs[*vert] * float(-3*n); // (-3 * attributs[*vert]
deltaV += sumFace; // + sumFace/n
deltaV += 2.0*sumEdge; // + sumEdge/n)
deltaV /= float(n*n); // /n
attributs[*vert] += deltaV;
}
}
template <typename PFP, typename EMBV>
void CatmullClarkInterpolSubdivision(typename PFP::MAP& map, EMBV& attributs)
{
typedef typename PFP::MAP MAP;
typedef typename EMBV::DATA_TYPE EMB;
VertexAutoAttribute<EMB, PFP::MAP> facesAverage(map);
std::vector<Dart> l_vertices;
std::vector<Dart> l_edges;
std::vector<Dart> l_faces;
l_vertices.reserve(attributs.nbElements() + 10);
l_faces.reserve(l_vertices.capacity() / 2);
l_edges.reserve(l_faces.capacity() * 2);
attributs[*vert] = emcp ;
DartMarker<MAP> mf(map);
DartMarker<MAP> me(map);
for (Vertex v : allVerticesOf(map))
{
l_vertices.push_back(v);
}
// first step: cut edges
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (!me.isMarked(d))
{
mf.markOrbit<EDGE>(d);
Dart f = map.phi1(d);
Dart e = map.cutEdge(d);
attributs[e] = (attributs[d] + attributs[f]) /2.0;
me.template markOrbit<EDGE>(d);
me.template markOrbit<EDGE>(e);
// warning store the dart that does not belong to the boundary
if (map.isBoundaryMarked<2>(e))
l_edges.push_back(map.phi2(d));
else
l_edges.push_back(e);
}
}
// second step: quandrangule faces
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (!map.template isBoundaryMarked<2>(d) && mf.isMarked(d))
{
EMB center(0.0);
unsigned int count = 0;
mf.template unmarkOrbit<FACE>(d);
Dart it = d;
do
{
center += attributs[it];
++count;
// unmark me on the fly
me.template unmarkOrbit<PFP::MAP::EDGE_OF_PARENT>(it);
it = map.phi1(it);
me.template unmarkOrbit<PFP::MAP::EDGE_OF_PARENT>(it);
it = map.phi1(it); // do not forget to skip the middle edge vertices
} while (it != d);
center /= float(count);
Dart cf = quadranguleFace<PFP>(map, d); // quadrangule the face
attributs[cf] = center; // affect the data to the central vertex
l_faces.push_back(cf);
}
}
// compute face average of "vertices"
for (Dart v : l_vertices)
{
EMB average(0.0);
int n = 0;
for (Face x : facesIncidentToVertex2(map, v))
{
Dart f = map.template phi<11>(x);
++n;
average += attributs[f];
}
facesAverage[v] = average / float(n);
}
// compute face average of "edges"
for (Dart e : l_edges)
{
if (!map.isBoundaryMarked<2>(map.phi2(e))) // faster than map.isBoundaryEdge(e)
{
Dart ff = map.phi_1(e);
Dart f = map.template phi<211>(e);
facesAverage[e] = (attributs[ff] + attributs[f]) / 2.0;
}
else
facesAverage[e] = attributs[e];
}
// Move edge points
for (Dart x: l_edges)
{
Dart xb = map.phi2(x);
if (map.isBoundaryMarked<2>(x))
std::cout << "ERROR " << attributs[x];
if (!map.isBoundaryMarked<2>(xb))
{
Dart v1 = map.phi1(x);
Dart v2 = map.phi_1(map.phi2(map.phi_1(x)));
attributs[x] -= (facesAverage[v1] + facesAverage[v2]) / 4.0 - facesAverage[x] / 2.0;
}
else // do the 4 point scheme
{
Dart a = map.template phi<1112>(xb);
Dart b = map.template phi<12>(xb);
Dart c = map.phi1(x);
Dart d = map.phi2(map.phi_1(map.phi_1(map.phi_1(xb))));
// use the 4 old vertices and not the two edge-points because we are writing on edge-points
attributs[x] -= (attributs[a] + attributs[b] + attributs[c] + attributs[d]) / 16.0 - attributs[x] / 4.0;
}
}
// Move face points
for (Dart f : l_faces)
{
EMB sumVert(0.0);
EMB sumEdge(0.0);
int n = 0;
Dart x = f;
do
{
Dart m = map.phi1(x);
Dart v = map.phi1(m);
sumVert += facesAverage[v];
sumEdge += facesAverage[m];
++n;
x = map.phi2_1(x);
} while (x != f);
EMB deltaF = (double(-3 * n)*attributs[f] + sumVert + 2.0*sumEdge) / double(n*n);
attributs[f] -= deltaF;
}
}
//template <typename PFP>
//void CatmullClarkSubdivision(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position)
//{
......
......@@ -536,8 +536,11 @@ void MapRender::initPrimitives(typename PFP::MAP& map, int prim, const VertexAtt
m_indexBufferUpToDate[prim] = true;
// setup du buffer d'indices
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[prim]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_nbIndices[prim] * sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW);
if (m_nbIndices[prim] > 0)
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[prim]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_nbIndices[prim] * sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW);
}
}
template <typename PFP>
......
......@@ -75,7 +75,7 @@ void set_eval_direction (vec3 v)
void main (void)
{
int size = (textureSize(texture,0)).x; // supposed square matrix
int size = (textureSize(texture,0)).x; // supposed square matrix
vec3 eyeV = normalize(camera - vxPos); // normalized outgoing line-of-sight vector
eyeV = 2*dot(vxNorm,eyeV)*vxNorm-eyeV ; // symmetrize
......
......@@ -67,6 +67,9 @@ public:
unsigned int setAttributePosition(VBO* vbo);
void setClippingPlane(const Geom::Vec4f& plane);
inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); }
};
} // namespace Utils
......
......@@ -39,41 +39,43 @@ namespace CGoGN
namespace Utils
{
#ifdef CGOGN_USE_OGL_CORE_PROFILE
unsigned int GLSLShader::CURRENT_OGL_VERSION = 3;
unsigned int GLSLShader::MAJOR_OGL_CORE = 3;
unsigned int GLSLShader::MINOR_OGL_CORE = 3;
#else
unsigned int GLSLShader::CURRENT_OGL_VERSION = 2;
unsigned int GLSLShader::MAJOR_OGL_CORE = 2;
unsigned int GLSLShader::MINOR_OGL_CORE = 1;
#endif
std::string GLSLShader::DEFINES_GL2=\
"#version 110\n"
"#define PRECISION float pipo_PRECISION\n"
"#define ATTRIBUTE attribute\n"
"#define VARYING_VERT varying\n"
"#define VARYING_FRAG varying\n"
"#define FRAG_OUT_DEF float pipo_FRAGDEF\n"
"#define FRAG_OUT gl_FragColor\n"
"#define INVARIANT_POS float pipo_INVARIANT\n"
"#define TEXTURE2D texture2D\n"
;
std::string GLSLShader::DEFINES_GL3=\
"#version 330\n"
"#define PRECISION precision highp float\n"
"#define ATTRIBUTE in\n"
"#define VARYING_VERT out\n"
"#define VARYING_FRAG in\n"
"#define FRAG_OUT_DEF out vec4 outFragColor\n"
"#define FRAG_OUT outFragColor\n"
"#define INVARIANT_POS invariant gl_Position\n"
"#define TEXTURE2D texture\n"
;
std::string* GLSLShader::DEFINES_GL = NULL;
//#ifdef CGOGN_USE_OGL_CORE_PROFILE
//unsigned int GLSLShader::CURRENT_OGL_VERSION = 3;
//unsigned int GLSLShader::MAJOR_OGL_CORE = 3;
//unsigned int GLSLShader::MINOR_OGL_CORE = 3;
//#else
//unsigned int GLSLShader::CURRENT_OGL_VERSION = 2;
//unsigned int GLSLShader::MAJOR_OGL_CORE = 2;
//unsigned int GLSLShader::MINOR_OGL_CORE = 1;
//#endif
//std::string GLSLShader::DEFINES_GL2=\
//"#version 110\n"
//"#define PRECISION float pipo_PRECISION\n"
//"#define ATTRIBUTE attribute\n"
//"#define VARYING_VERT varying\n"
//"#define VARYING_FRAG varying\n"
//"#define FRAG_OUT_DEF float pipo_FRAGDEF\n"
//"#define FRAG_OUT gl_FragColor\n"
//"#define INVARIANT_POS float pipo_INVARIANT\n"
//"#define TEXTURE2D texture2D\n";
//std::string GLSLShader::DEFINES_GL3=\
//"#version 150\n"
//"#define PRECISION precision highp float\n"
//"#define ATTRIBUTE in\n"
//"#define VARYING_VERT out\n"
//"#define VARYING_FRAG in\n"
//"#define FRAG_OUT_DEF out vec4 outFragColor\n"
//"#define FRAG_OUT outFragColor\n"
//"#define INVARIANT_POS invariant gl_Position\n"
//"#define TEXTURE2D texture\n";
//std::string* GLSLShader::DEFINES_GL = NULL;
std::vector<std::string> GLSLShader::m_pathes;
......
......@@ -21,7 +21,6 @@
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#define CGoGN_UTILS_DLL_EXPORT 1
#include <GL/glew.h>
#include "Utils/Shaders/shaderPhong.h"
......@@ -37,6 +36,7 @@ namespace Utils
#include "shaderPhongClip.vert"
#include "shaderPhongClip.frag"
ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePosition):
m_with_color(false),
m_with_eyepos(withEyePosition),
......@@ -54,17 +54,30 @@ ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePositi
std::string glxvert(GLSLShader::defines_gl());
std::string glxfrag(GLSLShader::defines_gl());
// get choose GL defines (2 or 3)
// ans compile shaders
std::string glxvert(GLSLShader::defines_gl());
if (m_with_eyepos)
glxvert.append("#define WITH_EYEPOSITION");
glxvert.append(vertexShaderText);
std::string glxfrag(GLSLShader::defines_gl());
// Use double sided lighting if set
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderText);
if (withClipping)
{
m_nameVS = "ShaderPhongClip_vs";
m_nameFS = "ShaderPhongClip_fs";
if (m_with_eyepos)
glxvert.append("#define WITH_EYEPOSITION");
glxvert.append(vertexShaderClipText);
// Use double sided lighting if set
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderClipText);
}
else
{
m_nameVS = "ShaderPhong_vs";
m_nameFS = "ShaderPhong_fs";
if (m_with_eyepos)
glxvert.append("#define WITH_EYEPOSITION");
glxvert.append(vertexShaderText);
// Use double sided lighting if set
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderText);
}
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());
......
......@@ -21,7 +21,6 @@
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#define CGoGN_UTILS_DLL_EXPORT 1
#include <GL/glew.h>
#include "Utils/Shaders/shaderSimpleFlat.h"
......@@ -37,6 +36,8 @@ namespace Utils
#include "shaderSimpleFlatClip.vert"
#include "shaderSimpleFlatClip.frag"
ShaderSimpleFlat::ShaderSimpleFlat(bool withClipping, bool doubleSided):
m_with_color(false),
m_ambiant(Geom::Vec4f(0.05f,0.05f,0.1f,0.0f)),
......@@ -47,18 +48,8 @@ ShaderSimpleFlat::ShaderSimpleFlat(bool withClipping, bool doubleSided):
m_vboColor(NULL),
m_planeClip(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f))
{
m_nameVS = "ShaderSimpleFlat_vs";
m_nameFS = "ShaderSimpleFlat_fs";
// m_nameGS = "ShaderSimpleFlat_gs";
// get choose GL defines (2 or 3)
// ans compile shaders
std::string glxvert(GLSLShader::defines_gl());
glxvert.append(vertexShaderText);
std::string glxfrag(GLSLShader::defines_gl());
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderText);
if (withClipping)
{
......@@ -126,6 +117,7 @@ void ShaderSimpleFlat::setDiffuse(const Geom::Vec4f& diffuse)
unbind();
}
void ShaderSimpleFlat::setLightPosition(const Geom::Vec3f& lightPos)
{
bind();
......@@ -134,6 +126,7 @@ void ShaderSimpleFlat::setLightPosition(const Geom::Vec3f& lightPos)
unbind();
}
void ShaderSimpleFlat::setBackColor(const Geom::Vec4f& back)
{
bind();
......@@ -142,6 +135,7 @@ void ShaderSimpleFlat::setBackColor(const Geom::Vec4f& back)