Commit 92e95d00 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

Merge cgogn:~thery/CGoGN

parents 2a8275df 0952c461
......@@ -27,7 +27,7 @@ IF(WIN32)
ENDIF(WIN32)
find_package(OpenGL REQUIRED)
find_package(Boost COMPONENTS regex thread REQUIRED)
find_package(Boost COMPONENTS regex thread system REQUIRED)
find_package(ZLIB REQUIRED)
find_package(LibXml2 REQUIRED)
find_package(GLEW REQUIRED)
......@@ -82,6 +82,7 @@ SET (CGoGN_EXT_LIBS
${GLEW_LIBRARIES}
${ZLIB_LIBRARIES}
${LIBXML2_LIBRARIES}
${Boost_SYSTEM_LIBRARY}
${Boost_REGEX_LIBRARY}
${Boost_THREAD_LIBRARY} )
......
......@@ -34,7 +34,7 @@ ENDIF(WIN32)
find_package(OpenGL REQUIRED)
find_package(Boost COMPONENTS regex thread REQUIRED)
find_package(Boost COMPONENTS regex thread system REQUIRED)
find_package(ZLIB REQUIRED)
find_package(LibXml2 REQUIRED)
find_package(GLEW REQUIRED)
......@@ -65,6 +65,7 @@ SET (COMMON_LIBS
${GLEW_LIBRARIES}
${ZLIB_LIBRARIES}
${LIBXML2_LIBRARIES}
${Boost_SYSTEM_LIBRARY}
${Boost_REGEX_LIBRARY}
${Boost_THREAD_LIBRARY} )
......
......@@ -45,11 +45,10 @@ namespace Modelisation
enum { NONE, GRID, CUBE, CYLINDER, CONE, SPHERE, TORE, COMPOSED };
/**
* sudivide the all quads of primtive into 2 triangles
* the vertex darts table remain valid (adding only darts, no remove)
* sudivide the all quads of a CC into 2 triangles
*/
// template <typename PFP>
// void onlyTriangles(typename PFP::MAP& the_map, Dart primd);
template <typename PFP>
void quads2TrianglesCC(typename PFP::MAP& the_map, Dart primd);
/**
* Create a triangle fans (to close cylinders)
......
......@@ -1142,52 +1142,51 @@ void Polyhedron<PFP>::embedHelicoid(float radius_min, float radius_max, float ma
}
}
// template <typename PFP>
// void onlyTriangles(typename PFP::MAP& the_map, Dart primd)
// {
// DartMarker m(the_map);
//
// // list of faces to process and processed(before pos iterator)
// std::list<Dart> ld;
// ld.push_back(primd);
// // current position in list
// typename std::list<Dart>::iterator pos = ld.begin();
// do
// {
// Dart d = *pos;
//
// // cut the face of first dart of list
// Dart d1 = the_map.phi1(d);
// Dart e = the_map.phi1(d1);
// Dart e1 = the_map.phi1(e);
// Dart f = the_map.phi1(e1);
// m.markOrbit<FACE>(d);
// if (f==d) // quad
// {
// Dart n = the_map.cutFace(d,e);
// Dart nn = the_map.phi2(n);
// // mark the face
// m.mark(n);
// m.mark(nn);
// }
//
// // and store neighbours faces in the list
// d = the_map.phi2(d);
// e = the_map.phi2(e);
// d1 = the_map.phi1(the_map.phi2(d1));
// e1 = the_map.phi1(the_map.phi2(e1));
//
// if (!m.isMarked(d))
// ld.push_back(d);
// if (!m.isMarked(e))
// ld.push_back(e);
// if (!m.isMarked(d1))
// ld.push_back(d1);
// if ((f==d) && (!m.isMarked(e1)))
// ld.push_back(e1);
// pos++;
// }while (pos!=ld.end()); // stop when no more face to process
// }
template <typename PFP>
void quads2TrianglesCC(typename PFP::MAP& the_map, Dart primd)
{
DartMarker m(the_map);
// list of faces to process and processed(before pos iterator)
std::list<Dart> ld;
ld.push_back(primd);
// current position in list
typename std::list<Dart>::iterator pos = ld.begin();
do
{
Dart d = *pos;
// cut the face of first dart of list
Dart d1 = the_map.phi1(d);
Dart e = the_map.phi1(d1);
Dart e1 = the_map.phi1(e);
Dart f = the_map.phi1(e1);
if (f==d) // quad
{
the_map.splitFace(d,e);
// mark the face
m.markOrbit<FACE>(d);
m.markOrbit<FACE>(e);
}
else m.markOrbit<FACE>(d);
// and store neighbours faces in the list
d = the_map.phi2(d);
e = the_map.phi2(e);
d1 = the_map.phi1(the_map.phi2(d1));
e1 = the_map.phi1(the_map.phi2(e1));
if (!m.isMarked(d))
ld.push_back(d);
if (!m.isMarked(e))
ld.push_back(e);
if (!m.isMarked(d1))
ld.push_back(d1);
if ((f==d) && (!m.isMarked(e1)))
ld.push_back(e1);
pos++;
}while (pos!=ld.end()); // stop when no more face to process
}
// template <typename PFP>
// Dart triangleFan_topo(typename PFP::MAP& the_map, int n)
......
......@@ -26,6 +26,7 @@
#define __COLLECTOR_H__
#include "Container/fakeAttribute.h"
#include "Geometry/basic.h"
/*****************************************
* Class hierarchy :
......
......@@ -212,7 +212,7 @@ void verticesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename
template<typename PFP>
void volumesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const FunctorSelect& good, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& vecVolumes)
{
std::vector<Dart>& vecFaces;
std::vector<Dart> vecFaces;
std::vector<typename PFP::VEC3> iPoints;
// get back intersected faces
......@@ -425,7 +425,7 @@ void facesPlanSelection(typename PFP::MAP& map, const VertexAttribute<typename P
* @param angle angle of the code in degree.
*/
template<typename PFP>
void verticesConeSelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, float angle, std::vector<Dart>& vecVertices, const FunctorSelect& good= allDarts)
void verticesConeSelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, float angle, std::vector<Dart>& vecVertices, const FunctorSelect& good)
{
typename PFP::REAL AB2 = rayAB * rayAB;
......@@ -533,7 +533,7 @@ void edgesConeSelection(typename PFP::MAP& map, const VertexAttribute<typename P
template<typename PFP>
Dart verticesBubbleSelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& cursor, typename PFP::REAL radiusMax, const FunctorSelect& good=allDarts)
Dart verticesBubbleSelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& cursor, typename PFP::REAL radiusMax, const FunctorSelect& good)
{
typename PFP::REAL l2max = radiusMax*radiusMax;
typename PFP::REAL l2min(std::numeric_limits<float>::max());
......@@ -555,7 +555,7 @@ Dart verticesBubbleSelection(typename PFP::MAP& map, const VertexAttribute<typen
template<typename PFP>
Dart edgesBubbleSelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& cursor, typename PFP::REAL radiusMax, const FunctorSelect& good=allDarts)
Dart edgesBubbleSelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& cursor, typename PFP::REAL radiusMax, const FunctorSelect& good)
{
typename PFP::REAL l2max = radiusMax*radiusMax;
typename PFP::REAL l2min(std::numeric_limits<float>::max());
......@@ -661,7 +661,7 @@ Dart edgesBubbleSelection(typename PFP::MAP& map, const VertexAttribute<typename
//
//
//template<typename PFP>
//void verticesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& vecVertices, float dist, const FunctorSelect& good= allDarts, unsigned int nbth=0, unsigned int current_thread=0)
//void verticesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& vecVertices, float dist, const FunctorSelect& good , unsigned int nbth=0, unsigned int current_thread=0)
//{
// typename PFP::REAL dist2 = dist * dist;
// typename PFP::REAL AB2 = rayAB * rayAB;
......
......@@ -239,7 +239,7 @@ typename VEC3::DATA_TYPE squaredDistanceLine2Seg(const VEC3& A, const VEC3& AB,
}
template <typename VEC3>
float squaredDistanceSeg2Point(const VEC3& A, const VEC3& AB, typename VEC3::DATA_TYPE AB2, const VEC3& P)
typename VEC3::DATA_TYPE squaredDistanceSeg2Point(const VEC3& A, const VEC3& AB, typename VEC3::DATA_TYPE AB2, const VEC3& P)
{
typedef typename VEC3::DATA_TYPE T ;
......
......@@ -79,6 +79,9 @@ protected:
static std::string defines_Geom(const std::string& primitivesIn, const std::string& primitivesOut, int maxVert);
int m_nbMaxVertices;
/**
* handle of vertex shader
*/
......@@ -167,7 +170,7 @@ protected:
/**
* create the shader (attach and link shaders into program)
*/
bool create(GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLES, int nb_max_vertices=16);
bool create(GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLES, int nb_max_vertices=-1);
/**
* get log after compiling
......@@ -270,6 +273,8 @@ public:
bool recompile();
bool changeNbMaxVertices(int nb_max_vertices);
/**
* Link the shader do it just after binding the attributes
*/
......
......@@ -197,6 +197,8 @@ public:
*/
void setParamObject(float width, float* pos) { m_glWidget->setParamObject(width, pos); }
void resetCenterOfRotation(float width, float* pos) { m_glWidget->resetCenterOfRotation(width, pos); }
/**
* make the contex of glWidget current
*/
......
......@@ -82,6 +82,8 @@ protected:
float m_obj_sc;
glm::vec3 m_obj_pos;
glm::vec3 m_obj_pos_save;
float m_obj_width;
// width and height of windows
int W;
......@@ -106,6 +108,8 @@ protected:
void changeCenterOfRotation(const glm::vec3& newCenter);
public:
void resetCenterOfRotation(float width, float* pos);
void setParamObject(float width, float* pos);
void setRotation(bool b);
......
......@@ -2,6 +2,7 @@
PRECISON;
VARYING_FRAG vec3 color;
uniform float alpha;
FRAG_OUT_DEF;
void main()
{
......@@ -9,5 +10,5 @@ void main()
if (dot(color,color) == 0.0)
discard;
#endif
gl_FragColor=vec4(color,0.0);
gl_FragColor=vec4(color,alpha);
}
......@@ -45,14 +45,30 @@ protected:
VBO* m_vboPos;
VBO* m_vboCol;
CGoGNGLuint m_unif_alpha;
float m_opacity;
void restoreUniformsAttribs();
public:
ShaderColorPerVertex(bool black_is_transparent = false);
unsigned int setAttributePosition(VBO* vbo);
/**
* set the VBO of position (vec3)
*/
unsigned int setAttributePosition(VBO* vbo);
/**
* set the VBO of color (vec3)
*/
unsigned int setAttributeColor(VBO* vbo);
/**
* set opacity (0=transparent / 1=opaque)
*/
void setOpacity(float op);
float getOpacity() const { return m_opacity;}
};
} // namespace Utils
......
//ShaderEnvMap::fragmentShaderText
PRECISON;
VARYING_FRAG vec3 EyeVector, Normal, LightDir;
#ifdef WITH_COLOR
VARYING_FRAG vec3 Color;
#endif
uniform vec4 materialDiffuse;
uniform vec4 materialAmbient;
uniform samplerCube EnvMap;
uniform float blendCoef;
FRAG_OUT_DEF;
void main()
{
vec3 N = normalize (Normal);
vec3 L = normalize (LightDir);
float lambertTerm = dot(N,L);
vec4 finalColor = materialAmbient;
#ifdef DOUBLE_SIDED
if (lambertTerm < 0.0)
{
N = -1.0*N;
lambertTerm = -1.0*lambertTerm;
#else
if (lambertTerm > 0.0)
{
#endif
#ifndef WITH_COLOR
vec4 col = materialDiffuse;
#else
vec4 col = vec4(Color,0.0) ;
#endif
vec3 R = reflect(-EyeVector,N);
finalColor += mix(col,textureCube(EnvMap,R),blendCoef) * lambertTerm;
}
gl_FragColor=finalColor;
}
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __CGOGN_SHADER_ENVMAP__
#define __CGOGN_SHADER_ENVMAP__
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Geometry/vector_gen.h"
#include <string>
#ifdef WITH_QT
#include <QImage>
#endif
namespace CGoGN
{
namespace Utils
{
/**
* Class for shader environment mapping (cube mapping)
*
* @warning shader code is GL2.0 compatible for GL3.0 replace textureCube by texture in fragment shader !
*/
class ShaderEnvMap : public ClippingShader
{
protected:
// flag color per vertex or not
bool m_with_color;
// flag color per vertex or not
bool m_with_eyepos;
// shader sources OGL3
static std::string vertexShaderText;
static std::string fragmentShaderText;
// uniform locations
CGoGNGLuint m_unif_ambiant;
CGoGNGLuint m_unif_diffuse;
CGoGNGLuint m_unif_blend;
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_eyePos;
CGoGNGLuint m_unif_envMap;
//values
Geom::Vec4f m_ambiant;
Geom::Vec4f m_diffuse;
float m_blend;
Geom::Vec3f m_lightPos;
Geom::Vec3f m_eyePos;
CGoGNGLuint m_texId;
VBO* m_vboPos;
VBO* m_vboNormal;
VBO* m_vboColor;
void getLocations();
void sendParams();
void restoreUniformsAttribs();
public:
ShaderEnvMap(bool doubleSided = false, bool withEyePosition=false);
// inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant);
void setDiffuse(const Geom::Vec4f& diffuse);
void setSpecular(const Geom::Vec4f& specular);
void setBlendCoef(float blend);
void setLightPosition(const Geom::Vec3f& lp);
/// set eye position for VR environement
void setEyePosition(const Geom::Vec3f& ep);
const Geom::Vec4f& getAmbiant() const { return m_ambiant; }
const Geom::Vec4f& getDiffuse() const { return m_diffuse; }
float getBlendCoef() const { return m_blend; }
const Geom::Vec3f& getLightPosition() const { return m_lightPos; }
/**
* set all parameter in on call (one bind also)
*/
void setParams(const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, float blend, const Geom::Vec3f& lightPos);
// attributes
unsigned int setAttributePosition(VBO* vbo);
unsigned int setAttributeNormal(VBO* vbo);
// optional attributes
unsigned int setAttributeColor(VBO* vbo);
void unsetAttributeColor();
/**
* need to be called just before draw
*/
void predraw();
/**
* need to be called just after draw
*/
void postdraw();
void setCubeMap(unsigned int sz, unsigned char* Xpos, unsigned char* Ypos, unsigned char* Zpos, unsigned char* Xneg, unsigned char* Yneg, unsigned char* Zneg);
/**
* set envmap texture image
* image looks likre:
* Y
* XZXZ
* Y
* @parameter sz size of edge of cube in pixel
* @parameter ptr pointer on image data (RGB RGB RGB ....)
*/
bool setCubeMapImg(unsigned int sz, unsigned char *ptr);
/**
* set colored plane for testing
*/
bool setCubeMapColored();
/**
* set colored plane for testing
*/
bool setCubeMapCheckered();
#ifdef WITH_QT
bool setCubeMap(const std::string& filename);
#endif
};
} // namespace Utils
} // namespace CGoGN
#endif
//ShaderEnvMap::vertexShaderText
ATTRIBUTE vec3 VertexPosition, VertexNormal;
#ifdef WITH_COLOR
ATTRIBUTE vec3 VertexColor;
#endif
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ModelViewMatrix;
uniform mat4 NormalMatrix;
uniform vec3 lightPosition;
VARYING_VERT vec3 EyeVector, Normal, LightDir;
#ifdef WITH_COLOR
VARYING_VERT vec3 Color;
#endif
#ifdef WITH_EYEPOSITION
uniform vec3 eyePosition;
#endif
INVARIANT_POS;
void main ()
{
Normal = vec3 (NormalMatrix * vec4 (VertexNormal, 0.0));
vec3 Position = vec3 (ModelViewMatrix * vec4 (VertexPosition, 1.0));
LightDir = lightPosition - Position;
#ifdef WITH_EYEPOSITION
EyeVector = eyePosition-Position;
#else
EyeVector = -Position;
#endif
#ifdef WITH_COLOR
Color = VertexColor;
#endif
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);
}
// ShaderIsoLines::fragmentShaderText
VARYING_FRAG vec4 ColorFS;
void main()
{
gl_FragColor = ColorFS;
}
// ShaderIsoLines::geometryShaderText
uniform mat4 NormalMatrix;
uniform mat4 ModelViewMatrix;
uniform mat4 ModelViewProjectionMatrix;
uniform vec4 colorMin;
uniform vec4 colorMax;
uniform float vmin;
uniform float vmax;
uniform int vnb;
VARYING_IN float attribData[3];
VARYING_OUT vec4 ColorFS;
float bary(float x, float xmin, float xmax)
{
return (x-xmin)/(xmax-xmin);
}
/*
* warning works only with triangles
*/
void isoLine(float x)
{
ColorFS = mix(colorMin,colorMax,(x-vmin)/(vmax-vmin));
float b01 = bary(x,attribData[0],attribData[1]);
float b02 = bary(x,attribData[0],attribData[2]);
float b12 = bary(x,attribData[1],attribData[2]);
bool in01 = (b01>=0.0) && (b01<=1.0);
bool in02 = (b02>=0.0) && (b02<=1.0);
bool in12 = (b12>=0.0) && (b12<=1.0);
if (in01)
{
vec4 pos01 = ModelViewProjectionMatrix * mix(POSITION_IN(0),POSITION_IN(1),b01);
if (in02)
{
// line 01 - 02
gl_Position = pos01;
EmitVertex();
vec4 pos = mix(POSITION_IN(0),POSITION_IN(2),b02);
gl_Position = ModelViewProjectionMatrix * pos;
EmitVertex();
EndPrimitive();
}
if (in12)
{
// line 01 - 12
gl_Position = pos01;
EmitVertex();