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 #pragma once
00028 #ifndef BUT_PROJECTION_H
00029 #define BUT_PROJECTION_H
00030
00031
00032 #include <message_filters/subscriber.h>
00033
00034
00035 #include <rviz/display.h>
00036 #include <rviz/view_controller.h>
00037 #include "rviz/properties/forwards.h"
00038 #include "rviz/properties/property.h"
00039 #include "rviz/properties/edit_enum_property.h"
00040 #include "rviz/properties/property_manager.h"
00041
00042 #include "rviz/properties/forwards.h"
00043 #include <image_geometry/pinhole_camera_model.h>
00044
00045
00046 #include <OGRE/OgreSceneNode.h>
00047 #include <OgreManualObject.h>
00048 #include <OgreCamera.h>
00049 #include "OGRE/OgreMaterialManager.h"
00050 #include <OGRE/OgreTexture.h>
00051
00052
00053 #include <string>
00054
00055
00056 #include <wx/wx.h>
00057
00058
00059 #include "ros_rtt_texture.h"
00060 #include "but_rostexture.h"
00061 #include "but_depthtexture.h"
00062
00063 namespace rviz
00064 {
00065 class WindowManagerInterface;
00066 }
00067
00068 namespace srs_ui_but
00069 {
00070
00071
00072
00076 class CMaterialListener : public Ogre::MaterialManager::Listener
00077 {
00078 protected:
00080 Ogre::Material * m_materialPtr;
00081
00083 std::string m_schemeName;
00084
00086 bool m_bNotPaused;
00087
00089 float m_testingDistance;
00090
00092 bool m_bDistanceChanged;
00093
00095 bool m_bMatricesChanged;
00096
00098 Ogre::Vector4 m_camPosition;
00099
00101 Ogre::Matrix4 m_projMatrix;
00102
00104 Ogre::Vector4 m_camPlane;
00105
00107 boost::mutex m_lock;
00108
00109 public:
00111
00112
00114 CMaterialListener( Ogre::Material * material, const std::string & schemeName );
00115
00117 ~CMaterialListener();
00118
00120 void setPaused( bool bPaused ) { m_bNotPaused = !bPaused; }
00121
00123 void setTestedDistance( float distance );
00124
00126 void setCameraPosition( const Ogre::Vector4 & position, const Ogre::Vector4 & camPlane, const Ogre::Matrix4 & projMatrix );
00127
00129 float getTestedDistance() { return m_testingDistance; }
00130
00132 Ogre::Technique *handleSchemeNotFound(unsigned short, const Ogre::String& schemeName, Ogre::Material*mat, unsigned short, const Ogre::Renderable*);
00133 };
00134
00135
00136
00140 class CProjectionData
00141 {
00142
00143 typedef CRosTopicTexture tRosTextureRGB;
00144
00146 typedef CRosDepthTexture tRosTextureDepth;
00147
00148 protected:
00149 enum ETextureMode
00150 {
00151 TM_INTERNAL,
00152 TM_ROS
00153 };
00154
00155 public:
00157 CProjectionData( Ogre::SceneManager * manager, const ros::NodeHandle &nh, const std::string & materialName, const std::string & groupName = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
00158
00160 virtual ~CProjectionData();
00161
00163 Ogre::Material * getMaterialPtr() { return m_materialPtr.get(); }
00164
00166 void setListenerPtr(CMaterialListener * ptr ) { m_materialListener = ptr; if( ptr != 0 ) updateMatrices(); }
00167
00169 void setFrustrumSize( Ogre::Vector2 size );
00170
00172 void setTextureSize( int width, int height );
00173
00175 void setRGBTextureTopic( const std::string & topic );
00176
00178 void setDepthTextureTopic( const std::string & topic );
00179
00181 int getTextureWidth() { return m_texW; }
00182
00184 int getTextureHeight() { return m_texH; }
00185
00187 void clear();
00188
00190 void update() { if( m_textureRosRGB != 0 ) m_textureRosRGB->update(); }
00191
00193 void setProjectorPosition( const Ogre::Vector3 & v ){ m_projectorNode->setPosition(v); }
00194
00196 void setProjectorOrientation( const Ogre::Quaternion & q ) { m_projectorNode->setOrientation( q ); }
00197
00199 void setProjectorEquation( const Ogre::Vector4 & e ) { m_cameraEquation = e; }
00200
00202 void updateMatrices();
00203
00205 void setFOVy( Ogre::Radian fovy ) { m_frustum->setFOVy( fovy ); }
00206
00208 void setAspectRatio( Ogre::Real ar ) { m_frustum->setAspectRatio( ar ); }
00209
00211 void setCameraModel(const sensor_msgs::CameraInfo& msg) { m_textureRosDepth->setCameraModel(msg); }
00212
00213 protected:
00215 CMaterialListener * m_materialListener;
00216
00218 Ogre::MaterialPtr m_materialPtr;
00219
00221 Ogre::Vector2 m_frustrumSize;
00222
00224 size_t m_texW, m_texH;
00225
00227 ETextureMode m_mode;
00228
00230 tRosTextureRGB * m_textureRosRGB;
00231 tRosTextureDepth* m_textureRosDepth;
00232
00234 Ogre::SceneNode * m_projectorNode;
00235
00237 Ogre::Frustum * m_frustum;
00238
00240 tf::TransformListener m_tfListener;
00241
00243 Ogre::TextureUnitState * m_texState;
00244
00246 boost::mutex m_lock;
00247
00249 Ogre::SceneManager * m_manager;
00250
00252 Ogre::Vector3 m_cameraPosition;
00253
00255 Ogre::Vector4 m_cameraEquation;
00256
00257 };
00258
00259
00260
00261
00265 class CButProjection : public rviz::Display
00266 {
00267 public:
00268
00272 class CControllPane : public wxPanel
00273 {
00274 public:
00276 typedef boost::signal< void (bool) > tSigCheckboxState;
00277
00279 typedef boost::signal< void ( std::string ) > tSigSave;
00280
00281 public:
00283 CControllPane(wxWindow *parent, const wxString& title, rviz::WindowManagerInterface * wmi );
00284
00286 void OnChckToggle(wxCommandEvent& event);
00287
00289 virtual void OnSave(wxCommandEvent& event);
00290
00292 tSigCheckboxState & getSigChckBox(){ return m_sigCheckBox; }
00293
00295 tSigSave & getSigSave(){ return m_sigSave; }
00296
00297 protected:
00299 rviz::WindowManagerInterface * m_wmi;
00300
00302 wxCheckBox * m_chkb;
00303
00305 wxButton * m_button;
00306
00308 tSigCheckboxState m_sigCheckBox;
00309
00311 tSigSave m_sigSave;
00312 private:
00313 DECLARE_EVENT_TABLE()
00314 };
00315
00316 public:
00318 CButProjection(const std::string & name,rviz::VisualizationManager * manager);
00319
00321 ~CButProjection();
00322
00323
00324 virtual void targetFrameChanged(){}
00325 virtual void fixedFrameChanged(){}
00326 virtual void createProperties();
00327
00329 const std::string& getRgbTopic() { return m_imageRGBInputTopicName; }
00330
00332 void setRgbTopic(const std::string& topic);
00333
00335 const std::string& getDepthTopic() { return m_imageDepthInputTopicName; }
00336
00338 void setDepthTopic(const std::string& topic);
00339
00341 virtual void update (float wall_dt, float ros_dt);
00342
00343 protected:
00344
00345 virtual void onEnable();
00346 virtual void onDisable();
00347
00349 void subscribe();
00350
00352 void unsubscribe();
00353
00355 bool createGeometry(const ros::NodeHandle & nh);
00356
00358 void destroyGeometry();
00359
00361
00362
00364 void onTimerPublish(const ros::TimerEvent&);
00365
00367 void onPublishStateChanged(bool state);
00368
00370 void onSave( std::string filename );
00371
00373 void createMaterials(Ogre::Camera * camera);
00374
00376 void removeMaterials();
00377
00379 void clear();
00380
00382 void cameraInfoCB(const sensor_msgs::CameraInfo::ConstPtr &cam_info);
00383
00385 void connectML( bool bConnect );
00386
00388 void setTestedDistance( float distance );
00389
00391 float getTestedDistance();
00392
00393 protected:
00395 Ogre::SceneNode * m_sceneNode;
00396
00398 std::string m_imageRGBInputTopicName, m_imageDepthInputTopicName;
00399
00401 ros::Timer m_timer;
00402
00404 rviz::ROSTopicStringPropertyWPtr m_rgb_topic_property;
00405
00407 rviz::ROSTopicStringPropertyWPtr m_depth_topic_property;
00408
00410 rviz::FloatPropertyWPtr m_distance_property;
00411
00413 double m_timerPeriod;
00414
00416 CControllPane * m_pane;
00417
00419 CProjectionData * m_projectionData;
00420
00422 std::string m_camera_info_topic;
00423
00424
00425 tf::TransformListener *m_tf_cam_info_Listener;
00426
00428 message_filters::Subscriber< sensor_msgs::CameraInfo > * m_ciSubscriber;
00429
00431 tf::MessageFilter<sensor_msgs::CameraInfo> * m_camInfoTransformFilter;
00432
00434 image_geometry::PinholeCameraModel m_camera_model;
00435
00437 cv::Size m_camera_size;
00438
00440 boost::mutex m_cameraInfoLock;
00441
00443 CMaterialListener * m_ml;
00444
00446 bool m_bMLConnected;
00447
00449 bool m_bCameraInitialized;
00450
00451
00452
00453 };
00454
00455 }
00456
00457 #endif // BUT_PROJECTION_H
00458
00459