ambient_sound_visual.cpp
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     // BEGIN_TUTORIAL
00014     AmbientSoundVisual::AmbientSoundVisual( Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node ): /*{{{*/
00015         width_ (0.1),
00016         scale_ (1.0),
00017         bias_ (10),
00018         grad_ (0.1)
00019     {
00020         scene_manager_ = scene_manager;
00021 
00022         // Ogre::SceneNode s form a tree, with each node storing the
00023         // transform (position and orientation) of itself relative to its
00024         // parent.  Ogre does the math of combining those transforms when it
00025         // is time to render.
00026         //
00027         // Here we create a node to store the pose of the Imu's header frame
00028         // relative to the RViz fixed frame.
00029         frame_node_ = parent_node->createChildSceneNode();
00030 
00031         // We create the arrow object within the frame node so that we can
00032         // set its position and direction relative to its header frame.
00033         ambient_sound_power_line_ = new rviz::BillboardLine( scene_manager_, frame_node_ );
00034         //axes_ = new rviz::Axes( scene_manager_ , frame_node_);
00035     }/*}}}*/
00036 
00037     AmbientSoundVisual::~AmbientSoundVisual()/*{{{*/
00038     {
00039         // Delete the arrow to make it disappear.
00040         delete ambient_sound_power_line_;
00041         //delete axes_;
00042 
00043         // Destroy the frame node since we don't need it anymore.
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         //float powers[] = {/*{{{*/
00053             //25,25,28,30,34,32,29,25,25,25,
00054             //25,25,25,25,25,25,25,25,25,25,
00055             //25,25,25,25,25,25,25,25,25,25,
00056             //25,25,25,25,25,25,25,25,25,25,
00057             //25,25,25,25,25,25,25,25,25,25,
00058             //25,25,25,25,25,25,25,25,25,25,
00059             //25,25,25,25,25,25,25,25,25,25,
00060             //25,25,
00061         //};/*}}}*/
00062 
00063         if ( powers[0] == 0.0 ){ return;}
00064         //float min_elem = *std::min_element(powers.begin(),powers.end());
00065         //axes_->setOrientation(orientation_);
00066         //axes_->setPosition(position_);
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             //std::cout << biased_power << " ";
00075         }
00076         //std::cout << std::endl;
00077 
00078         //Ogre::ColourValue color;
00079         //ambient_sound_power_line_->setColor(color.r, color.g, color.b, color.a);
00080     }/*}}}*/
00081 
00082     // Position and orientation are passed through to the SceneNode.
00083     void AmbientSoundVisual::setFramePosition( const Ogre::Vector3& position )/*{{{*/
00084     {
00085         //ROS_INFO_STREAM("pos: " << position);
00086         //frame_node_->setPosition( position ); //<- unnecessary
00087         position_ = position;
00088     }
00089 
00090     void AmbientSoundVisual::setFrameOrientation( const Ogre::Quaternion& orientation )
00091     {
00092         //ROS_INFO_STREAM("orientation: " << orientation);
00093         //frame_node_->setOrientation( orientation ); //<- unnecessary
00094         orientation_ = orientation;
00095     }
00096     /*}}}*/
00097 
00098     // Color is passed through to the Arrow object.
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     // added by sifi
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     // END_TUTORIAL
00125 
00126 } // end namespace jsk_rviz_plugins
00127 


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Sun Sep 13 2015 22:29:03