00001 #ifndef __AMBIENT_SOUND_DISPLAY__ 00002 #define __AMBIENT_SOUND_DISPLAY__ 00003 00004 #ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829 00005 #include <message_filters/subscriber.h> 00006 #include <tf/message_filter.h> 00007 #include <jsk_hark_msgs/HarkPower.h> 00008 #include <ambient_sound_visual.h> 00009 #include <boost/circular_buffer.hpp> 00010 #include <rviz/message_filter_display.h> 00011 #endif 00012 00013 namespace Ogre 00014 { 00015 class SceneNode; 00016 } 00017 00018 namespace rviz 00019 { 00020 class ColorProperty; 00021 class FloatProperty; 00022 class IntProperty; 00023 class ROSTopicStringProperty; 00024 } 00025 00026 // All the source in this plugin is in its own namespace. This is not 00027 // required but is good practice. 00028 namespace jsk_rviz_plugin 00029 { 00030 00031 class AmbientSoundVisual; 00032 00033 //class AmbientSoundDisplay: public rviz::Display 00034 class AmbientSoundDisplay: public rviz::MessageFilterDisplay<jsk_hark_msgs::HarkPower> 00035 { 00036 Q_OBJECT 00037 public: 00038 // Constructor. pluginlib::ClassLoader creates instances by calling 00039 // the default constructor, so make sure you have one. 00040 AmbientSoundDisplay(); 00041 virtual ~AmbientSoundDisplay(); 00042 00043 // Overrides of public virtual functions from the Display class. 00044 virtual void onInitialize(); 00045 //virtual void fixedFrameChanged(); 00046 virtual void reset(); 00047 //virtual void createProperties(); 00048 00049 // Setter and getter functions for user-editable properties. 00050 /* 00051 void setTopic(const std::string& topic); 00052 const std::string& getTopic() { return topic_; } 00053 00054 void setColor( const rviz::Color& color ); 00055 const rviz::Color& getColor() { return color_; } 00056 00057 void setAlpha( float alpha ); 00058 float getAlpha() { return alpha_; } 00059 00060 void setHistoryLength( int history_length ); 00061 int getHistoryLength() const { return history_length_; } 00062 00063 void setWidth( float width ); 00064 float getWidth() const { return width_; } 00065 00066 void setScale( float scale ); 00067 float getScale() const { return scale_; } 00068 00069 void setBias( float bias ); 00070 float getBias() const { return bias_; } 00071 00072 void setGrad( float grad ); 00073 float getGrad() const { return grad_; } 00074 */ 00075 00076 // Overrides of protected virtual functions from Display. As much 00077 // as possible, when Displays are not enabled, they should not be 00078 // subscribed to incoming data and should not show anything in the 00079 // 3D view. These functions are where these connections are made 00080 // and broken. 00081 /* 00082 protected: 00083 virtual void onEnable(); 00084 virtual void onDisable(); 00085 */ 00086 00087 private Q_SLOTS: 00088 void updateColorAndAlpha(); 00089 void updateAppearance(); 00090 void updateHistoryLength(); 00091 bool validateFloats( const jsk_hark_msgs::HarkPower& ); 00092 00093 // Function to handle an incoming ROS message. 00094 private: 00095 //void incomingMessage( const jsk_hark_msgs::HarkPower::ConstPtr& msg ); 00096 void processMessage( const jsk_hark_msgs::HarkPower::ConstPtr& msg ); 00097 00098 // Internal helpers which do the work of subscribing and 00099 // unsubscribing from the ROS topic. 00100 // void subscribe(); 00101 // void unsubscribe(); 00102 00103 // A helper to clear this display back to the initial state. 00104 //void clear(); 00105 00106 // Helper function to apply color and alpha to all visuals. 00107 00108 // Storage for the list of visuals. This display supports an 00109 // adjustable history length, so we need one visual per history 00110 // item. 00111 //boost::circular_buffer<AmbientSoundVisual*> visuals_; 00112 boost::circular_buffer<boost::shared_ptr<AmbientSoundVisual> > visuals_; 00113 00114 // A node in the Ogre scene tree to be the parent of all our visuals. 00115 //Ogre::SceneNode* scene_node_; 00116 00117 // Data input: Subscriber and tf message filter. 00118 //message_filters::Subscriber<jsk_hark_msgs::HarkPower> sub_; 00119 //tf::MessageFilter<jsk_hark_msgs::HarkPower>* tf_filter_; 00120 //int messages_received_; 00121 00122 // User-editable property variables. 00123 /* 00124 rviz::Color color_; 00125 std::string topic_; 00126 float alpha_; 00127 int history_length_; 00128 float width_,scale_,bias_,grad_; 00129 */ 00130 00131 // Property objects for user-editable properties. 00132 rviz::ColorProperty *color_property_; 00133 rviz::ROSTopicStringProperty *topic_property_; 00134 rviz::FloatProperty *alpha_property_; 00135 rviz::IntProperty *history_length_property_; 00136 rviz::FloatProperty *width_property_; 00137 rviz::FloatProperty *scale_property_; 00138 rviz::FloatProperty *bias_property_; 00139 rviz::FloatProperty *grad_property_; 00140 }; 00141 // END_TUTORIAL 00142 00143 } // end namespace jsk_rviz_plugin 00144 00145 #endif // __AMBIENT_SOUND_DISPLAY__ 00146 // %EndTag(FULL_SOURCE)%