Klamp't  0.9.0
RobotPoseWidget.h
Go to the documentation of this file.
1 #ifndef ROBOT_POSE_WIDGET_H
2 #define ROBOT_POSE_WIDGET_H
3 
4 #include <KrisLibrary/GLdraw/Widget.h>
5 #include <KrisLibrary/GLdraw/TransformWidget.h>
6 #include <KrisLibrary/robotics/IK.h>
7 #include "ViewRobot.h"
8 
9 namespace Klampt {
10 
11 /* @defgroup View
12  * @brief Definitions of OpenGL drawing routines and UI widgets.
13  */
14 
25 class RobotLinkPoseWidget : public GLDraw::Widget
26 {
27 public:
29  RobotLinkPoseWidget(RobotModel* robot,ViewRobot* viewRobot);
30  virtual ~RobotLinkPoseWidget() {}
32  void Set(RobotModel* robot,ViewRobot* viewRobot);
34  void SetActiveDofs(const vector<int>& activeDofs);
35  virtual bool Hover(int x,int y,Camera::Viewport& viewport,double& distance) override;
36  virtual void SetHighlight(bool active) override;
37  virtual bool BeginDrag(int x,int y,Camera::Viewport& viewport,double& distance) override;
38  virtual void Drag(int dx,int dy,Camera::Viewport& viewport) override;
39  virtual void DrawGL(Camera::Viewport& viewport) override;
40  void InitDefaultAppearance();
41 
42  RobotModel* robot;
43  ViewRobot* viewRobot;
44  Config poseConfig;
45  GLDraw::GLColor highlightColor;
46  int hoverLink,affectedLink,affectedDriver;
47  vector<int> activeDofs;
48  vector<int> highlightedLinks;
49  Vector3 hoverPt;
50  bool draw;
51  vector<GLDraw::GeometryAppearance> poserAppearance;
52 };
53 
56 class RobotIKPoseWidget : public GLDraw::WidgetSet
57 {
58 public:
61  void ClearLink(int link);
63  void FixPoint(int link,const Vector3& localpt);
65  void FixLink(int link);
67  void Add(const IKGoal& goal);
69  void AttachWidget(int widget,int link);
71  void SetPoseAndWidgetTransform(int widget,const RigidTransform& T);
73  void RefreshWidgets();
75  int HoverWidget() const;
77  int ActiveWidget() const;
79  bool ClearCurrent();
80  virtual void DrawGL(Camera::Viewport& viewport) override;
81  virtual void Drag(int dx,int dy,Camera::Viewport& viewport) override;
82 
83  //these are overloaded to allow IK widgets to shine through
84  virtual bool Hover(int x,int y,Camera::Viewport& viewport,double& closestDistance) override;
85  virtual bool BeginDrag(int x,int y,Camera::Viewport& viewport,double& closestDistance) override;
86 
87  RobotModel* robot;
88  vector<IKGoal> poseGoals;
89  vector<GLDraw::TransformWidget> poseWidgets;
90 };
91 
95 class RobotPoseWidget : public GLDraw::WidgetSet
96 {
97 public:
99  RobotPoseWidget(RobotModel* robot,ViewRobot* viewRobot);
100  void Set(RobotModel* robot,ViewRobot* viewRobot);
101 
102  const Config& Pose() const { return linkPoser.poseConfig; }
103  void SetPose(const Config& q);
104  vector<IKGoal>& Constraints() { return ikPoser.poseGoals; }
107  Config Pose_Conditioned(const Config& qref) const;
109  void SetActiveDofs(const vector<int>& activeDofs);
111  bool FixCurrent();
113  bool FixCurrentPoint();
115  bool DeleteConstraint();
117  void SetAttachIKMode(bool);
119  void SetPoseIKMode(bool);
121  void SetFixedPoseIKMode(bool);
123  void SetDeleteIKMode(bool);
124 
126  bool SolveIK(int iters=0,Real tol=0);
128  bool SolveIKFixedBase(int iters=0,Real tol=0);
130  bool SolveIKFixedJoint(int fixedJoint,int iters=0,Real tol=0);
131 
132  virtual void DrawGL(Camera::Viewport& viewport) override;
133  virtual bool BeginDrag(int x,int y,Camera::Viewport& viewport,double& distance) override;
134  virtual void Drag(int dx,int dy,Camera::Viewport& viewport) override;
135  virtual void EndDrag() override;
136  virtual void Keypress(char c) override;
137 
138  void Snapshot();
139  void Undo();
140 
141  bool useBase;
142  GLDraw::TransformWidget basePoser;
143  RobotLinkPoseWidget linkPoser;
144  RobotIKPoseWidget ikPoser;
145  enum { ModeNormal, ModeIKAttach, ModeIKPose, ModeIKPoseFixed, ModeIKDelete };
146  int mode;
147  int attachx,attachy;
148  Ray3D attachRay;
149  vector<Config> undoConfigs;
150  vector<vector<pair<int,RigidTransform> > > undoTransforms;
151 };
152 
154 } //namespace Klampt
155 
156 #endif
void SetActiveDofs(const vector< int > &activeDofs)
Sets the active dofs.
void Set(RobotModel *robot, ViewRobot *viewRobot)
Initializer.
Draws the robot (potentially color-coded)
Definition: ViewRobot.h:14
Definition: RobotPoseWidget.h:95
A widget that allows the robot&#39;s driven links to be posed.
Definition: RobotPoseWidget.h:25
A widget that allows creating and editing IK constraints.
Definition: RobotPoseWidget.h:56
The main robot type used in RobotSim.
Definition: Robot.h:83
Definition: ContactDistance.h:6