marker_with_covariance.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Lukas Pfeifhofer <lukas.pfeifhofer@devlabs.pro>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
34 
35 #include <OGRE/OgreVector3.h>
36 #include <OGRE/OgreSceneNode.h>
37 
38 #define SHAPE_WIDTH_MIN 0.005f // Avoid a complete flat sphere/cylinder
39 
40 namespace marker_rviz_plugin {
41 
42  MarkerWithCovariance::MarkerWithCovariance(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node, int id)
43  : Marker(scene_manager, parent_node, id) {
44 
45  variance_pos_parent = scene_node_->getParentSceneNode()->createChildSceneNode();
46 
48  variance_pos_->setColor(Ogre::ColourValue(1.0, 1.0, 0.0, 0.9f));
49  variance_pos_->getMaterial()->setReceiveShadows(false);
50 
51  for (int i = 0; i < 3; i++) {
53  variance_rpy_[i]->setColor(Ogre::ColourValue((255.0 / 255.0), (85.0 / 255.0), (255.0 / 255.0), 0.6f));
54  variance_rpy_[i]->getMaterial()->setReceiveShadows(false);
55  }
56  }
57 
60  scene_manager_->destroySceneNode(variance_pos_parent);
61 
62  delete variance_pos_;
63  for (int i = 0; i < 3; i++)
64  delete variance_rpy_[i];
65  }
66 
67  void MarkerWithCovariance::setCovarianceMatrix(boost::array<double, 36> m) {
68  Ogre::Matrix3 cov_xyz = Ogre::Matrix3(
69  m[6 * 0 + 0], m[6 * 0 + 1], m[6 * 0 + 2],
70  m[6 * 1 + 0], m[6 * 1 + 1], m[6 * 1 + 2],
71  m[6 * 2 + 0], m[6 * 2 + 1], m[6 * 2 + 2]
72  );
73 
74  Ogre::Real eigenvalues[3];
75  Ogre::Vector3 eigenvectors[3];
76  cov_xyz.EigenSolveSymmetric(eigenvalues, eigenvectors);
77 
78  if (eigenvalues[0] < 0)
79  eigenvalues[0] = 0;
80 
81  if (eigenvalues[1] < 0)
82  eigenvalues[1] = 0;
83 
84  if (eigenvalues[2] < 0)
85  eigenvalues[2] = 0;
86 
87 
88  variance_pos_parent->setPosition(scene_node_->getPosition());
89  variance_pos_->setOrientation(Ogre::Quaternion(eigenvectors[0], eigenvectors[1], eigenvectors[2]));
91  Ogre::Vector3(
92  fmax(2 * sqrt(eigenvalues[0]), SHAPE_WIDTH_MIN),
93  fmax(2 * sqrt(eigenvalues[1]), SHAPE_WIDTH_MIN),
94  fmax(2 * sqrt(eigenvalues[2]), SHAPE_WIDTH_MIN)
95  )
96  );
97 
98 
99  // Roll
100  Ogre::Matrix3 cov_roll = Ogre::Matrix3(
101  m[6 * 4 + 4], m[6 * 4 + 5], 0,
102  m[6 * 5 + 5], m[6 * 5 + 5], 0,
103  0, 0, 0
104  );
105  cov_roll.EigenSolveSymmetric(eigenvalues, eigenvectors);
106 
107  Ogre::Quaternion o = Ogre::Quaternion::IDENTITY;
108  o = o * Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3::UNIT_Z);
109  o = o * Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3::UNIT_Y);
110  o = o * (Ogre::Quaternion(Ogre::Matrix3(1, 0, 0,
111  0, eigenvectors[0][0], eigenvectors[0][1],
112  0, eigenvectors[1][0], eigenvectors[1][1])));
113 
115  variance_rpy_[0]->setPosition(Ogre::Vector3(0.7f, 0.0f, 0.0f));
117  Ogre::Vector3(
118  fmax(2 * sqrt(eigenvalues[0]), SHAPE_WIDTH_MIN),
120  fmax(2 * sqrt(eigenvalues[1]), SHAPE_WIDTH_MIN)
121  )
122  );
123 
124  // Pitch
125  Ogre::Matrix3 cov_pitch = Ogre::Matrix3(
126  m[6 * 3 + 3], m[6 * 3 + 5], 0,
127  m[6 * 5 + 3], m[6 * 5 + 5], 0,
128  0, 0, 0
129  );
130  cov_pitch.EigenSolveSymmetric(eigenvalues, eigenvectors);
131 
132  o = Ogre::Quaternion::IDENTITY;
133  o = o * Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3::UNIT_Y);
134  o = o * (Ogre::Quaternion(Ogre::Matrix3(eigenvectors[0][0], 0, eigenvectors[0][1],
135  0, 1, 0,
136  0, eigenvectors[1][0], eigenvectors[1][1])));
137 
139  variance_rpy_[1]->setPosition(Ogre::Vector3(0.0f, 0.7f, 0.0f));
141  Ogre::Vector3(
142  fmax(2 * sqrt(eigenvalues[0]), SHAPE_WIDTH_MIN),
144  fmax(2 * sqrt(eigenvalues[1]), SHAPE_WIDTH_MIN)
145  )
146  );
147 
148  // Yaw
149  Ogre::Matrix3 cov_yaw = Ogre::Matrix3(
150  m[6 * 3 + 3], m[6 * 3 + 4], 0,
151  m[6 * 4 + 3], m[6 * 4 + 4], 0,
152  0, 0, 0
153  );
154  cov_yaw.EigenSolveSymmetric(eigenvalues, eigenvectors);
155 
156  o = Ogre::Quaternion::IDENTITY;
157  o = o * Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3::UNIT_X);
158  o = o * (Ogre::Quaternion(Ogre::Matrix3(eigenvectors[0][0], eigenvectors[0][1], 0,
159  eigenvectors[1][0], eigenvectors[1][1], 0,
160  0, 0, 1)));
161 
163  variance_rpy_[2]->setPosition(Ogre::Vector3(0.0f, 0.0f, 0.7f));
165  Ogre::Vector3(
166  fmax(2 * sqrt(eigenvalues[0]), SHAPE_WIDTH_MIN),
168  fmax(2 * sqrt(eigenvalues[1]), SHAPE_WIDTH_MIN)
169  )
170  );
171  }
172 
173  void MarkerWithCovariance::setScale(const Ogre::Vector3 &scale) {
174  Marker::setScale(scale);
175  variance_pos_parent->setScale(scale);
176  }
177 
178 }
virtual void setOrientation(const Ogre::Quaternion &orientation)
f
MarkerWithCovariance(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node=0, int id=-1)
virtual void setScale(const Ogre::Vector3 &scale)
Definition: marker.cpp:145
virtual void setColor(float r, float g, float b, float a)
virtual void setCovarianceMatrix(boost::array< double, 36 > m)
virtual void setPosition(const Ogre::Vector3 &position)
Ogre::MaterialPtr getMaterial()
#define SHAPE_WIDTH_MIN
Ogre::SceneManager * scene_manager_
virtual void setScale(const Ogre::Vector3 &scale)
virtual void setScale(const Ogre::Vector3 &scale)
Ogre::SceneNode * scene_node_
Definition: marker.h:89


marker_rviz_plugin
Author(s): Markus Bader, Lukas Pfeifhofer, Markus Macsek
autogenerated on Mon Jun 10 2019 13:54:22