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
b4a91fe7
Commit
b4a91fe7
authored
Sep 26, 2016
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '9-findregular-ist-langsam' into 'patchRender'
Resolve "findRegular ist langsam" Closes
#9
See merge request
!8
parents
0fb2b6dd
d029fb25
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
52 deletions
+97
-52
subdivision.cpp
QTProject/subdivision.cpp
+84
-51
subdivision.h
QTProject/subdivision.h
+1
-1
triangle.cpp
QTProject/triangle.cpp
+11
-0
triangle.h
QTProject/triangle.h
+1
-0
No files found.
QTProject/subdivision.cpp
View file @
b4a91fe7
...
...
@@ -89,18 +89,29 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
Tables
tables
=
precomputeTables
(
input
);
Result
result
=
runShader
(
input
,
tables
);
QVector
<
unsigned
int
>
regular
;
QVector
<
unsigned
int
>
irregular
;
findRegular
(
tables
.
index_buffer
,
result
.
vertex_buffer
,
regular
,
irregular
);
QVector
<
Triangle
>
all_triangles
;
ibToTriangles
(
&
result
.
vertex_buffer
,
tables
.
index_buffer
,
all_triangles
);
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
;
buildNeighborsMap
(
result
.
vertex_buffer
,
all_triangles
,
neighbors
);
QVector
<
Triangle
>
regular
;
QVector
<
Triangle
>
irregular
;
findRegular
(
all_triangles
,
neighbors
,
regular
,
irregular
);
qCDebug
(
log_subdiv
)
<<
"Indices"
<<
tables
.
index_buffer
.
length
();
qCDebug
(
log_subdiv
)
<<
"subdivide: regular"
<<
regular
.
length
();
qCDebug
(
log_subdiv
)
<<
"subdivide: irregular"
<<
irregular
.
length
();
QVector
<
unsigned
int
>
patches
=
getPatchIndexBuffer
(
regular
,
irregular
,
result
.
vertex_buffer
);
//todo is this the correct vb?
QVector
<
unsigned
int
>
regular_ib
;
trianglesToIB
(
regular
,
regular_ib
);
QVector
<
unsigned
int
>
irregular_ib
;
trianglesToIB
(
irregular
,
irregular_ib
);
QVector
<
unsigned
int
>
patches
=
getPatchIndexBuffer
(
regular_ib
,
irregular_ib
,
result
.
vertex_buffer
);
qCDebug
(
log_subdiv
)
<<
"patches"
<<
patches
.
length
();
current_mesh
->
update
(
result
.
vb_handle
,
result
.
vertex_buffer
,
irregular
,
patches
);
current_mesh
->
update
(
result
.
vb_handle
,
result
.
vertex_buffer
,
irregular
_ib
,
patches
);
}
}
...
...
@@ -545,15 +556,43 @@ void Subdivision::splitRegular(Mesh *mesh) {
Mesh
::
MeshEntry
*
current_mesh
=
mesh
->
getMeshEntry
(
first_mesh_index
);
QVector
<
unsigned
int
>
regular
;
QVector
<
unsigned
int
>
irregular
;
QVector
<
Triangle
>
all_triangles
;
qDebug
()
<<
current_mesh
->
buffers
[
0
]
->
indices_irregular
.
size
()
<<
current_mesh
->
buffers
[
0
]
->
indices_regular
.
size
();
ibToTriangles
(
&
current_mesh
->
buffers
[
0
]
->
vertices
,
current_mesh
->
buffers
[
0
]
->
indices_irregular
,
all_triangles
);
QVector
<
unsigned
int
>
old_regular_ib
=
patchIBToTriangleIB
(
current_mesh
->
buffers
[
0
]
->
indices_regular
);
ibToTriangles
(
&
current_mesh
->
buffers
[
0
]
->
vertices
,
old_regular_ib
,
all_triangles
);
qDebug
()
<<
all_triangles
.
size
();
findRegular
(
current_mesh
->
buffers
[
0
]
->
indices_irregular
,
current_mesh
->
buffers
[
0
]
->
vertices
,
regular
,
irregular
);
findRegular
(
current_mesh
->
buffers
[
0
]
->
indices_regular
,
current_mesh
->
buffers
[
0
]
->
vertices
,
regular
,
irregular
);
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
;
buildNeighborsMap
(
current_mesh
->
buffers
[
0
]
->
vertices
,
all_triangles
,
neighbors
);
QVectorIterator
<
Triangle
>
i
(
all_triangles
);
while
(
i
.
hasNext
())
{
Triangle
triangle
=
i
.
next
();
Triangle
::
Neighbors
ns
=
neighbors
.
value
(
triangle
);
if
(
ns
.
uv
.
triangle
==
NULL
)
{
qDebug
()
<<
qSetRealNumberPrecision
(
10
)
<<
"uv"
<<
triangle
;
}
if
(
ns
.
vw
.
triangle
==
NULL
)
{
qDebug
()
<<
qSetRealNumberPrecision
(
10
)
<<
"vw"
<<
triangle
;
}
if
(
ns
.
wu
.
triangle
==
NULL
)
{
qDebug
()
<<
"wu"
<<
triangle
;
}
}
QVector
<
unsigned
int
>
patches
=
getPatchIndexBuffer
(
regular
,
irregular
,
current_mesh
->
buffers
[
0
]
->
vertices
);
//TODO is this the corret vertex buffer?
QVector
<
Triangle
>
regular
;
QVector
<
Triangle
>
irregular
;
findRegular
(
all_triangles
,
neighbors
,
regular
,
irregular
);
QVector
<
unsigned
int
>
regular_ib
;
trianglesToIB
(
regular
,
regular_ib
);
QVector
<
unsigned
int
>
irregular_ib
;
trianglesToIB
(
irregular
,
irregular_ib
);
QVector
<
unsigned
int
>
patches
=
getPatchIndexBuffer
(
regular_ib
,
irregular_ib
,
current_mesh
->
buffers
[
0
]
->
vertices
);
current_mesh
->
buffers
[
0
]
->
indices_regular
=
patches
;
current_mesh
->
buffers
[
0
]
->
indices_irregular
=
irregular
;
current_mesh
->
buffers
[
0
]
->
indices_irregular
=
irregular
_ib
;
current_mesh
->
buffers
[
0
]
->
updateIndices
();
...
...
@@ -759,50 +798,44 @@ QVector<unsigned int> Subdivision::patchIBToTriangleIB(QVector<unsigned int> ib)
return
new_ib
;
}
/**
* Generates index buffers containing all regular and all irregular triangles in the input index buffer.
*
* @param index_buffer Index buffer describing triangles.
* @param vertex_buffer Vertices used by index_buffer.
* @param regular All regular triangles are appended to this index buffer.
* @param irregular All irregular triangles are appended to this index buffer.
*/
void
Subdivision
::
findRegular
(
QVector
<
unsigned
int
>
index_buffer
,
QVector
<
Vertex
>
vertex_buffer
,
QVector
<
unsigned
int
>
&
regular
,
QVector
<
unsigned
int
>
&
irregular
)
{
QTime
totalTimer
;
totalTimer
.
start
();
qCDebug
(
log_timing
)
<<
"Find Regular started"
;
for
(
int
i
=
0
;
i
<
index_buffer
.
length
()
-
2
;
i
+=
3
){
Vertex
vx
=
vertex_buffer
[
index_buffer
[
i
]];
Vertex
vy
=
vertex_buffer
[
index_buffer
[
i
+
1
]];
Vertex
vz
=
vertex_buffer
[
index_buffer
[
i
+
2
]];
int
countx
=
0
;
int
county
=
0
;
int
countz
=
0
;
for
(
int
j
=
0
;
j
<
index_buffer
.
length
();
j
++
){
if
(
j
!=
i
&&
j
!=
i
+
1
&&
j
!=
i
+
2
){
if
(
vx
.
samePos
(
vertex_buffer
[
index_buffer
[
j
]])){
countx
++
;
}
if
(
vy
.
samePos
(
vertex_buffer
[
index_buffer
[
j
]])){
county
++
;
}
if
(
vz
.
samePos
(
vertex_buffer
[
index_buffer
[
j
]])){
countz
++
;
}
}
bool
isVertexRegular
(
Triangle
&
triangle
,
Triangle
::
Neighbor
current_neighbor
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
)
{
unsigned
int
count
=
1
;
while
(
count
<
6
&&
*
current_neighbor
.
triangle
!=
triangle
)
{
count
++
;
current_neighbor
=
neighbors
.
value
(
*
current_neighbor
.
triangle
).
get_neighbor
(
rotate_edge_name
(
current_neighbor
.
edge
.
name
));
}
return
count
==
6
&&
*
current_neighbor
.
triangle
==
triangle
;
}
void
Subdivision
::
findRegular
(
QVector
<
Triangle
>
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
,
QVector
<
Triangle
>
&
regular
,
QVector
<
Triangle
>
&
irregular
)
{
QTime
timer
;
timer
.
start
();
qCDebug
(
log_timing
)
<<
"findRegular started"
;
QVectorIterator
<
Triangle
>
it
(
triangles
);
while
(
it
.
hasNext
())
{
Triangle
triangle
=
it
.
next
();
Triangle
::
Neighbors
ns
=
neighbors
.
value
(
triangle
);
bool
is_regular
=
true
;
if
(
!
isVertexRegular
(
triangle
,
ns
.
uv
,
neighbors
))
{
is_regular
=
false
;
}
if
(
is_regular
&&
!
isVertexRegular
(
triangle
,
ns
.
vw
,
neighbors
))
{
is_regular
=
false
;
}
if
(
countx
==
5
&&
county
==
5
&&
countz
==
5
){
regular
.
push_back
(
index_buffer
[
i
]);
regular
.
push_back
(
index_buffer
[
i
+
1
]);
regular
.
push_back
(
index_buffer
[
i
+
2
]);
if
(
is_regular
&&
!
isVertexRegular
(
triangle
,
ns
.
wu
,
neighbors
))
{
is_regular
=
false
;
}
if
(
is_regular
)
{
regular
.
push_back
(
triangle
);
}
else
{
irregular
.
push_back
(
index_buffer
[
i
]);
irregular
.
push_back
(
index_buffer
[
i
+
1
]);
irregular
.
push_back
(
index_buffer
[
i
+
2
]);
irregular
.
push_back
(
triangle
);
}
}
qCDebug
(
log_timing
)
<<
"Find Regular done:"
<<
formatTimeMeasurement
(
totalTimer
.
elapsed
());
qCDebug
(
log_timing
)
<<
"findRegular done:"
<<
formatTimeMeasurement
(
timer
.
elapsed
());
}
Subdivision
::
Result
Subdivision
::
runShader
(
Input
input
,
Tables
&
tables
)
{
...
...
QTProject/subdivision.h
View file @
b4a91fe7
...
...
@@ -62,7 +62,7 @@ private:
void
precomputeEdgeTable
(
Subdivision
::
Tables
&
tables
,
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
unsigned
int
offset
);
void
precomputeVertexTable
(
Subdivision
::
Tables
&
tables
,
Input
&
input
,
QMap
<
unsigned
int
,
unsigned
int
>
&
modified_vertices
);
void
updateIndexBuffer
(
QVector
<
unsigned
int
>
&
index_buffer
,
QMap
<
unsigned
int
,
unsigned
int
>
map
);
void
findRegular
(
QVector
<
unsigned
int
>
index_buffer
,
QVector
<
Vertex
>
vertex_buffer
,
QVector
<
unsigned
int
>
&
regular
,
QVector
<
unsigned
int
>
&
irregular
);
void
findRegular
(
QVector
<
Triangle
>
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
,
QVector
<
Triangle
>
&
regular
,
QVector
<
Triangle
>
&
irregular
);
Result
runShader
(
Input
input
,
Tables
&
tables
);
void
runCopyShader
(
GLuint
size
,
GLuint
vb_in
,
GLuint
vb_out
);
void
runVertexShader
(
GLuint
size
,
GLuint
vb_handle
,
GLuint
vertex_indices_handle
,
GLuint
vertex_offsets_handle
,
GLuint
output_handle
,
GLuint
offset_handle
);
...
...
QTProject/triangle.cpp
View file @
b4a91fe7
...
...
@@ -192,6 +192,17 @@ void ibToTriangles(QVector<Vertex> *vb, QVector<unsigned int> &ib, QVector<Trian
}
}
void
trianglesToIB
(
const
QVector
<
Triangle
>
&
triangles
,
QVector
<
unsigned
int
>
&
ib
)
{
ib
.
reserve
(
ib
.
length
()
+
triangles
.
length
()
*
3
);
QVectorIterator
<
Triangle
>
it
(
triangles
);
while
(
it
.
hasNext
())
{
Triangle
triangle
=
it
.
next
();
ib
.
push_back
(
triangle
.
u_idx
());
ib
.
push_back
(
triangle
.
v_idx
());
ib
.
push_back
(
triangle
.
w_idx
());
}
}
Triangle
::
Neighbor
Triangle
::
Neighbors
::
get_neighbor
(
Triangle
::
Edge
::
Name
name
)
const
{
switch
(
name
)
{
case
Triangle
:
:
Edge
::
Name
::
uv
:
...
...
QTProject/triangle.h
View file @
b4a91fe7
...
...
@@ -73,6 +73,7 @@ class Triangle {
Triangle
::
Edge
::
Name
rotate_edge_name
(
Triangle
::
Edge
::
Name
edge
);
void
ibToTriangles
(
QVector
<
Vertex
>
*
vb
,
QVector
<
unsigned
int
>
&
ib
,
QVector
<
Triangle
>
&
triangles
);
void
trianglesToIB
(
const
QVector
<
Triangle
>
&
triangles
,
QVector
<
unsigned
int
>
&
ib
);
QDebug
operator
<<
(
QDebug
d
,
const
Triangle
&
triangle
);
...
...
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