00001 #ifndef ARTICULATION_RVIZ_PLUGIN_TRACK_DISPLAY_H 00002 #define ARTICULATION_RVIZ_PLUGIN_TRACK_DISPLAY_H 00003 00004 #include "rviz/display.h" 00005 #include "rviz/common.h" 00006 #include "rviz/properties/forwards.h" 00007 #include "rviz/helpers/color.h" 00008 00009 #include <ros/ros.h> 00010 00011 #include "articulation_msgs/TrackMsg.h" 00012 00013 #include <message_filters/subscriber.h> 00014 #include <tf/message_filter.h> 00015 #include <tf/transform_listener.h> 00016 00017 #include <ogre_tools/arrow.h> 00018 #include <ogre_tools/shape.h> 00019 #include <ogre_tools/billboard_line.h> 00020 #include <OGRE/OgreSceneNode.h> 00021 #include <OGRE/OgreSceneManager.h> 00022 #include <boost/thread/mutex.hpp> 00023 #include <boost/shared_ptr.hpp> 00024 namespace articulation_rviz_plugin 00025 { 00026 00031 class TrackDisplay : public rviz::Display 00032 { 00033 public: 00034 TrackDisplay( const std::string& name, rviz::VisualizationManager* manager ); 00035 virtual void createProperties(); 00036 virtual ~TrackDisplay(); 00037 00038 virtual void onEnable(); 00039 virtual void onDisable(); 00040 00041 std::string track_topic_; 00042 void setTopic( const std::string& topic ); 00043 const std::string& getTopic() { return track_topic_; } 00044 rviz::ROSTopicStringPropertyWPtr topic_property_; 00045 00046 rviz::Color color_; 00047 void setColor( const rviz::Color& color ); 00048 const rviz::Color& getColor() { return color_; } 00049 rviz::ColorPropertyWPtr color_property_; 00050 00051 float alpha_; 00052 void setAlpha(float a); 00053 float getAlpha() { return alpha_; } 00054 rviz::FloatPropertyWPtr alpha_property_; 00055 00056 float lineWidth_; 00057 void setLineWidth(float a); 00058 float getLineWidth() { return lineWidth_; } 00059 rviz::FloatPropertyWPtr lineWidth_property_; 00060 00061 enum ColorStyle 00062 { 00063 cs_fixed, 00064 cs_channel, 00065 cs_hue, 00066 cs_brightness, 00067 ColorStyleCount, 00068 }; 00069 00070 int trackColor_; 00071 void setTrackColor(int cs); 00072 int getTrackColor() { return trackColor_; } 00073 rviz::EnumPropertyWPtr trackColor_property_; 00074 00075 int poseColor_; 00076 void setPoseColor(int cs); 00077 int getPoseColor() { return poseColor_; } 00078 rviz::EnumPropertyWPtr poseColor_property_; 00079 00080 enum DisplayStyle 00081 { 00082 ds_line, 00083 ds_cross_line, 00084 ds_axes, 00085 ds_rectangle, 00086 DisplayStyleCount 00087 }; 00088 00089 int displayStyle_; 00090 void setDisplayStyle(int ds); 00091 int getDisplayStyle() { return displayStyle_; } 00092 rviz::EnumPropertyWPtr displayStyle_property_; 00093 00094 virtual void targetFrameChanged(); 00095 virtual void fixedFrameChanged(); 00096 virtual void reset(); 00097 virtual void update(float wall_dt, float ros_dt); 00098 00099 protected: 00100 std::map<int, std::vector<ogre_tools::BillboardLine*> > lines; 00101 std::vector<ogre_tools::BillboardLine*> recycleLines; 00102 ogre_tools::BillboardLine* newBillboardLine(); 00103 00104 void subscribe(); 00105 void unsubscribe(); 00106 00107 void clearVector(std::vector<ogre_tools::BillboardLine*>& vec); 00108 void clearMap(); 00109 void clearDisplay(); 00110 00111 void incomingTrack(const articulation_msgs::TrackMsg::ConstPtr& msg); 00112 00113 message_filters::Subscriber<articulation_msgs::TrackMsg> sub_; 00114 tf::MessageFilter<articulation_msgs::TrackMsg> tf_filter_; 00115 00116 articulation_msgs::TrackMsg::ConstPtr incoming_track_message_; 00117 00118 typedef std::vector<articulation_msgs::TrackMsg::ConstPtr> V_TrackMsg; 00119 V_TrackMsg message_queue_; 00120 boost::mutex queue_mutex_; 00121 00122 Ogre::SceneNode* scene_node_; 00123 00124 bool transform(const articulation_msgs::TrackMsg::ConstPtr& message, btTransform &transform); 00125 bool transform(const btTransform &pose, const btVector3 &scaleIn,Ogre::Vector3& pos, Ogre::Quaternion& orient, Ogre::Vector3& scaleOut); 00126 00127 void createRectangle(Ogre::Vector3 pos,Ogre::Quaternion orient,Ogre::Vector3 scale,double w,double h,btVector3 color, 00128 std::vector<ogre_tools::BillboardLine*> &vec); 00129 00130 void createAxes(Ogre::Vector3 pos,Ogre::Quaternion orient,Ogre::Vector3 scale,btVector3 color, 00131 std::vector<ogre_tools::BillboardLine*> &vec); 00132 00133 void createLine(Ogre::Vector3 pos,Ogre::Vector3 old_pos,Ogre::Vector3 scale,btVector3 color, 00134 std::vector<ogre_tools::BillboardLine*> &vec,bool add_cross); 00135 00136 btVector3 modifyColor( btVector3 color, int colorStyle, float f ); 00137 }; 00138 00139 } 00140 00141 #endif 00142 00143