11#include <range/v3/algorithm/contains.hpp>
12#include <range/v3/view/map.hpp>
14#include <SimoxUtility/algorithm/get_map_keys_values.h>
15#include <SimoxUtility/color/Color.h>
16#include <SimoxUtility/math/pose.h>
17#include <SimoxUtility/math/rescale.h>
18#include <SimoxUtility/shapes/OrientedBox.h>
50 defs->optional(
enabled, prefix +
"enabled",
"Enable or disable visualization of objects.");
52 prefix +
"minConfidence",
53 "Min confidence to visualize objects. If decay is enabled, "
54 "`decay.minConfidence` will be used instead.");
56 prefix +
"colModelsEnabled",
57 "Enable or disable visualization of collision models of objects.");
58 defs->optional(
frequencyHz, prefix +
"frequenzyHz",
"Frequency of visualization.");
60 prefix +
"inGlobalFrame",
61 "If true, show global poses. If false, show poses in robot frame.");
62 defs->optional(
alpha, prefix +
"alpha",
"Alpha of objects (1 = solid, 0 = transparent).");
64 prefix +
"alphaByConfidence",
65 "If true, use the pose confidence as alpha (if < 1.0).");
66 defs->optional(
oobbs, prefix +
"oobbs",
"Enable showing oriented bounding boxes.");
68 defs->optional(
objectFrames, prefix +
"objectFrames",
"Enable showing object frames.");
72 gaussians.defineProperties(defs, prefix +
"gaussians.");
75 prefix +
"useArticulatedModels",
76 "Prefer articulated object models if available.");
85 position, prefix +
"position",
"Enable showing pose gaussians (position part).");
87 positionScale, prefix +
"positionScale",
"Scaling of pose gaussians (position part).");
90 orientation, prefix +
"position",
"Enable showing pose gaussians (orientation part).");
92 prefix +
"positionScale",
93 "Scaling of pose gaussians (orientation part).");
96 prefix +
"positionDisplaced",
97 "Displace center orientation (co)variance circle arrows along their rotation axis.");
100 std::vector<viz::Layer>
102 const std::map<std::string, objpose::ObjectPoseSeq>& objectPoses,
103 const std::map<std::string, std::vector<std::map<DateTime, objpose::ObjectPose>>>&
107 std::vector<viz::Layer> layers;
108 for (
const auto& [name, poses] : objectPoses)
115 auto poseHistoryMap = poseHistories.find(name);
116 if (poseHistoryMap != poseHistories.end())
129 std::vector<viz::Layer>
131 const std::vector<std::map<DateTime, objpose::ObjectPose>>& poseHistories,
134 std::map<std::string, viz::Layer> stage;
135 for (
size_t i = 0; i < objectPoses.size(); ++i)
137 const std::string providerName = objectPoses.at(i).providerName;
138 if (providerName.empty())
159 return simox::alg::get_values(stage);
162 std::vector<viz::Layer>
165 const std::map<
ObjectID, std::map<DateTime, objpose::ObjectPose>>& poseHistories,
168 std::map<std::string, viz::Layer> stage;
169 for (
const auto& [
id, pose] : objectPoses)
171 if (pose.providerName.empty())
174 <<
" does not have a `providerName` set";
178 auto poseHistoryMap = poseHistories.find(
id);
179 if (poseHistoryMap != poseHistories.end())
183 poseHistoryMap->second,
190 getLayer(pose.providerName, stage), pose, {}, objectFinder,
false);
196 if (poseHistoryMap != poseHistories.end())
200 poseHistoryMap->second,
207 getLayer(pose.providerName +
"_col", stage), pose, {}, objectFinder,
true);
211 return simox::alg::get_values(stage);
215 Visu::getLayer(
const std::string& providerName, std::map<std::string, viz::Layer>& stage)
const
218 <<
"`providerName` used as layer name: must not be empty";
219 auto it = stage.find(providerName);
220 if (it == stage.end())
222 it = stage.emplace(providerName,
arviz.
layer(providerName)).first;
229 const std::string& providerName,
231 const std::vector<std::map<DateTime, objpose::ObjectPose>>& poseHistories,
235 for (
size_t i = 0; i < poseHistories.size(); ++i)
242 layer, objectPoses.at(i), poseHistories.at(i), objectFinder,
true);
251 const std::map<DateTime, objpose::ObjectPose>& poseHistory,
253 const bool useColModel)
const
261 const std::string key =
id.
str();
263 const Eigen::Matrix4f pose =
265 std::optional<ObjectInfo> objectInfo = objectFinder.
findObject(
id);
267 auto makeObject = [&objectInfo, &id](
const std::string& key)
272 object.file(objectInfo->package(), objectInfo->simoxXML().relativePath);
276 object.fileByObjectFinder(
id);
281 bool hasObject =
false;
287 if (std::optional<PackageFileLocation> model = objectInfo->getArticulatedModel())
291 robot.
file(model->package, model->package +
"/" + model->relativePath);
318 object.useCollisionModel();
330 const simox::OrientedBoxf oobb =
332 layer.
add(
viz::Box(key +
" OOBB").set(oobb).color(simox::Color::lime(255, 64)));
374 .color(viz::Color::azure(255, 32)));
378 for (
int i = 0; i < 3; ++i)
380 Eigen::Vector3i color = Eigen::Vector3i::Zero();
383 layer.
add(
viz::Arrow(key +
" Gaussian (Translation)" + std::to_string(i))
388 .
color(simox::Color(color)));
394 const float pi =
static_cast<float>(
M_PI);
395 for (
int i = 0; i < 3; ++i)
397 const bool global =
true;
400 Eigen::Vector4i color = Eigen::Vector4i::Zero();
410 .completion(simox::math::rescale(rot.angle(), 0.f,
pi * 2, 0.f, 1.f))
411 .width(simox::math::rescale(rot.angle(), 0.f,
pi * 2, 2.f, 7.f))
412 .color(simox::Color(color)));
424 alpha.setRange(0, 1.0);
429 auto initScale = [](
FloatSpinBox& scale,
float value,
float stepResolution)
441 initScale(
gaussians.positionScale,
visu.gaussians.positionScale, 10);
444 initScale(
gaussians.orientationScale,
visu.gaussians.orientationScale, 0.5);
445 gaussians.orientationDisplaced.setValue(
visu.gaussians.orientationDisplaced);
456 grid.
add(
Label(
"Alpha"), {row, 0}).add(
alpha, {row, 1}, {1, 3});
479 group.setLabel(
"Visualization");
480 group.addChild(grid);
501 group.setLabel(
"Pose Gaussians");
502 group.addChild(grid);
535 std::vector<viz::Layer>
537 const std::map<std::string, objpose::ObjectPoseMap>& objectPosesByProvider,
538 const std::map<std::string, std::map<
ObjectID, std::map<DateTime, objpose::ObjectPose>>>&
539 poseHistoriesByProvider,
542 std::map<std::string, viz::Layer> stage;
546 const auto availableProvidersInPoseHistories = ranges::views::keys(poseHistoriesByProvider);
548 for (
const auto& [provider, objectPoses] : objectPosesByProvider)
550 for (
const auto& [
id, pose] : objectPoses)
552 if (pose.providerName.empty())
555 <<
" does not have a `providerName` set";
559 const auto visualizeObjPose =
560 [&](
const std::map<DateTime, objpose::ObjectPose>& poseHistory)
563 getLayer(pose.providerName, stage), pose, poseHistory, objectFinder,
false);
566 if (ranges::contains(availableProvidersInPoseHistories, provider))
568 const auto& poseHistories = poseHistoriesByProvider.at(provider);
570 auto poseHistoryMap = poseHistories.find(
id);
571 if (poseHistoryMap != poseHistories.end())
573 visualizeObjPose(poseHistoryMap->second);
577 visualizeObjPose({});
582 visualizeObjPose({});
588 const auto visualizeObjColPose =
589 [&](
const std::map<DateTime, objpose::ObjectPose>& poseHistory)
599 if (ranges::contains(availableProvidersInPoseHistories, provider))
601 const auto& poseHistories = poseHistoriesByProvider.at(provider);
602 auto poseHistoryMap = poseHistories.find(
id);
604 if (poseHistoryMap != poseHistories.end())
606 visualizeObjColPose(poseHistoryMap->second);
610 visualizeObjColPose({});
615 visualizeObjColPose({});
627 for (
const auto& [provider, objectPoses] : objectPosesByProvider)
629 for (
const auto& [
id, pose] : objectPoses)
633 if (latestObjectPoses.count(
id) == 0)
635 latestObjectPoses.emplace(
id, pose);
640 auto& latestObjectPose = latestObjectPoses.at(
id);
643 if (pose.timestamp > latestObjectPose.timestamp)
645 latestObjectPose = pose;
654 auto& layer = getLayer(
"latest", stage);
656 for (
const auto& [
id, pose] : latestObjectPoses)
663 return simox::alg::get_values(stage);
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
#define ARMARX_CHECK_NOT_EMPTY(c)
Used to find objects in the ArmarX objects repository [1] (formerly [2]).
std::optional< ObjectInfo > findObject(const std::string &dataset, const std::string &name) const
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
std::string str() const
Return "dataset/className" or "dataset/className/instanceName".
Models decay of object localizations by decreasing the confidence the longer the object was not local...
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="visu.")
visu::LinearPredictions linearPredictions
Linear predictions for objects.
bool useArticulatedModels
Prefer articulated models if available.
std::vector< viz::Layer > visualizeCommit(const std::map< std::string, objpose::ObjectPoseSeq > &objectPoses, const std::map< std::string, std::vector< std::map< DateTime, objpose::ObjectPose > > > &poseHistories, const ObjectFinder &objectFinder) const
viz::Layer visualizeProvider(const std::string &providerName, const objpose::ObjectPoseSeq &objectPoses, const std::vector< std::map< DateTime, objpose::ObjectPose > > &poseHistories, const ObjectFinder &objectFinder) const
void visualizeObjectPose(viz::Layer &layer, const objpose::ObjectPose &objectPose, const std::map< DateTime, objpose::ObjectPose > &poseHistory, const ObjectFinder &objectFinder, bool useColModel) const
virtual Layer layer(std::string const &name) const
DerivedT & pose(Eigen::Matrix4f const &pose)
DerivedT & color(Color color)
Robot & joints(std::map< std::string, float > const &values)
Robot & useCollisionModel()
Robot & file(std::string const &project, std::string const &filename)
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
std::map< ObjectID, ObjectPose > ObjectPoseMap
std::vector< ObjectPose > ObjectPoseSeq
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
void setDecimals(int decimals)
void setRange(float min, float max)
void setValue(float newValue)
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
void draw(viz::Layer &layer, const objpose::ObjectPose &objectPose, bool inGlobalFrame) const
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix)
bool orientationDisplaced
armarx::RemoteGui::Client::CheckBox orientation
armarx::RemoteGui::Client::FloatSpinBox positionScale
void update(Visu::Gaussians &data)
armarx::RemoteGui::Client::CheckBox position
armarx::RemoteGui::Client::GroupBox group
armarx::RemoteGui::Client::CheckBox orientationDisplaced
armarx::RemoteGui::Client::FloatSpinBox orientationScale
void setup(const Visu &data)
armarx::RemoteGui::Client::CheckBox inGlobalFrame
armarx::RemoteGui::Client::FloatSpinBox objectFramesScale
armarx::RemoteGui::Client::CheckBox useArticulatedModels
armarx::RemoteGui::Client::GroupBox group
armarx::RemoteGui::Client::CheckBox alphaByConfidence
armarx::RemoteGui::Client::CheckBox objectFrames
armarx::RemoteGui::Client::FloatSlider alpha
visu::LinearPredictions::RemoteGui linearPredictions
armarx::RemoteGui::Client::CheckBox enabled
void setup(const Visu &visu)
armarx::RemoteGui::Client::CheckBox oobbs
An object pose as stored by the ObjectPoseStorage.
float confidence
Confidence in [0, 1] (1 = full, 0 = none).
armarx::ObjectID objectID
The object ID, i.e. dataset, class name and instance name.
std::optional< simox::OrientedBoxf > oobbRobot() const
Get the OOBB in the robot frame (according to objectPoseRobot).
Eigen::Matrix4f objectPoseRobot
The object pose in the robot root frame.
std::optional< PoseManifoldGaussian > objectPoseGlobalGaussian
... and with uncertainty.
std::map< std::string, float > objectJointValues
The object's joint values if it is articulated.
std::optional< simox::OrientedBoxf > localOOBB
Object bounding box in object's local coordinate frame.
std::optional< simox::OrientedBoxf > oobbGlobal() const
Get the OOBB in the global frame (according to objectPoseGlobal).
Eigen::Matrix4f objectPoseGlobal
The object pose in the global frame.
std::optional< PoseManifoldGaussian > objectPoseRobotGaussian
... and with uncertainty.
Eigen::Matrix3f orientation
A "gaussian" distribution in pose space (i.e.
Eigen::AngleAxisf getScaledRotationAxis(int index, bool global=false) const
Get a column of the pure orientational covariance matrix as axis-angle rotation.
Ellipsoid getPositionEllipsoid() const
Get the parameters of a 3D ellipsoid illustrating this gaussian.
void add(ElementT const &element)