publish_click_camera_display.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, 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 #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   //assign a PublishClickViewController to our render panel,
00055   //so it receives the mouse events while the "Move Camera" tool is active
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   //publish_click_view_controller_ will be deleted by render_panel_
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   //rviz::ROSTopicStringPropertyPtr topic_prop = publish_click_topic_property_.lock();
00077   //topic_prop->setMessageType(ros::message_traits::datatype< pr2_controllers_msgs::PublishClickActionGoal >());
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 // ----------------------------------- Pre- and Post-render ------------------------------------------
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 }


pr2_interactive_manipulation
Author(s): Matei Ciocarlie, Kaijen Hsiao, Adam Leeper
autogenerated on Fri Jan 3 2014 12:08:59