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 JSK Lab 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 #ifndef JSK_RVIZ_PLUGIN_OVERLAY_IMAGE_DISPLAY_H_ 00036 #define JSK_RVIZ_PLUGIN_OVERLAY_IMAGE_DISPLAY_H_ 00037 00038 #ifndef Q_MOC_RUN 00039 #include <rviz/display.h> 00040 #include <OGRE/OgreTexture.h> 00041 #include <OGRE/OgreColourValue.h> 00042 #include <OGRE/OgreMaterial.h> 00043 00044 #include <QPainter> 00045 00046 #include <rviz/properties/ros_topic_property.h> 00047 #include <rviz/properties/int_property.h> 00048 #include <rviz/properties/float_property.h> 00049 #include <rviz/properties/bool_property.h> 00050 #include <rviz/properties/editable_enum_property.h> 00051 00052 #include <image_transport/image_transport.h> 00053 #include <sensor_msgs/Image.h> 00054 00055 #include "overlay_utils.h" 00056 #include "image_transport_hints_property.h" 00057 #endif 00058 00059 namespace jsk_rviz_plugins 00060 { 00061 class OverlayImageDisplay : public rviz::Display 00062 { 00063 Q_OBJECT 00064 public: 00065 OverlayImageDisplay(); 00066 virtual ~OverlayImageDisplay(); 00067 00068 // methods for OverlayPickerTool 00069 virtual bool isInRegion(int x, int y); 00070 virtual void movePosition(int x, int y); 00071 virtual void setPosition(int x, int y); 00072 virtual int getX() { return left_; }; 00073 virtual int getY() { return top_; }; 00074 00075 protected: 00076 boost::mutex mutex_; 00077 OverlayObject::Ptr overlay_; 00078 rviz::RosTopicProperty* update_topic_property_; 00079 ImageTransportHintsProperty* transport_hint_property_; 00080 rviz::BoolProperty* keep_aspect_ratio_property_; 00081 rviz::IntProperty* width_property_; 00082 rviz::IntProperty* height_property_; 00083 rviz::IntProperty* left_property_; 00084 rviz::IntProperty* top_property_; 00085 rviz::FloatProperty* alpha_property_; 00086 int width_, height_, left_, top_; 00087 double alpha_; 00088 std::shared_ptr<image_transport::ImageTransport> it_; 00089 image_transport::Subscriber sub_; 00090 sensor_msgs::Image::ConstPtr msg_; 00091 bool is_msg_available_; 00092 bool require_update_; 00093 bool keep_aspect_ratio_; 00094 00095 virtual void redraw(); 00096 virtual void onInitialize(); 00097 virtual void onEnable(); 00098 virtual void onDisable(); 00099 virtual void update(float wall_dt, float ros_dt); 00100 virtual void subscribe(); 00101 virtual void unsubscribe(); 00102 virtual void setImageSize(); 00103 virtual void processMessage(const sensor_msgs::Image::ConstPtr& msg); 00104 protected Q_SLOTS: 00105 void updateTopic(); 00106 void updateWidth(); 00107 void updateHeight(); 00108 void updateLeft(); 00109 void updateTop(); 00110 void updateAlpha(); 00111 void updateKeepAspectRatio(); 00112 }; 00113 00114 } 00115 00116 #endif 00117