marker_detection_visual.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Lukas Pfeifhofer <lukas.pfeifhofer@devlabs.pro>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <OGRE/OgreVector3.h>
33 #include <OGRE/OgreSceneNode.h>
34 #include <OGRE/OgreSceneManager.h>
35 #include <OGRE/OgreEntity.h>
36 
37 #include "rviz/ogre_helpers/axes.h"
38 
40 
41 namespace marker_rviz_plugin {
42 
43  MarkerDetectionVisual::MarkerDetectionVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node) {
44  scene_manager_ = scene_manager;
45  frame_node_ = parent_node->createChildSceneNode();
46 
47  _showAxes = true;
48  _showMarker = true;
49  _showLabel = true;
50  _colorLabel = Ogre::ColourValue ( 0, 170, 0 );
51  _scale = 1;
52  }
53 
55  // Destroy the frame node since we don't need it anymore.
56  scene_manager_->destroySceneNode(frame_node_);
57  }
58 
59  void MarkerDetectionVisual::setMessage(const marker_msgs::MarkerDetection::ConstPtr &msg) {
60  _markers.resize(msg->markers.size());
61 
62  for (size_t i = 0; i < msg->markers.size(); i++) {
63  double p_x = msg->markers[i].pose.position.x;
64  double p_y = msg->markers[i].pose.position.y;
65  double p_z = msg->markers[i].pose.position.z;
66  double o_x = msg->markers[i].pose.orientation.x;
67  double o_y = msg->markers[i].pose.orientation.y;
68  double o_z = msg->markers[i].pose.orientation.z;
69  double o_w = msg->markers[i].pose.orientation.w;
70 
71  int id = -1;
72  if (msg->markers[i].ids.size() > 0)
73  id = msg->markers[i].ids[0];
74 
75  _markers[i].reset(new Marker(scene_manager_, frame_node_, id));
76  _markers[i]->setPosition(Ogre::Vector3(p_x, p_y, p_z));
77  _markers[i]->setOrientation(Ogre::Quaternion(o_w, o_x, o_y, o_z));
78  _markers[i]->setShowMarker(_showMarker);
79  _markers[i]->setShowAxes(_showAxes);
80  _markers[i]->setShowLabel(_showLabel);
81  _markers[i]->setColorLabel(_colorLabel);
82  _markers[i]->setScale(Ogre::Vector3(_scale, _scale, _scale));
83  }
84  }
85 
86  void MarkerDetectionVisual::setFramePosition(const Ogre::Vector3 &position) {
87  frame_node_->setPosition(position);
88  }
89 
90  void MarkerDetectionVisual::setFrameOrientation(const Ogre::Quaternion &orientation) {
91  frame_node_->setOrientation(orientation);
92  }
93 
94  void MarkerDetectionVisual::setShowAxes(bool showAxes) {
95  for (size_t i = 0; i < _markers.size(); i++) {
96  _markers[i]->setShowAxes(showAxes);
97  }
98 
99  _showAxes = showAxes;
100  }
101 
102  void MarkerDetectionVisual::setShowMarker(bool showMarker) {
103  for (size_t i = 0; i < _markers.size(); i++) {
104  _markers[i]->setShowMarker(showMarker);
105  }
106 
107  _showMarker = showMarker;
108  }
109 
110  void MarkerDetectionVisual::setShowLabel(bool showLabel) {
111  for (size_t i = 0; i < _markers.size(); i++) {
112  _markers[i]->setShowLabel(showLabel);
113  }
114 
115  _showLabel = showLabel;
116  }
117  void MarkerDetectionVisual::setColorLabel(Ogre::ColourValue color) {
118  _colorLabel = color;
119  for (size_t i = 0; i < _markers.size(); i++) {
120  _markers[i]->setColorLabel(_colorLabel);
121  }
122  }
123 
125  for (size_t i = 0; i < _markers.size(); i++) {
126  _markers[i]->setScale(Ogre::Vector3(scale, scale, scale));
127  }
128 
129  _scale = scale;
130  }
131 
132 }
std::vector< boost::shared_ptr< Marker > > _markers
void setFrameOrientation(const Ogre::Quaternion &orientation)
MarkerDetectionVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node)
void setMessage(const marker_msgs::MarkerDetection::ConstPtr &msg)
void setFramePosition(const Ogre::Vector3 &position)


marker_rviz_plugin
Author(s): Markus Bader, Lukas Pfeifhofer, Markus Macsek
autogenerated on Mon Jun 10 2019 13:54:22