MIRA
OgreUtils.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_OGREUTILS_H_
48 #define _MIRA_OGREUTILS_H_
49 
50 #include <geometry/Point.h>
51 #include <utils/Path.h>
52 #include <image/Color.h>
53 
54 #include <transform/Pose.h>
55 
56 #ifndef Q_MOC_RUN
57 #include <OGRE/OgreString.h>
58 #include <OGRE/OgreVector3.h>
59 #include <OGRE/OgreColourValue.h>
60 #include <OGRE/OgreSceneQuery.h>
61 #endif
62 
64 
65 namespace Ogre {
66  class SceneManager;
67  class SceneNode;
68  class ManualObject;
69  class MovableObject;
70 }
71 
73 
74 namespace mira { namespace OgreUtils {
75 
77 
78 template <typename TPoint>
79 inline Ogre::Vector3 toOgreVector(const TPoint& p)
80 {
81  static_assert(sizeof(TPoint)==0, "toOgreVector is not implemented for this type");
82  return Ogre::Vector3();
83 }
84 
85 template <>
86 inline Ogre::Vector3 toOgreVector<Point2f>(const Point2f& p)
87 {
88  return Ogre::Vector3(p.x(), p.y(), 0);
89 }
90 
91 template <>
92 inline Ogre::Vector3 toOgreVector<Point3f>(const Point3f& p)
93 {
94  return Ogre::Vector3(p.x(), p.y(), p.z());
95 }
96 
97 template <>
98 inline Ogre::Vector3 toOgreVector<Pose2>(const Pose2& p)
99 {
100  return Ogre::Vector3(p.x(), p.y(), 0);
101 }
102 
103 template <>
104 inline Ogre::Vector3 toOgreVector<PoseCov2>(const PoseCov2& p)
105 {
106  return Ogre::Vector3(p.x(), p.y(), 0);
107 }
108 
109 template <>
110 inline Ogre::Vector3 toOgreVector<Pose3>(const Pose3& p)
111 {
112  return Ogre::Vector3(p.x(), p.y(), p.z());
113 }
114 
115 template <>
116 inline Ogre::Vector3 toOgreVector<PoseCov3>(const PoseCov3& p)
117 {
118  return Ogre::Vector3(p.x(), p.y(), p.z());
119 }
120 
121 template <>
122 inline Ogre::Vector3 toOgreVector<RigidTransform<double, 2> >(const RigidTransform<double, 2>& p)
123 {
124  return Ogre::Vector3(p.x(), p.y(), 0);
125 }
126 
127 template <>
128 inline Ogre::Vector3 toOgreVector<RigidTransformCov<double, 2> >(const RigidTransformCov<double, 2>& p)
129 {
130  return Ogre::Vector3(p.x(), p.y(), 0);
131 }
132 
133 template <>
134 inline Ogre::Vector3 toOgreVector<RigidTransform<double, 3> >(const RigidTransform<double, 3>& p)
135 {
136  return Ogre::Vector3(p.x(), p.y(), p.z());
137 }
138 
139 template <>
140 inline Ogre::Vector3 toOgreVector<RigidTransformCov<double, 3> >(const RigidTransformCov<double, 3>& p)
141 {
142  return Ogre::Vector3(p.x(), p.y(), p.z());
143 }
144 
145 template <typename ColorType>
146 inline Ogre::ColourValue toOgreColor(const ColorType& c)
147 {
148  return Ogre::ColourValue();
149 }
150 
151 template <>
152 inline Ogre::ColourValue toOgreColor<Color::RGB>(const Color::RGB& c)
153 {
154  return Ogre::ColourValue(c.r, c.g, c.b, 1.0f);
155 }
156 
157 template <>
158 inline Ogre::ColourValue toOgreColor<Color::RGBA>(const Color::RGBA& c)
159 {
160  return Ogre::ColourValue(c.r, c.g, c.b, c.a);
161 }
162 
164 
165 void loadResource(const Path& path,
166  const Ogre::String& resourceGroup);
167 
172 void setTransform(Ogre::SceneNode* node,
173  const RigidTransform2f& t);
174 
179 void setTransform(Ogre::SceneNode* node,
180  const RigidTransform3f& t);
181 
186 void setPosition(Ogre::SceneNode* node,
187  const Eigen::Vector2f& t);
188 
193 void setPosition(Ogre::SceneNode* node,
194  const Eigen::Vector3f& t);
195 
200 void setOrientation(Ogre::SceneNode* node,
201  const Eigen::Rotation2D<float>& r);
202 
207 void setOrientation(Ogre::SceneNode* node,
208  const Eigen::Quaternion<float>& r);
209 
213 bool hasAttachedObject(Ogre::SceneNode* node,
214  Ogre::MovableObject* object);
215 
216 
222 void rayQuery(Ogre::SceneNode* node,
223  const Ogre::Ray& ray,
224  Ogre::RaySceneQueryResult& oResult,
225  uint32 queryMask=0xFFFFFFFF);
226 
227 
228 // intersection point: ray.getPoint(result.second);
238 std::pair<bool,float> rayObjectCollision(const Ogre::Ray& ray,
239  const Ogre::MovableObject* object);
240 
242 
243 }}
244 
245 #endif
void setPosition(Ogre::SceneNode *node, const Eigen::Vector2f &t)
Sets the position of the scene node according to the specified translation.
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
boost::filesystem::path Path
Typedef of a Path (shorter version for boost::filesystem::path)
Definition: Path.h:69
void loadResource(const Path &path, const Ogre::String &resourceGroup)
Class for 2D, 3D and N-dimensional points.
void rayQuery(Ogre::SceneNode *node, const Ogre::Ray &ray, Ogre::RaySceneQueryResult &oResult, uint32 queryMask=0xFFFFFFFF)
Performs ray intersection tests for ALL movable objects in the specified scene node and all of its ch...
uint32_t uint32
Definition: Types.h:64
Ogre::Vector3 toOgreVector< Pose2 >(const Pose2 &p)
Definition: OgreUtils.h:98
Color in RGBA color space.
Definition: Color.h:159
Ogre::Vector3 toOgreVector< Pose3 >(const Pose3 &p)
Definition: OgreUtils.h:110
Ogre::ColourValue toOgreColor(const ColorType &c)
Definition: OgreUtils.h:146
Ogre::Vector3 toOgreVector(const TPoint &p)
Definition: OgreUtils.h:79
This file contains color classes for the Img class.
bool hasAttachedObject(Ogre::SceneNode *node, Ogre::MovableObject *object)
Returns true if object is directly or indirectly attached to the given node.
std::pair< bool, float > rayObjectCollision(const Ogre::Ray &ray, const Ogre::MovableObject *object)
Performs a ray/object collision check.
Definition: ImageObject.h:60
void setTransform(Ogre::SceneNode *node, const RigidTransform2f &t)
Sets position and orientation of the scene node according to the specified transform.
Functions for modifying file system paths.
Ogre::Vector3 toOgreVector< Point3f >(const Point3f &p)
Definition: OgreUtils.h:92
Non intrusive reflect for OGRE color class.
Ogre::Vector3 toOgreVector< PoseCov3 >(const PoseCov3 &p)
Definition: OgreUtils.h:116
Typedefs for different Pose datatypes that are internally RigidTransforms.
Ogre::Vector3 toOgreVector< PoseCov2 >(const PoseCov2 &p)
Definition: OgreUtils.h:104
The different color spaces.
Definition: Color.h:104
Ogre::Vector3 toOgreVector< Point2f >(const Point2f &p)
Definition: OgreUtils.h:86
void setOrientation(Ogre::SceneNode *node, const Eigen::Rotation2D< float > &r)
Sets the orientation of the scene node according to the specified rotation.