planning_scene_render.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
40 #include <rviz/display_context.h>
41 
42 #include <OgreSceneNode.h>
43 #include <OgreSceneManager.h>
44 
45 namespace moveit_rviz_plugin
46 {
48  const RobotStateVisualizationPtr& robot)
49  : planning_scene_geometry_node_(node->createChildSceneNode()), context_(context), scene_robot_(robot)
50 {
51  render_shapes_.reset(new RenderShapes(context));
52 }
53 
55 {
56  context_->getSceneManager()->destroySceneNode(planning_scene_geometry_node_->getName());
57 }
58 
60 {
61  render_shapes_->clear();
62 }
63 
64 void PlanningSceneRender::renderPlanningScene(const planning_scene::PlanningSceneConstPtr& scene,
65  const rviz::Color& default_env_color,
66  const rviz::Color& default_attached_color,
67  OctreeVoxelRenderMode octree_voxel_rendering,
68  OctreeVoxelColorMode octree_color_mode, float default_scene_alpha)
69 {
70  if (!scene)
71  return;
72 
73  clear();
74 
75  if (scene_robot_)
76  {
77  robot_state::RobotState* rs = new robot_state::RobotState(scene->getCurrentState());
78  rs->update();
79 
80  std_msgs::ColorRGBA color;
81  color.r = default_attached_color.r_;
82  color.g = default_attached_color.g_;
83  color.b = default_attached_color.b_;
84  color.a = 1.0f;
86  scene->getKnownObjectColors(color_map);
87  scene_robot_->update(robot_state::RobotStateConstPtr(rs), color, color_map);
88  }
89 
90  const std::vector<std::string>& ids = scene->getWorld()->getObjectIds();
91  for (std::size_t i = 0; i < ids.size(); ++i)
92  {
93  collision_detection::CollisionWorld::ObjectConstPtr o = scene->getWorld()->getObject(ids[i]);
94  rviz::Color color = default_env_color;
95  float alpha = default_scene_alpha;
96  if (scene->hasObjectColor(ids[i]))
97  {
98  const std_msgs::ColorRGBA& c = scene->getObjectColor(ids[i]);
99  color.r_ = c.r;
100  color.g_ = c.g;
101  color.b_ = c.b;
102  alpha = c.a;
103  }
104  for (std::size_t j = 0; j < o->shapes_.size(); ++j)
105  render_shapes_->renderShape(planning_scene_geometry_node_, o->shapes_[j].get(), o->shape_poses_[j],
106  octree_voxel_rendering, octree_color_mode, color, alpha);
107  }
108 }
109 }
PlanningSceneRender(Ogre::SceneNode *root_node, rviz::DisplayContext *context, const RobotStateVisualizationPtr &robot)
World::ObjectConstPtr ObjectConstPtr
std::map< std::string, std_msgs::ColorRGBA > ObjectColorMap
virtual Ogre::SceneManager * getSceneManager() const =0
void renderPlanningScene(const planning_scene::PlanningSceneConstPtr &scene, const rviz::Color &default_scene_color, const rviz::Color &default_attached_color, OctreeVoxelRenderMode voxel_render_mode, OctreeVoxelColorMode voxel_color_mode, float default_scene_alpha)


visualization
Author(s): Ioan Sucan , Dave Coleman , Sachin Chitta
autogenerated on Sun Oct 18 2020 13:19:09