Commit 5835f74c authored by Sylvain Thery's avatar Sylvain Thery

update Tutos

parent 573ff74e
......@@ -23,114 +23,32 @@
*******************************************************************************/
#include "tuto1.h"
#include <iostream>
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Geometry/vector_gen.h"
#include "Algo/Import/import.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include <glm/gtc/type_ptr.hpp>
#include "Algo/Render/SVG/mapSVGRender.h"
using namespace CGoGN ;
/**
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
struct PFP: public PFP_STANDARD
{
// definition of the type of the map
typedef EmbeddedMap2 MAP;
};
// declaration of the map
PFP::MAP myMap;
// and attribute of position
AttributeHandler<PFP::VEC3> position;
void MyQT::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();
// using simple shader with color
m_shader = new Utils::ShaderSimpleColor();
m_shader->setAttributePosition(m_positionVBO);
m_shader->setColor(Geom::Vec4f(0.0f, 1.0f, 0.0f, 0.0f));
registerShader(m_shader);
}
void MyQT::cb_redraw()
int main(int argc, char **argv)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
if (m_shader)
{
glLineWidth(2.0f);
m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.));
m_render->draw(m_shader, Algo::Render::GL2::LINES);
m_shader->setColor(Geom::Vec4f(0.,1.,1.,0.));
m_render->draw(m_shader, Algo::Render::GL2::BOUNDARY);
glPointSize(7.0f);
m_shader->setColor(Geom::Vec4f(1.,1.,1.,0.));
m_render->draw(m_shader, Algo::Render::GL2::POINTS);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.));
m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES);
// // interface
QApplication app(argc, argv);
MyQT sqt;
glDisable(GL_POLYGON_OFFSET_FILL);
}
}
// example code itself
sqt.createMap();
void MyQT::cb_keyPress(int code)
{
if ((code >65) && (code< 123 ))
CGoGNout << " key char " << char(code) << "pressed"<< CGoGNendl;
if ((code >'0') && (code<='9'))
CGoGNout << " key num " << code-'0' << "pressed"<< CGoGNendl;
if (code == 's')
{
std::string filename = selectFileSave("Export SVG file ");
CGoGNout << "Exporting "<<filename<<CGoGNendl;
Algo::Render::SVG::SVGOut svg(filename,modelViewMatrix(),projectionMatrix());
svg.renderLinesToSVG<PFP>(myMap,position);
svg.setColor(Geom::Vec3f(0.7f,0.0f,0.4f));
svg.renderFacesToSVG<PFP>(myMap,position,0.8f);
//svg destruction close the file
}
// set help message in menu
sqt.setHelpMsg("First Tuto: \nCreate two faces\nsew them\nand affect positions");
// final show for redraw
sqt.show();
// and wait for the end
return app.exec();
}
int main(int argc, char **argv)
void MyQT::createMap()
{
// creation of 2 new faces: 1 triangle and 1 square
Dart d1 = myMap.newFace(3);
Dart d2 = myMap.newFace(4);
......@@ -138,64 +56,45 @@ int main(int argc, char **argv)
// sew these faces along one of their edge
myMap.sewFaces(d1, d2);
// creation of a new attribute on vertices of type 3D vector
// a handler to this attribute is returned
position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
// creation of a new attribute on vertices of type 3D vector for position.
// a handler to this attribute is returned (TVEC3 is a typdef of AttributeHandler<PFP::VEC3>)
PFP::TVEC3 position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
//warning: at the end of scope of variable position, handler is destroyed but attribute stay
// affect a position to the vertices of the mesh
// affect position by moving in the map
position[d1] = PFP::VEC3(0, 0, 0);
position[myMap.phi1(d1)] = PFP::VEC3(2, 0, 0);
position[myMap.phi_1(d1)] = PFP::VEC3(1, 2, 0);
position[myMap.phi<11>(d2)] = PFP::VEC3(0, -2, 0);
position[myMap.phi_1(d2)] = PFP::VEC3(2, -2, 0);
// interface:
QApplication app(argc, argv);
MyQT sqt;
// ajout entree dans le menu application
sqt.add_menu_entry("entree1", SLOT(menu_slot1()));
// message d'aide
sqt.setHelpMsg("First Tuto:\n"
"create 2 faces\n"
"and sew them \n"
"simple interface in Qt");
position[PHI1(d1)] = PFP::VEC3(2, 0, 0);
position[PHI_1(d1)] = PFP::VEC3(1, 2, 0);
position[PHI<11>(d2)] = PFP::VEC3(0, -2, 0);
position[PHI_1(d2)] = PFP::VEC3(2, -2, 0);
// bounding box
// bounding box of scene
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, 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
sqt.setParamObject(lWidthObj, lPosObj.data());
// send BB info to interface for centering on GL screen
setParamObject(lWidthObj, lPosObj.data());
// show 1 pour GL context
sqt.show();
// update du VBO position (context GL necessaire)
sqt.m_positionVBO->updateData(position);
// first show for be sure that GL context is binded
show();
// update des primitives du renderer
SelectorEdgeNoBoundary<PFP::MAP> insideEdges(myMap);// just to draw only inside edges
// render the topo of the map without boundary darts
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f,nb);
}
DartMarker dm(myMap);
dm.markOrbit(VERTEX,d2);
dm.markOrbit(VERTEX,d1);
CellMarker cm(myMap,FACE);
cm.mark(d2);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
sqt.m_render->initPrimitives<PFP>(myMap, insideEdges, Algo::Render::GL2::LINES);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::BOUNDARY); // special primitive for boundary edges
// example of using boolean operator on Selectors
sqt.m_render->initPrimitives<PFP>(myMap, ( SelectorFalse() || ( SelectorTrue() && (SelectorMarked(dm) && SelectorCellMarked(cm)))) , Algo::Render::GL2::POINTS); // special primitive for boundary edges
// initialization GL callback
void MyQT::cb_initGL()
{
m_render_topo = new Algo::Render::GL2::TopoRenderMapD() ;
}
// redraw GL callback (clear and swap already done)
void MyQT::cb_redraw()
{
m_render_topo->drawTopo();
}
// show final pour premier redraw
sqt.show();
// et on attend la fin.
return app.exec();
}
......@@ -25,51 +25,56 @@
#ifndef _TUTO1_
#define _TUTO1_
#include <iostream>
#include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h"
// forward definitions (minimize includes)
namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; } } } }
namespace CGoGN { namespace Utils { class VBO; } }
namespace CGoGN { namespace Utils { class ShaderSimpleColor; } }
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Algo/Render/GL2/topoRender.h"
using namespace CGoGN ;
/**
* A class for a little interface and rendering
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
class MyQT : public Utils::QT::SimpleQT
struct PFP: public PFP_STANDARD
{
Q_OBJECT
public:
// render
Algo::Render::GL2::MapRender* m_render;
// VBO
Utils::VBO* m_positionVBO;
// definition of the type of the map
typedef EmbeddedMap2 MAP;
};
// shader basic
Utils::ShaderSimpleColor* m_shader;
MyQT() : m_render(NULL), m_positionVBO(NULL), m_shader(NULL)
{}
class MyQT: public Utils::QT::SimpleQT
{
Q_OBJECT
public:
MyQT():m_render_topo(NULL) {}
// callbacks of simpleQT to overdefine:
void cb_redraw();
void cb_initGL();
void cb_redraw();
protected:
// declaration of the map
PFP::MAP myMap;
void cb_keyPress(int code);
// render (for the topo)
Algo::Render::GL2::TopoRenderMapD* m_render_topo;
void cb_New() { CGoGNout << "New ..." << CGoGNendl; }
void cb_Save() { CGoGNout << "Rien a sauver ..." << CGoGNendl; }
// just for more compact writing
inline Dart PHI1(Dart d) {return myMap.phi1(d);}
inline Dart PHI_1(Dart d) {return myMap.phi_1(d);}
inline Dart PHI2(Dart d) {return myMap.phi2(d);}
template<int X>
Dart PHI(Dart d) {return myMap.phi<X>(d);}
// callbacks (slots) locally defined
public slots:
void menu_slot1() { CGoGNout << "Exemple de menu" << CGoGNendl; }
public:
// example of simple map creation
void createMap();
};
#endif
......@@ -22,239 +22,176 @@
* *
*******************************************************************************/
#include <iostream>
#include "Topology/generic/parameters.h"
#include "Topology/map/map2.h"
#include "Topology/generic/mapBrowser.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/drawer.h"
#include "tuto2.h"
#include "Algo/Geometry/boundingbox.h"
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
{
// definition de la carte
typedef Map2 MAP;
};
PFP::MAP myMap;
PFP::TVEC3 position ;
PFP::TVEC3 normal ;
AttributeHandler<Geom::Vec4f> color ;
void MyQT::cb_initGL()
int main(int argc, char **argv)
{
// 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();
// using simple shader with color
m_shader = new Utils::ShaderSimpleColor();
m_shader->setAttributePosition(m_positionVBO);
m_color = Geom::Vec4f(0.,1.,0.,0.);
m_shader->setColor(m_color);
// // interface
QApplication app(argc, argv);
MyQT sqt;
// copy output tout Qt console of application (shift enter)
CGoGNout.toConsole(&sqt);
registerShader(m_shader);
// example code itself
sqt.createMap();
// set help message in menu
sqt.setHelpMsg("Tuto 2: \nCreate and use multiple attributes\nrender with multiple shaders");
m_with_lines = true;
m_line_width = 4.0;
// final show for redraw
sqt.show();
// and wait for the end
return app.exec();
}
void MyQT::cb_redraw()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
if (m_shader)
{
if (m_with_lines)
{
glLineWidth(m_line_width);
m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.));
m_render->draw(m_shader, Algo::Render::GL2::LINES);
}
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
m_shader->setColor(m_color);
m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES);
glDisable(GL_POLYGON_OFFSET_FILL);
}
}
void MyQT::lines_slot(bool x)
void MyQT::createMap()
{
m_with_lines = x;
updateGL();
}
void MyQT::line_width_slot(int x)
{
// creation of 2 new faces: 1 triangle and 1 square, sew and embed (see tuto1 for details)
Dart d1 = myMap.newFace(3);
Dart d2 = myMap.newFace(4);
myMap.sewFaces(d1, d2);
PFP::TVEC3 position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
position[d1] = PFP::VEC3(0, 0, 0);
position[PHI1(d1)] = PFP::VEC3(2, 0, 0);
position[PHI_1(d1)] = PFP::VEC3(1, 2, 0);
position[PHI<11>(d2)] = PFP::VEC3(0, -2, 0);
position[PHI_1(d2)] = PFP::VEC3(2, -2, 0);
m_line_width=x;
updateGL();
}
void MyQT::color_slot()
{
QColor col = QColorDialog::getColor ();
if (col.isValid())
{
// create another attribute on vertices (for faces drawing)
AttributeHandler<Geom::Vec3f> colorF = myMap.addAttribute<PFP::VEC3>(VERTEX, "colorF");
m_color = Geom::Vec4f(float(col.red())/255.0f,float(col.green())/255.0f,float(col.blue())/255.0f,0.0f);
updateGL();
}
else
{
CGoGNout << "Cancel Color" << CGoGNendl;
}
}
colorF[d1] = Geom::Vec3f(1.0f,0.0f,0.0f);
colorF[PHI1(d1)] = Geom::Vec3f(0.0f,1.0f,0.0f);
colorF[PHI_1(d1)] = Geom::Vec3f(0.0f,0.0f,1.0f);
colorF[PHI<11>(d2)] = Geom::Vec3f(1.0f,0.0f,1.0f);
colorF[PHI_1(d2)] = Geom::Vec3f(0.0f,1.0f,1.0f);
// Algorithme qui parcours une carte et affiche l'attribut position de chaque brin
template<typename PFP>
void TestDeParcoursAFF(typename PFP::MAP& m, MapBrowser& mb, const typename PFP::TVEC3& pos)
{
for (Dart d = mb.begin(); d != mb.end(); mb.next(d))
{
typename PFP::VEC3 P = pos[d];
CGoGNout << "P "<< P << CGoGNendl;
}
}
int main(int argc, char **argv)
{
/// Utilisation des MapBrowsers
// create another attribute on vertices (for edges drawing)
AttributeHandler<Geom::Vec3f> colorE = myMap.addAttribute<PFP::VEC3>(VERTEX, "colorE");
/// on reprend la carte de tuto1
colorE[d1] = Geom::Vec3f(0.0f,0.5f,0.5f);
colorE[PHI1(d1)] = Geom::Vec3f(0.5f,0.0f,0.5f);
colorE[PHI_1(d1)] = Geom::Vec3f(0.5f,0.5f,0.0f);
colorE[PHI<11>(d2)] = Geom::Vec3f(0.0f,0.5f,0.0f);
colorE[PHI_1(d2)] = Geom::Vec3f(0.5f,0.0f,0.0f);
Dart d2 = myMap.newFace(3);
Dart d3 = myMap.newFace(4);
myMap.sewFaces(d2, d3);
position = myMap.addAttribute<Geom::Vec3f>(VERTEX, "position");
// example of attribute on face
// here for example we store the number of edges of faces at construction
AttributeHandler<int> side = myMap.addAttribute<int>(FACE, "nb_sides");
side[d1]=3;
side[d2]=4;
position[d2] = PFP::VEC3(0.0f, 0.0f, 0.0f);
d2 = myMap.phi1(d2);
position[d2] = PFP::VEC3(2.0f, 0.0f, 0.0f);
d2 = myMap.phi1(d2);
position[d2] = PFP::VEC3(1.0f, 3.0f, 0.0f);
d2 = myMap.phi1(d2);
d3 = myMap.phi<11>(d3);
position[d3] = PFP::VEC3(0.0f, -2.0f, 0.0f);
d3 = myMap.phi1(d3);
position[d3] = PFP::VEC3(2.0f, -2.0f, 0.0f);
d3 = myMap.phi1(d3);
// bounding box of scene
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, 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);
// MapBrowser: la carte elle meme
CGoGNout << "Parcours avec la carte" << CGoGNendl;
TestDeParcoursAFF<PFP>(myMap, myMap, position);
// MapBrowserLinkedAuto
// sous-carte dans une liste avec attribut gere par le browser
CGoGNout << "Parcours avec le browser (les sommets)"<<CGoGNendl;
// send BB info to interface for centering on GL screen
setParamObject(lWidthObj, lPosObj.data());
// creation d'un browser avec attribut cree a la volee
MapBrowserLinked<PFP::MAP>mbl(myMap);
// first show for be sure that GL context is binded
show();
// on ajoute un brin par sommet dans le browser
myMap.foreach_orbit(VERTEX, mbl);
// et on parcours la sous-carte avec ce browser
TestDeParcoursAFF<PFP>(myMap, mbl, position);
// update of position VBO (context GL necessary)
m_positionVBO->updateData(position);
m_colorVBO1->updateData(colorF);
m_colorVBO2->updateData(colorE);
// construct rendering primities
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS); // special primitive for boundary edges
// MapBrowserLinkedAttr
// sous-carte dans une liste avec attribut gere par l'appelant
CGoGNout << "Parcours avec le browser (le triangle)"<<CGoGNendl;
// on cree un attribut Dart pour la liste
AutoAttributeHandler<Dart> tableLink(myMap, DART);
// le browser
MapBrowserLinked<PFP::MAP>mbl2(myMap,tableLink);
// que l'on remplit a la main
Dart d = d2;
mbl2.pushBack(d);
d = myMap.phi1(d);
mbl2.pushBack(d);
d = myMap.phi1(d);
mbl2.pushFront(d);
// traverse of all dart of the map:
// and write informations
for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
{
CGoGNout << "Dart "<< d;
if (myMap.isBoundaryMarked(d))
CGoGNout << " is a boundary dart (implicitly added)"<< CGoGNendl;
else
{
CGoGNout <<": position= "<< position[d];
CGoGNout <<" / color1= "<< colorF[d];
CGoGNout <<" / color2= "<< colorE[d];
CGoGNout << " / numer of side of face "<< side[d] << CGoGNendl;
}
}
// et on parcours la sous-carte avec ce browser
TestDeParcoursAFF<PFP>(myMap, mbl2, position);
}
// MapBrowserSelector
// sous-carte avec des brins marques (equivalent de l'utilisation de good dans les algos)
CGoGNout << "Parcours avec le browser selector"<<CGoGNendl;
// on marque 2 brins pour le test
DartMarker mk(myMap);
mk.mark(d2);
mk.mark(d3);
// le selector qui selectionne les "bons" brins (les autres sont reconduits a la frontiere ;)
SelectorMarked selector(mk);
// initialization GL callback
void MyQT::cb_initGL()
{
// choose to use GL version 2
Utils::GLSLShader::setCurrentOGLVersion(2);
// // le browser
// MapBrowserSelector<PFP::MAP>mbsel(myMap,selector);
// create the render
m_render = new Algo::Render::GL2::MapRender();
// // et on parcours la sous-carte avec ce browser
// TestDeParcoursAFF<PFP>(myMap,mbsel,position);
// create VBO for position
m_positionVBO = new Utils::VBO();
// and color
m_colorVBO1 = new Utils::VBO();
m_colorVBO2 = new Utils::VBO();
// interface:
QApplication app(argc, argv);
MyQT sqt;
// using simple shader with color
m_shader = new Utils::ShaderSimpleColor();
m_shader->setAttributePosition(m_positionVBO);
m_shader->setColor(Geom::Vec4f(0.0f, 1.0f, 0.0f, 0.0f));
// each shader must be registred to allow Qt interface to update matrices uniforms
registerShader(m_shader);
Utils::QT::uiDockInterface dock;
sqt.setDock(&dock);
m_shader2 = new Utils::ShaderColorPerVertex();
m_shader2->setAttributePosition(m_positionVBO);
// m_shader2->setAttributeColor(m_colorVBO1);
// each shader must be registred to allow Qt interface to update matrices uniforms
registerShader(m_shader2);
sqt.setCallBack( dock.checkLines, SIGNAL(toggled(bool)), SLOT(lines_slot(bool)) );
sqt.setCallBack( dock.color_button , SIGNAL(pressed()), SLOT(color_slot()) );
sqt.setCallBack( dock.dial_line_width , SIGNAL(valueChanged(int)), SLOT(line_width_slot(int)) );
// message d'aide
sqt.setHelpMsg("Second Tuto");
}
dock.number_of_darts->display(int(myMap.getNbDarts()));
// redraw GL callback (clear and swap already done)
void MyQT::cb_redraw()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_CULL_FACE);
// bounding box
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, 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);
// draw yellow points
glLineWidth(2.0f);
m_shader2->setAttributeColor(m_colorVBO1);
m_render->draw(m_shader2, Algo::Render::GL2::LINES);
// envoit info BB a l'interface
sqt.setParamObject(lWidthObj,lPosObj.data());
// draw white points
glPointSize(7.0f);
m_shader->setColor(Geom::Vec4f(1.,1.,1.,0.));
m_render->draw(m_shader, Algo::Render::GL2::POINTS);
// show 1 pour GL context
sqt.show();
// use offset for nice drawing
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
// update du VBO position (context GL necessaire)
sqt.m_positionVBO->updateData(position);
// draw faces with pervertex color rendering
m_shader2->setAttributeColor(m_colorVBO2);
m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES);
// update des primitives du renderer
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
glDisable(GL_POLYGON_OFFSET_FILL);
}
// show final pour premier redraw
sqt.show();
// et on attend la fin.
return app.exec();
}
......@@ -25,58 +25,71 @@
#ifndef _TUTO2_
#define _TUTO2_