ObjectDetectionDisplay.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2017 by Florian Beck <florian.beck@tuwien.ac.at> *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above copyright *
10  * notice, this list of conditions and the following disclaimer. *
11  * 2. Redistributions in binary form must reproduce the above copyright *
12  * notice, this list of conditions and the following disclaimer in *
13  * the documentation and/or other materials provided with the *
14  * distribution. *
15  * 3. Neither the name of the copyright holder nor the names of its *
16  * contributors may be used to endorse or promote products derived *
17  * from this software without specific prior written permission. *
18  * *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY *
29  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
30  * POSSIBILITY OF SUCH DAMAGE. *
31  ***************************************************************************/
32 
33 #include <OGRE/OgreSceneNode.h>
34 #include <OGRE/OgreSceneManager.h>
35 
36 #include <tf/transform_listener.h>
37 
42 #include <rviz/frame_manager.h>
43 
49 
50 #include <boost/foreach.hpp>
51 #define foreach BOOST_FOREACH
52 
53 namespace tuw_object_rviz
54 {
55 // The constructor must have no arguments, so we can't give the
56 // constructor the parameters it needs to fully initialize.
58 {
59 }
60 
61 // After the top-level rviz::Display::initialize() does its own setup,
62 // it calls the subclass's onInitialize() function. This is where we
63 // instantiate all the workings of the class. We make sure to also
64 // call our immediate super-class's onInitialize() function, since it
65 // does important stuff setting up the message filter.
66 //
67 // Note that "MFDClass" is a typedef of
68 // ``MessageFilterDisplay<message type>``, to save typing that long
69 // templated class name every time you need to refer to the
70 // superclass.
72 {
74 
75  visual_.clear();
76 
78  new rviz::BoolProperty("Render covariances", true, "Render covariance ellipses", this, SLOT(stylesChanged()));
79 
81  new rviz::BoolProperty("Render detection IDs", true, "Render IDs of the detection", this, SLOT(stylesChanged()));
82 
84  new rviz::BoolProperty("Render sensor type text", false,
85  "Render detection sensor type as text below detected object", this, SLOT(stylesChanged()));
86 
88  new rviz::BoolProperty("Render pose arrow", false,
89  "Render pose for detected object", this, SLOT(stylesChanged()));
90 
92  new rviz::ColorProperty("Color", Qt::black, "Color of detected object", this, SLOT(stylesChanged()));
93 
94  style_property_ = new rviz::EnumProperty( "Style", "Cylinders", "Rendering mode to use, in order of computational complexity.", this, SLOT(stylesChanged()), this );
96  style_property_->addOption( "Cylinders", STYLE_CYLINDER );
97  style_property_->addOption( "Person meshes", STYLE_PERSON_MESHES );
98  style_property_->addOption( "Bounding boxes", STYLE_BOUNDING_BOXES );
99 }
100 
102 {
103  foreach (boost::shared_ptr<ObjectDetectionVisual>& object_detection_visual, visual_)
104  {
105  object_detection_visual.reset(new ObjectDetectionVisual(context_->getSceneManager(), scene_node_));
106  }
107 }
108 
109 // Clear the visual by deleting its object.
111 {
112  MFDClass::reset();
113 }
114 
116 {
117  foreach (boost::shared_ptr<ObjectDetectionVisual>& object_detection_visual, visual_)
118  {
119  object_detection_visual->setColor(color_property_->getOgreColor());
120  object_detection_visual->setVisiblities(render_covariances_property_->getBool(),
124  );
125  object_detection_visual->setStyle(static_cast<Styles>(style_property_->getOptionInt()));
126  }
127 }
128 
129 // This is our callback to handle an incoming message.
130 void ObjectDetectionDisplay::processMessage(const tuw_object_msgs::ObjectDetection::ConstPtr& msg)
131 {
132  // clear previous detections
133  visual_.clear();
134 
135  for (std::vector<tuw_object_msgs::ObjectWithCovariance>::const_iterator detected_object_it = msg->objects.begin();
136  detected_object_it != msg->objects.end(); detected_object_it++)
137  {
138  // create new visual object
139  boost::shared_ptr<ObjectDetectionVisual> detected_object_visual;
140 
141  // TODO: add additional object types and their visualization
142  if(msg->type == tuw_object_msgs::ObjectDetection::OBJECT_TYPE_PERSON)
143  {
145  }
146  else if(detected_object_it->object.shape == tuw_object_msgs::Object::SHAPE_DOOR)
147  {
149  }
150  else if(detected_object_it->object.shape == tuw_object_msgs::Object::SHAPE_TRAFFIC_CONE)
151  {
153  }
154  else
155  {
157  }
158 
159  tuw_object_msgs::ObjectWithCovarianceConstPtr detected_object =
161  new tuw_object_msgs::ObjectWithCovariance(*detected_object_it));
162 
163  // Here we call the rviz::FrameManager to get the transform from the
164  // fixed frame to the frame in the header of this Imu message. If
165  // it fails, we can't do anything else so we return.
166  Ogre::Quaternion orientation;
167  Ogre::Vector3 position;
168 
169 // ROS_INFO("ObjectDetectionDisplay::processMessage(): msg frame id = %s", msg->header.frame_id.c_str());
170 // ROS_INFO("Transform from %s to %s", msg->header.frame_id.c_str(), qPrintable(fixed_frame_));
171  if (!context_->getFrameManager()->getTransform(msg->header, position, orientation))
172  {
173  ROS_DEBUG("Error transforming from frame '%s' to frame '%s'", msg->header.frame_id.c_str(),
174  qPrintable(fixed_frame_));
175  return;
176  }
177  // set frame position to origin of parent, then explicitly transform points in msg
178  // the advantage of this is that one can treat every detected object the same
179  // regardless of orientation of the coordinate system
180  // e.g. z = 0 means on the ground for every detection
181  detected_object_visual->setFramePosition(Ogre::Vector3(0, 0, 0));
182  detected_object_visual->setFrameOrientation(Ogre::Quaternion(1, 0, 0, 0));
183  detected_object_visual->setTransform(position, orientation);
184  detected_object_visual->setMessage(detected_object);
185 
186  visual_.push_back(detected_object_visual);
187 
188  // Now set or update the contents of the visual.
189  stylesChanged();
190  }
191 }
192 
193 } // end namespace tuw_geometry_rviz
194 
195 // Tell pluginlib about this class. It is important to do this in
196 // global scope, outside our package's namespace.
199 
void processMessage(const tuw_object_msgs::ObjectDetection::ConstPtr &msg)
Ogre::ColourValue getOgreColor() const
DisplayContext * context_
Ogre::SceneNode * scene_node_
virtual bool getBool() const
QString fixed_frame_
virtual void addOption(const QString &option, int value=0)
virtual FrameManager * getFrameManager() const =0
virtual Ogre::SceneManager * getSceneManager() const =0
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
virtual int getOptionInt()
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
std::vector< boost::shared_ptr< ObjectDetectionVisual > > visual_
#define ROS_DEBUG(...)


tuw_object_rviz
Author(s): Florian Beck
autogenerated on Mon Jun 10 2019 15:40:17