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_plugins
00011 {
00012 
00013     
00014     AmbientSoundVisual::AmbientSoundVisual( Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node ): 
00015         width_ (0.1),
00016         scale_ (1.0),
00017         bias_ (28),
00018         grad_ (0.4)
00019     {
00020         scene_manager_ = scene_manager;
00021 
00022         
00023         
00024         
00025         
00026         
00027         
00028         
00029         frame_node_ = parent_node->createChildSceneNode();
00030 
00031         
00032         
00033         ambient_sound_power_line_ = new rviz::BillboardLine( scene_manager_, frame_node_ );
00034         
00035     }
00036 
00037     AmbientSoundVisual::~AmbientSoundVisual()
00038     {
00039         
00040         delete ambient_sound_power_line_;
00041         
00042 
00043         
00044         scene_manager_->destroySceneNode( frame_node_ );
00045     }
00046 
00047     void AmbientSoundVisual::setMessage( const jsk_hark_msgs::HarkPower::ConstPtr& msg )
00048     {
00049         int directions = msg->directions;
00050         std::vector<float> powers = msg->powers;
00051 
00052         
00053             
00054             
00055             
00056             
00057             
00058             
00059             
00060             
00061         
00062 
00063         if ( powers[0] == 0.0 ){ return;}
00064         
00065         
00066         
00067         ambient_sound_power_line_->clear();
00068         ambient_sound_power_line_->setLineWidth(width_);
00069         for (int i = 0; i <= directions ; i++) {
00070             float biased_power = (powers[(i%directions)] - bias_) * grad_;
00071             if (biased_power <= 0.0) { biased_power = 0.001; }
00072             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);
00073             ambient_sound_power_line_->addPoint(orientation_ * point + position_);
00074             
00075         }
00076         
00077 
00078         
00079         
00080     }
00081 
00082     
00083     void AmbientSoundVisual::setFramePosition( const Ogre::Vector3& position )
00084     {
00085         
00086         
00087         position_ = position;
00088     }
00089 
00090     void AmbientSoundVisual::setFrameOrientation( const Ogre::Quaternion& orientation )
00091     {
00092         
00093         
00094         orientation_ = orientation;
00095     }
00096     
00097 
00098     
00099     
00100     void AmbientSoundVisual::setColor( float r, float g, float b, float a )
00101     {
00102         ambient_sound_power_line_->setColor( r, g, b, a );
00103     }
00104 
00105     
00106     void AmbientSoundVisual::setWidth( float w )
00107     {
00108         width_ = w;
00109     }
00110     void AmbientSoundVisual::setScale( float s )
00111     {
00112         scale_ = s;
00113     }
00114     void AmbientSoundVisual::setBias( float b )
00115     {
00116         bias_ = b;
00117     }
00118     void AmbientSoundVisual::setGrad( float g )
00119     {
00120         grad_ = g;
00121     }
00122     
00123 
00124     
00125 
00126 } 
00127