Grid.cpp
Go to the documentation of this file.
1#include "Grid.h"
2
3#include <cstddef>
4#include <functional>
5#include <optional>
6#include <vector>
7
8#include <SimoxUtility/color/Color.h>
9#include <SimoxUtility/color/ColorMap.h>
10
12#include <RobotAPI/interface/ArViz/Elements.h>
13
14namespace armarx::viz
15{
16
17 Grid&
18 Grid::grid(const GridT& grd,
19 const std::optional<MaskT>& mask,
20 const simox::color::ColorMap& cmap,
21 const std::optional<float>& vmin,
22 const std::optional<float>& vmax)
23 {
24 const float vMin = vmin.has_value() ? vmin.value() : grd.minCoeff();
25 const float vMax = vmax.has_value() ? vmax.value() : grd.maxCoeff();
26
27 const auto colorFn = [cmap, vMin, vMax](const float val) -> simox::Color
28 { return cmap.at(val, vMin, vMax); };
29
30 return grid(grd, mask, colorFn);
31 }
32
33 Grid&
34 Grid::grid(const GridT& grd, const std::optional<MaskT>& mask, const ColorFuncT& colorFunc)
35 {
36 this->data_->sizeX = grd.cols();
37 this->data_->sizeY = grd.rows();
38
39 auto& colors = this->data_->colors;
40 colors.clear();
41 colors.reserve(grd.size());
42
43 for (int r = 0; r < grd.rows(); ++r)
44 {
45 for (int c = 0; c < grd.cols(); ++c)
46 {
47 if (mask.has_value() and not mask->operator()(r, c))
48 {
49 colors.emplace_back(0, 0, 0, 0); // transparent
50 }
51 else
52 {
53 const auto color = colorFunc(grd(r, c));
54 colors.push_back(viz::Color::fromRGBA(color));
55 }
56 }
57 }
58
59
60 return *this;
61 }
62
63 Grid&
64 Grid::origin(const Eigen::Isometry3f& origin)
65 {
66 auto& pose = data_->pose;
67
68 // position
69 pose.x = origin.translation().x();
70 pose.y = origin.translation().y();
71 pose.z = origin.translation().z();
72
73 // orientation
74 Eigen::Quaternionf q{origin.rotation()};
75 pose.qw = q.w();
76 pose.qx = q.x();
77 pose.qy = q.y();
78 pose.qz = q.z();
79
80 return *this;
81 }
82
83 Grid&
84 Grid::resolution(const float res)
85 {
86 data_->resolution = res;
87 return *this;
88 }
89} // namespace armarx::viz
constexpr T c
Grid & pose(Eigen::Matrix4f const &pose)
Definition ElementOps.h:176
IceInternal::Handle< data::ElementGrid > data_
Definition ElementOps.h:315
Grid & origin(const Eigen::Isometry3f &origin)
Definition Grid.cpp:64
Grid & grid(const GridT &grd, const std::optional< MaskT > &mask, const ColorFuncT &colorFunc)
Definition Grid.cpp:34
Eigen::MatrixXf GridT
Definition Grid.h:25
std::function< simox::Color(float v)> ColorFuncT
Definition Grid.h:27
Grid & resolution(float res)
Definition Grid.cpp:84
#define q
Quaternion< float, 0 > Quaternionf
This file is part of ArmarX.