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
da78c82d
Commit
da78c82d
authored
Sep 24, 2016
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move neighbor map generation to triangle.c
parent
272cbb7e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
37 deletions
+39
-37
subdivision.cpp
QTProject/subdivision.cpp
+2
-37
triangle.cpp
QTProject/triangle.cpp
+36
-0
triangle.h
QTProject/triangle.h
+1
-0
No files found.
QTProject/subdivision.cpp
View file @
da78c82d
...
...
@@ -100,29 +100,6 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
}
}
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
:
ns
.
uv
=
neighbor
;
break
;
case
Triangle
:
:
Edge
::
Name
::
vw
:
ns
.
vw
=
neighbor
;
break
;
case
Triangle
:
:
Edge
::
Name
::
wu
:
ns
.
wu
=
neighbor
;
break
;
default
:
qCWarning
(
log_subdiv
)
<<
"got"
<<
edge_a
.
name
<<
"as edge!"
;
break
;
}
neighbors
.
insert
(
triangle_a
,
ns
);
}
struct
Edge
{
unsigned
int
a
;
unsigned
int
b
;
...
...
@@ -195,6 +172,8 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
//Format: first two entries: edge vertices. last two entries: distant vertices.
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
;
QVector
<
Triangle
>
all_triangles
=
triangles
+
triangles_regular
;
buildNeighborsMap
(
all_triangles
,
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
;
...
...
@@ -213,20 +192,6 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
* - Each edge point will be computed twice. This allows us to implicitly know the adjacent points.
*/
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_neighbor
(
neighbors
,
*
triangle
,
edge_a
,
&
triangles
[
j
],
edge_b
);
insert_neighbor
(
neighbors
,
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_neighbor
(
neighbors
,
*
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
}
}
Triangle
::
Neighbors
ns
=
neighbors
.
value
(
*
triangle
);
// indices of the three vertices added to the edges of this triangle
...
...
QTProject/triangle.cpp
View file @
da78c82d
...
...
@@ -189,6 +189,42 @@ void ibToTriangles(QVector<Vertex> *vb, QVector<unsigned int> &ib, QVector<Trian
}
}
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
:
ns
.
uv
=
neighbor
;
break
;
case
Triangle
:
:
Edge
::
Name
::
vw
:
ns
.
vw
=
neighbor
;
break
;
case
Triangle
:
:
Edge
::
Name
::
wu
:
ns
.
wu
=
neighbor
;
break
;
}
neighbors
.
insert
(
triangle_a
,
ns
);
}
void
buildNeighborsMap
(
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
)
{
Triangle
::
Edge
edge_a
,
edge_b
;
for
(
int
i
=
0
;
i
<
triangles
.
length
();
i
++
){
Triangle
*
triangle_a
=
&
triangles
[
i
];
for
(
int
j
=
i
+
1
;
j
<
triangles
.
length
();
j
++
){
Triangle
*
triangle_b
=
&
triangles
[
j
];
if
(
triangle_a
->
get_shared_edge
(
*
triangle_b
,
edge_a
,
edge_b
))
{
insert_neighbor
(
neighbors
,
*
triangle_a
,
edge_a
,
triangle_b
,
edge_b
);
insert_neighbor
(
neighbors
,
*
triangle_b
,
edge_b
,
triangle_a
,
edge_a
);
}
}
}
}
QDebug
operator
<<
(
QDebug
d
,
const
Triangle
&
triangle
)
{
QDebugStateSaver
saver
(
d
);
d
.
nospace
()
<<
"Triangle("
<<
triangle
.
u_idx
()
<<
", "
<<
triangle
.
v_idx
()
<<
", "
<<
triangle
.
w_idx
()
<<
"; "
<<
triangle
.
u
().
pos
<<
", "
<<
triangle
.
v
().
pos
<<
", "
<<
triangle
.
w
().
pos
<<
")"
;
...
...
QTProject/triangle.h
View file @
da78c82d
...
...
@@ -69,6 +69,7 @@ class Triangle {
};
void
ibToTriangles
(
QVector
<
Vertex
>
*
vb
,
QVector
<
unsigned
int
>
&
ib
,
QVector
<
Triangle
>
&
triangles
);
void
buildNeighborsMap
(
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
);
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