MapGraphDisplay.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
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  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #include <boost/bind.hpp>
29 
30 #include <OgreSceneNode.h>
31 #include <OgreSceneManager.h>
32 #include <OgreManualObject.h>
33 #include <OgreBillboardSet.h>
34 #include <OgreMatrix4.h>
35 
36 #include <tf/transform_listener.h>
37 
38 #include <rviz/display_context.h>
39 #include <rviz/frame_manager.h>
43 
44 #include "MapGraphDisplay.h"
45 
46 #include <rtabmap/core/Link.h>
48 
49 namespace rtabmap_ros
50 {
51 
53 {
54  color_neighbor_property_ = new rviz::ColorProperty( "Neighbor", Qt::blue,
55  "Color to draw neighbor links.", this );
56  color_neighbor_merged_property_ = new rviz::ColorProperty( "Merged neighbor", QColor(255,170,0),
57  "Color to draw merged neighbor links.", this );
58  color_global_property_ = new rviz::ColorProperty( "Global loop closure", Qt::red,
59  "Color to draw global loop closure links.", this );
60  color_local_property_ = new rviz::ColorProperty( "Local loop closure", Qt::yellow,
61  "Color to draw local loop closure links.", this );
62  color_landmark_property_ = new rviz::ColorProperty( "Landmark", Qt::darkGreen,
63  "Color to draw landmark links.", this );
64  color_user_property_ = new rviz::ColorProperty( "User", Qt::red,
65  "Color to draw user links.", this );
66  color_virtual_property_ = new rviz::ColorProperty( "Virtual", Qt::magenta,
67  "Color to draw virtual links.", this );
68 
69  alpha_property_ = new rviz::FloatProperty( "Alpha", 1.0,
70  "Amount of transparency to apply to the path.", this );
71 }
72 
74 {
76 }
77 
79 {
82 }
83 
85 {
88 }
89 
91 {
92  for(unsigned int i=0; i<manual_objects_.size(); ++i)
93  {
94  manual_objects_[i]->clear();
95  scene_manager_->destroyManualObject( manual_objects_[i] );
96  }
97  manual_objects_.clear();
98 }
99 
100 void MapGraphDisplay::processMessage( const rtabmap_ros::MapGraph::ConstPtr& msg )
101 {
102  if(!(msg->poses.size() == msg->posesId.size()))
103  {
104  ROS_ERROR("rtabmap_ros::MapGraph: Error pose ids and poses must have all the same size.");
105  return;
106  }
107 
108  // Get links
109  std::map<int, rtabmap::Transform> poses;
110  std::multimap<int, rtabmap::Link> links;
111  rtabmap::Transform mapToOdom;
112  rtabmap_ros::mapGraphFromROS(*msg, poses, links, mapToOdom);
113 
114  destroyObjects();
115 
116  Ogre::Vector3 position;
117  Ogre::Quaternion orientation;
118  if( !context_->getFrameManager()->getTransform( msg->header, position, orientation ))
119  {
120  ROS_DEBUG( "Error transforming from frame '%s' to frame '%s'", msg->header.frame_id.c_str(), qPrintable( fixed_frame_ ));
121  }
122 
123  Ogre::Matrix4 transform( orientation );
124  transform.setTrans( position );
125 
126  if(links.size())
127  {
128  Ogre::ColourValue color;
129  Ogre::ManualObject* manual_object = scene_manager_->createManualObject();
130  manual_object->setDynamic( true );
131  scene_node_->attachObject( manual_object );
132  manual_objects_.push_back(manual_object);
133 
134  manual_object->estimateVertexCount(links.size() * 2);
135  manual_object->begin( "BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST );
136  for(std::multimap<int, rtabmap::Link>::iterator iter=links.begin(); iter!=links.end(); ++iter)
137  {
138  std::map<int, rtabmap::Transform>::iterator poseIterFrom = poses.find(iter->second.from());
139  std::map<int, rtabmap::Transform>::iterator poseIterTo = poses.find(iter->second.to());
140  if(poseIterFrom != poses.end() && poseIterTo != poses.end())
141  {
142  if(iter->second.type() == rtabmap::Link::kNeighbor)
143  {
145  }
146  else if(iter->second.type() == rtabmap::Link::kNeighborMerged)
147  {
149  }
150  else if(iter->second.type() == rtabmap::Link::kVirtualClosure)
151  {
153  }
154  else if(iter->second.type() == rtabmap::Link::kUserClosure)
155  {
157  }
158  else if(iter->second.type() == rtabmap::Link::kLocalSpaceClosure || iter->second.type() == rtabmap::Link::kLocalTimeClosure)
159  {
161  }
162  else if(iter->second.type() == rtabmap::Link::kLandmark)
163  {
165  }
166  else
167  {
169  }
170  color.a = alpha_property_->getFloat();
171  Ogre::Vector3 pos;
172  pos = transform * Ogre::Vector3( poseIterFrom->second.x(), poseIterFrom->second.y(), poseIterFrom->second.z() );
173  manual_object->position( pos.x, pos.y, pos.z );
174  manual_object->colour( color );
175  pos = transform * Ogre::Vector3( poseIterTo->second.x(), poseIterTo->second.y(), poseIterTo->second.z() );
176  manual_object->position( pos.x, pos.y, pos.z );
177  manual_object->colour( color );
178  }
179  }
180 
181  manual_object->end();
182  }
183 }
184 
185 } // namespace rtabmap_ros
186 
Ogre::ColourValue getOgreColor() const
DisplayContext * context_
virtual float getFloat() const
virtual void reset()
Overridden from Display.
ColorProperty * color_global_property_
Ogre::SceneNode * scene_node_
QString fixed_frame_
void mapGraphFromROS(const rtabmap_ros::MapGraph &msg, std::map< int, rtabmap::Transform > &poses, std::multimap< int, rtabmap::Link > &links, rtabmap::Transform &mapToOdom)
virtual FrameManager * getFrameManager() const =0
ColorProperty * color_local_property_
Ogre::SceneManager * scene_manager_
ColorProperty * color_user_property_
ColorProperty * color_virtual_property_
void processMessage(const rtabmap_ros::MapGraph::ConstPtr &msg)
Overridden from MessageFilterDisplay.
ColorProperty * color_landmark_property_
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
std::vector< Ogre::ManualObject * > manual_objects_
PLUGINLIB_EXPORT_CLASS(rtabmap_ros::CoreWrapper, nodelet::Nodelet)
ColorProperty * color_neighbor_property_
Displays the graph of rtabmap::MapGraph message.
#define ROS_ERROR(...)
virtual void onInitialize()
Overridden from Display.
ColorProperty * color_neighbor_merged_property_
GLM_FUNC_DECL detail::tmat4x4< T, P > orientation(detail::tvec3< T, P > const &Normal, detail::tvec3< T, P > const &Up)
#define ROS_DEBUG(...)


rtabmap_ros
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:42:19