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
07e28ea6
Commit
07e28ea6
authored
Sep 27, 2016
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
temp
parent
2aba8a8a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
79 deletions
+96
-79
subdivision.cpp
QTProject/subdivision.cpp
+91
-77
subdivision.h
QTProject/subdivision.h
+5
-2
No files found.
QTProject/subdivision.cpp
View file @
07e28ea6
...
@@ -177,13 +177,16 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
...
@@ -177,13 +177,16 @@ 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
);
QVector
<
Triangle
>
foo
=
all_triangles
+
extra_old_triangles
;
precomputeVertexTable
(
tables
,
vb
,
foo
,
neighbors
,
modified_vertices
);
qCDebug
(
log_timing
)
<<
"precomputeVertexTable:"
<<
formatTimeMeasurement
(
subTimer
.
elapsed
());
qCDebug
(
log_timing
)
<<
"precomputeVertexTable:"
<<
formatTimeMeasurement
(
subTimer
.
elapsed
());
subTimer
.
restart
();
subTimer
.
restart
();
...
@@ -388,7 +391,7 @@ QVector<Triangle> Subdivision::vertexNeighbors(Triangle &triangle, Triangle::Nei
...
@@ -388,7 +391,7 @@ QVector<Triangle> Subdivision::vertexNeighbors(Triangle &triangle, Triangle::Nei
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 +510,7 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
...
@@ -507,6 +510,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 +607,91 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
...
@@ -603,81 +607,91 @@ 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
++
){
for
(
int
i
=
0
;
i
<
irregular_triangles
.
length
();
i
++
)
{
//hat evtl viel redundanz
Triangle
triangle
=
irregular_triangles
[
i
];
QVector
<
Vertex
>
adj_v
;
//helfer
Triangle
::
Neighbors
ns
=
neighbors
.
value
(
triangle
);
tables
.
vertex_offsets
.
push_back
(
offset
);
unsigned
int
idx
;
tables
.
vertex_indices
.
push_back
(
i
);
QVector
<
unsigned
int
>
neighbor_indices
;
modified_vertices
.
insert
(
i
,
output_offset
+
i
);
bool
removed
;
offset
++
;
idx
=
triangle
.
u_idx
();
Vertex
originalVertex
=
input
.
vertex_buffer
[
i
];
if
(
!
modified_vertices
.
contains
(
idx
))
{
tables
.
vertex_indices
.
push_back
(
idx
);
QVector
<
unsigned
int
>
d
;
modified_vertices
.
insert
(
idx
,
output_offset
++
);
neighbor_indices
=
getAllVertexIndices
(
vb
,
vertexNeighbors
(
triangle
,
ns
.
uv
,
neighbors
));
for
(
int
j
=
0
;
j
<
ib_combined
.
length
();
j
++
){
removed
=
removeVertexIndex
(
vb
,
neighbor_indices
,
triangle
.
u
());
assert
(
removed
);
//suche verweise auf vertex im indexbuffer
tables
.
vertex_indices
+=
neighbor_indices
;
if
(
input
.
vertex_buffer
[
ib_combined
[
j
]].
samePos
(
originalVertex
)){
tables
.
vertex_offsets
.
push_back
(
tables
.
vertex_indices
.
length
());
d
.
push_back
(
j
);
}
unsigned
int
i1
,
i2
;
//indices for neighbour vertices
switch
(
j
%
3
)
{
idx
=
triangle
.
v_idx
();
case
0
:
if
(
!
modified_vertices
.
contains
(
idx
))
{
i1
=
ib_combined
[
j
+
1
];
tables
.
vertex_indices
.
push_back
(
idx
);
i2
=
ib_combined
[
j
+
2
];
modified_vertices
.
insert
(
idx
,
output_offset
++
);
break
;
neighbor_indices
=
getAllVertexIndices
(
vb
,
vertexNeighbors
(
triangle
,
ns
.
vw
,
neighbors
));
case
1
:
removed
=
removeVertexIndex
(
vb
,
neighbor_indices
,
triangle
.
v
());
i1
=
ib_combined
[
j
-
1
];
assert
(
removed
);
i2
=
ib_combined
[
j
+
1
];
tables
.
vertex_indices
+=
neighbor_indices
;
break
;
tables
.
vertex_offsets
.
push_back
(
tables
.
vertex_indices
.
length
());
case
2
:
}
i1
=
ib_combined
[
j
-
2
];
i2
=
ib_combined
[
j
-
1
];
idx
=
triangle
.
w_idx
();
break
;
if
(
!
modified_vertices
.
contains
(
idx
))
{
}
tables
.
vertex_indices
.
push_back
(
idx
);
modified_vertices
.
insert
(
idx
,
output_offset
++
);
Vertex
v1
,
v2
;
//neighbour vertices;
neighbor_indices
=
getAllVertexIndices
(
vb
,
vertexNeighbors
(
triangle
,
ns
.
wu
,
neighbors
));
v1
=
input
.
vertex_buffer
[
i1
];
removed
=
removeVertexIndex
(
vb
,
neighbor_indices
,
triangle
.
w
());
v2
=
input
.
vertex_buffer
[
i2
];
assert
(
removed
);
//check if vertices where already used to influence this vertex
tables
.
vertex_indices
+=
neighbor_indices
;
//Note: Can't use contain. Contain uses equal (would have to implement equal, but we're only interested in the position here.
tables
.
vertex_offsets
.
push_back
(
tables
.
vertex_indices
.
length
());
bool
found1
=
false
;
}
bool
found2
=
false
;
}
for
(
int
k
=
0
;
k
<
adj_v
.
length
();
k
++
){
qCDebug
(
log_timing
)
<<
"precomputeVertexTable done:"
<<
formatTimeMeasurement
(
timer
.
elapsed
());
if
(
adj_v
[
k
].
samePos
(
v1
))
found1
=
true
;
}
if
(
adj_v
[
k
].
samePos
(
v2
))
found2
=
true
;
}
bool
Subdivision
::
containsVertexIndex
(
const
QVector
<
Vertex
>
&
vb
,
const
QVector
<
unsigned
int
>
&
vertices
,
const
Vertex
vertex
)
const
{
if
(
!
found1
){
for
(
int
i
=
0
;
i
<
vertices
.
length
();
i
++
)
{
adj_v
.
push_back
(
v1
);
if
(
vertex
.
samePos
(
vb
[
vertices
[
i
]]))
{
tables
.
vertex_indices
.
push_back
(
i1
);
return
true
;
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
);
}
tables
.
vertex_offsets
.
push_back
(
offset
);
qCDebug
(
log_subdiv
)
<<
"Done with vertex index table. "
;
qCDebug
(
log_subdiv
)
<<
"Duplicates: "
<<
duplicates
.
length
();
for
(
int
i
=
0
;
i
<
duplicates
.
length
();
i
++
){
qCDebug
(
log_subdiv_trace
)
<<
duplicates
[
i
];
}
}
}
return
false
;
}
QVector
<
unsigned
int
>
Subdivision
::
getAllVertexIndices
(
const
QVector
<
Vertex
>
&
vb
,
const
QVector
<
Triangle
>
&
triangles
)
{
QVector
<
unsigned
int
>
result
;
QVectorIterator
<
Triangle
>
i
(
triangles
);
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
)
{
...
...
QTProject/subdivision.h
View file @
07e28ea6
...
@@ -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
);
...
...
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