Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Thomas Pitiot
CGoGN
Commits
9e4f8b88
Commit
9e4f8b88
authored
Feb 02, 2011
by
Sylvain Thery
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ajout mini graph de scene
vbo avec partage de sommets
parent
a3a475f3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
604 additions
and
190 deletions
+604
-190
Apps/Examples/scene.cpp
Apps/Examples/scene.cpp
+76
-34
include/Algo/Modelisation/polyhedron.h
include/Algo/Modelisation/polyhedron.h
+4
-2
include/Algo/Modelisation/polyhedron.hpp
include/Algo/Modelisation/polyhedron.hpp
+2
-2
include/Algo/Render/vbo_MapRender.h
include/Algo/Render/vbo_MapRender.h
+5
-2
include/Utils/glutwin.h
include/Utils/glutwin.h
+1
-1
include/Utils/scene_graph.h
include/Utils/scene_graph.h
+226
-149
src/Utils/scene_graph.cpp
src/Utils/scene_graph.cpp
+290
-0
No files found.
Apps/Examples/scene.cpp
View file @
9e4f8b88
...
...
@@ -34,9 +34,11 @@
#include "Geometry/matrix.h"
#include "Geometry/transfo.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Geometry/normal.h"
#include "Algo/Render/vbo_MapRender.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Topology/generic/cellmarker.h"
#include "Utils/scene_graph.h"
...
...
@@ -53,7 +55,7 @@ struct PFP: public PFP_STANDARD
PFP
::
MAP
myMap
;
Utils
::
SceneGraph
::
Material_Node
*
root
;
class
myGlutWin
:
public
Utils
::
SimpleGlutWin
{
...
...
@@ -91,6 +93,9 @@ public:
// position handler
PFP
::
TVEC3
position
;
PFP
::
TVEC3
normal
;
Utils
::
SceneGraph
::
Group_Node
*
root
;
/**
* render object
...
...
@@ -104,13 +109,19 @@ public:
m_render
(
NULL
)
{
}
~
myGlutWin
();
void
exitCallback
();
~
myGlutWin
()
{}
};
myGlutWin
::
~
myGlutWin
()
void
myGlutWin
::
exitCallback
()
{
if
(
m_render
)
delete
m_render
;
std
::
cout
<<
"DESTRUCTOR"
<<
std
::
endl
;
eraseGraph
(
root
);
// if (m_render)
// delete m_render;
}
void
myGlutWin
::
init
()
...
...
@@ -140,9 +151,14 @@ void myGlutWin::updateRender()
m_render
->
updateData
(
Algo
::
Render
::
VBO
::
POSITIONS
,
position
);
// update flat faces primtives (warning need position buffer)
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
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)
//
// glDisable( GL_POLYGON_OFFSET_FILL );
Utils
::
SceneGraph
::
render
(
root
);
Utils
::
SceneGraph
::
render
Graph
(
root
);
glPopMatrix
();
}
...
...
@@ -183,8 +199,6 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y)
{
switch
(
keycode
)
{
case
27
:
exit
(
0
);
default:
break
;
}
...
...
@@ -198,61 +212,91 @@ int main(int argc, char **argv)
mgw
.
init
();
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
Algo
::
Modelisation
::
Polyhedron
<
PFP
>
prim2
(
myMap
,
mgw
.
position
);
prim2
.
cylinder_topo
(
16
,
16
,
true
,
true
);
// topo of sphere is a closed cylinder
prim2
.
embedSphere
(
40.0
f
);
//
// 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
mgw
.
updateRender
();
root
=
new
Utils
::
SceneGraph
::
Material_Node
();
root
->
setDiffuse
(
Geom
::
Vec4f
(
0.3
f
,
1.0
f
,
0.0
f
,
1.0
f
));
root
->
setColor
(
Geom
::
Vec4f
(
0.0
f
,
0.0
f
,
0.0
f
,
1.0
f
));
mgw
.
root
=
new
Utils
::
SceneGraph
::
Group_Node
();
Utils
::
SceneGraph
::
Material_Node
*
mater
=
new
Utils
::
SceneGraph
::
Material_Node
();
mater
->
setDiffuse
(
Geom
::
Vec4f
(
0.3
f
,
1.0
f
,
0.0
f
,
1.0
f
));
mater
->
setColor
(
Geom
::
Vec4f
(
0.0
f
,
0.0
f
,
0.0
f
,
1.0
f
));
Utils
::
SceneGraph
::
VBO_Node
*
vbon
=
new
Utils
::
SceneGraph
::
VBO_Node
();
vbon
->
setVBO
(
mgw
.
m_render
);
mgw
.
root
->
setMaterial
(
mater
);
Utils
::
SceneGraph
::
VBO_Node
*
vbon
=
new
Utils
::
SceneGraph
::
VBO_Node
(
mgw
.
m_render
);
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
;
mat
.
identity
();
Geom
::
translate
(
80.0
f
,
0.0
f
,
0.0
f
,
mat
);
transfo
->
setMatrix
(
mat
);
group1
->
setMatrix
Transfo
(
mat
);
root
->
addChild
(
transfo
);
mgw
.
root
->
addChild
(
group1
);
vbon
=
new
Utils
::
SceneGraph
::
VBO_Node
();
vbon
->
setVBO
(
mgw
.
m_render
);
vbon
->
setPrimitives
(
Algo
::
Render
::
VBO
::
FLAT_TRIANGLES
);
vbon
=
new
Utils
::
SceneGraph
::
VBO_Node
(
mgw
.
m_render
);
vbon
->
setPrimitives
(
Algo
::
Render
::
VBO
::
TRIANGLES
);
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
();
Geom
::
translate
(
100.0
f
,
50.0
f
,
20.0
f
,
mat
);
transfo
->
setMatrix
(
mat
);
group2
->
setMatrix
Transfo
(
mat
);
root
->
addChild
(
transfo
);
mgw
.
root
->
addChild
(
group2
);
Utils
::
SceneGraph
::
Material_Node
*
material
=
new
Utils
::
SceneGraph
::
Material_Node
();
material
->
setDiffuse
(
Geom
::
Vec4f
(
1.0
f
,
0.0
f
,
0.0
f
,
1.0
f
));
transfo
->
addChild
(
material
);
mater
=
new
Utils
::
SceneGraph
::
Material_Node
();
mater
->
setDiffuse
(
Geom
::
Vec4f
(
1.0
f
,
0.0
f
,
0.0
f
,
1.0
f
));
mater
->
setColor
(
Geom
::
Vec4f
(
1.0
f
,
1.0
f
,
0.0
f
,
1.0
f
));
group2
->
setMaterial
(
mater
);
vbon
=
new
Utils
::
SceneGraph
::
VBO_Node
();
vbon
->
setVBO
(
mgw
.
m_render
);
vbon
=
new
Utils
::
SceneGraph
::
VBO_Node
(
mgw
.
m_render
);
vbon
->
setPrimitives
(
Algo
::
Render
::
VBO
::
FLAT_TRIANGLES
);
vbon
->
setPrimitives
(
Algo
::
Render
::
VBO
::
LINES
);
material
->
addChild
(
vbon
);
delete
root
;
group2
->
addChild
(
vbon
);
// compute BB and store it for object positionning in screen
...
...
@@ -262,8 +306,6 @@ int main(int argc, char **argv)
mgw
.
mainLoop
();
return
0
;
}
...
...
include/Algo/Modelisation/polyhedron.h
View file @
9e4f8b88
...
...
@@ -28,6 +28,8 @@
#include <vector>
#include "Algo/Modelisation/subdivision.h"
#include "Geometry/transfo.h"
#include "Topology/generic/cellmarker.h"
#include "Utils/os_spec.h"
...
...
@@ -316,9 +318,9 @@ public:
/**
* 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
(
Cell
Marker
m
);
/**
* mark all embedded vertices of the Polyhedron
...
...
include/Algo/Modelisation/polyhedron.hpp
View file @
9e4f8b88
...
...
@@ -971,11 +971,11 @@ void Polyhedron<PFP>::transform(const Geom::Matrix44f& matrice)
}
template
<
typename
PFP
>
void
Polyhedron
<
PFP
>::
mark
(
Marker
m
)
void
Polyhedron
<
PFP
>::
mark
(
Cell
Marker
m
)
{
for
(
typename
std
::
vector
<
Dart
>::
iterator
di
=
m_tableVertDarts
.
begin
();
di
!=
m_tableVertDarts
.
end
();
++
di
)
{
m
_map
.
mark
Orbit
(
0
,
*
di
,
m
);
m
.
mark
(
*
di
);
}
}
...
...
include/Algo/Render/vbo_MapRender.h
View file @
9e4f8b88
...
...
@@ -109,11 +109,14 @@ protected:
public:
/**
* Constructor
* @param map the map to draw
* @param good functor that return true for darts of part to draw
*/
MapRender_VBO
()
;
/**
* Constructor that share vertices attributes vbo (position/normals/colors...)
*/
MapRender_VBO
(
const
MapRender_VBO
&
mrvbo
);
/**
* Destructor
*/
...
...
include/Utils/glutwin.h
View file @
9e4f8b88
...
...
@@ -125,7 +125,7 @@ public:
/**
* destructor
*/
virtual
~
SimpleGlutWin
()
{}
;
virtual
~
SimpleGlutWin
()
{}
/**
* set the focale distance (for a screen width of 2), default value is 1
...
...
include/Utils/scene_graph.h
View file @
9e4f8b88
/*******************************************************************************
* 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_
#define __SCENE_GRAPH_
...
...
@@ -13,98 +37,63 @@ namespace Utils
namespace
SceneGraph
{
/**
* Simple Node class
*/
class
Node
{
protected:
std
::
string
m_label
;
unsigned
int
m_nbRefs
;
public:
Node
()
:
m_label
(
"SceneGraph::Node"
)
{}
virtual
~
Node
()
{}
Node
(
const
std
::
string
&
lab
)
:
m_label
(
lab
)
{}
const
std
::
string
&
getLabel
()
const
{
return
m_label
;}
void
setLabel
(
const
std
::
string
&
lab
)
{
m_label
=
lab
;}
virtual
void
apply
()
=
0
;
/**
* Constructor
*/
Node
();
/**
* Constructor
*/
Node
(
const
std
::
string
&
lab
);
/**
* 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
)
{
node
->
apply
();
}
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
/**
* Class describing OpenGL materials
*/
class
Material_Node
:
public
Node
{
protected:
Geom
::
Vec4f
m_diffuse
;
...
...
@@ -119,91 +108,179 @@ protected:
bool
m_has_color
;
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
){}
void
setDiffuse
(
const
Geom
::
Vec4f
&
v
)
{
m_diffuse
=
v
;
m_has_diffuse
=
true
;}
/**
* Constructor
*/
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
()
{
if
(
m_has_diffuse
)
glMaterialfv
(
GL_FRONT_AND_BACK
,
GL_DIFFUSE
,
m_diffuse
.
data
());
if
(
m_has_specular
)
glMaterialfv
(
GL_FRONT_AND_BACK
,
GL_SPECULAR
,
m_specular
.
data
());
if
(
m_has_ambient
)
glMaterialfv
(
GL_FRONT_AND_BACK
,
GL_AMBIENT
,
m_ambient
.
data
());
if
(
m_has_shininess
)
glMaterialfv
(
GL_FRONT_AND_BACK
,
GL_SHININESS
,
&
m_shininess
);
if
(
m_has_color
)
glColor3fv
(
m_color
.
data
());
public:
/**
* Constructor
*/
Group_Node
();
/**
* Constructor
*/
Group_Node
(
const
std
::
string
&
label
);
/**
* Destructor
*/
virtual
~
Group_Node
();
/**
* get the children list
* @return the list (no modification allowed)
*/
const
std
::
list
<
Node
*>&
getChildren
()
const
;
/**
* add a child
* @param child
*/
void
addChild
(
Node
*
child
);
/**
* remove a child
* @param child
*/
void
removeChild
(
Node
*
child
);
/**
* set trnaformation matrix (4x4)
* @param mat matrix (copy and stored here transposed for OGL)
*/
void
setMatrixTransfo
(
const
Geom
::
Matrix44f
&
mat
);
/**
* set material
* @param v the color RGBA
*/
void
setMaterial
(
Material_Node
*
mat
);
/**
* Rendering callback (used in traversal by renderGraph)
*/
virtual
void
render
();
Group_Node
::
apply
();
}
};
class
VBO_Node
:
public
Node
{
protected:
Algo
::
Render
::
VBO
::
MapRender_VBO
*
m_vbo
;
unsigned
int
m_primitives
;
public:
VBO_Node
()
:
Node
(
"SceneGraph::VBO_Node"
),
m_vbo
(
NULL
),
m_primitives
(
0
)
{}
VBO_Node
(
Algo
::
Render
::
VBO
::
MapRender_VBO
*
vbo
)
:
m_vbo
(
vbo
)
{}
void
setVBO
(
Algo
::
Render
::
VBO
::
MapRender_VBO
*
vbo
)
{
m_vbo
=
vbo
;}
void
setPrimitives
(
unsigned
int
p
)
{
m_primitives
|=
p
;}
void
unsetPrimitives
(
unsigned
int
p
)
{
m_primitives
&=
~
p
;}
virtual
void
apply
()
{
if
(
m_vbo
!=
NULL
)
{
if
(
m_primitives
&
Algo
::
Render
::
VBO
::
TRIANGLES
)
{
glEnable
(
GL_POLYGON_OFFSET_FILL
);
glPolygonOffset
(
1.0
f
,
1.0
f
);
glEnable
(
GL_LIGHTING
);
m_vbo
->
draw
(
Algo
::
Render
::
VBO
::
TRIANGLES
);
}
if
(
m_primitives
&
Algo
::
Render
::
VBO
::
LINES
)
{
glDisable
(
GL_POLYGON_OFFSET_FILL
);
glDisable
(
GL_LIGHTING
);
m_vbo
->
draw
(
Algo
::
Render
::
VBO
::
LINES
);
}
if
(
m_primitives
&
Algo
::
Render
::
VBO
::
POINTS
)