ambient_sound_visual.cpp
Go to the documentation of this file.
1 #include <OGRE/OgreVector3.h>
2 #include <OGRE/OgreSceneNode.h>
3 #include <OGRE/OgreSceneManager.h>
4 
7 
8 #include "ambient_sound_visual.h"
9 
10 namespace jsk_rviz_plugins
11 {
12 
13  // BEGIN_TUTORIAL
14  AmbientSoundVisual::AmbientSoundVisual( Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node ): /*{{{*/
15  width_ (0.1),
16  scale_ (1.0),
17  bias_ (28),
18  grad_ (0.4)
19  {
20  scene_manager_ = scene_manager;
21 
22  // Ogre::SceneNode s form a tree, with each node storing the
23  // transform (position and orientation) of itself relative to its
24  // parent. Ogre does the math of combining those transforms when it
25  // is time to render.
26  //
27  // Here we create a node to store the pose of the Imu's header frame
28  // relative to the RViz fixed frame.
29  frame_node_ = parent_node->createChildSceneNode();
30 
31  // We create the arrow object within the frame node so that we can
32  // set its position and direction relative to its header frame.
34  //axes_ = new rviz::Axes( scene_manager_ , frame_node_);
35  }/*}}}*/
36 
38  {
39  // Delete the arrow to make it disappear.
41  //delete axes_;
42 
43  // Destroy the frame node since we don't need it anymore.
44  scene_manager_->destroySceneNode( frame_node_ );
45  }/*}}}*/
46 
47  void AmbientSoundVisual::setMessage( const jsk_hark_msgs::HarkPower::ConstPtr& msg )/*{{{*/
48  {
49  int directions = msg->directions;
50  std::vector<float> powers = msg->powers;
51 
52  //float powers[] = {/*{{{*/
53  //25,25,28,30,34,32,29,25,25,25,
54  //25,25,25,25,25,25,25,25,25,25,
55  //25,25,25,25,25,25,25,25,25,25,
56  //25,25,25,25,25,25,25,25,25,25,
57  //25,25,25,25,25,25,25,25,25,25,
58  //25,25,25,25,25,25,25,25,25,25,
59  //25,25,25,25,25,25,25,25,25,25,
60  //25,25,
61  //};/*}}}*/
62 
63  if ( powers[0] == 0.0 ){ return;}
64  //float min_elem = *std::min_element(powers.begin(),powers.end());
65  //axes_->setOrientation(orientation_);
66  //axes_->setPosition(position_);
69  for (int i = 0; i <= directions ; i++) {
70  float biased_power = (powers[(i%directions)] - bias_) * grad_;
71  if (biased_power <= 0.0) { biased_power = 0.001; }
72  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);
74  //std::cout << biased_power << " ";
75  }
76  //std::cout << std::endl;
77 
78  //Ogre::ColourValue color;
79  //ambient_sound_power_line_->setColor(color.r, color.g, color.b, color.a);
80  }/*}}}*/
81 
82  // Position and orientation are passed through to the SceneNode.
83  void AmbientSoundVisual::setFramePosition( const Ogre::Vector3& position )/*{{{*/
84  {
85  //ROS_INFO_STREAM("pos: " << position);
86  //frame_node_->setPosition( position ); //<- unnecessary
87  position_ = position;
88  }
89 
90  void AmbientSoundVisual::setFrameOrientation( const Ogre::Quaternion& orientation )
91  {
92  //ROS_INFO_STREAM("orientation: " << orientation);
93  //frame_node_->setOrientation( orientation ); //<- unnecessary
94  orientation_ = orientation;
95  }
96  /*}}}*/
97 
98  // Color is passed through to the Arrow object.
99  /*{{{*/
100  void AmbientSoundVisual::setColor( float r, float g, float b, float a )
101  {
102  ambient_sound_power_line_->setColor( r, g, b, a );
103  }
104 
105  // added by sifi
107  {
108  width_ = w;
109  }
111  {
112  scale_ = s;
113  }
115  {
116  bias_ = b;
117  }
119  {
120  grad_ = g;
121  }
122  /*}}}*/
123 
124  // END_TUTORIAL
125 
126 } // end namespace jsk_rviz_plugins
127 
void addPoint(const Ogre::Vector3 &point)
void setFramePosition(const Ogre::Vector3 &position)
void setFrameOrientation(const Ogre::Quaternion &orientation)
virtual void setColor(float r, float g, float b, float a)
void setColor(float r, float g, float b, float a)
rviz::BillboardLine * ambient_sound_power_line_
void setMessage(const jsk_hark_msgs::HarkPower::ConstPtr &msg)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
AmbientSoundVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
void setLineWidth(float width)


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Sat Mar 20 2021 03:03:18