GraspCandidateVisu.cpp
Go to the documentation of this file.
1 #include "GraspCandidateVisu.h"
2 
5 
6 
7 namespace armarx::grasping
8 {
10  {
11  }
12 
13 
15  const grasping::GraspCandidateDict& candidates,
16  viz::Client& arviz)
17  {
18  viz::Layer graspsLayer = arviz.layer("Grasps");
19  viz::Layer graspsNonReachableLayer = arviz.layer("Grasps Non-Reachable");
20 
21  visualize(candidates, graspsLayer, graspsNonReachableLayer);
22  arviz.commit({graspsLayer, graspsNonReachableLayer});
23  }
24 
25 
26  void GraspCandidateVisu::visualize(const std::string &id, const GraspCandidate &candidate,
27  viz::Layer& layerReachable,
28  viz::Layer& layerNonReachable)
29  {
30  int alpha = alpha_default;
31  if (auto it = alphasByKey.find(id); it != alphasByKey.end())
32  {
33  alpha = it->second;
34  }
35 
36  ARMARX_CHECK(candidate.tcpPoseInHandRoot) << "Candidate needs to have tcpPoseInHandRoot to be visualized!";
37  viz::Robot hand = visualize("Grasp_" + id, candidate, alpha);
38 
39  if (candidate.reachabilityInfo && candidate.reachabilityInfo->reachable)
40  {
41  layerReachable.add(hand);
42  }
43  else
44  {
45  layerNonReachable.add(hand);
46  }
47  }
48 
49  void GraspCandidateVisu::visualize(const grasping::GraspCandidateDict& candidates,
50  viz::Layer& layerReachable,
51  viz::Layer& layerNonReachable)
52  {
53  for (auto& [id, candidate] : candidates)
54  {
55  visualize(id, *candidate, layerReachable, layerNonReachable);
56  }
57  }
58 
59 
61  const std::string& name,
62  const GraspCandidate& candidate)
63  {
64  return visualize(name, candidate, alpha_default);
65  }
66 
67 
70  const std::string& name,
71  const grasping::GraspCandidate& candidate,
72  int alpha)
73  {
74  bool isReachable = candidate.reachabilityInfo && candidate.reachabilityInfo->reachable;
75  viz::Color color = isReachable ? viz::Color::green() : viz::Color::orange();
76  color.a = alpha;
77 
78  Eigen::Matrix4f tcp2handRoot = fromIce(candidate.tcpPoseInHandRoot).inverse();
79  Eigen::Matrix4f graspPose = PosePtr::dynamicCast(candidate.graspPose)->toEigen();
80  std::string modelFile = "rt/robotmodel/Armar6-SH/Armar6-" + candidate.side + "Hand-v3.xml";
81 
82  viz::Robot hand = viz::RobotHand(name)
83  .file("Armar6RT", modelFile)
84  .pose(fromIce(candidate.robotPose) * graspPose * tcp2handRoot)
85  .overrideColor(color);
86 
87  return hand;
88  }
89 }
90 
armarx::grasping
Definition: aron_conversions.h:9
armarx::viz::Client::commit
CommitResult commit(StagedCommit const &commit)
Definition: Client.cpp:80
armarx::viz::Robot::file
Robot & file(std::string const &project, std::string const &filename)
Definition: Robot.h:15
Pose.h
armarx::grasping::GraspCandidateVisu::alphasByKey
std::map< std::string, int > alphasByKey
Definition: GraspCandidateVisu.h:44
GraspCandidateVisu.h
RobotHand.h
armarx::grasping::GraspCandidateVisu::visualize
void visualize(const grasping::GraspCandidateDict &candidates, viz::Client &arviz)
Definition: GraspCandidateVisu.cpp:14
armarx::viz::Layer::add
void add(ElementT const &element)
Definition: Layer.h:29
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::grasping::GraspCandidateVisu::GraspCandidateVisu
GraspCandidateVisu()
Definition: GraspCandidateVisu.cpp:9
armarx::viz::Color
Definition: Color.h:13
armarx::viz::Robot::overrideColor
Robot & overrideColor(Color c)
Definition: Robot.h:45
armarx::viz::Robot
Definition: Robot.h:10
armarx::fromIce
void fromIce(const std::map< IceKeyT, IceValueT > &iceMap, boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:26
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::viz::ElementOps::pose
DerivedT & pose(Eigen::Matrix4f const &pose)
Definition: ElementOps.h:159
armarx::viz::RobotHand
Left or right hand of a robot.
Definition: RobotHand.h:19
armarx::viz::Color::orange
static Color orange(int o=255, int a=255)
2 Red + 1 Green
Definition: Color.h:119
armarx::viz::Color::green
static Color green(int g=255, int a=255)
Definition: Color.h:84
armarx::viz::Client::layer
Layer layer(std::string const &name) const
Definition: Client.cpp:73
armarx::viz::Client
Definition: Client.h:109
armarx::viz::Layer
Definition: Layer.h:12
armarx::grasping::GraspCandidateVisu::alpha_default
int alpha_default
Definition: GraspCandidateVisu.h:43