3
3
#include " EulerWidget.h"
4
4
5
5
#include < QBoxLayout>
6
+ #include < visualization_msgs/InteractiveMarker.h>
7
+ #include < visualization_msgs/InteractiveMarkerFeedback.h>
6
8
7
- RotationControl::RotationControl (QWidget *parent, const QString &title) :
8
- QWidget(parent)
9
+ RotationControl::RotationControl (const std::string &title,
10
+ const Eigen::Vector3d &position,
11
+ boost::shared_ptr<interactive_markers::InteractiveMarkerServer> &server,
12
+ QWidget *parent) :
13
+ QGroupBox(QString::fromStdString(title), parent), _server(server), _title(title)
9
14
{
10
15
qRegisterMetaType<Eigen::Quaterniond>(" Eigen::Quaterniond" );
11
16
12
- _qw = new QuaternionWidget (parent);
13
- _ew = new EulerWidget (parent);
17
+ setupUi ();
18
+ createInteractiveMarker (position);
19
+ }
20
+
21
+ void RotationControl::setupUi () {
22
+ _qw = new QuaternionWidget (this );
23
+ _ew = new EulerWidget (this );
14
24
15
25
QBoxLayout *layout = new QBoxLayout (QBoxLayout::TopToBottom, this );
16
26
layout->addWidget (_qw);
@@ -38,9 +48,13 @@ void RotationControl::setValue(const Eigen::Quaterniond &q) {
38
48
39
49
if (!q.isApprox (_qw->value ())) _qw->setValue (q);
40
50
if (!q.isApprox (_ew->value ())) _ew->setValue (q);
51
+
52
+ updatePose (_q);
53
+
41
54
emit valueChanged (q);
42
55
}
43
56
57
+
44
58
void RotationControl::setEulerAxes (uint a1, uint a2, uint a3) {
45
59
_ew->setEulerAxes (a1, a2, a3);
46
60
}
@@ -54,3 +68,58 @@ const Eigen::Vector3d RotationControl::eulerAngles() const {
54
68
void RotationControl::setEulerAngles (double e1 , double e2 , double e3 ) {
55
69
_ew->setEulerAngles (e1 , e2 , e3 );
56
70
}
71
+
72
+ void RotationControl::updatePose (const Eigen::Quaterniond &q) {
73
+ _pose.orientation .w = q.w ();
74
+ _pose.orientation .x = q.x ();
75
+ _pose.orientation .y = q.y ();
76
+ _pose.orientation .z = q.z ();
77
+ }
78
+
79
+ static visualization_msgs::InteractiveMarkerControl createViewPlaneControl () {
80
+ visualization_msgs::InteractiveMarkerControl control;
81
+ control.orientation_mode = visualization_msgs::InteractiveMarkerControl::VIEW_FACING;
82
+ control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_3D;
83
+ control.independent_marker_orientation = true ;
84
+ control.always_visible = true ;
85
+ control.name = " rotate" ;
86
+
87
+ return control;
88
+ }
89
+
90
+ static visualization_msgs::Marker createBoxMarker (double x, double y, double z,
91
+ const QColor &color) {
92
+ visualization_msgs::Marker marker;
93
+
94
+ marker.type = visualization_msgs::Marker::CUBE;
95
+ marker.scale .x = x;
96
+ marker.scale .y = y;
97
+ marker.scale .z = z;
98
+
99
+ marker.color .r = color.redF ();
100
+ marker.color .g = color.greenF ();
101
+ marker.color .b = color.blueF ();
102
+ marker.color .a = color.alphaF ();
103
+
104
+ return marker;
105
+ }
106
+
107
+ void RotationControl::createInteractiveMarker (const Eigen::Vector3d &pos) {
108
+ _pose.position .x = pos[0 ];
109
+ _pose.position .y = pos[1 ];
110
+ _pose.position .z = pos[2 ];
111
+ updatePose (_q);
112
+
113
+ visualization_msgs::InteractiveMarker imarker;
114
+ imarker.header .frame_id = " world" ;
115
+ imarker.header .stamp = ros::Time::now ();
116
+ imarker.pose = _pose;
117
+ imarker.name = _title;
118
+ float s = imarker.scale = 0.2 ;
119
+
120
+ visualization_msgs::InteractiveMarkerControl ctrl = createViewPlaneControl ();
121
+ ctrl.markers .push_back (createBoxMarker (3 *s, 2 *s, 1 *s, QColor (" grey" )));
122
+ imarker.controls .push_back (ctrl);
123
+
124
+ _server->insert (imarker);
125
+ }
0 commit comments