Klamp't  0.8.1
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 /* @defgroup View
10  * @brief Definitions of OpenGL drawing routines and UI widgets.
11  */
12 
23 class RobotLinkPoseWidget : public GLDraw::Widget
24 {
25 public:
27  RobotLinkPoseWidget(Robot* robot,ViewRobot* viewRobot);
28  virtual ~RobotLinkPoseWidget() {}
30  void Set(Robot* robot,ViewRobot* viewRobot);
32  void SetActiveDofs(const vector<int>& activeDofs);
33  virtual bool Hover(int x,int y,Camera::Viewport& viewport,double& distance);
34  virtual bool BeginDrag(int x,int y,Camera::Viewport& viewport,double& distance);
35  virtual void Drag(int dx,int dy,Camera::Viewport& viewport);
36  virtual void DrawGL(Camera::Viewport& viewport);
37 
38  Robot* robot;
39  ViewRobot* viewRobot;
40  Config poseConfig;
41  GLDraw::GLColor highlightColor;
42  int hoverLink,affectedLink,affectedDriver;
43  vector<int> activeDofs;
44  vector<int> highlightedLinks;
45  Vector3 hoverPt;
46  bool draw;
47  vector<GLDraw::GeometryAppearance> poserAppearance;
48 };
49 
52 class RobotIKPoseWidget : public GLDraw::WidgetSet
53 {
54 public:
55  RobotIKPoseWidget(Robot* robot);
57  void ClearLink(int link);
59  void FixPoint(int link,const Vector3& localpt);
61  void FixLink(int link);
63  void Add(const IKGoal& goal);
65  void AttachWidget(int widget,int link);
67  void SetPoseAndWidgetTransform(int widget,const RigidTransform& T);
69  void RefreshWidgets();
71  int HoverWidget() const;
73  int ActiveWidget() const;
75  bool ClearCurrent();
76  virtual void DrawGL(Camera::Viewport& viewport);
77  virtual void Drag(int dx,int dy,Camera::Viewport& viewport);
78 
79  //these are overloaded to allow IK widgets to shine through
80  virtual bool Hover(int x,int y,Camera::Viewport& viewport,double& closestDistance);
81  virtual bool BeginDrag(int x,int y,Camera::Viewport& viewport,double& closestDistance);
82 
83  Robot* robot;
84  vector<IKGoal> poseGoals;
85  vector<GLDraw::TransformWidget> poseWidgets;
86 };
87 
91 class RobotPoseWidget : public GLDraw::WidgetSet
92 {
93 public:
95  RobotPoseWidget(Robot* robot,ViewRobot* viewRobot);
96  void Set(Robot* robot,ViewRobot* viewRobot);
97 
98  const Config& Pose() const { return linkPoser.poseConfig; }
99  void SetPose(const Config& q);
100  vector<IKGoal>& Constraints() { return ikPoser.poseGoals; }
103  Config Pose_Conditioned(const Config& qref) const;
105  void SetActiveDofs(const vector<int>& activeDofs) { linkPoser.SetActiveDofs(activeDofs); }
107  bool FixCurrent();
109  bool FixCurrentPoint();
111  bool DeleteConstraint();
113  void SetAttachIKMode(bool);
115  void SetPoseIKMode(bool);
117  void SetFixedPoseIKMode(bool);
119  void SetDeleteIKMode(bool);
120 
122  bool SolveIK(int iters=0,Real tol=0);
124  bool SolveIKFixedBase(int iters=0,Real tol=0);
126  bool SolveIKFixedJoint(int fixedJoint,int iters=0,Real tol=0);
127 
128  virtual void DrawGL(Camera::Viewport& viewport);
129  virtual bool BeginDrag(int x,int y,Camera::Viewport& viewport,double& distance);
130  virtual void Drag(int dx,int dy,Camera::Viewport& viewport);
131  virtual void EndDrag();
132  virtual void Keypress(char c);
133 
134  void Snapshot();
135  void Undo();
136 
137  bool useBase;
138  GLDraw::TransformWidget basePoser;
139  RobotLinkPoseWidget linkPoser;
140  RobotIKPoseWidget ikPoser;
141  enum { ModeNormal, ModeIKAttach, ModeIKPose, ModeIKPoseFixed, ModeIKDelete };
142  int mode;
143  int attachx,attachy;
144  Ray3D attachRay;
145  vector<Config> undoConfigs;
146  vector<vector<pair<int,RigidTransform> > > undoTransforms;
147 };
148 
151 #endif
void SetActiveDofs(const vector< int > &activeDofs)
Sets the active dofs.
The main robot type used in RobotSim.
Definition: Robot.h:79
Draws the robot (potentially color-coded)
Definition: ViewRobot.h:12
Definition: RobotPoseWidget.h:91
A widget that allows the robot&#39;s driven links to be posed.
Definition: RobotPoseWidget.h:23
void SetActiveDofs(const vector< int > &activeDofs)
Enables / disables editing certain joints.
Definition: RobotPoseWidget.h:105
A widget that allows creating and editing IK constraints.
Definition: RobotPoseWidget.h:52
void Set(Robot *robot, ViewRobot *viewRobot)
Initializer.