Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OpenMesh
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
Martin Heistermann
OpenMesh
Commits
c23d410c
Commit
c23d410c
authored
5 years ago
by
Max Lyon
Committed by
Patrick Schmidt
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
add arg min and arg max methods to smart ranges
parent
6ac21207
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/OpenMesh/Core/Mesh/SmartRange.hh
+63
-0
63 additions, 0 deletions
src/OpenMesh/Core/Mesh/SmartRange.hh
with
63 additions
and
0 deletions
src/OpenMesh/Core/Mesh/SmartRange.hh
+
63
−
0
View file @
c23d410c
...
@@ -250,6 +250,37 @@ struct SmartRangeT
...
@@ -250,6 +250,37 @@ struct SmartRangeT
return
res
;
return
res
;
}
}
/** @brief Compute minimal element.
*
* Computes the element that minimizes \p f.
*
* @param f Functor that is applied to all elements before comparing.
*/
template
<
typename
Functor
>
auto
argmin
(
Functor
&&
f
)
->
HandleT
{
auto
range
=
static_cast
<
const
RangeT
*>
(
this
);
auto
it
=
range
->
begin
();
auto
min_it
=
it
;
auto
end
=
range
->
end
();
assert
(
it
!=
end
);
typename
std
::
decay
<
decltype
(
f
(
std
::
declval
<
HandleT
>
()))
>::
type
curr_min
=
f
(
*
it
);
++
it
;
for
(;
it
!=
end
;
++
it
)
{
auto
val
=
f
(
*
it
);
if
(
val
<
curr_min
)
{
curr_min
=
val
;
min_it
=
it
;
}
}
return
*
min_it
;
}
/** @brief Compute maximum.
/** @brief Compute maximum.
*
*
* Computes the maximum of all objects returned by functor \p f.
* Computes the maximum of all objects returned by functor \p f.
...
@@ -275,6 +306,38 @@ struct SmartRangeT
...
@@ -275,6 +306,38 @@ struct SmartRangeT
return
res
;
return
res
;
}
}
/** @brief Compute maximal element.
*
* Computes the element that maximizes \p f.
*
* @param f Functor that is applied to all elements before comparing.
*/
template
<
typename
Functor
>
auto
argmax
(
Functor
&&
f
)
->
HandleT
{
auto
range
=
static_cast
<
const
RangeT
*>
(
this
);
auto
it
=
range
->
begin
();
auto
max_it
=
it
;
auto
end
=
range
->
end
();
assert
(
it
!=
end
);
typename
std
::
decay
<
decltype
(
f
(
std
::
declval
<
HandleT
>
()))
>::
type
curr_max
=
f
(
*
it
);
++
it
;
for
(;
it
!=
end
;
++
it
)
{
auto
val
=
f
(
*
it
);
if
(
val
>
curr_max
)
{
curr_max
=
val
;
max_it
=
it
;
}
}
return
*
max_it
;
}
/** @brief Computes minimum and maximum.
/** @brief Computes minimum and maximum.
*
*
* Computes the minimum and maximum of all objects returned by functor \p f. Result is returned as std::pair
* Computes the minimum and maximum of all objects returned by functor \p f. Result is returned as std::pair
...
...
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