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
Sauvage
CGoGN
Commits
1bbca422
Commit
1bbca422
authored
Feb 08, 2012
by
Sylvain Thery
Browse files
add interactive operation on 2-map tutorial
parent
9ea67fa3
Changes
10
Hide whitespace changes
Inline
Side-by-side
Apps/Tuto/CMakeLists.txt
View file @
1bbca422
...
...
@@ -53,6 +53,12 @@ add_executable( tuto5 tuto5.cpp ${tuto5_ui} ${tuto5_moc})
target_link_libraries
(
tuto5
${
CGoGN_LIBS_D
}
${
CGoGN_EXT_LIBS
}
)
QT4_WRAP_UI
(
tuto_oper2_ui tuto_oper2.ui
)
QT4_WRAP_CPP
(
tuto_oper2_moc tuto_oper2.h
)
add_executable
(
tuto_oper2 tuto_oper2.cpp
${
tuto_oper2_ui
}
${
tuto_oper2_moc
}
)
target_link_libraries
(
tuto_oper2
${
CGoGN_LIBS_D
}
${
CGoGN_EXT_LIBS
}
)
QT4_WRAP_UI
(
tuto_orbits_ui tuto_orbits.ui
)
QT4_WRAP_CPP
(
tuto_orbits_moc tuto_orbits.h
)
add_executable
(
tuto_orbits tuto_orbits.cpp
${
tuto_orbits_ui
}
${
tuto_orbits_moc
}
)
...
...
Apps/Tuto/tuto_oper2.cpp
0 → 100644
View file @
1bbca422
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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: http://cgogn.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include
"tuto_oper2.h"
#include
"Algo/Geometry/boundingbox.h"
#include
"Algo/Modelisation/polyhedron.h"
#include
"Algo/Geometry/centroid.h"
using
namespace
CGoGN
;
int
main
(
int
argc
,
char
**
argv
)
{
// // interface
QApplication
app
(
argc
,
argv
);
MyQT
sqt
;
sqt
.
setDock
(
&
sqt
.
dock
);
sqt
.
setCallBack
(
sqt
.
dock
.
listOper
,
SIGNAL
(
currentRowChanged
(
int
)),
SLOT
(
operation
(
int
))
);
int
n
=
3
;
if
(
argc
==
2
)
n
=
atoi
(
argv
[
1
]);
// example code itself
sqt
.
createMap
(
n
);
// set help message in menu
sqt
.
setHelpMsg
(
"First Tuto:
\n
Create two faces
\n
sew them
\n
and affect positions"
);
// final show for redraw
sqt
.
show
();
// and wait for the end
return
app
.
exec
();
}
void
MyQT
::
operation
(
int
x
)
{
switch
(
x
)
{
case
0
:
CGoGNout
<<
"split vertex"
<<
CGoGNendl
;
if
((
m_selected
!=
NIL
)
&&
(
m_selected2
!=
NIL
))
{
dm
.
markAll
();
myMap
.
splitVertex
(
m_selected
,
m_selected2
);
PFP
::
VEC3
c1
=
Algo
::
Geometry
::
faceCentroid
<
PFP
>
(
myMap
,
m_selected
,
position
);
PFP
::
VEC3
c2
=
Algo
::
Geometry
::
faceCentroid
<
PFP
>
(
myMap
,
m_selected2
,
position
);
position
[
m_selected
]
=
position
[
m_selected
]
*
0.7
f
+
c1
*
0.3
f
;
position
[
m_selected2
]
=
position
[
m_selected2
]
*
0.7
f
+
c2
*
0.3
f
;
updateMap
();
}
break
;
case
1
:
CGoGNout
<<
"delete vertex"
<<
CGoGNendl
;
if
(
m_selected
!=
NIL
)
{
dm
.
markAll
();
myMap
.
deleteVertex
(
m_selected
);
updateMap
();
m_selected
=
NIL
;
}
break
;
case
2
:
CGoGNout
<<
"cut edge"
<<
CGoGNendl
;
if
(
m_selected
!=
NIL
)
{
dm
.
markAll
();
PFP
::
VEC3
Q
=
position
[
myMap
.
phi1
(
m_selected
)];
myMap
.
cutEdge
(
m_selected
);
position
[
myMap
.
phi1
(
m_selected
)]
=
(
position
[
m_selected
]
+
Q
)
/
2.0
f
;
updateMap
();
}
break
;
case
3
:
CGoGNout
<<
"uncut edge"
<<
CGoGNendl
;
if
(
m_selected
!=
NIL
)
{
myMap
.
uncutEdge
(
m_selected
);
updateMap
();
}
break
;
case
4
:
CGoGNout
<<
"collapse edge"
<<
CGoGNendl
;
if
(
m_selected
!=
NIL
)
{
PFP
::
VEC3
M
=
(
position
[
m_selected
]
+
position
[
myMap
.
phi1
(
m_selected
)])
/
2.0
f
;
Dart
d
=
myMap
.
collapseEdge
(
m_selected
,
true
);
position
[
d
]
=
M
;
updateMap
();
m_selected
=
NIL
;
}
break
;
case
5
:
CGoGNout
<<
"flip edge"
<<
CGoGNendl
;
if
(
m_selected
!=
NIL
)
{
myMap
.
flipEdge
(
m_selected
);
updateMap
();
}
break
;
case
6
:
CGoGNout
<<
"flip back edge"
<<
CGoGNendl
;
if
(
m_selected
!=
NIL
)
{
myMap
.
flipBackEdge
(
m_selected
);
updateMap
();
}
break
;
case
7
:
CGoGNout
<<
"split face"
<<
CGoGNendl
;
if
(
m_selected
!=
NIL
)
{
myMap
.
splitFace
(
m_selected
,
m_selected2
);
updateMap
();
}
break
;
case
8
:
CGoGNout
<<
"merge face"
<<
CGoGNendl
;
if
(
m_selected
!=
NIL
)
{
myMap
.
mergeFaces
(
m_selected
);
updateMap
();
m_selected
=
NIL
;
}
break
;
default:
break
;
}
updateGL
();
dock
.
listOper
->
setCurrentRow
(
-
1
);
}
void
MyQT
::
createMap
(
int
n
)
{
position
=
myMap
.
addAttribute
<
PFP
::
VEC3
>
(
VERTEX
,
"position"
);
colorDarts
=
myMap
.
addAttribute
<
PFP
::
VEC3
>
(
DART
,
"color"
);
Algo
::
Modelisation
::
Polyhedron
<
PFP
>
grid
(
myMap
,
position
);
grid
.
grid_topo
(
n
,
n
);
grid
.
embedGrid
(
1.
,
1.
,
0.
);
// 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
);
// send BB info to interface for centering on GL screen
setParamObject
(
lWidthObj
,
lPosObj
.
data
());
// first show for be sure that GL context is binded
show
();
// render the topo of the map without boundary darts
dm
.
markAll
();
m_render_topo
->
setDartWidth
(
5.0
f
);
m_render_topo
->
setInitialDartsColor
(
0.0
f
,
0.0
f
,
0.0
f
);
m_render_topo
->
updateData
<
PFP
>
(
myMap
,
position
,
0.9
f
,
0.9
f
,
nb
);
for
(
Dart
d
=
myMap
.
begin
();
d
!=
myMap
.
end
();
myMap
.
next
(
d
))
{
if
(
dm
.
isMarked
(
d
)
&&
(
!
myMap
.
isBoundaryMarked
(
d
)))
{
int
n
=
random
();
float
r
=
float
(
n
&
0x7f
)
/
255.0
f
+
0.25
f
;
float
g
=
float
((
n
>>
8
)
&
0x7f
)
/
255.0
f
+
0.25
f
;
float
b
=
float
((
n
>>
16
)
&
0x7f
)
/
255.0
+
0.25
f
;
colorDarts
[
d
]
=
Geom
::
Vec3f
(
r
,
g
,
b
);
m_render_topo
->
setDartColor
(
d
,
r
,
g
,
b
);
}
}
}
void
MyQT
::
updateMap
()
{
m_render_topo
->
updateData
<
PFP
>
(
myMap
,
position
,
0.9
f
,
0.9
f
,
nb
);
for
(
Dart
d
=
myMap
.
begin
();
d
!=
myMap
.
end
();
myMap
.
next
(
d
))
{
if
(
dm
.
isMarked
(
d
)
&&
(
!
myMap
.
isBoundaryMarked
(
d
)))
{
const
Geom
::
Vec3f
&
C
=
colorDarts
[
d
];
if
(
C
*
C
!=
0.0
f
)
m_render_topo
->
setDartColor
(
d
,
C
[
0
],
C
[
1
],
C
[
2
]);
}
}
}
// initialization GL callback
void
MyQT
::
cb_initGL
()
{
glClearColor
(
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
);
m_render_topo
=
new
Algo
::
Render
::
GL2
::
TopoRender
()
;
}
// redraw GL callback (clear and swap already done)
void
MyQT
::
cb_redraw
()
{
glEnable
(
GL_POLYGON_OFFSET_FILL
);
glPolygonOffset
(
1.0
f
,
1.0
f
);
m_render_topo
->
drawTopo
();
glDisable
(
GL_POLYGON_OFFSET_FILL
);
if
(
m_selected
!=
NIL
)
m_render_topo
->
overdrawDart
(
m_selected
,
11
,
1.0
f
,
0.0
f
,
0.0
f
);
if
(
m_selected2
!=
NIL
)
m_render_topo
->
overdrawDart
(
m_selected2
,
11
,
0.0
f
,
1.0
f
,
0.0
f
);
}
void
MyQT
::
cb_mousePress
(
int
button
,
int
x
,
int
y
)
{
if
(
Shift
())
{
Dart
d
=
m_render_topo
->
picking
<
PFP
>
(
myMap
,
x
,
y
,
nb
);
if
(
button
==
Qt
::
LeftButton
)
{
if
(
d
!=
Dart
::
nil
())
m_selected
=
d
;
}
if
(
button
==
Qt
::
RightButton
)
{
if
(
d
!=
Dart
::
nil
())
m_selected2
=
d
;
}
updateGL
();
}
}
void
MyQT
::
cb_keyPress
(
int
keycode
)
{
switch
(
keycode
)
{
case
'c'
:
for
(
Dart
d
=
myMap
.
begin
();
d
!=
myMap
.
end
();
myMap
.
next
(
d
))
{
if
(
!
myMap
.
isBoundaryMarked
(
d
))
{
int
n
=
random
();
float
r
=
float
(
n
&
0x7f
)
/
255.0
f
+
0.25
f
;
float
g
=
float
((
n
>>
8
)
&
0x7f
)
/
255.0
f
+
0.25
f
;
float
b
=
float
((
n
>>
16
)
&
0x7f
)
/
255.0
+
0.25
f
;
colorDarts
[
d
]
=
Geom
::
Vec3f
(
r
,
g
,
b
);
m_render_topo
->
setDartColor
(
d
,
r
,
g
,
b
);
}
}
break
;
case
'g'
:
for
(
Dart
d
=
myMap
.
begin
();
d
!=
myMap
.
end
();
myMap
.
next
(
d
))
{
if
(
!
myMap
.
isBoundaryMarked
(
d
))
{
colorDarts
[
d
]
=
Geom
::
Vec3f
(
0.5
f
,
0.5
f
,
0.5
f
);
m_render_topo
->
setDartColor
(
d
,
0.5
f
,
0.5
f
,
0.5
f
);
}
}
break
;
}
updateGL
();
}
Apps/Tuto/tuto_oper2.h
0 → 100644
View file @
1bbca422
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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: http://cgogn.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef _TUTO_OPER2_
#define _TUTO_OPER2_
//#define USE_GMAP
#include
"Topology/generic/parameters.h"
#ifdef USE_GMAP
#include
"Topology/gmap/embeddedGMap2.h"
#else
#include
"Topology/map/embeddedMap2.h"
#endif
#include
"Algo/Render/GL2/topoRender.h"
#include
"ui_tuto_oper2.h"
#include
"Utils/Qt/qtui.h"
#include
"Utils/Qt/qtSimple.h"
#include
"Utils/cgognStream.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
#ifdef USE_GMAP
typedef
EmbeddedGMap2
MAP
;
#else
typedef
EmbeddedMap2
MAP
;
#endif
};
class
MyQT
:
public
Utils
::
QT
::
SimpleQT
{
Q_OBJECT
public:
MyQT
()
:
nb
(
myMap
),
m_render_topo
(
NULL
),
m_selected
(
NIL
),
m_selected2
(
NIL
),
dm
(
myMap
)
{}
void
cb_redraw
();
void
cb_initGL
();
void
cb_mousePress
(
int
button
,
int
x
,
int
y
);
void
cb_keyPress
(
int
code
);
Utils
::
QT
::
uiDockInterface
dock
;
protected:
// declaration of the map
PFP
::
MAP
myMap
;
PFP
::
TVEC3
position
;
AttributeHandler
<
Geom
::
Vec3f
>
colorDarts
;
SelectorDartNoBoundary
<
PFP
::
MAP
>
nb
;
// render (for the topo)
Algo
::
Render
::
GL2
::
TopoRender
*
m_render_topo
;
Dart
m_selected
;
Dart
m_selected2
;
DartMarker
dm
;
// 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
);}
public:
// example of simple map creation
void
createMap
(
int
n
);
void
updateMap
();
public
slots
:
void
operation
(
int
x
);
};
#endif
Apps/Tuto/tuto_oper2.ui
0 → 100644
View file @
1bbca422
<?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>
227
</width>
<height>
369
</height>
</rect>
</property>
<property
name=
"minimumSize"
>
<size>
<width>
150
</width>
<height>
250
</height>
</size>
</property>
<property
name=
"windowTitle"
>
<string>
Interface
</string>
</property>
<widget
class=
"QWidget"
name=
"dockWidgetContents"
>
<property
name=
"enabled"
>
<bool>
true
</bool>
</property>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Preferred"
vsizetype=
"Preferred"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"minimumSize"
>
<size>
<width>
150
</width>
<height>
200
</height>
</size>
</property>
<layout
class=
"QGridLayout"
name=
"gridLayout"
>
<property
name=
"margin"
>
<number>
2
</number>
</property>
<property
name=
"spacing"
>
<number>
4
</number>
</property>
<item
row=
"0"
column=
"0"
>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout"
>
<item>
<widget
class=
"QListWidget"
name=
"listOper"
>
<property
name=
"focusPolicy"
>
<enum>
Qt::NoFocus
</enum>
</property>
<item>
<property
name=
"text"
>
<string>
splitVertex
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
deleteVertex
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
cutEdge
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
uncutEdge
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
collapseEdge
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
flipEdge
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
flipBackEdge
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
splitFace
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
mergeFace
</string>
</property>
</item>
</widget>
</item>
<item>
<spacer
name=
"verticalSpacer"
>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
20
</width>
<height>
40
</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>
include/Algo/Render/GL2/topo3Render.h
View file @
1bbca422
...
...
@@ -33,6 +33,7 @@
#include
"Topology/generic/dart.h"
#include
"Topology/generic/attributeHandler.h"
#include
"Topology/generic/functor.h"
#include
"Geometry/vector_gen.h"
#include
"Utils/vbo.h"
...
...
@@ -102,9 +103,19 @@ protected:
*/
float
m_topo_relation_width
;
/**
* pointer for saved colorvbo (in picking)
*/
float
*
m_color_save
;
/**
* initial darts color (set in update)
*/
Geom
::
Vec3f
m_dartsColor
;
/**
* attribute index to get easy correspdance dart/color
*/
AttributeHandler
<
unsigned
int
>
m_attIndex
;
...
...
@@ -204,6 +215,15 @@ public:
*/
void
setAllDartsColor
(
float
r
,
float
g
,
float
b
);
/**
* change dart initial color (used when calling updateData)
* @param d the dart
* @param r red !
* @param g green !
* @param b blue !
*/
void
setInitialDartsColor
(
float
r
,
float
g
,
float
b
);
/**
* overdraw a dart with given width and color
* @param d the dart
...
...
include/Algo/Render/GL2/topo3Render.hpp
View file @
1bbca422
...
...
@@ -167,8 +167,8 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
*
positionDartBuf
++
=
P
;
*
positionDartBuf
++
=
Q
;
*
colorDartBuf
++
=
VEC3
(
1.
,
1.
,
1.0
)
;
*
colorDartBuf
++
=
VEC3
(
1.
,
1.
,
1.0
)
;
*
colorDartBuf
++
=
m_dartsColor
;
*
colorDartBuf
++
=
m_dartsColor
;
fv1
[
d
]
=
P
*
0.1
f
+
Q
*
0.9
f
;
fv11
[
d
]
=
P
*
0.9
f
+
Q
*
0.1
f
;
...
...
@@ -417,10 +417,10 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T
*
positionDartBuf
++
=
PP
;
*
positionDartBuf
++
=
Q
;
*
positionDartBuf
++
=
QQ
;
*
colorDartBuf
++
=
VEC3
(
1.
,
1.
,
1.
)
;
*
colorDartBuf
++
=
VEC3
(
1.
,
1.
,
1.
)
;
*
colorDartBuf
++
=
VEC3
(
1.
,
1.
,
1.
)
;
*
colorDartBuf
++
=
VEC3
(
1.
,
1.
,
1.
)
;
*
colorDartBuf
++
=
m_dartsColor
;
*
colorDartBuf
++
=
m_dartsColor
;
*
colorDartBuf
++
=
m_dartsColor
;
*
colorDartBuf
++
=
m_dartsColor
;
m_attIndex
[
d
]
=
posDBI
;
posDBI
+=
2
;
...
...
include/Algo/Render/GL2/topoRender.h
View file @
1bbca422
...
...
@@ -33,6 +33,7 @@
#include
"Topology/generic/dart.h"
#include
"Topology/generic/attributeHandler.h"
#include
"Topology/generic/functor.h"
#include
"Geometry/vector_gen.h"
#include
"Utils/vbo.h"
...
...
@@ -88,6 +89,11 @@ protected:
*/
float
m_topo_relation_width
;