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
272cbb7e
Commit
272cbb7e
authored
Sep 24, 2016
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add neighbors struct
parent
49e0acb1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
20 deletions
+26
-20
subdivision.cpp
QTProject/subdivision.cpp
+20
-20
triangle.h
QTProject/triangle.h
+6
-0
No files found.
QTProject/subdivision.cpp
View file @
272cbb7e
...
...
@@ -100,25 +100,27 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
}
}
void
insert_edge
(
QMap
<
Triangle
,
QVector
<
Triangle
::
Neighbor
>>
&
opposite_edges
,
const
Triangle
&
triangle_a
,
const
Triangle
::
Edge
&
edge_a
,
Triangle
*
triangle_b
,
const
Triangle
::
Edge
&
edge_b
)
{
QVector
<
Triangle
::
Neighbor
>
edges
=
opposite_edges
.
value
(
triangle_a
,
QVector
<
Triangle
::
Neighbor
>
());
edges
.
resize
(
3
);
void
insert_neighbor
(
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
const
Triangle
&
triangle_a
,
const
Triangle
::
Edge
&
edge_a
,
Triangle
*
triangle_b
,
const
Triangle
::
Edge
&
edge_b
)
{
if
(
!
neighbors
.
contains
(
triangle_a
))
{
neighbors
.
insert
(
triangle_a
,
Triangle
::
Neighbors
());
}
Triangle
::
Neighbors
&
ns
=
neighbors
[
triangle_a
];
Triangle
::
Neighbor
neighbor
=
{
triangle_b
,
edge_b
};
switch
(
edge_a
.
name
)
{
case
Triangle
:
:
Edge
::
Name
::
uv
:
edges
[
0
]
=
neighbor
;
ns
.
uv
=
neighbor
;
break
;
case
Triangle
:
:
Edge
::
Name
::
vw
:
edges
[
1
]
=
neighbor
;
ns
.
vw
=
neighbor
;
break
;
case
Triangle
:
:
Edge
::
Name
::
wu
:
edges
[
2
]
=
neighbor
;
ns
.
wu
=
neighbor
;
break
;
default
:
qCWarning
(
log_subdiv
)
<<
"got"
<<
edge_a
.
name
<<
"as edge!"
;
break
;
}
opposite_edges
.
insert
(
triangle_a
,
edge
s
);
neighbors
.
insert
(
triangle_a
,
n
s
);
}
struct
Edge
{
...
...
@@ -192,9 +194,7 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
//compute edge table
//Format: first two entries: edge vertices. last two entries: distant vertices.
// for each triangle the edges of the neighbor triangles are stored.
// First the edge shared with the triangles uv edge, then vw and wu.
QMap
<
Triangle
,
QVector
<
Triangle
::
Neighbor
>>
opposite_edges
;
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
;
// Maps edges to the index of the new vertex added on that edge. The keys are the indices of the two vertices defining the edge and must be in the order uv, vw or uw.
QMap
<
Edge
,
unsigned
int
>
edge_indices
;
...
...
@@ -216,18 +216,18 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
Triangle
::
Edge
edge_a
,
edge_b
;
for
(
int
j
=
i
+
1
;
j
<
triangles
.
length
();
j
++
){
if
(
triangle
->
get_shared_edge
(
triangles
[
j
],
edge_a
,
edge_b
))
{
insert_
edge
(
opposite_edge
s
,
*
triangle
,
edge_a
,
&
triangles
[
j
],
edge_b
);
insert_
edge
(
opposite_edge
s
,
triangles
[
j
],
edge_b
,
triangle
,
edge_a
);
insert_
neighbor
(
neighbor
s
,
*
triangle
,
edge_a
,
&
triangles
[
j
],
edge_b
);
insert_
neighbor
(
neighbor
s
,
triangles
[
j
],
edge_b
,
triangle
,
edge_a
);
}
}
for
(
int
j
=
0
;
j
<
triangles_regular
.
length
();
j
++
){
if
(
triangle
->
get_shared_edge
(
triangles_regular
[
j
],
edge_a
,
edge_b
))
{
insert_
edge
(
opposite_edge
s
,
*
triangle
,
edge_a
,
&
triangles_regular
[
j
],
edge_b
);
insert_
neighbor
(
neighbor
s
,
*
triangle
,
edge_a
,
&
triangles_regular
[
j
],
edge_b
);
// no need to insert the opposite edge of a regular triangle - it won't be processed by the outer loop
}
}
QVector
<
Triangle
::
Neighbor
>
opposite
=
opposite_edge
s
.
value
(
*
triangle
);
Triangle
::
Neighbors
ns
=
neighbor
s
.
value
(
*
triangle
);
// indices of the three vertices added to the edges of this triangle
unsigned
int
uv
,
vw
,
wu
;
...
...
@@ -241,13 +241,13 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
uv
=
offset
++
;
edge_indices
.
insert
(
edge
,
uv
);
edge
=
{
opposite
[
0
].
edge
.
a
,
opposite
[
0
]
.
edge
.
b
};
edge
=
{
ns
.
uv
.
edge
.
a
,
ns
.
uv
.
edge
.
b
};
edge_indices
.
insert
(
edge
,
uv
);
tables
.
edge_indices
.
push_back
(
triangle
->
u_idx
());
tables
.
edge_indices
.
push_back
(
triangle
->
v_idx
());
tables
.
edge_indices
.
push_back
(
triangle
->
w_idx
());
tables
.
edge_indices
.
push_back
(
opposite
[
0
]
.
edge
.
c
);
tables
.
edge_indices
.
push_back
(
ns
.
uv
.
edge
.
c
);
}
edge
=
{
triangle
->
v_idx
(),
triangle
->
w_idx
()
};
...
...
@@ -257,13 +257,13 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
vw
=
offset
++
;
edge_indices
.
insert
(
edge
,
vw
);
edge
=
{
opposite
[
1
].
edge
.
a
,
opposite
[
1
]
.
edge
.
b
};
edge
=
{
ns
.
vw
.
edge
.
a
,
ns
.
vw
.
edge
.
b
};
edge_indices
.
insert
(
edge
,
vw
);
tables
.
edge_indices
.
push_back
(
triangle
->
v_idx
());
tables
.
edge_indices
.
push_back
(
triangle
->
w_idx
());
tables
.
edge_indices
.
push_back
(
triangle
->
u_idx
());
tables
.
edge_indices
.
push_back
(
opposite
[
1
]
.
edge
.
c
);
tables
.
edge_indices
.
push_back
(
ns
.
vw
.
edge
.
c
);
}
edge
=
{
triangle
->
w_idx
(),
triangle
->
u_idx
()
};
...
...
@@ -273,13 +273,13 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
wu
=
offset
++
;
edge_indices
.
insert
(
edge
,
wu
);
edge
=
{
opposite
[
2
].
edge
.
a
,
opposite
[
2
]
.
edge
.
b
};
edge
=
{
ns
.
wu
.
edge
.
a
,
ns
.
wu
.
edge
.
b
};
edge_indices
.
insert
(
edge
,
wu
);
tables
.
edge_indices
.
push_back
(
triangle
->
w_idx
());
tables
.
edge_indices
.
push_back
(
triangle
->
u_idx
());
tables
.
edge_indices
.
push_back
(
triangle
->
v_idx
());
tables
.
edge_indices
.
push_back
(
opposite
[
2
]
.
edge
.
c
);
tables
.
edge_indices
.
push_back
(
ns
.
wu
.
edge
.
c
);
}
//add indices to new index buffer
...
...
QTProject/triangle.h
View file @
272cbb7e
...
...
@@ -26,6 +26,12 @@ class Triangle {
Edge
edge
;
};
struct
Neighbors
{
Neighbor
uv
;
Neighbor
vw
;
Neighbor
wu
;
};
Triangle
();
Triangle
(
const
Triangle
&
other
);
Triangle
(
const
QVector
<
Vertex
>
*
vertex_buffer
,
unsigned
int
u
,
unsigned
int
v
,
unsigned
int
w
);
...
...
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