Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Simox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Leander Singer
Simox
Commits
23ea8f7f
Commit
23ea8f7f
authored
5 years ago
by
Rainer Kartmann
Browse files
Options
Downloads
Patches
Plain Diff
Add simox::apply
parent
c3a8f767
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
SimoxUtility/CMakeLists.txt
+1
-0
1 addition, 0 deletions
SimoxUtility/CMakeLists.txt
SimoxUtility/algorithm/apply.hpp
+44
-0
44 additions, 0 deletions
SimoxUtility/algorithm/apply.hpp
SimoxUtility/color/ColorMap.h
+4
-22
4 additions, 22 deletions
SimoxUtility/color/ColorMap.h
with
49 additions
and
22 deletions
SimoxUtility/CMakeLists.txt
+
1
−
0
View file @
23ea8f7f
...
...
@@ -82,6 +82,7 @@ SET(INCLUDES
EigenStdVector.h
algorithm/for_each_if.h
algorithm/apply.hpp
color/cmaps/colormaps.h
color/cmaps/Named.h
...
...
This diff is collapsed.
Click to expand it.
SimoxUtility/algorithm/apply.hpp
0 → 100644
+
44
−
0
View file @
23ea8f7f
#pragma once
#include
<functional>
#include
<map>
#include
<vector>
namespace
simox
{
template
<
typename
ValueIn
,
typename
ValueOut
>
ValueOut
apply
(
const
ValueIn
&
value
,
const
std
::
function
<
ValueIn
(
ValueOut
)
>&
op
)
{
return
op
(
value
);
}
template
<
typename
ValueIn
,
typename
ValueOut
>
std
::
vector
<
ValueOut
>
apply
(
const
std
::
vector
<
ValueIn
>&
vector
,
const
std
::
function
<
ValueIn
(
ValueOut
)
>&
op
)
{
std
::
vector
<
ValueOut
>
result
;
std
::
transform
(
vector
.
begin
(),
vector
.
end
(),
std
::
back_inserter
(
result
),
[
&
op
](
const
auto
&
v
)
{
return
apply
(
v
,
op
);
});
return
result
;
}
template
<
typename
ValueIn
,
typename
ValueOut
,
typename
Key
>
std
::
map
<
Key
,
ValueOut
>
apply
(
const
std
::
map
<
Key
,
ValueIn
>&
map
,
const
std
::
function
<
ValueIn
(
ValueOut
)
>&
op
)
{
std
::
map
<
Key
,
ValueOut
>
result
;
for
(
const
auto
&
[
name
,
value
]
:
map
)
{
result
[
name
]
=
apply
(
value
,
op
);
}
return
result
;
}
}
This diff is collapsed.
Click to expand it.
SimoxUtility/color/ColorMap.h
+
4
−
22
View file @
23ea8f7f
...
...
@@ -4,6 +4,8 @@
#include
<map>
#include
<string>
#include
<SimoxUtility/algorithm/apply.hpp>
#include
"Color.h"
#include
"interpolation.h"
...
...
@@ -56,10 +58,10 @@ namespace simox::color
/// Apply this colormap to a vector.
template
<
typename
V
>
std
::
vector
<
Color
>
operator
()(
const
std
::
vector
<
V
>&
vector
)
const
;
std
::
vector
<
Color
>
operator
()(
const
std
::
vector
<
V
>&
vector
)
const
{
return
simox
::
apply
(
vector
,
*
this
);
}
/// Apply this colormap to a map.
template
<
typename
K
,
typename
V
>
std
::
map
<
K
,
Color
>
operator
()(
const
std
::
map
<
K
,
V
>&
map
)
const
;
std
::
map
<
K
,
Color
>
operator
()(
const
std
::
map
<
K
,
V
>&
map
)
const
{
return
simox
::
apply
(
map
,
*
this
);
}
std
::
string
name
()
const
{
return
_name
;
}
void
setName
(
const
std
::
string
&
name
)
{
this
->
_name
=
name
;
}
...
...
@@ -99,26 +101,6 @@ namespace simox::color
};
template
<
typename
V
>
std
::
vector
<
Color
>
ColorMap
::
operator
()(
const
std
::
vector
<
V
>&
vector
)
const
{
std
::
vector
<
Color
>
result
;
std
::
transform
(
vector
.
begin
(),
vector
.
end
(),
std
::
back_inserter
(
result
),
*
this
);
return
result
;
}
template
<
typename
K
,
typename
V
>
std
::
map
<
K
,
Color
>
ColorMap
::
operator
()(
const
std
::
map
<
K
,
V
>&
map
)
const
{
std
::
map
<
K
,
Color
>
result
;
for
(
const
auto
&
[
name
,
value
]
:
map
)
{
result
[
name
]
=
(
*
this
)(
value
);
}
return
result
;
}
}
...
...
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