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 #include "but_camcast.h"
00029
00030
00031 #include <OGRE/OgreSceneManager.h>
00032 #include "OGRE/OgreWindowEventUtilities.h"
00033 #include "OGRE/OgreManualObject.h"
00034 #include "OGRE/OgreEntity.h"
00035
00036
00037 #include <rviz/render_panel.h>
00038 #include <rviz/visualization_manager.h>
00039 #include <rviz/window_manager_interface.h>
00040
00041 #include <wx/filedlg.h>
00042
00043
00044 #include <sensor_msgs/Image.h>
00045
00046
00047 #include <sstream>
00048
00049 #define CAMERA_SCREENCAST_TOPIC_NAME std::string("rviz_cam_rgb")
00050 #define DEFAULT_PUBLISHING_PERIOD double(0.1)
00051
00052
00053
00054
00055 srs_ui_but::CButCamCast::CButCamCast(const std::string & name,rviz::VisualizationManager * manager)
00056 : Display( name, manager )
00057 , m_bPublish(true)
00058 {
00059
00060 rviz::WindowManagerInterface * wi( manager->getWindowManager() );
00061
00062 if( wi != 0 )
00063 {
00064
00065 m_pane = new CControllPane( wi->getParentWindow(), wxT("Screencasts manager"), wi);
00066
00067 if( m_pane != 0 )
00068 {
00069 wi->addPane( "Screencasts manager", m_pane );
00070 wi->showPane( m_pane );
00071
00072
00073 m_pane->getSigChckBox().connect( boost::bind( &CButCamCast::onPublishStateChanged, this, _1) );
00074 m_pane->getSigSave().connect( boost::bind( &CButCamCast::onSave, this, _1 ) );
00075 }
00076
00077 }else{
00078 std::cerr << "No window manager, no panes :( " << std::endl;
00079 }
00080
00081
00082
00083 ros::NodeHandle private_nh("/");
00084
00085
00086
00087
00088 private_nh.param("rviz_screencast_topic_name", m_camCastPublisherName, CAMERA_SCREENCAST_TOPIC_NAME);
00089
00090
00091 private_nh.param("publishig_period", m_timerPeriod, DEFAULT_PUBLISHING_PERIOD );
00092
00093
00094 m_sceneNode = scene_manager_->getRootSceneNode()->createChildSceneNode();
00095
00096
00097 this->m_camCastPublisher = private_nh.advertise< sensor_msgs::Image >(m_camCastPublisherName, 100, false);
00098
00099
00100 createGeometry(private_nh);
00101
00102
00103 m_timer = private_nh.createTimer( ros::Duration(m_timerPeriod), boost::bind( &CButCamCast::onTimerPublish, this, _1) );
00104
00105
00106 m_textureWithRtt->setFrame("/map");
00107
00108 }
00109
00110
00111
00112
00113 srs_ui_but::CButCamCast::~CButCamCast()
00114 {
00115
00116 destroyGeometry();
00117
00118 }
00119
00120
00121
00122
00123
00124 void srs_ui_but::CButCamCast::onEnable()
00125 {
00126 m_sceneNode->setVisible( true );
00127 }
00128
00129
00130
00131
00132 void srs_ui_but::CButCamCast::onDisable()
00133 {
00134 m_sceneNode->setVisible( false );
00135 }
00136
00137
00138
00139
00140 bool srs_ui_but::CButCamCast::createGeometry(const ros::NodeHandle & nh)
00141 {
00142
00143 rviz::RenderPanel * panel = vis_manager_->getRenderPanel();
00144 if( panel == 0 )
00145 {
00146 ROS_DEBUG( "No render panel... ");
00147 return false;
00148 }
00149
00150 Ogre::Camera * camera = panel->getCamera();
00151
00152
00153
00154 m_textureWithRtt = new CRosRttTexture( 512, 512, camera );
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 return true;
00260 }
00261
00262 void srs_ui_but::CButCamCast::destroyGeometry()
00263 {
00264
00265 if( m_sceneNode != 0 )
00266 scene_manager_->destroySceneNode(m_sceneNode->getName());
00267 }
00268
00270 void srs_ui_but::CButCamCast::update (float wall_dt, float ros_dt)
00271 {
00272 rviz::RenderPanel * panel = vis_manager_->getRenderPanel();
00273 if( panel == 0 )
00274 {
00275 ROS_DEBUG( "No render panel... ");
00276 }
00277
00278 Ogre::Camera * camera = panel->getCamera();
00279
00280 if( camera == 0 )
00281 {
00282 ROS_DEBUG( "No camera ");
00283 }
00284 }
00285
00286
00287
00288
00289
00290 void srs_ui_but::CButCamCast::onTimerPublish(const ros::TimerEvent&)
00291 {
00292
00293
00294 if( m_bPublish && (m_camCastPublisher.getNumSubscribers() > 0 ) && m_textureWithRtt->hasData() )
00295 {
00296
00297 m_camCastPublisher.publish( m_textureWithRtt->getImage() );
00298 }
00299 }
00300
00304 void srs_ui_but::CButCamCast::onPublishStateChanged(bool state)
00305 {
00306 if( state )
00307 m_timer.start();
00308 else
00309 m_timer.stop();
00310 }
00311
00315 void srs_ui_but::CButCamCast::onSave( std::string filename )
00316 {
00317 m_textureWithRtt->saveImage( filename );
00318 }
00319
00320
00322 const int ID_CHECKBOX(100);
00323 const int ID_SAVE_BUTTON(101);
00324
00325 srs_ui_but::CButCamCast::CControllPane::CControllPane(wxWindow *parent, const wxString& title, rviz::WindowManagerInterface * wmi): wxPanel( parent, wxID_ANY, wxDefaultPosition, wxSize(280, 180), wxTAB_TRAVERSAL, title)
00326 , m_wmi( wmi )
00327 {
00328
00329 m_button = new wxButton(this, ID_SAVE_BUTTON, wxT("Save screenshot"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
00330
00331 m_chkb = new wxCheckBox(this, ID_CHECKBOX, wxT("Publish images"),
00332 wxPoint(20, 20));
00333 m_chkb->SetValue( true );
00334
00335
00336 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00337 this->SetSizer(sizer);
00338
00339 wxSizer *hsizer = new wxBoxSizer(wxHORIZONTAL);
00340 hsizer->Add(m_chkb, ID_CHECKBOX, wxALIGN_LEFT);
00341 hsizer->Add(m_button, ID_SAVE_BUTTON, wxALIGN_RIGHT);
00342
00343 sizer->Add(hsizer, 0, wxALIGN_LEFT);
00344
00345 sizer->SetSizeHints(this);
00346
00347 }
00348
00350
00354 void srs_ui_but::CButCamCast::CControllPane::OnChckToggle(wxCommandEvent& event)
00355 {
00356
00357 m_sigCheckBox( m_chkb->GetValue() );
00358 }
00359
00361
00365 void srs_ui_but::CButCamCast::CControllPane::OnSave(wxCommandEvent& event)
00366 {
00367 wxFileDialog fileDlg(this, _("Choose file to save"), wxEmptyString, _("screenshot.png"), _("*.*"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
00368
00369 wxString filename, directory;
00370
00371
00372 if(m_chkb->GetValue())
00373 m_sigCheckBox( false );
00374
00375 if( fileDlg.ShowModal() == wxID_OK )
00376 {
00377 filename = fileDlg.GetFilename();
00378 directory = fileDlg.GetDirectory();
00379
00380 std::string path(std::string( wxString(directory + wxFileName::GetPathSeparator() + filename).mb_str() ) );
00381
00382 m_sigSave( path );
00383 }
00384
00385
00386 if(m_chkb->GetValue())
00387 m_sigCheckBox( true );
00388
00389
00390 }
00391
00393 BEGIN_EVENT_TABLE(srs_ui_but::CButCamCast::CControllPane, wxPanel)
00394 EVT_BUTTON(ID_SAVE_BUTTON, srs_ui_but::CButCamCast::CControllPane::OnSave)
00395 EVT_CHECKBOX(ID_CHECKBOX, srs_ui_but::CButCamCast::CControllPane::OnChckToggle )
00396 END_EVENT_TABLE()