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
acadd249
Commit
acadd249
authored
Jul 01, 2018
by
Philip Trettner
Browse files
working on smart ranges
parent
bed5c608
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/polymesh/algorithms/properties.hh
View file @
acadd249
...
...
@@ -16,6 +16,9 @@
// - vertex normal
// - curvature
// - topological properties
//
// Note: unary properties should be usable as free functions OR as index into handles
// e.g. valence(v) is the same as v[valence]
namespace
polymesh
{
/// returns true if the vertex lies at a boundary
...
...
@@ -33,7 +36,7 @@ bool is_isolated(vertex_handle v);
bool
is_isolated
(
edge_handle
v
);
/// returns the vertex valence (number of adjacent vertices)
int
valence
_of
(
vertex_handle
v
);
int
valence
(
vertex_handle
v
);
/// returns the area of the (flat) polygonal face
template
<
class
Vec3
>
...
...
@@ -65,7 +68,7 @@ inline bool is_isolated(vertex_handle v) { return v.is_isolated(); }
inline
bool
is_isolated
(
edge_handle
v
)
{
return
v
.
is_isolated
();
}
inline
int
valence
_of
(
vertex_handle
v
)
{
return
v
.
adjacent_vertices
().
size
();
}
inline
int
valence
(
vertex_handle
v
)
{
return
v
.
adjacent_vertices
().
size
();
}
template
<
class
Vec3
>
typename
field_3d
<
Vec3
>::
Scalar
triangle_area
(
face_handle
f
,
vertex_attribute
<
Vec3
>
const
&
position
)
...
...
src/polymesh/impl/impl_ranges.hh
View file @
acadd249
...
...
@@ -4,33 +4,33 @@
namespace
polymesh
{
template
<
class
this_t
,
class
tag
>
typename
smart_range
<
this_t
,
tag
>::
handle
smart_range
<
this_t
,
tag
>::
first
()
const
template
<
class
this_t
,
class
ElementT
>
ElementT
smart_range
<
this_t
,
ElementT
>::
first
()
const
{
for
(
auto
h
:
static_cast
<
this_t
const
*>
(
this
))
return
h
;
return
handle
::
invalid
()
;
return
{}
;
}
template
<
class
this_t
,
class
tag
>
typename
smart_range
<
this_t
,
tag
>::
handle
smart_range
<
this_t
,
tag
>::
last
()
const
template
<
class
this_t
,
class
ElementT
>
ElementT
smart_range
<
this_t
,
ElementT
>::
last
()
const
{
handle
result
;
ElementT
result
;
for
(
auto
h
:
static_cast
<
this_t
const
*>
(
this
))
result
=
h
;
return
result
;
}
template
<
class
this_t
,
class
tag
>
bool
smart_range
<
this_t
,
tag
>::
any
()
const
template
<
class
this_t
,
class
ElementT
>
bool
smart_range
<
this_t
,
ElementT
>::
any
()
const
{
for
(
auto
h
:
static_cast
<
this_t
const
*>
(
this
))
return
true
;
return
false
;
}
template
<
class
this_t
,
class
tag
>
template
<
typename
PredT
>
bool
smart_range
<
this_t
,
tag
>::
any
(
PredT
&&
p
)
const
template
<
class
this_t
,
class
ElementT
>
template
<
class
PredT
>
bool
smart_range
<
this_t
,
ElementT
>::
any
(
PredT
&&
p
)
const
{
for
(
auto
h
:
static_cast
<
this_t
const
*>
(
this
))
if
(
p
(
h
))
...
...
@@ -38,8 +38,18 @@ bool smart_range<this_t, tag>::any(PredT&& p) const
return
false
;
}
template
<
class
this_t
,
class
tag
>
int
smart_range
<
this_t
,
tag
>::
count
()
const
template
<
class
this_t
,
class
ElementT
>
template
<
class
PredT
>
bool
smart_range
<
this_t
,
ElementT
>::
all
(
PredT
&&
p
)
const
{
for
(
auto
h
:
static_cast
<
this_t
const
*>
(
this
))
if
(
!
p
(
h
))
return
false
;
return
true
;
}
template
<
class
this_t
,
class
ElementT
>
int
smart_range
<
this_t
,
ElementT
>::
count
()
const
{
auto
cnt
=
0
;
for
(
auto
h
:
static_cast
<
this_t
const
*>
(
this
))
...
...
src/polymesh/ranges.hh
View file @
acadd249
...
...
@@ -7,40 +7,43 @@
namespace
polymesh
{
template
<
class
T
>
struct
aabb
{
T
min
;
T
max
;
};
template
<
class
this_t
,
class
tag
>
template
<
class
this_t
,
class
ElementT
>
struct
smart_range
{
template
<
class
AttrT
>
using
attribute
=
typename
primitive
<
tag
>::
template
attribute
<
AttrT
>;
using
handle
=
typename
primitive
<
tag
>::
handle
;
/// returns the first element in this range
/// returns invalid on empty ranges
handle
first
()
const
;
/// returns the last element in this range
/// returns invalid on empty ranges
/// returns invalid on empty ranges
(or default ctor'd one)
ElementT
first
()
const
;
/// returns the last element in this range
/// returns invalid on empty ranges
(or default ctor'd one)
/// TODO: how to make this O(1)
handle
last
()
const
;
ElementT
last
()
const
;
/// returns true if the range is non-empty
bool
any
()
const
;
/// returns true if any handle fulfils p(h)
template
<
typename
PredT
>
/// also works for boolean attributes
template
<
class
PredT
>
bool
any
(
PredT
&&
p
)
const
;
/// returns true if any attribute is true for this range
// bool any(attribute<bool> const& a) const;
/// returns true if all handles fulfil p(h)
template
<
typename
PredT
>
/// also works for boolean attributes
template
<
class
PredT
>
bool
all
(
PredT
&&
p
)
const
;
/// returns true if all attributes are true for this range
// bool all(attribute<bool> const& a) const;
/// returns the number of elements in this range
/// NOTE: this is an O(n) operation, prefer size() if available
/// TODO: maybe SFINAE to implement this via size() if available?
int
count
()
const
;
// template<class T>
// T min() const;
// TODO:
// - average
// - sum
...
...
@@ -51,15 +54,14 @@ struct smart_range
// - map
// - skip
// - only_valid
// - count
};
// ================= COLLECTION =================
template
<
class
mesh_ptr
,
class
tag
,
class
iterator
>
struct
smart_collection
:
smart_range
<
smart_collection
<
mesh_ptr
,
tag
,
iterator
>
,
t
ag
>
struct
smart_collection
:
smart_range
<
smart_collection
<
mesh_ptr
,
tag
,
iterator
>
,
t
ypename
primitive
<
tag
>::
handle
>
{
template
<
typename
AttrT
>
template
<
class
AttrT
>
using
attribute
=
typename
primitive
<
tag
>::
template
attribute
<
AttrT
>;
/// Number of primitives, INCLUDING those marked for deletion
...
...
@@ -232,7 +234,7 @@ struct valid_halfedge_const_collection : smart_collection<Mesh const*, halfedge_
// ================= RINGS =================
template
<
class
this_t
,
class
tag
>
struct
primitive_ring
:
smart_range
<
this_t
,
t
ag
>
struct
primitive_ring
:
smart_range
<
this_t
,
t
ypename
primitive
<
tag
>::
handle
>
{
using
handle
=
typename
primitive
<
tag
>::
handle
;
...
...
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