marker_with_covariance_array_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 <ros/ros.h>
33 
34 #include <OGRE/OgreVector3.h>
35 #include <OGRE/OgreMatrix3.h>
36 #include <OGRE/OgreSceneNode.h>
37 #include <OGRE/OgreSceneManager.h>
38 
40 
41 namespace marker_rviz_plugin {
42 
43  MarkerWithCovarianceArrayVisual::MarkerWithCovarianceArrayVisual(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  _scale = 1;
51  }
52 
54  // Destroy the frame node since we don't need it anymore.
55  scene_manager_->destroySceneNode(frame_node_);
56  }
57 
58  void MarkerWithCovarianceArrayVisual::setMessage(const marker_msgs::MarkerWithCovarianceArray::ConstPtr &msg) {
59  _markers.resize(msg->markers.size());
60 
61  for (size_t i = 0; i < msg->markers.size(); i++) {
62  marker_msgs::MarkerWithCovariance marker_cov = msg->markers[i];
63  marker_msgs::Marker marker = marker_cov.marker;
64 
65  double p_x = marker.pose.position.x;
66  double p_y = marker.pose.position.y;
67  double p_z = marker.pose.position.z;
68  double o_x = marker.pose.orientation.x;
69  double o_y = marker.pose.orientation.y;
70  double o_z = marker.pose.orientation.z;
71  double o_w = marker.pose.orientation.w;
72 
73  int id = -1;
74  if (marker.ids.size() > 0)
75  id = marker.ids[0];
76 
78  m->setPosition(Ogre::Vector3(p_x, p_y, p_z));
79  m->setOrientation(Ogre::Quaternion(o_w, o_x, o_y, o_z));
80  m->setShowMarker(_showMarker);
81  m->setShowAxes(_showAxes);
82  m->setShowLabel(_showLabel);
83  m->setScale(Ogre::Vector3(_scale, _scale, _scale));
84  m->setCovarianceMatrix(msg->markers[i].covariance);
85  _markers[i].reset(m);
86  }
87  }
88 
89  void MarkerWithCovarianceArrayVisual::setFramePosition(const Ogre::Vector3 &position) {
90  frame_node_->setPosition(position);
91  }
92 
93  void MarkerWithCovarianceArrayVisual::setFrameOrientation(const Ogre::Quaternion &orientation) {
94  frame_node_->setOrientation(orientation);
95  }
96 
98  for (size_t i = 0; i < _markers.size(); i++) {
99  _markers[i]->setShowAxes(showAxes);
100  }
101 
102  _showAxes = showAxes;
103  }
104 
106  for (size_t i = 0; i < _markers.size(); i++) {
107  _markers[i]->setShowMarker(showMarker);
108  }
109 
110  _showMarker = showMarker;
111  }
112 
114  for (size_t i = 0; i < _markers.size(); i++) {
115  _markers[i]->setShowLabel(showLabel);
116  }
117 
118  _showLabel = showLabel;
119  }
120 
122  for (size_t i = 0; i < _markers.size(); i++) {
123  _markers[i]->setScale(Ogre::Vector3(scale, scale, scale));
124  }
125 
126  _scale = scale;
127  }
128 
129 } // end namespace marker_rviz_plugin
MarkerWithCovarianceArrayVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node)
virtual void setPosition(const Ogre::Vector3 &position)
Definition: marker.cpp:137
void setMessage(const marker_msgs::MarkerWithCovarianceArray::ConstPtr &msg)


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