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

Merge branch 'develop' into 'develop'

Develop

See merge request !63
parents acfee411 b5f3f45d
...@@ -40,7 +40,7 @@ qt_wrap_cpp( viewer_moc viewer.h ) ...@@ -40,7 +40,7 @@ qt_wrap_cpp( viewer_moc viewer.h )
add_executable( viewer viewer.cpp ${viewer_moc} ${viewer_ui} ) add_executable( viewer viewer.cpp ${viewer_moc} ${viewer_ui} )
target_link_libraries( viewer ${CGoGN_LIBS} ${NUMERICAL_LIBS} ${CGoGN_EXT_LIBS} ) 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_ui( clipping_ui clipping.ui )
qt_wrap_cpp( clipping_moc clipping.h ) qt_wrap_cpp( clipping_moc clipping.h )
add_executable( clipping clipping.cpp ${clipping_ui} ${clipping_moc} ) add_executable( clipping clipping.cpp ${clipping_ui} ${clipping_moc} )
......
...@@ -94,6 +94,12 @@ void quadranguleFaces(typename PFP::MAP& map, EMBV& attributs) ; ...@@ -94,6 +94,12 @@ void quadranguleFaces(typename PFP::MAP& map, EMBV& attributs) ;
template <typename PFP, typename EMBV> template <typename PFP, typename EMBV>
void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs) ; 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 * Loop subdivision scheme
*/ */
......
...@@ -180,9 +180,142 @@ void quadranguleFaces(typename PFP::MAP& map, EMBV& attributs) ...@@ -180,9 +180,142 @@ void quadranguleFaces(typename PFP::MAP& map, EMBV& attributs)
// quadranguleFaces<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, position) ; // 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> template <typename PFP, typename EMBV>
void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs) void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs)
{ {
typedef typename PFP::MAP MAP; typedef typename PFP::MAP MAP;
typedef typename EMBV::DATA_TYPE EMB; typedef typename EMBV::DATA_TYPE EMB;
...@@ -233,7 +366,6 @@ void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs) ...@@ -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 if ( !map.template isBoundaryMarked<2>(d) && mf.isMarked(d)) // for each face not subdivided
{ {
// compute center skip darts of new vertices non embedded // compute center skip darts of new vertices non embedded
// EMB center = AttribOps::zero<EMB,PFP>();
EMB center(0.0); EMB center(0.0);
unsigned int count = 0 ; unsigned int count = 0 ;
mf.template unmarkOrbit<FACE>(d) ; mf.template unmarkOrbit<FACE>(d) ;
...@@ -251,11 +383,12 @@ void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs) ...@@ -251,11 +383,12 @@ void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs)
center /= float(count); center /= float(count);
Dart cf = quadranguleFace<PFP>(map, d); // quadrangule the face Dart cf = quadranguleFace<PFP>(map, d); // quadrangule the face
attributs[cf] = center; // affect the data to the central vertex attributs[cf] = center; // affect the data to the central vertex
} }
} }
// Compute edge points // 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; Dart x = *mid;
// other side of the edge // other side of the edge
...@@ -263,52 +396,195 @@ void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs) ...@@ -263,52 +396,195 @@ void CatmullClarkSubdivision(typename PFP::MAP& map, EMBV& attributs)
{ {
Dart f1 = map.phi_1(x); Dart f1 = map.phi_1(x);
Dart f2 = map.phi2(map.phi1(map.phi2(x))); Dart f2 = map.phi2(map.phi1(map.phi2(x)));
// EMB temp = AttribOps::zero<EMB,PFP>(); attributs[x] += (attributs[f1] + attributs[f2]) / 4.0 - (attributs[x] / 2.0);
// 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 // else nothing to do point already in the middle of segment
} }
// Compute vertex points // 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); m0.unmark(*vert);
// EMB temp = AttribOps::zero<EMB,PFP>(); EMB sumFace(0.0); // Sum_F
// EMB temp2 = AttribOps::zero<EMB,PFP>(); EMB sumEdge(0.0);// Sum_E
EMB temp(0.0);
EMB temp2(0.0);
unsigned int n = 0; int n = 0;
Dart x = *vert; Dart x = *vert;
do do
{ {
Dart m = map.phi1(x); Dart m = map.phi1(x);
Dart f = map.phi2(m); 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; ++n;
x = map.phi2_1(x); x = map.phi2_1(x);
} while (x != *vert); } while (x != *vert);
EMB emcp = attributs[*vert]; EMB deltaV = attributs[*vert] * float(-3*n); // (-3 * attributs[*vert]
emcp *= float((n-2)*n); // V' = (n-2)/n*V + 1/n2 *(F+E) deltaV += sumFace; // + sumFace/n
emcp += temp; deltaV += 2.0*sumEdge; // + sumEdge/n)
emcp += temp2; deltaV /= float(n*n); // /n
emcp /= float(n*n);
attributs[*vert] = emcp ; 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);
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> //template <typename PFP>
//void CatmullClarkSubdivision(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position) //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 ...@@ -536,8 +536,11 @@ void MapRender::initPrimitives(typename PFP::MAP& map, int prim, const VertexAtt
m_indexBufferUpToDate[prim] = true; m_indexBufferUpToDate[prim] = true;
// setup du buffer d'indices // setup du buffer d'indices
if (m_nbIndices[prim] > 0)
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[prim]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[prim]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_nbIndices[prim] * sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_nbIndices[prim] * sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW);
}
} }
template <typename PFP> template <typename PFP>
......
...@@ -67,6 +67,9 @@ public: ...@@ -67,6 +67,9 @@ public:
unsigned int setAttributePosition(VBO* vbo); unsigned int setAttributePosition(VBO* vbo);
void setClippingPlane(const Geom::Vec4f& plane); void setClippingPlane(const Geom::Vec4f& plane);
inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); }
}; };
} // namespace Utils } // namespace Utils
......
...@@ -39,41 +39,43 @@ namespace CGoGN ...@@ -39,41 +39,43 @@ namespace CGoGN
namespace Utils namespace Utils
{ {
#ifdef CGOGN_USE_OGL_CORE_PROFILE //#ifdef CGOGN_USE_OGL_CORE_PROFILE
unsigned int GLSLShader::CURRENT_OGL_VERSION = 3; //unsigned int GLSLShader::CURRENT_OGL_VERSION = 3;
unsigned int GLSLShader::MAJOR_OGL_CORE = 3; //unsigned int GLSLShader::MAJOR_OGL_CORE = 3;
unsigned int GLSLShader::MINOR_OGL_CORE = 3; //unsigned int GLSLShader::MINOR_OGL_CORE = 3;
#else //#else
unsigned int GLSLShader::CURRENT_OGL_VERSION = 2; //unsigned int GLSLShader::CURRENT_OGL_VERSION = 2;
unsigned int GLSLShader::MAJOR_OGL_CORE = 2; //unsigned int GLSLShader::MAJOR_OGL_CORE = 2;
unsigned int GLSLShader::MINOR_OGL_CORE = 1; //unsigned int GLSLShader::MINOR_OGL_CORE = 1;
#endif //#endif
std::string GLSLShader::DEFINES_GL2=\
"#version 110\n"
"#define PRECISION float pipo_PRECISION\n" //std::string GLSLShader::DEFINES_GL2=\
"#define ATTRIBUTE attribute\n" //"#version 110\n"
"#define VARYING_VERT varying\n" //"#define PRECISION float pipo_PRECISION\n"
"#define VARYING_FRAG varying\n" //"#define ATTRIBUTE attribute\n"
"#define FRAG_OUT_DEF float pipo_FRAGDEF\n" //"#define VARYING_VERT varying\n"
"#define FRAG_OUT gl_FragColor\n" //"#define VARYING_FRAG varying\n"
"#define INVARIANT_POS float pipo_INVARIANT\n" //"#define FRAG_OUT_DEF float pipo_FRAGDEF\n"
"#define TEXTURE2D texture2D\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" //std::string GLSLShader::DEFINES_GL3=\
"#define ATTRIBUTE in\n" //"#version 150\n"
"#define VARYING_VERT out\n" //"#define PRECISION precision highp float\n"
"#define VARYING_FRAG in\n" //"#define ATTRIBUTE in\n"
"#define FRAG_OUT_DEF out vec4 outFragColor\n" //"#define VARYING_VERT out\n"
"#define FRAG_OUT outFragColor\n" //"#define VARYING_FRAG in\n"
"#define INVARIANT_POS invariant gl_Position\n" //"#define FRAG_OUT_DEF out vec4 outFragColor\n"
"#define TEXTURE2D texture\n" //"#define FRAG_OUT outFragColor\n"
; //"#define INVARIANT_POS invariant gl_Position\n"
//"#define TEXTURE2D texture\n";
std::string* GLSLShader::DEFINES_GL = NULL;
//std::string* GLSLShader::DEFINES_GL = NULL;
std::vector<std::string> GLSLShader::m_pathes; std::vector<std::string> GLSLShader::m_pathes;
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
* Contact information: cgogn@unistra.fr * * Contact information: cgogn@unistra.fr *
* * * *
*******************************************************************************/ *******************************************************************************/
#define CGoGN_UTILS_DLL_EXPORT 1 #define CGoGN_UTILS_DLL_EXPORT 1
#include <GL/glew.h> #include <GL/glew.h>
#include "Utils/Shaders/shaderPhong.h" #include "Utils/Shaders/shaderPhong.h"
...@@ -37,6 +36,7 @@ namespace Utils ...@@ -37,6 +36,7 @@ namespace Utils
#include "shaderPhongClip.vert" #include "shaderPhongClip.vert"
#include "shaderPhongClip.frag" #include "shaderPhongClip.frag"
ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePosition): ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePosition):
m_with_color(false), m_with_color(false),
m_with_eyepos(withEyePosition), m_with_eyepos(withEyePosition),
...@@ -54,17 +54,30 @@ ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePositi ...@@ -54,17 +54,30 @@ ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePositi
std::string glxvert(GLSLShader::defines_gl()); std::string glxvert(GLSLShader::defines_gl());
std::string glxfrag(GLSLShader::defines_gl());