Commit 4beeb689 authored by Thomas's avatar Thomas

modif exemple gmap2, ajout visu gmap 2 et 3

parent 4e1f6ec2
......@@ -54,6 +54,11 @@ add_executable( texturesExampleD ../texturesExample.cpp ${texturesExample_moc} )
target_link_libraries( texturesExampleD
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_CPP(simpleGMap2_moc ../simpleGMap2.h)
add_executable( simpleGMap2D ../simpleGMap2.cpp ${simpleGMap2_moc} )
target_link_libraries( simpleGMap2D
${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
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg *
* Copyright (C) 2009, 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 *
......@@ -17,432 +17,68 @@
* 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/ *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include <iostream>
#include "Utils/os_spec.h"
#include "simpleGMap2.h"
#include "Utils/GLSLShader.h"
#include "Utils/glutwin.h"
#include "Topology/generic/parameters.h"
#include "Topology/gmap/gmap2.h"
#include "Topology/generic/embeddedMap2.h"
#include "Geometry/matrix.h"
#include "Geometry/vector_gen.h"
#include "Algo/Import/import.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Render/map_glRender.h"
#include "Algo/Render/topo_vboRender.h"
using namespace CGoGN;
// definition des parametres de la carte
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2<GMap2> MAP;
};
#include "Algo/Modelisation/polyhedron.h"
PFP::MAP myMap;
// interface
class myGlutWin: public Utils::SimpleGlutWin
SimpleGMap2::SimpleGMap2()
{
public:
Geom::Vec4f colDif;
Geom::Vec4f colSpec;
Geom::Vec4f colClear;
Geom::Vec4f colNormal;
float shininess;
PFP::TVEC3 position ;
PFP::TVEC3 normal ;
/**
* position of object
*/
PFP::VEC3 gPosObj;
/**
* width of object
*/
float gWidthObj;
/**
* factor to apply to normal drawing
*/
float normalScaleFactor;
/**
* mesh normals
*/
std::vector<PFP::VEC3> vnormals;
/**
* redraw CB
*/
void myRedraw();
/**
* keyboard CB
*/
void myKeyboard(unsigned char keycode, int x, int y);
/**
* Display list init
*/
void initDL();
/**
* Display list init only for normal drawing
*/
void initDLNormals(void);
/**
* Display list init only for lines drawing
*/
void initDLLines(void);
/**
* GL (old school) rendering function (called by init DL)
*/
void render(int renderMode);
/**
* inverse the normal when computing normal
*/
bool invertedNormals;
/**
* inverse object for culling
*/
bool invertedObject;
/**
* rendering normals ?
*/
bool renderNormal;
position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
/**
* rendering lines ?
*/
bool renderLines;
/**
* aide affichee
*/
bool aff_help;
/**
* style of rendering
*/
int renderStyle;
/**
* Display List for object
*/
GLuint dl_obj;
/**
* Display List for object (second)
*/
GLuint dl_obj2;
/**
* Display List for normal
*/
GLuint dl_norm;
/**
* render topology
*/
Algo::Render::GL2::topo_VBORenderGMap* m_render_topo;
/**
* render mode enum
*/
enum { CLEAR=1, LINE, FLAT, GOURAUD, PHONG, NORMAL,NONE };
myGlutWin( int* argc, char **argv, int winX, int winY) :
SimpleGlutWin(argc,argv,winX,winY),
invertedNormals(true),
invertedObject(true),
renderNormal(false),
renderLines(true),
aff_help(false),
renderStyle(FLAT),
dl_obj(-1),
dl_obj2(-1),
dl_norm(-1)
{
if (this->shaderOk) shaders[0].loadShaders("phong_vs.txt","phong_ps.txt");
m_render_topo = new Algo::Render::GL2::topo_VBORenderGMap();
}
};
void myGlutWin::render(int renderMode)
{
switch (renderMode)
{
case FLAT:
glEnable(GL_LIGHTING);
glDisable(GL_CULL_FACE);
glPolygonMode(GL_FRONT,GL_FILL);
glShadeModel(GL_FLAT);
Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
if (invertedObject)
glFrontFace(GL_CW);
else
glFrontFace(GL_CCW);
Algo::Render::Direct::renderTriQuadPoly<PFP>(myMap, Algo::Render::Direct::FLAT, 1.0f, position, normal);
break;
case LINE:
glDisable(GL_LIGHTING);
glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT,GL_LINE);
if (invertedObject)
glFrontFace(GL_CW);
else
glFrontFace(GL_CCW);
if (renderStyle!=CLEAR)
glColor3f(1.0f,1.0f,0.0f);
else
glColor4fv(colDif.data());
Algo::Render::Direct::renderTriQuadPoly<PFP>(myMap, Algo::Render::Direct::LINE, 1.0f, position, normal);
break;
case NONE:
break;
default:
break;
}
Dart d = Algo::Modelisation::Polyhedron<PFP>::createOrientedTetra(myMap);
position[d] = VEC3(0,0,0);
position[myMap.phi1(d)] = VEC3(10,0,0);
position[myMap.phi_1(d)] = VEC3(10,20,0);
position[myMap.phi_1(myMap.phi2(d))] = VEC3(0,0,15);
}
void myGlutWin::initDL(void)
void SimpleGMap2::initGUI()
{
if (glIsList(dl_obj))
glDeleteLists(dl_obj,1);
dl_obj = glGenLists(1);
glNewList(dl_obj,GL_COMPILE);
if (renderStyle==FLAT)
render(FLAT);
glEndList();
}
void myGlutWin::initDLLines(void)
void SimpleGMap2::cb_initGL()
{
std::vector<PFP::VEC3> normals;
if (glIsList(dl_obj2))
glDeleteLists(dl_obj2,1);
dl_obj2 = glGenLists(1);
Utils::GLSLShader::setCurrentOGLVersion(1) ;
glNewList(dl_obj2,GL_COMPILE);
render(LINE);
glEndList();
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
VEC3 gPosObj = bb.center() ;
float tailleX = bb.size(0) ;
float tailleY = bb.size(1) ;
float tailleZ = bb.size(2) ;
float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ) ;
setParamObject(gWidthObj, gPosObj.data());
}
void myGlutWin::myRedraw(void)
void SimpleGMap2::cb_redraw()
{
GLfloat black[4]= {0.0f,0.0f,0.0f,1.0f};
GLfloat amb[4]= {0.2f,0.1f,0.1f,1.0f};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
float sc = 50./gWidthObj;
glScalef(sc,sc,sc);
glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]);
if (glIsList(dl_obj2))
glCallList(dl_obj2);
m_render_topo->drawTopo();
glEnable( GL_POLYGON_OFFSET_FILL );
glPolygonOffset( 1.0f, 1.0f );
if (glIsList(dl_obj))
{
glMaterialfv(GL_FRONT, GL_DIFFUSE, colDif.data());
glMaterialfv(GL_FRONT, GL_AMBIENT, amb);
glMaterialfv(GL_FRONT,GL_SPECULAR,black);
glMaterialf( GL_FRONT, GL_SHININESS, 1.0f );
glCallList(dl_obj);
}
glDisable( GL_POLYGON_OFFSET_FILL );
glPopMatrix();
glDisable(GL_LIGHTING);
glLineWidth(1.0f);
Algo::Render::GL1::renderTopoGMD2<PFP>(myMap, position, true, true, 0.9f, 0.9f);
}
void myGlutWin::myKeyboard(unsigned char keycode, int, int)
{
// GLint t1,t2;
// GLfloat seconds;
switch (keycode) {
case 'd':
setFoc(getFoc()/1.05f);
reshape(-1,-1);
glutPostRedisplay();
break;
case 'D':
setFoc(getFoc()*1.05f);
reshape(-1,-1);
glutPostRedisplay();
break;
case 'i':
invertedNormals = !invertedNormals;
initDL();
glutPostRedisplay();
break;
case 'o':
invertedObject = !invertedObject;
initDL();
glutPostRedisplay();
break;
case 'O':
invertedObject = !invertedObject;
invertedNormals = !invertedNormals;
initDL();
glutPostRedisplay();
break;
case 'f':
renderStyle = FLAT;
initDL();
glutPostRedisplay();
break;
case 'l':
renderLines = !renderLines;
if (renderLines)
initDLLines();
else {
if (glIsList(dl_obj2))
glDeleteLists(dl_obj2,1);
}
initDL();
glutPostRedisplay();
break;
case 'z':
shininess /= 1.1f;
glutPostRedisplay();
break;
case 'Z':
shininess *= 1.1f;
glutPostRedisplay();
break;
}
}
/**********************************************************************************************
* MAIN FUNCTION *
**********************************************************************************************/
int main(int argc, char **argv)
{
myGlutWin mgw(&argc,argv,800,800);
char* filename = argv[1] ;
PFP::VEC3 gMax;
PFP::VEC3 gMin;
if(argc < 2)
{
mgw.position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position") ;
Dart d = myMap.newFace(4);
Dart e = myMap.newFace(3);
myMap.sewFaces(d, e);
// plonge les 4 sommets du carré
mgw.position[d] = PFP::VEC3(-1,1,0);
d = myMap.phi1(d);
mgw.position[d] = PFP::VEC3(1,1,0);
d = myMap.phi1(d);
mgw.position[d] = PFP::VEC3(1,-1,0);
QApplication app(argc, argv) ;
d = myMap.phi1(d);
mgw.position[d] = PFP::VEC3(-1,-1,0);
SimpleGMap2 sqt ;
sqt.setGeometry(0, 0, 1000, 800) ;
sqt.show() ;
// plonge le dernier sommet du triangle
d = myMap.phi_1(e);
mgw.position[d] = PFP::VEC3(0,2,0);
}
else
{
std::vector<std::string> attrNames ;
if(!Algo::Import::importMesh<PFP>(myMap, filename, attrNames))
{
CGoGNerr <<"Import fail"<< CGoGNendl;
exit(1);
}
mgw.position = myMap.getAttribute<PFP::VEC3>(VERTEX, attrNames[0]) ;
}
sqt.initGUI() ;
mgw.normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal") ;
// pour le rendu
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, mgw.position) ;
mgw.gPosObj = bb.center() ;
float tailleX = bb.size(0) ;
float tailleY = bb.size(1) ;
float tailleZ = bb.size(2) ;
mgw.gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ) ;
mgw.normalScaleFactor = std::min<float>(std::min<float>(tailleX,tailleY),tailleZ) / 50.0f ;
mgw.colClear = Geom::Vec4f(0.2f,0.2f,0.2f,0.1);
mgw.colDif = Geom::Vec4f(0.8f,0.9f,0.7f,1.0f);
mgw.colSpec = Geom::Vec4f(0.9f,0.9f,0.9f,1.0f);
mgw.colNormal = Geom::Vec4f(1.0f,0.0f,0.0f,1.0f);
mgw.shininess=80.0f;
mgw.m_render_topo->updateData<PFP>(myMap,mgw.position,0.9f, 0.9f);
mgw.initDL();
mgw.initDLLines();
mgw.mainLoop();
return 0;
return app.exec() ;
}
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, 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: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include <iostream>
#include "Utils/qtSimple.h"
#include "ui_viewer.h"
#include "Utils/qtui.h"
#include "Topology/generic/parameters.h"
#include "Topology/gmap/gmap2.h"
#include "Topology/generic/embeddedMap2.h"
#include "Geometry/vector_gen.h"
#include "Algo/Render/GL1/topo_render.h"
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2<GMap2> MAP ;
};
typedef PFP::MAP MAP ;
typedef PFP::VEC3 VEC3 ;
class SimpleGMap2 : public Utils::QT::SimpleQT
{
Q_OBJECT
public:
MAP myMap ;
SelectorTrue allDarts ;
PFP::TVEC3 position ;
SimpleGMap2() ;
void initGUI() ;
void cb_initGL() ;
void cb_redraw() ;
};
......@@ -59,7 +59,7 @@ namespace GL1
* @param drawPhi1 draw the phi1 relation ?
* @param drawPhi2 draw the phi2 relation ?
* @param ke exploding coefficient for edge (1.0 normal draw)
* @param kf exploding coefficient for edge (1.0 normal draw)
* @param kf exploding coefficient for face (1.0 normal draw)
*/
template <typename PFP>
......@@ -74,15 +74,43 @@ void renderTopoMD2(typename PFP::MAP& the_map, const typename PFP::TVEC3& positi
* @param drawPhi2 draw the phi2 relation ?
* @param drawPhi3 draw the phi3 relation ?
* @param ke exploding coefficient for edge (1.0 normal draw)
* @param kf exploding coefficient for edge (1.0 normal draw)
* @param kv exploding coefficient for volumes (0.0 normal draw)
* @param kf exploding coefficient for face (1.0 normal draw)
* @param kv exploding coefficient for volumes (1.0 normal draw)
*/
template <typename PFP>
void renderTopoMD3(typename PFP::MAP& the_map, const typename PFP::TVEC3& positions, bool drawPhi1, bool drawPhi2, bool drawPhi3, float ke, float kf, float kv, FunctorType& good);
void renderTopoMD3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, bool drawPhi1, bool drawPhi2, bool drawPhi3, float ke, float kf, float kv, FunctorType& good);
template <typename PFP>
void renderTopoMD3(typename PFP::MAP& map, typename PFP::TVEC3& positions, bool drawPhi1, bool drawPhi2, bool drawPhi3, float ke, float kf, float kv);
/**
* Render darts of g-map
*
* @param the_map map to render
* @param drawPhi1 draw the beta1 relation ?
* @param drawPhi2 draw the beta2 relation ?
* @param ke exploding coefficient for edge (1.0 normal draw)
* @param kf exploding coefficient for face (1.0 normal draw)
*/
template <typename PFP>
void renderTopoGMD2(typename PFP::MAP& map, const typename PFP::TVEC3& positions, bool drawBeta1, bool drawBeta2, float ke, float kf);
/**
* Render darts of g-map
*
* @param the_map map to render
* @param drawPhi1 draw the beta1 relation ?
* @param drawPhi2 draw the beta2 relation ?
* @param drawPhi3 draw the beta3 relation ?
* @param ke exploding coefficient for edge (1.0 normal draw)
* @param kf exploding coefficient for face (1.0 normal draw)
* @param kv exploding coefficient for volumes (1.0 normal draw)
*/
template <typename PFP>
void renderTopoGMD3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, bool drawBeta1, bool drawBeta2, bool drawBeta3, float ke, float kf, float kv);
} // namespace GL1
} // namespace Render
......
......@@ -479,14 +479,12 @@ void renderTopoMD3(typename PFP::MAP& map, typename PFP::TVEC3& positions, bool
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
AutoAttributeHandler<Geom::Vec3f> fv1(map, DART);
AutoAttributeHandler<Geom::Vec3f> fv11(map, DART);
AutoAttributeHandler<Geom::Vec3f> fv2(map, DART);
AutoAttributeHandler<Geom::Vec3f> fv2x(map, DART);
AutoAttributeHandler<Geom::Vec3f> vert(map, DART);
int m_nbDarts = 0;
// table of center of volume
......@@ -642,6 +640,334 @@ void renderTopoMD3(typename PFP::MAP& map, typename PFP::TVEC3& positions, bool
}
template <typename PFP>
void renderTopoGMD2(typename PFP::MAP& map, const typename PFP::TVEC3& positions, bool drawBeta1, bool drawBeta2, float ke, float kf)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
AutoAttributeHandler<Geom::Vec3f> fv1(map, DART);
AutoAttributeHandler<Geom::Vec3f> fv11(map, DART);
AutoAttributeHandler<Geom::Vec3f> fv2(map, DART);
AutoAttributeHandler<Geom::Vec3f> fv2x(map, DART);
AutoAttributeHandler<Geom::Vec3f> vert(map, DART);