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

update Tutos

parent 573ff74e
...@@ -23,114 +23,32 @@ ...@@ -23,114 +23,32 @@
*******************************************************************************/ *******************************************************************************/
#include "tuto1.h" #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/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 ; 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 int main(int argc, char **argv)
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()
{ {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // // interface
glEnable(GL_CULL_FACE); QApplication app(argc, argv);
glEnable(GL_LIGHTING); MyQT sqt;
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);
glDisable(GL_POLYGON_OFFSET_FILL); // example code itself
} sqt.createMap();
}
void MyQT::cb_keyPress(int code) // set help message in menu
{ sqt.setHelpMsg("First Tuto: \nCreate two faces\nsew them\nand affect positions");
if ((code >65) && (code< 123 )) // final show for redraw
CGoGNout << " key char " << char(code) << "pressed"<< CGoGNendl; sqt.show();
// and wait for the end
if ((code >'0') && (code<='9')) return app.exec();
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
}
} }
int main(int argc, char **argv) void MyQT::createMap()
{ {
// creation of 2 new faces: 1 triangle and 1 square // creation of 2 new faces: 1 triangle and 1 square
Dart d1 = myMap.newFace(3); Dart d1 = myMap.newFace(3);
Dart d2 = myMap.newFace(4); Dart d2 = myMap.newFace(4);
...@@ -138,64 +56,45 @@ int main(int argc, char **argv) ...@@ -138,64 +56,45 @@ int main(int argc, char **argv)
// sew these faces along one of their edge // sew these faces along one of their edge
myMap.sewFaces(d1, d2); myMap.sewFaces(d1, d2);
// creation of a new attribute on vertices of type 3D vector // creation of a new attribute on vertices of type 3D vector for position.
// a handler to this attribute is returned // a handler to this attribute is returned (TVEC3 is a typdef of AttributeHandler<PFP::VEC3>)
position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position"); 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[d1] = PFP::VEC3(0, 0, 0);
position[myMap.phi1(d1)] = PFP::VEC3(2, 0, 0); position[PHI1(d1)] = PFP::VEC3(2, 0, 0);
position[myMap.phi_1(d1)] = PFP::VEC3(1, 2, 0); position[PHI_1(d1)] = PFP::VEC3(1, 2, 0);
position[PHI<11>(d2)] = PFP::VEC3(0, -2, 0);
position[myMap.phi<11>(d2)] = PFP::VEC3(0, -2, 0); position[PHI_1(d2)] = PFP::VEC3(2, -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");
// bounding box // bounding box of scene
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position); 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)); 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); Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
// envoit info BB a l'interface // send BB info to interface for centering on GL screen
sqt.setParamObject(lWidthObj, lPosObj.data()); setParamObject(lWidthObj, lPosObj.data());
// show 1 pour GL context // first show for be sure that GL context is binded
sqt.show(); show();
// update du VBO position (context GL necessaire)
sqt.m_positionVBO->updateData(position);
// update des primitives du renderer // render the topo of the map without boundary darts
SelectorEdgeNoBoundary<PFP::MAP> insideEdges(myMap);// just to draw only inside edges 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); // initialization GL callback
sqt.m_render->initPrimitives<PFP>(myMap, insideEdges, Algo::Render::GL2::LINES); void MyQT::cb_initGL()
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::BOUNDARY); // special primitive for boundary edges {
// example of using boolean operator on Selectors m_render_topo = new Algo::Render::GL2::TopoRenderMapD() ;
sqt.m_render->initPrimitives<PFP>(myMap, ( SelectorFalse() || ( SelectorTrue() && (SelectorMarked(dm) && SelectorCellMarked(cm)))) , Algo::Render::GL2::POINTS); // special primitive for boundary edges }
// 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 @@ ...@@ -25,51 +25,56 @@
#ifndef _TUTO1_ #ifndef _TUTO1_
#define _TUTO1_ #define _TUTO1_
#include <iostream>
#include "Utils/Qt/qtSimple.h" #include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h" #include "Utils/cgognStream.h"
// forward definitions (minimize includes) #include "Topology/generic/parameters.h"
namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; } } } } #include "Topology/map/embeddedMap2.h"
namespace CGoGN { namespace Utils { class VBO; } } #include "Algo/Render/GL2/topoRender.h"
namespace CGoGN { namespace Utils { class ShaderSimpleColor; } }
using namespace CGoGN ; 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 // definition of the type of the map
typedef EmbeddedMap2 MAP;
public: };
// render
Algo::Render::GL2::MapRender* m_render;
// VBO
Utils::VBO* m_positionVBO;
// 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_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; } // just for more compact writing
void cb_Save() { CGoGNout << "Rien a sauver ..." << CGoGNendl; } 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:
public slots: // example of simple map creation
void menu_slot1() { CGoGNout << "Exemple de menu" << CGoGNendl; } void createMap();
}; };
#endif #endif
This diff is collapsed.
...@@ -25,58 +25,71 @@ ...@@ -25,58 +25,71 @@
#ifndef _TUTO2_ #ifndef _TUTO2_
#define _TUTO2_ #define _TUTO2_
#include <iostream>
#include "Utils/Qt/qtSimple.h" #include "Utils/Qt/qtSimple.h"
#include "ui_tuto2.h" #include "Utils/cgognStream.h"
#include "Utils/Qt/qtui.h"
#include "Geometry/vector_gen.h" #include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderColorPerVertex.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; } }
using namespace CGoGN ; using namespace CGoGN ;
/** /**
* Utilisation de designer-qt4: * Struct that contains some informations about the types of the manipulated objects
* Faire un DockWiget (laisser le nom par defaut * Mainly here to be used by the algorithms that are parameterized by it
* dans le Contents ajouter le layout choisi (vertical classiquement)
* Ajouter les widgets necessaires, mettre des noms clairs pour
* les utiliser dans le .cpp (pour les call back principalement)
*/ */
struct PFP: public PFP_STANDARD
{
// definition of the type of the map
typedef EmbeddedMap2 MAP;
};
class MyQT: public Utils::QT::SimpleQT class MyQT: public Utils::QT::SimpleQT
{ {
Q_OBJECT Q_OBJECT
public:
MyQT(): m_render(NULL), m_positionVBO(NULL), m_shader(NULL) {}
void cb_redraw();
void cb_initGL();
bool m_with_lines; protected:
Geom::Vec4f m_color; // declaration of the map
int m_line_width; PFP::MAP myMap;
// render (for the topo)
// Algo::Render::GL2::TopoRenderMapD* m_render_topo;
public:
// render // render
Algo::Render::GL2::MapRender* m_render; Algo::Render::GL2::MapRender* m_render;
// VBO // VBO
Utils::VBO* m_positionVBO; Utils::VBO* m_positionVBO; // position 3D
Utils::VBO* m_colorVBO1; // color per vertex for face drawing
Utils::VBO* m_colorVBO2; // color per vertex for edge drawing
// shader basic //shaders
Utils::ShaderSimpleColor* m_shader; Utils::ShaderSimpleColor* m_shader;
Utils::ShaderColorPerVertex* m_shader2;
MyQT():m_render(NULL), m_positionVBO(NULL), m_shader(NULL) // 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);}
void cb_redraw(); public:
// example of simple map creation
void createMap();
};
void cb_initGL();
// slots locaux
public slots:
void lines_slot(bool x);
void line_width_slot(int x);
void color_slot();
};
#endif #endif
...@@ -22,219 +22,164 @@ ...@@ -22,219 +22,164 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include <iostream>
#include "Topology/generic/parameters.h"
#include "Topology/map/map2.h"
#include "Topology/generic/cellmarker.h"
#include "Geometry/vector_gen.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderColorPerVertex.h"
#include "tuto3.h" #include "tuto3.h"
#include "Algo/Geometry/boundingbox.h"
MyQT* sqt1_ptr; #include "Algo/Selection/raySelector.h"
MyQT* sqt2_ptr; #include "Algo/Modelisation/polyhedron.h"
using namespace CGoGN ; using namespace CGoGN ;
struct PFP: public PFP_STANDARD
{
// definition de la carte
typedef Map2 MAP;
};
void MyQT::cb_initGL() int main(int argc, char **argv)
{ {
// choose to use GL version 2 // // interface
Utils::GLSLShader::setCurrentOGLVersion(2); QApplication app(argc, argv);
MyQT sqt;
// copy output tout Qt console of application (shift enter)
CGoGNout.toConsole(&sqt);
// create the render // example code itself
m_render = new Algo::Render::GL2::MapRender(); sqt.createMap();
// create VBO for position sqt.traverseMap();
m_positionVBO = new Utils::VBO();
m_colorVBO = new Utils::VBO();
// using simple shader with color // set help message in menu
m_shader = new Utils::ShaderSimpleColor(); sqt.setHelpMsg("Tuto 3: \nUsage of DartMarker and CellMarker\nPick of dart with mouse");
m_shader->setAttributePosition(m_positionVBO); // final show for redraw
sqt.show();
m_shader2 = new Utils::ShaderColorPerVertex(); CGoGNout << "You can pick darts dans see it's id with left mouse button"<< CGoGNendl;
m_shader2->setAttributePosition(m_positionVBO);
m_shader2->setAttributeColor(m_colorVBO);
registerShader(m_shader); // and wait for the end
registerShader(m_shader2); return app.exec();
} }
void MyQT::cb_redraw()
void MyQT::traverseMap()
{ {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glLineWidth(2.0f); //traverse cells of map using topological markers on darts
m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.));
m_render->draw(m_shader, Algo::Render::GL2::LINES);
glEnable(GL_POLYGON_OFFSET_FILL); CGoGNout << "Traverse with DartMarkers:"<< CGoGNendl;
glPolygonOffset(1.0f, 1.0f); DartMarker dmV(myMap);
m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES); DartMarker dmE(myMap);
glDisable(GL_POLYGON_OFFSET_FILL); DartMarker dmF(myMap);
} for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
void MyQT::cb_keyPress(int code)
{
switch(code)
{ {
case 's': if (!dmV.isMarked(d))
if (this == sqt2_ptr) {
sqt1_ptr->synchronize(sqt2_ptr); CGoGNout << "Vertex of dart "<<d<<CGoGNendl;
if (this == sqt1_ptr) dmV.markOrbit(VERTEX,d);
sqt2_ptr->synchronize(sqt1_ptr); }
break; if (!dmE.isMarked(d))
{
CGoGNout << "Edgee of dart "<<d<<CGoGNendl;
dmE.markOrbit(EDGE,d);
}
if (!dmF.isMarked(d))
{
CGoGNout << "Face of dart "<<d<<CGoGNendl;
dmF.markOrbit(FACE,d);
}
} }
}
int main(int argc, char **argv)
{
PFP::MAP myMap;
PFP::TVEC3 position ;
PFP::TVEC3 normal ;
AttributeHandler<Geom::Vec3f> color ;
Dart d2 = myMap.newFace(3); // traverses cells of map with markers on embedded cells.
Dart d3 = myMap.newFace(4); // More efficients but more memory costly if cells are not already embedded.
myMap.sewFaces(d2,d3); // Avoid using construction of objects not ell embedded
position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position"); CGoGNout << "========================="<< CGoGNendl;
color = myMap.addAttribute<PFP::VEC3>(VERTEX, "couleur"); CGoGNout << "Traverse with CellMarkers:"<< CGoGNendl;
CellMarker cmV(myMap,VERTEX);
position[d2] = PFP::VEC3(0.0f, 0.0f, 0.0f); CellMarker cmE(myMap,EDGE);
color[d2] = PFP::VEC3(1.0f, 0.0f, 0.0f); CellMarker cmF(myMap,FACE);
d2 = myMap.phi1(d2); for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
position[d2] = PFP::VEC3(2.0f, 0.0f, 0.0f);
color[d2] = PFP::VEC3(0.0f, 1.0f, 0.0f);
d2 = myMap.phi1(d2);
position[d2] = PFP::VEC3(1.0f, 3.0f, 0.0f);
color[d2] = PFP::VEC3(0.0f, 0.0f, 1.0f);
d2 = myMap.phi1(d2);
d3 = myMap.phi<11>(d3);
position[d3] = PFP::VEC3(0.0f, -2.0f, 0.0f);
color[d3] = PFP::VEC3(1.0f, 0.0f, 1.0f);
d3 = myMap.phi1(d3);
position[d3] = PFP::VEC3(2.0f, -2.0f, 0.0f);
color[d3] = PFP::VEC3(0.0f, 1.0f, 1.0f);
d3 = myMap.phi1(d3);
//MARK !!!
// on reserve des marqueur de brins
DartMarkerStore mf(myMap);
DartMarkerStore me(myMap);
// avec lesquels on peut marquer des orbits
mf.markOrbit(FACE, d2);
me.markOrbit(EDGE, d2);
// les sommet sont plonges, on peut utiliser un marqueur de cellule sommet
CellMarker cm(myMap, VERTEX);
cm.mark(d3);
for (Dart d = myMap.begin(); d!= myMap.end(); myMap.next(d))
{ {
if (me.isMarked(d)) if (!cmV.isMarked(d))
CGoGNout << "Dart "<< d.label() << " marque par me"<< CGoGNendl; {
if (mf.isMarked(d)) CGoGNout << "Vertex of dart "<<d<<CGoGNendl;
CGoGNout << "Dart "<< d.label() << " marque par mf"<< CGoGNendl; cmV.mark(d);
if (cm.isMarked(d)) }
CGoGNout << "Sommet de dart "<< d.label() << " marque par mcv"<< CGoGNendl; if (!cmE.isMarked(d))
{
CGoGNout << "Edgee of dart "<<d<<CGoGNendl;
cmE.mark(d);
}
if (!cmF.isMarked(d))
{
CGoGNout << "Face of dart "<<d<<CGoGNendl;
cmF.mark(d);
}
} }
//nettoyage // markers are cleaned and released at destruction of DartMarkers & CellMarkers
cm.unmarkAll(); // DartMarkerStore should be used if few darts are traversed
// DartMarkerNoUnmark can be use if you want to manage unmarking yourself
// interface: