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 <sstream>
00031
00032 #include <OGRE/OgreSceneNode.h>
00033 #include <OGRE/OgreSceneManager.h>
00034 #include <OGRE/OgreMaterialManager.h>
00035 #include <OGRE/OgreManualObject.h>
00036
00037 #include <tf/transform_listener.h>
00038
00039 #include <rviz/visualization_manager.h>
00040 #include <rviz/properties/property.h>
00041
00042 #include <rviz/frame_manager.h>
00043
00044 #include <rviz/image/ros_image_texture.h>
00045 #include "backdrop_display.h"
00046
00047 namespace rviz_backdrop
00048 {
00049
00050
00051
00052
00053
00054
00055 BackdropDisplay::BackdropDisplay()
00056 : Display()
00057 , scale_( 0.01 )
00058 {
00059
00060 }
00061
00062
00063
00064
00065
00066 void BackdropDisplay::onInitialize()
00067 {
00068
00069 scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
00070
00071
00072 static int count = 0;
00073 std::stringstream ss;
00074 ss << "BackdropDisplay" << count++ << "Material";
00075
00076
00077 image_material_ =
00078 Ogre::MaterialManager::getSingleton().create( ss.str(),
00079 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
00080 image_material_->getTechnique( 0 )->setLightingEnabled( false );
00081 Ogre::TextureUnitState* tu = image_material_->getTechnique( 0 )->getPass( 0 )->createTextureUnitState();
00082 tu->setTextureName( texture_.getTexture()->getName() );
00083 tu->setTextureFiltering( Ogre::TFO_NONE );
00084 tu->setAlphaOperation( Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, 0.0 );
00085 image_material_->setCullingMode( Ogre::CULL_NONE );
00086 image_material_->setSceneBlending( Ogre::SBT_REPLACE );
00087
00088
00089 manual_object_ = scene_manager_->createManualObject();
00090 scene_node_->attachObject( manual_object_ );
00091 manual_object_->estimateVertexCount( 10 );
00092 manual_object_->begin( image_material_->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST );
00093
00094 manual_object_->position( -1, -1, 0 );
00095 manual_object_->textureCoord( 0, 1 );
00096
00097 manual_object_->position( -1, 1, 0 );
00098 manual_object_->textureCoord( .5, 1 );
00099
00100 manual_object_->position( 1, 1, 0 );
00101 manual_object_->textureCoord( 1, 1 );
00102
00103 manual_object_->position( 1, 1, 2 );
00104 manual_object_->textureCoord( 1, 0 );
00105
00106 manual_object_->position( -1, 1, 2 );
00107 manual_object_->textureCoord( .5, 0 );
00108
00109 manual_object_->position( -1, -1, 2 );
00110 manual_object_->textureCoord( 0, 0 );
00111
00112 manual_object_->quad( 0, 1, 4, 5 );
00113 manual_object_->quad( 1, 2, 3, 4 );
00114
00115 manual_object_->position( -1, -1, 0 );
00116 manual_object_->textureCoord( 0, .999 );
00117
00118 manual_object_->position( 1, -1, 0 );
00119 manual_object_->textureCoord( 0, .999 );
00120
00121 manual_object_->position( 1, 1, 0 );
00122 manual_object_->textureCoord( 0, .999 );
00123
00124 manual_object_->position( -1, 1, 0 );
00125 manual_object_->textureCoord( 0, .999 );
00126
00127 manual_object_->quad( 6, 7, 8, 9 );
00128
00129 manual_object_->end();
00130 }
00131
00132 BackdropDisplay::~BackdropDisplay()
00133 {
00134 unsubscribe();
00135
00136 scene_manager_->destroySceneNode( scene_node_ );
00137 scene_manager_->destroyManualObject( manual_object_ );
00138 image_material_->unload();
00139 }
00140
00141 void BackdropDisplay::setTopic( const std::string& topic )
00142 {
00143 unsubscribe();
00144 topic_ = topic;
00145 subscribe();
00146
00147
00148
00149
00150
00151
00152 }
00153
00154
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 void BackdropDisplay::onEnable()
00187 {
00188 subscribe();
00189 scene_node_->setVisible( true );
00190 }
00191
00192 void BackdropDisplay::onDisable()
00193 {
00194 unsubscribe();
00195 scene_node_->setVisible( false );
00196 }
00197
00198 void BackdropDisplay::update( float dt, float ros_dt )
00199 {
00200 if (!texture_.getImage())
00201 {
00202
00203 }
00204 else
00205 {
00206 std::stringstream ss;
00207
00208
00209 }
00210
00211
00212
00213 sensor_msgs::Image::ConstPtr current_image = texture_.getImage();
00214 if( current_image )
00215 {
00216 scene_node_->setScale( scale_, scale_, scale_ * 2.0 * current_image->height / current_image->width );
00217
00218 std::string image_frame = current_image->header.frame_id;
00219 if( image_frame == "" )
00220 {
00221
00222
00223 }
00224
00225 Ogre::Vector3 position;
00226 Ogre::Quaternion orientation;
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 }
00239 }
00240
00241 void BackdropDisplay::setScale( float scale )
00242 {
00243 scale_ = scale;
00244
00245 }
00246
00247
00248
00249
00250
00251 void BackdropDisplay::createProperties()
00252 {
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 }
00278
00279 }
00280
00281
00282
00283 #include <pluginlib/class_list_macros.h>
00284 PLUGINLIB_DECLARE_CLASS( rviz_backdrop, Backdrop, rviz_backdrop::BackdropDisplay, rviz::Display )
00285