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


jsk_rviz_plugins
Author(s): Kei Okada
autogenerated on Sat Mar 23 2013 20:30:29