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 #include "pr2_interactive_manipulation/publish_click_camera_display.h"
00031
00032 #include <boost/make_shared.hpp>
00033
00034 #include <rviz/visualization_manager.h>
00035 #include <rviz/render_panel.h>
00036 #include <rviz/selection/selection_manager.h>
00037 #include <rviz/properties/property.h>
00038 #include <rviz/properties/property_manager.h>
00039
00040 namespace pr2_interactive_manipulation
00041 {
00042
00043 PublishClickCameraDisplay::PublishClickCameraDisplay() :
00044 rviz::CameraDisplay(),
00045 selection_handler_( new PublishClickSelectionHandler(this) ),
00046 publish_click_view_controller_( NULL )
00047 {
00048 }
00049
00050 void PublishClickCameraDisplay::onInitialize()
00051 {
00052 CameraDisplay::onInitialize();
00053
00054
00055
00056 publish_click_view_controller_ = new PublishClickViewController( texture_, vis_manager_, name_ );
00057 render_panel_->setViewController( publish_click_view_controller_ );
00058 setPublishClickTopic( "/interactive_manipulation_image_click" );
00059 vis_manager_->getSelectionManager()->addObject( vis_manager_->getSelectionManager()->createHandle(),
00060 selection_handler_ );
00061 }
00062
00063 PublishClickCameraDisplay::~PublishClickCameraDisplay()
00064 {
00065
00066 }
00067
00068 void PublishClickCameraDisplay::createProperties()
00069 {
00070 publish_click_topic_property_ = property_manager_->createProperty<rviz::ROSTopicStringProperty>(
00071 "Publish Click Topic", property_prefix_,
00072 boost::bind( &PublishClickCameraDisplay::getPublishClickTopic, this ),
00073 boost::bind( &PublishClickCameraDisplay::setPublishClickTopic, this, _1 ),
00074 parent_category_, this );
00075 setPropertyHelpText(publish_click_topic_property_, "Topic where click information is published.");
00076
00077
00078 CameraDisplay::createProperties();
00079 }
00080
00081 void PublishClickCameraDisplay::setPublishClickTopic(const std::string& topic)
00082 {
00083 publish_click_view_controller_->setTopic( topic );
00084 propertyChanged(publish_click_topic_property_);
00085 }
00086
00087 const std::string& PublishClickCameraDisplay::getPublishClickTopic()
00088 {
00089 return publish_click_view_controller_->getTopic();
00090 }
00091
00092 void PublishClickCameraDisplay::update(float wall_dt, float ros_dt)
00093 {
00094 force_render_ = true;
00095 CameraDisplay::update(wall_dt, ros_dt);
00096 }
00097
00098 void PublishClickCameraDisplay::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
00099 {
00100 hideBlacklistDisplays("/publish_click_camera_display/render_blacklist");
00101 CameraDisplay::preRenderTargetUpdate(evt);
00102 }
00103
00104 void PublishClickCameraDisplay::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
00105 {
00106 restoreBlacklistDisplays();
00107 CameraDisplay::postRenderTargetUpdate(evt);
00108 }
00109
00110 void PublishClickCameraDisplay::preRenderSelectionHandler(uint32_t pass)
00111 {
00112 if (vis_manager_->getSelectionManager()->getCurrentViewport() == render_panel_->getViewport())
00113 {
00114 hideBlacklistDisplays("/publish_click_camera_display/selection_blacklist");
00115 }
00116 }
00117
00118 void PublishClickCameraDisplay::postRenderSelectionHandler(uint32_t pass)
00119 {
00120 if (vis_manager_->getSelectionManager()->getCurrentViewport() == render_panel_->getViewport())
00121 {
00122 restoreBlacklistDisplays();
00123 }
00124 }
00125
00126
00127
00128 void PublishClickCameraDisplay::hideBlacklistDisplays(std::string blacklist_name)
00129 {
00130 hidden_displays_.clear();
00131 std::vector<std::string> blacklist;
00132 try
00133 {
00134 blacklist = object_manipulator::configurationLoader().getVectorParam(blacklist_name);
00135 }
00136 catch(object_manipulator::MissingParamException &ex)
00137 {
00138 ROS_ERROR_STREAM("Camera display blacklist not found at " << blacklist_name);
00139 return;
00140 }
00141 catch(object_manipulator::BadParamException &ex)
00142 {
00143 ROS_ERROR_STREAM("Camera display blacklist at " << blacklist_name << " is malformed");
00144 return;
00145 }
00146
00147 std::vector<rviz::DisplayWrapper*> &displays = vis_manager_->getDisplays();
00148 for (std::vector<std::string>::iterator name_it = blacklist.begin(); name_it != blacklist.end(); name_it++)
00149 {
00150 for (std::vector<rviz::DisplayWrapper*>::iterator it = displays.begin(); it != displays.end(); it++)
00151 {
00152 if ( (*it)->getName() == *name_it ) hidden_displays_.insert( *it );
00153 }
00154 }
00155 for (std::set<rviz::DisplayWrapper*>::iterator it = hidden_displays_.begin(); it != hidden_displays_.end(); it++)
00156 {
00157 ROS_DEBUG_STREAM("Hiding display: " << (*it)->getName());
00158 (*it)->getDisplay()->hideVisible();
00159 }
00160 }
00161
00162 void PublishClickCameraDisplay::restoreBlacklistDisplays()
00163 {
00164 std::vector<rviz::DisplayWrapper*> &displays = vis_manager_->getDisplays();
00165 for (std::vector<rviz::DisplayWrapper*>::iterator it = displays.begin(); it != displays.end(); it++)
00166 {
00167 std::set<rviz::DisplayWrapper*>::iterator my_it = hidden_displays_.find( *it );
00168 if ( my_it != hidden_displays_.end())
00169 {
00170 ROS_DEBUG_STREAM("Hiding display: " << (*it)->getName());
00171 (*my_it)->getDisplay()->restoreVisible();
00172 hidden_displays_.erase(my_it);
00173 }
00174 }
00175 for (std::set<rviz::DisplayWrapper*>::iterator it = hidden_displays_.begin(); it != hidden_displays_.end(); it++)
00176 {
00177 ROS_WARN_STREAM("Display " << (*it)->getDisplay()->getName() << " not found for post-render update");
00178 }
00179 }
00180
00181
00182 }