00001 /* 00002 * Copyright (c) 2008, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 #ifndef RVIZ_MARKER_DISPLAY_H 00031 #define RVIZ_MARKER_DISPLAY_H 00032 00033 #include <map> 00034 #include <set> 00035 00036 #include <boost/thread/mutex.hpp> 00037 #include <boost/shared_ptr.hpp> 00038 00039 #ifndef Q_MOC_RUN 00040 #include <tf/message_filter.h> 00041 #include <message_filters/subscriber.h> 00042 #endif 00043 00044 #include <visualization_msgs/Marker.h> 00045 #include <visualization_msgs/MarkerArray.h> 00046 00047 #include "rviz/display.h" 00048 #include "rviz/properties/bool_property.h" 00049 #include "rviz/selection/forwards.h" 00050 00051 namespace rviz 00052 { 00053 class IntProperty; 00054 class MarkerBase; 00055 class MarkerNamespace; 00056 class MarkerSelectionHandler; 00057 class Object; 00058 class RosTopicProperty; 00059 00060 typedef boost::shared_ptr<MarkerSelectionHandler> MarkerSelectionHandlerPtr; 00061 typedef boost::shared_ptr<MarkerBase> MarkerBasePtr; 00062 typedef std::pair<std::string, int32_t> MarkerID; 00063 00070 class MarkerDisplay: public Display 00071 { 00072 Q_OBJECT 00073 public: 00074 MarkerDisplay(); 00075 virtual ~MarkerDisplay(); 00076 00077 virtual void onInitialize(); 00078 00079 virtual void update(float wall_dt, float ros_dt); 00080 00081 virtual void fixedFrameChanged(); 00082 virtual void reset(); 00083 00084 void deleteMarker(MarkerID id); 00085 00086 void setMarkerStatus(MarkerID id, StatusLevel level, const std::string& text); 00087 void deleteMarkerStatus(MarkerID id); 00088 00089 protected: 00090 virtual void onEnable(); 00091 virtual void onDisable(); 00092 00095 virtual void subscribe(); 00096 00099 virtual void unsubscribe(); 00100 00102 void incomingMarkerArray( const visualization_msgs::MarkerArray::ConstPtr& array ); 00103 00104 ros::Subscriber array_sub_; 00105 00106 RosTopicProperty* marker_topic_property_; 00107 IntProperty* queue_size_property_; 00108 00109 private Q_SLOTS: 00110 void updateQueueSize(); 00111 void updateTopic(); 00112 00113 private: 00115 void deleteMarkersInNamespace( const std::string& ns ); 00116 00120 void clearMarkers(); 00121 00126 void processMessage( const visualization_msgs::Marker::ConstPtr& message ); 00131 void processAdd( const visualization_msgs::Marker::ConstPtr& message ); 00136 void processDelete( const visualization_msgs::Marker::ConstPtr& message ); 00137 00141 void incomingMarker(const visualization_msgs::Marker::ConstPtr& marker); 00142 00143 void failedMarker(const visualization_msgs::Marker::ConstPtr& marker, tf::FilterFailureReason reason); 00144 00145 typedef std::map<MarkerID, MarkerBasePtr> M_IDToMarker; 00146 typedef std::set<MarkerBasePtr> S_MarkerBase; 00147 M_IDToMarker markers_; 00148 S_MarkerBase markers_with_expiration_; 00149 S_MarkerBase frame_locked_markers_; 00150 typedef std::vector<visualization_msgs::Marker::ConstPtr> V_MarkerMessage; 00151 V_MarkerMessage message_queue_; 00152 00153 boost::mutex queue_mutex_; 00154 00155 message_filters::Subscriber<visualization_msgs::Marker> sub_; 00156 tf::MessageFilter<visualization_msgs::Marker>* tf_filter_; 00157 00158 typedef QHash<QString, MarkerNamespace*> M_Namespace; 00159 M_Namespace namespaces_; 00160 00161 Property* namespaces_category_; 00162 00163 friend class MarkerNamespace; 00164 }; 00165 00168 class MarkerNamespace: public BoolProperty 00169 { 00170 Q_OBJECT 00171 public: 00172 MarkerNamespace( const QString& name, Property* parent_property, MarkerDisplay* owner ); 00173 bool isEnabled() const { return getBool(); } 00174 00175 public Q_SLOTS: 00176 void onEnableChanged(); 00177 00178 private: 00179 MarkerDisplay* owner_; 00180 }; 00181 00182 } // namespace rviz 00183 00184 #endif /* RVIZ_MARKER_DISPLAY_H */