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
d029fb25
Commit
d029fb25
authored
Sep 26, 2016
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite findRegular to use neighbors map
parent
36f9cdb3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
49 deletions
+82
-49
subdivision.cpp
QTProject/subdivision.cpp
+81
-48
subdivision.h
QTProject/subdivision.h
+1
-1
No files found.
QTProject/subdivision.cpp
View file @
d029fb25
...
@@ -89,18 +89,29 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
...
@@ -89,18 +89,29 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
Tables
tables
=
precomputeTables
(
input
);
Tables
tables
=
precomputeTables
(
input
);
Result
result
=
runShader
(
input
,
tables
);
Result
result
=
runShader
(
input
,
tables
);
QVector
<
unsigned
int
>
regular
;
QVector
<
Triangle
>
all_triangles
;
QVector
<
unsigned
int
>
irregular
;
ibToTriangles
(
&
result
.
vertex_buffer
,
tables
.
index_buffer
,
all_triangles
);
findRegular
(
tables
.
index_buffer
,
result
.
vertex_buffer
,
regular
,
irregular
);
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
)
<<
"Indices"
<<
tables
.
index_buffer
.
length
();
qCDebug
(
log_subdiv
)
<<
"subdivide: regular"
<<
regular
.
length
();
qCDebug
(
log_subdiv
)
<<
"subdivide: regular"
<<
regular
.
length
();
qCDebug
(
log_subdiv
)
<<
"subdivide: irregular"
<<
irregular
.
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
();
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) {
...
@@ -545,15 +556,43 @@ void Subdivision::splitRegular(Mesh *mesh) {
Mesh
::
MeshEntry
*
current_mesh
=
mesh
->
getMeshEntry
(
first_mesh_index
);
Mesh
::
MeshEntry
*
current_mesh
=
mesh
->
getMeshEntry
(
first_mesh_index
);
QVector
<
unsigned
int
>
regular
;
QVector
<
Triangle
>
all_triangles
;
QVector
<
unsigned
int
>
irregular
;
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
();
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
;
}
}
findRegular
(
current_mesh
->
buffers
[
0
]
->
indices_irregular
,
current_mesh
->
buffers
[
0
]
->
vertices
,
regular
,
irregular
);
QVector
<
Triangle
>
regular
;
findRegular
(
current_mesh
->
buffers
[
0
]
->
indices_regular
,
current_mesh
->
buffers
[
0
]
->
vertices
,
regular
,
irregular
);
QVector
<
Triangle
>
irregular
;
findRegular
(
all_triangles
,
neighbors
,
regular
,
irregular
);
QVector
<
unsigned
int
>
patches
=
getPatchIndexBuffer
(
regular
,
irregular
,
current_mesh
->
buffers
[
0
]
->
vertices
);
//TODO is this the corret vertex buffer?
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_regular
=
patches
;
current_mesh
->
buffers
[
0
]
->
indices_irregular
=
irregular
;
current_mesh
->
buffers
[
0
]
->
indices_irregular
=
irregular
_ib
;
current_mesh
->
buffers
[
0
]
->
updateIndices
();
current_mesh
->
buffers
[
0
]
->
updateIndices
();
...
@@ -759,50 +798,44 @@ QVector<unsigned int> Subdivision::patchIBToTriangleIB(QVector<unsigned int> ib)
...
@@ -759,50 +798,44 @@ QVector<unsigned int> Subdivision::patchIBToTriangleIB(QVector<unsigned int> ib)
return
new_ib
;
return
new_ib
;
}
}
/**
bool
isVertexRegular
(
Triangle
&
triangle
,
Triangle
::
Neighbor
current_neighbor
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
)
{
* Generates index buffers containing all regular and all irregular triangles in the input index buffer.
unsigned
int
count
=
1
;
*
while
(
count
<
6
&&
*
current_neighbor
.
triangle
!=
triangle
)
{
* @param index_buffer Index buffer describing triangles.
count
++
;
* @param vertex_buffer Vertices used by index_buffer.
current_neighbor
=
neighbors
.
value
(
*
current_neighbor
.
triangle
).
get_neighbor
(
rotate_edge_name
(
current_neighbor
.
edge
.
name
));
* @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
]])){
return
count
==
6
&&
*
current_neighbor
.
triangle
==
triangle
;
county
++
;
}
}
if
(
vz
.
samePos
(
vertex_buffer
[
index_buffer
[
j
]])){
void
Subdivision
::
findRegular
(
QVector
<
Triangle
>
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
,
QVector
<
Triangle
>
&
regular
,
QVector
<
Triangle
>
&
irregular
)
{
countz
++
;
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
(
is_regular
&&
!
isVertexRegular
(
triangle
,
ns
.
wu
,
neighbors
))
{
is_regular
=
false
;
}
}
if
(
countx
==
5
&&
county
==
5
&&
countz
==
5
){
regular
.
push_back
(
index_buffer
[
i
]);
if
(
is_regular
)
{
regular
.
push_back
(
index_buffer
[
i
+
1
]);
regular
.
push_back
(
triangle
);
regular
.
push_back
(
index_buffer
[
i
+
2
]);
}
else
{
}
else
{
irregular
.
push_back
(
index_buffer
[
i
]);
irregular
.
push_back
(
triangle
);
irregular
.
push_back
(
index_buffer
[
i
+
1
]);
irregular
.
push_back
(
index_buffer
[
i
+
2
]);
}
}
}
}
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
)
{
Subdivision
::
Result
Subdivision
::
runShader
(
Input
input
,
Tables
&
tables
)
{
...
...
QTProject/subdivision.h
View file @
d029fb25
...
@@ -62,7 +62,7 @@ private:
...
@@ -62,7 +62,7 @@ private:
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
);
void
precomputeVertexTable
(
Subdivision
::
Tables
&
tables
,
Input
&
input
,
QMap
<
unsigned
int
,
unsigned
int
>
&
modified_vertices
);
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
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
);
Result
runShader
(
Input
input
,
Tables
&
tables
);
void
runCopyShader
(
GLuint
size
,
GLuint
vb_in
,
GLuint
vb_out
);
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
);
void
runVertexShader
(
GLuint
size
,
GLuint
vb_handle
,
GLuint
vertex_indices_handle
,
GLuint
vertex_offsets_handle
,
GLuint
output_handle
,
GLuint
offset_handle
);
...
...
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