Go to the documentation of this file.00001 #include <OGRE/OgreVector3.h>
00002 #include <OGRE/OgreSceneNode.h>
00003 #include <OGRE/OgreSceneManager.h>
00004
00005 #include <rviz/ogre_helpers/billboard_line.h>
00006 #include <rviz/ogre_helpers/axes.h>
00007
00008 #include "ambient_sound_visual.h"
00009
00010 namespace jsk_rviz_plugin
00011 {
00012
00013
00014 AmbientSoundVisual::AmbientSoundVisual( Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node ):
00015 width_ (1.0),
00016 scale_ (2),
00017 bias_ (16)
00018 {
00019 scene_manager_ = scene_manager;
00020
00021
00022
00023
00024
00025
00026
00027
00028 frame_node_ = parent_node->createChildSceneNode();
00029
00030
00031
00032 ambient_sound_power_line_ = new rviz::BillboardLine( scene_manager_, frame_node_ );
00033
00034 }
00035
00036 AmbientSoundVisual::~AmbientSoundVisual()
00037 {
00038
00039 delete ambient_sound_power_line_;
00040
00041
00042
00043 scene_manager_->destroySceneNode( frame_node_ );
00044 }
00045
00046 void AmbientSoundVisual::setMessage( const hark_msgs::HarkPower::ConstPtr& msg )
00047 {
00048 int directions = msg->directions;
00049 std::vector<float> powers = msg->powers;
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 if ( powers[0] == 0.0 ){ return;}
00063
00064
00065
00066 ambient_sound_power_line_->clear();
00067 ambient_sound_power_line_->setLineWidth(width_);
00068 for (int i = 0; i <= directions ; i++) {
00069 float biased_power = (powers[(i%directions)] - bias_) * grad_;
00070 if (biased_power < 0) { biased_power=0; }
00071 Ogre::Vector3 point = Ogre::Vector3((biased_power*scale_)*cos(i*(2*M_PI/directions)- M_PI), (biased_power*scale_)*sin(i*(2*M_PI/directions) - M_PI), 0);
00072 ambient_sound_power_line_->addPoint(orientation_ * point + position_);
00073
00074 }
00075
00076
00077
00078
00079 }
00080
00081
00082 void AmbientSoundVisual::setFramePosition( const Ogre::Vector3& position )
00083 {
00084
00085
00086 position_ = position;
00087 }
00088
00089 void AmbientSoundVisual::setFrameOrientation( const Ogre::Quaternion& orientation )
00090 {
00091
00092
00093 orientation_ = orientation;
00094 }
00095
00096
00097
00098
00099 void AmbientSoundVisual::setColor( float r, float g, float b, float a )
00100 {
00101 ambient_sound_power_line_->setColor( r, g, b, a );
00102 }
00103
00104
00105 void AmbientSoundVisual::setWidth( float w )
00106 {
00107 width_ = w;
00108 }
00109 void AmbientSoundVisual::setScale( float s )
00110 {
00111 scale_ = s;
00112 }
00113 void AmbientSoundVisual::setBias( float b )
00114 {
00115 bias_ = b;
00116 }
00117 void AmbientSoundVisual::setGrad( float g )
00118 {
00119 grad_ = g;
00120 }
00121
00122
00123
00124
00125 }
00126