Karto.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 SRI International
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef OPEN_KARTO_KARTO_H
19 #define OPEN_KARTO_KARTO_H
20 
21 #include <string>
22 #include <fstream>
23 #include <limits>
24 #include <algorithm>
25 #include <map>
26 #include <vector>
27 #include <iostream>
28 #include <iomanip>
29 #include <sstream>
30 #include <stdexcept>
31 
32 #include <math.h>
33 #include <float.h>
34 #include <stdio.h>
35 #include <assert.h>
36 #include <string.h>
37 #include <boost/thread.hpp>
38 
39 #ifdef USE_POCO
40 #include <Poco/Mutex.h>
41 #endif
42 
43 #include <open_karto/Math.h>
44 #include <open_karto/Macros.h>
45 
46 #define KARTO_Object(name) \
47  virtual const char* GetClassName() const { return #name; } \
48  virtual kt_objecttype GetObjectType() const { return ObjectType_##name; }
49 
51 
52 const kt_objecttype ObjectType_None = 0x00000000;
53 const kt_objecttype ObjectType_Sensor = 0x00001000;
56 const kt_objecttype ObjectType_Misc = 0x10000000;
57 
61 
67 
72 
73 namespace karto
74 {
75 
80 
85  {
86  public:
92  Exception(const std::string& rMessage = "Karto Exception", kt_int32s errorCode = 0)
93  : m_Message(rMessage)
94  , m_ErrorCode(errorCode)
95  {
96  }
97 
101  Exception(const Exception& rException)
102  : m_Message(rException.m_Message)
103  , m_ErrorCode(rException.m_ErrorCode)
104  {
105  }
106 
110  virtual ~Exception()
111  {
112  }
113 
114  public:
118  Exception& operator = (const Exception& rException)
119  {
120  m_Message = rException.m_Message;
121  m_ErrorCode = rException.m_ErrorCode;
122 
123  return *this;
124  }
125 
126  public:
131  const std::string& GetErrorMessage() const
132  {
133  return m_Message;
134  }
135 
141  {
142  return m_ErrorCode;
143  }
144 
145  public:
151  friend KARTO_EXPORT std::ostream& operator << (std::ostream& rStream, Exception& rException);
152 
153  private:
154  std::string m_Message;
156  }; // class Exception
157 
161 
167  {
168  private:
169  NonCopyable(const NonCopyable&);
170  const NonCopyable& operator=(const NonCopyable&);
171 
172  protected:
174  {
175  }
176 
177  virtual ~NonCopyable()
178  {
179  }
180  }; // class NonCopyable
181 
185 
189  template <class T>
190  class Singleton
191  {
192  public:
197  : m_pPointer(NULL)
198  {
199  }
200 
204  virtual ~Singleton()
205  {
206  delete m_pPointer;
207  }
208 
213  T* Get()
214  {
215 #ifdef USE_POCO
216  Poco::FastMutex::ScopedLock lock(m_Mutex);
217 #endif
218  if (m_pPointer == NULL)
219  {
220  m_pPointer = new T;
221  }
222 
223  return m_pPointer;
224  }
225 
226  private:
228 
229 #ifdef USE_POCO
230  Poco::FastMutex m_Mutex;
231 #endif
232 
233  private:
234  Singleton(const Singleton&);
235  const Singleton& operator=(const Singleton&);
236  };
237 
241 
246  {
247  public:
251  virtual void operator() (kt_int32u) {};
252  }; // Functor
253 
257 
259 
263  typedef std::vector<AbstractParameter*> ParameterVector;
264 
269  {
270  public:
275  {
276  }
277 
282  {
283  Clear();
284  }
285 
286  public:
291  void Add(AbstractParameter* pParameter);
292 
298  AbstractParameter* Get(const std::string& rName)
299  {
300  if (m_ParameterLookup.find(rName) != m_ParameterLookup.end())
301  {
302  return m_ParameterLookup[rName];
303  }
304 
305  std::cout << "Unknown parameter: " << rName << std::endl;
306 
307  return NULL;
308  }
309 
313  void Clear();
314 
319  inline const ParameterVector& GetParameterVector() const
320  {
321  return m_Parameters;
322  }
323 
324  public:
330  AbstractParameter* operator() (const std::string& rName)
331  {
332  return Get(rName);
333  }
334 
335  private:
337  const ParameterManager& operator=(const ParameterManager&);
338 
339  private:
340  ParameterVector m_Parameters;
341  std::map<std::string, AbstractParameter*> m_ParameterLookup;
342  }; // ParameterManager
343 
347 
348  // valid names
349  // 'Test' -- no scope
350  // '/Test' -- no scope will be parsed to 'Test'
351  // '/scope/Test' - 'scope' scope and 'Test' name
352  // '/scope/name/Test' - 'scope/name' scope and 'Test' name
353  //
354  class Name
355  {
356  public:
361  {
362  }
363 
367  Name(const std::string& rName)
368  {
369  Parse(rName);
370  }
371 
375  Name(const Name& rOther)
376  : m_Name(rOther.m_Name)
377  , m_Scope(rOther.m_Scope)
378  {
379  }
380 
384  virtual ~Name()
385  {
386  }
387 
388  public:
393  inline const std::string& GetName() const
394  {
395  return m_Name;
396  }
397 
402  inline void SetName(const std::string& rName)
403  {
404  std::string::size_type pos = rName.find_last_of('/');
405  if (pos != 0 && pos != std::string::npos)
406  {
407  throw Exception("Name can't contain a scope!");
408  }
409 
410  m_Name = rName;
411  }
412 
417  inline const std::string& GetScope() const
418  {
419  return m_Scope;
420  }
421 
426  inline void SetScope(const std::string& rScope)
427  {
428  m_Scope = rScope;
429  }
430 
435  inline std::string ToString() const
436  {
437  if (m_Scope == "")
438  {
439  return m_Name;
440  }
441  else
442  {
443  std::string name;
444  name.append("/");
445  name.append(m_Scope);
446  name.append("/");
447  name.append(m_Name);
448 
449  return name;
450  }
451  }
452 
453  public:
457  Name& operator = (const Name& rOther)
458  {
459  if (&rOther != this)
460  {
461  m_Name = rOther.m_Name;
462  m_Scope = rOther.m_Scope;
463  }
464 
465  return *this;
466  }
467 
471  kt_bool operator == (const Name& rOther) const
472  {
473  return (m_Name == rOther.m_Name) && (m_Scope == rOther.m_Scope);
474  }
475 
479  kt_bool operator != (const Name& rOther) const
480  {
481  return !(*this == rOther);
482  }
483 
487  kt_bool operator < (const Name& rOther) const
488  {
489  return ToString() < rOther.ToString();
490  }
491 
497  friend inline std::ostream& operator << (std::ostream& rStream, const Name& rName)
498  {
499  rStream << rName.ToString();
500  return rStream;
501  }
502 
503  private:
508  void Parse(const std::string& rName)
509  {
510  std::string::size_type pos = rName.find_last_of('/');
511 
512  if (pos == std::string::npos)
513  {
514  m_Name = rName;
515  }
516  else
517  {
518  m_Scope = rName.substr(0, pos);
519  m_Name = rName.substr(pos+1, rName.size());
520 
521  // remove '/' from m_Scope if first!!
522  if (m_Scope.size() > 0 && m_Scope[0] == '/')
523  {
524  m_Scope = m_Scope.substr(1, m_Scope.size());
525  }
526  }
527  }
528 
533  void Validate(const std::string& rName)
534  {
535  if (rName.empty())
536  {
537  return;
538  }
539 
540  char c = rName[0];
541  if (IsValidFirst(c))
542  {
543  for (size_t i = 1; i < rName.size(); ++i)
544  {
545  c = rName[i];
546  if (!IsValid(c))
547  {
548  throw Exception("Invalid character in name. Valid characters must be within the ranges A-Z, a-z, 0-9, '/', '_' and '-'.");
549  }
550  }
551  }
552  else
553  {
554  throw Exception("Invalid first character in name. Valid characters must be within the ranges A-Z, a-z, and '/'.");
555  }
556  }
557 
563  inline kt_bool IsValidFirst(char c)
564  {
565  return (isalpha(c) || c == '/');
566  }
567 
573  inline kt_bool IsValid(char c)
574  {
575  return (isalnum(c) || c == '/' || c == '_' || c == '-');
576  }
577 
578  private:
579  std::string m_Name;
580  std::string m_Scope;
581  };
582 
586 
591  {
592  public:
596  Object();
597 
602  Object(const Name& rName);
603 
607  virtual ~Object();
608 
609  public:
614  inline const Name& GetName() const
615  {
616  return m_Name;
617  }
618 
623  virtual const char* GetClassName() const = 0;
624 
629  virtual kt_objecttype GetObjectType() const = 0;
630 
636  {
637  return m_pParameterManager;
638  }
639 
645  inline AbstractParameter* GetParameter(const std::string& rName) const
646  {
647  return m_pParameterManager->Get(rName);
648  }
649 
655  template<typename T>
656  inline void SetParameter(const std::string& rName, T value);
657 
662  inline const ParameterVector& GetParameters() const
663  {
664  return m_pParameterManager->GetParameterVector();
665  }
666 
667  private:
668  Object(const Object&);
669  const Object& operator=(const Object&);
670 
671  private:
674  };
675 
679  typedef std::vector<Object*> ObjectVector;
680 
684 
690  inline kt_bool IsSensor(Object* pObject)
691  {
692  return (pObject->GetObjectType() & ObjectType_Sensor) == ObjectType_Sensor;
693  }
694 
700  inline kt_bool IsSensorData(Object* pObject)
701  {
703  }
704 
711  {
713  }
714 
721  {
723  }
724 
731  {
733  }
734 
740  inline kt_bool IsParameters(Object* pObject)
741  {
743  }
744 
750  inline kt_bool IsDatasetInfo(Object* pObject)
751  {
753  }
754 
758 
762  class KARTO_EXPORT Module : public Object
763  {
764  public:
765  // @cond EXCLUDE
767  // @endcond
768 
769  public:
774  Module(const std::string& rName);
775 
779  virtual ~Module();
780 
781  public:
785  virtual void Reset() = 0;
786 
791  {
792  return false;
793  }
794 
795  private:
796  Module(const Module&);
797  const Module& operator=(const Module&);
798  };
799 
803 
807  template<typename T>
808  class Size2
809  {
810  public:
815  : m_Width(0)
816  , m_Height(0)
817  {
818  }
819 
825  Size2(T width, T height)
826  : m_Width(width)
827  , m_Height(height)
828  {
829  }
830 
835  Size2(const Size2& rOther)
836  : m_Width(rOther.m_Width)
837  , m_Height(rOther.m_Height)
838  {
839  }
840 
841  public:
846  inline const T GetWidth() const
847  {
848  return m_Width;
849  }
850 
855  inline void SetWidth(T width)
856  {
857  m_Width = width;
858  }
859 
864  inline const T GetHeight() const
865  {
866  return m_Height;
867  }
868 
873  inline void SetHeight(T height)
874  {
875  m_Height = height;
876  }
877 
881  inline Size2& operator = (const Size2& rOther)
882  {
883  m_Width = rOther.m_Width;
884  m_Height = rOther.m_Height;
885 
886  return(*this);
887  }
888 
892  inline kt_bool operator == (const Size2& rOther) const
893  {
894  return (m_Width == rOther.m_Width && m_Height == rOther.m_Height);
895  }
896 
900  inline kt_bool operator != (const Size2& rOther) const
901  {
902  return (m_Width != rOther.m_Width || m_Height != rOther.m_Height);
903  }
904 
910  friend inline std::ostream& operator << (std::ostream& rStream, const Size2& rSize)
911  {
912  rStream << "(" << rSize.m_Width << ", " << rSize.m_Height << ")";
913  return rStream;
914  }
915 
916  private:
919  }; // Size2<T>
920 
924 
928  template<typename T>
929  class Vector2
930  {
931  public:
936  {
937  m_Values[0] = 0;
938  m_Values[1] = 0;
939  }
940 
946  Vector2(T x, T y)
947  {
948  m_Values[0] = x;
949  m_Values[1] = y;
950  }
951 
952  public:
957  inline const T& GetX() const
958  {
959  return m_Values[0];
960  }
961 
966  inline void SetX(const T& x)
967  {
968  m_Values[0] = x;
969  }
970 
975  inline const T& GetY() const
976  {
977  return m_Values[1];
978  }
979 
984  inline void SetY(const T& y)
985  {
986  m_Values[1] = y;
987  }
988 
993  inline void MakeFloor(const Vector2& rOther)
994  {
995  if ( rOther.m_Values[0] < m_Values[0] ) m_Values[0] = rOther.m_Values[0];
996  if ( rOther.m_Values[1] < m_Values[1] ) m_Values[1] = rOther.m_Values[1];
997  }
998 
1003  inline void MakeCeil(const Vector2& rOther)
1004  {
1005  if ( rOther.m_Values[0] > m_Values[0] ) m_Values[0] = rOther.m_Values[0];
1006  if ( rOther.m_Values[1] > m_Values[1] ) m_Values[1] = rOther.m_Values[1];
1007  }
1008 
1013  inline kt_double SquaredLength() const
1014  {
1015  return math::Square(m_Values[0]) + math::Square(m_Values[1]);
1016  }
1017 
1022  inline kt_double Length() const
1023  {
1024  return sqrt(SquaredLength());
1025  }
1026 
1031  inline kt_double SquaredDistance(const Vector2& rOther) const
1032  {
1033  return (*this - rOther).SquaredLength();
1034  }
1035 
1041  inline kt_double Distance(const Vector2& rOther) const
1042  {
1043  return sqrt(SquaredDistance(rOther));
1044  }
1045 
1046  public:
1050  inline void operator += (const Vector2& rOther)
1051  {
1052  m_Values[0] += rOther.m_Values[0];
1053  m_Values[1] += rOther.m_Values[1];
1054  }
1055 
1059  inline void operator -= (const Vector2& rOther)
1060  {
1061  m_Values[0] -= rOther.m_Values[0];
1062  m_Values[1] -= rOther.m_Values[1];
1063  }
1064 
1070  inline const Vector2 operator + (const Vector2& rOther) const
1071  {
1072  return Vector2(m_Values[0] + rOther.m_Values[0], m_Values[1] + rOther.m_Values[1]);
1073  }
1074 
1080  inline const Vector2 operator - (const Vector2& rOther) const
1081  {
1082  return Vector2(m_Values[0] - rOther.m_Values[0], m_Values[1] - rOther.m_Values[1]);
1083  }
1084 
1089  inline void operator /= (T scalar)
1090  {
1091  m_Values[0] /= scalar;
1092  m_Values[1] /= scalar;
1093  }
1094 
1100  inline const Vector2 operator / (T scalar) const
1101  {
1102  return Vector2(m_Values[0] / scalar, m_Values[1] / scalar);
1103  }
1104 
1110  inline kt_double operator * (const Vector2& rOther) const
1111  {
1112  return m_Values[0] * rOther.m_Values[0] + m_Values[1] * rOther.m_Values[1];
1113  }
1114 
1119  inline const Vector2 operator * (T scalar) const
1120  {
1121  return Vector2(m_Values[0] * scalar, m_Values[1] * scalar);
1122  }
1123 
1128  inline const Vector2 operator - (T scalar) const
1129  {
1130  return Vector2(m_Values[0] - scalar, m_Values[1] - scalar);
1131  }
1132 
1137  inline void operator *= (T scalar)
1138  {
1139  m_Values[0] *= scalar;
1140  m_Values[1] *= scalar;
1141  }
1142 
1147  inline kt_bool operator == (const Vector2& rOther) const
1148  {
1149  return (m_Values[0] == rOther.m_Values[0] && m_Values[1] == rOther.m_Values[1]);
1150  }
1151 
1156  inline kt_bool operator != (const Vector2& rOther) const
1157  {
1158  return (m_Values[0] != rOther.m_Values[0] || m_Values[1] != rOther.m_Values[1]);
1159  }
1160 
1166  inline kt_bool operator < (const Vector2& rOther) const
1167  {
1168  if (m_Values[0] < rOther.m_Values[0])
1169  return true;
1170  else if (m_Values[0] > rOther.m_Values[0])
1171  return false;
1172  else
1173  return (m_Values[1] < rOther.m_Values[1]);
1174  }
1175 
1181  friend inline std::ostream& operator << (std::ostream& rStream, const Vector2& rVector)
1182  {
1183  rStream << rVector.GetX() << " " << rVector.GetY();
1184  return rStream;
1185  }
1186 
1191  friend inline std::istream& operator >> (std::istream& rStream, const Vector2& /*rVector*/)
1192  {
1193  // Implement me!! TODO(lucbettaieb): What the what? Do I need to implement this?
1194  return rStream;
1195  }
1196 
1197  private:
1198  T m_Values[2];
1199  }; // Vector2<T>
1200 
1204  typedef std::vector< Vector2<kt_double> > PointVectorDouble;
1205 
1209 
1213  template<typename T>
1214  class Vector3
1215  {
1216  public:
1221  {
1222  m_Values[0] = 0;
1223  m_Values[1] = 0;
1224  m_Values[2] = 0;
1225  }
1226 
1233  Vector3(T x, T y, T z)
1234  {
1235  m_Values[0] = x;
1236  m_Values[1] = y;
1237  m_Values[2] = z;
1238  }
1239 
1244  Vector3(const Vector3& rOther)
1245  {
1246  m_Values[0] = rOther.m_Values[0];
1247  m_Values[1] = rOther.m_Values[1];
1248  m_Values[2] = rOther.m_Values[2];
1249  }
1250 
1251  public:
1256  inline const T& GetX() const
1257  {
1258  return m_Values[0];
1259  }
1260 
1265  inline void SetX(const T& x)
1266  {
1267  m_Values[0] = x;
1268  }
1269 
1274  inline const T& GetY() const
1275  {
1276  return m_Values[1];
1277  }
1278 
1283  inline void SetY(const T& y)
1284  {
1285  m_Values[1] = y;
1286  }
1287 
1292  inline const T& GetZ() const
1293  {
1294  return m_Values[2];
1295  }
1296 
1301  inline void SetZ(const T& z)
1302  {
1303  m_Values[2] = z;
1304  }
1305 
1310  inline void MakeFloor(const Vector3& rOther)
1311  {
1312  if (rOther.m_Values[0] < m_Values[0]) m_Values[0] = rOther.m_Values[0];
1313  if (rOther.m_Values[1] < m_Values[1]) m_Values[1] = rOther.m_Values[1];
1314  if (rOther.m_Values[2] < m_Values[2]) m_Values[2] = rOther.m_Values[2];
1315  }
1316 
1321  inline void MakeCeil(const Vector3& rOther)
1322  {
1323  if (rOther.m_Values[0] > m_Values[0]) m_Values[0] = rOther.m_Values[0];
1324  if (rOther.m_Values[1] > m_Values[1]) m_Values[1] = rOther.m_Values[1];
1325  if (rOther.m_Values[2] > m_Values[2]) m_Values[2] = rOther.m_Values[2];
1326  }
1327 
1332  inline kt_double SquaredLength() const
1333  {
1334  return math::Square(m_Values[0]) + math::Square(m_Values[1]) + math::Square(m_Values[2]);
1335  }
1336 
1341  inline kt_double Length() const
1342  {
1343  return sqrt(SquaredLength());
1344  }
1345 
1350  inline std::string ToString() const
1351  {
1352  std::stringstream converter;
1353  converter.precision(std::numeric_limits<double>::digits10);
1354 
1355  converter << GetX() << " " << GetY() << " " << GetZ();
1356 
1357  return converter.str();
1358  }
1359 
1360  public:
1364  inline Vector3& operator = (const Vector3& rOther)
1365  {
1366  m_Values[0] = rOther.m_Values[0];
1367  m_Values[1] = rOther.m_Values[1];
1368  m_Values[2] = rOther.m_Values[2];
1369 
1370  return *this;
1371  }
1372 
1378  inline const Vector3 operator + (const Vector3& rOther) const
1379  {
1380  return Vector3(m_Values[0] + rOther.m_Values[0],
1381  m_Values[1] + rOther.m_Values[1],
1382  m_Values[2] + rOther.m_Values[2]);
1383  }
1384 
1390  inline const Vector3 operator + (kt_double scalar) const
1391  {
1392  return Vector3(m_Values[0] + scalar,
1393  m_Values[1] + scalar,
1394  m_Values[2] + scalar);
1395  }
1396 
1402  inline const Vector3 operator - (const Vector3& rOther) const
1403  {
1404  return Vector3(m_Values[0] - rOther.m_Values[0],
1405  m_Values[1] - rOther.m_Values[1],
1406  m_Values[2] - rOther.m_Values[2]);
1407  }
1408 
1414  inline const Vector3 operator - (kt_double scalar) const
1415  {
1416  return Vector3(m_Values[0] - scalar, m_Values[1] - scalar, m_Values[2] - scalar);
1417  }
1418 
1423  inline const Vector3 operator * (T scalar) const
1424  {
1425  return Vector3(m_Values[0] * scalar, m_Values[1] * scalar, m_Values[2] * scalar);
1426  }
1427 
1432  inline kt_bool operator == (const Vector3& rOther) const
1433  {
1434  return (m_Values[0] == rOther.m_Values[0] &&
1435  m_Values[1] == rOther.m_Values[1] &&
1436  m_Values[2] == rOther.m_Values[2]);
1437  }
1438 
1443  inline kt_bool operator != (const Vector3& rOther) const
1444  {
1445  return (m_Values[0] != rOther.m_Values[0] ||
1446  m_Values[1] != rOther.m_Values[1] ||
1447  m_Values[2] != rOther.m_Values[2]);
1448  }
1449 
1455  friend inline std::ostream& operator << (std::ostream& rStream, const Vector3& rVector)
1456  {
1457  rStream << rVector.ToString();
1458  return rStream;
1459  }
1460 
1465  friend inline std::istream& operator >> (std::istream& rStream, const Vector3& /*rVector*/)
1466  {
1467  // Implement me!!
1468  return rStream;
1469  }
1470 
1471  private:
1472  T m_Values[3];
1473  }; // Vector3
1474 
1478 
1501  {
1502  public:
1506  inline Quaternion()
1507  {
1508  m_Values[0] = 0.0;
1509  m_Values[1] = 0.0;
1510  m_Values[2] = 0.0;
1511  m_Values[3] = 1.0;
1512  }
1513 
1522  {
1523  m_Values[0] = x;
1524  m_Values[1] = y;
1525  m_Values[2] = z;
1526  m_Values[3] = w;
1527  }
1528 
1532  inline Quaternion(const Quaternion& rQuaternion)
1533  {
1534  m_Values[0] = rQuaternion.m_Values[0];
1535  m_Values[1] = rQuaternion.m_Values[1];
1536  m_Values[2] = rQuaternion.m_Values[2];
1537  m_Values[3] = rQuaternion.m_Values[3];
1538  }
1539 
1540  public:
1545  inline kt_double GetX() const
1546  {
1547  return m_Values[0];
1548  }
1549 
1554  inline void SetX(kt_double x)
1555  {
1556  m_Values[0] = x;
1557  }
1558 
1563  inline kt_double GetY() const
1564  {
1565  return m_Values[1];
1566  }
1567 
1572  inline void SetY(kt_double y)
1573  {
1574  m_Values[1] = y;
1575  }
1576 
1581  inline kt_double GetZ() const
1582  {
1583  return m_Values[2];
1584  }
1585 
1590  inline void SetZ(kt_double z)
1591  {
1592  m_Values[2] = z;
1593  }
1594 
1599  inline kt_double GetW() const
1600  {
1601  return m_Values[3];
1602  }
1603 
1608  inline void SetW(kt_double w)
1609  {
1610  m_Values[3] = w;
1611  }
1612 
1620  void ToEulerAngles(kt_double& rYaw, kt_double& rPitch, kt_double& rRoll) const
1621  {
1622  kt_double test = m_Values[0] * m_Values[1] + m_Values[2] * m_Values[3];
1623 
1624  if (test > 0.499)
1625  {
1626  // singularity at north pole
1627  rYaw = 2 * atan2(m_Values[0], m_Values[3]);;
1628  rPitch = KT_PI_2;
1629  rRoll = 0;
1630  }
1631  else if (test < -0.499)
1632  {
1633  // singularity at south pole
1634  rYaw = -2 * atan2(m_Values[0], m_Values[3]);
1635  rPitch = -KT_PI_2;
1636  rRoll = 0;
1637  }
1638  else
1639  {
1640  kt_double sqx = m_Values[0] * m_Values[0];
1641  kt_double sqy = m_Values[1] * m_Values[1];
1642  kt_double sqz = m_Values[2] * m_Values[2];
1643 
1644  rYaw = atan2(2 * m_Values[1] * m_Values[3] - 2 * m_Values[0] * m_Values[2], 1 - 2 * sqy - 2 * sqz);
1645  rPitch = asin(2 * test);
1646  rRoll = atan2(2 * m_Values[0] * m_Values[3] - 2 * m_Values[1] * m_Values[2], 1 - 2 * sqx - 2 * sqz);
1647  }
1648  }
1649 
1658  {
1659  kt_double angle;
1660 
1661  angle = yaw * 0.5;
1662  kt_double cYaw = cos(angle);
1663  kt_double sYaw = sin(angle);
1664 
1665  angle = pitch * 0.5;
1666  kt_double cPitch = cos(angle);
1667  kt_double sPitch = sin(angle);
1668 
1669  angle = roll * 0.5;
1670  kt_double cRoll = cos(angle);
1671  kt_double sRoll = sin(angle);
1672 
1673  m_Values[0] = sYaw * sPitch * cRoll + cYaw * cPitch * sRoll;
1674  m_Values[1] = sYaw * cPitch * cRoll + cYaw * sPitch * sRoll;
1675  m_Values[2] = cYaw * sPitch * cRoll - sYaw * cPitch * sRoll;
1676  m_Values[3] = cYaw * cPitch * cRoll - sYaw * sPitch * sRoll;
1677  }
1678 
1683  inline Quaternion& operator = (const Quaternion& rQuaternion)
1684  {
1685  m_Values[0] = rQuaternion.m_Values[0];
1686  m_Values[1] = rQuaternion.m_Values[1];
1687  m_Values[2] = rQuaternion.m_Values[2];
1688  m_Values[3] = rQuaternion.m_Values[3];
1689 
1690  return(*this);
1691  }
1692 
1697  inline kt_bool operator == (const Quaternion& rOther) const
1698  {
1699  return (m_Values[0] == rOther.m_Values[0] &&
1700  m_Values[1] == rOther.m_Values[1] &&
1701  m_Values[2] == rOther.m_Values[2] &&
1702  m_Values[3] == rOther.m_Values[3]);
1703  }
1704 
1709  inline kt_bool operator != (const Quaternion& rOther) const
1710  {
1711  return (m_Values[0] != rOther.m_Values[0] ||
1712  m_Values[1] != rOther.m_Values[1] ||
1713  m_Values[2] != rOther.m_Values[2] ||
1714  m_Values[3] != rOther.m_Values[3]);
1715  }
1716 
1722  friend inline std::ostream& operator << (std::ostream& rStream, const Quaternion& rQuaternion)
1723  {
1724  rStream << rQuaternion.m_Values[0] << " "
1725  << rQuaternion.m_Values[1] << " "
1726  << rQuaternion.m_Values[2] << " "
1727  << rQuaternion.m_Values[3];
1728  return rStream;
1729  }
1730 
1731  private:
1732  kt_double m_Values[4];
1733  };
1734 
1738 
1743  template<typename T>
1745  {
1746  public:
1751  {
1752  }
1753 
1761  Rectangle2(T x, T y, T width, T height)
1762  : m_Position(x, y)
1763  , m_Size(width, height)
1764  {
1765  }
1766 
1772  Rectangle2(const Vector2<T>& rPosition, const Size2<T>& rSize)
1773  : m_Position(rPosition)
1774  , m_Size(rSize)
1775  {
1776  }
1777 
1781  Rectangle2(const Rectangle2& rOther)
1782  : m_Position(rOther.m_Position)
1783  , m_Size(rOther.m_Size)
1784  {
1785  }
1786 
1787  public:
1792  inline T GetX() const
1793  {
1794  return m_Position.GetX();
1795  }
1796 
1801  inline void SetX(T x)
1802  {
1803  m_Position.SetX(x);
1804  }
1805 
1810  inline T GetY() const
1811  {
1812  return m_Position.GetY();
1813  }
1814 
1819  inline void SetY(T y)
1820  {
1821  m_Position.SetY(y);
1822  }
1823 
1828  inline T GetWidth() const
1829  {
1830  return m_Size.GetWidth();
1831  }
1832 
1837  inline void SetWidth(T width)
1838  {
1839  m_Size.SetWidth(width);
1840  }
1841 
1846  inline T GetHeight() const
1847  {
1848  return m_Size.GetHeight();
1849  }
1850 
1855  inline void SetHeight(T height)
1856  {
1857  m_Size.SetHeight(height);
1858  }
1859 
1864  inline const Vector2<T>& GetPosition() const
1865  {
1866  return m_Position;
1867  }
1868 
1874  inline void SetPosition(const T& rX, const T& rY)
1875  {
1876  m_Position = Vector2<T>(rX, rY);
1877  }
1878 
1883  inline void SetPosition(const Vector2<T>& rPosition)
1884  {
1885  m_Position = rPosition;
1886  }
1887 
1892  inline const Size2<T>& GetSize() const
1893  {
1894  return m_Size;
1895  }
1896 
1901  inline void SetSize(const Size2<T>& rSize)
1902  {
1903  m_Size = rSize;
1904  }
1905 
1910  inline const Vector2<T> GetCenter() const
1911  {
1912  return Vector2<T>(m_Position.GetX() + m_Size.GetWidth() * 0.5, m_Position.GetY() + m_Size.GetHeight() * 0.5);
1913  }
1914 
1915  public:
1919  Rectangle2& operator = (const Rectangle2& rOther)
1920  {
1921  m_Position = rOther.m_Position;
1922  m_Size = rOther.m_Size;
1923 
1924  return *this;
1925  }
1926 
1930  inline kt_bool operator == (const Rectangle2& rOther) const
1931  {
1932  return (m_Position == rOther.m_Position && m_Size == rOther.m_Size);
1933  }
1934 
1938  inline kt_bool operator != (const Rectangle2& rOther) const
1939  {
1940  return (m_Position != rOther.m_Position || m_Size != rOther.m_Size);
1941  }
1942 
1943  private:
1946  }; // Rectangle2
1947 
1951 
1952  class Pose3;
1953 
1957  class Pose2
1958  {
1959  public:
1964  : m_Heading(0.0)
1965  {
1966  }
1967 
1973  Pose2(const Vector2<kt_double>& rPosition, kt_double heading)
1974  : m_Position(rPosition)
1975  , m_Heading(heading)
1976  {
1977  }
1978 
1986  : m_Position(x, y)
1987  , m_Heading(heading)
1988  {
1989  }
1990 
1994  Pose2(const Pose3& rPose);
1995 
1999  Pose2(const Pose2& rOther)
2000  : m_Position(rOther.m_Position)
2001  , m_Heading(rOther.m_Heading)
2002  {
2003  }
2004 
2005  public:
2010  inline kt_double GetX() const
2011  {
2012  return m_Position.GetX();
2013  }
2014 
2019  inline void SetX(kt_double x)
2020  {
2021  m_Position.SetX(x);
2022  }
2023 
2028  inline kt_double GetY() const
2029  {
2030  return m_Position.GetY();
2031  }
2032 
2037  inline void SetY(kt_double y)
2038  {
2039  m_Position.SetY(y);
2040  }
2041 
2046  inline const Vector2<kt_double>& GetPosition() const
2047  {
2048  return m_Position;
2049  }
2050 
2055  inline void SetPosition(const Vector2<kt_double>& rPosition)
2056  {
2057  m_Position = rPosition;
2058  }
2059 
2064  inline kt_double GetHeading() const
2065  {
2066  return m_Heading;
2067  }
2068 
2073  inline void SetHeading(kt_double heading)
2074  {
2075  m_Heading = heading;
2076  }
2077 
2082  inline kt_double SquaredDistance(const Pose2& rOther) const
2083  {
2084  return m_Position.SquaredDistance(rOther.m_Position);
2085  }
2086 
2087  public:
2091  inline Pose2& operator = (const Pose2& rOther)
2092  {
2093  m_Position = rOther.m_Position;
2094  m_Heading = rOther.m_Heading;
2095 
2096  return *this;
2097  }
2098 
2102  inline kt_bool operator == (const Pose2& rOther) const
2103  {
2104  return (m_Position == rOther.m_Position && m_Heading == rOther.m_Heading);
2105  }
2106 
2110  inline kt_bool operator != (const Pose2& rOther) const
2111  {
2112  return (m_Position != rOther.m_Position || m_Heading != rOther.m_Heading);
2113  }
2114 
2118  inline void operator += (const Pose2& rOther)
2119  {
2120  m_Position += rOther.m_Position;
2121  m_Heading = math::NormalizeAngle(m_Heading + rOther.m_Heading);
2122  }
2123 
2129  inline Pose2 operator + (const Pose2& rOther) const
2130  {
2131  return Pose2(m_Position + rOther.m_Position, math::NormalizeAngle(m_Heading + rOther.m_Heading));
2132  }
2133 
2139  inline Pose2 operator - (const Pose2& rOther) const
2140  {
2141  return Pose2(m_Position - rOther.m_Position, math::NormalizeAngle(m_Heading - rOther.m_Heading));
2142  }
2143 
2148  friend inline std::istream& operator >> (std::istream& rStream, const Pose2& /*rPose*/)
2149  {
2150  // Implement me!!
2151  return rStream;
2152  }
2153 
2159  friend inline std::ostream& operator << (std::ostream& rStream, const Pose2& rPose)
2160  {
2161  rStream << rPose.m_Position.GetX() << " " << rPose.m_Position.GetY() << " " << rPose.m_Heading;
2162  return rStream;
2163  }
2164 
2165  private:
2167 
2169  }; // Pose2
2170 
2174  typedef std::vector< Pose2 > Pose2Vector;
2175 
2179 
2187  class Pose3
2188  {
2189  public:
2194  {
2195  }
2196 
2201  Pose3(const Vector3<kt_double>& rPosition)
2202  : m_Position(rPosition)
2203  {
2204  }
2205 
2211  Pose3(const Vector3<kt_double>& rPosition, const karto::Quaternion& rOrientation)
2212  : m_Position(rPosition)
2213  , m_Orientation(rOrientation)
2214  {
2215  }
2216 
2220  Pose3(const Pose3& rOther)
2221  : m_Position(rOther.m_Position)
2222  , m_Orientation(rOther.m_Orientation)
2223  {
2224  }
2225 
2229  Pose3(const Pose2& rPose)
2230  {
2231  m_Position = Vector3<kt_double>(rPose.GetX(), rPose.GetY(), 0.0);
2232  m_Orientation.FromEulerAngles(rPose.GetHeading(), 0.0, 0.0);
2233  }
2234 
2235  public:
2240  inline const Vector3<kt_double>& GetPosition() const
2241  {
2242  return m_Position;
2243  }
2244 
2249  inline void SetPosition(const Vector3<kt_double>& rPosition)
2250  {
2251  m_Position = rPosition;
2252  }
2253 
2258  inline const Quaternion& GetOrientation() const
2259  {
2260  return m_Orientation;
2261  }
2262 
2267  inline void SetOrientation(const Quaternion& rOrientation)
2268  {
2269  m_Orientation = rOrientation;
2270  }
2271 
2276  inline std::string ToString()
2277  {
2278  std::stringstream converter;
2279  converter.precision(std::numeric_limits<double>::digits10);
2280 
2281  converter << GetPosition() << " " << GetOrientation();
2282 
2283  return converter.str();
2284  }
2285 
2286  public:
2290  inline Pose3& operator = (const Pose3& rOther)
2291  {
2292  m_Position = rOther.m_Position;
2293  m_Orientation = rOther.m_Orientation;
2294 
2295  return *this;
2296  }
2297 
2301  inline kt_bool operator == (const Pose3& rOther) const
2302  {
2303  return (m_Position == rOther.m_Position && m_Orientation == rOther.m_Orientation);
2304  }
2305 
2309  inline kt_bool operator != (const Pose3& rOther) const
2310  {
2311  return (m_Position != rOther.m_Position || m_Orientation != rOther.m_Orientation);
2312  }
2313 
2319  friend inline std::ostream& operator << (std::ostream& rStream, const Pose3& rPose)
2320  {
2321  rStream << rPose.GetPosition() << ", " << rPose.GetOrientation();
2322  return rStream;
2323  }
2324 
2329  friend inline std::istream& operator >> (std::istream& rStream, const Pose3& /*rPose*/)
2330  {
2331  // Implement me!!
2332  return rStream;
2333  }
2334 
2335  private:
2338  }; // Pose3
2339 
2343 
2347  class Matrix3
2348  {
2349  public:
2354  {
2355  Clear();
2356  }
2357 
2361  inline Matrix3(const Matrix3& rOther)
2362  {
2363  memcpy(m_Matrix, rOther.m_Matrix, 9*sizeof(kt_double));
2364  }
2365 
2366  public:
2371  {
2372  memset(m_Matrix, 0, 9*sizeof(kt_double));
2373 
2374  for (kt_int32s i = 0; i < 3; i++)
2375  {
2376  m_Matrix[i][i] = 1.0;
2377  }
2378  }
2379 
2383  void Clear()
2384  {
2385  memset(m_Matrix, 0, 9*sizeof(kt_double));
2386  }
2387 
2395  void FromAxisAngle(kt_double x, kt_double y, kt_double z, const kt_double radians)
2396  {
2397  kt_double cosRadians = cos(radians);
2398  kt_double sinRadians = sin(radians);
2399  kt_double oneMinusCos = 1.0 - cosRadians;
2400 
2401  kt_double xx = x * x;
2402  kt_double yy = y * y;
2403  kt_double zz = z * z;
2404 
2405  kt_double xyMCos = x * y * oneMinusCos;
2406  kt_double xzMCos = x * z * oneMinusCos;
2407  kt_double yzMCos = y * z * oneMinusCos;
2408 
2409  kt_double xSin = x * sinRadians;
2410  kt_double ySin = y * sinRadians;
2411  kt_double zSin = z * sinRadians;
2412 
2413  m_Matrix[0][0] = xx * oneMinusCos + cosRadians;
2414  m_Matrix[0][1] = xyMCos - zSin;
2415  m_Matrix[0][2] = xzMCos + ySin;
2416 
2417  m_Matrix[1][0] = xyMCos + zSin;
2418  m_Matrix[1][1] = yy * oneMinusCos + cosRadians;
2419  m_Matrix[1][2] = yzMCos - xSin;
2420 
2421  m_Matrix[2][0] = xzMCos - ySin;
2422  m_Matrix[2][1] = yzMCos + xSin;
2423  m_Matrix[2][2] = zz * oneMinusCos + cosRadians;
2424  }
2425 
2431  {
2432  Matrix3 transpose;
2433 
2434  for (kt_int32u row = 0; row < 3; row++)
2435  {
2436  for (kt_int32u col = 0; col < 3; col++)
2437  {
2438  transpose.m_Matrix[row][col] = m_Matrix[col][row];
2439  }
2440  }
2441 
2442  return transpose;
2443  }
2444 
2449  {
2450  Matrix3 kInverse = *this;
2451  kt_bool haveInverse = InverseFast(kInverse, 1e-14);
2452  if (haveInverse == false)
2453  {
2454  assert(false);
2455  }
2456  return kInverse;
2457  }
2458 
2463  kt_bool InverseFast(Matrix3& rkInverse, kt_double fTolerance = KT_TOLERANCE) const
2464  {
2465  // Invert a 3x3 using cofactors. This is about 8 times faster than
2466  // the Numerical Recipes code which uses Gaussian elimination.
2467  rkInverse.m_Matrix[0][0] = m_Matrix[1][1]*m_Matrix[2][2] - m_Matrix[1][2]*m_Matrix[2][1];
2468  rkInverse.m_Matrix[0][1] = m_Matrix[0][2]*m_Matrix[2][1] - m_Matrix[0][1]*m_Matrix[2][2];
2469  rkInverse.m_Matrix[0][2] = m_Matrix[0][1]*m_Matrix[1][2] - m_Matrix[0][2]*m_Matrix[1][1];
2470  rkInverse.m_Matrix[1][0] = m_Matrix[1][2]*m_Matrix[2][0] - m_Matrix[1][0]*m_Matrix[2][2];
2471  rkInverse.m_Matrix[1][1] = m_Matrix[0][0]*m_Matrix[2][2] - m_Matrix[0][2]*m_Matrix[2][0];
2472  rkInverse.m_Matrix[1][2] = m_Matrix[0][2]*m_Matrix[1][0] - m_Matrix[0][0]*m_Matrix[1][2];
2473  rkInverse.m_Matrix[2][0] = m_Matrix[1][0]*m_Matrix[2][1] - m_Matrix[1][1]*m_Matrix[2][0];
2474  rkInverse.m_Matrix[2][1] = m_Matrix[0][1]*m_Matrix[2][0] - m_Matrix[0][0]*m_Matrix[2][1];
2475  rkInverse.m_Matrix[2][2] = m_Matrix[0][0]*m_Matrix[1][1] - m_Matrix[0][1]*m_Matrix[1][0];
2476 
2477  kt_double fDet = m_Matrix[0][0]*rkInverse.m_Matrix[0][0] +
2478  m_Matrix[0][1]*rkInverse.m_Matrix[1][0] +
2479  m_Matrix[0][2]*rkInverse.m_Matrix[2][0];
2480 
2481  if (fabs(fDet) <= fTolerance)
2482  {
2483  return false;
2484  }
2485 
2486  kt_double fInvDet = 1.0/fDet;
2487  for (size_t row = 0; row < 3; row++)
2488  {
2489  for (size_t col = 0; col < 3; col++)
2490  {
2491  rkInverse.m_Matrix[row][col] *= fInvDet;
2492  }
2493  }
2494 
2495  return true;
2496  }
2497 
2502  inline std::string ToString() const
2503  {
2504  std::stringstream converter;
2505  converter.precision(std::numeric_limits<double>::digits10);
2506 
2507  for (int row = 0; row < 3; row++)
2508  {
2509  for (int col = 0; col < 3; col++)
2510  {
2511  converter << m_Matrix[row][col] << " ";
2512  }
2513  }
2514 
2515  return converter.str();
2516  }
2517 
2518  public:
2522  inline Matrix3& operator = (const Matrix3& rOther)
2523  {
2524  memcpy(m_Matrix, rOther.m_Matrix, 9*sizeof(kt_double));
2525  return *this;
2526  }
2527 
2535  {
2536  return m_Matrix[row][column];
2537  }
2538 
2545  inline kt_double operator()(kt_int32u row, kt_int32u column) const
2546  {
2547  return m_Matrix[row][column];
2548  }
2549 
2555  Matrix3 operator * (const Matrix3& rOther) const
2556  {
2557  Matrix3 product;
2558 
2559  for (size_t row = 0; row < 3; row++)
2560  {
2561  for (size_t col = 0; col < 3; col++)
2562  {
2563  product.m_Matrix[row][col] = m_Matrix[row][0]*rOther.m_Matrix[0][col] +
2564  m_Matrix[row][1]*rOther.m_Matrix[1][col] +
2565  m_Matrix[row][2]*rOther.m_Matrix[2][col];
2566  }
2567  }
2568 
2569  return product;
2570  }
2571 
2577  inline Pose2 operator * (const Pose2& rPose2) const
2578  {
2579  Pose2 pose2;
2580 
2581  pose2.SetX(m_Matrix[0][0] * rPose2.GetX() + m_Matrix[0][1] *
2582  rPose2.GetY() + m_Matrix[0][2] * rPose2.GetHeading());
2583  pose2.SetY(m_Matrix[1][0] * rPose2.GetX() + m_Matrix[1][1] *
2584  rPose2.GetY() + m_Matrix[1][2] * rPose2.GetHeading());
2585  pose2.SetHeading(m_Matrix[2][0] * rPose2.GetX() + m_Matrix[2][1] *
2586  rPose2.GetY() + m_Matrix[2][2] * rPose2.GetHeading());
2587 
2588  return pose2;
2589  }
2590 
2595  inline void operator += (const Matrix3& rkMatrix)
2596  {
2597  for (kt_int32u row = 0; row < 3; row++)
2598  {
2599  for (kt_int32u col = 0; col < 3; col++)
2600  {
2601  m_Matrix[row][col] += rkMatrix.m_Matrix[row][col];
2602  }
2603  }
2604  }
2605 
2611  friend inline std::ostream& operator << (std::ostream& rStream, const Matrix3& rMatrix)
2612  {
2613  rStream << rMatrix.ToString();
2614  return rStream;
2615  }
2616 
2617  private:
2618  kt_double m_Matrix[3][3];
2619  }; // Matrix3
2620 
2624 
2628  class Matrix
2629  {
2630  public:
2634  Matrix(kt_int32u rows, kt_int32u columns)
2635  : m_Rows(rows)
2636  , m_Columns(columns)
2637  , m_pData(NULL)
2638  {
2639  Allocate();
2640 
2641  Clear();
2642  }
2643 
2647  virtual ~Matrix()
2648  {
2649  delete [] m_pData;
2650  }
2651 
2652  public:
2656  void Clear()
2657  {
2658  if (m_pData != NULL)
2659  {
2660  memset(m_pData, 0, sizeof(kt_double) * m_Rows * m_Columns);
2661  }
2662  }
2663 
2668  inline kt_int32u GetRows() const
2669  {
2670  return m_Rows;
2671  }
2672 
2677  inline kt_int32u GetColumns() const
2678  {
2679  return m_Columns;
2680  }
2681 
2689  {
2690  RangeCheck(row, column);
2691 
2692  return m_pData[row + column * m_Rows];
2693  }
2694 
2701  inline const kt_double& operator()(kt_int32u row, kt_int32u column) const
2702  {
2703  RangeCheck(row, column);
2704 
2705  return m_pData[row + column * m_Rows];
2706  }
2707 
2708  private:
2712  void Allocate()
2713  {
2714  try
2715  {
2716  if (m_pData != NULL)
2717  {
2718  delete[] m_pData;
2719  }
2720 
2721  m_pData = new kt_double[m_Rows * m_Columns];
2722  }
2723  catch (const std::bad_alloc& ex)
2724  {
2725  throw Exception("Matrix allocation error");
2726  }
2727 
2728  if (m_pData == NULL)
2729  {
2730  throw Exception("Matrix allocation error");
2731  }
2732  }
2733 
2739  inline void RangeCheck(kt_int32u row, kt_int32u column) const
2740  {
2741  if (math::IsUpTo(row, m_Rows) == false)
2742  {
2743  throw Exception("Matrix - RangeCheck ERROR!!!!");
2744  }
2745 
2746  if (math::IsUpTo(column, m_Columns) == false)
2747  {
2748  throw Exception("Matrix - RangeCheck ERROR!!!!");
2749  }
2750  }
2751 
2752  private:
2755 
2757  }; // Matrix
2758 
2762 
2767  {
2768  public:
2769  /*
2770  * Default constructor
2771  */
2773  : m_Minimum(999999999999999999.99999, 999999999999999999.99999)
2774  , m_Maximum(-999999999999999999.99999, -999999999999999999.99999)
2775  {
2776  }
2777 
2778  public:
2782  inline const Vector2<kt_double>& GetMinimum() const
2783  {
2784  return m_Minimum;
2785  }
2786 
2790  inline void SetMinimum(const Vector2<kt_double>& mMinimum)
2791  {
2792  m_Minimum = mMinimum;
2793  }
2794 
2798  inline const Vector2<kt_double>& GetMaximum() const
2799  {
2800  return m_Maximum;
2801  }
2802 
2806  inline void SetMaximum(const Vector2<kt_double>& rMaximum)
2807  {
2808  m_Maximum = rMaximum;
2809  }
2810 
2814  inline Size2<kt_double> GetSize() const
2815  {
2816  Vector2<kt_double> size = m_Maximum - m_Minimum;
2817 
2818  return Size2<kt_double>(size.GetX(), size.GetY());
2819  }
2820 
2824  inline void Add(const Vector2<kt_double>& rPoint)
2825  {
2826  m_Minimum.MakeFloor(rPoint);
2827  m_Maximum.MakeCeil(rPoint);
2828  }
2829 
2833  inline void Add(const BoundingBox2& rBoundingBox)
2834  {
2835  Add(rBoundingBox.GetMinimum());
2836  Add(rBoundingBox.GetMaximum());
2837  }
2838 
2844  inline kt_bool IsInBounds(const Vector2<kt_double>& rPoint) const
2845  {
2846  return (math::InRange(rPoint.GetX(), m_Minimum.GetX(), m_Maximum.GetX()) &&
2847  math::InRange(rPoint.GetY(), m_Minimum.GetY(), m_Maximum.GetY()));
2848  }
2849 
2850  private:
2853  }; // BoundingBox2
2854 
2858 
2863  {
2864  public:
2869  Transform(const Pose2& rPose)
2870  {
2871  SetTransform(Pose2(), rPose);
2872  }
2873 
2879  Transform(const Pose2& rPose1, const Pose2& rPose2)
2880  {
2881  SetTransform(rPose1, rPose2);
2882  }
2883 
2884  public:
2890  inline Pose2 TransformPose(const Pose2& rSourcePose)
2891  {
2892  Pose2 newPosition = m_Transform + m_Rotation * rSourcePose;
2893  kt_double angle = math::NormalizeAngle(rSourcePose.GetHeading() + m_Transform.GetHeading());
2894 
2895  return Pose2(newPosition.GetPosition(), angle);
2896  }
2897 
2903  inline Pose2 InverseTransformPose(const Pose2& rSourcePose)
2904  {
2905  Pose2 newPosition = m_InverseRotation * (rSourcePose - m_Transform);
2906  kt_double angle = math::NormalizeAngle(rSourcePose.GetHeading() - m_Transform.GetHeading());
2907 
2908  // components of transform
2909  return Pose2(newPosition.GetPosition(), angle);
2910  }
2911 
2912  private:
2918  void SetTransform(const Pose2& rPose1, const Pose2& rPose2)
2919  {
2920  if (rPose1 == rPose2)
2921  {
2922  m_Rotation.SetToIdentity();
2923  m_InverseRotation.SetToIdentity();
2924  m_Transform = Pose2();
2925  return;
2926  }
2927 
2928  // heading transformation
2929  m_Rotation.FromAxisAngle(0, 0, 1, rPose2.GetHeading() - rPose1.GetHeading());
2930  m_InverseRotation.FromAxisAngle(0, 0, 1, rPose1.GetHeading() - rPose2.GetHeading());
2931 
2932  // position transformation
2933  Pose2 newPosition;
2934  if (rPose1.GetX() != 0.0 || rPose1.GetY() != 0.0)
2935  {
2936  newPosition = rPose2 - m_Rotation * rPose1;
2937  }
2938  else
2939  {
2940  newPosition = rPose2;
2941  }
2942 
2943  m_Transform = Pose2(newPosition.GetPosition(), rPose2.GetHeading() - rPose1.GetHeading());
2944  }
2945 
2946  private:
2947  // pose transformation
2949 
2952  }; // Transform
2953 
2957 
2961  typedef enum
2962  {
2964 
2968 
2972 
2976 
2981  {
2982  public:
2988  AbstractParameter(const std::string& rName, ParameterManager* pParameterManger = NULL)
2989  : m_Name(rName)
2990  {
2991  // if parameter manager is provided add myself to it!
2992  if (pParameterManger != NULL)
2993  {
2994  pParameterManger->Add(this);
2995  }
2996  }
2997 
3004  AbstractParameter(const std::string& rName,
3005  const std::string& rDescription,
3006  ParameterManager* pParameterManger = NULL)
3007  : m_Name(rName)
3008  , m_Description(rDescription)
3009  {
3010  // if parameter manager is provided add myself to it!
3011  if (pParameterManger != NULL)
3012  {
3013  pParameterManger->Add(this);
3014  }
3015  }
3016 
3021  {
3022  }
3023 
3024  public:
3029  inline const std::string& GetName() const
3030  {
3031  return m_Name;
3032  }
3033 
3038  inline const std::string& GetDescription() const
3039  {
3040  return m_Description;
3041  }
3042 
3047  virtual const std::string GetValueAsString() const = 0;
3048 
3053  virtual void SetValueFromString(const std::string& rStringValue) = 0;
3054 
3059  virtual AbstractParameter* Clone() = 0;
3060 
3061  public:
3067  friend std::ostream& operator << (std::ostream& rStream, const AbstractParameter& rParameter)
3068  {
3069  rStream.precision(6);
3070  rStream.flags(std::ios::fixed);
3071 
3072  rStream << rParameter.GetName() << " = " << rParameter.GetValueAsString();
3073  return rStream;
3074  }
3075 
3076  private:
3077  std::string m_Name;
3078  std::string m_Description;
3079  }; // AbstractParameter
3080 
3084 
3088  template<typename T>
3090  {
3091  public:
3098  Parameter(const std::string& rName, T value, ParameterManager* pParameterManger = NULL)
3099  : AbstractParameter(rName, pParameterManger)
3100  , m_Value(value)
3101  {
3102  }
3103 
3111  Parameter(const std::string& rName,
3112  const std::string& rDescription,
3113  T value,
3114  ParameterManager* pParameterManger = NULL)
3115  : AbstractParameter(rName, rDescription, pParameterManger)
3116  , m_Value(value)
3117  {
3118  }
3119 
3123  virtual ~Parameter()
3124  {
3125  }
3126 
3127  public:
3132  inline const T& GetValue() const
3133  {
3134  return m_Value;
3135  }
3136 
3141  inline void SetValue(const T& rValue)
3142  {
3143  m_Value = rValue;
3144  }
3145 
3150  virtual const std::string GetValueAsString() const
3151  {
3152  std::stringstream converter;
3153  converter << m_Value;
3154  return converter.str();
3155  }
3156 
3161  virtual void SetValueFromString(const std::string& rStringValue)
3162  {
3163  std::stringstream converter;
3164  converter.str(rStringValue);
3165  converter >> m_Value;
3166  }
3167 
3172  virtual Parameter* Clone()
3173  {
3174  return new Parameter(GetName(), GetDescription(), GetValue());
3175  }
3176 
3177  public:
3181  Parameter& operator = (const Parameter& rOther)
3182  {
3183  m_Value = rOther.m_Value;
3184 
3185  return *this;
3186  }
3187 
3191  T operator = (T value)
3192  {
3193  m_Value = value;
3194 
3195  return m_Value;
3196  }
3197 
3198  protected:
3203  }; // Parameter
3204 
3205  template<>
3206  inline void Parameter<kt_double>::SetValueFromString(const std::string& rStringValue)
3207  {
3208  int precision = std::numeric_limits<double>::digits10;
3209  std::stringstream converter;
3210  converter.precision(precision);
3211 
3212  converter.str(rStringValue);
3213 
3214  m_Value = 0.0;
3215  converter >> m_Value;
3216  }
3217 
3218  template<>
3219  inline const std::string Parameter<kt_double>::GetValueAsString() const
3220  {
3221  std::stringstream converter;
3222  converter.precision(std::numeric_limits<double>::digits10);
3223  converter << m_Value;
3224  return converter.str();
3225  }
3226 
3227  template<>
3228  inline void Parameter<kt_bool>::SetValueFromString(const std::string& rStringValue)
3229  {
3230  if (rStringValue == "true" || rStringValue == "TRUE")
3231  {
3232  m_Value = true;
3233  }
3234  else
3235  {
3236  m_Value = false;
3237  }
3238  }
3239 
3240  template<>
3241  inline const std::string Parameter<kt_bool>::GetValueAsString() const
3242  {
3243  if (m_Value == true)
3244  {
3245  return "true";
3246  }
3247 
3248  return "false";
3249  }
3250 
3254 
3258  class ParameterEnum : public Parameter<kt_int32s>
3259  {
3260  typedef std::map<std::string, kt_int32s> EnumMap;
3261 
3262  public:
3269  ParameterEnum(const std::string& rName, kt_int32s value, ParameterManager* pParameterManger = NULL)
3270  : Parameter<kt_int32s>(rName, value, pParameterManger)
3271  {
3272  }
3273 
3277  virtual ~ParameterEnum()
3278  {
3279  }
3280 
3281  public:
3287  {
3288  ParameterEnum* pEnum = new ParameterEnum(GetName(), GetValue());
3289 
3290  pEnum->m_EnumDefines = m_EnumDefines;
3291 
3292  return pEnum;
3293  }
3294 
3299  virtual void SetValueFromString(const std::string& rStringValue)
3300  {
3301  if (m_EnumDefines.find(rStringValue) != m_EnumDefines.end())
3302  {
3303  m_Value = m_EnumDefines[rStringValue];
3304  }
3305  else
3306  {
3307  std::string validValues;
3308 
3309  const_forEach(EnumMap, &m_EnumDefines)
3310  {
3311  validValues += iter->first + ", ";
3312  }
3313 
3314  throw Exception("Unable to set enum: " + rStringValue + ". Valid values are: " + validValues);
3315  }
3316  }
3317 
3322  virtual const std::string GetValueAsString() const
3323  {
3324  const_forEach(EnumMap, &m_EnumDefines)
3325  {
3326  if (iter->second == m_Value)
3327  {
3328  return iter->first;
3329  }
3330  }
3331 
3332  throw Exception("Unable to lookup enum");
3333  }
3334 
3340  void DefineEnumValue(kt_int32s value, const std::string& rName)
3341  {
3342  if (m_EnumDefines.find(rName) == m_EnumDefines.end())
3343  {
3344  m_EnumDefines[rName] = value;
3345  }
3346  else
3347  {
3348  std::cerr << "Overriding enum value: " << m_EnumDefines[rName] << " with " << value << std::endl;
3349 
3350  m_EnumDefines[rName] = value;
3351 
3352  assert(false);
3353  }
3354  }
3355 
3356  public:
3360  ParameterEnum& operator = (const ParameterEnum& rOther)
3361  {
3362  SetValue(rOther.GetValue());
3363 
3364  return *this;
3365  }
3366 
3370  kt_int32s operator = (kt_int32s value)
3371  {
3372  SetValue(value);
3373 
3374  return m_Value;
3375  }
3376 
3377  private:
3378  EnumMap m_EnumDefines;
3379  }; // ParameterEnum
3380 
3384 
3388  class Parameters : public Object
3389  {
3390  public:
3391  // @cond EXCLUDE
3393  // @endcond
3394 
3395  public:
3400  Parameters(const std::string& rName)
3401  : Object(rName)
3402  {
3403  }
3404 
3408  virtual ~Parameters()
3409  {
3410  }
3411 
3412  private:
3413  Parameters(const Parameters&);
3414  const Parameters& operator=(const Parameters&);
3415  }; // Parameters
3416 
3420 
3421  class SensorData;
3422 
3426  class KARTO_EXPORT Sensor : public Object
3427  {
3428  public:
3429  // @cond EXCLUDE
3431  // @endcond
3432 
3433  protected:
3438  Sensor(const Name& rName);
3439 
3440  public:
3444  virtual ~Sensor();
3445 
3446  public:
3451  inline const Pose2& GetOffsetPose() const
3452  {
3453  return m_pOffsetPose->GetValue();
3454  }
3455 
3460  inline void SetOffsetPose(const Pose2& rPose)
3461  {
3462  m_pOffsetPose->SetValue(rPose);
3463  }
3464 
3469  virtual kt_bool Validate() = 0;
3470 
3476  virtual kt_bool Validate(SensorData* pSensorData) = 0;
3477 
3478  private:
3482  Sensor(const Sensor&);
3483 
3487  const Sensor& operator=(const Sensor&);
3488 
3489  private:
3494  }; // Sensor
3495 
3499  typedef std::vector<Sensor*> SensorVector;
3500 
3504 
3508  typedef std::map<Name, Sensor*> SensorManagerMap;
3509 
3514  {
3515  public:
3520  {
3521  }
3522 
3526  virtual ~SensorManager()
3527  {
3528  }
3529 
3530  public:
3534  static SensorManager* GetInstance();
3535 
3536  public:
3544  void RegisterSensor(Sensor* pSensor, kt_bool override = false)
3545  {
3546  Validate(pSensor);
3547 
3548  if ((m_Sensors.find(pSensor->GetName()) != m_Sensors.end()) && !override)
3549  {
3550  throw Exception("Cannot register sensor: already registered: [" +
3551  pSensor->GetName().ToString() +
3552  "] (Consider setting 'override' to true)");
3553  }
3554 
3555  std::cout << "Registering sensor: [" << pSensor->GetName().ToString() << "]" << std::endl;
3556 
3557  m_Sensors[pSensor->GetName()] = pSensor;
3558  }
3559 
3564  void UnregisterSensor(Sensor* pSensor)
3565  {
3566  Validate(pSensor);
3567 
3568  if (m_Sensors.find(pSensor->GetName()) != m_Sensors.end())
3569  {
3570  std::cout << "Unregistering sensor: " << pSensor->GetName().ToString() << std::endl;
3571 
3572  m_Sensors.erase(pSensor->GetName());
3573  }
3574  else
3575  {
3576  throw Exception("Cannot unregister sensor: not registered: [" + pSensor->GetName().ToString() + "]");
3577  }
3578  }
3579 
3585  Sensor* GetSensorByName(const Name& rName)
3586  {
3587  if (m_Sensors.find(rName) != m_Sensors.end())
3588  {
3589  return m_Sensors[rName];
3590  }
3591 
3592  throw Exception("Sensor not registered: [" + rName.ToString() + "] (Did you add the sensor to the Dataset?)");
3593  }
3594 
3600  template<class T>
3601  T* GetSensorByName(const Name& rName)
3602  {
3603  Sensor* pSensor = GetSensorByName(rName);
3604 
3605  return dynamic_cast<T*>(pSensor);
3606  }
3607 
3612  SensorVector GetAllSensors()
3613  {
3614  SensorVector sensors;
3615 
3616  forEach(SensorManagerMap, &m_Sensors)
3617  {
3618  sensors.push_back(iter->second);
3619  }
3620 
3621  return sensors;
3622  }
3623 
3624  protected:
3629  static void Validate(Sensor* pSensor)
3630  {
3631  if (pSensor == NULL)
3632  {
3633  throw Exception("Invalid sensor: NULL");
3634  }
3635  else if (pSensor->GetName().ToString() == "")
3636  {
3637  throw Exception("Invalid sensor: nameless");
3638  }
3639  }
3640 
3641  protected:
3645  SensorManagerMap m_Sensors;
3646  };
3647 
3651 
3658  class Drive : public Sensor
3659  {
3660  public:
3661  // @cond EXCLUDE
3663  // @endcond
3664 
3665  public:
3669  Drive(const std::string& rName)
3670  : Sensor(rName)
3671  {
3672  }
3673 
3677  virtual ~Drive()
3678  {
3679  }
3680 
3681  public:
3682  virtual kt_bool Validate()
3683  {
3684  return true;
3685  }
3686 
3687  virtual kt_bool Validate(SensorData* pSensorData)
3688  {
3689  if (pSensorData == NULL)
3690  {
3691  return false;
3692  }
3693 
3694  return true;
3695  }
3696 
3697  private:
3698  Drive(const Drive&);
3699  const Drive& operator=(const Drive&);
3700  }; // class Drive
3701 
3705 
3706  class LocalizedRangeScan;
3707  class CoordinateConverter;
3708 
3722  {
3723  public:
3724  // @cond EXCLUDE
3726  // @endcond
3727 
3728  public:
3733  {
3734  }
3735 
3736  public:
3742  {
3743  return m_pMinimumRange->GetValue();
3744  }
3745 
3750  inline void SetMinimumRange(kt_double minimumRange)
3751  {
3752  m_pMinimumRange->SetValue(minimumRange);
3753 
3754  SetRangeThreshold(GetRangeThreshold());
3755  }
3756 
3762  {
3763  return m_pMaximumRange->GetValue();
3764  }
3765 
3770  inline void SetMaximumRange(kt_double maximumRange)
3771  {
3772  m_pMaximumRange->SetValue(maximumRange);
3773 
3774  SetRangeThreshold(GetRangeThreshold());
3775  }
3776 
3782  {
3783  return m_pRangeThreshold->GetValue();
3784  }
3785 
3790  inline void SetRangeThreshold(kt_double rangeThreshold)
3791  {
3792  // make sure rangeThreshold is within laser range finder range
3793  m_pRangeThreshold->SetValue(math::Clip(rangeThreshold, GetMinimumRange(), GetMaximumRange()));
3794 
3795  if (math::DoubleEqual(GetRangeThreshold(), rangeThreshold) == false)
3796  {
3797  std::cout << "Info: clipped range threshold to be within minimum and maximum range!" << std::endl;
3798  }
3799  }
3800 
3806  {
3807  return m_pMinimumAngle->GetValue();
3808  }
3809 
3814  inline void SetMinimumAngle(kt_double minimumAngle)
3815  {
3816  m_pMinimumAngle->SetValue(minimumAngle);
3817 
3818  Update();
3819  }
3820 
3826  {
3827  return m_pMaximumAngle->GetValue();
3828  }
3829 
3834  inline void SetMaximumAngle(kt_double maximumAngle)
3835  {
3836  m_pMaximumAngle->SetValue(maximumAngle);
3837 
3838  Update();
3839  }
3840 
3846  {
3847  return m_pAngularResolution->GetValue();
3848  }
3849 
3854  inline void SetAngularResolution(kt_double angularResolution)
3855  {
3856  if (m_pType->GetValue() == LaserRangeFinder_Custom)
3857  {
3858  m_pAngularResolution->SetValue(angularResolution);
3859  }
3860  else if (m_pType->GetValue() == LaserRangeFinder_Sick_LMS100)
3861  {
3862  if (math::DoubleEqual(angularResolution, math::DegreesToRadians(0.25)))
3863  {
3864  m_pAngularResolution->SetValue(math::DegreesToRadians(0.25));
3865  }
3866  else if (math::DoubleEqual(angularResolution, math::DegreesToRadians(0.50)))
3867  {
3868  m_pAngularResolution->SetValue(math::DegreesToRadians(0.50));
3869  }
3870  else
3871  {
3872  std::stringstream stream;
3873  stream << "Invalid resolution for Sick LMS100: ";
3874  stream << angularResolution;
3875  throw Exception(stream.str());
3876  }
3877  }
3878  else if (m_pType->GetValue() == LaserRangeFinder_Sick_LMS200 ||
3879  m_pType->GetValue() == LaserRangeFinder_Sick_LMS291)
3880  {
3881  if (math::DoubleEqual(angularResolution, math::DegreesToRadians(0.25)))
3882  {
3883  m_pAngularResolution->SetValue(math::DegreesToRadians(0.25));
3884  }
3885  else if (math::DoubleEqual(angularResolution, math::DegreesToRadians(0.50)))
3886  {
3887  m_pAngularResolution->SetValue(math::DegreesToRadians(0.50));
3888  }
3889  else if (math::DoubleEqual(angularResolution, math::DegreesToRadians(1.00)))
3890  {
3891  m_pAngularResolution->SetValue(math::DegreesToRadians(1.00));
3892  }
3893  else
3894  {
3895  std::stringstream stream;
3896  stream << "Invalid resolution for Sick LMS291: ";
3897  stream << angularResolution;
3898  throw Exception(stream.str());
3899  }
3900  }
3901  else
3902  {
3903  throw Exception("Can't set angular resolution, please create a LaserRangeFinder of type Custom");
3904  }
3905 
3906  Update();
3907  }
3908 
3913  {
3914  return m_pType->GetValue();
3915  }
3916 
3922  {
3923  return m_NumberOfRangeReadings;
3924  }
3925 
3926  virtual kt_bool Validate()
3927  {
3928  Update();
3929 
3930  if (math::InRange(GetRangeThreshold(), GetMinimumRange(), GetMaximumRange()) == false)
3931  {
3932  std::cout << "Please set range threshold to a value between ["
3933  << GetMinimumRange() << ";" << GetMaximumRange() << "]" << std::endl;
3934  return false;
3935  }
3936 
3937  return true;
3938  }
3939 
3940  virtual kt_bool Validate(SensorData* pSensorData);
3941 
3949  const PointVectorDouble GetPointReadings(LocalizedRangeScan* pLocalizedRangeScan,
3950  CoordinateConverter* pCoordinateConverter,
3951  kt_bool ignoreThresholdPoints = true,
3952  kt_bool flipY = false) const;
3953 
3954  public:
3962  {
3963  LaserRangeFinder* pLrf = NULL;
3964 
3965  switch (type)
3966  {
3967  // see http://www.hizook.com/files/publications/SICK_LMS100.pdf
3968  // set range threshold to 18m
3970  {
3971  pLrf = new LaserRangeFinder((rName.GetName() != "") ? rName : Name("Sick LMS 100"));
3972 
3973  // Sensing range is 18 meters (at 10% reflectivity, max range of 20 meters), with an error of about 20mm
3974  pLrf->m_pMinimumRange->SetValue(0.0);
3975  pLrf->m_pMaximumRange->SetValue(20.0);
3976 
3977  // 270 degree range, 50 Hz
3980 
3981  // 0.25 degree angular resolution
3983 
3984  pLrf->m_NumberOfRangeReadings = 1081;
3985  }
3986  break;
3987 
3988  // see http://www.hizook.com/files/publications/SICK_LMS200-291_Tech_Info.pdf
3989  // set range threshold to 10m
3991  {
3992  pLrf = new LaserRangeFinder((rName.GetName() != "") ? rName : Name("Sick LMS 200"));
3993 
3994  // Sensing range is 80 meters
3995  pLrf->m_pMinimumRange->SetValue(0.0);
3996  pLrf->m_pMaximumRange->SetValue(80.0);
3997 
3998  // 180 degree range, 75 Hz
4001 
4002  // 0.5 degree angular resolution
4004 
4005  pLrf->m_NumberOfRangeReadings = 361;
4006  }
4007  break;
4008 
4009  // see http://www.hizook.com/files/publications/SICK_LMS200-291_Tech_Info.pdf
4010  // set range threshold to 30m
4012  {
4013  pLrf = new LaserRangeFinder((rName.GetName() != "") ? rName : Name("Sick LMS 291"));
4014 
4015  // Sensing range is 80 meters
4016  pLrf->m_pMinimumRange->SetValue(0.0);
4017  pLrf->m_pMaximumRange->SetValue(80.0);
4018 
4019  // 180 degree range, 75 Hz
4022 
4023  // 0.5 degree angular resolution
4025 
4026  pLrf->m_NumberOfRangeReadings = 361;
4027  }
4028  break;
4029 
4030  // see http://www.hizook.com/files/publications/Hokuyo_UTM_LaserRangeFinder_LIDAR.pdf
4031  // set range threshold to 30m
4033  {
4034  pLrf = new LaserRangeFinder((rName.GetName() != "") ? rName : Name("Hokuyo UTM-30LX"));
4035 
4036  // Sensing range is 30 meters
4037  pLrf->m_pMinimumRange->SetValue(0.1);
4038  pLrf->m_pMaximumRange->SetValue(30.0);
4039 
4040  // 270 degree range, 40 Hz
4043 
4044  // 0.25 degree angular resolution
4046 
4047  pLrf->m_NumberOfRangeReadings = 1081;
4048  }
4049  break;
4050 
4051  // see http://www.hizook.com/files/publications/HokuyoURG_Datasheet.pdf
4052  // set range threshold to 3.5m
4054  {
4055  pLrf = new LaserRangeFinder((rName.GetName() != "") ? rName : Name("Hokuyo URG-04LX"));
4056 
4057  // Sensing range is 4 meters. It has detection problems when
4058  // scanning absorptive surfaces (such as black trimming).
4059  pLrf->m_pMinimumRange->SetValue(0.02);
4060  pLrf->m_pMaximumRange->SetValue(4.0);
4061 
4062  // 240 degree range, 10 Hz
4065 
4066  // 0.352 degree angular resolution
4068 
4069  pLrf->m_NumberOfRangeReadings = 751;
4070  }
4071  break;
4072 
4074  {
4075  pLrf = new LaserRangeFinder((rName.GetName() != "") ? rName : Name("User-Defined LaserRangeFinder"));
4076 
4077  // Sensing range is 80 meters.
4078  pLrf->m_pMinimumRange->SetValue(0.0);
4079  pLrf->m_pMaximumRange->SetValue(80.0);
4080 
4081  // 180 degree range
4084 
4085  // 1.0 degree angular resolution
4087 
4088  pLrf->m_NumberOfRangeReadings = 181;
4089  }
4090  break;
4091  }
4092 
4093  if (pLrf != NULL)
4094  {
4095  pLrf->m_pType->SetValue(type);
4096 
4097  Pose2 defaultOffset;
4098  pLrf->SetOffsetPose(defaultOffset);
4099  }
4100 
4101  return pLrf;
4102  }
4103 
4104  private:
4108  LaserRangeFinder(const Name& rName)
4109  : Sensor(rName)
4110  , m_NumberOfRangeReadings(0)
4111  {
4112  m_pMinimumRange = new Parameter<kt_double>("MinimumRange", 0.0, GetParameterManager());
4113  m_pMaximumRange = new Parameter<kt_double>("MaximumRange", 80.0, GetParameterManager());
4114 
4115  m_pMinimumAngle = new Parameter<kt_double>("MinimumAngle", -KT_PI_2, GetParameterManager());
4116  m_pMaximumAngle = new Parameter<kt_double>("MaximumAngle", KT_PI_2, GetParameterManager());
4117 
4118  m_pAngularResolution = new Parameter<kt_double>("AngularResolution",
4120  GetParameterManager());
4121 
4122  m_pRangeThreshold = new Parameter<kt_double>("RangeThreshold", 12.0, GetParameterManager());
4123 
4124  m_pType = new ParameterEnum("Type", LaserRangeFinder_Custom, GetParameterManager());
4125  m_pType->DefineEnumValue(LaserRangeFinder_Custom, "Custom");
4126  m_pType->DefineEnumValue(LaserRangeFinder_Sick_LMS100, "Sick_LMS100");
4127  m_pType->DefineEnumValue(LaserRangeFinder_Sick_LMS200, "Sick_LMS200");
4128  m_pType->DefineEnumValue(LaserRangeFinder_Sick_LMS291, "Sick_LMS291");
4129  m_pType->DefineEnumValue(LaserRangeFinder_Hokuyo_UTM_30LX, "Hokuyo_UTM_30LX");
4130  m_pType->DefineEnumValue(LaserRangeFinder_Hokuyo_URG_04LX, "Hokuyo_URG_04LX");
4131  }
4132 
4137  void Update()
4138  {
4139  m_NumberOfRangeReadings = static_cast<kt_int32u>(math::Round((GetMaximumAngle() -
4140  GetMinimumAngle())
4141  / GetAngularResolution()) + 1);
4142  }
4143 
4144  private:
4146  const LaserRangeFinder& operator=(const LaserRangeFinder&);
4147 
4148  private:
4149  // sensor m_Parameters
4152 
4154 
4157 
4159 
4161 
4163 
4164  // static std::string LaserRangeFinderTypeNames[6];
4165  }; // LaserRangeFinder
4166 
4170 
4174  typedef enum
4175  {
4179  } GridStates;
4180 
4184 
4191  {
4192  public:
4197  : m_Scale(20.0)
4198  {
4199  }
4200 
4201  public:
4208  {
4209  return value * m_Scale;
4210  }
4211 
4218  inline Vector2<kt_int32s> WorldToGrid(const Vector2<kt_double>& rWorld, kt_bool flipY = false) const
4219  {
4220  kt_double gridX = (rWorld.GetX() - m_Offset.GetX()) * m_Scale;
4221  kt_double gridY = 0.0;
4222 
4223  if (flipY == false)
4224  {
4225  gridY = (rWorld.GetY() - m_Offset.GetY()) * m_Scale;
4226  }
4227  else
4228  {
4229  gridY = (m_Size.GetHeight() / m_Scale - rWorld.GetY() + m_Offset.GetY()) * m_Scale;
4230  }
4231 
4232  return Vector2<kt_int32s>(static_cast<kt_int32s>(math::Round(gridX)), static_cast<kt_int32s>(math::Round(gridY)));
4233  }
4234 
4241  inline Vector2<kt_double> GridToWorld(const Vector2<kt_int32s>& rGrid, kt_bool flipY = false) const
4242  {
4243  kt_double worldX = m_Offset.GetX() + rGrid.GetX() / m_Scale;
4244  kt_double worldY = 0.0;
4245 
4246  if (flipY == false)
4247  {
4248  worldY = m_Offset.GetY() + rGrid.GetY() / m_Scale;
4249  }
4250  else
4251  {
4252  worldY = m_Offset.GetY() + (m_Size.GetHeight() - rGrid.GetY()) / m_Scale;
4253  }
4254 
4255  return Vector2<kt_double>(worldX, worldY);
4256  }
4257 
4262  inline kt_double GetScale() const
4263  {
4264  return m_Scale;
4265  }
4266 
4271  inline void SetScale(kt_double scale)
4272  {
4273  m_Scale = scale;
4274  }
4275 
4280  inline const Vector2<kt_double>& GetOffset() const
4281  {
4282  return m_Offset;
4283  }
4284 
4289  inline void SetOffset(const Vector2<kt_double>& rOffset)
4290  {
4291  m_Offset = rOffset;
4292  }
4293 
4298  inline void SetSize(const Size2<kt_int32s>& rSize)
4299  {
4300  m_Size = rSize;
4301  }
4302 
4307  inline const Size2<kt_int32s>& GetSize() const
4308  {
4309  return m_Size;
4310  }
4311 
4316  inline kt_double GetResolution() const
4317  {
4318  return 1.0 / m_Scale;
4319  }
4320 
4325  inline void SetResolution(kt_double resolution)
4326  {
4327  m_Scale = 1.0 / resolution;
4328  }
4329 
4335  {
4336  BoundingBox2 box;
4337 
4338  kt_double minX = GetOffset().GetX();
4339  kt_double minY = GetOffset().GetY();
4340  kt_double maxX = minX + GetSize().GetWidth() * GetResolution();
4341  kt_double maxY = minY + GetSize().GetHeight() * GetResolution();
4342 
4343  box.SetMinimum(GetOffset());
4344  box.SetMaximum(Vector2<kt_double>(maxX, maxY));
4345  return box;
4346  }
4347 
4348  private:
4351 
4353  }; // CoordinateConverter
4354 
4358 
4362  template<typename T>
4363  class Grid
4364  {
4365  public:
4373  static Grid* CreateGrid(kt_int32s width, kt_int32s height, kt_double resolution)
4374  {
4375  Grid* pGrid = new Grid(width, height);
4376 
4377  pGrid->GetCoordinateConverter()->SetScale(1.0 / resolution);
4378 
4379  return pGrid;
4380  }
4381 
4385  virtual ~Grid()
4386  {
4387  delete [] m_pData;
4388  delete m_pCoordinateConverter;
4389  }
4390 
4391  public:
4395  void Clear()
4396  {
4397  memset(m_pData, 0, GetDataSize() * sizeof(T));
4398  }
4399 
4405  {
4406  Grid* pGrid = CreateGrid(GetWidth(), GetHeight(), GetResolution());
4407  pGrid->GetCoordinateConverter()->SetOffset(GetCoordinateConverter()->GetOffset());
4408 
4409  memcpy(pGrid->GetDataPointer(), GetDataPointer(), GetDataSize());
4410 
4411  return pGrid;
4412  }
4413 
4419  virtual void Resize(kt_int32s width, kt_int32s height)
4420  {
4421  m_Width = width;
4422  m_Height = height;
4423  m_WidthStep = math::AlignValue<kt_int32s>(width, 8);
4424 
4425  if (m_pData != NULL)
4426  {
4427  delete[] m_pData;
4428  m_pData = NULL;
4429  }
4430 
4431  try
4432  {
4433  m_pData = new T[GetDataSize()];
4434 
4435  if (m_pCoordinateConverter == NULL)
4436  {
4437  m_pCoordinateConverter = new CoordinateConverter();
4438  }
4439 
4440  m_pCoordinateConverter->SetSize(Size2<kt_int32s>(width, height));
4441  }
4442  catch(...)
4443  {
4444  m_pData = NULL;
4445 
4446  m_Width = 0;
4447  m_Height = 0;
4448  m_WidthStep = 0;
4449  }
4450 
4451  Clear();
4452  }
4453 
4458  inline kt_bool IsValidGridIndex(const Vector2<kt_int32s>& rGrid) const
4459  {
4460  return (math::IsUpTo(rGrid.GetX(), m_Width) && math::IsUpTo(rGrid.GetY(), m_Height));
4461  }
4462 
4469  virtual kt_int32s GridIndex(const Vector2<kt_int32s>& rGrid, kt_bool boundaryCheck = true) const
4470  {
4471  if (boundaryCheck == true)
4472  {
4473  if (IsValidGridIndex(rGrid) == false)
4474  {
4475  std::stringstream error;
4476  error << "Index " << rGrid << " out of range. Index must be between [0; "
4477  << m_Width << ") and [0; " << m_Height << ")";
4478  throw Exception(error.str());
4479  }
4480  }
4481 
4482  kt_int32s index = rGrid.GetX() + (rGrid.GetY() * m_WidthStep);
4483 
4484  if (boundaryCheck == true)
4485  {
4486  assert(math::IsUpTo(index, GetDataSize()));
4487  }
4488 
4489  return index;
4490  }
4491 
4498  {
4499  Vector2<kt_int32s> grid;
4500 
4501  grid.SetY(index / m_WidthStep);
4502  grid.SetX(index - grid.GetY() * m_WidthStep);
4503 
4504  return grid;
4505  }
4506 
4513  inline Vector2<kt_int32s> WorldToGrid(const Vector2<kt_double>& rWorld, kt_bool flipY = false) const
4514  {
4515  return GetCoordinateConverter()->WorldToGrid(rWorld, flipY);
4516  }
4517 
4524  inline Vector2<kt_double> GridToWorld(const Vector2<kt_int32s>& rGrid, kt_bool flipY = false) const
4525  {
4526  return GetCoordinateConverter()->GridToWorld(rGrid, flipY);
4527  }
4528 
4535  {
4536  kt_int32s index = GridIndex(rGrid, true);
4537  return m_pData + index;
4538  }
4539 
4545  T* GetDataPointer(const Vector2<kt_int32s>& rGrid) const
4546  {
4547  kt_int32s index = GridIndex(rGrid, true);
4548  return m_pData + index;
4549  }
4550 
4555  inline kt_int32s GetWidth() const
4556  {
4557  return m_Width;
4558  };
4559 
4564  inline kt_int32s GetHeight() const
4565  {
4566  return m_Height;
4567  };
4568 
4573  inline const Size2<kt_int32s> GetSize() const
4574  {
4575  return Size2<kt_int32s>(m_Width, m_Height);
4576  }
4577 
4582  inline kt_int32s GetWidthStep() const
4583  {
4584  return m_WidthStep;
4585  }
4586 
4591  inline T* GetDataPointer()
4592  {
4593  return m_pData;
4594  }
4595 
4600  inline T* GetDataPointer() const
4601  {
4602  return m_pData;
4603  }
4604 
4609  inline kt_int32s GetDataSize() const
4610  {
4611  return m_WidthStep * m_Height;
4612  }
4613 
4619  inline T GetValue(const Vector2<kt_int32s>& rGrid) const
4620  {
4621  kt_int32s index = GridIndex(rGrid);
4622  return m_pData[index];
4623  }
4624 
4630  {
4631  return m_pCoordinateConverter;
4632  }
4633 
4638  inline kt_double GetResolution() const
4639  {
4640  return GetCoordinateConverter()->GetResolution();
4641  }
4642 
4648  {
4649  return GetCoordinateConverter()->GetBoundingBox();
4650  }
4651 
4661  void TraceLine(kt_int32s x0, kt_int32s y0, kt_int32s x1, kt_int32s y1, Functor* f = NULL)
4662  {
4663  kt_bool steep = abs(y1 - y0) > abs(x1 - x0);
4664  if (steep)
4665  {
4666  std::swap(x0, y0);
4667  std::swap(x1, y1);
4668  }
4669  if (x0 > x1)
4670  {
4671  std::swap(x0, x1);
4672  std::swap(y0, y1);
4673  }
4674 
4675  kt_int32s deltaX = x1 - x0;
4676  kt_int32s deltaY = abs(y1 - y0);
4677  kt_int32s error = 0;
4678  kt_int32s ystep;
4679  kt_int32s y = y0;
4680 
4681  if (y0 < y1)
4682  {
4683  ystep = 1;
4684  }
4685  else
4686  {
4687  ystep = -1;
4688  }
4689 
4690  kt_int32s pointX;
4691  kt_int32s pointY;
4692  for (kt_int32s x = x0; x <= x1; x++)
4693  {
4694  if (steep)
4695  {
4696  pointX = y;
4697  pointY = x;
4698  }
4699  else
4700  {
4701  pointX = x;
4702  pointY = y;
4703  }
4704 
4705  error += deltaY;
4706 
4707  if (2 * error >= deltaX)
4708  {
4709  y += ystep;
4710  error -= deltaX;
4711  }
4712 
4713  Vector2<kt_int32s> gridIndex(pointX, pointY);
4714  if (IsValidGridIndex(gridIndex))
4715  {
4716  kt_int32s index = GridIndex(gridIndex, false);
4717  T* pGridPointer = GetDataPointer();
4718  pGridPointer[index]++;
4719 
4720  if (f != NULL)
4721  {
4722  (*f)(index);
4723  }
4724  }
4725  }
4726  }
4727 
4728  protected:
4734  Grid(kt_int32s width, kt_int32s height)
4735  : m_pData(NULL)
4736  , m_pCoordinateConverter(NULL)
4737  {
4738  Resize(width, height);
4739  }
4740 
4741  private:
4742  kt_int32s m_Width; // width of grid
4743  kt_int32s m_Height; // height of grid
4744  kt_int32s m_WidthStep; // 8 bit aligned width of grid
4745  T* m_pData; // grid data
4746 
4747  // coordinate converter to convert between world coordinates and grid coordinates
4749  }; // Grid
4750 
4754 
4758  class CustomData : public Object
4759  {
4760  public:
4761  // @cond EXCLUDE
4763  // @endcond
4764 
4765  public:
4770  : Object()
4771  {
4772  }
4773 
4777  virtual ~CustomData()
4778  {
4779  }
4780 
4781  public:
4786  virtual const std::string Write() const = 0;
4787 
4792  virtual void Read(const std::string& rValue) = 0;
4793 
4794  private:
4795  CustomData(const CustomData&);
4796  const CustomData& operator=(const CustomData&);
4797  };
4798 
4802  typedef std::vector<CustomData*> CustomDataVector;
4803 
4807 
4812  {
4813  public:
4814  // @cond EXCLUDE
4816  // @endcond
4817 
4818  public:
4822  virtual ~SensorData();
4823 
4824  public:
4829  inline kt_int32s GetStateId() const
4830  {
4831  return m_StateId;
4832  }
4833 
4838  inline void SetStateId(kt_int32s stateId)
4839  {
4840  m_StateId = stateId;
4841  }
4842 
4847  inline kt_int32s GetUniqueId() const
4848  {
4849  return m_UniqueId;
4850  }
4851 
4856  inline void SetUniqueId(kt_int32u uniqueId)
4857  {
4858  m_UniqueId = uniqueId;
4859  }
4860 
4865  inline kt_double GetTime() const
4866  {
4867  return m_Time;
4868  }
4869 
4874  inline void SetTime(kt_double time)
4875  {
4876  m_Time = time;
4877  }
4878 
4883  inline const Name& GetSensorName() const
4884  {
4885  return m_SensorName;
4886  }
4887 
4892  inline void AddCustomData(CustomData* pCustomData)
4893  {
4894  m_CustomData.push_back(pCustomData);
4895  }
4896 
4901  inline const CustomDataVector& GetCustomData() const
4902  {
4903  return m_CustomData;
4904  }
4905 
4906  protected:
4910  SensorData(const Name& rSensorName);
4911 
4912  private:
4916  SensorData(const SensorData&);
4917 
4921  const SensorData& operator=(const SensorData&);
4922 
4923  private:
4928 
4933 
4938 
4943 
4944  CustomDataVector m_CustomData;
4945  };
4946 
4950 
4954  typedef std::vector<kt_double> RangeReadingsVector;
4955 
4960  {
4961  public:
4962  // @cond EXCLUDE
4964  // @endcond
4965 
4966  public:
4971  LaserRangeScan(const Name& rSensorName)
4972  : SensorData(rSensorName)
4973  , m_pRangeReadings(NULL)
4974  , m_NumberOfRangeReadings(0)
4975  {
4976  }
4977 
4983  LaserRangeScan(const Name& rSensorName, const RangeReadingsVector& rRangeReadings)
4984  : SensorData(rSensorName)
4985  , m_pRangeReadings(NULL)
4986  , m_NumberOfRangeReadings(0)
4987  {
4988  assert(rSensorName.ToString() != "");
4989 
4990  SetRangeReadings(rRangeReadings);
4991  }
4992 
4997  {
4998  delete [] m_pRangeReadings;
4999  }
5000 
5001  public:
5006  inline kt_double* GetRangeReadings() const
5007  {
5008  return m_pRangeReadings;
5009  }
5010 
5011  inline RangeReadingsVector GetRangeReadingsVector() const
5012  {
5013  return RangeReadingsVector(m_pRangeReadings, m_pRangeReadings + m_NumberOfRangeReadings);
5014  }
5015 
5020  inline void SetRangeReadings(const RangeReadingsVector& rRangeReadings)
5021  {
5022  // ignore for now! XXXMAE BUGUBUG 05/21/2010 << TODO(lucbettaieb): What the heck is this??
5023  // if (rRangeReadings.size() != GetNumberOfRangeReadings())
5024  // {
5025  // std::stringstream error;
5026  // error << "Given number of readings (" << rRangeReadings.size()
5027  // << ") does not match expected number of range finder (" << GetNumberOfRangeReadings() << ")";
5028  // throw Exception(error.str());
5029  // }
5030 
5031  if (!rRangeReadings.empty())
5032  {
5033  if (rRangeReadings.size() != m_NumberOfRangeReadings)
5034  {
5035  // delete old readings
5036  delete [] m_pRangeReadings;
5037 
5038  // store size of array!
5039  m_NumberOfRangeReadings = static_cast<kt_int32u>(rRangeReadings.size());
5040 
5041  // allocate range readings
5042  m_pRangeReadings = new kt_double[m_NumberOfRangeReadings];
5043  }
5044 
5045  // copy readings
5046  kt_int32u index = 0;
5047  const_forEach(RangeReadingsVector, &rRangeReadings)
5048  {
5049  m_pRangeReadings[index++] = *iter;
5050  }
5051  }
5052  else
5053  {
5054  delete [] m_pRangeReadings;
5055  m_pRangeReadings = NULL;
5056  }
5057  }
5058 
5064  {
5065  return SensorManager::GetInstance()->GetSensorByName<LaserRangeFinder>(GetSensorName());
5066  }
5067 
5073  {
5074  return m_NumberOfRangeReadings;
5075  }
5076 
5077  private:
5079  const LaserRangeScan& operator=(const LaserRangeScan&);
5080 
5081  private:
5084  }; // LaserRangeScan
5085 
5089 
5093  class DrivePose : public SensorData
5094  {
5095  public:
5096  // @cond EXCLUDE
5098  // @endcond
5099 
5100  public:
5105  DrivePose(const Name& rSensorName)
5106  : SensorData(rSensorName)
5107  {
5108  }
5109 
5113  virtual ~DrivePose()
5114  {
5115  }
5116 
5117  public:
5122  inline const Pose3& GetOdometricPose() const
5123  {
5124  return m_OdometricPose;
5125  }
5126 
5131  inline void SetOdometricPose(const Pose3& rPose)
5132  {
5133  m_OdometricPose = rPose;
5134  }
5135 
5136  private:
5137  DrivePose(const DrivePose&);
5138  const DrivePose& operator=(const DrivePose&);
5139 
5140  private:
5145  }; // class DrivePose
5146 
5150 
5158  {
5159  public:
5160  // @cond EXCLUDE
5162  // @endcond
5163 
5164  public:
5168  LocalizedRangeScan(const Name& rSensorName, const RangeReadingsVector& rReadings)
5169  : LaserRangeScan(rSensorName, rReadings)
5170  , m_IsDirty(true)
5171  {
5172  }
5173 
5178  {
5179  }
5180 
5181  private:
5182  mutable boost::shared_mutex m_Lock;
5183 
5184  public:
5189  inline const Pose2& GetOdometricPose() const
5190  {
5191  return m_OdometricPose;
5192  }
5193 
5198  inline void SetOdometricPose(const Pose2& rPose)
5199  {
5200  m_OdometricPose = rPose;
5201  }
5202 
5211  inline const Pose2& GetCorrectedPose() const
5212  {
5213  return m_CorrectedPose;
5214  }
5215 
5220  inline void SetCorrectedPose(const Pose2& rPose)
5221  {
5222  m_CorrectedPose = rPose;
5223 
5224  m_IsDirty = true;
5225  }
5226 
5230  inline const Pose2& GetBarycenterPose() const
5231  {
5232  boost::shared_lock<boost::shared_mutex> lock(m_Lock);
5233  if (m_IsDirty)
5234  {
5235  // throw away constness and do an update!
5236  lock.unlock();
5237  boost::unique_lock<boost::shared_mutex> uniqueLock(m_Lock);
5238  const_cast<LocalizedRangeScan*>(this)->Update();
5239  }
5240 
5241  return m_BarycenterPose;
5242  }
5243 
5249  inline Pose2 GetReferencePose(kt_bool useBarycenter) const
5250  {
5251  boost::shared_lock<boost::shared_mutex> lock(m_Lock);
5252  if (m_IsDirty)
5253  {
5254  // throw away constness and do an update!
5255  lock.unlock();
5256  boost::unique_lock<boost::shared_mutex> uniqueLock(m_Lock);
5257  const_cast<LocalizedRangeScan*>(this)->Update();
5258  }
5259 
5260  return useBarycenter ? GetBarycenterPose() : GetSensorPose();
5261  }
5262 
5267  inline Pose2 GetSensorPose() const
5268  {
5269  return GetSensorAt(m_CorrectedPose);
5270  }
5271 
5276  void SetSensorPose(const Pose2& rScanPose)
5277  {
5278  Pose2 deviceOffsetPose2 = GetLaserRangeFinder()->GetOffsetPose();
5279  kt_double offsetLength = deviceOffsetPose2.GetPosition().Length();
5280  kt_double offsetHeading = deviceOffsetPose2.GetHeading();
5281  kt_double angleoffset = atan2(deviceOffsetPose2.GetY(), deviceOffsetPose2.GetX());
5282  kt_double correctedHeading = math::NormalizeAngle(rScanPose.GetHeading());
5283  Pose2 worldSensorOffset = Pose2(offsetLength * cos(correctedHeading + angleoffset - offsetHeading),
5284  offsetLength * sin(correctedHeading + angleoffset - offsetHeading),
5285  offsetHeading);
5286 
5287  m_CorrectedPose = rScanPose - worldSensorOffset;
5288 
5289  Update();
5290  }
5291 
5297  inline Pose2 GetSensorAt(const Pose2& rPose) const
5298  {
5299  return Transform(rPose).TransformPose(GetLaserRangeFinder()->GetOffsetPose());
5300  }
5301 
5306  inline const BoundingBox2& GetBoundingBox() const
5307  {
5308  boost::shared_lock<boost::shared_mutex> lock(m_Lock);
5309  if (m_IsDirty)
5310  {
5311  // throw away constness and do an update!
5312  lock.unlock();
5313  boost::unique_lock<boost::shared_mutex> uniqueLock(m_Lock);
5314  const_cast<LocalizedRangeScan*>(this)->Update();
5315  }
5316 
5317  return m_BoundingBox;
5318  }
5319 
5323  inline const PointVectorDouble& GetPointReadings(kt_bool wantFiltered = false) const
5324  {
5325  boost::shared_lock<boost::shared_mutex> lock(m_Lock);
5326  if (m_IsDirty)
5327  {
5328  // throw away constness and do an update!
5329  lock.unlock();
5330  boost::unique_lock<boost::shared_mutex> uniqueLock(m_Lock);
5331  const_cast<LocalizedRangeScan*>(this)->Update();
5332  }
5333 
5334  if (wantFiltered == true)
5335  {
5336  return m_PointReadings;
5337  }
5338  else
5339  {
5340  return m_UnfilteredPointReadings;
5341  }
5342  }
5343 
5344  private:
5349  virtual void Update()
5350  {
5351  LaserRangeFinder* pLaserRangeFinder = GetLaserRangeFinder();
5352 
5353  if (pLaserRangeFinder != NULL)
5354  {
5355  m_PointReadings.clear();
5356  m_UnfilteredPointReadings.clear();
5357 
5358  kt_double rangeThreshold = pLaserRangeFinder->GetRangeThreshold();
5359  kt_double minimumAngle = pLaserRangeFinder->GetMinimumAngle();
5360  kt_double angularResolution = pLaserRangeFinder->GetAngularResolution();
5361  Pose2 scanPose = GetSensorPose();
5362 
5363  // compute point readings
5364  Vector2<kt_double> rangePointsSum;
5365  kt_int32u beamNum = 0;
5366  for (kt_int32u i = 0; i < pLaserRangeFinder->GetNumberOfRangeReadings(); i++, beamNum++)
5367  {
5368  kt_double rangeReading = GetRangeReadings()[i];
5369  if (!math::InRange(rangeReading, pLaserRangeFinder->GetMinimumRange(), rangeThreshold))
5370  {
5371  kt_double angle = scanPose.GetHeading() + minimumAngle + beamNum * angularResolution;
5372 
5373  Vector2<kt_double> point;
5374  point.SetX(scanPose.GetX() + (rangeReading * cos(angle)));
5375  point.SetY(scanPose.GetY() + (rangeReading * sin(angle)));
5376 
5377  m_UnfilteredPointReadings.push_back(point);
5378  continue;
5379  }
5380 
5381  kt_double angle = scanPose.GetHeading() + minimumAngle + beamNum * angularResolution;
5382 
5383  Vector2<kt_double> point;
5384  point.SetX(scanPose.GetX() + (rangeReading * cos(angle)));
5385  point.SetY(scanPose.GetY() + (rangeReading * sin(angle)));
5386 
5387  m_PointReadings.push_back(point);
5388  m_UnfilteredPointReadings.push_back(point);
5389 
5390  rangePointsSum += point;
5391  }
5392 
5393  // compute barycenter
5394  kt_double nPoints = static_cast<kt_double>(m_PointReadings.size());
5395  if (nPoints != 0.0)
5396  {
5397  Vector2<kt_double> averagePosition = Vector2<kt_double>(rangePointsSum / nPoints);
5398  m_BarycenterPose = Pose2(averagePosition, 0.0);
5399  }
5400  else
5401  {
5402  m_BarycenterPose = scanPose;
5403  }
5404 
5405  // calculate bounding box of scan
5406  m_BoundingBox = BoundingBox2();
5407  m_BoundingBox.Add(scanPose.GetPosition());
5408  forEach(PointVectorDouble, &m_PointReadings)
5409  {
5410  m_BoundingBox.Add(*iter);
5411  }
5412  }
5413 
5414  m_IsDirty = false;
5415  }
5416 
5417  private:
5419  const LocalizedRangeScan& operator=(const LocalizedRangeScan&);
5420 
5421  private:
5426 
5431 
5432  protected:
5437 
5441  PointVectorDouble m_PointReadings;
5442 
5446  PointVectorDouble m_UnfilteredPointReadings;
5447 
5452 
5457  }; // LocalizedRangeScan
5458 
5462  typedef std::vector<LocalizedRangeScan*> LocalizedRangeScanVector;
5463 
5467 
5472  {
5473  public:
5474  // @cond EXCLUDE
5476  // @endcond
5477 
5478  public:
5483  LocalizedRangeScanWithPoints(const Name& rSensorName, const RangeReadingsVector& rReadings,
5484  const PointVectorDouble& rPoints)
5485  : m_Points(rPoints),
5486  LocalizedRangeScan(rSensorName, rReadings)
5487  {
5488  }
5489 
5494  {
5495  }
5496 
5497  private:
5501  void Update()
5502  {
5503  m_PointReadings.clear();
5504  m_UnfilteredPointReadings.clear();
5505 
5506  Pose2 scanPose = GetSensorPose();
5507  Pose2 robotPose = GetCorrectedPose();
5508 
5509  // update point readings
5510  Vector2<kt_double> rangePointsSum;
5511  for (kt_int32u i = 0; i < m_Points.size(); i++)
5512  {
5513  // check if this has a NaN
5514  if (!std::isfinite(m_Points[i].GetX()) || !std::isfinite(m_Points[i].GetY()))
5515  {
5516  Vector2<kt_double> point(m_Points[i].GetX(), m_Points[i].GetY());
5517  m_UnfilteredPointReadings.push_back(point);
5518 
5519  continue;
5520  }
5521 
5522  // transform into world coords
5523  Pose2 pointPose(m_Points[i].GetX(), m_Points[i].GetY(), 0);
5524  Pose2 result = Transform(robotPose).TransformPose(pointPose);
5525  Vector2<kt_double> point(result.GetX(), result.GetY());
5526 
5527  m_PointReadings.push_back(point);
5528  m_UnfilteredPointReadings.push_back(point);
5529 
5530  rangePointsSum += point;
5531  }
5532 
5533  // compute barycenter
5534  kt_double nPoints = static_cast<kt_double>(m_PointReadings.size());
5535  if (nPoints != 0.0)
5536  {
5537  Vector2<kt_double> averagePosition = Vector2<kt_double>(rangePointsSum / nPoints);
5538  m_BarycenterPose = Pose2(averagePosition, 0.0);
5539  }
5540  else
5541  {
5542  m_BarycenterPose = scanPose;
5543  }
5544 
5545  // calculate bounding box of scan
5546  m_BoundingBox = BoundingBox2();
5547  m_BoundingBox.Add(scanPose.GetPosition());
5548  forEach(PointVectorDouble, &m_PointReadings)
5549  {
5550  m_BoundingBox.Add(*iter);
5551  }
5552 
5553  m_IsDirty = false;
5554  }
5555 
5556  private:
5559 
5560  private:
5561  const PointVectorDouble m_Points;
5562  }; // LocalizedRangeScanWithPoints
5563 
5567 
5568  class OccupancyGrid;
5569 
5571  {
5572  public:
5574  : m_pOccupancyGrid(pGrid)
5575  {
5576  }
5577 
5582  virtual void operator() (kt_int32u index);
5583 
5584  private:
5586  }; // CellUpdater
5587 
5591  class OccupancyGrid : public Grid<kt_int8u>
5592  {
5593  friend class CellUpdater;
5594  friend class IncrementalOccupancyGrid;
5595 
5596  public:
5604  OccupancyGrid(kt_int32s width, kt_int32s height, const Vector2<kt_double>& rOffset, kt_double resolution)
5605  : Grid<kt_int8u>(width, height)
5606  , m_pCellPassCnt(Grid<kt_int32u>::CreateGrid(0, 0, resolution))
5607  , m_pCellHitsCnt(Grid<kt_int32u>::CreateGrid(0, 0, resolution))
5608  , m_pCellUpdater(NULL)
5609  {
5610  m_pCellUpdater = new CellUpdater(this);
5611 
5612  if (karto::math::DoubleEqual(resolution, 0.0))
5613  {
5614  throw Exception("Resolution cannot be 0");
5615  }
5616 
5617  m_pMinPassThrough = new Parameter<kt_int32u>("MinPassThrough", 2);
5618  m_pOccupancyThreshold = new Parameter<kt_double>("OccupancyThreshold", 0.1);
5619 
5620  GetCoordinateConverter()->SetScale(1.0 / resolution);
5621  GetCoordinateConverter()->SetOffset(rOffset);
5622  }
5623 
5627  virtual ~OccupancyGrid()
5628  {
5629  delete m_pCellUpdater;
5630 
5631  delete m_pCellPassCnt;
5632  delete m_pCellHitsCnt;
5633 
5634  delete m_pMinPassThrough;
5635  delete m_pOccupancyThreshold;
5636  }
5637 
5638  public:
5644  static OccupancyGrid* CreateFromScans(const LocalizedRangeScanVector& rScans, kt_double resolution)
5645  {
5646  if (rScans.empty())
5647  {
5648  return NULL;
5649  }
5650 
5651  kt_int32s width, height;
5652  Vector2<kt_double> offset;
5653  ComputeDimensions(rScans, resolution, width, height, offset);
5654  OccupancyGrid* pOccupancyGrid = new OccupancyGrid(width, height, offset, resolution);
5655  pOccupancyGrid->CreateFromScans(rScans);
5656 
5657  return pOccupancyGrid;
5658  }
5659 
5665  {
5666  OccupancyGrid* pOccupancyGrid = new OccupancyGrid(GetWidth(),
5667  GetHeight(),
5668  GetCoordinateConverter()->GetOffset(),
5669  1.0 / GetCoordinateConverter()->GetScale());
5670  memcpy(pOccupancyGrid->GetDataPointer(), GetDataPointer(), GetDataSize());
5671 
5672  pOccupancyGrid->GetCoordinateConverter()->SetSize(GetCoordinateConverter()->GetSize());
5673  pOccupancyGrid->m_pCellPassCnt = m_pCellPassCnt->Clone();
5674  pOccupancyGrid->m_pCellHitsCnt = m_pCellHitsCnt->Clone();
5675 
5676  return pOccupancyGrid;
5677  }
5678 
5684  virtual kt_bool IsFree(const Vector2<kt_int32s>& rPose) const
5685  {
5686  kt_int8u* pOffsets = reinterpret_cast<kt_int8u*>(GetDataPointer(rPose));
5687  if (*pOffsets == GridStates_Free)
5688  {
5689  return true;
5690  }
5691 
5692  return false;
5693  }
5694 
5702  virtual kt_double RayCast(const Pose2& rPose2, kt_double maxRange) const
5703  {
5704  double scale = GetCoordinateConverter()->GetScale();
5705 
5706  kt_double x = rPose2.GetX();
5707  kt_double y = rPose2.GetY();
5708  kt_double theta = rPose2.GetHeading();
5709 
5710  kt_double sinTheta = sin(theta);
5711  kt_double cosTheta = cos(theta);
5712 
5713  kt_double xStop = x + maxRange * cosTheta;
5714  kt_double xSteps = 1 + fabs(xStop - x) * scale;
5715 
5716  kt_double yStop = y + maxRange * sinTheta;
5717  kt_double ySteps = 1 + fabs(yStop - y) * scale;
5718 
5719  kt_double steps = math::Maximum(xSteps, ySteps);
5720  kt_double delta = maxRange / steps;
5721  kt_double distance = delta;
5722 
5723  for (kt_int32u i = 1; i < steps; i++)
5724  {
5725  kt_double x1 = x + distance * cosTheta;
5726  kt_double y1 = y + distance * sinTheta;
5727 
5728  Vector2<kt_int32s> gridIndex = WorldToGrid(Vector2<kt_double>(x1, y1));
5729  if (IsValidGridIndex(gridIndex) && IsFree(gridIndex))
5730  {
5731  distance = (i + 1) * delta;
5732  }
5733  else
5734  {
5735  break;
5736  }
5737  }
5738 
5739  return (distance < maxRange)? distance : maxRange;
5740  }
5741 
5748  {
5749  m_pMinPassThrough->SetValue(count);
5750  }
5751 
5757  {
5758  m_pOccupancyThreshold->SetValue(thresh);
5759  }
5760 
5761  protected:
5767  {
5768  return m_pCellHitsCnt;
5769  }
5770 
5776  {
5777  return m_pCellPassCnt;
5778  }
5779 
5780  protected:
5789  static void ComputeDimensions(const LocalizedRangeScanVector& rScans,
5790  kt_double resolution,
5791  kt_int32s& rWidth,
5792  kt_int32s& rHeight,
5793  Vector2<kt_double>& rOffset)
5794  {
5795  BoundingBox2 boundingBox;
5796  const_forEach(LocalizedRangeScanVector, &rScans)
5797  {
5798  boundingBox.Add((*iter)->GetBoundingBox());
5799  }
5800 
5801  kt_double scale = 1.0 / resolution;
5802  Size2<kt_double> size = boundingBox.GetSize();
5803 
5804  rWidth = static_cast<kt_int32s>(math::Round(size.GetWidth() * scale));
5805  rHeight = static_cast<kt_int32s>(math::Round(size.GetHeight() * scale));
5806  rOffset = boundingBox.GetMinimum();
5807  }
5808 
5813  virtual void CreateFromScans(const LocalizedRangeScanVector& rScans)
5814  {
5815  m_pCellPassCnt->Resize(GetWidth(), GetHeight());
5816  m_pCellPassCnt->GetCoordinateConverter()->SetOffset(GetCoordinateConverter()->GetOffset());
5817 
5818  m_pCellHitsCnt->Resize(GetWidth(), GetHeight());
5819  m_pCellHitsCnt->GetCoordinateConverter()->SetOffset(GetCoordinateConverter()->GetOffset());
5820 
5821  const_forEach(LocalizedRangeScanVector, &rScans)
5822  {
5823  LocalizedRangeScan* pScan = *iter;
5824  AddScan(pScan);
5825  }
5826 
5827  Update();
5828  }
5829 
5837  virtual kt_bool AddScan(LocalizedRangeScan* pScan, kt_bool doUpdate = false)
5838  {
5839  kt_double rangeThreshold = pScan->GetLaserRangeFinder()->GetRangeThreshold();
5840  kt_double maxRange = pScan->GetLaserRangeFinder()->GetMaximumRange();
5841  kt_double minRange = pScan->GetLaserRangeFinder()->GetMinimumRange();
5842 
5843  Vector2<kt_double> scanPosition = pScan->GetSensorPose().GetPosition();
5844 
5845  // get scan point readings
5846  const PointVectorDouble& rPointReadings = pScan->GetPointReadings(false);
5847 
5848  kt_bool isAllInMap = true;
5849 
5850  // draw lines from scan position to all point readings
5851  int pointIndex = 0;
5852  const_forEachAs(PointVectorDouble, &rPointReadings, pointsIter)
5853  {
5854  Vector2<kt_double> point = *pointsIter;
5855  kt_double rangeReading = pScan->GetRangeReadings()[pointIndex];
5856  kt_bool isEndPointValid = rangeReading < (rangeThreshold - KT_TOLERANCE);
5857 
5858  if (rangeReading <= minRange || rangeReading >= maxRange || std::isnan(rangeReading))
5859  {
5860  // ignore these readings
5861  pointIndex++;
5862  continue;
5863  }
5864  else if (rangeReading >= rangeThreshold)
5865  {
5866  // trace up to range reading
5867  kt_double ratio = rangeThreshold / rangeReading;
5868  kt_double dx = point.GetX() - scanPosition.GetX();
5869  kt_double dy = point.GetY() - scanPosition.GetY();
5870  point.SetX(scanPosition.GetX() + ratio * dx);
5871  point.SetY(scanPosition.GetY() + ratio * dy);
5872  }
5873 
5874  kt_bool isInMap = RayTrace(scanPosition, point, isEndPointValid, doUpdate);
5875  if (!isInMap)
5876  {
5877  isAllInMap = false;
5878  }
5879 
5880  pointIndex++;
5881  }
5882 
5883  return isAllInMap;
5884  }
5885 
5895  virtual kt_bool RayTrace(const Vector2<kt_double>& rWorldFrom,
5896  const Vector2<kt_double>& rWorldTo,
5897  kt_bool isEndPointValid,
5898  kt_bool doUpdate = false)
5899  {
5900  assert(m_pCellPassCnt != NULL && m_pCellHitsCnt != NULL);
5901 
5902  Vector2<kt_int32s> gridFrom = m_pCellPassCnt->WorldToGrid(rWorldFrom);
5903  Vector2<kt_int32s> gridTo = m_pCellPassCnt->WorldToGrid(rWorldTo);
5904 
5905  CellUpdater* pCellUpdater = doUpdate ? m_pCellUpdater : NULL;
5906  m_pCellPassCnt->TraceLine(gridFrom.GetX(), gridFrom.GetY(), gridTo.GetX(), gridTo.GetY(), pCellUpdater);
5907 
5908  // for the end point
5909  if (isEndPointValid)
5910  {
5911  if (m_pCellPassCnt->IsValidGridIndex(gridTo))
5912  {
5913  kt_int32s index = m_pCellPassCnt->GridIndex(gridTo, false);
5914 
5915  kt_int32u* pCellPassCntPtr = m_pCellPassCnt->GetDataPointer();
5916  kt_int32u* pCellHitCntPtr = m_pCellHitsCnt->GetDataPointer();
5917 
5918  // increment cell pass through and hit count
5919  pCellPassCntPtr[index]++;
5920  pCellHitCntPtr[index]++;
5921 
5922  if (doUpdate)
5923  {
5924  (*m_pCellUpdater)(index);
5925  }
5926  }
5927  }
5928 
5929  return m_pCellPassCnt->IsValidGridIndex(gridTo);
5930  }
5931 
5938  virtual void UpdateCell(kt_int8u* pCell, kt_int32u cellPassCnt, kt_int32u cellHitCnt)
5939  {
5940  if (cellPassCnt > m_pMinPassThrough->GetValue())
5941  {
5942  kt_double hitRatio = static_cast<kt_double>(cellHitCnt) / static_cast<kt_double>(cellPassCnt);
5943 
5944  if (hitRatio > m_pOccupancyThreshold->GetValue())
5945  {
5946  *pCell = GridStates_Occupied;
5947  }
5948  else
5949  {
5950  *pCell = GridStates_Free;
5951  }
5952  }
5953  }
5954 
5958  virtual void Update()
5959  {
5960  assert(m_pCellPassCnt != NULL && m_pCellHitsCnt != NULL);
5961 
5962  // clear grid
5963  Clear();
5964 
5965  // set occupancy status of cells
5966  kt_int8u* pDataPtr = GetDataPointer();
5967  kt_int32u* pCellPassCntPtr = m_pCellPassCnt->GetDataPointer();
5968  kt_int32u* pCellHitCntPtr = m_pCellHitsCnt->GetDataPointer();
5969 
5970  kt_int32u nBytes = GetDataSize();
5971  for (kt_int32u i = 0; i < nBytes; i++, pDataPtr++, pCellPassCntPtr++, pCellHitCntPtr++)
5972  {
5973  UpdateCell(pDataPtr, *pCellPassCntPtr, *pCellHitCntPtr);
5974  }
5975  }
5976 
5982  virtual void Resize(kt_int32s width, kt_int32s height)
5983  {
5984  Grid<kt_int8u>::Resize(width, height);
5985  m_pCellPassCnt->Resize(width, height);
5986  m_pCellHitsCnt->Resize(width, height);
5987  }
5988 
5989  protected:
5994 
5999 
6000  private:
6004  OccupancyGrid(const OccupancyGrid&);
6005 
6009  const OccupancyGrid& operator=(const OccupancyGrid&);
6010 
6011  private:
6013 
6015  // NOTE: These two values are dependent on the resolution. If the resolution is too small,
6016  // then not many beams will hit the cell!
6017 
6018  // Number of beams that must pass through a cell before it will be considered to be occupied
6019  // or unoccupied. This prevents stray beams from messing up the map.
6021 
6022  // Minimum ratio of beams hitting cell to beams passing through cell for cell to be marked as occupied
6024  }; // OccupancyGrid
6025 
6029 
6034  class DatasetInfo : public Object
6035  {
6036  public:
6037  // @cond EXCLUDE
6039  // @endcond
6040 
6041  public:
6043  : Object()
6044  {
6045  m_pTitle = new Parameter<std::string>("Title", "", GetParameterManager());
6046  m_pAuthor = new Parameter<std::string>("Author", "", GetParameterManager());
6047  m_pDescription = new Parameter<std::string>("Description", "", GetParameterManager());
6048  m_pCopyright = new Parameter<std::string>("Copyright", "", GetParameterManager());
6049  }
6050 
6051  virtual ~DatasetInfo()
6052  {
6053  }
6054 
6055  public:
6059  const std::string& GetTitle() const
6060  {
6061  return m_pTitle->GetValue();
6062  }
6063 
6067  const std::string& GetAuthor() const
6068  {
6069  return m_pAuthor->GetValue();
6070  }
6071 
6075  const std::string& GetDescription() const
6076  {
6077  return m_pDescription->GetValue();
6078  }
6079 
6083  const std::string& GetCopyright() const
6084  {
6085  return m_pCopyright->GetValue();
6086  }
6087 
6088  private:
6089  DatasetInfo(const DatasetInfo&);
6090  const DatasetInfo& operator=(const DatasetInfo&);
6091 
6092  private:
6097  }; // class DatasetInfo
6098 
6102 
6107  class Dataset
6108  {
6109  public:
6114  : m_pDatasetInfo(NULL)
6115  {
6116  }
6117 
6121  virtual ~Dataset()
6122  {
6123  Clear();
6124  }
6125 
6126  public:
6131  void Add(Object* pObject)
6132  {
6133  if (pObject != NULL)
6134  {
6135  if (dynamic_cast<Sensor*>(pObject))
6136  {
6137  Sensor* pSensor = dynamic_cast<Sensor*>(pObject);
6138  if (pSensor != NULL)
6139  {
6140  m_SensorNameLookup[pSensor->GetName()] = pSensor;
6141 
6143  }
6144 
6145  m_Objects.push_back(pObject);
6146  }
6147  else if (dynamic_cast<SensorData*>(pObject))
6148  {
6149  SensorData* pSensorData = dynamic_cast<SensorData*>(pObject);
6150  m_Objects.push_back(pSensorData);
6151  }
6152  else if (dynamic_cast<DatasetInfo*>(pObject))
6153  {
6154  m_pDatasetInfo = dynamic_cast<DatasetInfo*>(pObject);
6155  }
6156  else
6157  {
6158  m_Objects.push_back(pObject);
6159  }
6160  }
6161  }
6162 
6167  inline const ObjectVector& GetObjects() const
6168  {
6169  return m_Objects;
6170  }
6171 
6177  {
6178  return m_pDatasetInfo;
6179  }
6180 
6184  virtual void Clear()
6185  {
6186  for (std::map<Name, Sensor*>::iterator iter = m_SensorNameLookup.begin(); iter != m_SensorNameLookup.end(); ++iter)
6187  {
6189  }
6190 
6191  forEach(ObjectVector, &m_Objects)
6192  {
6193  delete *iter;
6194  }
6195 
6196  m_Objects.clear();
6197 
6198  if (m_pDatasetInfo != NULL)
6199  {
6200  delete m_pDatasetInfo;
6201  m_pDatasetInfo = NULL;
6202  }
6203  }
6204 
6205  private:
6206  std::map<Name, Sensor*> m_SensorNameLookup;
6207  ObjectVector m_Objects;
6209  }; // Dataset
6210 
6214 
6220  {
6221  public:
6226  : m_pArray(NULL)
6227  , m_Capacity(0)
6228  , m_Size(0)
6229  {
6230  }
6231 
6235  virtual ~LookupArray()
6236  {
6237  assert(m_pArray != NULL);
6238 
6239  delete[] m_pArray;
6240  m_pArray = NULL;
6241  }
6242 
6243  public:
6247  void Clear()
6248  {
6249  memset(m_pArray, 0, sizeof(kt_int32s) * m_Capacity);
6250  }
6251 
6257  {
6258  return m_Size;
6259  }
6260 
6265  void SetSize(kt_int32u size)
6266  {
6267  assert(size != 0);
6268 
6269  if (size > m_Capacity)
6270  {
6271  if (m_pArray != NULL)
6272  {
6273  delete [] m_pArray;
6274  }
6275  m_Capacity = size;
6276  m_pArray = new kt_int32s[m_Capacity];
6277  }
6278 
6279  m_Size = size;
6280  }
6281 
6287  inline kt_int32s& operator [] (kt_int32u index)
6288  {
6289  assert(index < m_Size);
6290 
6291  return m_pArray[index];
6292  }
6293 
6299  inline kt_int32s operator [] (kt_int32u index) const
6300  {
6301  assert(index < m_Size);
6302 
6303  return m_pArray[index];
6304  }
6305 
6311  {
6312  return m_pArray;
6313  }
6314 
6319  inline kt_int32s* GetArrayPointer() const
6320  {
6321  return m_pArray;
6322  }
6323 
6324  private:
6328  }; // LookupArray
6329 
6333 
6347  template<typename T>
6349  {
6350  public:
6356  : m_pGrid(pGrid)
6357  , m_Capacity(0)
6358  , m_Size(0)
6359  , m_ppLookupArray(NULL)
6360  {
6361  }
6362 
6367  {
6368  DestroyArrays();
6369  }
6370 
6371  public:
6378  {
6379  assert(math::IsUpTo(index, m_Size));
6380 
6381  return m_ppLookupArray[index];
6382  }
6383 
6388  const std::vector<kt_double>& GetAngles() const
6389  {
6390  return m_Angles;
6391  }
6392 
6401  kt_double angleCenter,
6402  kt_double angleOffset,
6403  kt_double angleResolution)
6404  {
6405  assert(angleOffset != 0.0);
6406  assert(angleResolution != 0.0);
6407 
6408  kt_int32u nAngles = static_cast<kt_int32u>(math::Round(angleOffset * 2.0 / angleResolution) + 1);
6409  SetSize(nAngles);
6410 
6412  // convert points into local coordinates of scan pose
6413 
6414  const PointVectorDouble& rPointReadings = pScan->GetPointReadings();
6415 
6416  // compute transform to scan pose
6417  Transform transform(pScan->GetSensorPose());
6418 
6419  Pose2Vector localPoints;
6420  const_forEach(PointVectorDouble, &rPointReadings)
6421  {
6422  // do inverse transform to get points in local coordinates
6423  Pose2 vec = transform.InverseTransformPose(Pose2(*iter, 0.0));
6424  localPoints.push_back(vec);
6425  }
6426 
6428  // create lookup array for different angles
6429  kt_double angle = 0.0;
6430  kt_double startAngle = angleCenter - angleOffset;
6431  for (kt_int32u angleIndex = 0; angleIndex < nAngles; angleIndex++)
6432  {
6433  angle = startAngle + angleIndex * angleResolution;
6434  ComputeOffsets(angleIndex, angle, localPoints, pScan);
6435  }
6436  // assert(math::DoubleEqual(angle, angleCenter + angleOffset));
6437  }
6438 
6439  private:
6446  void ComputeOffsets(kt_int32u angleIndex, kt_double angle, const Pose2Vector& rLocalPoints, LocalizedRangeScan* pScan)
6447  {
6448  m_ppLookupArray[angleIndex]->SetSize(static_cast<kt_int32u>(rLocalPoints.size()));
6449  m_Angles.at(angleIndex) = angle;
6450 
6451  // set up point array by computing relative offsets to points readings
6452  // when rotated by given angle
6453 
6454  const Vector2<kt_double>& rGridOffset = m_pGrid->GetCoordinateConverter()->GetOffset();
6455 
6456  kt_double cosine = cos(angle);
6457  kt_double sine = sin(angle);
6458 
6459  kt_int32u readingIndex = 0;
6460 
6461  kt_int32s* pAngleIndexPointer = m_ppLookupArray[angleIndex]->GetArrayPointer();
6462 
6463  kt_double maxRange = pScan->GetLaserRangeFinder()->GetMaximumRange();
6464 
6465  const_forEach(Pose2Vector, &rLocalPoints)
6466  {
6467  const Vector2<kt_double>& rPosition = iter->GetPosition();
6468 
6469  if (std::isnan(pScan->GetRangeReadings()[readingIndex]) || std::isinf(pScan->GetRangeReadings()[readingIndex]))
6470  {
6471  pAngleIndexPointer[readingIndex] = INVALID_SCAN;
6472  readingIndex++;
6473  continue;
6474  }
6475 
6476 
6477  // counterclockwise rotation and that rotation is about the origin (0, 0).
6478  Vector2<kt_double> offset;
6479  offset.SetX(cosine * rPosition.GetX() - sine * rPosition.GetY());
6480  offset.SetY(sine * rPosition.GetX() + cosine * rPosition.GetY());
6481 
6482  // have to compensate for the grid offset when getting the grid index
6483  Vector2<kt_int32s> gridPoint = m_pGrid->WorldToGrid(offset + rGridOffset);
6484 
6485  // use base GridIndex to ignore ROI
6486  kt_int32s lookupIndex = m_pGrid->Grid<T>::GridIndex(gridPoint, false);
6487 
6488  pAngleIndexPointer[readingIndex] = lookupIndex;
6489 
6490  readingIndex++;
6491  }
6492  assert(readingIndex == rLocalPoints.size());
6493  }
6494 
6499  void SetSize(kt_int32u size)
6500  {
6501  assert(size != 0);
6502 
6503  if (size > m_Capacity)
6504  {
6505  if (m_ppLookupArray != NULL)
6506  {
6507  DestroyArrays();
6508  }
6509 
6510  m_Capacity = size;
6511  m_ppLookupArray = new LookupArray*[m_Capacity];
6512  for (kt_int32u i = 0; i < m_Capacity; i++)
6513  {
6514  m_ppLookupArray[i] = new LookupArray();
6515  }
6516  }
6517 
6518  m_Size = size;
6519 
6520  m_Angles.resize(size);
6521  }
6522 
6527  {
6528  for (kt_int32u i = 0; i < m_Capacity; i++)
6529  {
6530  delete m_ppLookupArray[i];
6531  }
6532 
6533  delete[] m_ppLookupArray;
6534  m_ppLookupArray = NULL;
6535  }
6536 
6537  private:
6539 
6542 
6544 
6545  // for sanity check
6546  std::vector<kt_double> m_Angles;
6547  }; // class GridIndexLookup
6548 
6552 
6553  inline Pose2::Pose2(const Pose3& rPose)
6554  : m_Position(rPose.GetPosition().GetX(), rPose.GetPosition().GetY())
6555  {
6556  kt_double t1, t2;
6557 
6558  // calculates heading from orientation
6559  rPose.GetOrientation().ToEulerAngles(m_Heading, t1, t2);
6560  }
6561 
6565 
6566  // @cond EXCLUDE
6567 
6568  template<typename T>
6569  inline void Object::SetParameter(const std::string& rName, T value)
6570  {
6571  AbstractParameter* pParameter = GetParameter(rName);
6572  if (pParameter != NULL)
6573  {
6574  std::stringstream stream;
6575  stream << value;
6576  pParameter->SetValueFromString(stream.str());
6577  }
6578  else
6579  {
6580  throw Exception("Parameter does not exist: " + rName);
6581  }
6582  }
6583 
6584  template<>
6585  inline void Object::SetParameter(const std::string& rName, kt_bool value)
6586  {
6587  AbstractParameter* pParameter = GetParameter(rName);
6588  if (pParameter != NULL)
6589  {
6590  pParameter->SetValueFromString(value ? "true" : "false");
6591  }
6592  else
6593  {
6594  throw Exception("Parameter does not exist: " + rName);
6595  }
6596  }
6597 
6598  // @endcond
6599 
6601 } // namespace karto
6602 
6603 #endif // OPEN_KARTO_KARTO_H
kt_int32s GetHeight() const
Definition: Karto.h:4564
void Add(const BoundingBox2 &rBoundingBox)
Definition: Karto.h:2833
BoundingBox2 m_BoundingBox
Definition: Karto.h:5451
const Pose2 & GetOdometricPose() const
Definition: Karto.h:5189
kt_bool InverseFast(Matrix3 &rkInverse, kt_double fTolerance=KT_TOLERANCE) const
Definition: Karto.h:2463
std::vector< kt_double > m_Angles
Definition: Karto.h:6546
kt_double GetX() const
Definition: Karto.h:1545
Parameters(const std::string &rName)
Definition: Karto.h:3400
const kt_objecttype ObjectType_Misc
Definition: Karto.h:56
const kt_objecttype ObjectType_CustomData
Definition: Karto.h:55
T GetHeight() const
Definition: Karto.h:1846
std::string m_Description
Definition: Karto.h:3078
kt_int32u m_Capacity
Definition: Karto.h:6540
void SetSize(const Size2< kt_int32s > &rSize)
Definition: Karto.h:4298
void SetX(T x)
Definition: Karto.h:1801
kt_int32s GetStateId() const
Definition: Karto.h:4829
kt_double Distance(const Vector2 &rOther) const
Definition: Karto.h:1041
RangeReadingsVector GetRangeReadingsVector() const
Definition: Karto.h:5011
DrivePose(const Name &rSensorName)
Definition: Karto.h:5105
AbstractParameter(const std::string &rName, const std::string &rDescription, ParameterManager *pParameterManger=NULL)
Definition: Karto.h:3004
int32_t kt_int32s
Definition: Types.h:51
PointVectorDouble m_UnfilteredPointReadings
Definition: Karto.h:5446
Matrix3(const Matrix3 &rOther)
Definition: Karto.h:2361
virtual kt_bool Validate()
Definition: Karto.h:3926
Size2< kt_int32s > m_Size
Definition: Karto.h:4349
void SetSize(const Size2< T > &rSize)
Definition: Karto.h:1901
Quaternion m_Orientation
Definition: Karto.h:2337
kt_int32s GetDataSize() const
Definition: Karto.h:4609
const kt_objecttype ObjectType_LocalizedRangeScan
Definition: Karto.h:64
std::vector< Sensor * > SensorVector
Definition: Karto.h:3499
virtual ~Singleton()
Definition: Karto.h:204
kt_int32u GetNumberOfRangeReadings() const
Definition: Karto.h:3921
void SetHeight(T height)
Definition: Karto.h:1855
virtual kt_objecttype GetObjectType() const =0
Exception(const std::string &rMessage="Karto Exception", kt_int32s errorCode=0)
Definition: Karto.h:92
CellUpdater * m_pCellUpdater
Definition: Karto.h:6012
Parameter< kt_double > * m_pOccupancyThreshold
Definition: Karto.h:6023
kt_bool IsSensorData(Object *pObject)
Definition: Karto.h:700
void SetY(const T &y)
Definition: Karto.h:1283
Pose3(const Vector3< kt_double > &rPosition)
Definition: Karto.h:2201
virtual ~Name()
Definition: Karto.h:384
const Size2< kt_int32s > GetSize() const
Definition: Karto.h:4573
Pose2(kt_double x, kt_double y, kt_double heading)
Definition: Karto.h:1985
kt_double SquaredLength() const
Definition: Karto.h:1332
virtual ~ParameterManager()
Definition: Karto.h:281
LaserRangeScan(const Name &rSensorName)
Definition: Karto.h:4971
const kt_int32s INVALID_SCAN
Definition: Math.h:47
T * GetDataPointer() const
Definition: Karto.h:4600
void SetMinimum(const Vector2< kt_double > &mMinimum)
Definition: Karto.h:2790
kt_double GetHeading() const
Definition: Karto.h:2064
Name(const std::string &rName)
Definition: Karto.h:367
kt_double Round(kt_double value)
Definition: Math.h:87
const PointVectorDouble & GetPointReadings(kt_bool wantFiltered=false) const
Definition: Karto.h:5323
void MakeCeil(const Vector2 &rOther)
Definition: Karto.h:1003
const Vector2< kt_double > & GetMinimum() const
Definition: Karto.h:2782
kt_double & operator()(kt_int32u row, kt_int32u column)
Definition: Karto.h:2534
void SetUniqueId(kt_int32u uniqueId)
Definition: Karto.h:4856
Vector2< kt_double > GridToWorld(const Vector2< kt_int32s > &rGrid, kt_bool flipY=false) const
Definition: Karto.h:4524
static void Validate(Sensor *pSensor)
Definition: Karto.h:3629
kt_int32u GetColumns() const
Definition: Karto.h:2677
kt_int32s GetWidthStep() const
Definition: Karto.h:4582
std::string ToString()
Definition: Karto.h:2276
const Pose2 & GetOffsetPose() const
Definition: Karto.h:3451
virtual void Update()
Definition: Karto.h:5349
const std::string & GetTitle() const
Definition: Karto.h:6059
std::vector< Vector2< kt_double > > PointVectorDouble
Definition: Karto.h:1204
const kt_objecttype ObjectType_DatasetInfo
Definition: Karto.h:70
virtual ~CustomData()
Definition: Karto.h:4777
void SetValue(const T &rValue)
Definition: Karto.h:3141
const kt_objecttype ObjectType_CameraImage
Definition: Karto.h:65
void SetX(kt_double x)
Definition: Karto.h:1554
Pose2(const Vector2< kt_double > &rPosition, kt_double heading)
Definition: Karto.h:1973
const std::string & GetCopyright() const
Definition: Karto.h:6083
void FromEulerAngles(kt_double yaw, kt_double pitch, kt_double roll)
Definition: Karto.h:1657
Pose2 m_Transform
Definition: Karto.h:2948
void DefineEnumValue(kt_int32s value, const std::string &rName)
Definition: Karto.h:3340
void SetWidth(T width)
Definition: Karto.h:855
void SetPosition(const T &rX, const T &rY)
Definition: Karto.h:1874
kt_bool IsValidFirst(char c)
Definition: Karto.h:563
void SetRangeThreshold(kt_double rangeThreshold)
Definition: Karto.h:3790
const kt_objecttype ObjectType_Module
Definition: Karto.h:71
std::vector< Object * > ObjectVector
Definition: Karto.h:679
const Size2< kt_int32s > & GetSize() const
Definition: Karto.h:4307
kt_int32u kt_objecttype
Definition: Karto.h:50
kt_int32s * GetArrayPointer()
Definition: Karto.h:6310
Vector2< kt_int32s > WorldToGrid(const Vector2< kt_double > &rWorld, kt_bool flipY=false) const
Definition: Karto.h:4513
kt_int32u m_NumberOfRangeReadings
Definition: Karto.h:4162
T m_Values[2]
Definition: Karto.h:1198
const T & GetValue() const
Definition: Karto.h:3132
const T & GetY() const
Definition: Karto.h:975
Vector2< kt_double > m_Maximum
Definition: Karto.h:2852
Pose2 GetReferencePose(kt_bool useBarycenter) const
Definition: Karto.h:5249
uint8_t kt_int8u
Definition: Types.h:46
kt_bool IsLocalizedRangeScanWithPoints(Object *pObject)
Definition: Karto.h:730
const T & Maximum(const T &value1, const T &value2)
Definition: Math.h:111
BoundingBox2 GetBoundingBox() const
Definition: Karto.h:4334
ObjectVector m_Objects
Definition: Karto.h:6207
kt_double DegreesToRadians(kt_double degrees)
Definition: Math.h:56
void SetScope(const std::string &rScope)
Definition: Karto.h:426
const kt_objecttype ObjectType_None
Definition: Karto.h:52
AbstractParameter(const std::string &rName, ParameterManager *pParameterManger=NULL)
Definition: Karto.h:2988
const kt_objecttype ObjectType_Header
Definition: Karto.h:68
kt_double GetX() const
Definition: Karto.h:2010
void SetX(const T &x)
Definition: Karto.h:966
Parameter< kt_double > * m_pMinimumAngle
Definition: Karto.h:4150
virtual ~LaserRangeFinder()
Definition: Karto.h:3732
const CustomDataVector & GetCustomData() const
Definition: Karto.h:4901
const std::string & GetName() const
Definition: Karto.h:3029
Grid< T > * m_pGrid
Definition: Karto.h:6538
BoundingBox2 GetBoundingBox() const
Definition: Karto.h:4647
virtual const std::string GetValueAsString() const
Definition: Karto.h:3150
LaserRangeFinder(const Name &rName)
Definition: Karto.h:4108
LocalizedRangeScanWithPoints(const Name &rSensorName, const RangeReadingsVector &rReadings, const PointVectorDouble &rPoints)
Definition: Karto.h:5483
virtual ~LookupArray()
Definition: Karto.h:6235
Size2(const Size2 &rOther)
Definition: Karto.h:835
kt_double GetAngularResolution() const
Definition: Karto.h:3845
void SetY(T y)
Definition: Karto.h:1819
const Pose2 & GetBarycenterPose() const
Definition: Karto.h:5230
Size2< T > m_Size
Definition: Karto.h:1945
T GetWidth() const
Definition: Karto.h:1828
Vector3(const Vector3 &rOther)
Definition: Karto.h:1244
Parameter(const std::string &rName, T value, ParameterManager *pParameterManger=NULL)
Definition: Karto.h:3098
void SetParameter(const std::string &rName, T value)
kt_int32s GetWidth() const
Definition: Karto.h:4555
LaserRangeFinderType
Definition: Karto.h:2961
const Name & GetName() const
Definition: Karto.h:614
AbstractParameter * Get(const std::string &rName)
Definition: Karto.h:298
Matrix3 Transpose() const
Definition: Karto.h:2430
void SetStateId(kt_int32s stateId)
Definition: Karto.h:4838
LaserRangeScan(const Name &rSensorName, const RangeReadingsVector &rRangeReadings)
Definition: Karto.h:4983
Parameter< Pose2 > * m_pOffsetPose
Definition: Karto.h:3493
Parameter(const std::string &rName, const std::string &rDescription, T value, ParameterManager *pParameterManger=NULL)
Definition: Karto.h:3111
virtual void UpdateCell(kt_int8u *pCell, kt_int32u cellPassCnt, kt_int32u cellHitCnt)
Definition: Karto.h:5938
#define forEach(listtype, list)
Definition: Macros.h:66
kt_double * m_pData
Definition: Karto.h:2756
const kt_objecttype ObjectType_LaserRangeFinder
Definition: Karto.h:59
void SetW(kt_double w)
Definition: Karto.h:1608
boost::shared_mutex m_Lock
Definition: Karto.h:5182
static void ComputeDimensions(const LocalizedRangeScanVector &rScans, kt_double resolution, kt_int32s &rWidth, kt_int32s &rHeight, Vector2< kt_double > &rOffset)
Definition: Karto.h:5789
virtual Grid< kt_int32u > * GetCellPassCounts()
Definition: Karto.h:5775
const PointVectorDouble m_Points
Definition: Karto.h:5561
Parameter< std::string > * m_pAuthor
Definition: Karto.h:6094
void SetSensorPose(const Pose2 &rScanPose)
Definition: Karto.h:5276
void SetMinimumAngle(kt_double minimumAngle)
Definition: Karto.h:3814
std::string ToString() const
Definition: Karto.h:1350
kt_double Length() const
Definition: Karto.h:1022
void Add(const Vector2< kt_double > &rPoint)
Definition: Karto.h:2824
void SetMaximumRange(kt_double maximumRange)
Definition: Karto.h:3770
Drive(const std::string &rName)
Definition: Karto.h:3669
void SetOffsetPose(const Pose2 &rPose)
Definition: Karto.h:3460
void SetToIdentity()
Definition: Karto.h:2370
Sensor * GetSensorByName(const Name &rName)
Definition: Karto.h:3585
Parameter< std::string > * m_pDescription
Definition: Karto.h:6095
kt_int32s m_UniqueId
Definition: Karto.h:4932
Rectangle2(const Rectangle2 &rOther)
Definition: Karto.h:1781
virtual ~DatasetInfo()
Definition: Karto.h:6051
kt_double GetZ() const
Definition: Karto.h:1581
kt_int32s m_Width
Definition: Karto.h:4742
const Vector2< T > GetCenter() const
Definition: Karto.h:1910
Parameter< kt_double > * m_pAngularResolution
Definition: Karto.h:4153
kt_int32u m_Size
Definition: Karto.h:6327
Pose3(const Vector3< kt_double > &rPosition, const karto::Quaternion &rOrientation)
Definition: Karto.h:2211
void Clear()
Definition: Karto.h:4395
Vector2< T > m_Position
Definition: Karto.h:1944
const kt_objecttype ObjectType_Sensor
Definition: Karto.h:53
void ComputeOffsets(kt_int32u angleIndex, kt_double angle, const Pose2Vector &rLocalPoints, LocalizedRangeScan *pScan)
Definition: Karto.h:6446
void SetPosition(const Vector2< T > &rPosition)
Definition: Karto.h:1883
Pose2(const Pose2 &rOther)
Definition: Karto.h:1999
const T & GetX() const
Definition: Karto.h:957
virtual const std::string GetValueAsString() const
Definition: Karto.h:3322
void SetResolution(kt_double resolution)
Definition: Karto.h:4325
kt_double & operator()(kt_int32u row, kt_int32u column)
Definition: Karto.h:2688
kt_int32s m_StateId
Definition: Karto.h:4927
Pose2 GetSensorPose() const
Definition: Karto.h:5267
virtual kt_bool AddScan(LocalizedRangeScan *pScan, kt_bool doUpdate=false)
Definition: Karto.h:5837
kt_int32s * m_pArray
Definition: Karto.h:6325
std::vector< kt_double > RangeReadingsVector
Definition: Karto.h:4954
void SetAngularResolution(kt_double angularResolution)
Definition: Karto.h:3854
void Add(Object *pObject)
Definition: Karto.h:6131
const kt_objecttype ObjectType_Camera
Definition: Karto.h:60
const kt_objecttype ObjectType_SensorData
Definition: Karto.h:54
Vector2(T x, T y)
Definition: Karto.h:946
Parameter< std::string > * m_pTitle
Definition: Karto.h:6093
Pose3(const Pose3 &rOther)
Definition: Karto.h:2220
void ComputeOffsets(LocalizedRangeScan *pScan, kt_double angleCenter, kt_double angleOffset, kt_double angleResolution)
Definition: Karto.h:6400
const BoundingBox2 & GetBoundingBox() const
Definition: Karto.h:5306
std::string m_Message
Definition: Karto.h:154
std::string ToString() const
Definition: Karto.h:435
virtual ~LaserRangeScan()
Definition: Karto.h:4996
const std::string & GetErrorMessage() const
Definition: Karto.h:131
std::string m_Scope
Definition: Karto.h:580
Pose3 m_OdometricPose
Definition: Karto.h:5144
Parameter< kt_int32u > * m_pMinPassThrough
Definition: Karto.h:6020
void SetScale(kt_double scale)
Definition: Karto.h:4271
const std::string & GetName() const
Definition: Karto.h:393
Quaternion(const Quaternion &rQuaternion)
Definition: Karto.h:1532
kt_double SquaredDistance(const Pose2 &rOther) const
Definition: Karto.h:2082
kt_int32s m_WidthStep
Definition: Karto.h:4744
T GetY() const
Definition: Karto.h:1810
void TraceLine(kt_int32s x0, kt_int32s y0, kt_int32s x1, kt_int32s y1, Functor *f=NULL)
Definition: Karto.h:4661
T * GetDataPointer(const Vector2< kt_int32s > &rGrid) const
Definition: Karto.h:4545
virtual kt_bool Validate()
Definition: Karto.h:3682
Quaternion(kt_double x, kt_double y, kt_double z, kt_double w)
Definition: Karto.h:1521
Vector2< kt_double > m_Position
Definition: Karto.h:2166
T m_Height
Definition: Karto.h:918
virtual ParameterManager * GetParameterManager()
Definition: Karto.h:635
Grid * Clone()
Definition: Karto.h:4404
void SetMaximumAngle(kt_double maximumAngle)
Definition: Karto.h:3834
T * m_pPointer
Definition: Karto.h:227
std::vector< CustomData * > CustomDataVector
Definition: Karto.h:4802
virtual void Update()
Definition: Karto.h:5958
const T & Clip(const T &n, const T &minValue, const T &maxValue)
Definition: Math.h:124
const T & GetY() const
Definition: Karto.h:1274
void Clear()
Definition: Karto.h:2383
virtual ~OccupancyGrid()
Definition: Karto.h:5627
virtual ~Parameters()
Definition: Karto.h:3408
void SetX(const T &x)
Definition: Karto.h:1265
kt_bool IsLaserRangeFinder(Object *pObject)
Definition: Karto.h:710
kt_bool IsInBounds(const Vector2< kt_double > &rPoint) const
Definition: Karto.h:2844
const Name & GetSensorName() const
Definition: Karto.h:4883
virtual void Clear()
Definition: Karto.h:6184
virtual ~Parameter()
Definition: Karto.h:3123
const ParameterVector & GetParameterVector() const
Definition: Karto.h:319
Size2< kt_double > GetSize() const
Definition: Karto.h:2814
kt_double GetResolution() const
Definition: Karto.h:4638
virtual void Resize(kt_int32s width, kt_int32s height)
Definition: Karto.h:5982
Name(const Name &rOther)
Definition: Karto.h:375
SensorVector GetAllSensors()
Definition: Karto.h:3612
ParameterManager * m_pParameterManager
Definition: Karto.h:673
#define KARTO_Object(name)
Definition: Karto.h:46
virtual kt_double RayCast(const Pose2 &rPose2, kt_double maxRange) const
Definition: Karto.h:5702
void SetOccupancyThreshold(kt_double thresh)
Definition: Karto.h:5756
virtual ~AbstractParameter()
Definition: Karto.h:3020
virtual void Resize(kt_int32s width, kt_int32s height)
Definition: Karto.h:4419
T * GetSensorByName(const Name &rName)
Definition: Karto.h:3601
const LookupArray * GetLookupArray(kt_int32u index) const
Definition: Karto.h:6377
kt_int32s GetUniqueId() const
Definition: Karto.h:4847
virtual ~Dataset()
Definition: Karto.h:6121
void MakeFloor(const Vector2 &rOther)
Definition: Karto.h:993
kt_bool IsDatasetInfo(Object *pObject)
Definition: Karto.h:750
static Grid * CreateGrid(kt_int32s width, kt_int32s height, kt_double resolution)
Definition: Karto.h:4373
void UnregisterSensor(Sensor *pSensor)
Definition: Karto.h:3564
std::map< std::string, kt_int32s > EnumMap
Definition: Karto.h:3260
virtual ~ParameterEnum()
Definition: Karto.h:3277
Parameter< kt_double > * m_pRangeThreshold
Definition: Karto.h:4158
virtual kt_bool RayTrace(const Vector2< kt_double > &rWorldFrom, const Vector2< kt_double > &rWorldTo, kt_bool isEndPointValid, kt_bool doUpdate=false)
Definition: Karto.h:5895
void SetPosition(const Vector3< kt_double > &rPosition)
Definition: Karto.h:2249
Grid< kt_int32u > * m_pCellPassCnt
Definition: Karto.h:5993
Vector2< kt_int32s > IndexToGrid(kt_int32s index) const
Definition: Karto.h:4497
const std::vector< kt_double > & GetAngles() const
Definition: Karto.h:6388
Parameter< kt_double > * m_pMinimumRange
Definition: Karto.h:4155
std::vector< Pose2 > Pose2Vector
Definition: Karto.h:2174
virtual const std::string GetValueAsString() const =0
void SetOffset(const Vector2< kt_double > &rOffset)
Definition: Karto.h:4289
kt_int32s GetErrorCode()
Definition: Karto.h:140
Matrix3 m_Rotation
Definition: Karto.h:2950
const ParameterVector & GetParameters() const
Definition: Karto.h:662
T * GetDataPointer()
Definition: Karto.h:4591
DatasetInfo * GetDatasetInfo()
Definition: Karto.h:6176
const std::string & GetDescription() const
Definition: Karto.h:3038
virtual kt_int32s GridIndex(const Vector2< kt_int32s > &rGrid, kt_bool boundaryCheck=true) const
Definition: Karto.h:4469
virtual Parameter * Clone()
Definition: Karto.h:3172
std::string m_Name
Definition: Karto.h:3077
Rectangle2(const Vector2< T > &rPosition, const Size2< T > &rSize)
Definition: Karto.h:1772
T * GetDataPointer(const Vector2< kt_int32s > &rGrid)
Definition: Karto.h:4534
Size2(T width, T height)
Definition: Karto.h:825
kt_double * m_pRangeReadings
Definition: Karto.h:5082
std::map< std::string, AbstractParameter * > m_ParameterLookup
Definition: Karto.h:341
Name m_SensorName
Definition: Karto.h:4937
EnumMap m_EnumDefines
Definition: Karto.h:3378
kt_int32s m_Height
Definition: Karto.h:4743
kt_double GetTime() const
Definition: Karto.h:4865
kt_bool InRange(const T &value, const T &a, const T &b)
Definition: Math.h:172
kt_double SquaredDistance(const Vector2 &rOther) const
Definition: Karto.h:1031
kt_int32u GetRows() const
Definition: Karto.h:2668
const kt_double KT_TOLERANCE
Definition: Math.h:41
kt_double NormalizeAngle(kt_double angle)
Definition: Math.h:182
kt_int32u m_Size
Definition: Karto.h:6541
kt_double GetY() const
Definition: Karto.h:1563
kt_int32u m_NumberOfRangeReadings
Definition: Karto.h:5083
static SensorManager * GetInstance()
Definition: Karto.cpp:35
#define const_forEach(listtype, list)
Definition: Macros.h:72
T GetX() const
Definition: Karto.h:1792
Matrix(kt_int32u rows, kt_int32u columns)
Definition: Karto.h:2634
ParameterVector m_Parameters
Definition: Karto.h:340
static OccupancyGrid * CreateFromScans(const LocalizedRangeScanVector &rScans, kt_double resolution)
Definition: Karto.h:5644
Parameter< kt_double > * m_pMaximumRange
Definition: Karto.h:4156
void RangeCheck(kt_int32u row, kt_int32u column) const
Definition: Karto.h:2739
void SetSize(kt_int32u size)
Definition: Karto.h:6499
GridIndexLookup(Grid< T > *pGrid)
Definition: Karto.h:6355
const Vector2< T > & GetPosition() const
Definition: Karto.h:1864
virtual ~SensorManager()
Definition: Karto.h:3526
kt_double GetMinimumAngle() const
Definition: Karto.h:3805
kt_int32s GetType()
Definition: Karto.h:3912
kt_bool IsParameters(Object *pObject)
Definition: Karto.h:740
Vector2< kt_double > m_Offset
Definition: Karto.h:4352
kt_int32u GetSize() const
Definition: Karto.h:6256
virtual void SetValueFromString(const std::string &rStringValue)=0
Pose2 TransformPose(const Pose2 &rSourcePose)
Definition: Karto.h:2890
void SetOdometricPose(const Pose2 &rPose)
Definition: Karto.h:5198
virtual void CreateFromScans(const LocalizedRangeScanVector &rScans)
Definition: Karto.h:5813
void Validate(const std::string &rName)
Definition: Karto.h:533
virtual ~Grid()
Definition: Karto.h:4385
void Clear()
Definition: Karto.h:2656
void SetHeight(T height)
Definition: Karto.h:873
static LaserRangeFinder * CreateLaserRangeFinder(LaserRangeFinderType type, const Name &rName)
Definition: Karto.h:3961
bool kt_bool
Definition: Types.h:64
Vector2< kt_double > m_Minimum
Definition: Karto.h:2851
const kt_objecttype ObjectType_DrivePose
Definition: Karto.h:62
const std::string & GetAuthor() const
Definition: Karto.h:6067
DatasetInfo * m_pDatasetInfo
Definition: Karto.h:6208
kt_double operator()(kt_int32u row, kt_int32u column) const
Definition: Karto.h:2545
const Vector2< kt_double > & GetOffset() const
Definition: Karto.h:4280
virtual ~DrivePose()
Definition: Karto.h:5113
void SetName(const std::string &rName)
Definition: Karto.h:402
ParameterEnum * m_pType
Definition: Karto.h:4160
const std::string & GetScope() const
Definition: Karto.h:417
virtual ~GridIndexLookup()
Definition: Karto.h:6366
virtual void SetValueFromString(const std::string &rStringValue)
Definition: Karto.h:3299
kt_int32s m_ErrorCode
Definition: Karto.h:155
const kt_double & operator()(kt_int32u row, kt_int32u column) const
Definition: Karto.h:2701
virtual kt_bool IsFree(const Vector2< kt_int32s > &rPose) const
Definition: Karto.h:5684
virtual ~LocalizedRangeScan()
Definition: Karto.h:5177
LookupArray ** m_ppLookupArray
Definition: Karto.h:6543
void SetPosition(const Vector2< kt_double > &rPosition)
Definition: Karto.h:2055
kt_double GetW() const
Definition: Karto.h:1599
CoordinateConverter * GetCoordinateConverter() const
Definition: Karto.h:4629
kt_int32s * GetArrayPointer() const
Definition: Karto.h:6319
OccupancyGrid * Clone() const
Definition: Karto.h:5664
void Parse(const std::string &rName)
Definition: Karto.h:508
virtual ~Drive()
Definition: Karto.h:3677
void SetSize(kt_int32u size)
Definition: Karto.h:6265
void SetMinimumRange(kt_double minimumRange)
Definition: Karto.h:3750
kt_int32u m_Rows
Definition: Karto.h:2753
LaserRangeFinder * GetLaserRangeFinder() const
Definition: Karto.h:5063
CustomDataVector m_CustomData
Definition: Karto.h:4944
const std::string & GetDescription() const
Definition: Karto.h:6075
void SetZ(kt_double z)
Definition: Karto.h:1590
void SetRangeReadings(const RangeReadingsVector &rRangeReadings)
Definition: Karto.h:5020
Vector2< kt_double > GridToWorld(const Vector2< kt_int32s > &rGrid, kt_bool flipY=false) const
Definition: Karto.h:4241
virtual Parameter< kt_int32s > * Clone()
Definition: Karto.h:3286
void SetCorrectedPose(const Pose2 &rPose)
Definition: Karto.h:5220
kt_double m_Matrix[3][3]
Definition: Karto.h:2618
Parameter< std::string > * m_pCopyright
Definition: Karto.h:6096
Pose2 GetSensorAt(const Pose2 &rPose) const
Definition: Karto.h:5297
void SetWidth(T width)
Definition: Karto.h:1837
void SetY(kt_double y)
Definition: Karto.h:1572
virtual kt_bool Process(karto::Object *)
Definition: Karto.h:790
void SetTransform(const Pose2 &rPose1, const Pose2 &rPose2)
Definition: Karto.h:2918
Parameter< kt_double > * m_pMaximumAngle
Definition: Karto.h:4151
kt_bool IsValid(char c)
Definition: Karto.h:573
Rectangle2(T x, T y, T width, T height)
Definition: Karto.h:1761
std::string m_Name
Definition: Karto.h:579
Matrix3 m_InverseRotation
Definition: Karto.h:2951
T Square(T value)
Definition: Math.h:77
void MakeFloor(const Vector3 &rOther)
Definition: Karto.h:1310
void SetOdometricPose(const Pose3 &rPose)
Definition: Karto.h:5131
kt_bool IsSensor(Object *pObject)
Definition: Karto.h:690
kt_double SquaredLength() const
Definition: Karto.h:1013
T GetValue(const Vector2< kt_int32s > &rGrid) const
Definition: Karto.h:4619
AbstractParameter * GetParameter(const std::string &rName) const
Definition: Karto.h:645
kt_double Length() const
Definition: Karto.h:1341
PointVectorDouble m_PointReadings
Definition: Karto.h:5441
void SetTime(kt_double time)
Definition: Karto.h:4874
kt_double GetResolution() const
Definition: Karto.h:4316
const Vector3< kt_double > & GetPosition() const
Definition: Karto.h:2240
const Pose3 & GetOdometricPose() const
Definition: Karto.h:5122
OccupancyGrid * m_pOccupancyGrid
Definition: Karto.h:5585
kt_double m_Values[4]
Definition: Karto.h:1732
kt_bool DoubleEqual(kt_double a, kt_double b)
Definition: Math.h:135
kt_double GetMaximumAngle() const
Definition: Karto.h:3825
const Quaternion & GetOrientation() const
Definition: Karto.h:2258
Transform(const Pose2 &rPose1, const Pose2 &rPose2)
Definition: Karto.h:2879
const ObjectVector & GetObjects() const
Definition: Karto.h:6167
kt_double GetY() const
Definition: Karto.h:2028
const T GetWidth() const
Definition: Karto.h:846
Pose3(const Pose2 &rPose)
Definition: Karto.h:2229
void SetHeading(kt_double heading)
Definition: Karto.h:2073
CoordinateConverter * m_pCoordinateConverter
Definition: Karto.h:4748
double kt_double
Definition: Types.h:67
void SetX(kt_double x)
Definition: Karto.h:2019
Definition: Karto.h:73
SensorManagerMap m_Sensors
Definition: Karto.h:3645
void RegisterSensor(Sensor *pSensor, kt_bool override=false)
Definition: Karto.h:3544
Pose2 InverseTransformPose(const Pose2 &rSourcePose)
Definition: Karto.h:2903
const kt_objecttype ObjectType_Parameters
Definition: Karto.h:69
virtual ~NonCopyable()
Definition: Karto.h:177
OccupancyGrid(kt_int32s width, kt_int32s height, const Vector2< kt_double > &rOffset, kt_double resolution)
Definition: Karto.h:5604
Vector3(T x, T y, T z)
Definition: Karto.h:1233
kt_double GetMinimumRange() const
Definition: Karto.h:3741
const T & GetX() const
Definition: Karto.h:1256
void SetMaximum(const Vector2< kt_double > &rMaximum)
Definition: Karto.h:2806
kt_double GetScale() const
Definition: Karto.h:4262
const Vector2< kt_double > & GetMaximum() const
Definition: Karto.h:2798
const T & GetZ() const
Definition: Karto.h:1292
std::ostream & operator<<(std::ostream &rStream, Exception &rException)
Definition: Karto.cpp:129
void SetOrientation(const Quaternion &rOrientation)
Definition: Karto.h:2267
virtual ~Matrix()
Definition: Karto.h:2647
Grid< kt_int32u > * m_pCellHitsCnt
Definition: Karto.h:5998
void SetZ(const T &z)
Definition: Karto.h:1301
virtual Grid< kt_int32u > * GetCellHitsCounts()
Definition: Karto.h:5766
const kt_objecttype ObjectType_LaserRangeScan
Definition: Karto.h:63
Matrix3 Inverse() const
Definition: Karto.h:2448
const kt_double KT_PI_2
Definition: Math.h:34
kt_int32u m_Capacity
Definition: Karto.h:6326
GridStates
Definition: Karto.h:4174
LocalizedRangeScan(const Name &rSensorName, const RangeReadingsVector &rReadings)
Definition: Karto.h:5168
const Vector2< kt_double > & GetPosition() const
Definition: Karto.h:2046
std::vector< AbstractParameter * > ParameterVector
Definition: Karto.h:258
void Allocate()
Definition: Karto.h:2712
const T GetHeight() const
Definition: Karto.h:864
kt_bool IsValidGridIndex(const Vector2< kt_int32s > &rGrid) const
Definition: Karto.h:4458
ParameterEnum(const std::string &rName, kt_int32s value, ParameterManager *pParameterManger=NULL)
Definition: Karto.h:3269
std::map< Name, Sensor * > m_SensorNameLookup
Definition: Karto.h:6206
kt_double m_Heading
Definition: Karto.h:2168
#define const_forEachAs(listtype, list, iter)
Definition: Macros.h:75
kt_double * GetRangeReadings() const
Definition: Karto.h:5006
const kt_objecttype ObjectType_LocalizedRangeScanWithPoints
Definition: Karto.h:66
void SetY(const T &y)
Definition: Karto.h:984
kt_double GetRangeThreshold() const
Definition: Karto.h:3781
T * m_pData
Definition: Karto.h:4745
kt_int32u GetNumberOfRangeReadings() const
Definition: Karto.h:5072
Transform(const Pose2 &rPose)
Definition: Karto.h:2869
Vector2< kt_int32s > WorldToGrid(const Vector2< kt_double > &rWorld, kt_bool flipY=false) const
Definition: Karto.h:4218
virtual ~Exception()
Definition: Karto.h:110
virtual kt_bool Validate(SensorData *pSensorData)
Definition: Karto.h:3687
uint32_t kt_int32u
Definition: Types.h:52
const Pose2 & GetCorrectedPose() const
Definition: Karto.h:5211
T m_Values[3]
Definition: Karto.h:1472
CellUpdater(OccupancyGrid *pGrid)
Definition: Karto.h:5573
kt_double m_Time
Definition: Karto.h:4942
#define KARTO_EXPORT
Definition: Macros.h:56
kt_bool IsUpTo(const T &value, const T &maximum)
Definition: Math.h:147
Exception(const Exception &rException)
Definition: Karto.h:101
std::map< Name, Sensor * > SensorManagerMap
Definition: Karto.h:3508
kt_bool IsLocalizedRangeScan(Object *pObject)
Definition: Karto.h:720
virtual void SetValueFromString(const std::string &rStringValue)
Definition: Karto.h:3161
void SetY(kt_double y)
Definition: Karto.h:2037
const kt_objecttype ObjectType_Drive
Definition: Karto.h:58
Grid(kt_int32s width, kt_int32s height)
Definition: Karto.h:4734
Name m_Name
Definition: Karto.h:672
kt_int32u m_Columns
Definition: Karto.h:2754
std::vector< LocalizedRangeScan * > LocalizedRangeScanVector
Definition: Karto.h:5462
void ToEulerAngles(kt_double &rYaw, kt_double &rPitch, kt_double &rRoll) const
Definition: Karto.h:1620
void AddCustomData(CustomData *pCustomData)
Definition: Karto.h:4892
void SetMinPassThrough(kt_int32u count)
Definition: Karto.h:5747
Vector3< kt_double > m_Position
Definition: Karto.h:2336
kt_double Transform(kt_double value)
Definition: Karto.h:4207
kt_double GetMaximumRange() const
Definition: Karto.h:3761
const Size2< T > & GetSize() const
Definition: Karto.h:1892
std::string ToString() const
Definition: Karto.h:2502
void FromAxisAngle(kt_double x, kt_double y, kt_double z, const kt_double radians)
Definition: Karto.h:2395
void MakeCeil(const Vector3 &rOther)
Definition: Karto.h:1321


open_karto
Author(s):
autogenerated on Mon Jun 10 2019 14:02:19