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 
66 
67 namespace Ogre {
68  class SceneManager;
69  class SceneNode;
70  class ManualObject;
71  class MovableObject;
72 }
73 
75 
76 namespace mira { namespace OgreUtils {
77 
79 
80 template <typename TPoint>
81 inline Ogre::Vector3 toOgreVector(const TPoint& p)
82 {
83  static_assert(sizeof(TPoint)==0, "toOgreVector is not implemented for this type");
84  return Ogre::Vector3();
85 }
86 
87 template <>
88 inline Ogre::Vector3 toOgreVector<Point2f>(const Point2f& p)
89 {
90  return Ogre::Vector3(p.x(), p.y(), 0);
91 }
92 
93 template <>
94 inline Ogre::Vector3 toOgreVector<Point3f>(const Point3f& p)
95 {
96  return Ogre::Vector3(p.x(), p.y(), p.z());
97 }
98 
99 template <>
100 inline Ogre::Vector3 toOgreVector<Pose2>(const Pose2& p)
101 {
102  return Ogre::Vector3(p.x(), p.y(), 0);
103 }
104 
105 template <>
106 inline Ogre::Vector3 toOgreVector<PoseCov2>(const PoseCov2& p)
107 {
108  return Ogre::Vector3(p.x(), p.y(), 0);
109 }
110 
111 template <>
112 inline Ogre::Vector3 toOgreVector<Pose3>(const Pose3& p)
113 {
114  return Ogre::Vector3(p.x(), p.y(), p.z());
115 }
116 
117 template <>
118 inline Ogre::Vector3 toOgreVector<PoseCov3>(const PoseCov3& p)
119 {
120  return Ogre::Vector3(p.x(), p.y(), p.z());
121 }
122 
123 template <>
124 inline Ogre::Vector3 toOgreVector<RigidTransform<double, 2> >(const RigidTransform<double, 2>& p)
125 {
126  return Ogre::Vector3(p.x(), p.y(), 0);
127 }
128 
129 template <>
130 inline Ogre::Vector3 toOgreVector<RigidTransformCov<double, 2> >(const RigidTransformCov<double, 2>& p)
131 {
132  return Ogre::Vector3(p.x(), p.y(), 0);
133 }
134 
135 template <>
136 inline Ogre::Vector3 toOgreVector<RigidTransform<double, 3> >(const RigidTransform<double, 3>& p)
137 {
138  return Ogre::Vector3(p.x(), p.y(), p.z());
139 }
140 
141 template <>
142 inline Ogre::Vector3 toOgreVector<RigidTransformCov<double, 3> >(const RigidTransformCov<double, 3>& p)
143 {
144  return Ogre::Vector3(p.x(), p.y(), p.z());
145 }
146 
147 template <typename ColorType>
148 inline Ogre::ColourValue toOgreColor(const ColorType& c)
149 {
150  return Ogre::ColourValue();
151 }
152 
153 template <>
154 inline Ogre::ColourValue toOgreColor<Color::RGB>(const Color::RGB& c)
155 {
156  return Ogre::ColourValue(c.r, c.g, c.b, 1.0f);
157 }
158 
159 template <>
160 inline Ogre::ColourValue toOgreColor<Color::RGBA>(const Color::RGBA& c)
161 {
162  return Ogre::ColourValue(c.r, c.g, c.b, c.a);
163 }
164 
166 
167 MIRA_GUI_WIDGETS_EXPORT void loadResource(const Path& path,
168  const Ogre::String& resourceGroup);
169 
174 MIRA_GUI_WIDGETS_EXPORT void setTransform(Ogre::SceneNode* node,
175  const RigidTransform2f& t);
176 
181 MIRA_GUI_WIDGETS_EXPORT void setTransform(Ogre::SceneNode* node,
182  const RigidTransform3f& t);
183 
188 MIRA_GUI_WIDGETS_EXPORT void setPosition(Ogre::SceneNode* node,
189  const Eigen::Vector2f& t);
190 
195 MIRA_GUI_WIDGETS_EXPORT void setPosition(Ogre::SceneNode* node,
196  const Eigen::Vector3f& t);
197 
202 MIRA_GUI_WIDGETS_EXPORT void setOrientation(Ogre::SceneNode* node,
203  const Eigen::Rotation2D<float>& r);
204 
209 MIRA_GUI_WIDGETS_EXPORT void setOrientation(Ogre::SceneNode* node,
210  const Eigen::Quaternion<float>& r);
211 
215 MIRA_GUI_WIDGETS_EXPORT bool hasAttachedObject(Ogre::SceneNode* node,
216  Ogre::MovableObject* object);
217 
218 
224 MIRA_GUI_WIDGETS_EXPORT void rayQuery(Ogre::SceneNode* node,
225  const Ogre::Ray& ray,
226  Ogre::RaySceneQueryResult& oResult,
227  uint32 queryMask=0xFFFFFFFF);
228 
229 
230 // intersection point: ray.getPoint(result.second);
240 MIRA_GUI_WIDGETS_EXPORT std::pair<bool,float> rayObjectCollision(const Ogre::Ray& ray,
241  const Ogre::MovableObject* object);
242 
244 
245 }}
246 
247 #endif
#define MIRA_GUI_WIDGETS_EXPORT
Definition: GuiWidgetsExports.h:61
MIRA_GUI_WIDGETS_EXPORT void loadResource(const Path &path, const Ogre::String &resourceGroup)
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
Class for 2D, 3D and N-dimensional points.
MIRA_GUI_WIDGETS_EXPORT std::pair< bool, float > rayObjectCollision(const Ogre::Ray &ray, const Ogre::MovableObject *object)
Performs a ray/object collision check.
Ogre::Vector3 toOgreVector< Pose2 >(const Pose2 &p)
Definition: OgreUtils.h:100
Color in RGBA color space.
Definition: Color.h:159
Ogre::Vector3 toOgreVector< Pose3 >(const Pose3 &p)
Definition: OgreUtils.h:112
GUI export macro declaration.
MIRA_GUI_WIDGETS_EXPORT void setPosition(Ogre::SceneNode *node, const Eigen::Vector2f &t)
Sets the position of the scene node according to the specified translation.
Ogre::ColourValue toOgreColor(const ColorType &c)
Definition: OgreUtils.h:148
Ogre::Vector3 toOgreVector(const TPoint &p)
Definition: OgreUtils.h:81
This file contains color classes for the Img class.
Definition: ImageObject.h:60
Functions for modifying file system paths.
Ogre::Vector3 toOgreVector< Point3f >(const Point3f &p)
Definition: OgreUtils.h:94
Non intrusive reflect for OGRE color class.
MIRA_GUI_WIDGETS_EXPORT void setOrientation(Ogre::SceneNode *node, const Eigen::Rotation2D< float > &r)
Sets the orientation of the scene node according to the specified rotation.
Ogre::Vector3 toOgreVector< PoseCov3 >(const PoseCov3 &p)
Definition: OgreUtils.h:118
Typedefs for different Pose datatypes that are internally RigidTransforms.
Ogre::Vector3 toOgreVector< PoseCov2 >(const PoseCov2 &p)
Definition: OgreUtils.h:106
The different color spaces.
Definition: Color.h:104
MIRA_GUI_WIDGETS_EXPORT bool hasAttachedObject(Ogre::SceneNode *node, Ogre::MovableObject *object)
Returns true if object is directly or indirectly attached to the given node.
MIRA_GUI_WIDGETS_EXPORT 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...
Ogre::Vector3 toOgreVector< Point2f >(const Point2f &p)
Definition: OgreUtils.h:88
MIRA_GUI_WIDGETS_EXPORT void setTransform(Ogre::SceneNode *node, const RigidTransform2f &t)
Sets position and orientation of the scene node according to the specified transform.