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
Etienne Schmitt
CGoGN
Commits
3346213e
Commit
3346213e
authored
Feb 25, 2011
by
Pierre Kraemer
Browse files
sqrt3 subdivision OK
parent
6346fca0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Apps/Examples/Release/CMakeLists.txt
View file @
3346213e
...
...
@@ -17,7 +17,6 @@ include_directories(
${
CGoGN_ROOT_DIR
}
/ThirdParty/OpenCTM
${
CGoGN_ROOT_DIR
}
/ThirdParty/Assimp/include
${
CGoGN_ROOT_DIR
}
/ThirdParty/glm
)
# define libs path
...
...
Apps/Examples/miniTest.cpp
View file @
3346213e
...
...
@@ -432,61 +432,102 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
{
case
'l'
:
{
GLint
t1
=
glutGet
(
GLUT_ELAPSED_TIME
);
Algo
::
Modelisation
::
LoopSubdivision
<
PFP
>
(
myMap
,
position
);
GLint
t2
=
glutGet
(
GLUT_ELAPSED_TIME
);
GLfloat
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"loop: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
GLint
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
Algo
::
Modelisation
::
LoopSubdivision
<
PFP
>
(
myMap
,
position
)
;
GLint
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
GLfloat
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"loop: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
t1
=
glutGet
(
GLUT_ELAPSED_TIME
);
updateVBOprimitives
(
Algo
::
Render
::
VBO
::
TRIANGLES
|
Algo
::
Render
::
VBO
::
LINES
|
Algo
::
Render
::
VBO
::
POINTS
)
;
updateVBOdata
(
Algo
::
Render
::
VBO
::
POSITIONS
|
Algo
::
Render
::
VBO
::
NORMALS
)
;
topo_render
->
updateData
<
PFP
>
(
myMap
,
position
,
0.9
f
,
0.9
f
)
;
t2
=
glutGet
(
GLUT_ELAPSED_TIME
);
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"display update: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
glutPostRedisplay
()
;
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"display update: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
glutPostRedisplay
()
;
break
;
}
case
'c'
:
{
GLint
t1
=
glutGet
(
GLUT_ELAPSED_TIME
);
Algo
::
Modelisation
::
CatmullClarkSubdivision
<
PFP
>
(
myMap
,
position
);
GLint
t2
=
glutGet
(
GLUT_ELAPSED_TIME
);
GLfloat
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"catmull-clark: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
GLint
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
Algo
::
Modelisation
::
CatmullClarkSubdivision
<
PFP
>
(
myMap
,
position
)
;
GLint
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
GLfloat
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"catmull-clark: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
t1
=
glutGet
(
GLUT_ELAPSED_TIME
);
updateVBOprimitives
(
Algo
::
Render
::
VBO
::
TRIANGLES
|
Algo
::
Render
::
VBO
::
LINES
|
Algo
::
Render
::
VBO
::
POINTS
)
;
updateVBOdata
(
Algo
::
Render
::
VBO
::
POSITIONS
|
Algo
::
Render
::
VBO
::
NORMALS
)
;
topo_render
->
updateData
<
PFP
>
(
myMap
,
position
,
0.9
f
,
0.9
f
)
;
t2
=
glutGet
(
GLUT_ELAPSED_TIME
);
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"display update: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"display update: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
glutPostRedisplay
()
;
break
;
}
case
'3'
:
{
GLint
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
Algo
::
Modelisation
::
Sqrt3Subdivision
<
PFP
>
(
myMap
,
position
)
;
GLint
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
GLfloat
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"sqrt3: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
normal
=
myMap
.
getAttribute
<
PFP
::
VEC3
>
(
VERTEX_ORBIT
,
"normal"
)
;
if
(
!
normal
.
isValid
())
normal
=
myMap
.
addAttribute
<
PFP
::
VEC3
>
(
VERTEX_ORBIT
,
"normal"
)
;
laplacian
=
myMap
.
getAttribute
<
PFP
::
VEC3
>
(
VERTEX_ORBIT
,
"laplacian"
)
;
if
(
!
laplacian
.
isValid
())
laplacian
=
myMap
.
addAttribute
<
PFP
::
VEC3
>
(
VERTEX_ORBIT
,
"laplacian"
)
;
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
updateVBOprimitives
(
Algo
::
Render
::
VBO
::
TRIANGLES
|
Algo
::
Render
::
VBO
::
LINES
|
Algo
::
Render
::
VBO
::
POINTS
)
;
updateVBOdata
(
Algo
::
Render
::
VBO
::
POSITIONS
|
Algo
::
Render
::
VBO
::
NORMALS
)
;
topo_render
->
updateData
<
PFP
>
(
myMap
,
position
,
0.9
f
,
0.9
f
)
;
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"display update: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
glutPostRedisplay
()
;
break
;
}
case
't'
:
{
GLint
t1
=
glutGet
(
GLUT_ELAPSED_TIME
);
GLint
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
Algo
::
Modelisation
::
trianguleFaces
<
PFP
>
(
myMap
,
position
)
;
GLint
t2
=
glutGet
(
GLUT_ELAPSED_TIME
);
GLfloat
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"triangulation: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
t1
=
glutGet
(
GLUT_ELAPSED_TIME
);
GLint
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
GLfloat
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"triangulation: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
updateVBOprimitives
(
Algo
::
Render
::
VBO
::
TRIANGLES
|
Algo
::
Render
::
VBO
::
LINES
|
Algo
::
Render
::
VBO
::
POINTS
)
;
updateVBOdata
(
Algo
::
Render
::
VBO
::
POSITIONS
|
Algo
::
Render
::
VBO
::
NORMALS
)
;
topo_render
->
updateData
<
PFP
>
(
myMap
,
position
,
0.9
f
,
0.9
f
)
;
t2
=
glutGet
(
GLUT_ELAPSED_TIME
);
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"display update: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"display update: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
glutPostRedisplay
()
;
break
;
...
...
@@ -494,19 +535,23 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
case
'q'
:
{
GLint
t1
=
glutGet
(
GLUT_ELAPSED_TIME
);
GLint
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
Algo
::
Modelisation
::
quadranguleFaces
<
PFP
>
(
myMap
,
position
)
;
GLint
t2
=
glutGet
(
GLUT_ELAPSED_TIME
);
GLfloat
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"quadrangulation: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
t1
=
glutGet
(
GLUT_ELAPSED_TIME
);
GLint
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
GLfloat
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"quadrangulation: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
updateVBOprimitives
(
Algo
::
Render
::
VBO
::
TRIANGLES
|
Algo
::
Render
::
VBO
::
LINES
|
Algo
::
Render
::
VBO
::
POINTS
)
;
updateVBOdata
(
Algo
::
Render
::
VBO
::
POSITIONS
|
Algo
::
Render
::
VBO
::
NORMALS
)
;
topo_render
->
updateData
<
PFP
>
(
myMap
,
position
,
0.9
f
,
0.9
f
)
;
t2
=
glutGet
(
GLUT_ELAPSED_TIME
);
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"display update: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"display update: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
glutPostRedisplay
()
;
break
;
...
...
@@ -516,19 +561,23 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
{
unsigned
int
nbVertices
=
myMap
.
getNbOrbits
(
VERTEX_ORBIT
)
;
GLint
t1
=
glutGet
(
GLUT_ELAPSED_TIME
);
GLint
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
Algo
::
Decimation
::
decimate
<
PFP
>
(
myMap
,
Algo
::
Decimation
::
S_QEM
,
Algo
::
Decimation
::
A_QEM
,
position
,
nbVertices
*
0.75
)
;
GLint
t2
=
glutGet
(
GLUT_ELAPSED_TIME
);
GLfloat
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"decimation: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
t1
=
glutGet
(
GLUT_ELAPSED_TIME
);
GLint
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
GLfloat
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"decimation: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
updateVBOprimitives
(
Algo
::
Render
::
VBO
::
TRIANGLES
|
Algo
::
Render
::
VBO
::
LINES
|
Algo
::
Render
::
VBO
::
POINTS
)
;
updateVBOdata
(
Algo
::
Render
::
VBO
::
POSITIONS
|
Algo
::
Render
::
VBO
::
NORMALS
)
;
topo_render
->
updateData
<
PFP
>
(
myMap
,
position
,
0.9
f
,
0.9
f
)
;
t2
=
glutGet
(
GLUT_ELAPSED_TIME
);
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"display update: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"display update: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
glutPostRedisplay
()
;
break
;
...
...
@@ -541,13 +590,13 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
positionF
=
myMap
.
addAttribute
<
PFP
::
VEC3
>
(
FACE_ORBIT
,
"position"
)
;
Algo
::
Geometry
::
computeCentroidFaces
<
PFP
>
(
myMap
,
position
,
positionF
)
;
GLint
t1
=
glutGet
(
GLUT_ELAPSED_TIME
);
GLint
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
Algo
::
Modelisation
::
computeDual
<
PFP
>
(
myMap
)
;
GLint
t2
=
glutGet
(
GLUT_ELAPSED_TIME
);
GLfloat
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"dual computation: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
GLint
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
GLfloat
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"dual computation: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
position
=
myMap
.
getAttribute
<
PFP
::
VEC3
>
(
VERTEX_ORBIT
,
"position"
)
;
...
...
@@ -558,19 +607,21 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
if
(
!
laplacian
.
isValid
())
laplacian
=
myMap
.
addAttribute
<
PFP
::
VEC3
>
(
VERTEX_ORBIT
,
"laplacian"
)
;
t1
=
glutGet
(
GLUT_ELAPSED_TIME
);
t1
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
updateVBOprimitives
(
Algo
::
Render
::
VBO
::
TRIANGLES
|
Algo
::
Render
::
VBO
::
LINES
|
Algo
::
Render
::
VBO
::
POINTS
)
;
updateVBOdata
(
Algo
::
Render
::
VBO
::
POSITIONS
|
Algo
::
Render
::
VBO
::
NORMALS
)
;
topo_render
->
updateData
<
PFP
>
(
myMap
,
position
,
0.9
f
,
0.9
f
)
;
t2
=
glutGet
(
GLUT_ELAPSED_TIME
);
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"display update: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
t2
=
glutGet
(
GLUT_ELAPSED_TIME
)
;
seconds
=
(
t2
-
t1
)
/
1000.0
f
;
std
::
cout
<<
"display update: "
<<
seconds
<<
"sec"
<<
std
::
endl
;
glutPostRedisplay
()
;
break
;
}
case
'
3
'
:
case
'
9
'
:
{
CellMarker
markVisit
(
myMap
,
VERTEX_CELL
)
;
...
...
@@ -624,6 +675,7 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
updateVBOprimitives
(
Algo
::
Render
::
VBO
::
TRIANGLES
|
Algo
::
Render
::
VBO
::
LINES
|
Algo
::
Render
::
VBO
::
POINTS
)
;
updateVBOdata
(
Algo
::
Render
::
VBO
::
POSITIONS
|
Algo
::
Render
::
VBO
::
NORMALS
)
;
topo_render
->
updateData
<
PFP
>
(
myMap
,
position
,
0.9
f
,
0.9
f
)
;
glutPostRedisplay
()
;
break
;
}
...
...
include/Algo/Modelisation/subdivision.h
View file @
3346213e
...
...
@@ -54,6 +54,16 @@ void trianguleFaces(typename PFP::MAP& map, EMBV& attributs, const FunctorSelect
template
<
typename
PFP
>
void
trianguleFaces
(
typename
PFP
::
MAP
&
map
,
typename
PFP
::
TVEC3
&
position
,
const
FunctorSelect
&
selected
=
SelectorTrue
())
;
/**
* Triangule all the faces of the mesh
* positions for new vertices are given as face attribute
*/
template
<
typename
PFP
>
void
trianguleFaces
(
typename
PFP
::
MAP
&
map
,
typename
PFP
::
TVEC3
&
position
,
typename
PFP
::
TVEC3
&
positionF
,
const
FunctorSelect
&
selected
=
SelectorTrue
())
;
/**
* Quadrangule a face with central vertex
* warning: edges are considered here as already cut !!
...
...
include/Algo/Modelisation/subdivision.hpp
View file @
3346213e
...
...
@@ -84,6 +84,33 @@ void trianguleFaces(typename PFP::MAP& map, typename PFP::TVEC3& position, const
trianguleFaces
<
PFP
,
typename
PFP
::
TVEC3
,
typename
PFP
::
VEC3
>
(
map
,
position
,
selected
)
;
}
template
<
typename
PFP
>
void
trianguleFaces
(
typename
PFP
::
MAP
&
map
,
typename
PFP
::
TVEC3
&
position
,
typename
PFP
::
TVEC3
&
positionF
,
const
FunctorSelect
&
selected
)
{
assert
(
position
.
getOrbit
()
==
VERTEX_ORBIT
)
;
assert
(
positionF
.
getOrbit
()
==
FACE_ORBIT
)
;
DartMarker
m
(
map
)
;
for
(
Dart
d
=
map
.
begin
();
d
!=
map
.
end
();
map
.
next
(
d
))
{
if
(
selected
(
d
)
&&
!
m
.
isMarked
(
d
))
{
typename
PFP
::
VEC3
p
=
positionF
[
d
]
;
Dart
cd
=
trianguleFace
<
PFP
>
(
map
,
d
)
;
// triangule the face
position
[
cd
]
=
p
;
// affect the data to the central vertex
Dart
fit
=
cd
;
do
{
m
.
markOrbit
(
FACE_ORBIT
,
fit
);
fit
=
map
.
alpha1
(
fit
);
}
while
(
fit
!=
cd
);
}
}
}
template
<
typename
PFP
>
Dart
quadranguleFace
(
typename
PFP
::
MAP
&
map
,
Dart
d
)
{
...
...
@@ -478,11 +505,73 @@ void computeDual(typename PFP::MAP& map, const FunctorSelect& selected)
reverseOrientation
<
PFP
>
(
map
)
;
}
inline
double
sqrt3_K
(
unsigned
int
n
)
{
switch
(
n
)
{
case
1
:
return
0.333333
;
case
2
:
return
0.555556
;
case
3
:
return
0.5
;
case
4
:
return
0.444444
;
case
5
:
return
0.410109
;
case
6
:
return
0.388889
;
case
7
:
return
0.375168
;
case
8
:
return
0.365877
;
case
9
:
return
0.359328
;
case
10
:
return
0.354554
;
case
11
:
return
0.350972
;
case
12
:
return
0.348219
;
default:
double
t
=
cos
((
2.0
*
M_PI
)
/
double
(
n
))
;
return
(
4.0
-
t
)
/
9.0
;
}
}
template
<
typename
PFP
>
void
Sqrt3Subdivision
(
typename
PFP
::
MAP
&
map
,
typename
PFP
::
TVEC3
&
position
,
const
FunctorSelect
&
selected
)
{
typedef
typename
PFP
::
VEC3
VEC3
;
typedef
typename
PFP
::
REAL
REAL
;
AttributeHandler
<
VEC3
>
positionF
=
map
.
template
getAttribute
<
VEC3
>(
FACE_ORBIT
,
"position"
)
;
if
(
!
positionF
.
isValid
())
positionF
=
map
.
template
addAttribute
<
VEC3
>(
FACE_ORBIT
,
"position"
)
;
Algo
::
Geometry
::
computeCentroidFaces
<
PFP
>
(
map
,
position
,
positionF
)
;
computeDual
<
PFP
>
(
map
,
selected
);
trianguleFaces
<
PFP
>
(
map
,
position
,
selected
);
AttributeHandler
<
VEC3
>
tmp
=
position
;
position
=
positionF
;
positionF
=
tmp
;
CellMarker
m
(
map
,
VERTEX_ORBIT
)
;
m
.
markAll
()
;
trianguleFaces
<
PFP
>
(
map
,
position
,
positionF
,
selected
);
for
(
Dart
d
=
map
.
begin
();
d
!=
map
.
end
();
map
.
next
(
d
))
{
if
(
!
m
.
isMarked
(
d
))
{
m
.
mark
(
d
)
;
VEC3
P
=
position
[
d
]
;
VEC3
newP
(
0
)
;
unsigned
int
val
=
0
;
Dart
vit
=
d
;
do
{
newP
+=
position
[
map
.
phi2
(
vit
)]
;
++
val
;
vit
=
map
.
alpha1
(
vit
)
;
}
while
(
vit
!=
d
)
;
REAL
K
=
sqrt3_K
(
val
)
;
newP
*=
REAL
(
3
)
;
newP
-=
REAL
(
val
)
*
P
;
newP
*=
K
/
REAL
(
2
*
val
)
;
newP
+=
(
REAL
(
1
)
-
K
)
*
P
;
position
[
d
]
=
newP
;
}
}
}
template
<
typename
PFP
,
typename
EMBV
,
typename
EMB
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment