Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polymesh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Philip Trettner
polymesh
Commits
befd1997
Commit
befd1997
authored
6 years ago
by
Philip Trettner
Browse files
Options
Downloads
Patches
Plain Diff
added random to ranges
parent
f587df38
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/polymesh/impl/impl_ranges.hh
+17
-0
17 additions, 0 deletions
src/polymesh/impl/impl_ranges.hh
src/polymesh/iterators.hh
+6
-0
6 additions, 0 deletions
src/polymesh/iterators.hh
src/polymesh/ranges.hh
+6
-0
6 additions, 0 deletions
src/polymesh/ranges.hh
with
29 additions
and
0 deletions
src/polymesh/impl/impl_ranges.hh
+
17
−
0
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
{
...
...
This diff is collapsed.
Click to expand it.
src/polymesh/iterators.hh
+
6
−
0
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
)
{}
...
...
This diff is collapsed.
Click to expand it.
src/polymesh/ranges.hh
+
6
−
0
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
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment