6#include <Eigen/Geometry>
8#include <SimoxUtility/algorithm/get_map_keys_values.h>
9#include <SimoxUtility/iterator.h>
28 inline Eigen::Vector3f
29 toMM(
const Eigen::Vector3f& vec)
34 inline Eigen::Isometry3f
35 toMM(Eigen::Isometry3f pose)
37 pose.translation() *= 1000;
42 nameWithId(
const std::string& name,
const int id,
const unsigned int idWidth = 6)
45 ss << name <<
"_" << std::setw(
static_cast<int>(idWidth)) << std::setfill(
'0') << id;
53 const unsigned int idWidth = 6)
56 ss << name <<
"_" << std::setw(
static_cast<int>(idWidth)) << std::setfill(
'0') <<
id <<
"_"
57 << std::setw(
static_cast<int>(idWidth)) << std::setfill(
'0') << subId;
64 std::vector<std::vector<viz::data::Color>> colors(
65 numCells.x(), std::vector<viz::data::Color>(numCells.y(), viz::Color::black()));
70 auto xyIter = simox::iterator::XYIndexRangeIterator({numCells.x(), numCells.y()});
71 std::for_each(xyIter.begin(),
75 const auto& [x, y] = p;
76 colors[x][y] = toVizColor(colorGrid[x][y]);
86 for (
auto& vv : vvertices)
101 ::cartographer::mapping::MapBuilderInterface& mapBuilder,
102 const Eigen::Isometry3f& world_T_map) :
104 mapBuilder(mapBuilder),
106 world_T_map(world_T_map)
115 runningTask->start();
125 ArVizDrawerMapBuilder::run()
129 while (!runningTask->isStopped())
132 metronome.waitForNextTick();
146 ArVizDrawerMapBuilder::drawFrames()
148 auto framesLayer = arviz.
layer(
"frames");
155 .
fromTo(Eigen::Vector3f::Zero(), world_T_map.translation());
157 framesLayer.add(worldPose);
158 framesLayer.add(mapPose);
159 framesLayer.add(arr);
160 arviz.
commit(framesLayer);
164 ArVizDrawerMapBuilder::drawOptimizedPoseGraph()
166 auto optimizedGraphLayerGlobal = arviz.
layer(
"optimized_graph_global");
170 for (
const auto& nodeData : optimizedGraphData.
nodes_data)
172 const Eigen::Isometry3f globalPose = world_T_map *
toMM(nodeData.global_pose);
174 const auto globalPoseViz =
viz::Pose(
"node_" + std::to_string(nodeData.node_id))
177 optimizedGraphLayerGlobal.add(globalPoseViz);
180 arviz.
commit(optimizedGraphLayerGlobal);
184 ArVizDrawerMapBuilder::drawGridMap()
188 std::map<int, viz::Layer> layers;
190 if (submapData.empty())
195 for (
const auto& submap : submapData)
197 if (layers.find(submap.trajectory_id) == layers.end())
199 layers[submap.trajectory_id] =
200 arviz.layer(
nameWithId(
"grid_maps_trajectory", submap.trajectory_id));
203 auto& gridMapLayer = layers.at(submap.trajectory_id);
205 auto mesh = viz::Mesh(
nameWithIds(
"submap", submap.trajectory_id, submap.id));
207 const Eigen::Isometry3f mapPose =
toMM(submap.global_pose());
208 const Eigen::Isometry3f globalPose = world_T_map * mapPose;
212 mesh.position(globalPose.translation() + Eigen::Vector3f{0.F, 0.F, -1.F})
213 .orientation(globalPose.linear())
214 .grid2D(
toVizPoint(submap.mesh_grid.vertices),
215 toVizColor(submap.mesh_grid.colors, submap.mesh_grid.num_cells));
217 gridMapLayer.add(mesh);
220 const auto layersV = simox::alg::get_values(layers);
221 arviz.commit(layersV);
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
ArVizDrawerMapBuilder(armarx::viz::Client &arviz, ::cartographer::mapping::MapBuilderInterface &mapBuilder, const Eigen::Isometry3f &world_T_map)
virtual Layer layer(std::string const &name) const
CommitResult commit(StagedCommit const &commit)
DerivedT & pose(Eigen::Matrix4f const &pose)
DerivedT & position(float x, float y, float z)
DerivedT & orientation(Eigen::Quaternionf const &ori)
DerivedT & scale(Eigen::Vector3f scale)
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_VERBOSE
The logging level for verbose information.
std::string const GlobalFrame
Variable of the global coordinate system.
SubMapDataVector submapData(::cartographer::mapping::MapBuilderInterface &mapBuilder, const int trajectoryId)
OptimizedGraphData optimizedGraphData(::cartographer::mapping::MapBuilderInterface &mapBuilder)
This file is part of ArmarX.
Eigen::Vector3f toMM(const Eigen::Vector3f &vec)
auto toVizColor(const ColoredMeshGrid::ColorGrid &colorGrid, const Eigen::Array2i &numCells)
std::string nameWithId(const std::string &name, const int id, const unsigned int idWidth=6)
std::string nameWithIds(const std::string &name, const int id, const int subId, const unsigned int idWidth=6)
auto toVizPoint(ColoredMeshGrid::VertexGrid vvertices)
std::vector< SubMapData > SubMapDataVector
std::string const MapFrame
std::vector< std::vector< Color > > ColorGrid
std::vector< std::vector< Position > > VertexGrid
std::vector< OptimizedNodeData > nodes_data
Arrow & fromTo(const Eigen::Vector3f &from, const Eigen::Vector3f &to)