marker_detection_display.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/OgreManualObject.h>
33 #include <OGRE/OgreEntity.h>
34 #include <OGRE/OgreMeshManager.h>
35 #include <OGRE/OgreSceneNode.h>
36 #include <OGRE/OgreSceneManager.h>
37 
38 #include <ros/package.h>
39 
40 #include <tf/transform_listener.h>
41 
47 #include <rviz/frame_manager.h>
48 #include "rviz/ogre_helpers/axes.h"
49 
52 
53 namespace marker_rviz_plugin {
54 
56 
57  _showAxesProperty = new rviz::BoolProperty("Show Axes", true, "Show or hide axes.", this, SLOT (updateVisual()));
58  _showMarkerProperty = new rviz::BoolProperty("Show Marker", true, "Show or hide marker image.", this, SLOT (updateVisual()));
59  _showLabelProperty = new rviz::BoolProperty("Show Label", true, "Show or hide marker label.", this, SLOT (updateVisual()));
60  _colourLabelProperty = new rviz::ColorProperty ( "Color Label", QColor ( 170, 170, 170 ), "Color id label", this, SLOT ( updateVisual() ) );
61  _markerSizeProperty = new rviz::FloatProperty("Marker Size", 0.3, "Size of the marker image.", this, SLOT (updateVisual()));
63 
64  // Add the plugin media folder to the Ogre ResourceGroup so it is possible to access plugin textures later on
65  std::string rviz_path = ros::package::getPath(ROS_PACKAGE_NAME);
66  Ogre::ResourceGroupManager::getSingleton().addResourceLocation(rviz_path + "/media", "FileSystem", ROS_PACKAGE_NAME);
67  Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(ROS_PACKAGE_NAME);
68 
69  }
70 
73 
75  }
76 
78  }
79 
80 // Clear the ogre_visuals by deleting their objects.
83  }
84 
91  }
92 
93 // This is our callback to handle an incoming message.
94  void MarkerDetectionDisplay::processMessage(const marker_msgs::MarkerDetection::ConstPtr &msg) {
95 
96  // Here we call the rviz::FrameManager to get the transform from the
97  // fixed frame to the frame in the header of this Imu message. If
98  // it fails, we can't do anything else so we return.
99  Ogre::Quaternion orientation;
100  Ogre::Vector3 position;
101  if (!context_->getFrameManager()->getTransform(msg->header.frame_id, msg->header.stamp, position, orientation)) {
102  ROS_DEBUG ("Error transforming from frame '%s' to frame '%s'", msg->header.frame_id.c_str(), qPrintable(fixed_frame_));
103  return;
104  }
105 
106  // Now set or update the contents of the chosen visual.
107  _visual->setMessage(msg);
108  _visual->setFramePosition(position);
109  _visual->setFrameOrientation(orientation);
114 
116  }
117 
118 } // end namespace marker_rviz_plugin
119 
120 // Tell pluginlib about this class. It is important to do this in
121 // global scope, outside our package's namespace.
123 
void setFrameOrientation(const Ogre::Quaternion &orientation)
void setMin(float min)
Ogre::ColourValue getOgreColor() const
DisplayContext * context_
virtual float getFloat() const
Ogre::SceneNode * scene_node_
virtual bool getBool() const
QString fixed_frame_
void setMessage(const marker_msgs::MarkerDetection::ConstPtr &msg)
virtual FrameManager * getFrameManager() const =0
ROSLIB_DECL std::string getPath(const std::string &package_name)
virtual Ogre::SceneManager * getSceneManager() const =0
virtual void queueRender()=0
void setFramePosition(const Ogre::Vector3 &position)
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
void processMessage(const marker_msgs::MarkerDetection::ConstPtr &msg)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
#define ROS_DEBUG(...)


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