HumanPoseBody25.cpp
Go to the documentation of this file.
1#include "HumanPoseBody25.h"
2
3#include <string>
4
6
9
13
14namespace armarx::viz
15{
16
17 using namespace armarx::human::pose::model::openpose_body_25;
18
19 void
21 HumanPoseLayers& layers,
22 const std::string& prefix,
23 const DrawingStyle& drawingStyle)
24 {
26
27 // Segments.
28 for (const auto& [index1, index2] : Segments)
29 {
30 const std::string& name1 = JointNames.map().left.at(index1);
31 const std::string& name2 = JointNames.map().left.at(index2);
32
33 // Only draw segment if start end end are in keypoint map.
34 if (pose.keypoints.find(name1) == pose.keypoints.end() or
35 pose.keypoints.find(name2) == pose.keypoints.end())
36 {
37 continue;
38 }
39
40 const armarx::armem::human::PoseKeypoint p1 = pose.keypoints.at(name1);
41 const armarx::armem::human::PoseKeypoint p2 = pose.keypoints.at(name2);
42
43 const Eigen::Vector3f pos1 = p1.positionGlobal->toEigen();
44 const Eigen::Vector3f pos2 = p2.positionGlobal->toEigen();
45
46 if (pos1.allFinite() and pos2.allFinite())
47 {
48 if (pos1 == Eigen::Vector3f(0, 0, 0) or pos2 == Eigen::Vector3f(0, 0, 0))
49 {
50 continue;
51 }
52
53 const armarx::viz::Color color =
54 drawingStyle.segmentColor.value_or(Colors.at(index2));
55
57 armarx::viz::Cylinder(prefix + "::" + p1.label + "_" + p2.label)
58 .fromTo(pos1, pos2)
59 .radius(drawingStyle.segmentThickness)
60 .color(color);
61 layers.skeleton.add(line);
62 }
63 }
64
65 // Keypoints.
66 for (auto const& [id, name] : JointNames.map())
67 {
68 if (pose.keypoints.find(name) != pose.keypoints.end() and
69 name != JointNames.map().left.at(Joints::Background))
70 {
71 armarx::armem::human::PoseKeypoint kp = pose.keypoints.at(name);
72
73 const armarx::viz::Color color = drawingStyle.jointColor.value_or(Colors.at(id));
74 armarx::viz::Sphere sphere = armarx::viz::Sphere(prefix + "::" + name)
75 .position(kp.positionGlobal->toEigen())
76 .radius(drawingStyle.jointThickness)
77 .color(color);
78 layers.skeleton.add(sphere);
79 }
80 }
81 }
82
83} // namespace armarx::viz
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, HumanPoseLayers &layer, const std::string &prefix, const DrawingStyle &drawingStyle=DrawingStyle())
This file is part of ArmarX.
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
#define ARMARX_TRACE
Definition trace.h:77