Skip to content
GitLab
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
befd1997
Commit
befd1997
authored
Jul 23, 2018
by
Philip Trettner
Browse files
added random to ranges
parent
f587df38
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/polymesh/impl/impl_ranges.hh
View file @
befd1997
...
...
@@ -448,6 +448,23 @@ iterator smart_collection<mesh_ptr, tag, iterator>::end() const
return
{{
this
->
mesh
,
typename
primitive
<
tag
>::
index
(
primitive
<
tag
>::
all_size
(
*
this
->
mesh
))}};
}
template
<
class
mesh_ptr
,
class
tag
,
class
iterator
>
template
<
class
Generator
>
typename
primitive
<
tag
>::
handle
smart_collection
<
mesh_ptr
,
tag
,
iterator
>::
random
(
Generator
&
g
)
const
{
auto
s
=
primitive
<
tag
>::
all_size
(
*
this
->
mesh
);
assert
(
s
>
0
&&
"Cannot chose from empty mesh"
);
std
::
uniform_int_distribution
<>
uniform
(
0
,
s
-
1
);
typename
primitive
<
tag
>::
handle
h
=
{
this
->
mesh
,
typename
primitive
<
tag
>::
index
(
uniform
(
g
))};
if
(
iterator
::
is_valid_iterator
)
while
(
h
.
is_removed
())
h
=
{
this
->
mesh
,
typename
primitive
<
tag
>::
index
(
uniform
(
g
))};
return
h
;
}
template
<
class
iterator
>
void
vertex_collection
<
iterator
>::
remove
(
vertex_handle
v
)
const
{
...
...
src/polymesh/iterators.hh
View file @
befd1997
...
...
@@ -16,6 +16,9 @@ struct valid_primitive_iterator
{
using
handle_t
=
typename
primitive
<
tag
>::
handle
;
static
const
bool
is_all_iterator
=
false
;
static
const
bool
is_valid_iterator
=
true
;
valid_primitive_iterator
()
=
default
;
valid_primitive_iterator
(
handle_t
handle
)
:
handle
(
handle
)
{
this
->
handle
.
idx
=
handle
.
mesh
->
next_valid_idx_from
(
handle
.
idx
);
}
...
...
@@ -53,6 +56,9 @@ struct all_primitive_iterator
{
using
handle_t
=
typename
primitive
<
tag
>::
handle
;
static
const
bool
is_all_iterator
=
true
;
static
const
bool
is_valid_iterator
=
false
;
all_primitive_iterator
()
=
default
;
all_primitive_iterator
(
handle_t
handle
)
:
handle
(
handle
)
{}
...
...
src/polymesh/ranges.hh
View file @
befd1997
...
...
@@ -175,6 +175,12 @@ struct smart_collection : smart_range<smart_collection<mesh_ptr, tag, iterator>,
iterator
begin
()
const
;
iterator
end
()
const
;
/// returns a handle chosen uniformly at random
/// NOTE: when only valid handles are allowed, this will use rejection sampling
/// and thus get very slow if a lot of data is invalid
template
<
class
Generator
>
handle
random
(
Generator
&
g
)
const
;
protected:
/// Backreference to mesh
mesh_ptr
mesh
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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