7 #include <Eigen/Geometry>
9 #include <SimoxUtility/algorithm/get_map_keys_values.h>
10 #include <SimoxUtility/math/pose.h>
16 #include <ArmarXCore/interface/core/PackagePath.h>
32 poseSegment(poseSegment),
33 faceRecognitionSegment(faceRecognitionSegment),
34 personInstanceSegment(personInstanceSegment)
42 defs->optional(p.enabled, prefix +
"enabled",
"Enable or disable visualization of humans.");
43 defs->optional(p.frequencyHz, prefix +
"frequenzyHz",
"Frequency of visualization.");
58 bool batchMode =
true;
74 const std::vector<armarx::armem::human::HumanPose>& humanPoses)
76 std::string providerName =
"azure_kinect";
78 std::map<std::string, armarx::armem::human::HumanPose> poseMap;
82 if (humanPose.humanTrackingId.has_value())
84 poseMap[humanPose.humanTrackingId.value()] = humanPose;
97 Visu::visualizeFaceRecognitions(
99 const std::vector<armarx::armem::human::FaceRecognition>& faceRecognitions)
101 std::string providerName =
"azure_kinect";
103 std::map<std::string, armarx::armem::human::FaceRecognition> faceRecognitionMap;
107 if (faceRecognition.profileID.has_value())
109 faceRecognitionMap[faceRecognition.profileID.value().entityName] = faceRecognition;
114 faceRecognitionMap[
"unknown_face_" +
std::to_string(unknown++)] = faceRecognition;
117 if (faceRecognitionMap.size() == 0)
123 faceRecognitionMap, faceRecognitionLayer, providerName);
127 Visu::visualizePersonInstances(
129 const std::vector<armarx::armem::human::PersonInstance>& personInstances)
131 std::string providerName =
"person_instanciator";
133 std::map<std::string, armarx::armem::human::PersonInstance> personInstanceMap;
136 personInstanceMap[personInstance.profileID.entityName] = personInstance;
138 if (personInstanceMap.size() == 0)
142 for (
const auto& [name, personInstance] : personInstanceMap)
147 faceReco, name, personInstanceLayer, providerName);
155 while (updateTask and not updateTask->isStopped())
164 visualizeOnce(timestamp);
166 catch (
const std::exception& e)
168 ARMARX_WARNING <<
"Caught exception while visualizing robots: \n" << e.what();
172 ARMARX_WARNING <<
"Caught unknown exception while visualizing robots.";
175 if (debugObserver.has_value())
177 debugObserver->sendDebugObserverBatch();
180 metronome.waitForNextTick();
185 Visu::visualizeOnce(
const Time& timestamp)
197 const std::map<std::string, std::vector<armarx::armem::human::HumanPose>>
199 const std::map<std::string, std::vector<armarx::armem::human::FaceRecognition>>
201 const std::map<std::string, std::vector<armarx::armem::human::PersonInstance>>
210 std::vector<viz::Layer> providerLayers;
211 for (
const auto& [providerName, humanPoses] : humanPosesPerProvider)
214 viz::Layer layerFrames = arviz.
layer(
"HumanPoses_" + providerName +
"_Frames");
217 visualizeHumanPoses(layers, humanPoses);
218 providerLayers.push_back(layerSkeleton);
219 providerLayers.push_back(layerFrames);
221 for (
const auto& [providerName, faceRecognitions] : faceRecognitionsPerProvider)
223 viz::Layer faceRecognitionLayer = arviz.
layer(
"FaceRecognitions_" + providerName);
224 visualizeFaceRecognitions(faceRecognitionLayer, faceRecognitions);
225 providerLayers.push_back(faceRecognitionLayer);
227 for (
const auto& [providerName, personInstances] : personInstancesPerProvider)
229 viz::Layer personInstanceLayer = arviz.
layer(
"PersonInstances_" + providerName);
230 visualizePersonInstances(personInstanceLayer, personInstances);
231 providerLayers.push_back(personInstanceLayer);
240 arviz.
commit(providerLayers);
245 if (debugObserver.has_value())
247 const std::string p =
"Visu | ";
248 debugObserver->setDebugObserverDatafield(p +
"t Total (ms)",
249 tVisuTotal.toMilliSecondsDouble());
250 debugObserver->setDebugObserverDatafield(p +
"t 1 Get Data (ms)",
251 tVisuGetData.toMilliSecondsDouble());
252 debugObserver->setDebugObserverDatafield(p +
"t 1.1 Descriptions (ms)",
253 tRobotDescriptions.toMilliSecondsDouble());
255 debugObserver->setDebugObserverDatafield(p +
"t 2 Build Layers (ms)",
256 tVisuBuildLayers.toMilliSecondsDouble());
257 debugObserver->setDebugObserverDatafield(p +
"t 3 Commit (ms)",
258 tVisuCommit.toMilliSecondsDouble());