ObjectDetectionTrafficConeVisual.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2017 by Florian Beck <florian.beck@tuwien.ac.at> *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above copyright *
10  * notice, this list of conditions and the following disclaimer. *
11  * 2. Redistributions in binary form must reproduce the above copyright *
12  * notice, this list of conditions and the following disclaimer in *
13  * the documentation and/or other materials provided with the *
14  * distribution. *
15  * 3. Neither the name of the copyright holder nor the names of its *
16  * contributors may be used to endorse or promote products derived *
17  * from this software without specific prior written permission. *
18  * *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY *
29  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
30  * POSSIBILITY OF SUCH DAMAGE. *
31  ***************************************************************************/
32 
33 #include <OGRE/OgreVector3.h>
34 #include <OGRE/OgreMatrix3.h>
35 #include <OGRE/OgreSceneNode.h>
36 #include <OGRE/OgreSceneManager.h>
37 
39 
40 namespace tuw_object_rviz
41 {
42 ObjectDetectionTrafficConeVisual::ObjectDetectionTrafficConeVisual(Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node) : ObjectDetectionVisual(scene_manager, parent_node)
43 {
46 }
47 
49 {
50  // empty destructor since parent destructor destroys frame node anyway
51 }
52 
53 void ObjectDetectionTrafficConeVisual::setMessage(const tuw_object_msgs::ObjectWithCovariance::ConstPtr& msg)
54 {
55  // call parent class set Message to also display covariance, center, ids
57 
58  Ogre::Vector3 position = Ogre::Vector3(msg->object.pose.position.x, msg->object.pose.position.y, msg->object.pose.position.z);
59  position = transform_ * position;
60  position.z = 0; // fix on ground z=0
61 
62  double c_90 = cos(M_PI/2.0);
63  double s_90 = sin(M_PI/2.0);
64  Ogre::Matrix3 R_x(1,0,0,
65  0,c_90,-s_90,
66  0,s_90,c_90);
67  Ogre::Quaternion q_flip;
68  q_flip.FromRotationMatrix(R_x);
69 
70  Ogre::Quaternion orientation = Ogre::Quaternion(msg->object.pose.orientation.w, msg->object.pose.orientation.x,
71  msg->object.pose.orientation.y, msg->object.pose.orientation.z);
72  orientation = q_flip * orientation;
73  double radius = msg->object.shape_variables[0];
74  double height = msg->object.shape_variables[1];
75  int color = (int) msg->object.shape_variables[2];
76  traffic_cone_visual_->setRadius(radius);
77  traffic_cone_visual_->setHeight(height);
78  Ogre::ColourValue c(0,0,0,1.0);
79  if (color == 1) // blue
80  {
81  c.b = 1.0;
82  }
83  else if (color == 2) // yellow
84  {
85  c.r = 1.0;
86  c.g = 1.0;
87  }
88  else if (color == 3)
89  {
90  c.r = 1.0;
91  }
92 
93  traffic_cone_visual_->setColor(c);
94  traffic_cone_visual_->setPosition(position + Ogre::Vector3(0, 0, height/2.0));
95  traffic_cone_visual_->setOrientation(orientation);
96  traffic_cone_visual_->update(0.0);
97 }
98 
99 // Color is passed through to the pose Shape object.
100 void ObjectDetectionTrafficConeVisual::setColor(Ogre::ColourValue color)
101 {
103  //traffic_cone_visual_->setColor(color);
104 }
105 
107 {
108  Ogre::Vector3 position;
109  Ogre::Quaternion orientation;
110  Ogre::ColourValue color;
112 
113  position = traffic_cone_visual_->getPosition();
114  orientation = traffic_cone_visual_->getOrientation();
115  color = traffic_cone_visual_->getColor();
116 
117  switch (style)
118  {
120  traffic_cone_visual_.reset(new TrafficConeVisualImpl(default_args));
121  break;
122  default:
123  break;
124  }
125 
126  traffic_cone_visual_->setOrientation(orientation);
127  traffic_cone_visual_->setPosition(position);
128  traffic_cone_visual_->setColor(color);
129 
130 }
131 
132 } // end namespace tuw_object_rviz
virtual void setColor(Ogre::ColourValue color)
virtual void setMessage(const tuw_object_msgs::ObjectWithCovariance::ConstPtr &msg)
void setMessage(const tuw_object_msgs::ObjectWithCovariance::ConstPtr &msg)
Visualization of a person as a wireframe bounding box.
Styles
Visualization style for an object.
Definition: common.h:40
ObjectDetectionTrafficConeVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node)


tuw_object_rviz
Author(s): Florian Beck
autogenerated on Mon Jun 10 2019 15:40:17