HumanPoseK4ABTBody32.cpp
Go to the documentation of this file.
2
3#include <string>
4
7
11
12namespace armarx::viz
13{
14
15 using namespace armarx::human::pose::model::k4a_bt_body_32;
16
17 void
19 const HumanPoseLayers& layers,
20 const std::string& prefix,
21 const DrawingStyle& drawingStyle)
22 {
23 //const armarx::viz::Color colorCylinder =
24 // armarx::viz::Color::fromRGBA(1, 1, 1, 1); // TODO: Random, seed with person ID.
25
26 // Segments.
27 for (const auto& [index1, index2] : Segments)
28 {
29 const std::string& name1 = JointNames.map().left.at(index1);
30 const std::string& name2 = JointNames.map().left.at(index2);
31
32 // Only draw segment if start end end are in keypoint map.
33 if (pose.keypoints.find(name1) == pose.keypoints.end() or
34 pose.keypoints.find(name2) == pose.keypoints.end())
35 {
36 continue;
37 }
38
39 const armarx::armem::human::PoseKeypoint p1 = pose.keypoints.at(name1);
40 const armarx::armem::human::PoseKeypoint p2 = pose.keypoints.at(name2);
41
42 const Eigen::Vector3f pos1 = p1.positionGlobal->toEigen();
43 const Eigen::Vector3f pos2 = p2.positionGlobal->toEigen();
44
45 if (pos1.allFinite() and pos2.allFinite())
46 {
47 if (pos1 == Eigen::Vector3f(0, 0, 0) or pos2 == Eigen::Vector3f(0, 0, 0))
48 {
49 continue;
50 }
51
52 armarx::viz::Color color =
53 drawingStyle.segmentColor.value_or(Colors.at(JointNames.from_name(p2.label)));
54
56 armarx::viz::Cylinder(prefix + "::" + p1.label + "_" + p2.label)
57 .fromTo(pos1, pos2)
58 .radius(drawingStyle.segmentThickness)
59 .color(color);
60 layers.skeleton.add(line);
61 }
62 }
63
64 // Keypoints.
65 for (auto const& [id, name] : JointNames.map())
66 {
67 const auto it = pose.keypoints.find(name);
68 if (it != pose.keypoints.end())
69 {
70 armarx::armem::human::PoseKeypoint kp = pose.keypoints.at(name);
71 armarx::viz::Color color =
72 drawingStyle.jointColor.value_or(Colors.at(JointNames.from_name(kp.label)));
73
74 armarx::viz::Sphere sphere = armarx::viz::Sphere(prefix + "::" + name)
75 .position(kp.positionGlobal->toEigen())
76 .radius(drawingStyle.jointThickness)
77 .color(color);
78
79 if (kp.orientationGlobal.has_value())
80 {
81 armarx::viz::Pose pose = armarx::viz::Pose(prefix + "::" + name + "_pose")
82 .pose(kp.positionGlobal.value().toEigen(),
83 kp.orientationGlobal.value().toEigen());
84 layers.frames.add(pose);
85 }
86
87 layers.skeleton.add(sphere);
88 }
89 }
90 }
91
92
93} // namespace armarx::viz
DerivedT & pose(Eigen::Matrix4f const &pose)
Definition ElementOps.h:176
DerivedT & color(Color color)
Definition ElementOps.h:218
DerivedT & position(float x, float y, float z)
Definition ElementOps.h:136
const std::map< Joints, simox::Color > Colors
const simox::meta::EnumNames< Joints > JointNames
Names of the joints as defined in the body model.
const std::vector< std::pair< Joints, Joints > > Segments
Segments (defined by pairs of joints) as defined in the body model.
void addPoseToLayer(const armarx::armem::human::HumanPose &pose, const HumanPoseLayers &layers, const std::string &prefix, const DrawingStyle &drawingStyle=DrawingStyle())
This file is part of ArmarX.
std::optional< armarx::FramedOrientation > orientationGlobal
Definition types.h:38
std::optional< armarx::FramedPosition > positionGlobal
Definition types.h:37
Cylinder & radius(float r)
Definition Elements.h:76
Cylinder & fromTo(Eigen::Vector3f from, Eigen::Vector3f to)
Definition Elements.cpp:93
std::optional<::simox::Color > jointColor
Definition HumanPose.h:30
std::optional<::simox::Color > segmentColor
Definition HumanPose.h:29
void add(ElementT const &element)
Definition Layer.h:31
Sphere & radius(float r)
Definition Elements.h:138