planning_scene_render.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 /* Author: Ioan Sucan */
00031 
00032 #include <moveit/rviz_plugin_render_tools/planning_scene_render.h>
00033 #include <moveit/rviz_plugin_render_tools/robot_state_visualization.h>
00034 #include <moveit/rviz_plugin_render_tools/render_shapes.h>
00035 #include <rviz/display_context.h>
00036 
00037 #include <OGRE/OgreSceneNode.h>
00038 #include <OGRE/OgreSceneManager.h>
00039 
00040 namespace moveit_rviz_plugin
00041 {
00042 
00043 PlanningSceneRender::PlanningSceneRender(Ogre::SceneNode *node, rviz::DisplayContext *context, const RobotStateVisualizationPtr &robot) :
00044   planning_scene_geometry_node_(node->createChildSceneNode()),
00045   context_(context),
00046   scene_robot_(robot)
00047 {
00048   render_shapes_.reset(new RenderShapes(context));
00049 }
00050 
00051 PlanningSceneRender::~PlanningSceneRender()
00052 {
00053   context_->getSceneManager()->destroySceneNode(planning_scene_geometry_node_->getName());
00054 }
00055 
00056 void PlanningSceneRender::clear()
00057 {
00058   render_shapes_->clear();
00059 }
00060 
00061 void PlanningSceneRender::renderPlanningScene(const planning_scene::PlanningSceneConstPtr &scene,
00062                                               const rviz::Color &default_env_color,
00063                                               const rviz::Color &default_attached_color,
00064                                               OctreeVoxelRenderMode octree_voxel_rendering,
00065                                               OctreeVoxelColorMode octree_color_mode,
00066                                               float default_scene_alpha)
00067 {
00068   if (!scene)
00069     return;
00070 
00071   clear();
00072 
00073   if (scene_robot_)
00074   {
00075     robot_state::RobotStateConstPtr ks(new robot_state::RobotState(scene->getCurrentState()));
00076     std_msgs::ColorRGBA color;
00077     color.r = default_attached_color.r_;
00078     color.g = default_attached_color.g_;
00079     color.b = default_attached_color.b_;
00080     color.a = 1.0f;
00081     planning_scene::ObjectColorMap color_map;
00082     scene->getKnownObjectColors(color_map);
00083     scene_robot_->update(ks, color, color_map);
00084   }
00085 
00086   const std::vector<std::string> &ids = scene->getWorld()->getObjectIds();
00087   for (std::size_t i = 0 ; i < ids.size() ; ++i)
00088   {
00089     collision_detection::CollisionWorld::ObjectConstPtr o = scene->getWorld()->getObject(ids[i]);
00090     rviz::Color color = default_env_color;
00091     float alpha = default_scene_alpha;
00092     if (scene->hasObjectColor(ids[i]))
00093     {
00094       const std_msgs::ColorRGBA &c = scene->getObjectColor(ids[i]);
00095       color.r_ = c.r; color.g_ = c.g; color.b_ = c.b;
00096       alpha = c.a;
00097     }
00098     for (std::size_t j = 0 ; j < o->shapes_.size() ; ++j)
00099       render_shapes_->renderShape(planning_scene_geometry_node_, o->shapes_[j].get(), o->shape_poses_[j],
00100                                   octree_voxel_rendering, octree_color_mode, color, alpha);
00101   }
00102 }
00103 
00104 }


visualization
Author(s): Ioan Sucan , Dave Coleman
autogenerated on Mon Oct 6 2014 02:34:03