Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Philip Trettner
polymesh
Commits
209097ab
Commit
209097ab
authored
Jun 25, 2018
by
Philip Trettner
Browse files
refactored access to internal information structs
parent
5dc77e5d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/polymesh/Mesh.hh
View file @
209097ab
...
...
@@ -204,13 +204,13 @@ private:
halfedge_index
halfedge_of
(
edge_index
idx
,
int
i
)
const
{
return
halfedge_index
((
idx
.
value
<<
1
)
+
i
);
}
/// returns the vertex that this half-edge is pointing to
vertex_index
to_vertex_of
(
halfedge_index
idx
)
const
{
return
mH
alfedge
s
[
idx
.
value
]
.
to_vertex
;
}
vertex_index
to_vertex_of
(
halfedge_index
idx
)
const
{
return
h
alfedge
(
idx
)
.
to_vertex
;
}
/// returns the vertex that this half-edge is leaving from
vertex_index
from_vertex_of
(
halfedge_index
idx
)
const
{
return
mH
alfedge
s
[
opposite
(
idx
)
.
value
]
.
to_vertex
;
}
vertex_index
from_vertex_of
(
halfedge_index
idx
)
const
{
return
h
alfedge
(
opposite
(
idx
)
)
.
to_vertex
;
}
// internal datastructures
private:
struct
face
struct
face
_info
{
halfedge_index
halfedge
;
///< one half-edge bounding this face
...
...
@@ -218,7 +218,7 @@ private:
void
set_deleted
()
{
halfedge
=
halfedge_index
::
invalid
();
}
};
struct
vertex
struct
vertex
_info
{
halfedge_index
outgoing_halfedge
;
...
...
@@ -229,7 +229,7 @@ private:
// is_boundary: check if outgoing_halfedge is boundary
};
struct
halfedge
struct
halfedge
_info
{
vertex_index
to_vertex
;
///< half-edge points towards this vertex
face_index
face
;
///< might be invalid if boundary
...
...
@@ -249,9 +249,18 @@ private:
// internal primitives
private:
std
::
vector
<
face
>
mFaces
;
std
::
vector
<
vertex
>
mVertices
;
std
::
vector
<
halfedge
>
mHalfedges
;
std
::
vector
<
face_info
>
mFaces
;
std
::
vector
<
vertex_info
>
mVertices
;
std
::
vector
<
halfedge_info
>
mHalfedges
;
struct
face_info
&
face
(
face_index
i
)
{
return
mFaces
[
i
.
value
];
}
struct
face_info
const
&
face
(
face_index
i
)
const
{
return
mFaces
[
i
.
value
];
}
struct
vertex_info
&
vertex
(
vertex_index
i
)
{
return
mVertices
[
i
.
value
];
}
struct
vertex_info
const
&
vertex
(
vertex_index
i
)
const
{
return
mVertices
[
i
.
value
];
}
struct
halfedge_info
&
halfedge
(
halfedge_index
i
)
{
return
mHalfedges
[
i
.
value
];
}
struct
halfedge_info
const
&
halfedge
(
halfedge_index
i
)
const
{
return
mHalfedges
[
i
.
value
];
}
struct
halfedge_info
&
halfedge
(
edge_index
i
,
int
h
)
{
return
mHalfedges
[(
i
.
value
>>
1
)
+
h
];
}
struct
halfedge_info
const
&
halfedge
(
edge_index
i
,
int
h
)
const
{
return
mHalfedges
[(
i
.
value
>>
1
)
+
h
];
}
// internal state
private:
...
...
@@ -300,7 +309,7 @@ inline vertex_index Mesh::add_vertex()
/// TODO: properties
auto
idx
=
vertex_index
((
int
)
mVertices
.
size
());
mVertices
.
push_back
(
vertex
());
mVertices
.
push_back
(
vertex
_info
());
return
idx
;
}
...
...
@@ -344,17 +353,17 @@ inline face_index Mesh::add_face(const halfedge_index *half_loop, size_t vcnt)
// half-edge must form a chain
assert
(
to_vertex_of
(
h0
)
==
from_vertex_of
(
h1
));
// half-edge must be free, i.e. allow a new polygon
assert
(
mH
alfedge
s
[
h0
.
value
]
.
is_free
());
assert
(
h
alfedge
(
h0
)
.
is_free
());
// make them adjacent
make_adjacent
(
h0
,
h1
);
// link face
mH
alfedge
s
[
h0
.
value
]
.
face
=
fidx
;
h
alfedge
(
h0
)
.
face
=
fidx
;
}
// set up face data
face
f
;
face
_info
f
;
f
.
halfedge
=
half_loop
[
0
];
mFaces
.
push_back
(
f
);
...
...
@@ -370,16 +379,16 @@ inline edge_index Mesh::add_or_get_edge(vertex_index v_from, vertex_index v_to)
if
(
he
.
is_valid
())
return
edge_of
(
he
);
auto
&
vd_from
=
mV
ert
ices
[
v_from
.
value
]
;
auto
&
vd_to
=
mV
ert
ices
[
v_to
.
value
]
;
auto
&
vd_from
=
v
ert
ex
(
v_from
)
;
auto
&
vd_to
=
v
ert
ex
(
v_to
)
;
// allocate new
auto
he_size
=
(
int
)
mHalfedges
.
size
();
auto
h_from_to_idx
=
halfedge_index
(
he_size
+
0
);
auto
h_to_from_idx
=
halfedge_index
(
he_size
+
1
);
auto
eidx
=
edge_index
(
he_size
>>
1
);
halfedge
h_from_to
;
halfedge
h_to_from
;
halfedge
_info
h_from_to
;
halfedge
_info
h_to_from
;
// setup data (self-connected edge)
h_from_to
.
to_vertex
=
v_to
;
...
...
@@ -394,9 +403,9 @@ inline edge_index Mesh::add_or_get_edge(vertex_index v_from, vertex_index v_to)
{
auto
from_in_idx
=
find_free_incident
(
v_from
);
assert
(
from_in_idx
.
is_valid
()
&&
"vertex is already fully connected"
);
auto
&
from_in
=
mH
alfedge
s
[
from_in_idx
.
value
]
;
auto
&
from_in
=
h
alfedge
(
from_in_idx
)
;
auto
from_out_idx
=
from_in
.
next_halfedge
;
auto
&
from_out
=
mH
alfedge
s
[
from_out_idx
.
value
]
;
auto
&
from_out
=
h
alfedge
(
from_out_idx
)
;
from_in
.
next_halfedge
=
h_from_to_idx
;
h_from_to
.
prev_halfedge
=
from_in_idx
;
...
...
@@ -412,9 +421,9 @@ inline edge_index Mesh::add_or_get_edge(vertex_index v_from, vertex_index v_to)
{
auto
to_in_idx
=
find_free_incident
(
v_to
);
assert
(
to_in_idx
.
is_valid
()
&&
"vertex is already fully connected"
);
auto
&
to_in
=
mH
alfedge
s
[
to_in_idx
.
value
]
;
auto
&
to_in
=
h
alfedge
(
to_in_idx
)
;
auto
to_out_idx
=
to_in
.
next_halfedge
;
auto
&
to_out
=
mH
alfedge
s
[
to_out_idx
.
value
]
;
auto
&
to_out
=
h
alfedge
(
to_out_idx
)
;
to_in
.
next_halfedge
=
h_to_from_idx
;
h_to_from
.
prev_halfedge
=
to_in_idx
;
...
...
@@ -434,14 +443,14 @@ inline halfedge_index Mesh::add_or_get_halfedge(vertex_index v_from, vertex_inde
auto
e
=
add_or_get_edge
(
v_from
,
v_to
);
auto
h0
=
halfedge_of
(
e
,
0
);
auto
h1
=
halfedge_of
(
e
,
1
);
return
mH
alfedge
s
[
h0
.
value
]
.
to_vertex
==
v_to
?
h0
:
h1
;
return
h
alfedge
(
h0
)
.
to_vertex
==
v_to
?
h0
:
h1
;
}
inline
void
Mesh
::
make_adjacent
(
halfedge_index
he_in
,
halfedge_index
he_out
)
{
// see http://kaba.hilvi.org/homepage/blog/halfedge/halfedge.htm ::makeAdjacent
auto
&
in
=
mH
alfedge
s
[
he_in
.
value
]
;
auto
&
out
=
mH
alfedge
s
[
he_out
.
value
]
;
auto
&
in
=
h
alfedge
(
he_in
)
;
auto
&
out
=
h
alfedge
(
he_out
)
;
auto
he_b
=
in
.
next_halfedge
;
auto
he_d
=
out
.
prev_halfedge
;
...
...
@@ -454,12 +463,12 @@ inline void Mesh::make_adjacent(halfedge_index he_in, halfedge_index he_out)
auto
he_g
=
find_free_incident
(
opposite
(
he_out
),
he_in
);
assert
(
he_g
.
is_valid
());
// unable to make adjacent
auto
&
b
=
mH
alfedge
s
[
he_b
.
value
]
;
auto
&
d
=
mH
alfedge
s
[
he_d
.
value
]
;
auto
&
g
=
mH
alfedge
s
[
he_g
.
value
]
;
auto
&
b
=
h
alfedge
(
he_b
)
;
auto
&
d
=
h
alfedge
(
he_d
)
;
auto
&
g
=
h
alfedge
(
he_g
)
;
auto
he_h
=
g
.
next_halfedge
;
auto
&
h
=
mH
alfedge
s
[
he_d
.
value
]
;
auto
&
h
=
h
alfedge
(
he_d
)
;
// properly rewire
in
.
next_halfedge
=
he_out
;
...
...
@@ -474,13 +483,13 @@ inline void Mesh::make_adjacent(halfedge_index he_in, halfedge_index he_out)
inline
halfedge_index
Mesh
::
find_free_incident
(
halfedge_index
in_begin
,
halfedge_index
in_end
)
const
{
assert
(
mH
alfedge
s
[
in_begin
.
value
]
.
to_vertex
==
mH
alfedge
s
[
in_end
.
value
]
.
to_vertex
);
assert
(
h
alfedge
(
in_begin
)
.
to_vertex
==
h
alfedge
(
in_end
)
.
to_vertex
);
auto
he
=
in_begin
;
do
{
auto
const
&
h
=
mH
alfedge
s
[
he
.
value
]
;
assert
(
h
.
to_vertex
==
mH
alfedge
s
[
in_end
.
value
]
.
to_vertex
);
auto
const
&
h
=
h
alfedge
(
he
)
;
assert
(
h
.
to_vertex
==
h
alfedge
(
in_end
)
.
to_vertex
);
// free? found one!
if
(
h
.
is_free
())
...
...
@@ -495,20 +504,20 @@ inline halfedge_index Mesh::find_free_incident(halfedge_index in_begin, halfedge
inline
halfedge_index
Mesh
::
find_free_incident
(
vertex_index
v
)
const
{
auto
in_begin
=
opposite
(
mV
ert
ices
[
v
.
value
]
.
outgoing_halfedge
);
auto
in_begin
=
opposite
(
v
ert
ex
(
v
)
.
outgoing_halfedge
);
return
find_free_incident
(
in_begin
,
in_begin
);
}
inline
halfedge_index
Mesh
::
find_halfedge
(
vertex_index
from
,
vertex_index
to
)
const
{
auto
he_begin
=
mV
ert
ices
[
from
.
value
]
.
outgoing_halfedge
;
auto
he_begin
=
v
ert
ex
(
from
)
.
outgoing_halfedge
;
if
(
!
he_begin
.
is_valid
())
return
halfedge_index
::
invalid
();
// isolated vertex
auto
he
=
he_begin
;
do
{
auto
const
&
h
=
mH
alfedge
s
[
he
.
value
]
;
auto
const
&
h
=
h
alfedge
(
he
)
;
// found?
if
(
h
.
to_vertex
==
to
)
...
...
@@ -524,13 +533,13 @@ inline halfedge_index Mesh::find_halfedge(vertex_index from, vertex_index to) co
inline
bool
Mesh
::
is_boundary
(
vertex_index
idx
)
const
{
auto
const
&
v
=
mV
ert
ices
[
idx
.
value
]
;
auto
const
&
v
=
v
ert
ex
(
idx
)
;
return
v
.
outgoing_halfedge
.
is_valid
()
&&
is_boundary
(
v
.
outgoing_halfedge
);
}
inline
bool
Mesh
::
is_boundary
(
halfedge_index
idx
)
const
{
return
mH
alfedge
s
[
idx
.
value
]
.
is_free
();
return
h
alfedge
(
idx
)
.
is_free
();
}
inline
halfedge_index
Mesh
::
opposite
(
halfedge_index
he
)
const
...
...
@@ -952,42 +961,41 @@ inline valid_halfedge_iterator valid_halfedge_collection::end() const
inline
bool
vertex_handle
::
is_valid
()
const
{
return
idx
.
is_valid
()
&&
mesh
->
mV
ert
ices
[
idx
.
value
]
.
is_valid
();
return
idx
.
is_valid
()
&&
mesh
->
v
ert
ex
(
idx
)
.
is_valid
();
}
inline
bool
vertex_handle
::
is_deleted
()
const
{
return
!
idx
.
is_valid
()
||
!
mesh
->
mV
ert
ices
[
idx
.
value
]
.
is_valid
();
return
!
idx
.
is_valid
()
||
!
mesh
->
v
ert
ex
(
idx
)
.
is_valid
();
}
inline
bool
face_handle
::
is_valid
()
const
{
return
idx
.
is_valid
()
&&
mesh
->
mF
ace
s
[
idx
.
value
]
.
is_valid
();
return
idx
.
is_valid
()
&&
mesh
->
f
ace
(
idx
)
.
is_valid
();
}
inline
bool
face_handle
::
is_deleted
()
const
{
return
!
idx
.
is_valid
()
||
!
mesh
->
mF
ace
s
[
idx
.
value
]
.
is_valid
();
return
!
idx
.
is_valid
()
||
!
mesh
->
f
ace
(
idx
)
.
is_valid
();
}
inline
bool
edge_handle
::
is_valid
()
const
{
return
idx
.
is_valid
()
&&
mesh
->
mH
alfedge
s
[
idx
.
value
>>
1
]
.
is_valid
();
return
idx
.
is_valid
()
&&
mesh
->
h
alfedge
(
idx
,
0
)
.
is_valid
();
}
inline
bool
edge_handle
::
is_deleted
()
const
{
return
!
idx
.
is_valid
()
||
!
mesh
->
mH
alfedge
s
[
idx
.
value
>>
1
]
.
is_valid
();
return
!
idx
.
is_valid
()
||
!
mesh
->
h
alfedge
(
idx
,
0
)
.
is_valid
();
}
inline
bool
halfedge_handle
::
is_valid
()
const
{
return
idx
.
is_valid
()
&&
mesh
->
mH
alfedge
s
[
idx
.
value
]
.
is_valid
();
return
idx
.
is_valid
()
&&
mesh
->
h
alfedge
(
idx
)
.
is_valid
();
}
inline
bool
halfedge_handle
::
is_deleted
()
const
{
return
!
idx
.
is_valid
()
||
!
mesh
->
mH
alfedge
s
[
idx
.
value
]
.
is_valid
();
return
!
idx
.
is_valid
()
||
!
mesh
->
h
alfedge
(
idx
)
.
is_valid
();
}
}
Write
Preview
Supports
Markdown
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