Commit d6ae7f40 authored by Maire Nicolas's avatar Maire Nicolas

Merge branch 'master' of cgogn:~cgogn/CGoGN

parents 08e3f5a8 19782a24
......@@ -43,6 +43,11 @@ add_executable( frame_manipD ../frame_manip.cpp ${frame_manip_moc})
target_link_libraries( frame_manipD
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_CPP(texturesExample_moc ../texturesExample.h)
add_executable( texturesExampleD ../texturesExample.cpp ${texturesExample_moc} )
target_link_libraries( texturesExampleD
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_CPP(extrusionView_moc ../extrusionView.h)
add_executable( extrusionViewD ../extrusionView.cpp ${extrusionView_moc})
target_link_libraries( extrusionViewD
......
......@@ -46,6 +46,11 @@ QT4_WRAP_CPP(frame_manip_moc ../frame_manip.h)
add_executable( frame_manip ../frame_manip.cpp ${frame_manip_moc})
target_link_libraries( frame_manip
${CGoGN_LIBS_R} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_CPP(texturesExample_moc ../texturesExample.h)
add_executable( texturesExample ../texturesExample.cpp ${texturesExample_moc} )
target_link_libraries( texturesExample
${CGoGN_LIBS_R} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_CPP(extrusionView_moc ../extrusionView.h)
add_executable( extrusionView ../extrusionView.cpp ${extrusionView_moc})
......
/*
* texture.cpp
*
* Created on: Jul 25, 2011
* Author: thery
*/
/*
* texturesExample.cpp
*
* Created on: Jul 21, 2011
* Author: thery
*/
#include "texturesExample.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Modelisation/polyhedron.h"
TexView::TexView():
m_render(NULL), m_positionVBO(NULL), m_texcoordVBO(NULL), m_texture(NULL), m_shader(NULL),m_modeMask(false),m_fileName("")
{
}
TexView::~TexView()
{
delete m_render;
delete m_shader;
delete m_positionVBO;
delete m_texcoordVBO;
delete m_texture;
}
void TexView::cb_initGL()
{
// choose to use GL version 2
Utils::GLSLShader::setCurrentOGLVersion(2);
// create the render
m_render = new Algo::Render::GL2::MapRender();
// create VBO for position
m_positionVBO = new Utils::VBO;
m_texcoordVBO = new Utils::VBO;
m_texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
computeImage();
m_texture->update();
m_mask = new Utils::Texture<2,float>(GL_FLOAT);
m_mask->create(Geom::Vec2ui(256,256));
createMask(8);
m_mask->update();
m_shader = new Utils::ShaderSimpleTexture();
m_shader->setAttributePosition(m_positionVBO);
m_shader->setAttributeTexCoord(m_texcoordVBO);
m_shader->setTextureUnit(GL_TEXTURE0);
m_shader->setTexture(m_texture);
registerShader(m_shader);
m_shader2 = new Utils::ShaderTextureMask();
m_shader2->setAttributePosition(m_positionVBO);
m_shader2->setAttributeTexCoord(m_texcoordVBO);
m_shader2->setTextureUnits(GL_TEXTURE0,GL_TEXTURE1);
m_shader2->setTextures(m_texture,m_mask);
registerShader(m_shader2);
glEnable(GL_TEXTURE_2D);
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
}
void TexView::cb_redraw()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
if (m_shader)
{
if (m_modeMask)
{
m_shader2->activeTextures();
m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES);
}
else
{
m_shader->activeTexture();
m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES);
}
}
}
void TexView::cb_keyPress(int code)
{
switch(code)
{
case 'l':
m_texture->setFiltering(GL_LINEAR);
break;
case 'n':
m_texture->setFiltering(GL_NEAREST);
break;
case 'm':
m_modeMask = !m_modeMask;
if (m_modeMask)
{
createMask(16);
m_mask->update();
}
break;
case 'M':
m_modeMask = !m_modeMask;
if (m_modeMask)
{
createMask(8);
m_mask->update();
}
break;
case 's':
m_texture->subSample2<Geom::Vec3d>();
m_texture->update();
break;
case 't':
m_texture->rotate90(3);
m_texture->update();
break;
case 'r':
m_texture->load(m_fileName);
m_texture->update();
break;
}
updateGL();
}
void TexView::cb_Open()
{
std::string filename = selectFile("Open Image","/tmp");
if (!filename.empty())
{
m_fileName = filename;
if (m_texture->load(filename))
{
m_texture->update();
updateGL();
}
else
CGoGNerr << "Problem loading image"<< CGoGNendl;
}
else
{
computeImage();
m_texture->update();
updateGL();
}
}
void TexView::createMask(unsigned int nb)
{
if (nb ==0)
return;
unsigned int sz0 = m_mask->size()[0]/nb;
unsigned int sz1 = m_mask->size()[1]/nb;
for (unsigned int j=0; j<m_mask->size()[1]; ++j)
for (unsigned int i=0; i<m_mask->size()[0]; ++i)
{
bool b1 = (i/sz0)%2 ==0;
bool b2 = (j/sz1)%2 ==0;
if (b1!=b2)
(*m_mask)(i,j)=1.0f;
else
(*m_mask)(i,j)= 0.0f;
}
}
void TexView::computeImage()
{
std::vector<Geom::Vec3f> colorTable;
colorTable.push_back(Geom::Vec3uc(255,0,0));
colorTable.push_back(Geom::Vec3uc(0,255,0));
colorTable.push_back(Geom::Vec3uc(0,0,255));
colorTable.push_back(Geom::Vec3uc(255,255,0));
colorTable.push_back(Geom::Vec3uc(255,0,255));
colorTable.push_back(Geom::Vec3uc(0,255,255));
colorTable.push_back(Geom::Vec3uc(255,255,255));
m_texture->create(Geom::Vec2ui(512,512));
#define WIDTHCHECKER 20
for (unsigned int ki = 0; ki < m_texture->size()[0]; ++ki)
{
for (unsigned int kj = 0; kj < m_texture->size()[1]; ++kj)
{
unsigned int kc = ((kj/WIDTHCHECKER)*m_texture->size()[0] + (ki/WIDTHCHECKER))%7;
(*m_texture)(ki,kj) =colorTable[kc];
}
}
#undef WIDTHCHECKER
}
int main(int argc, char**argv)
{
ilInit();
// interface:
QApplication app(argc, argv);
TexView tv;
PFP::MAP& m = tv.myMap;
AttributeHandler<PFP::VEC3> position = m.addAttribute<PFP::VEC3>(VERTEX, "position");
AttributeHandler<Geom::Vec2f> texcoord = m.addAttribute<Geom::Vec2f>(VERTEX, "texcoord");
#define NB 96
Algo::Modelisation::Polyhedron<PFP> prim(m, position);
prim.tore_topo(NB, NB);
prim.embedTore(40.0f,20.0f);
Dart d = prim.getDart();
for(unsigned int i=0; i<NB; ++i)
{
for(unsigned int j=0; j<NB; ++j)
{
float a;
if (i<=NB/2)
a = (2.0f/NB)*i;
else
a = (2.0f/NB)*(NB-i);
float b;
if (j<=NB/2)
b = (2.0f/NB)*j;
else
b =(2.0f/NB)*(NB-j);
texcoord[d] = Geom::Vec2f(a,b);
d = m.phi<121>(d);
}
d = m.phi<211>(d);
}
#undef NB
// bounding box
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(m, position);
float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
// envoit info BB a l'interface
tv.setParamObject(lWidthObj, lPosObj.data());
// show 1 pour GL context
tv.show();
// update des VBO (position et texture coord)
tv.m_positionVBO->updateData(position);
tv.m_texcoordVBO->updateData(texcoord);
// show final pour premier redraw
tv.show();
// et on attend la fin.
return app.exec();
}
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef _TEXTURE_EXAMPLE_
#define _TEXTURE_EXAMPLE_
#include <iostream>
#include "Utils/qtSimple.h"
#include "Utils/textures.h"
#include "Utils/Shaders/shaderSimpleTexture.h"
#include "Utils/Shaders/shaderTextureMask.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/map2.h"
#include "Topology/generic/embeddedMap2.h"
#include "Algo/Render/GL2/mapRender.h"
// forward definitions (minimize includes)
namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; }}}}
namespace CGoGN { namespace Utils { class VBO; } }
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2<Map2> MAP ;
};
typedef PFP::MAP MAP ;
/**
* A class for a little interface and rendering
*/
class TexView: public Utils::QT::SimpleQT
{
Q_OBJECT
protected:
void createMask(unsigned int nb);
void computeImage();
public:
MAP myMap ;
SelectorTrue allDarts ;
// render
Algo::Render::GL2::MapRender* m_render;
// VBO
Utils::VBO* m_positionVBO;
Utils::VBO* m_texcoordVBO;
Utils::Texture<2,Geom::Vec3uc>* m_texture;
Utils::Texture<2,float>* m_mask;
//2 shaders
Utils::ShaderSimpleTexture* m_shader;
Utils::ShaderTextureMask* m_shader2;
//with mask or not
bool m_modeMask;
/// filename of last loaded texture
std::string m_fileName;
TexView();
~TexView();
// callbacks of simpleQT to overdefine:
void cb_redraw();
void cb_initGL();
void cb_keyPress(int code);
void cb_Open();
};
#endif
......@@ -334,13 +334,13 @@ void MyQT::cb_initGL()
m_shader = new Utils::ShaderPhong();
m_shader->setAttributePosition(m_positionVBO);
m_shader->setAttributeNormal(m_normalVBO);
m_shader->setDiffuse(Geom::Vec4f(0.,0.6,0.,0.));
m_shader->setSpecular(Geom::Vec4f(0.,0.0,0.,0.)); // no specular
m_shader->setDiffuse(Geom::Vec4f(0.0f,0.6f,0.0f,0.0f));
m_shader->setSpecular(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); // no specular
// using simple shader with color
m_shader2 = new Utils::ShaderSimpleColor();
m_shader2->setAttributePosition(m_positionVBO);
m_shader2->setColor(Geom::Vec4f(0.,0.1,0.,0.));
m_shader2->setColor(Geom::Vec4f(0.0f,0.1f,0.0f,0.0f));
registerShader(m_shader);
registerShader(m_shader2);
}
......
......@@ -160,7 +160,7 @@ void MyQT::cb_initGL()
m_sprite = new Utils::PointSprite();
m_sprite->setAttributePosition(m_positionVBO);
m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1,0.,0.3));
m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f));
storeVerticesInfo();
m_strings->sendToVBO();
......@@ -192,7 +192,7 @@ void MyQT::cb_initGL()
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS);
m_render_topo->updateData<PFP>(myMap, allDarts, position, 0.9, 0.9, 0.9);
m_render_topo->updateData<PFP>(myMap, allDarts, position, 0.9f, 0.9f, 0.9f);
// timer example for animation
......@@ -284,7 +284,7 @@ int main(int argc, char **argv)
{
position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
CGoGNout << 5.34 << " toto "<< Geom::Vec3f(2.5, 2.2, 4.3) << CGoGNendl;
CGoGNout << 5.34 << " toto "<< Geom::Vec3f(2.5f, 2.2f, 4.3f) << CGoGNendl;
CGoGNout << 3 << " tutu "<< 4 <<CGoGNendl;
......@@ -307,11 +307,11 @@ int main(int argc, char **argv)
sqt.setHelpMsg("Enter pour dock on/off\nShift Enter pour console on/off\nShift Click gauche pour selectionner un brin");
CGoGNout.toStatusBar(&sqt);
CGoGNout << "CGoGNOut StatusBar" << Geom::Vec3f(2.5, 2.2, 4.3) << CGoGNendl;
CGoGNout << "CGoGNOut StatusBar" << Geom::Vec3f(2.5f, 2.2f, 4.3f) << CGoGNendl;
CGoGNout.toConsole(&sqt);
CGoGNout << "CGoGNOut dans la console" << Geom::Vec3f(2.5, 2.2, 4.3) << CGoGNendl;
CGoGNout << "CGoGNOut dans la console" << Geom::Vec3f(2.5f, 2.2f, 4.3f) << CGoGNendl;
CGoGNout.toStatusBar(NULL);
CGoGNout << "tirelipinpon .." << CGoGNendl;
......
......@@ -2,26 +2,33 @@ Prérequis:
Visual Studio ou C++ Express (au moins 2005)
CMake (au moins 2.6)
Unziper le windows_dependencies.zip (http://iggservis.u-strasbg.fr/Data/) a la racine de CGoGN
Lancer CMake
Mettre le chemin de la racine de CGoGN + /ThirdParty pour les sources
Mettre le chemin de la racine de CGoGN + /ThirdParty/Visual (par exemple) pour le build
Cliquer sur Configure
Choisir le bon compilateur (celui de votre version de Visual C++)
Recliquer sur Configure
Cliquer sur Generate
Aller compiler sous visual(en release)
Relancer CMake
Mettre le chemin de la racine de CGoGN + /build pour les sources
Mettre le chemin de la racine de CGoGN + /Visual (par exemple) pour le build
ajouter deux entrees dans le cache (pour utilisation de boost precompile: www.boostpro.com)
boost_path avec le chemin d'acces (exemple: C:\Program Files\boost\boost_1_44\)
boost_extension avec ce que vous voulez utiliser (exemple: -vc100-mt-1_44)
Cliquer sur Configure
Choisir le bon compilateur (celui de votre version de Visual C++)
Recliquer sur Configure
Cliquer sur Generate
Unziper le windows_dependencies.zip (http://iggservis.u-strasbg.fr/Data/) a la racine de CGoGN
Aller dans Visual et double-cliquer sur CGoGN.sln !!
Pour que les executables fonctionnent ajouter le chemin vers les dll dans la variable d'environnement path
(ou copier les dll dans un répertoire déjà dans le path)
Remarque pour l'utilisation de boost (manière simple):
-installer les binaires a l'aide de boostpro (www.boostpro.com)
-definir la varible d'env "boost_extension" avec ce que vous voulez utiliser (exemple: -vc100-mt-1_44)
-definir la varible d'env "boost_path" avec le chemin d'acces (exemple: C:\Program Files\boost\boost_1_44\)
-ajouter le chemin vers les dll dans le path (comme cf ci-dessus)
......
......@@ -39,15 +39,15 @@ IF(WIN32)
MACRO(BOOST_LIBS lib_lists names)
SET (${lib_lists} "")
FOREACH(name ${names})
STRING(REGEX REPLACE "-mt" $ENV{boost_extension} newname ${name})
STRING(REGEX REPLACE "-mt" ${boost_extension} newname ${name})
SET (${lib_lists} ${${lib_lists}} ${newname} )
ENDFOREACH(name)
ENDMACRO(BOOST_LIBS)
set (BOOST_INCLUDE_PATH $ENV{boost_path})
set (BOOST_INCLUDE_PATH ${boost_path})
INCLUDE_DIRECTORIES(${CGoGN_ROOT_DIR}/windows_dependencies/include/)
LINK_DIRECTORIES(${CGoGN_ROOT_DIR}/windows_dependencies/lib/ $ENV{boost_path}/lib)
LINK_DIRECTORIES(${CGoGN_ROOT_DIR}/windows_dependencies/lib/ ${boost_path}/lib)
add_subdirectory(Release)
add_subdirectory(${CGoGN_ROOT_DIR}/Apps Apps)
if (EXISTS "${CGoGN_ROOT_DIR}/Perso")
......
......@@ -1127,7 +1127,7 @@ bool MeshTablesSurface<PFP>::importASSIMP(const std::string& filename, std::vect
template<typename PFP>
bool MeshTablesSurface<PFP>::mergeCloseVertices()
{
const unsigned int NBV=64; // seems to be good
const int NBV=64; // seems to be good
const int NEIGH[27]={
-NBV*NBV - NBV - 1, -NBV*NBV - NBV, -NBV*NBV - NBV + 1,
......
......@@ -25,6 +25,9 @@
#include "Algo/Geometry/centroid.h"
#include "Topology/generic/autoAttributeHandler.h"
#define _USE_MATH_DEFINES
#include <math.h>
namespace CGoGN
{
......
......@@ -59,6 +59,9 @@ public:
Vector(const Vector<DIM,T>& v) ;
template <typename T2>
Vector(const Vector<DIM,T2>& v) ;
Vector(T x, T y) ;
Vector(T x, T y, T z) ;
......
......@@ -61,6 +61,15 @@ Vector<DIM,T>::Vector(const Vector<DIM,T>& v)
m_data[i] = v[i] ;
}
template <unsigned int DIM, typename T>
template <typename T2>
Vector<DIM,T>::Vector(const Vector<DIM,T2>& v)
{
for(unsigned int i = 0; i < DIM; ++i)
m_data[i] = T(v[i]) ;
}
template <unsigned int DIM, typename T>
Vector<DIM,T>::Vector(T x, T y)
{
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __CGOGN_SHADER_SIMPLETEXTURE__
#define __CGOGN_SHADER_SIMPLETEXTURE__
#include "Geometry/vector_gen.h"
#include "Utils/GLSLShader.h"
#include "Utils/textures.h"
namespace CGoGN
{
namespace Utils
{
class ShaderSimpleTexture : public GLSLShader
{
protected:
// shader sources
static std::string vertexShaderText;
static std::string fragmentShaderText;
GLuint m_unif_unit;
int m_unit;
Utils::GTexture* m_tex_ptr;
VBO* m_vboPos;
VBO* m_vboTexCoord;
void restoreUniformsAttribs();
public:
ShaderSimpleTexture();
/**
* choose the texture unit engine to use for this texture
*/
void setTextureUnit(GLenum texture_unit);
/**
* set the texture to use
*/
void setTexture(Utils::GTexture* tex);
/**
* activation of texture unit
*/
void activeTexture();
unsigned int setAttributePosition(VBO* vbo);
unsigned int setAttributeTexCoord(VBO* vbo);
};
} // namespace Utils
} // namespace CGoGN
#endif /* __CGOGN_SHADER_SIMPLETEXTURE__ */
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __CGOGN_SHADERTEXTUREMASK_H_
#define __CGOGN_SHADERTEXTUREMASK_H_
#include "Geometry/vector_gen.h"
#include "Utils/GLSLShader.h"
#include "Utils/textures.h"
namespace CGoGN
{
namespace Utils
{