marker_detection_visual.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2016, Lukas Pfeifhofer <lukas.pfeifhofer@devlabs.pro>
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  * this list of conditions and the following disclaimer.
00010  *
00011  * 2. Redistributions in binary form must reproduce the above copyright notice,
00012  * this list of conditions and the following disclaimer in the documentation
00013  * and/or other materials provided with the distribution.
00014  *
00015  * 3. Neither the name of the copyright holder nor the names of its contributors
00016  * may be used to endorse or promote products derived from this software without
00017  * specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
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         // Destroy the frame node since we don't need it anymore.
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 }


marker_rviz_plugin
Author(s): Markus Bader, Lukas Pfeifhofer, Markus Macsek
autogenerated on Wed Nov 9 2016 04:02:20