Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
Unterteilungsalgorithmen
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kai Westerkamp
Unterteilungsalgorithmen
Commits
9349f665
Commit
9349f665
authored
Sep 27, 2016
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '14-benutze-neighbors-map-in-precomputevertextable' into 'patchRender'
Resolve "Benutze neighbors map in precomputeVertexTable" Closes
#14
See merge request
!11
parents
25fccdc3
6883649b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
172 additions
and
97 deletions
+172
-97
mesh.cpp
QTProject/mesh.cpp
+21
-4
mesh.h
QTProject/mesh.h
+5
-2
subdivision.cpp
QTProject/subdivision.cpp
+140
-89
subdivision.h
QTProject/subdivision.h
+6
-2
No files found.
QTProject/mesh.cpp
View file @
9349f665
...
@@ -40,22 +40,24 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Verti
...
@@ -40,22 +40,24 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Verti
f
->
glBufferData
(
GL_ARRAY_BUFFER
,
sizeof
(
Vertex
)
*
Vertices
.
size
(),
&
Vertices
[
0
],
GL_STATIC_DRAW
);
f
->
glBufferData
(
GL_ARRAY_BUFFER
,
sizeof
(
Vertex
)
*
Vertices
.
size
(),
&
Vertices
[
0
],
GL_STATIC_DRAW
);
QVector
<
unsigned
int
>
patches
;
QVector
<
unsigned
int
>
patches
;
this
->
init
(
f
,
VB_handle
,
Vertices
,
Vertices
,
Indices_irregular
,
patches
);
this
->
init
(
f
,
VB_handle
,
Vertices
,
Vertices
,
Indices_irregular
,
patches
,
patches
);
}
}
void
Mesh
::
SubdivEntry
::
init
(
QOpenGLFunctions_4_3_Core
*
f
,
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
Vertex
>&
Vertices_irregular
,
void
Mesh
::
SubdivEntry
::
init
(
QOpenGLFunctions_4_3_Core
*
f
,
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
Vertex
>&
Vertices_irregular
,
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
){
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
,
QVector
<
unsigned
int
>&
Indices_extra
){
this
->
f
=
f
;
this
->
f
=
f
;
this
->
VB_handle
=
VB_handle
;
this
->
VB_handle
=
VB_handle
;
vertices
=
Vertices
;
vertices
=
Vertices
;
indices_irregular
=
Indices_irregular
;
indices_irregular
=
Indices_irregular
;
indices_regular
=
patches
;
indices_regular
=
patches
;
indices_extra
=
Indices_extra
;
qCDebug
(
log_mesh
)
<<
"Vertices"
<<
vertices
.
length
();
qCDebug
(
log_mesh
)
<<
"Vertices"
<<
vertices
.
length
();
qCDebug
(
log_mesh
)
<<
"Vertices Irregular"
<<
Vertices_irregular
.
length
();
qCDebug
(
log_mesh
)
<<
"Vertices Irregular"
<<
Vertices_irregular
.
length
();
qCDebug
(
log_mesh
)
<<
"Indices irregular"
<<
indices_irregular
.
length
();
qCDebug
(
log_mesh
)
<<
"Indices irregular"
<<
indices_irregular
.
length
();
qCDebug
(
log_mesh
)
<<
"Indices patches"
<<
patches
.
length
();
qCDebug
(
log_mesh
)
<<
"Indices patches"
<<
patches
.
length
();
qCDebug
(
log_mesh
)
<<
"Indices extra"
<<
Indices_extra
.
length
();
f
->
glGenBuffers
(
1
,
&
VB_handle_irregular
);
f
->
glGenBuffers
(
1
,
&
VB_handle_irregular
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
VB_handle_irregular
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
VB_handle_irregular
);
...
@@ -71,6 +73,11 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVe
...
@@ -71,6 +73,11 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVe
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
IB_regular_handle
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
IB_regular_handle
);
if
(
patches
.
size
()
!=
0
)
if
(
patches
.
size
()
!=
0
)
f
->
glBufferData
(
GL_ELEMENT_ARRAY_BUFFER
,
sizeof
(
unsigned
int
)
*
patches
.
size
(),
&
patches
[
0
],
GL_STATIC_DRAW
);
f
->
glBufferData
(
GL_ELEMENT_ARRAY_BUFFER
,
sizeof
(
unsigned
int
)
*
patches
.
size
(),
&
patches
[
0
],
GL_STATIC_DRAW
);
f
->
glGenBuffers
(
1
,
&
IB_extra_handle
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
IB_extra_handle
);
if
(
Indices_extra
.
size
()
!=
0
)
f
->
glBufferData
(
GL_ELEMENT_ARRAY_BUFFER
,
sizeof
(
unsigned
int
)
*
Indices_extra
.
size
(),
&
Indices_extra
[
0
],
GL_STATIC_DRAW
);
}
}
...
@@ -103,10 +110,10 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
...
@@ -103,10 +110,10 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
}
}
}
}
void
Mesh
::
MeshEntry
::
update
(
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
Vertex
>&
Vertices_Irregular
,
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
)
{
void
Mesh
::
MeshEntry
::
update
(
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
Vertex
>&
Vertices_Irregular
,
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
,
QVector
<
unsigned
int
>&
Indices_extra
)
{
SubdivEntry
*
entry
=
new
SubdivEntry
;
SubdivEntry
*
entry
=
new
SubdivEntry
;
buffers
.
push_back
(
std
::
shared_ptr
<
SubdivEntry
>
(
entry
));
buffers
.
push_back
(
std
::
shared_ptr
<
SubdivEntry
>
(
entry
));
entry
->
init
(
f
,
VB_handle
,
Vertices
,
Vertices_Irregular
,
Indices_irregular
,
patches
);
entry
->
init
(
f
,
VB_handle
,
Vertices
,
Vertices_Irregular
,
Indices_irregular
,
patches
,
Indices_extra
);
}
}
Mesh
::
MeshEntry
::~
MeshEntry
()
Mesh
::
MeshEntry
::~
MeshEntry
()
...
@@ -495,6 +502,16 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
...
@@ -495,6 +502,16 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
f
->
glPatchParameteri
(
GL_PATCH_VERTICES
,
3
);
f
->
glPatchParameteri
(
GL_PATCH_VERTICES
,
3
);
f
->
glDrawElements
(
GL_PATCHES
,
entry
->
indices_irregular
.
size
(),
GL_UNSIGNED_INT
,
0
);
f
->
glDrawElements
(
GL_PATCHES
,
entry
->
indices_irregular
.
size
(),
GL_UNSIGNED_INT
,
0
);
}
}
if
(
!
entry
->
indices_extra
.
isEmpty
()
&&
false
)
{
shader
->
setUniformValue
(
"materialInfo.Diffuse"
,
QVector3D
(
0.0
,
156.0
,
18.0
)
/
255.0
);
f
->
glBindBuffer
(
GL_ARRAY_BUFFER
,
entry
->
VB_handle
);
f
->
glVertexAttribPointer
(
positionIndex
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
0
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
entry
->
IB_extra_handle
);
f
->
glPatchParameteri
(
GL_PATCH_VERTICES
,
3
);
f
->
glDrawElements
(
GL_PATCHES
,
entry
->
indices_extra
.
size
(),
GL_UNSIGNED_INT
,
0
);
}
}
}
}
}
...
...
QTProject/mesh.h
View file @
9349f665
...
@@ -34,20 +34,23 @@ public:
...
@@ -34,20 +34,23 @@ public:
GLuint
VB_handle
;
GLuint
VB_handle
;
GLuint
VB_handle_irregular
;
GLuint
VB_handle_irregular
;
GLuint
IB_irregular_handle
;
GLuint
IB_irregular_handle
;
GLuint
IB_regular_handle
;
GLuint
IB_regular_handle
;
GLuint
IB_extra_handle
;
QVector
<
Vertex
>
vertices
;
QVector
<
Vertex
>
vertices
;
QVector
<
Vertex
>
vertices_irregular
;
QVector
<
Vertex
>
vertices_irregular
;
QVector
<
unsigned
int
>
indices_irregular
;
QVector
<
unsigned
int
>
indices_irregular
;
QVector
<
unsigned
int
>
indices_regular
;
QVector
<
unsigned
int
>
indices_regular
;
QVector
<
unsigned
int
>
indices_extra
;
QOpenGLFunctions_4_3_Core
*
f
;
QOpenGLFunctions_4_3_Core
*
f
;
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
QVector
<
Vertex
>&
Vertices
,
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
unsigned
int
>&
Indices_irregular
);
QVector
<
unsigned
int
>&
Indices_irregular
);
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
Vertex
>&
Vertices_irregular
,
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
Vertex
>&
Vertices_irregular
,
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
);
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
,
QVector
<
unsigned
int
>&
Indices_extra
);
void
updateIndices
();
void
updateIndices
();
};
};
...
@@ -56,7 +59,7 @@ public:
...
@@ -56,7 +59,7 @@ public:
~
MeshEntry
();
~
MeshEntry
();
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
unsigned
int
>&
Indices
);
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
unsigned
int
>&
Indices
);
void
update
(
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
Vertex
>&
Vertices_Irregular
,
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
);
void
update
(
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
Vertex
>&
Vertices_Irregular
,
QVector
<
unsigned
int
>&
Indices_irregular
,
QVector
<
unsigned
int
>&
patches
,
QVector
<
unsigned
int
>&
Indices_extra
);
QString
name
;
QString
name
;
...
...
QTProject/subdivision.cpp
View file @
9349f665
...
@@ -17,9 +17,9 @@ Subdivision::~Subdivision()
...
@@ -17,9 +17,9 @@ Subdivision::~Subdivision()
}
}
QString
Subdivision
::
formatTimeMeasurement
(
int
time
){
QString
Subdivision
::
formatTimeMeasurement
(
int
time
){
return
QString
(
"%1m %2s %3ms"
).
arg
(
time
/
60000
,
2
,
10
,
QChar
(
'0'
))
return
QString
(
"%1m %2s %3ms"
).
arg
(
time
/
60000
,
2
,
10
,
QChar
(
'0'
))
.
arg
((
time
%
60000
)
/
1000
,
2
,
10
,
QChar
(
'0'
))
.
arg
((
time
%
60000
)
/
1000
,
2
,
10
,
QChar
(
'0'
))
.
arg
((
time
%
1000
)
,
3
,
10
,
QChar
(
'0'
));
.
arg
((
time
%
1000
)
,
3
,
10
,
QChar
(
'0'
));
}
}
void
Subdivision
::
init
()
{
void
Subdivision
::
init
()
{
...
@@ -72,9 +72,9 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
...
@@ -72,9 +72,9 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
Input
input
;
Input
input
;
int
currentMax
=
current_mesh
->
buffers
.
size
()
-
1
;
int
currentMax
=
current_mesh
->
buffers
.
size
()
-
1
;
//qCDebug(log_subdiv) << "Subdiv Level" << level << "Requested. Current Max:" << currentMax;
if
(
level
<=
currentMax
)
if
(
level
<=
currentMax
)
return
;
return
;
qCDebug
(
log_subdiv
)
<<
"========== Caluculating Subdiv Level"
<<
level
<<
"=========="
;
std
::
shared_ptr
<
Mesh
::
SubdivEntry
>
entry
=
current_mesh
->
buffers
[
currentMax
];
std
::
shared_ptr
<
Mesh
::
SubdivEntry
>
entry
=
current_mesh
->
buffers
[
currentMax
];
...
@@ -119,7 +119,7 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
...
@@ -119,7 +119,7 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
getPatchIndexBuffer
(
regular
,
neighbors
,
patches
);
getPatchIndexBuffer
(
regular
,
neighbors
,
patches
);
qCDebug
(
log_subdiv
)
<<
"patches"
<<
patches
.
length
();
qCDebug
(
log_subdiv
)
<<
"patches"
<<
patches
.
length
();
current_mesh
->
update
(
result
.
vb_handle
,
result
.
vertex_buffer
,
result
.
vertex_buffer_irregular
,
irregular_ib
,
patches
);
current_mesh
->
update
(
result
.
vb_handle
,
result
.
vertex_buffer
,
result
.
vertex_buffer_irregular
,
irregular_ib
,
patches
,
tables
.
extra_triangles
);
qCDebug
(
log_timing
)
<<
"subdivide done:"
<<
formatTimeMeasurement
(
timer
.
elapsed
());
qCDebug
(
log_timing
)
<<
"subdivide done:"
<<
formatTimeMeasurement
(
timer
.
elapsed
());
}
}
...
@@ -177,13 +177,15 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
...
@@ -177,13 +177,15 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
QVector
<
Triangle
>
all_triangles
=
triangles
+
triangles_regular
;
QVector
<
Triangle
>
all_triangles
=
triangles
+
triangles_regular
;
buildNeighborsMap
(
vb
,
all_triangles
,
neighbors
);
buildNeighborsMap
(
vb
,
all_triangles
,
neighbors
);
QVector
<
Triangle
>
extra_old_triangles
;
subTimer
.
restart
();
subTimer
.
restart
();
precomputeEdgeTable
(
tables
,
triangles
,
neighbors
,
(
unsigned
int
)
vb
.
length
());
precomputeEdgeTable
(
tables
,
triangles
,
neighbors
,
(
unsigned
int
)
vb
.
length
()
,
extra_old_triangles
);
qCDebug
(
log_timing
)
<<
"precomputeEdgeTable:"
<<
formatTimeMeasurement
(
subTimer
.
elapsed
());
qCDebug
(
log_timing
)
<<
"precomputeEdgeTable:"
<<
formatTimeMeasurement
(
subTimer
.
elapsed
());
QVector
<
Triangle
>
irregular_and_extra_triangles
=
triangles
+
extra_old_triangles
;
QMap
<
unsigned
int
,
unsigned
int
>
modified_vertices
;
QMap
<
unsigned
int
,
unsigned
int
>
modified_vertices
;
subTimer
.
restart
();
subTimer
.
restart
();
precomputeVertexTable
(
tables
,
input
,
modified_vertices
);
precomputeVertexTable
(
tables
,
vb
,
irregular_and_extra_triangles
,
neighbors
,
modified_vertices
);
qCDebug
(
log_timing
)
<<
"precomputeVertexTable:"
<<
formatTimeMeasurement
(
subTimer
.
elapsed
());
qCDebug
(
log_timing
)
<<
"precomputeVertexTable:"
<<
formatTimeMeasurement
(
subTimer
.
elapsed
());
subTimer
.
restart
();
subTimer
.
restart
();
...
@@ -380,15 +382,22 @@ void Subdivision::buildNeighborsMap(QVector<Vertex> &vb, QVector<Triangle> &tria
...
@@ -380,15 +382,22 @@ void Subdivision::buildNeighborsMap(QVector<Vertex> &vb, QVector<Triangle> &tria
QVector
<
Triangle
>
Subdivision
::
vertexNeighbors
(
Triangle
&
triangle
,
Triangle
::
Neighbor
current_neighbor
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
)
{
QVector
<
Triangle
>
Subdivision
::
vertexNeighbors
(
Triangle
&
triangle
,
Triangle
::
Neighbor
current_neighbor
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
)
{
QVector
<
Triangle
>
ns
;
QVector
<
Triangle
>
ns
;
do
{
do
{
assert
(
current_neighbor
.
triangle
!=
NULL
);
if
(
current_neighbor
.
triangle
==
NULL
){
ns
.
clear
();
return
ns
;
}
ns
.
push_back
(
*
current_neighbor
.
triangle
);
ns
.
push_back
(
*
current_neighbor
.
triangle
);
current_neighbor
=
neighbors
.
value
(
*
current_neighbor
.
triangle
).
get_neighbor
(
rotate_edge_name
(
current_neighbor
.
edge
.
name
));
current_neighbor
=
neighbors
.
value
(
*
current_neighbor
.
triangle
).
get_neighbor
(
rotate_edge_name
(
current_neighbor
.
edge
.
name
));
if
(
current_neighbor
.
triangle
==
NULL
){
ns
.
clear
();
return
ns
;
}
}
while
(
*
current_neighbor
.
triangle
!=
triangle
);
}
while
(
*
current_neighbor
.
triangle
!=
triangle
);
assert
(
current_neighbor
.
triangle
!=
NULL
);
assert
(
current_neighbor
.
triangle
!=
NULL
);
return
ns
;
return
ns
;
}
}
void
Subdivision
::
precomputeEdgeTable
(
Subdivision
::
Tables
&
tables
,
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
unsigned
int
offset
)
{
void
Subdivision
::
precomputeEdgeTable
(
Subdivision
::
Tables
&
tables
,
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
unsigned
int
offset
,
QVector
<
Triangle
>
extra_old_triangles
)
{
//compute edge table
//compute edge table
//Format: first two entries: edge vertices. last two entries: distant vertices.
//Format: first two entries: edge vertices. last two entries: distant vertices.
...
@@ -507,6 +516,7 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
...
@@ -507,6 +516,7 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
while
(
extra_it
.
hasNext
())
{
while
(
extra_it
.
hasNext
())
{
extra_it
.
next
();
extra_it
.
next
();
Triangle
triangle
=
extra_it
.
key
();
Triangle
triangle
=
extra_it
.
key
();
extra_old_triangles
.
push_back
(
triangle
);
int
uv
=
-
1
;
int
uv
=
-
1
;
int
vw
=
-
1
;
int
vw
=
-
1
;
int
wu
=
-
1
;
int
wu
=
-
1
;
...
@@ -603,81 +613,101 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
...
@@ -603,81 +613,101 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
}
}
}
}
void
Subdivision
::
precomputeVertexTable
(
Subdivision
::
Tables
&
tables
,
Input
&
input
,
QMap
<
unsigned
int
,
unsigned
int
>
&
modified_vertices
)
{
void
Subdivision
::
precomputeVertexTable
(
Tables
&
tables
,
QVector
<
Vertex
>
&
vb
,
QVector
<
Triangle
>
&
irregular_triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
,
QMap
<
unsigned
int
,
unsigned
int
>
&
modified_vertices
)
{
//compute vertex table
QTime
timer
;
//Format: First entry: original vertex. Other entries: adjacent vertices.
timer
.
start
();
QVector
<
QVector
<
unsigned
int
>
>
duplicates
;
//for debugging
qCDebug
(
log_timing
)
<<
"precomputeVertexTable started"
;
QVector
<
unsigned
int
>
ib_combined
=
input
.
index_irregular_buffer
+
input
.
index_regular_buffer
;
unsigned
int
offset
=
0
;
unsigned
int
output_offset
=
vb
.
size
()
+
tables
.
edge_indices
.
size
()
/
4
;
unsigned
int
output_offset
=
input
.
vertex_buffer
.
size
()
+
tables
.
edge_indices
.
size
()
/
4
;
tables
.
vertex_offsets
.
push_back
(
0
);
for
(
int
i
=
0
;
i
<
input
.
vertex_buffer
.
length
();
i
++
){
//hat evtl viel redundanz
for
(
int
i
=
0
;
i
<
irregular_triangles
.
length
();
i
++
)
{
Triangle
triangle
=
irregular_triangles
[
i
];
QVector
<
Vertex
>
adj_v
;
//helfer
tables
.
vertex_offsets
.
push_back
(
offset
);
Triangle
::
Neighbors
ns
=
neighbors
.
value
(
triangle
);
tables
.
vertex_indices
.
push_back
(
i
);
unsigned
int
idx
;
modified_vertices
.
insert
(
i
,
output_offset
+
i
);
QVector
<
unsigned
int
>
neighbor_indices
;
offset
++
;
bool
removed
;
Vertex
originalVertex
=
input
.
vertex_buffer
[
i
];
idx
=
triangle
.
u_idx
();
if
(
!
modified_vertices
.
contains
(
idx
))
{
QVector
<
unsigned
int
>
d
;
QVector
<
Triangle
>
neighborTriangles
=
vertexNeighbors
(
triangle
,
ns
.
uv
,
neighbors
);
if
(
!
neighborTriangles
.
empty
()){
for
(
int
j
=
0
;
j
<
ib_combined
.
length
();
j
++
){
tables
.
vertex_indices
.
push_back
(
idx
);
modified_vertices
.
insert
(
idx
,
output_offset
++
);
//suche verweise auf vertex im indexbuffer
neighbor_indices
=
getAllVertexIndices
(
vb
,
neighborTriangles
);
if
(
input
.
vertex_buffer
[
ib_combined
[
j
]].
samePos
(
originalVertex
)){
removed
=
removeVertexIndex
(
vb
,
neighbor_indices
,
triangle
.
u
());
d
.
push_back
(
j
);
assert
(
removed
);
unsigned
int
i1
,
i2
;
//indices for neighbour vertices
tables
.
vertex_indices
+=
neighbor_indices
;
switch
(
j
%
3
)
{
tables
.
vertex_offsets
.
push_back
(
tables
.
vertex_indices
.
length
());
case
0
:
}
i1
=
ib_combined
[
j
+
1
];
}
i2
=
ib_combined
[
j
+
2
];
break
;
idx
=
triangle
.
v_idx
();
case
1
:
if
(
!
modified_vertices
.
contains
(
idx
))
{
i1
=
ib_combined
[
j
-
1
];
QVector
<
Triangle
>
neighborTriangles
=
vertexNeighbors
(
triangle
,
ns
.
vw
,
neighbors
);
i2
=
ib_combined
[
j
+
1
];
if
(
!
neighborTriangles
.
empty
()){
break
;
tables
.
vertex_indices
.
push_back
(
idx
);
case
2
:
modified_vertices
.
insert
(
idx
,
output_offset
++
);
i1
=
ib_combined
[
j
-
2
];
neighbor_indices
=
getAllVertexIndices
(
vb
,
neighborTriangles
);
i2
=
ib_combined
[
j
-
1
];
removed
=
removeVertexIndex
(
vb
,
neighbor_indices
,
triangle
.
v
());
break
;
assert
(
removed
);
}
tables
.
vertex_indices
+=
neighbor_indices
;
tables
.
vertex_offsets
.
push_back
(
tables
.
vertex_indices
.
length
());
Vertex
v1
,
v2
;
//neighbour vertices;
}
v1
=
input
.
vertex_buffer
[
i1
];
}
v2
=
input
.
vertex_buffer
[
i2
];
//check if vertices where already used to influence this vertex
idx
=
triangle
.
w_idx
();
//Note: Can't use contain. Contain uses equal (would have to implement equal, but we're only interested in the position here.
if
(
!
modified_vertices
.
contains
(
idx
))
{
bool
found1
=
false
;
QVector
<
Triangle
>
neighborTriangles
=
vertexNeighbors
(
triangle
,
ns
.
wu
,
neighbors
);
bool
found2
=
false
;
if
(
!
neighborTriangles
.
empty
()){
for
(
int
k
=
0
;
k
<
adj_v
.
length
();
k
++
){
tables
.
vertex_indices
.
push_back
(
idx
);
if
(
adj_v
[
k
].
samePos
(
v1
))
found1
=
true
;
modified_vertices
.
insert
(
idx
,
output_offset
++
);
if
(
adj_v
[
k
].
samePos
(
v2
))
found2
=
true
;
neighbor_indices
=
getAllVertexIndices
(
vb
,
neighborTriangles
);
}
removed
=
removeVertexIndex
(
vb
,
neighbor_indices
,
triangle
.
w
());
if
(
!
found1
){
assert
(
removed
);
adj_v
.
push_back
(
v1
);
tables
.
vertex_indices
+=
neighbor_indices
;
tables
.
vertex_indices
.
push_back
(
i1
);
tables
.
vertex_offsets
.
push_back
(
tables
.
vertex_indices
.
length
());
offset
++
;
}
if
(
!
found2
){
adj_v
.
push_back
(
v2
);
tables
.
vertex_indices
.
push_back
(
i2
);
offset
++
;
}
//if one adjacent vertex is referenced by multiple different indices, only its first index will appear in the adjacent_indices list.1
}
}
}
}
if
(
!
duplicates
.
contains
(
d
))
duplicates
.
push_back
(
d
);
}
}
qCDebug
(
log_timing
)
<<
"precomputeVertexTable done:"
<<
formatTimeMeasurement
(
timer
.
elapsed
());
}
tables
.
vertex_offsets
.
push_back
(
offset
);
bool
Subdivision
::
containsVertexIndex
(
const
QVector
<
Vertex
>
&
vb
,
const
QVector
<
unsigned
int
>
&
vertices
,
const
Vertex
vertex
)
const
{
for
(
int
i
=
0
;
i
<
vertices
.
length
();
i
++
)
{
if
(
vertex
.
samePos
(
vb
[
vertices
[
i
]]))
{
return
true
;
}
}
return
false
;
}
qCDebug
(
log_subdiv
)
<<
"Done with vertex index table. "
;
QVector
<
unsigned
int
>
Subdivision
::
getAllVertexIndices
(
const
QVector
<
Vertex
>
&
vb
,
const
QVector
<
Triangle
>
&
triangles
)
{
qCDebug
(
log_subdiv
)
<<
"Duplicates: "
<<
duplicates
.
length
();
QVector
<
unsigned
int
>
result
;
for
(
int
i
=
0
;
i
<
duplicates
.
length
();
i
++
){
QVectorIterator
<
Triangle
>
i
(
triangles
);
qCDebug
(
log_subdiv_trace
)
<<
duplicates
[
i
];
while
(
i
.
hasNext
())
{
Triangle
extra_triangle
=
i
.
next
();
if
(
!
containsVertexIndex
(
vb
,
result
,
extra_triangle
.
u
()))
result
.
push_back
(
extra_triangle
.
u_idx
());
if
(
!
containsVertexIndex
(
vb
,
result
,
extra_triangle
.
v
()))
result
.
push_back
(
extra_triangle
.
v_idx
());
if
(
!
containsVertexIndex
(
vb
,
result
,
extra_triangle
.
w
()))
result
.
push_back
(
extra_triangle
.
w_idx
());
}
}
return
result
;
}
bool
Subdivision
::
removeVertexIndex
(
const
QVector
<
Vertex
>
&
vb
,
QVector
<
unsigned
int
>
&
vertices
,
const
Vertex
&
vertex
)
{
QMutableVectorIterator
<
unsigned
int
>
i
(
vertices
);
while
(
i
.
hasNext
())
{
if
(
vertex
.
samePos
(
vb
[
i
.
next
()]))
{
i
.
remove
();
return
true
;
}
}
return
false
;
}
}
void
Subdivision
::
updateIndexBuffer
(
QVector
<
unsigned
int
>
&
index_buffer
,
QMap
<
unsigned
int
,
unsigned
int
>
map
)
{
void
Subdivision
::
updateIndexBuffer
(
QVector
<
unsigned
int
>
&
index_buffer
,
QMap
<
unsigned
int
,
unsigned
int
>
map
)
{
...
@@ -852,6 +882,7 @@ void Subdivision::findRegular(QVector<Triangle> triangles, QMap<Triangle, Triang
...
@@ -852,6 +882,7 @@ void Subdivision::findRegular(QVector<Triangle> triangles, QMap<Triangle, Triang
Triangle
::
Neighbors
ns
=
neighbors
.
value
(
triangle
);
Triangle
::
Neighbors
ns
=
neighbors
.
value
(
triangle
);
bool
is_regular
=
true
;
bool
is_regular
=
true
;
if
(
!
isVertexRegular
(
triangle
,
ns
.
uv
,
neighbors
))
{
if
(
!
isVertexRegular
(
triangle
,
ns
.
uv
,
neighbors
))
{
is_regular
=
false
;
is_regular
=
false
;
}
}
...
@@ -862,6 +893,7 @@ void Subdivision::findRegular(QVector<Triangle> triangles, QMap<Triangle, Triang
...
@@ -862,6 +893,7 @@ void Subdivision::findRegular(QVector<Triangle> triangles, QMap<Triangle, Triang
is_regular
=
false
;
is_regular
=
false
;
}
}
if
(
is_regular
)
{
if
(
is_regular
)
{
regular
.
push_back
(
triangle
);
regular
.
push_back
(
triangle
);
}
else
{
}
else
{
...
@@ -1057,20 +1089,39 @@ bool Subdivision::containsVertex(QVector<Vertex> &vertices, Vertex vertex) {
...
@@ -1057,20 +1089,39 @@ bool Subdivision::containsVertex(QVector<Vertex> &vertices, Vertex vertex) {
return
false
;
return
false
;
}
}
QVector
<
Vertex
>
Subdivision
::
getAllVertices
(
const
QVector
<
Triangle
>
&
triangles
)
{
QVector
<
Vertex
>
result
;
QVectorIterator
<
Triangle
>
i
(
triangles
);
while
(
i
.
hasNext
())
{
Triangle
extra_triangle
=
i
.
next
();
if
(
!
containsVertex
(
result
,
extra_triangle
.
u
()))
result
.
push_back
(
extra_triangle
.
u
());
if
(
!
containsVertex
(
result
,
extra_triangle
.
v
()))
result
.
push_back
(
extra_triangle
.
v
());
if
(
!
containsVertex
(
result
,
extra_triangle
.
w
()))
result
.
push_back
(
extra_triangle
.
w
());
}
return
result
;
}
bool
removeVertex
(
QVector
<
Vertex
>
&
vertices
,
const
Vertex
&
vertex
)
{
QMutableVectorIterator
<
Vertex
>
i
(
vertices
);
while
(
i
.
hasNext
())
{
if
(
vertex
.
samePos
(
i
.
next
()))
{
i
.
remove
();
return
true
;
}
}
return
false
;
}
QVector3D
Subdivision
::
updateIrregularVertexForDraw
(
Vertex
currentCorner
,
QVector
<
Triangle
>
neighboring_triangles
)
{
QVector3D
Subdivision
::
updateIrregularVertexForDraw
(
Vertex
currentCorner
,
QVector
<
Triangle
>
neighboring_triangles
)
{
QVector
<
Vertex
>
surroundingVertex
;
QVector
<
Vertex
>
surroundingVertex
;
QVectorIterator
<
Triangle
>
extra
(
neighboring_triangles
);
surroundingVertex
=
getAllVertices
(
neighboring_triangles
);
while
(
extra
.
hasNext
())
{
bool
removed
=
removeVertex
(
surroundingVertex
,
currentCorner
);
Triangle
extra_triangle
=
extra
.
next
();
assert
(
removed
);
if
(
!
currentCorner
.
samePos
(
extra_triangle
.
u
())
&&
!
containsVertex
(
surroundingVertex
,
extra_triangle
.
u
()))
surroundingVertex
.
push_back
(
extra_triangle
.
u
());
if
(
!
currentCorner
.
samePos
(
extra_triangle
.
v
())
&&
!
containsVertex
(
surroundingVertex
,
extra_triangle
.
v
()))
surroundingVertex
.
push_back
(
extra_triangle
.
v
());
if
(
!
currentCorner
.
samePos
(
extra_triangle
.
w
())
&&
!
containsVertex
(
surroundingVertex
,
extra_triangle
.
w
()))
surroundingVertex
.
push_back
(
extra_triangle
.
w
());
}
QVector3D
newPos
(
0.0
,
0.0
,
0.0
);
QVector3D
newPos
(
0.0
,
0.0
,
0.0
);
...
...
QTProject/subdivision.h
View file @
9349f665
...
@@ -62,8 +62,11 @@ private:
...
@@ -62,8 +62,11 @@ private:
Tables
precomputeTables
(
Input
input
);
Tables
precomputeTables
(
Input
input
);
void
buildNeighborsMap
(
QVector
<
Vertex
>
&
vb
,
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
);
void
buildNeighborsMap
(
QVector
<
Vertex
>
&
vb
,
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
);
QVector
<
Triangle
>
vertexNeighbors
(
Triangle
&
triangle
,
Triangle
::
Neighbor
current_neighbor
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
);
QVector
<
Triangle
>
vertexNeighbors
(
Triangle
&
triangle
,
Triangle
::
Neighbor
current_neighbor
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
);
void
precomputeEdgeTable
(
Subdivision
::
Tables
&
tables
,
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
unsigned
int
offset
);
void
precomputeEdgeTable
(
Subdivision
::
Tables
&
tables
,
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
unsigned
int
offset
,
QVector
<
Triangle
>
extra_old_triangles
);
void
precomputeVertexTable
(
Subdivision
::
Tables
&
tables
,
Input
&
input
,
QMap
<
unsigned
int
,
unsigned
int
>
&
modified_vertices
);
void
precomputeVertexTable
(
Tables
&
tables
,
QVector
<
Vertex
>
&
vb
,
QVector
<
Triangle
>
&
irregular_triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
,
QMap
<
unsigned
int
,
unsigned
int
>
&
modified_vertices
);
bool
containsVertexIndex
(
const
QVector
<
Vertex
>
&
vb
,
const
QVector
<
unsigned
int
>
&
vertices
,
const
Vertex
vertex
)
const
;
QVector
<
unsigned
int
>
getAllVertexIndices
(
const
QVector
<
Vertex
>
&
vb
,
const
QVector
<
Triangle
>
&
triangles
);
bool
removeVertexIndex
(
const
QVector
<
Vertex
>
&
vb
,
QVector
<
unsigned
int
>
&
vertices
,
const
Vertex
&
vertex
);
void
updateIndexBuffer
(
QVector
<
unsigned
int
>
&
index_buffer
,
QMap
<
unsigned
int
,
unsigned
int
>
map
);
void
updateIndexBuffer
(
QVector
<
unsigned
int
>
&
index_buffer
,
QMap
<
unsigned
int
,
unsigned
int
>
map
);
void
findRegular
(
QVector
<
Triangle
>
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
,
QVector
<
Triangle
>
&
regular
,
QVector
<
Triangle
>
&
irregular
);
void
findRegular
(
QVector
<
Triangle
>
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
,
QVector
<
Triangle
>
&
regular
,
QVector
<
Triangle
>
&
irregular
);
Result
runShader
(
Input
input
,
Tables
&
tables
);
Result
runShader
(
Input
input
,
Tables
&
tables
);
...
@@ -72,6 +75,7 @@ private:
...
@@ -72,6 +75,7 @@ private:
void
runEdgeShader
(
GLuint
size
,
GLuint
vb_handle
,
GLuint
edge_indices_handle
,
GLuint
output_handle
,
GLuint
offset_handle
);
void
runEdgeShader
(
GLuint
size
,
GLuint
vb_handle
,
GLuint
edge_indices_handle
,
GLuint
output_handle
,
GLuint
offset_handle
);
void
updateIrregularForDraw
(
const
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
Result
&
result
);
void
updateIrregularForDraw
(
const
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
Result
&
result
);
bool
containsVertex
(
QVector
<
Vertex
>
&
vertices
,
Vertex
vertex
);
bool
containsVertex
(
QVector
<
Vertex
>
&
vertices
,
Vertex
vertex
);
QVector
<
Vertex
>
getAllVertices
(
const
QVector
<
Triangle
>
&
triangles
);
QVector3D
updateIrregularVertexForDraw
(
Vertex
currentCorner
,
QVector
<
Triangle
>
neighboring_triangles
);
QVector3D
updateIrregularVertexForDraw
(
Vertex
currentCorner
,
QVector
<
Triangle
>
neighboring_triangles
);
QVector
<
unsigned
int
>
patchIBToTriangleIB
(
QVector
<
unsigned
int
>
ib
);
QVector
<
unsigned
int
>
patchIBToTriangleIB
(
QVector
<
unsigned
int
>
ib
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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