Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <moveit/rviz_plugin_render_tools/planning_scene_render.h>
00038 #include <moveit/rviz_plugin_render_tools/robot_state_visualization.h>
00039 #include <moveit/rviz_plugin_render_tools/render_shapes.h>
00040 #include <rviz/display_context.h>
00041
00042 #include <OgreSceneNode.h>
00043 #include <OgreSceneManager.h>
00044
00045 namespace moveit_rviz_plugin
00046 {
00047 PlanningSceneRender::PlanningSceneRender(Ogre::SceneNode* node, rviz::DisplayContext* context,
00048 const RobotStateVisualizationPtr& robot)
00049 : planning_scene_geometry_node_(node->createChildSceneNode()), context_(context), scene_robot_(robot)
00050 {
00051 render_shapes_.reset(new RenderShapes(context));
00052 }
00053
00054 PlanningSceneRender::~PlanningSceneRender()
00055 {
00056 context_->getSceneManager()->destroySceneNode(planning_scene_geometry_node_->getName());
00057 }
00058
00059 void PlanningSceneRender::clear()
00060 {
00061 render_shapes_->clear();
00062 }
00063
00064 void PlanningSceneRender::renderPlanningScene(const planning_scene::PlanningSceneConstPtr& scene,
00065 const rviz::Color& default_env_color,
00066 const rviz::Color& default_attached_color,
00067 OctreeVoxelRenderMode octree_voxel_rendering,
00068 OctreeVoxelColorMode octree_color_mode, float default_scene_alpha)
00069 {
00070 if (!scene)
00071 return;
00072
00073 clear();
00074
00075 if (scene_robot_)
00076 {
00077 robot_state::RobotState* rs = new robot_state::RobotState(scene->getCurrentState());
00078 rs->update();
00079
00080 std_msgs::ColorRGBA color;
00081 color.r = default_attached_color.r_;
00082 color.g = default_attached_color.g_;
00083 color.b = default_attached_color.b_;
00084 color.a = 1.0f;
00085 planning_scene::ObjectColorMap color_map;
00086 scene->getKnownObjectColors(color_map);
00087 scene_robot_->update(robot_state::RobotStateConstPtr(rs), color, color_map);
00088 }
00089
00090 const std::vector<std::string>& ids = scene->getWorld()->getObjectIds();
00091 for (std::size_t i = 0; i < ids.size(); ++i)
00092 {
00093 collision_detection::CollisionWorld::ObjectConstPtr o = scene->getWorld()->getObject(ids[i]);
00094 rviz::Color color = default_env_color;
00095 float alpha = default_scene_alpha;
00096 if (scene->hasObjectColor(ids[i]))
00097 {
00098 const std_msgs::ColorRGBA& c = scene->getObjectColor(ids[i]);
00099 color.r_ = c.r;
00100 color.g_ = c.g;
00101 color.b_ = c.b;
00102 alpha = c.a;
00103 }
00104 for (std::size_t j = 0; j < o->shapes_.size(); ++j)
00105 render_shapes_->renderShape(planning_scene_geometry_node_, o->shapes_[j].get(), o->shape_poses_[j],
00106 octree_voxel_rendering, octree_color_mode, color, alpha);
00107 }
00108 }
00109 }