Visu.cpp
Go to the documentation of this file.
1 #include "Visu.h"
2 
3 #include <Eigen/Geometry>
4 
5 #include <SimoxUtility/color/Color.h>
6 #include <SimoxUtility/color/cmaps/colormaps.h>
7 #include <SimoxUtility/math/pose.h>
8 #include <SimoxUtility/math/rescale.h>
9 
14 
23 
25 {
26 
27  void
28  Visu::defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string& prefix)
29  {
30  defs->optional(enabled, prefix + "enabled", "Enable or disable visualization of objects.");
31  defs->optional(frequencyHz, prefix + "frequenzyHz", "Frequency of visualization.");
32  defs->optional(inGlobalFrame,
33  prefix + "inGlobalFrame",
34  "If true, show global poses. If false, show poses in robot frame.");
35  defs->optional(alpha, prefix + "alpha", "Alpha of objects (1 = solid, 0 = transparent).");
36  defs->optional(alphaByConfidence,
37  prefix + "alphaByConfidence",
38  "If true, use the pose confidence as alpha (if < 1.0).");
39  defs->optional(oobbs, prefix + "oobbs", "Enable showing oriented bounding boxes.");
40  defs->optional(sizePixel, prefix + "sizePixel", "Pixel size of point cloud.");
41 
42  defs->optional(visualizePointCloud, prefix + "visualizePointCloud", "");
43  defs->optional(visualizePose, prefix + "visualizePose", "");
44  defs->optional(visualizeBoundingBox, prefix + "visualizeBoundingBox", "");
45  defs->optional(visualizeLabels, prefix + "visualizeLabels", "");
46 
47  defs->optional(objectFrames, prefix + "objectFrames", "Enable showing object frames.");
48  defs->optional(
49  objectFramesScale, prefix + "objectFramesScale", "Scaling of object frames.");
50  defs->optional(visualizationDuration,
51  prefix + "maxAgeSeconds",
52  "Maximum age in seconds for visualization.");
53  }
54 
55  void
57  const std::map<std::string, std::vector<armarx::armem::arondto::FamiliarObjectInstance>>&
58  familiarObjectsByProvider)
59  {
60  const auto timestamp = armarx::Clock::Now();
61 
62  const auto isWithinTimeFrame =
63  [&timestamp,
64  this](const armarx::armem::arondto::FamiliarObjectInstance& instance) -> bool
65  {
66  const auto dt = timestamp - instance.timestamp;
68 
69  return dt.toSecondsDouble() < visualizationDuration;
70  };
71 
72  std::vector<viz::Layer> layers;
73 
74  for (const auto& [providerName, familiarObjects] : familiarObjectsByProvider)
75  {
76  auto layerPose = arviz.layer("familiar_objects/pose/" + providerName);
77  auto layerPointCloud = arviz.layer("familiar_objects/points/" + providerName);
78  auto layerLabels = arviz.layer("familiar_objects/labels/" + providerName);
79  auto layerBox = arviz.layer("familiar_objects/box/" + providerName);
80 
81  auto confidenceCmap = simox::color::cmaps::viridis();
82  confidenceCmap.set_vlimits(0, 1);
83 
84  for (const auto& familiarObject : familiarObjects)
85  {
86  if (not isWithinTimeFrame(familiarObject))
87  {
88  continue;
89  }
90 
91  armarx::ObjectID objectId;
92  fromAron(familiarObject.objectID, objectId);
93 
94  if (familiarObject.poseGlobal.has_value())
95  {
96  if (visualizePose)
97  {
98  auto pose = viz::Pose(objectId.str()).pose(familiarObject.poseGlobal->pose);
99  layerPose.add(pose);
100  }
101 
102  const int alpha = static_cast<int>(255 * this->alpha);
103 
104  if (visualizePointCloud and not familiarObject.points.empty())
105  {
106  auto points = viz::PointCloud(objectId.str())
107  .pointCloud(familiarObject.points)
108  .pose(familiarObject.poseGlobal->pose);
109 
110  points.pointSizeInPixels(sizePixel);
111  layerPointCloud.add(points);
112  }
113 
114  if (visualizeLabels)
115  {
116  Eigen::Isometry3f pose{familiarObject.poseGlobal->pose};
117 
118  // gently above object
119  // FIXME derive from bounding box
120  pose.translation().z() += 200;
121 
122  const std::string name = familiarObject.objectID.className + "/" +
123  familiarObject.objectID.instanceName;
124 
125  layerLabels.add(viz::Text(name).pose(pose).scale(20));
126  }
127 
129  {
130 
131  const Eigen::Isometry3f global_T_obj{familiarObject.poseGlobal->pose};
132  Eigen::Isometry3f obj_T_bb = Eigen::Isometry3f::Identity();
133  obj_T_bb.translation() = familiarObject.bounding_box.center;
134 
135  if (familiarObject.boundingBoxOrientation.has_value())
136  {
137  obj_T_bb.linear() =
138  familiarObject.boundingBoxOrientation->toRotationMatrix();
139  }
140 
141  const Eigen::Isometry3f global_T_bb = global_T_obj * obj_T_bb;
142 
143  auto box = viz::Box(objectId.str());
144  box.pose(global_T_bb.matrix());
145  box.size(familiarObject.bounding_box.extents);
146 
147  auto color = confidenceCmap.at(familiarObject.confidence);
148  color.a = alpha;
149 
150  box.color(color);
151  layerBox.add(box);
152  }
153  }
154  }
155 
156  layers.push_back(layerPose);
157  layers.push_back(layerPointCloud);
158  layers.push_back(layerLabels);
159  layers.push_back(layerBox);
160  }
161 
162  arviz.commit(layers);
163  }
164 
165 
166 } // namespace armarx::armem::server::obj::familiar_object_instance
armarx::viz::Client::commit
CommitResult commit(StagedCommit const &commit)
Definition: Client.cpp:89
armarx::armem::server::obj::familiar_object_instance::Visu::visualizeBoundingBox
bool visualizeBoundingBox
Definition: Visu.h:54
armarx::armem::server::obj::familiar_object_instance::Visu::visualizePointCloud
bool visualizePointCloud
Definition: Visu.h:53
ice_conversions.h
armarx::ObjectID
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition: ObjectID.h:10
predictions.h
armarx::armem::server::obj::familiar_object_instance::Visu::visualizationDuration
float visualizationDuration
Definition: Visu.h:61
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::armem::server::obj::familiar_object_instance::Visu::objectFrames
bool objectFrames
Definition: Visu.h:58
armarx::armem::server::obj::familiar_object_instance::Visu::enabled
bool enabled
Definition: Visu.h:42
armarx::armem::server::obj::familiar_object_instance::Visu::objectFramesScale
float objectFramesScale
Definition: Visu.h:59
armarx::armem::server::obj::familiar_object_instance::Visu::visualizeLabels
bool visualizeLabels
Definition: Visu.h:56
ice_conversions.h
aron_conversions.h
Elements.h
Clock.h
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
armarx::armem::server::obj::familiar_object_instance::Visu::sizePixel
std::uint8_t sizePixel
Definition: Visu.h:51
armarx::armem::server::obj::familiar_object_instance::Visu::defineProperties
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="visu.")
Definition: Visu.cpp:28
armarx::armem::server::obj::familiar_object_instance::Visu::visualizePose
bool visualizePose
Definition: Visu.h:55
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
ObjectID.h
armarx::viz::Box
Definition: Elements.h:47
armarx::armem::server::obj::familiar_object_instance::Visu::alpha
float alpha
Definition: Visu.h:47
armarx::viz::Text
Definition: Elements.h:183
armarx::armem::server::obj::familiar_object_instance::Visu::visualizeFamiliarObjectsByProvider
void visualizeFamiliarObjectsByProvider(const std::map< std::string, std::vector< armarx::armem::arondto::FamiliarObjectInstance >> &familiarObjectsByProvider)
Definition: Visu.cpp:56
armarx::armem::server::obj::familiar_object_instance::Visu::oobbs
bool oobbs
Definition: Visu.h:49
visionx::PointCloud
pcl::PointCloud< Point > PointCloud
Definition: RCPointCloudProvider.cpp:55
armarx::armem::server::obj::familiar_object_instance::Visu::alphaByConfidence
bool alphaByConfidence
Definition: Visu.h:48
armarx::armem::server::obj::familiar_object_instance::Visu::frequencyHz
float frequencyHz
Definition: Visu.h:43
armarx::armem::fromAron
void fromAron(const arondto::MemoryID &dto, MemoryID &bo)
Definition: aron_conversions.cpp:8
TimeUtil.h
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:198
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::armem::server::obj::familiar_object_instance::Visu::inGlobalFrame
bool inGlobalFrame
Definition: Visu.h:45
armarx::core::time::Clock::Now
static DateTime Now()
Current time on the virtual clock.
Definition: Clock.cpp:93
ice_conversions_templates.h
armarx::armem::server::obj::familiar_object_instance
Definition: Decay.cpp:8
armarx::viz::Client::layer
Layer layer(std::string const &name) const
Definition: Client.cpp:80
aron_conversions.h
Visu.h
armarx::armem::server::obj::familiar_object_instance::Visu::arviz
viz::Client arviz
Definition: Visu.h:40
dt
constexpr T dt
Definition: UnscentedKalmanFilterTest.cpp:45
PointCloud.h
armarx::ObjectID::str
std::string str() const
Return "dataset/className" or "dataset/className/instanceName".
Definition: ObjectID.cpp:60
ObjectFinder.h