Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Thomas Pitiot
CGoGN
Commits
968767a9
Commit
968767a9
authored
Jun 06, 2011
by
Thomas
Browse files
Merge branch 'master' of cgogn:~untereiner/CGoGN
parents
7085f8c9
1b5409d4
Changes
17
Hide whitespace changes
Inline
Side-by-side
Apps/Tuto/CMakeLists.txt
View file @
968767a9
...
...
@@ -65,6 +65,14 @@ add_executable( tuto5 tuto5.cpp ${tuto5_ui} ${tuto5_moc})
target_link_libraries
(
tuto5
${
CGoGN_LIBS_D
}
${
COMMON_LIBS
}
${
QT_LIBRARIES
}
)
QT4_WRAP_UI
(
stage_shader_ui stage_shader.ui
)
QT4_WRAP_CPP
(
stage_shader_moc stage_shader.h
)
add_executable
(
stage_shader stage_shader.cpp
${
stage_shader_ui
}
${
stage_shader_moc
}
)
target_link_libraries
(
stage_shader
${
CGoGN_LIBS_D
}
${
COMMON_LIBS
}
${
QT_LIBRARIES
}
)
#add_executable( tuto_subdivision tuto_subdivision.cpp)
#target_link_libraries( tuto_subdivision
# ${CGoGN_LIBS_D} ${COMMON_LIBS} )
...
...
@@ -90,6 +98,8 @@ add_executable( tuto_ogl3 tuto_ogl3.cpp ${tuto_ogl3_moc})
target_link_libraries
(
tuto_ogl3
${
CGoGN_LIBS_D
}
${
COMMON_LIBS
}
${
QT_LIBRARIES
}
)
#add_executable( tuto_ogl2 tuto_ogl2.cpp)
#target_link_libraries( tuto_ogl2
# ${CGoGN_LIBS_D} ${COMMON_LIBS} )
Apps/Tuto/stage_shader.cpp
0 → 100644
View file @
968767a9
/*
* stage_shader.cpp
*
* Created on: 6 juin 2011
* Author: untereiner
*/
#include
"stage_shader.h"
/*******************************************************************************
* SLOTS
*******************************************************************************/
void
StageShader
::
slot_drawTopo
(
bool
b
)
{
m_drawTopo
=
b
;
updateGL
();
}
void
StageShader
::
slot_drawVertices
(
bool
b
)
{
m_drawVertices
=
b
;
updateGL
();
}
void
StageShader
::
slot_drawLines
(
bool
b
)
{
m_drawLines
=
b
;
updateGL
();
}
void
StageShader
::
slot_drawFaces
(
bool
b
)
{
m_drawFaces
=
b
;
updateGL
();
}
void
StageShader
::
slot_explodTopoPhi1
(
double
c
)
{
m_coeffTopoExplod
[
0
]
=
(
float
)
c
;
m_render_topo
->
updateData
<
PFP
>
(
myMap
,
allDarts
,
position
,
m_coeffTopoExplod
[
0
],
m_coeffTopoExplod
[
1
],
m_coeffTopoExplod
[
2
]);
updateGL
();
}
void
StageShader
::
slot_explodTopoPhi2
(
double
c
)
{
m_coeffTopoExplod
[
1
]
=
(
float
)
c
;
m_render_topo
->
updateData
<
PFP
>
(
myMap
,
allDarts
,
position
,
m_coeffTopoExplod
[
0
],
m_coeffTopoExplod
[
1
],
m_coeffTopoExplod
[
2
]);
updateGL
();
}
void
StageShader
::
slot_explodTopoPhi3
(
double
c
)
{
m_coeffTopoExplod
[
2
]
=
(
float
)
c
;
m_render_topo
->
updateData
<
PFP
>
(
myMap
,
allDarts
,
position
,
m_coeffTopoExplod
[
0
],
m_coeffTopoExplod
[
1
],
m_coeffTopoExplod
[
2
]);
updateGL
();
}
void
StageShader
::
button_compile
()
{
QString
st1
=
dynamic_cast
<
Utils
::
QT
::
uiDockInterface
*>
(
dockWidget
())
->
vertexEdit
->
toPlainText
();
QString
st2
=
dynamic_cast
<
Utils
::
QT
::
uiDockInterface
*>
(
dockWidget
())
->
fragmentEdit
->
toPlainText
();
QString
st3
=
dynamic_cast
<
Utils
::
QT
::
uiDockInterface
*>
(
dockWidget
())
->
geometryEdit
->
toPlainText
();
m_shader
->
reloadVertexShaderFromMemory
(
st1
.
toStdString
().
c_str
());
m_shader
->
reloadFragmentShaderFromMemory
(
st2
.
toStdString
().
c_str
());
m_shader
->
reloadGeometryShaderFromMemory
(
st3
.
toStdString
().
c_str
());
m_shader
->
recompile
();
updateGLMatrices
();
}
/*******************************************************************************
* QT TRICK
*******************************************************************************/
void
StageShader
::
dockWidget_topLevelChanged
(
bool
isFloating
)
{
if
(
isFloating
)
{
dockWidget
()
->
setWindowFlags
(
Qt
::
Window
);
// setWindowFlags calls setParent() when changing the flags for a window, causing the widget to be hidden.
// You must call show() to make the widget visible again
dockWidget
()
->
show
();
}
}
/*******************************************************************************
* Init Functions
*******************************************************************************/
StageShader
::
StageShader
()
:
m_drawVertices
(
false
),
m_drawLines
(
true
),
m_drawFaces
(
true
),
m_drawTopo
(
false
),
m_render
(
NULL
),
m_render_topo
(
NULL
),
m_positionVBO
(
NULL
),
m_shader
(
NULL
)
{
m_coeffTopoExplod
=
Geom
::
Vec3f
(
0.9
,
0.9
,
0.9
);
}
void
StageShader
::
initGUI
()
{
CGoGNStream
::
allToConsole
(
this
)
;
CGoGNStream
::
allToStd
(
false
)
;
setDock
(
&
dock
);
dock
.
setWindowFlags
(
Qt
::
WindowMinimizeButtonHint
);
setCallBack
(
dock
.
checkBox_vertices
,
SIGNAL
(
toggled
(
bool
)),
SLOT
(
slot_drawVertices
(
bool
)));
setCallBack
(
dock
.
checkBox_lines
,
SIGNAL
(
toggled
(
bool
)),
SLOT
(
slot_drawLines
(
bool
)));
setCallBack
(
dock
.
checkBox_faces
,
SIGNAL
(
toggled
(
bool
)),
SLOT
(
slot_drawFaces
(
bool
)));
setCallBack
(
dock
.
groupBox_topo
,
SIGNAL
(
toggled
(
bool
)),
SLOT
(
slot_drawTopo
(
bool
)));
setCallBack
(
dock
.
explod_phi1
,
SIGNAL
(
valueChanged
(
double
)),
SLOT
(
slot_explodTopoPhi1
(
double
)));
setCallBack
(
dock
.
explod_phi2
,
SIGNAL
(
valueChanged
(
double
)),
SLOT
(
slot_explodTopoPhi2
(
double
)));
setCallBack
(
dock
.
explod_phi3
,
SIGNAL
(
valueChanged
(
double
)),
SLOT
(
slot_explodTopoPhi3
(
double
)));
setCallBack
(
&
dock
,
SIGNAL
(
topLevelChanged
(
bool
)),
SLOT
(
dockWidget_topLevelChanged
(
bool
)));
setCallBack
(
dock
.
compileButton
,
SIGNAL
(
clicked
()),
SLOT
(
button_compile
())
);
dock
.
vertexEdit
->
setPlainText
(
QString
(
m_shader
->
getVertexShaderSrc
()));
dock
.
fragmentEdit
->
setPlainText
(
QString
(
m_shader
->
getFragmentShaderSrc
()));
dock
.
geometryEdit
->
setPlainText
(
QString
(
m_shader
->
getGeometryShaderSrc
()));
}
void
StageShader
::
cb_Open
()
{
std
::
string
filters
(
"all (*.*)"
)
;
std
::
string
filename
=
selectFile
(
"Open Mesh"
,
""
,
filters
)
;
importMesh
(
filename
)
;
updateGL
()
;
}
void
StageShader
::
importMesh
(
std
::
string
&
filename
)
{
std
::
vector
<
std
::
string
>
attrNames
;
std
::
string
extension
;
size_t
pos
;
pos
=
filename
.
rfind
(
"."
);
// position of "." in filename
extension
=
filename
.
substr
(
pos
);
if
(
extension
==
std
::
string
(
".tet"
))
{
if
(
!
Algo
::
Import
::
importTet
<
PFP
>
(
myMap
,
filename
.
c_str
(),
attrNames
))
{
CGoGNerr
<<
"could not import "
<<
filename
<<
CGoGNendl
;
return
;
}
else
position
=
myMap
.
getAttribute
<
PFP
::
VEC3
>
(
VERTEX
,
attrNames
[
0
])
;
}
else
if
(
extension
==
std
::
string
(
".ts"
))
{
if
(
!
Algo
::
Import
::
importTs
<
PFP
>
(
myMap
,
filename
.
c_str
(),
attrNames
))
{
CGoGNerr
<<
"could not import "
<<
filename
<<
CGoGNendl
;
return
;
}
else
position
=
myMap
.
getAttribute
<
PFP
::
VEC3
>
(
VERTEX
,
attrNames
[
0
])
;
}
else
{
position
=
myMap
.
addAttribute
<
PFP
::
VEC3
>
(
VERTEX
,
"position"
);
Algo
::
Modelisation
::
Primitive3D
<
PFP
>
prim
(
myMap
,
position
);
prim
.
hexaGrid_topo
(
10
,
10
,
10
);
prim
.
embedHexaGrid
(
1.0
f
,
1.0
f
,
1.0
f
);
}
updateVBOprimitives
(
Algo
::
Render
::
GL2
::
TRIANGLES
|
Algo
::
Render
::
GL2
::
LINES
|
Algo
::
Render
::
GL2
::
POINTS
)
;
m_render_topo
->
updateData
<
PFP
>
(
myMap
,
allDarts
,
position
,
m_coeffTopoExplod
[
0
],
m_coeffTopoExplod
[
1
],
m_coeffTopoExplod
[
2
]);
Geom
::
BoundingBox
<
PFP
::
VEC3
>
bb
=
Algo
::
Geometry
::
computeBoundingBox
<
PFP
>
(
myMap
,
position
)
;
gPosObj
=
bb
.
center
()
;
float
tailleX
=
bb
.
size
(
0
)
;
float
tailleY
=
bb
.
size
(
1
)
;
float
tailleZ
=
bb
.
size
(
2
)
;
gWidthObj
=
std
::
max
<
float
>
(
std
::
max
<
float
>
(
tailleX
,
tailleY
),
tailleZ
)
;
m_positionVBO
->
updateData
(
position
)
;
setParamObject
(
gWidthObj
,
gPosObj
.
data
())
;
updateGLMatrices
()
;
}
/*******************************************************************************
* GL FUNCTIONS
*******************************************************************************/
void
StageShader
::
cb_initGL
()
{
// choose to use GL version 2
Utils
::
GLSLShader
::
setCurrentOGLVersion
(
2
);
// create the render
m_render
=
new
Algo
::
Render
::
GL2
::
MapRender
();
m_render_topo
=
new
Algo
::
Render
::
GL2
::
Topo3RenderMapD
();
// 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.
,
1.
,
0.
,
0.
));
registerShader
(
m_shader
);
}
void
StageShader
::
updateVBOprimitives
(
int
upType
)
{
if
(
upType
&
Algo
::
Render
::
GL2
::
TRIANGLES
)
{
m_render
->
initPrimitives
<
PFP
>
(
myMap
,
allDarts
,
Algo
::
Render
::
GL2
::
TRIANGLES
)
;
}
if
(
upType
&
Algo
::
Render
::
GL2
::
LINES
)
{
m_render
->
initPrimitives
<
PFP
>
(
myMap
,
allDarts
,
Algo
::
Render
::
GL2
::
LINES
,
false
)
;
}
if
(
upType
&
Algo
::
Render
::
GL2
::
POINTS
)
{
m_render
->
initPrimitives
<
PFP
>
(
myMap
,
allDarts
,
Algo
::
Render
::
GL2
::
POINTS
)
;
}
}
void
StageShader
::
cb_redraw
()
{
if
(
m_drawVertices
)
{
m_shader
->
setColor
(
Geom
::
Vec4f
(
0.
,
0.
,
1.
,
0.
));
m_render
->
draw
(
m_shader
,
Algo
::
Render
::
GL2
::
POINTS
);
}
if
(
m_drawLines
)
{
glLineWidth
(
2.0
f
);
m_shader
->
setColor
(
Geom
::
Vec4f
(
1.
,
1.
,
0.
,
0.
));
m_render
->
draw
(
m_shader
,
Algo
::
Render
::
GL2
::
LINES
);
}
if
(
m_drawFaces
)
{
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_FILL
);
glEnable
(
GL_LIGHTING
);
glEnable
(
GL_POLYGON_OFFSET_FILL
);
glPolygonOffset
(
1.0
f
,
1.0
f
);
m_shader
->
setColor
(
Geom
::
Vec4f
(
0.
,
1.
,
0.
,
0.
));
m_render
->
draw
(
m_shader
,
Algo
::
Render
::
GL2
::
TRIANGLES
);
glDisable
(
GL_POLYGON_OFFSET_FILL
);
}
if
(
m_drawTopo
)
m_render_topo
->
drawTopo
();
}
void
StageShader
::
cb_keyPress
(
int
code
)
{
}
void
StageShader
::
cb_mousePress
(
int
button
,
int
x
,
int
y
)
{
}
/**********************************************************************************************
* MAIN FUNCTION *
**********************************************************************************************/
int
main
(
int
argc
,
char
**
argv
)
{
QApplication
app
(
argc
,
argv
)
;
StageShader
sqt
;
sqt
.
setGeometry
(
0
,
0
,
1000
,
800
)
;
sqt
.
show
()
;
if
(
argc
==
2
)
{
std
::
string
filename
(
argv
[
1
])
;
sqt
.
importMesh
(
filename
)
;
}
sqt
.
initGUI
()
;
return
app
.
exec
()
;
}
Apps/Tuto/stage_shader.h
0 → 100644
View file @
968767a9
/*
* stage_shader.h
*
* Created on: 6 juin 2011
* Author: untereiner
*/
#ifndef __STAGE_SHADER_H__
#define __STAGE_SHADER_H__
#include
<iostream>
#include
"Utils/qtSimple.h"
#include
"ui_stage_shader.h"
// inclure qtui.h juste après le ui_xxx.h
#include
"Utils/qtui.h"
#include
"Topology/generic/parameters.h"
#include
"Topology/map/map3.h"
#include
"Topology/generic/embeddedMap3.h"
#include
"Geometry/vector_gen.h"
#include
"Geometry/matrix.h"
#include
"Geometry/bounding_box.h"
#include
"Algo/Import/import.h"
//#include "Algo/Export/export.h"
#include
"Algo/Geometry/boundingbox.h"
#include
"Algo/Render/GL2/mapRender.h"
#include
"Algo/Render/GL2/topo3Render.h"
#include
"Utils/shaderSimpleColor.h"
#include
"Utils/cgognStream.h"
#include
"Utils/drawer.h"
using
namespace
CGoGN
;
struct
PFP
:
public
PFP_STANDARD
{
// definition of the map
typedef
EmbeddedMap3
<
Map3
>
MAP
;
};
class
StageShader
:
public
Utils
::
QT
::
SimpleQT
{
Q_OBJECT
public:
typedef
PFP
::
MAP
MAP
;
typedef
PFP
::
TVEC3
TVEC3
;
//Manip Carte
MAP
myMap
;
SelectorTrue
allDarts
;
TVEC3
position
;
Dart
dglobal
;
//Render
bool
m_drawVertices
;
bool
m_drawLines
;
bool
m_drawFaces
;
bool
m_drawTopo
;
Algo
::
Render
::
GL2
::
MapRender
*
m_render
;
Algo
::
Render
::
GL2
::
Topo3RenderMapD
*
m_render_topo
;
Utils
::
VBO
*
m_positionVBO
;
Utils
::
ShaderSimpleColor
*
m_shader
;
Utils
::
Drawer
*
influence_area
;
Utils
::
Drawer
*
chips_area
;
Geom
::
Vec3f
m_coeffTopoExplod
;
Geom
::
Vec3f
gPosObj
;
float
gWidthObj
;
//QT
Utils
::
QT
::
uiDockInterface
dock
;
StageShader
();
void
initGUI
();
void
cb_Open
();
void
updateVBOprimitives
(
int
upType
);
void
cb_initGL
();
void
cb_redraw
();
void
cb_mousePress
(
int
button
,
int
x
,
int
y
);
void
cb_keyPress
(
int
code
);
void
importMesh
(
std
::
string
&
filename
);
public
slots
:
void
slot_drawVertices
(
bool
b
);
void
slot_drawLines
(
bool
b
);
void
slot_drawFaces
(
bool
b
);
void
slot_drawTopo
(
bool
b
);
void
slot_explodTopoPhi1
(
double
c
);
void
slot_explodTopoPhi2
(
double
c
);
void
slot_explodTopoPhi3
(
double
c
);
void
dockWidget_topLevelChanged
(
bool
isFloating
);
void
button_compile
();
};
#endif
Apps/Tuto/stage_shader.ui
0 → 100644
View file @
968767a9
<?xml version="1.0" encoding="UTF-8"?>
<ui
version=
"4.0"
>
<class>
DockWidget
</class>
<widget
class=
"QDockWidget"
name=
"DockWidget"
>
<property
name=
"geometry"
>
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
324
</width>
<height>
473
</height>
</rect>
</property>
<property
name=
"allowedAreas"
>
<set>
Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea
</set>
</property>
<property
name=
"windowTitle"
>
<string>
Interface
</string>
</property>
<widget
class=
"QWidget"
name=
"dockWidgetContents"
>
<layout
class=
"QGridLayout"
name=
"gridLayout"
>
<item
row=
"0"
column=
"0"
>
<widget
class=
"QTabWidget"
name=
"tabWidget"
>
<property
name=
"tabPosition"
>
<enum>
QTabWidget::East
</enum>
</property>
<property
name=
"currentIndex"
>
<number>
0
</number>
</property>
<widget
class=
"QWidget"
name=
"tab"
>
<attribute
name=
"title"
>
<string>
Visualisation
</string>
</attribute>
<layout
class=
"QGridLayout"
name=
"gridLayout_6"
>
<item
row=
"0"
column=
"0"
>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout"
>
<item>
<widget
class=
"QCheckBox"
name=
"checkBox_vertices"
>
<property
name=
"text"
>
<string>
Vertices
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QCheckBox"
name=
"checkBox_lines"
>
<property
name=
"text"
>
<string>
Lines
</string>
</property>
<property
name=
"checked"
>
<bool>
true
</bool>
</property>
</widget>
</item>
<item>
<widget
class=
"QCheckBox"
name=
"checkBox_faces"
>
<property
name=
"text"
>
<string>
Faces
</string>
</property>
<property
name=
"checked"
>
<bool>
true
</bool>
</property>
</widget>
</item>
<item>
<widget
class=
"QGroupBox"
name=
"groupBox_topo"
>
<property
name=
"enabled"
>
<bool>
true
</bool>
</property>
<property
name=
"title"
>
<string>
Topo
</string>
</property>
<property
name=
"checkable"
>
<bool>
true
</bool>
</property>
<property
name=
"checked"
>
<bool>
false
</bool>
</property>
<layout
class=
"QGridLayout"
name=
"gridLayout_3"
>
<item
row=
"1"
column=
"0"
>
<layout
class=
"QGridLayout"
name=
"gridLayout_2"
>
<item
row=
"3"
column=
"2"
>
<widget
class=
"QDoubleSpinBox"
name=
"explod_phi2"
>
<property
name=
"maximum"
>
<double>
1.000000000000000
</double>
</property>
<property
name=
"singleStep"
>
<double>
0.100000000000000
</double>
</property>
<property
name=
"value"
>
<double>
0.900000000000000
</double>
</property>
</widget>
</item>
<item
row=
"5"
column=
"2"
>
<widget
class=
"QDoubleSpinBox"
name=
"explod_phi3"
>
<property
name=
"maximum"
>
<double>
1.000000000000000
</double>
</property>
<property
name=
"singleStep"
>
<double>
0.100000000000000
</double>
</property>
<property
name=
"value"
>
<double>
0.900000000000000
</double>
</property>
</widget>
</item>
<item
row=
"3"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_faces"
>
<property
name=
"text"
>
<string>
Faces
</string>
</property>
</widget>
</item>
<item
row=
"5"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_volumes"
>
<property
name=
"text"
>
<string>
Volumes
</string>
</property>
</widget>
</item>
<item
row=
"2"
column=
"2"
>
<widget
class=
"QDoubleSpinBox"
name=
"explod_phi1"
>
<property
name=
"prefix"
>
<string/>
</property>
<property
name=
"maximum"
>
<double>
1.000000000000000
</double>
</property>
<property
name=
"singleStep"
>
<double>
0.100000000000000
</double>
</property>
<property
name=
"value"
>
<double>
0.900000000000000
</double>
</property>
</widget>
</item>
<item
row=
"2"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_edges"
>
<property
name=
"text"
>
<string>
Edges
</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget
class=
"QGroupBox"
name=
"groupBox_rotate"
>
<property
name=
"title"
>
<string>
Rotate
</string>
</property>
<property
name=
"checkable"
>
<bool>
true
</bool>
</property>
<property
name=
"checked"
>
<bool>
false
</bool>
</property>
<layout
class=
"QGridLayout"
name=
"gridLayout_5"
>
<item
row=
"0"
column=
"0"
>
<layout
class=
"QGridLayout"
name=
"gridLayout_4"
>
<item
row=
"0"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label"
>
<property
name=
"text"
>
<string>
Speed
</string>
</property>
</widget>
</item>
<item
row=
"0"
column=
"1"
>
<widget
class=
"QDoubleSpinBox"
name=
"doubleSpinBox"
/>
</item>
</layout>
</item>
<item
row=
"1"
column=
"0"
>
<spacer
name=
"verticalSpacer"
>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>