Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <OGRE/OgreVector3.h>
00033 #include <OGRE/OgreSceneNode.h>
00034 #include <OGRE/OgreSceneManager.h>
00035 #include <OGRE/OgreEntity.h>
00036
00037 #include "rviz/ogre_helpers/axes.h"
00038
00039 #include "marker_detection/marker_detection_visual.h"
00040
00041 namespace marker_rviz_plugin {
00042
00043 MarkerDetectionVisual::MarkerDetectionVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node) {
00044 scene_manager_ = scene_manager;
00045 frame_node_ = parent_node->createChildSceneNode();
00046
00047 _showAxes = true;
00048 _showMarker = true;
00049 _showLabel = true;
00050 _colorLabel = Ogre::ColourValue ( 0, 170, 0 );
00051 _scale = 1;
00052 }
00053
00054 MarkerDetectionVisual::~MarkerDetectionVisual() {
00055
00056 scene_manager_->destroySceneNode(frame_node_);
00057 }
00058
00059 void MarkerDetectionVisual::setMessage(const marker_msgs::MarkerDetection::ConstPtr &msg) {
00060 _markers.resize(msg->markers.size());
00061
00062 for (size_t i = 0; i < msg->markers.size(); i++) {
00063 double p_x = msg->markers[i].pose.position.x;
00064 double p_y = msg->markers[i].pose.position.y;
00065 double p_z = msg->markers[i].pose.position.z;
00066 double o_x = msg->markers[i].pose.orientation.x;
00067 double o_y = msg->markers[i].pose.orientation.y;
00068 double o_z = msg->markers[i].pose.orientation.z;
00069 double o_w = msg->markers[i].pose.orientation.w;
00070
00071 int id = -1;
00072 if (msg->markers[i].ids.size() > 0)
00073 id = msg->markers[i].ids[0];
00074
00075 _markers[i].reset(new Marker(scene_manager_, frame_node_, id));
00076 _markers[i]->setPosition(Ogre::Vector3(p_x, p_y, p_z));
00077 _markers[i]->setOrientation(Ogre::Quaternion(o_w, o_x, o_y, o_z));
00078 _markers[i]->setShowMarker(_showMarker);
00079 _markers[i]->setShowAxes(_showAxes);
00080 _markers[i]->setShowLabel(_showLabel);
00081 _markers[i]->setColorLabel(_colorLabel);
00082 _markers[i]->setScale(Ogre::Vector3(_scale, _scale, _scale));
00083 }
00084 }
00085
00086 void MarkerDetectionVisual::setFramePosition(const Ogre::Vector3 &position) {
00087 frame_node_->setPosition(position);
00088 }
00089
00090 void MarkerDetectionVisual::setFrameOrientation(const Ogre::Quaternion &orientation) {
00091 frame_node_->setOrientation(orientation);
00092 }
00093
00094 void MarkerDetectionVisual::setShowAxes(bool showAxes) {
00095 for (size_t i = 0; i < _markers.size(); i++) {
00096 _markers[i]->setShowAxes(showAxes);
00097 }
00098
00099 _showAxes = showAxes;
00100 }
00101
00102 void MarkerDetectionVisual::setShowMarker(bool showMarker) {
00103 for (size_t i = 0; i < _markers.size(); i++) {
00104 _markers[i]->setShowMarker(showMarker);
00105 }
00106
00107 _showMarker = showMarker;
00108 }
00109
00110 void MarkerDetectionVisual::setShowLabel(bool showLabel) {
00111 for (size_t i = 0; i < _markers.size(); i++) {
00112 _markers[i]->setShowLabel(showLabel);
00113 }
00114
00115 _showLabel = showLabel;
00116 }
00117 void MarkerDetectionVisual::setColorLabel(Ogre::ColourValue color) {
00118 _colorLabel = color;
00119 for (size_t i = 0; i < _markers.size(); i++) {
00120 _markers[i]->setColorLabel(_colorLabel);
00121 }
00122 }
00123
00124 void MarkerDetectionVisual::setScale(float scale) {
00125 for (size_t i = 0; i < _markers.size(); i++) {
00126 _markers[i]->setScale(Ogre::Vector3(scale, scale, scale));
00127 }
00128
00129 _scale = scale;
00130 }
00131
00132 }