Commit 9e4f8b88 authored by Sylvain Thery's avatar Sylvain Thery
Browse files

ajout mini graph de scene

vbo avec partage de sommets
parent a3a475f3
...@@ -34,9 +34,11 @@ ...@@ -34,9 +34,11 @@
#include "Geometry/matrix.h" #include "Geometry/matrix.h"
#include "Geometry/transfo.h" #include "Geometry/transfo.h"
#include "Algo/Geometry/boundingbox.h" #include "Algo/Geometry/boundingbox.h"
#include "Algo/Geometry/normal.h"
#include "Algo/Render/vbo_MapRender.h" #include "Algo/Render/vbo_MapRender.h"
#include "Algo/Modelisation/polyhedron.h" #include "Algo/Modelisation/polyhedron.h"
#include "Topology/generic/cellmarker.h"
#include "Utils/scene_graph.h" #include "Utils/scene_graph.h"
...@@ -53,7 +55,7 @@ struct PFP: public PFP_STANDARD ...@@ -53,7 +55,7 @@ struct PFP: public PFP_STANDARD
PFP::MAP myMap; PFP::MAP myMap;
Utils::SceneGraph::Material_Node* root;
class myGlutWin: public Utils::SimpleGlutWin class myGlutWin: public Utils::SimpleGlutWin
{ {
...@@ -91,6 +93,9 @@ public: ...@@ -91,6 +93,9 @@ public:
// position handler // position handler
PFP::TVEC3 position ; PFP::TVEC3 position ;
PFP::TVEC3 normal ;
Utils::SceneGraph::Group_Node* root;
/** /**
* render object * render object
...@@ -104,13 +109,19 @@ public: ...@@ -104,13 +109,19 @@ public:
m_render(NULL) m_render(NULL)
{ } { }
~myGlutWin(); void exitCallback();
~myGlutWin() {}
}; };
myGlutWin::~myGlutWin() void myGlutWin::exitCallback()
{ {
if (m_render) std::cout << "DESTRUCTOR"<< std::endl;
delete m_render; eraseGraph(root);
// if (m_render)
// delete m_render;
} }
void myGlutWin::init() void myGlutWin::init()
...@@ -140,9 +151,14 @@ void myGlutWin::updateRender() ...@@ -140,9 +151,14 @@ void myGlutWin::updateRender()
m_render->updateData(Algo::Render::VBO::POSITIONS, position); m_render->updateData(Algo::Render::VBO::POSITIONS, position);
// update flat faces primtives (warning need position buffer) // update flat faces primtives (warning need position buffer)
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::FLAT_TRIANGLES); m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::FLAT_TRIANGLES);
// update smooth faces primtives
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::TRIANGLES);
// update lines primitives // update lines primitives
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::LINES); m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::LINES);
Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
m_render->updateData(Algo::Render::VBO::NORMALS, normal);
} }
...@@ -174,7 +190,7 @@ void myGlutWin::myRedraw(void) ...@@ -174,7 +190,7 @@ void myGlutWin::myRedraw(void)
// //
// glDisable( GL_POLYGON_OFFSET_FILL ); // glDisable( GL_POLYGON_OFFSET_FILL );
Utils::SceneGraph::render(root); Utils::SceneGraph::renderGraph(root);
glPopMatrix(); glPopMatrix();
} }
...@@ -183,8 +199,6 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) ...@@ -183,8 +199,6 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y)
{ {
switch(keycode) switch(keycode)
{ {
case 27:
exit(0);
default: default:
break; break;
} }
...@@ -198,61 +212,91 @@ int main(int argc, char **argv) ...@@ -198,61 +212,91 @@ int main(int argc, char **argv)
mgw.init(); mgw.init();
mgw.position = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position") ; mgw.position = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position") ;
mgw.normal = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "normal") ;
// Algo::Modelisation::Polyhedron<PFP> prim1(myMap, mgw.position);
// prim1.cylinder_topo(16,16, true, true); // topo of sphere is a closed cylinder
// prim1.embedCylinder(40.0f,40.0f,30.0f);
//
// CellMarker mark1(myMap,VERTEX_CELL);
// prim1.mark(mark1);
//
// create a sphere // create a sphere
Algo::Modelisation::Polyhedron<PFP> prim2(myMap, mgw.position); Algo::Modelisation::Polyhedron<PFP> prim2(myMap, mgw.position);
prim2.cylinder_topo(16,16, true, true); // topo of sphere is a closed cylinder prim2.cylinder_topo(16,16, true, true); // topo of sphere is a closed cylinder
prim2.embedSphere(40.0f); prim2.embedSphere(40.0f);
//
// CellMarker mark2(myMap,VERTEX_CELL);
// prim2.mark(mark2);
//
// Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
//
// Algo::Render::VBO::MapRender_VBO render1 = new Algo::Render::VBO::MapRender_VBO() ;
//
// render1->updateData(Algo::Render::VBO::POSITIONS, position);
// render1->updateData(Algo::Render::VBO::NORMALS, normal);
// // update flat faces primtives (warning need position buffer)
// render1->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::FLAT_TRIANGLES);
// // update smooth faces primtives
// render1->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::TRIANGLES);
// // update lines primitives
// render1->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::LINES);
//
//
// update renderer // update renderer
mgw.updateRender(); mgw.updateRender();
root = new Utils::SceneGraph::Material_Node(); mgw.root = new Utils::SceneGraph::Group_Node();
root->setDiffuse(Geom::Vec4f(0.3f, 1.0f, 0.0f, 1.0f));
root->setColor(Geom::Vec4f(0.0f, 0.0f, 0.0f, 1.0f)); Utils::SceneGraph::Material_Node* mater = new Utils::SceneGraph::Material_Node();
mater->setDiffuse(Geom::Vec4f(0.3f, 1.0f, 0.0f, 1.0f));
mater->setColor(Geom::Vec4f(0.0f, 0.0f, 0.0f, 1.0f));
Utils::SceneGraph::VBO_Node* vbon = new Utils::SceneGraph::VBO_Node(); mgw.root->setMaterial(mater);
vbon->setVBO(mgw.m_render);
Utils::SceneGraph::VBO_Node* vbon = new Utils::SceneGraph::VBO_Node(mgw.m_render);
vbon->setPrimitives(Algo::Render::VBO::FLAT_TRIANGLES); vbon->setPrimitives(Algo::Render::VBO::FLAT_TRIANGLES);
root->addChild(vbon); mgw.root->addChild(vbon);
Utils::SceneGraph::Transfo_Node* transfo = new Utils::SceneGraph::Transfo_Node(); Utils::SceneGraph::Group_Node* group1 = new Utils::SceneGraph::Group_Node();
Geom::Matrix44f mat; Geom::Matrix44f mat;
mat.identity(); mat.identity();
Geom::translate(80.0f, 0.0f, 0.0f,mat); Geom::translate(80.0f, 0.0f, 0.0f,mat);
transfo->setMatrix(mat); group1->setMatrixTransfo(mat);
root->addChild(transfo); mgw.root->addChild(group1);
vbon = new Utils::SceneGraph::VBO_Node(); vbon = new Utils::SceneGraph::VBO_Node(mgw.m_render);
vbon->setVBO(mgw.m_render); vbon->setPrimitives(Algo::Render::VBO::TRIANGLES);
vbon->setPrimitives(Algo::Render::VBO::FLAT_TRIANGLES);
vbon->setPrimitives(Algo::Render::VBO::LINES); vbon->setPrimitives(Algo::Render::VBO::LINES);
transfo->addChild(vbon); group1->addChild(vbon);
transfo = new Utils::SceneGraph::Transfo_Node(); Utils::SceneGraph::Group_Node* group2 = new Utils::SceneGraph::Group_Node();
mat.identity(); mat.identity();
Geom::translate(100.0f, 50.0f, 20.0f,mat); Geom::translate(100.0f, 50.0f, 20.0f,mat);
transfo->setMatrix(mat); group2->setMatrixTransfo(mat);
root->addChild(transfo); mgw.root->addChild(group2);
Utils::SceneGraph::Material_Node* material = new Utils::SceneGraph::Material_Node();
material->setDiffuse(Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f));
transfo->addChild(material); mater = new Utils::SceneGraph::Material_Node();
mater->setDiffuse(Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f));
mater->setColor(Geom::Vec4f(1.0f, 1.0f, 0.0f, 1.0f));
group2->setMaterial(mater);
vbon = new Utils::SceneGraph::VBO_Node(); vbon = new Utils::SceneGraph::VBO_Node(mgw.m_render);
vbon->setVBO(mgw.m_render);
vbon->setPrimitives(Algo::Render::VBO::FLAT_TRIANGLES); vbon->setPrimitives(Algo::Render::VBO::FLAT_TRIANGLES);
vbon->setPrimitives(Algo::Render::VBO::LINES);
material->addChild(vbon); group2->addChild(vbon);
delete root;
// compute BB and store it for object positionning in screen // compute BB and store it for object positionning in screen
...@@ -262,8 +306,6 @@ int main(int argc, char **argv) ...@@ -262,8 +306,6 @@ int main(int argc, char **argv)
mgw.mainLoop(); mgw.mainLoop();
return 0; return 0;
} }
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include <vector> #include <vector>
#include "Algo/Modelisation/subdivision.h" #include "Algo/Modelisation/subdivision.h"
#include "Geometry/transfo.h" #include "Geometry/transfo.h"
#include "Topology/generic/cellmarker.h"
#include "Utils/os_spec.h" #include "Utils/os_spec.h"
...@@ -316,9 +318,9 @@ public: ...@@ -316,9 +318,9 @@ public:
/** /**
* mark all darts of the Polyhedron * mark all darts of the Polyhedron
* @param m the marker to use * @param m the CellMarker(VERTEX) to use
*/ */
void mark(Marker m); void mark(CellMarker m);
/** /**
* mark all embedded vertices of the Polyhedron * mark all embedded vertices of the Polyhedron
......
...@@ -971,11 +971,11 @@ void Polyhedron<PFP>::transform(const Geom::Matrix44f& matrice) ...@@ -971,11 +971,11 @@ void Polyhedron<PFP>::transform(const Geom::Matrix44f& matrice)
} }
template <typename PFP> template <typename PFP>
void Polyhedron<PFP>::mark(Marker m) void Polyhedron<PFP>::mark(CellMarker m)
{ {
for(typename std::vector<Dart>::iterator di=m_tableVertDarts.begin(); di!=m_tableVertDarts.end(); ++di) for(typename std::vector<Dart>::iterator di=m_tableVertDarts.begin(); di!=m_tableVertDarts.end(); ++di)
{ {
m_map.markOrbit(0,*di,m); m.mark(*di);
} }
} }
......
...@@ -109,11 +109,14 @@ protected: ...@@ -109,11 +109,14 @@ protected:
public: public:
/** /**
* Constructor * Constructor
* @param map the map to draw
* @param good functor that return true for darts of part to draw
*/ */
MapRender_VBO() ; MapRender_VBO() ;
/**
* Constructor that share vertices attributes vbo (position/normals/colors...)
*/
MapRender_VBO(const MapRender_VBO& mrvbo);
/** /**
* Destructor * Destructor
*/ */
......
...@@ -125,7 +125,7 @@ public: ...@@ -125,7 +125,7 @@ public:
/** /**
* destructor * destructor
*/ */
virtual ~SimpleGlutWin() {}; virtual ~SimpleGlutWin() {}
/** /**
* set the focale distance (for a screen width of 2), default value is 1 * set the focale distance (for a screen width of 2), default value is 1
......
/*******************************************************************************
* 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 *
* *
*******************************************************************************/
#ifndef __SCENE_GRAPH_ #ifndef __SCENE_GRAPH_
#define __SCENE_GRAPH_ #define __SCENE_GRAPH_
...@@ -13,98 +37,63 @@ namespace Utils ...@@ -13,98 +37,63 @@ namespace Utils
namespace SceneGraph namespace SceneGraph
{ {
/**
* Simple Node class
*/
class Node class Node
{ {
protected: protected:
std::string m_label; std::string m_label;
unsigned int m_nbRefs;
public: public:
Node():m_label("SceneGraph::Node") {} /**
* Constructor
virtual ~Node() {} */
Node();
Node(const std::string& lab): m_label(lab) {}
/**
const std::string& getLabel() const { return m_label;} * Constructor
*/
void setLabel(const std::string& lab) { m_label = lab ;} Node(const std::string& lab);
virtual void apply() = 0; /**
* Destructor
*/
virtual ~Node();
/**
* increment reference counter
*/
void ref();
/**
* decrement reference counter
* @return true if counter is 0 and node can be destructed
*/
bool unref();
/**
* get the label
* @return the label
*/
const std::string& getLabel() const;
/**
* set the label
* @param lab label
*/
void setLabel(const std::string& lab);
/**
* Rendering callback (used in traversal by renderGraph)
*/
virtual void render() = 0;
}; };
void render(Node* node) /**
{ * Class describing OpenGL materials
node->apply(); */
} class Material_Node: public Node
void eraseGraph(Node* node)
{
node->apply();
}
class Group_Node: public Node
{
protected:
std::list<Node*> m_children;
public:
Group_Node(): Node("SceneGraph::Group_Node") {}
Group_Node(const std::string& label): Node(label) {}
virtual ~Group_Node()
{
std::cout<< "delete group"<<std::endl;
for (std::list<Node*>::const_iterator it = m_children.begin(); it !=m_children.end(); ++it)
delete *it;
}
const std::list<Node*>& getChildren() const { return m_children;}
void addChild(Node* child) { m_children.push_back(child);}
void removeChild(Node* child) {m_children.remove( child);}
virtual void apply()
{
for (std::list<Node*>::const_iterator it = m_children.begin(); it !=m_children.end(); ++it)
render(*it);
}
};
class Transfo_Node: public Group_Node
{
protected:
Geom::Matrix44f* m_matrix;
public:
Transfo_Node():Group_Node("SceneGraph::Transfo_Node"),m_matrix(NULL) {}
virtual ~Transfo_Node() {std::cout<< "delete group"<<std::endl; delete m_matrix; }
void setMatrix(const Geom::Matrix44f& mat)
{
if (m_matrix == NULL)
m_matrix = new Geom::Matrix44f(mat);
*m_matrix = mat.transposed();
}
Geom::Matrix44f getMatrix() const { return m_matrix->transposed(); }
virtual void apply()
{
if (m_matrix != NULL)
glMultMatrixf(&((*m_matrix)(0,0)));
Group_Node::apply();
} // transpose ??
};
class Material_Node: public Group_Node
{ {
protected: protected:
Geom::Vec4f m_diffuse; Geom::Vec4f m_diffuse;
...@@ -119,91 +108,179 @@ protected: ...@@ -119,91 +108,179 @@ protected:
bool m_has_color; bool m_has_color;
public: public:
Material_Node():Group_Node("SceneGraph::Material_Node"), m_has_diffuse(false), m_has_specular(false),m_has_ambient(false),m_has_shininess(false),m_has_color(false){} /**
* Constructor
void setDiffuse(const Geom::Vec4f& v) { m_diffuse = v; m_has_diffuse=true;} */
Material_Node();
/**
* set diffuse color material
* @param v the color RGBA
*/
void setDiffuse(const Geom::Vec4f& v);
/**
* set specular color material
* @param v the color RGBA
*/
void setSpecular(const Geom::Vec4f& v);
/**
* set ambient color material
* @param v the color RGBA
*/
void setAmbient(const Geom::Vec4f& v);
/**
* set shinineess (OGL)
* @param s the shininess
*/
void setShininess(float s);
/**
* set color (for rendering with no lighting)
* @param v the color RGBA
*/
void setColor(const Geom::Vec4f& v);
/**
* Rendering callback (used in traversal by renderGraph)
*/
virtual void render();
};
void setSpecular(const Geom::Vec4f& v) { m_specular = v; m_has_specular=true;}
void setAmbient(const Geom::Vec4f& v) { m_ambient = v; m_has_ambient=true;} /**
* class of group node
* contain a list of child, a transformation, and material
*/
class Group_Node: public Node
{
protected:
std::list<Node*> m_children;
void setShininess(float v) { m_shininess = v; m_has_shininess=true; } Geom::Matrix44f* m_matrix_transfo;
void setColor(const Geom::Vec4f& v) { m_color = v; m_has_color=true;} Material_Node* m_material;
virtual void apply()