00001 // -*- mode: c++; -*- 00002 /********************************************************************* 00003 * Software License Agreement (BSD License) 00004 * 00005 * Copyright (c) 2014, JSK Lab 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following 00016 * disclaimer in the documentation and/o2r other materials provided 00017 * with the distribution. 00018 * * Neither the name of the Willow Garage nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 *********************************************************************/ 00035 00036 #ifndef JSK_RVIZ_PLUGINS_OVERLAY_CAMERA_DISPLAY_H_ 00037 #define JSK_RVIZ_PLUGINS_OVERLAY_CAMERA_DISPLAY_H_ 00038 00039 #include <rviz/default_plugin/camera_display.h> 00040 00041 #include <QObject> 00042 00043 #include <OgreMaterial.h> 00044 #include <OgreRenderTargetListener.h> 00045 #include <OgreSharedPtr.h> 00046 00047 #ifndef Q_MOC_RUN 00048 # include <sensor_msgs/CameraInfo.h> 00049 00050 # include <message_filters/subscriber.h> 00051 # include <tf/message_filter.h> 00052 00053 # include "rviz/image/image_display_base.h" 00054 # include "rviz/image/ros_image_texture.h" 00055 # include "rviz/render_panel.h" 00056 #endif 00057 00058 #include "overlay_utils.h" 00059 00060 namespace Ogre 00061 { 00062 class SceneNode; 00063 class ManualObject; 00064 class Rectangle2D; 00065 class Camera; 00066 } 00067 00068 namespace rviz 00069 { 00070 00071 class EnumProperty; 00072 class FloatProperty; 00073 class IntProperty; 00074 class RenderPanel; 00075 class RosTopicProperty; 00076 class DisplayGroupVisibilityProperty; 00077 } 00082 namespace jsk_rviz_plugin 00083 { 00084 using namespace rviz; 00085 class OverlayCameraDisplay: public rviz::ImageDisplayBase, public Ogre::RenderTargetListener 00086 { 00087 Q_OBJECT 00088 public: 00089 OverlayCameraDisplay(); 00090 virtual ~OverlayCameraDisplay(); 00091 00092 // Overrides from Display 00093 virtual void onInitialize(); 00094 virtual void fixedFrameChanged(); 00095 virtual void update( float wall_dt, float ros_dt ); 00096 virtual void reset(); 00097 00098 // Overrides from Ogre::RenderTargetListener 00099 virtual void preRenderTargetUpdate( const Ogre::RenderTargetEvent& evt ); 00100 virtual void postRenderTargetUpdate( const Ogre::RenderTargetEvent& evt ); 00101 00102 static const QString BACKGROUND; 00103 static const QString OVERLAY; 00104 static const QString BOTH; 00105 00106 protected: 00107 // overrides from Display 00108 virtual void onEnable(); 00109 virtual void onDisable(); 00110 00111 ROSImageTexture texture_; 00112 RenderPanel* render_panel_; 00113 00114 private Q_SLOTS: 00115 void forceRender(); 00116 void updateAlpha(); 00117 00118 virtual void updateQueueSize(); 00119 00120 private: 00121 void subscribe(); 00122 void unsubscribe(); 00123 00124 virtual void processMessage(const sensor_msgs::Image::ConstPtr& msg); 00125 void caminfoCallback( const sensor_msgs::CameraInfo::ConstPtr& msg ); 00126 00127 bool updateCamera(); 00128 00129 void clear(); 00130 void updateStatus(); 00131 00132 Ogre::SceneNode* bg_scene_node_; 00133 Ogre::SceneNode* fg_scene_node_; 00134 00135 Ogre::Rectangle2D* bg_screen_rect_; 00136 Ogre::MaterialPtr bg_material_; 00137 00138 Ogre::Rectangle2D* fg_screen_rect_; 00139 Ogre::MaterialPtr fg_material_; 00140 00141 message_filters::Subscriber<sensor_msgs::CameraInfo> caminfo_sub_; 00142 tf::MessageFilter<sensor_msgs::CameraInfo>* caminfo_tf_filter_; 00143 00144 FloatProperty* alpha_property_; 00145 EnumProperty* image_position_property_; 00146 FloatProperty* zoom_property_; 00147 DisplayGroupVisibilityProperty* visibility_property_; 00148 00149 sensor_msgs::CameraInfo::ConstPtr current_caminfo_; 00150 boost::mutex caminfo_mutex_; 00151 00152 bool new_caminfo_; 00153 00154 bool caminfo_ok_; 00155 00156 bool force_render_; 00157 00158 uint32_t vis_bit_; 00159 protected: 00160 OverlayObject::Ptr overlay_; 00161 void redraw(); 00162 rviz::IntProperty* width_property_; 00163 rviz::IntProperty* height_property_; 00164 rviz::IntProperty* left_property_; 00165 rviz::IntProperty* top_property_; 00166 rviz::FloatProperty* texture_alpha_property_; 00167 int width_, height_; 00168 int left_, top_; 00169 float texture_alpha_; 00170 bool initializedp_; 00171 private Q_SLOTS: 00172 void updateWidth(); 00173 void updateHeight(); 00174 void updateLeft(); 00175 void updateTop(); 00176 void updateTextureAlpha(); 00177 }; 00178 00179 } 00180 00181 #endif