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
1a3b3656
Commit
1a3b3656
authored
Sep 27, 2016
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1-irregulare-dreiecke-und-patches-sind-nicht-verbunden' into 'patchRender'
Resolve "Irreguläre Dreiecke und Patches sind nicht verbunden" Closes
#1
See merge request
!10
parents
2d5d8f0f
8c518806
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
94 additions
and
11 deletions
+94
-11
Subdivision.pro
QTProject/Subdivision.pro
+1
-1
main.cpp
QTProject/main.cpp
+1
-1
mainwidget.cpp
QTProject/mainwidget.cpp
+2
-1
mesh.cpp
QTProject/mesh.cpp
+12
-5
mesh.h
QTProject/mesh.h
+4
-2
subdivision.cpp
QTProject/subdivision.cpp
+68
-1
subdivision.h
QTProject/subdivision.h
+6
-0
No files found.
QTProject/Subdivision.pro
View file @
1a3b3656
...
...
@@ -8,7 +8,7 @@ QT += core gui opengl
greaterThan
(
QT_MAJOR_VERSION
,
4
)
:
QT
+=
widgets
CONFIG
+=
c
++
11
CONFIG
+=
c
++
11
debug
TARGET
=
Subdivision
TEMPLATE
=
app
...
...
QTProject/main.cpp
View file @
1a3b3656
...
...
@@ -6,7 +6,7 @@ int main(int argc, char *argv[])
{
QApplication
a
(
argc
,
argv
);
QLoggingCategory
::
setFilterRules
(
"timing.debug=true
\n
"
"mesh.debug=
fals
e
\n
"
"mesh.debug=
tru
e
\n
"
"mesh.render.debug=false
\n
"
"subdiv.debug=true
\n
"
"subdiv.trace.debug=false
\n
"
);
...
...
QTProject/mainwidget.cpp
View file @
1a3b3656
...
...
@@ -145,7 +145,8 @@ void MainWidget::initializeGL(){
subdivision
->
init
();
//loadNewMesh( "../Models/demon_head.3ds");
loadNewMesh
(
"../Models/torus.obj"
);
// loadNewMesh( "../Models/torus.obj");
loadNewMesh
(
"../Models/box.obj"
);
}
void
MainWidget
::
loadNewMesh
(){
...
...
QTProject/mesh.cpp
View file @
1a3b3656
...
...
@@ -4,6 +4,7 @@
Mesh
::
SubdivEntry
::
SubdivEntry
()
{
VB_handle
=
0xFFFFFFFF
;
VB_handle_irregular
=
0xFFFFFFFF
;
IB_irregular_handle
=
0xFFFFFFFF
;
IB_regular_handle
=
0xFFFFFFFF
;
}
...
...
@@ -39,10 +40,10 @@ 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
);
QVector
<
unsigned
int
>
patches
;
this
->
init
(
f
,
VB_handle
,
Vertices
,
Indices_irregular
,
patches
);
this
->
init
(
f
,
VB_handle
,
Vertices
,
Vertices
,
Indices_irregular
,
patches
);
}
void
Mesh
::
SubdivEntry
::
init
(
QOpenGLFunctions_4_3_Core
*
f
,
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
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
){
this
->
f
=
f
;
this
->
VB_handle
=
VB_handle
;
...
...
@@ -52,9 +53,15 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVe
indices_regular
=
patches
;
qCDebug
(
log_mesh
)
<<
"Vertices"
<<
vertices
.
length
();
qCDebug
(
log_mesh
)
<<
"Vertices Irregular"
<<
Vertices_irregular
.
length
();
qCDebug
(
log_mesh
)
<<
"Indices irregular"
<<
indices_irregular
.
length
();
qCDebug
(
log_mesh
)
<<
"Indices patches"
<<
patches
.
length
();
f
->
glGenBuffers
(
1
,
&
VB_handle_irregular
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
VB_handle_irregular
);
if
(
Vertices_irregular
.
size
()
!=
0
)
f
->
glBufferData
(
GL_ELEMENT_ARRAY_BUFFER
,
sizeof
(
Vertex
)
*
Vertices_irregular
.
size
(),
&
Vertices_irregular
[
0
],
GL_STATIC_DRAW
);
f
->
glGenBuffers
(
1
,
&
IB_irregular_handle
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
IB_irregular_handle
);
if
(
indices_irregular
.
size
()
!=
0
)
...
...
@@ -96,10 +103,10 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
}
}
void
Mesh
::
MeshEntry
::
update
(
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
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
)
{
SubdivEntry
*
entry
=
new
SubdivEntry
;
buffers
.
push_back
(
std
::
shared_ptr
<
SubdivEntry
>
(
entry
));
entry
->
init
(
f
,
VB_handle
,
Vertices
,
Indices_irregular
,
patches
);
entry
->
init
(
f
,
VB_handle
,
Vertices
,
Vertices_Irregular
,
Indices_irregular
,
patches
);
}
Mesh
::
MeshEntry
::~
MeshEntry
()
...
...
@@ -481,7 +488,7 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision,
}
}
else
{
if
(
!
entry
->
indices_irregular
.
isEmpty
())
{
f
->
glBindBuffer
(
GL_ARRAY_BUFFER
,
entry
->
VB_handle
);
f
->
glBindBuffer
(
GL_ARRAY_BUFFER
,
entry
->
VB_handle
_irregular
);
f
->
glVertexAttribPointer
(
positionIndex
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
0
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
entry
->
IB_irregular_handle
);
...
...
QTProject/mesh.h
View file @
1a3b3656
...
...
@@ -32,11 +32,13 @@ public:
SubdivEntry
();
~
SubdivEntry
();
GLuint
VB_handle
;
GLuint
VB_handle_irregular
;
GLuint
IB_irregular_handle
;
GLuint
IB_regular_handle
;
QVector
<
Vertex
>
vertices
;
QVector
<
Vertex
>
vertices_irregular
;
QVector
<
unsigned
int
>
indices_irregular
;
QVector
<
unsigned
int
>
indices_regular
;
...
...
@@ -44,7 +46,7 @@ public:
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
unsigned
int
>&
Indices_irregular
);
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
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
);
void
updateIndices
();
};
...
...
@@ -54,7 +56,7 @@ public:
~
MeshEntry
();
void
init
(
QOpenGLFunctions_4_3_Core
*
f
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
unsigned
int
>&
Indices
);
void
update
(
GLuint
VB_handle
,
QVector
<
Vertex
>&
Vertices
,
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
);
QString
name
;
...
...
QTProject/subdivision.cpp
View file @
1a3b3656
...
...
@@ -109,11 +109,13 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
QVector
<
unsigned
int
>
irregular_ib
;
trianglesToIB
(
irregular
,
irregular_ib
);
updateIrregularForDraw
(
irregular
,
neighbors
,
result
);
QVector
<
unsigned
int
>
patches
;
getPatchIndexBuffer
(
regular
,
neighbors
,
patches
);
qCDebug
(
log_subdiv
)
<<
"patches"
<<
patches
.
length
();
current_mesh
->
update
(
result
.
vb_handle
,
result
.
vertex_buffer
,
irregular_ib
,
patches
);
current_mesh
->
update
(
result
.
vb_handle
,
result
.
vertex_buffer
,
result
.
vertex_buffer_irregular
,
irregular_ib
,
patches
);
}
}
...
...
@@ -1037,3 +1039,68 @@ void Subdivision::runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indic
edgeShader
->
release
();
}
QVector3D
Subdivision
::
updateIrregularVertexForDraw
(
Vertex
currentCorner
,
QVector
<
Triangle
>
neighboring_triangles
)
{
QVector
<
Vertex
>
surroundingVertex
;
QVectorIterator
<
Triangle
>
extra
(
neighboring_triangles
);
while
(
extra
.
hasNext
())
{
Triangle
extra_triangle
=
extra
.
next
();
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
);
double
n
=
surroundingVertex
.
length
();
double
a
=
5.0
/
8.0
-
pow
((
3.0
/
8.0
+
2.0
/
8.0
*
cos
(
2.0
*
M_PI
/
n
)),
2.0
);
double
omega
=
3.0
*
n
/
(
8.0
*
a
);
for
(
int
i
=
0
;
i
<
surroundingVertex
.
length
();
i
++
)
{
newPos
+=
surroundingVertex
[
i
].
pos
;
}
newPos
*=
1.0
/
(
omega
+
n
);
newPos
+=
omega
/
(
omega
+
n
)
*
currentCorner
.
pos
;
return
newPos
;
}
void
Subdivision
::
updateIrregularForDraw
(
const
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
Result
&
result
){
result
.
vertex_buffer_irregular
.
resize
(
result
.
vertex_buffer
.
size
());
QVectorIterator
<
Triangle
>
it
(
triangles
);
while
(
it
.
hasNext
())
{
Triangle
triangle
=
it
.
next
();
Triangle
::
Neighbors
ns
=
neighbors
.
value
(
triangle
);
// u
QVector3D
new_u_pos
=
updateIrregularVertexForDraw
(
triangle
.
u
(),
vertexNeighbors
(
triangle
,
ns
.
uv
,
neighbors
));
//v
QVector3D
new_v_pos
=
updateIrregularVertexForDraw
(
triangle
.
v
(),
vertexNeighbors
(
triangle
,
ns
.
vw
,
neighbors
));
//w
QVector3D
new_w_pos
=
updateIrregularVertexForDraw
(
triangle
.
w
(),
vertexNeighbors
(
triangle
,
ns
.
wu
,
neighbors
));
result
.
vertex_buffer_irregular
[
triangle
.
u_idx
()]
=
result
.
vertex_buffer
.
at
(
triangle
.
u_idx
());
result
.
vertex_buffer_irregular
[
triangle
.
u_idx
()].
pos
=
new_u_pos
;
result
.
vertex_buffer_irregular
[
triangle
.
v_idx
()]
=
result
.
vertex_buffer
.
at
(
triangle
.
v_idx
());
result
.
vertex_buffer_irregular
[
triangle
.
v_idx
()].
pos
=
new_v_pos
;
result
.
vertex_buffer_irregular
[
triangle
.
w_idx
()]
=
result
.
vertex_buffer
.
at
(
triangle
.
w_idx
());
result
.
vertex_buffer_irregular
[
triangle
.
w_idx
()].
pos
=
new_w_pos
;
}
}
bool
Subdivision
::
containsVertex
(
QVector
<
Vertex
>
&
vertices
,
Vertex
vertex
)
{
for
(
int
i
=
0
;
i
<
vertices
.
length
();
i
++
)
{
if
(
vertex
.
samePos
(
vertices
[
i
]))
{
return
true
;
}
}
return
false
;
}
QTProject/subdivision.h
View file @
1a3b3656
...
...
@@ -41,6 +41,7 @@ private:
{
GLuint
vb_handle
;
QVector
<
Vertex
>
vertex_buffer
;
QVector
<
Vertex
>
vertex_buffer_irregular
;
};
struct
Patch
...
...
@@ -69,6 +70,11 @@ private:
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
runEdgeShader
(
GLuint
size
,
GLuint
vb_handle
,
GLuint
edge_indices_handle
,
GLuint
output_handle
,
GLuint
offset_handle
);
QVector3D
updateIrregularVertexForDraw
(
Vertex
currentCorner
,
QVector
<
Triangle
>
neighboring_triangles
);
void
updateIrregularForDraw
(
const
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
Result
&
result
);
bool
containsVertex
(
QVector
<
Vertex
>
&
vertices
,
Vertex
vertex
);
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