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/camera_focus_frontend.h"
00031
00032 #include <view_controller_msgs/CameraPlacement.h>
00033
00034 #include "object_manipulator/tools/camera_configurations.h"
00035
00036 #include <rviz/window_manager_interface.h>
00037 #include <rviz/display_context.h>
00038 #include <rviz/display.h>
00039 #include <rviz/view_controller.h>
00040 #include <rviz/selection/selection_manager.h>
00041 #include <rviz/properties/property.h>
00042 #include <rviz/properties/ros_topic_property.h>
00043 #include <rviz/load_resource.h>
00044
00045 #include <QMainWindow>
00046 #include <QToolBar>
00047 #include <QAction>
00048 #include <QPainter>
00049
00050 namespace pr2_interactive_manipulation {
00051
00052 CameraFocusFrontend::CameraFocusFrontend() :
00053 root_nh_(""),
00054 toolbar_( 0 )
00055 {
00056 topic_prop_ = new rviz::RosTopicProperty( "Command topic", "/rviz/camera_placement",
00057 QString::fromStdString(ros::message_traits::datatype<view_controller_msgs::CameraPlacement>() ),
00058 "Topic on which to send out camera placement messages.", this , SLOT( updateTopic() ) );
00059 }
00060
00061 CameraFocusFrontend::~CameraFocusFrontend()
00062 {
00063 delete toolbar_actions_;
00064 delete toolbar_;
00065 }
00066
00067 void CameraFocusFrontend::addFocusButton( QString id )
00068 {
00069
00070 QPixmap icon_fg = rviz::loadPixmap( "package://pr2_interactive_manipulation_frontend/icons/"+id+".png" );
00071 icon_fg = icon_fg.scaled( 32, 32 );
00072
00073
00074 QPixmap icon_bg = rviz::loadPixmap( "package://pr2_interactive_manipulation_frontend/icons/icon_bg.svg" );
00075
00076
00077 QPainter painter( &icon_bg );
00078 painter.drawPixmap( 0, 0, icon_fg );
00079
00080
00081 QString name = icon_bg.isNull() ? id : "";
00082 QAction* action = new QAction( icon_bg, id, toolbar_ );
00083 action->setData( QVariant( id ) );
00084 toolbar_actions_->addAction( action );
00085 toolbar_->addAction( action );
00086 }
00087
00088 void CameraFocusFrontend::onDisable()
00089 {
00090 toolbar_->setVisible(false);
00091 }
00092
00093 void CameraFocusFrontend::onEnable()
00094 {
00095 toolbar_->setVisible(true);
00096 }
00097
00098 void CameraFocusFrontend::onInitialize()
00099 {
00100 rviz::WindowManagerInterface* window_context = context_->getWindowManager();
00101 QMainWindow* main_win = dynamic_cast<QMainWindow*>( window_context );
00102
00103 if ( !main_win )
00104 {
00105 setStatusStd( rviz::StatusProperty::Error, "Initialization", "This display needs a QMainWindow as Window Manager." );
00106 return;
00107 }
00108
00109 toolbar_ = main_win->addToolBar( "CameraFocus" );
00110 toolbar_->setObjectName( "CameraFocus" );
00111 toolbar_->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
00112
00113 toolbar_actions_ = new QActionGroup( this );
00114 connect( toolbar_actions_, SIGNAL( triggered( QAction* )), this, SLOT( changeView( QAction* )));
00115
00116 addFocusButton("left");
00117 addFocusButton("right");
00118 addFocusButton("facing");
00119 addFocusButton("top");
00120
00121 addFocusButton("overhead");
00122 addFocusButton("kinect");
00123
00124 updateTopic();
00125 }
00126
00127 void CameraFocusFrontend::changeView( QAction* action )
00128 {
00129 processButtonClick( action->data().toString().toStdString() );
00130 }
00131
00132 void CameraFocusFrontend::updateTopic()
00133 {
00134 pub_ = root_nh_.advertise<view_controller_msgs::CameraPlacement>(topic_prop_->getStdString(), 5);
00135 }
00136
00137 void CameraFocusFrontend::processButtonClick(const std::string &name)
00138 {
00139 view_controller_msgs::CameraPlacement cp;
00140 try
00141 {
00142 if(object_manipulator::cameraConfigurations().get_camera_placement(name.c_str(), cp.eye, cp.focus, cp.up))
00143 {
00144 cp.target_frame = (name == "kinect") ? "head_mount_kinect_rgb_link" : "<Fixed Frame>" ;
00145 cp.time_from_start = ros::Duration(0.6);
00146 ROS_DEBUG_STREAM("Publishing camera placement request [" << name << "]: " << cp);
00147 pub_.publish(cp);
00148 }
00149 else
00150 {
00151 ROS_ERROR("There was an error processing pre-defined camera position [%s]", name.c_str());
00152 }
00153 }
00154 catch(...)
00155 {
00156 ROS_ERROR("There was an unhandled exception processing pre-defined camera position [%s]", name.c_str());
00157 }
00158 }
00159
00160 }
00161
00162
00163 #include <pluginlib/class_list_macros.h>
00164 PLUGINLIB_EXPORT_CLASS(pr2_interactive_manipulation::CameraFocusFrontend,rviz::Display )