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 karto_sdk_KARTO_H
19 #define karto_sdk_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 #include <boost/serialization/base_object.hpp>
40 #include <boost/serialization/nvp.hpp>
41 #include <boost/serialization/utility.hpp>
42 #include <boost/serialization/export.hpp>
43 #include <boost/type_traits/is_abstract.hpp>
44 #include <boost/archive/binary_iarchive.hpp>
45 #include <boost/archive/binary_oarchive.hpp>
46 #include <boost/serialization/map.hpp>
47 #include <boost/serialization/vector.hpp>
48 #include <boost/serialization/string.hpp>
49 #include <boost/serialization/array.hpp>
50 #include <boost/version.hpp>
51 
52 #ifdef USE_POCO
53 #include <Poco/Mutex.h>
54 #endif
55 
56 #include <karto_sdk/Math.h>
57 #include <karto_sdk/Macros.h>
58 
59 #define KARTO_Object(name) \
60  virtual const char* GetClassName() const { return #name; } \
61  virtual kt_objecttype GetObjectType() const { return ObjectType_##name; }
62 
64 
65 const kt_objecttype ObjectType_None = 0x00000000;
66 const kt_objecttype ObjectType_Sensor = 0x00001000;
69 const kt_objecttype ObjectType_Misc = 0x10000000;
70 
74 
80 
85 
86 namespace karto
87 {
88 
93 
98  {
99  public:
105  Exception(const std::string& rMessage = "Karto Exception", kt_int32s errorCode = 0)
106  : m_Message(rMessage)
107  , m_ErrorCode(errorCode)
108  {
109  }
110 
114  Exception(const Exception& rException)
115  : m_Message(rException.m_Message)
116  , m_ErrorCode(rException.m_ErrorCode)
117  {
118  }
119 
123  virtual ~Exception()
124  {
125  }
126 
127  public:
131  Exception& operator = (const Exception& rException)
132  {
133  m_Message = rException.m_Message;
134  m_ErrorCode = rException.m_ErrorCode;
135 
136  return *this;
137  }
138 
139  public:
144  const std::string& GetErrorMessage() const
145  {
146  return m_Message;
147  }
148 
154  {
155  return m_ErrorCode;
156  }
157 
158  public:
164  friend KARTO_EXPORT std::ostream& operator << (std::ostream& rStream, Exception& rException);
165 
166  private:
167  std::string m_Message;
169  }; // class Exception
170 
174 
180  {
181  private:
182  NonCopyable(const NonCopyable&) = delete;
183  const NonCopyable& operator=(const NonCopyable&) = delete;
184 
185  public:
187  {
188  }
189 
190  virtual ~NonCopyable()
191  {
192  }
193 
194  friend class boost::serialization::access;
195  template<class Archive>
196  void serialize(Archive &ar, const unsigned int version)
197  {
198  }
199  }; // class NonCopyable
200 
204 
208  template <class T>
209  class Singleton
210  {
211  public:
216  : m_pPointer(NULL)
217  {
218  }
219 
223  virtual ~Singleton()
224  {
225  delete m_pPointer;
226  }
227 
232  T* Get()
233  {
234 #ifdef USE_POCO
235  Poco::FastMutex::ScopedLock lock(m_Mutex);
236 #endif
237  if (m_pPointer == NULL)
238  {
239  m_pPointer = new T;
240  }
241 
242  return m_pPointer;
243  }
244 
245  private:
247 
248 #ifdef USE_POCO
249  Poco::FastMutex m_Mutex;
250 #endif
251 
252  private:
253  Singleton(const Singleton&);
254  const Singleton& operator=(const Singleton&);
255  };
256 
260 
265  {
266  public:
270  virtual void operator() (kt_int32u) {};
271  }; // Functor
272 
276 
278 
282  typedef std::vector<AbstractParameter*> ParameterVector;
283 
288  {
289  public:
294  {
295  }
296 
301  {
302  Clear();
303  }
304 
305  public:
310  void Add(AbstractParameter* pParameter);
311 
317  AbstractParameter* Get(const std::string& rName)
318  {
319  if (m_ParameterLookup.find(rName) != m_ParameterLookup.end())
320  {
321  return m_ParameterLookup[rName];
322  }
323 
324  std::cout << "Unknown parameter: " << rName << std::endl;
325 
326  return NULL;
327  }
328 
332  void Clear();
333 
338  inline const ParameterVector& GetParameterVector() const
339  {
340  return m_Parameters;
341  }
342 
343  public:
349  AbstractParameter* operator() (const std::string& rName)
350  {
351  return Get(rName);
352  }
353 
358  private:
360  const ParameterManager& operator=(const ParameterManager&);
361 
362  private:
363  ParameterVector m_Parameters;
364  std::map<std::string, AbstractParameter*> m_ParameterLookup;
365 
366  friend class boost::serialization::access;
367  template<class Archive>
368  void serialize(Archive &ar, const unsigned int version)
369  {
370  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(NonCopyable);
371  ar & BOOST_SERIALIZATION_NVP(m_Parameters);
372  ar & BOOST_SERIALIZATION_NVP(m_ParameterLookup);
373  }
374 
375  }; // ParameterManager
376 
380 
381  // valid names
382  // 'Test' -- no scope
383  // '/Test' -- no scope will be parsed to 'Test'
384  // '/scope/Test' - 'scope' scope and 'Test' name
385  // '/scope/name/Test' - 'scope/name' scope and 'Test' name
386  //
387  class Name
388  {
389  public:
394  {
395  }
396 
400  Name(const std::string& rName)
401  {
402  Parse(rName);
403  }
404 
408  Name(const Name& rOther)
409  : m_Scope(rOther.m_Scope), m_Name(rOther.m_Name)
410  {
411  }
412 
416  virtual ~Name()
417  {
418  }
419 
420  public:
425  inline const std::string& GetName() const
426  {
427  return m_Name;
428  }
429 
434  inline void SetName(const std::string& rName)
435  {
436  std::string::size_type pos = rName.find_last_of('/');
437  if (pos != 0 && pos != std::string::npos)
438  {
439  throw Exception("Name can't contain a scope!");
440  }
441 
442  m_Name = rName;
443  }
444 
449  inline const std::string& GetScope() const
450  {
451  return m_Scope;
452  }
453 
458  inline void SetScope(const std::string& rScope)
459  {
460  m_Scope = rScope;
461  }
462 
467  inline std::string ToString() const
468  {
469  if (m_Scope.empty())
470  {
471  return m_Name;
472  }
473  else
474  {
475  std::string name;
476  name.append("/");
477  name.append(m_Scope);
478  name.append("/");
479  name.append(m_Name);
480 
481  return name;
482  }
483  }
484 
485  public:
489  Name& operator = (const Name& rOther)
490  {
491  if (&rOther != this)
492  {
493  m_Name = rOther.m_Name;
494  m_Scope = rOther.m_Scope;
495  }
496 
497  return *this;
498  }
499 
503  kt_bool operator == (const Name& rOther) const
504  {
505  return (m_Name == rOther.m_Name) && (m_Scope == rOther.m_Scope);
506  }
507 
511  kt_bool operator != (const Name& rOther) const
512  {
513  return !(*this == rOther);
514  }
515 
519  kt_bool operator < (const Name& rOther) const
520  {
521  return this->ToString() < rOther.ToString();
522  }
523 
529  friend inline std::ostream& operator << (std::ostream& rStream, const Name& rName)
530  {
531  rStream << rName.ToString();
532  return rStream;
533  }
534 
535  private:
540  void Parse(const std::string& rName)
541  {
542  std::string::size_type pos = rName.find_last_of('/');
543 
544  if (pos == std::string::npos)
545  {
546  m_Name = rName;
547  }
548  else
549  {
550  m_Scope = rName.substr(0, pos);
551  m_Name = rName.substr(pos+1, rName.size());
552 
553  // remove '/' from m_Scope if first!!
554  if (m_Scope.size() > 0 && m_Scope[0] == '/')
555  {
556  m_Scope = m_Scope.substr(1, m_Scope.size());
557  }
558  }
559  }
560 
565  void Validate(const std::string& rName)
566  {
567  if (rName.empty())
568  {
569  return;
570  }
571 
572  char c = rName[0];
573  if (IsValidFirst(c))
574  {
575  for (size_t i = 1; i < rName.size(); ++i)
576  {
577  c = rName[i];
578  if (!IsValid(c))
579  {
580  throw Exception("Invalid character in name. Valid characters must be within the ranges A-Z, a-z, 0-9, '/', '_' and '-'.");
581  }
582  }
583  }
584  else
585  {
586  throw Exception("Invalid first character in name. Valid characters must be within the ranges A-Z, a-z, and '/'.");
587  }
588  }
589 
595  inline kt_bool IsValidFirst(char c)
596  {
597  return (isalpha(c) || c == '/');
598  }
599 
605  inline kt_bool IsValid(char c)
606  {
607  return (isalnum(c) || c == '/' || c == '_' || c == '-');
608  }
609 
610  private:
611  std::string m_Name;
612  std::string m_Scope;
616  friend class boost::serialization::access;
617  template<class Archive>
618  void serialize(Archive &ar, const unsigned int version)
619  {
620  ar & BOOST_SERIALIZATION_NVP(m_Name);
621  ar & BOOST_SERIALIZATION_NVP(m_Scope);
622  }
623  };
624 
628 
633  {
634  public:
638  Object();
639 
644  Object(const Name& rName);
645 
649  virtual ~Object();
650 
651  public:
656  inline const Name& GetName() const
657  {
658  return m_Name;
659  }
660 
665  virtual const char* GetClassName() const = 0;
666 
671  virtual kt_objecttype GetObjectType() const = 0;
672 
678  {
679  return m_pParameterManager;
680  }
681 
687  inline AbstractParameter* GetParameter(const std::string& rName) const
688  {
689  return m_pParameterManager->Get(rName);
690  }
691 
697  template<typename T>
698  inline void SetParameter(const std::string& rName, T value);
699 
704  inline const ParameterVector& GetParameters() const
705  {
706  return m_pParameterManager->GetParameterVector();
707  }
708 
709  Object(const Object&);
710  const Object& operator=(const Object&);
711 
712  private:
718  friend class boost::serialization::access;
719  template<class Archive>
720  void serialize(Archive &ar, const unsigned int version)
721  {
722  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(NonCopyable);
723  ar & BOOST_SERIALIZATION_NVP(m_pParameterManager);
724  ar & BOOST_SERIALIZATION_NVP(m_Name);
725  }
726  };
727  BOOST_SERIALIZATION_ASSUME_ABSTRACT(Object)
728 
729 
732  typedef std::vector<Object*> ObjectVector;
733  typedef std::map<kt_int32s, Object*> DataMap;
734 
738 
744  inline kt_bool IsSensor(Object* pObject)
745  {
746  return (pObject->GetObjectType() & ObjectType_Sensor) == ObjectType_Sensor;
747  }
748 
754  inline kt_bool IsSensorData(Object* pObject)
755  {
757  }
758 
765  {
767  }
768 
775  {
777  }
778 
785  {
787  }
788 
794  inline kt_bool IsParameters(Object* pObject)
795  {
797  }
798 
804  inline kt_bool IsDatasetInfo(Object* pObject)
805  {
807  }
808 
812 
816  class KARTO_EXPORT Module : public Object
817  {
818  public:
819  // @cond EXCLUDE
821  // @endcond
822 
823  public:
828  Module(const std::string& rName);
829 
833  virtual ~Module();
834 
835  public:
839  virtual void Reset() = 0;
840 
845  {
846  return false;
847  }
848 
849  private:
850  Module(const Module&);
851  const Module& operator=(const Module&);
852 
853  friend class boost::serialization::access;
854  template<class Archive>
855  void serialize(Archive &ar, const unsigned int version)
856  {
857  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Object);
858  }
859  };
860  BOOST_SERIALIZATION_ASSUME_ABSTRACT(Module)
861 
862 
863 
869  template<typename T>
870  class Size2
871  {
872  public:
877  : m_Width(0)
878  , m_Height(0)
879  {
880  }
881 
887  Size2(T width, T height)
888  : m_Width(width)
889  , m_Height(height)
890  {
891  }
892 
897  Size2(const Size2& rOther)
898  : m_Width(rOther.m_Width)
899  , m_Height(rOther.m_Height)
900  {
901  }
902 
903  public:
908  inline const T GetWidth() const
909  {
910  return m_Width;
911  }
912 
917  inline void SetWidth(T width)
918  {
919  m_Width = width;
920  }
921 
926  inline const T GetHeight() const
927  {
928  return m_Height;
929  }
930 
935  inline void SetHeight(T height)
936  {
937  m_Height = height;
938  }
939 
943  inline Size2& operator = (const Size2& rOther)
944  {
945  m_Width = rOther.m_Width;
946  m_Height = rOther.m_Height;
947 
948  return(*this);
949  }
950 
954  inline kt_bool operator == (const Size2& rOther) const
955  {
956  return (m_Width == rOther.m_Width && m_Height == rOther.m_Height);
957  }
958 
962  inline kt_bool operator != (const Size2& rOther) const
963  {
964  return (m_Width != rOther.m_Width || m_Height != rOther.m_Height);
965  }
966 
972  friend inline std::ostream& operator << (std::ostream& rStream, const Size2& rSize)
973  {
974  rStream << "(" << rSize.m_Width << ", " << rSize.m_Height << ")";
975  return rStream;
976  }
977 
978  private:
981  friend class boost::serialization::access;
982  template<class Archive>
983  void serialize(Archive &ar, const unsigned int version)
984  {
985  ar & BOOST_SERIALIZATION_NVP(m_Width);
986  ar & BOOST_SERIALIZATION_NVP(m_Height);
987  }
988  }; // Size2<T>
989 
993 
997  template<typename T>
998  class Vector2
999  {
1000  public:
1005  {
1006  m_Values[0] = 0;
1007  m_Values[1] = 0;
1008  }
1009 
1015  Vector2(T x, T y)
1016  {
1017  m_Values[0] = x;
1018  m_Values[1] = y;
1019  }
1020 
1021  public:
1026  inline const T& GetX() const
1027  {
1028  return m_Values[0];
1029  }
1030 
1035  inline void SetX(const T& x)
1036  {
1037  m_Values[0] = x;
1038  }
1039 
1044  inline const T& GetY() const
1045  {
1046  return m_Values[1];
1047  }
1048 
1053  inline void SetY(const T& y)
1054  {
1055  m_Values[1] = y;
1056  }
1057 
1062  inline void MakeFloor(const Vector2& rOther)
1063  {
1064  if ( rOther.m_Values[0] < m_Values[0] ) m_Values[0] = rOther.m_Values[0];
1065  if ( rOther.m_Values[1] < m_Values[1] ) m_Values[1] = rOther.m_Values[1];
1066  }
1067 
1072  inline void MakeCeil(const Vector2& rOther)
1073  {
1074  if ( rOther.m_Values[0] > m_Values[0] ) m_Values[0] = rOther.m_Values[0];
1075  if ( rOther.m_Values[1] > m_Values[1] ) m_Values[1] = rOther.m_Values[1];
1076  }
1077 
1082  inline kt_double SquaredLength() const
1083  {
1084  return math::Square(m_Values[0]) + math::Square(m_Values[1]);
1085  }
1086 
1091  inline kt_double Length() const
1092  {
1093  return sqrt(SquaredLength());
1094  }
1095 
1100  inline kt_double SquaredDistance(const Vector2& rOther) const
1101  {
1102  return (*this - rOther).SquaredLength();
1103  }
1104 
1110  inline kt_double Distance(const Vector2& rOther) const
1111  {
1112  return sqrt(SquaredDistance(rOther));
1113  }
1114 
1115  public:
1119  inline void operator += (const Vector2& rOther)
1120  {
1121  m_Values[0] += rOther.m_Values[0];
1122  m_Values[1] += rOther.m_Values[1];
1123  }
1124 
1128  inline void operator -= (const Vector2& rOther)
1129  {
1130  m_Values[0] -= rOther.m_Values[0];
1131  m_Values[1] -= rOther.m_Values[1];
1132  }
1133 
1139  inline const Vector2 operator + (const Vector2& rOther) const
1140  {
1141  return Vector2(m_Values[0] + rOther.m_Values[0], m_Values[1] + rOther.m_Values[1]);
1142  }
1143 
1149  inline const Vector2 operator - (const Vector2& rOther) const
1150  {
1151  return Vector2(m_Values[0] - rOther.m_Values[0], m_Values[1] - rOther.m_Values[1]);
1152  }
1153 
1158  inline void operator /= (T scalar)
1159  {
1160  m_Values[0] /= scalar;
1161  m_Values[1] /= scalar;
1162  }
1163 
1169  inline const Vector2 operator / (T scalar) const
1170  {
1171  return Vector2(m_Values[0] / scalar, m_Values[1] / scalar);
1172  }
1173 
1179  inline kt_double operator * (const Vector2& rOther) const
1180  {
1181  return m_Values[0] * rOther.m_Values[0] + m_Values[1] * rOther.m_Values[1];
1182  }
1183 
1188  inline const Vector2 operator * (T scalar) const
1189  {
1190  return Vector2(m_Values[0] * scalar, m_Values[1] * scalar);
1191  }
1192 
1197  inline const Vector2 operator - (T scalar) const
1198  {
1199  return Vector2(m_Values[0] - scalar, m_Values[1] - scalar);
1200  }
1201 
1206  inline void operator *= (T scalar)
1207  {
1208  m_Values[0] *= scalar;
1209  m_Values[1] *= scalar;
1210  }
1211 
1216  inline kt_bool operator == (const Vector2& rOther) const
1217  {
1218  return (m_Values[0] == rOther.m_Values[0] && m_Values[1] == rOther.m_Values[1]);
1219  }
1220 
1225  inline kt_bool operator != (const Vector2& rOther) const
1226  {
1227  return (m_Values[0] != rOther.m_Values[0] || m_Values[1] != rOther.m_Values[1]);
1228  }
1229 
1235  inline kt_bool operator < (const Vector2& rOther) const
1236  {
1237  if (m_Values[0] < rOther.m_Values[0])
1238  return true;
1239  else if (m_Values[0] > rOther.m_Values[0])
1240  return false;
1241  else
1242  return (m_Values[1] < rOther.m_Values[1]);
1243  }
1244 
1250  friend inline std::ostream& operator << (std::ostream& rStream, const Vector2& rVector)
1251  {
1252  rStream << rVector.GetX() << " " << rVector.GetY();
1253  return rStream;
1254  }
1255 
1260  friend inline std::istream& operator >> (std::istream& rStream, const Vector2& /*rVector*/)
1261  {
1262  // Implement me!! TODO(lucbettaieb): What the what? Do I need to implement this?
1263  return rStream;
1264  }
1265 
1266  friend class boost::serialization::access;
1267  template<class Archive>
1268  void serialize(Archive &ar, const unsigned int version)
1269  {
1270  ar & boost::serialization::make_nvp("m_Values_0", m_Values[0]);
1271  ar & boost::serialization::make_nvp("m_Values_1", m_Values[1]);
1272  }
1273 
1274  private:
1275  T m_Values[2];
1276  }; // Vector2<T>
1277 
1281  typedef std::vector< Vector2<kt_double> > PointVectorDouble;
1282 
1286 
1290  template<typename T>
1291  class Vector3
1292  {
1293  public:
1298  {
1299  m_Values[0] = 0;
1300  m_Values[1] = 0;
1301  m_Values[2] = 0;
1302  }
1303 
1310  Vector3(T x, T y, T z)
1311  {
1312  m_Values[0] = x;
1313  m_Values[1] = y;
1314  m_Values[2] = z;
1315  }
1316 
1321  Vector3(const Vector3& rOther)
1322  {
1323  m_Values[0] = rOther.m_Values[0];
1324  m_Values[1] = rOther.m_Values[1];
1325  m_Values[2] = rOther.m_Values[2];
1326  }
1327 
1328  public:
1333  inline const T& GetX() const
1334  {
1335  return m_Values[0];
1336  }
1337 
1342  inline void SetX(const T& x)
1343  {
1344  m_Values[0] = x;
1345  }
1346 
1351  inline const T& GetY() const
1352  {
1353  return m_Values[1];
1354  }
1355 
1360  inline void SetY(const T& y)
1361  {
1362  m_Values[1] = y;
1363  }
1364 
1369  inline const T& GetZ() const
1370  {
1371  return m_Values[2];
1372  }
1373 
1378  inline void SetZ(const T& z)
1379  {
1380  m_Values[2] = z;
1381  }
1382 
1387  inline void MakeFloor(const Vector3& rOther)
1388  {
1389  if (rOther.m_Values[0] < m_Values[0]) m_Values[0] = rOther.m_Values[0];
1390  if (rOther.m_Values[1] < m_Values[1]) m_Values[1] = rOther.m_Values[1];
1391  if (rOther.m_Values[2] < m_Values[2]) m_Values[2] = rOther.m_Values[2];
1392  }
1393 
1398  inline void MakeCeil(const Vector3& rOther)
1399  {
1400  if (rOther.m_Values[0] > m_Values[0]) m_Values[0] = rOther.m_Values[0];
1401  if (rOther.m_Values[1] > m_Values[1]) m_Values[1] = rOther.m_Values[1];
1402  if (rOther.m_Values[2] > m_Values[2]) m_Values[2] = rOther.m_Values[2];
1403  }
1404 
1409  inline kt_double SquaredLength() const
1410  {
1411  return math::Square(m_Values[0]) + math::Square(m_Values[1]) + math::Square(m_Values[2]);
1412  }
1413 
1418  inline kt_double Length() const
1419  {
1420  return sqrt(SquaredLength());
1421  }
1422 
1427  inline std::string ToString() const
1428  {
1429  std::stringstream converter;
1430  converter.precision(std::numeric_limits<double>::digits10);
1431 
1432  converter << GetX() << " " << GetY() << " " << GetZ();
1433 
1434  return converter.str();
1435  }
1436 
1437  public:
1441  inline Vector3& operator = (const Vector3& rOther)
1442  {
1443  m_Values[0] = rOther.m_Values[0];
1444  m_Values[1] = rOther.m_Values[1];
1445  m_Values[2] = rOther.m_Values[2];
1446 
1447  return *this;
1448  }
1449 
1455  inline const Vector3 operator + (const Vector3& rOther) const
1456  {
1457  return Vector3(m_Values[0] + rOther.m_Values[0],
1458  m_Values[1] + rOther.m_Values[1],
1459  m_Values[2] + rOther.m_Values[2]);
1460  }
1461 
1467  inline const Vector3 operator + (kt_double scalar) const
1468  {
1469  return Vector3(m_Values[0] + scalar,
1470  m_Values[1] + scalar,
1471  m_Values[2] + scalar);
1472  }
1473 
1479  inline const Vector3 operator - (const Vector3& rOther) const
1480  {
1481  return Vector3(m_Values[0] - rOther.m_Values[0],
1482  m_Values[1] - rOther.m_Values[1],
1483  m_Values[2] - rOther.m_Values[2]);
1484  }
1485 
1491  inline const Vector3 operator - (kt_double scalar) const
1492  {
1493  return Vector3(m_Values[0] - scalar, m_Values[1] - scalar, m_Values[2] - scalar);
1494  }
1495 
1500  inline const Vector3 operator * (T scalar) const
1501  {
1502  return Vector3(m_Values[0] * scalar, m_Values[1] * scalar, m_Values[2] * scalar);
1503  }
1504 
1509  inline kt_bool operator == (const Vector3& rOther) const
1510  {
1511  return (m_Values[0] == rOther.m_Values[0] &&
1512  m_Values[1] == rOther.m_Values[1] &&
1513  m_Values[2] == rOther.m_Values[2]);
1514  }
1515 
1520  inline kt_bool operator != (const Vector3& rOther) const
1521  {
1522  return (m_Values[0] != rOther.m_Values[0] ||
1523  m_Values[1] != rOther.m_Values[1] ||
1524  m_Values[2] != rOther.m_Values[2]);
1525  }
1526 
1532  friend inline std::ostream& operator << (std::ostream& rStream, const Vector3& rVector)
1533  {
1534  rStream << rVector.ToString();
1535  return rStream;
1536  }
1537 
1542  friend inline std::istream& operator >> (std::istream& rStream, const Vector3& /*rVector*/)
1543  {
1544  // Implement me!!
1545  return rStream;
1546  }
1547 
1548  private:
1549  T m_Values[3];
1550  }; // Vector3
1551 
1555 
1578  {
1579  public:
1583  inline Quaternion()
1584  {
1585  m_Values[0] = 0.0;
1586  m_Values[1] = 0.0;
1587  m_Values[2] = 0.0;
1588  m_Values[3] = 1.0;
1589  }
1590 
1599  {
1600  m_Values[0] = x;
1601  m_Values[1] = y;
1602  m_Values[2] = z;
1603  m_Values[3] = w;
1604  }
1605 
1609  inline Quaternion(const Quaternion& rQuaternion)
1610  {
1611  m_Values[0] = rQuaternion.m_Values[0];
1612  m_Values[1] = rQuaternion.m_Values[1];
1613  m_Values[2] = rQuaternion.m_Values[2];
1614  m_Values[3] = rQuaternion.m_Values[3];
1615  }
1616 
1617  public:
1622  inline kt_double GetX() const
1623  {
1624  return m_Values[0];
1625  }
1626 
1631  inline void SetX(kt_double x)
1632  {
1633  m_Values[0] = x;
1634  }
1635 
1640  inline kt_double GetY() const
1641  {
1642  return m_Values[1];
1643  }
1644 
1649  inline void SetY(kt_double y)
1650  {
1651  m_Values[1] = y;
1652  }
1653 
1658  inline kt_double GetZ() const
1659  {
1660  return m_Values[2];
1661  }
1662 
1667  inline void SetZ(kt_double z)
1668  {
1669  m_Values[2] = z;
1670  }
1671 
1676  inline kt_double GetW() const
1677  {
1678  return m_Values[3];
1679  }
1680 
1685  inline void SetW(kt_double w)
1686  {
1687  m_Values[3] = w;
1688  }
1689 
1697  void ToEulerAngles(kt_double& rYaw, kt_double& rPitch, kt_double& rRoll) const
1698  {
1699  kt_double test = m_Values[0] * m_Values[1] + m_Values[2] * m_Values[3];
1700 
1701  if (test > 0.499)
1702  {
1703  // singularity at north pole
1704  rYaw = 2 * atan2(m_Values[0], m_Values[3]);;
1705  rPitch = KT_PI_2;
1706  rRoll = 0;
1707  }
1708  else if (test < -0.499)
1709  {
1710  // singularity at south pole
1711  rYaw = -2 * atan2(m_Values[0], m_Values[3]);
1712  rPitch = -KT_PI_2;
1713  rRoll = 0;
1714  }
1715  else
1716  {
1717  kt_double sqx = m_Values[0] * m_Values[0];
1718  kt_double sqy = m_Values[1] * m_Values[1];
1719  kt_double sqz = m_Values[2] * m_Values[2];
1720 
1721  rYaw = atan2(2 * m_Values[1] * m_Values[3] - 2 * m_Values[0] * m_Values[2], 1 - 2 * sqy - 2 * sqz);
1722  rPitch = asin(2 * test);
1723  rRoll = atan2(2 * m_Values[0] * m_Values[3] - 2 * m_Values[1] * m_Values[2], 1 - 2 * sqx - 2 * sqz);
1724  }
1725  }
1726 
1735  {
1736  kt_double angle;
1737 
1738  angle = yaw * 0.5;
1739  kt_double cYaw = cos(angle);
1740  kt_double sYaw = sin(angle);
1741 
1742  angle = pitch * 0.5;
1743  kt_double cPitch = cos(angle);
1744  kt_double sPitch = sin(angle);
1745 
1746  angle = roll * 0.5;
1747  kt_double cRoll = cos(angle);
1748  kt_double sRoll = sin(angle);
1749 
1750  m_Values[0] = sYaw * sPitch * cRoll + cYaw * cPitch * sRoll;
1751  m_Values[1] = sYaw * cPitch * cRoll + cYaw * sPitch * sRoll;
1752  m_Values[2] = cYaw * sPitch * cRoll - sYaw * cPitch * sRoll;
1753  m_Values[3] = cYaw * cPitch * cRoll - sYaw * sPitch * sRoll;
1754  }
1755 
1760  inline Quaternion& operator = (const Quaternion& rQuaternion)
1761  {
1762  m_Values[0] = rQuaternion.m_Values[0];
1763  m_Values[1] = rQuaternion.m_Values[1];
1764  m_Values[2] = rQuaternion.m_Values[2];
1765  m_Values[3] = rQuaternion.m_Values[3];
1766 
1767  return(*this);
1768  }
1769 
1774  inline kt_bool operator == (const Quaternion& rOther) const
1775  {
1776  return (m_Values[0] == rOther.m_Values[0] &&
1777  m_Values[1] == rOther.m_Values[1] &&
1778  m_Values[2] == rOther.m_Values[2] &&
1779  m_Values[3] == rOther.m_Values[3]);
1780  }
1781 
1786  inline kt_bool operator != (const Quaternion& rOther) const
1787  {
1788  return (m_Values[0] != rOther.m_Values[0] ||
1789  m_Values[1] != rOther.m_Values[1] ||
1790  m_Values[2] != rOther.m_Values[2] ||
1791  m_Values[3] != rOther.m_Values[3]);
1792  }
1793 
1799  friend inline std::ostream& operator << (std::ostream& rStream, const Quaternion& rQuaternion)
1800  {
1801  rStream << rQuaternion.m_Values[0] << " "
1802  << rQuaternion.m_Values[1] << " "
1803  << rQuaternion.m_Values[2] << " "
1804  << rQuaternion.m_Values[3];
1805  return rStream;
1806  }
1807 
1808  private:
1809  kt_double m_Values[4];
1810  };
1811 
1815 
1820  template<typename T>
1822  {
1823  public:
1828  {
1829  }
1830 
1838  Rectangle2(T x, T y, T width, T height)
1839  : m_Position(x, y)
1840  , m_Size(width, height)
1841  {
1842  }
1843 
1849  Rectangle2(const Vector2<T>& rPosition, const Size2<T>& rSize)
1850  : m_Position(rPosition)
1851  , m_Size(rSize)
1852  {
1853  }
1854 
1858  Rectangle2(const Rectangle2& rOther)
1859  : m_Position(rOther.m_Position)
1860  , m_Size(rOther.m_Size)
1861  {
1862  }
1863 
1864  public:
1869  inline T GetX() const
1870  {
1871  return m_Position.GetX();
1872  }
1873 
1878  inline void SetX(T x)
1879  {
1880  m_Position.SetX(x);
1881  }
1882 
1887  inline T GetY() const
1888  {
1889  return m_Position.GetY();
1890  }
1891 
1896  inline void SetY(T y)
1897  {
1898  m_Position.SetY(y);
1899  }
1900 
1905  inline T GetWidth() const
1906  {
1907  return m_Size.GetWidth();
1908  }
1909 
1914  inline void SetWidth(T width)
1915  {
1916  m_Size.SetWidth(width);
1917  }
1918 
1923  inline T GetHeight() const
1924  {
1925  return m_Size.GetHeight();
1926  }
1927 
1932  inline void SetHeight(T height)
1933  {
1934  m_Size.SetHeight(height);
1935  }
1936 
1941  inline const Vector2<T>& GetPosition() const
1942  {
1943  return m_Position;
1944  }
1945 
1951  inline void SetPosition(const T& rX, const T& rY)
1952  {
1953  m_Position = Vector2<T>(rX, rY);
1954  }
1955 
1960  inline void SetPosition(const Vector2<T>& rPosition)
1961  {
1962  m_Position = rPosition;
1963  }
1964 
1969  inline const Size2<T>& GetSize() const
1970  {
1971  return m_Size;
1972  }
1973 
1978  inline void SetSize(const Size2<T>& rSize)
1979  {
1980  m_Size = rSize;
1981  }
1982 
1987  inline const Vector2<T> GetCenter() const
1988  {
1989  return Vector2<T>(m_Position.GetX() + m_Size.GetWidth() * 0.5, m_Position.GetY() + m_Size.GetHeight() * 0.5);
1990  }
1991 
1992  public:
1996  Rectangle2& operator = (const Rectangle2& rOther)
1997  {
1998  m_Position = rOther.m_Position;
1999  m_Size = rOther.m_Size;
2000 
2001  return *this;
2002  }
2003 
2007  inline kt_bool operator == (const Rectangle2& rOther) const
2008  {
2009  return (m_Position == rOther.m_Position && m_Size == rOther.m_Size);
2010  }
2011 
2015  inline kt_bool operator != (const Rectangle2& rOther) const
2016  {
2017  return (m_Position != rOther.m_Position || m_Size != rOther.m_Size);
2018  }
2019 
2020  private:
2026  friend class boost::serialization::access;
2027  template<class Archive>
2028  void serialize(Archive &ar, const unsigned int version)
2029  {
2030  ar & BOOST_SERIALIZATION_NVP(m_Position);
2031  ar & BOOST_SERIALIZATION_NVP(m_Size);
2032  }
2033  }; // Rectangle2
2034 
2038 
2039  class Pose3;
2040 
2044  class Pose2
2045  {
2046  public:
2051  : m_Heading(0.0)
2052  {
2053  }
2054 
2060  Pose2(const Vector2<kt_double>& rPosition, kt_double heading)
2061  : m_Position(rPosition)
2062  , m_Heading(heading)
2063  {
2064  }
2065 
2073  : m_Position(x, y)
2074  , m_Heading(heading)
2075  {
2076  }
2077 
2081  Pose2(const Pose3& rPose);
2082 
2086  Pose2(const Pose2& rOther)
2087  : m_Position(rOther.m_Position)
2088  , m_Heading(rOther.m_Heading)
2089  {
2090  }
2091 
2092  public:
2097  inline kt_double GetX() const
2098  {
2099  return m_Position.GetX();
2100  }
2101 
2106  inline void SetX(kt_double x)
2107  {
2108  m_Position.SetX(x);
2109  }
2110 
2115  inline kt_double GetY() const
2116  {
2117  return m_Position.GetY();
2118  }
2119 
2124  inline void SetY(kt_double y)
2125  {
2126  m_Position.SetY(y);
2127  }
2128 
2133  inline const Vector2<kt_double>& GetPosition() const
2134  {
2135  return m_Position;
2136  }
2137 
2142  inline void SetPosition(const Vector2<kt_double>& rPosition)
2143  {
2144  m_Position = rPosition;
2145  }
2146 
2151  inline kt_double GetHeading() const
2152  {
2153  return m_Heading;
2154  }
2155 
2160  inline void SetHeading(kt_double heading)
2161  {
2162  m_Heading = heading;
2163  }
2164 
2169  inline kt_double SquaredDistance(const Pose2& rOther) const
2170  {
2171  return m_Position.SquaredDistance(rOther.m_Position);
2172  }
2173 
2174  public:
2178  inline Pose2& operator = (const Pose2& rOther)
2179  {
2180  m_Position = rOther.m_Position;
2181  m_Heading = rOther.m_Heading;
2182 
2183  return *this;
2184  }
2185 
2189  inline kt_bool operator == (const Pose2& rOther) const
2190  {
2191  return (m_Position == rOther.m_Position && m_Heading == rOther.m_Heading);
2192  }
2193 
2197  inline kt_bool operator != (const Pose2& rOther) const
2198  {
2199  return (m_Position != rOther.m_Position || m_Heading != rOther.m_Heading);
2200  }
2201 
2205  inline void operator += (const Pose2& rOther)
2206  {
2207  m_Position += rOther.m_Position;
2208  m_Heading = math::NormalizeAngle(m_Heading + rOther.m_Heading);
2209  }
2210 
2216  inline Pose2 operator + (const Pose2& rOther) const
2217  {
2218  return Pose2(m_Position + rOther.m_Position, math::NormalizeAngle(m_Heading + rOther.m_Heading));
2219  }
2220 
2226  inline Pose2 operator - (const Pose2& rOther) const
2227  {
2228  return Pose2(m_Position - rOther.m_Position, math::NormalizeAngle(m_Heading - rOther.m_Heading));
2229  }
2230 
2235  friend inline std::istream& operator >> (std::istream& rStream, const Pose2& /*rPose*/)
2236  {
2237  // Implement me!!
2238  return rStream;
2239  }
2240 
2246  friend inline std::ostream& operator << (std::ostream& rStream, const Pose2& rPose)
2247  {
2248  rStream << rPose.m_Position.GetX() << " " << rPose.m_Position.GetY() << " " << rPose.m_Heading;
2249  return rStream;
2250  }
2251 
2252  friend class boost::serialization::access;
2253  template<class Archive>
2254  void serialize(Archive &ar, const unsigned int version)
2255  {
2256  ar & BOOST_SERIALIZATION_NVP(m_Position);
2257  ar & BOOST_SERIALIZATION_NVP(m_Heading);
2258  }
2259 
2260  private:
2262 
2264  }; // Pose2
2265 
2269  typedef std::vector< Pose2 > Pose2Vector;
2270 
2274 
2282  class Pose3
2283  {
2284  public:
2289  {
2290  }
2291 
2296  Pose3(const Vector3<kt_double>& rPosition)
2297  : m_Position(rPosition)
2298  {
2299  }
2300 
2306  Pose3(const Vector3<kt_double>& rPosition, const karto::Quaternion& rOrientation)
2307  : m_Position(rPosition)
2308  , m_Orientation(rOrientation)
2309  {
2310  }
2311 
2315  Pose3(const Pose3& rOther)
2316  : m_Position(rOther.m_Position)
2317  , m_Orientation(rOther.m_Orientation)
2318  {
2319  }
2320 
2324  Pose3(const Pose2& rPose)
2325  {
2326  m_Position = Vector3<kt_double>(rPose.GetX(), rPose.GetY(), 0.0);
2327  m_Orientation.FromEulerAngles(rPose.GetHeading(), 0.0, 0.0);
2328  }
2329 
2330  public:
2335  inline const Vector3<kt_double>& GetPosition() const
2336  {
2337  return m_Position;
2338  }
2339 
2344  inline void SetPosition(const Vector3<kt_double>& rPosition)
2345  {
2346  m_Position = rPosition;
2347  }
2348 
2353  inline const Quaternion& GetOrientation() const
2354  {
2355  return m_Orientation;
2356  }
2357 
2362  inline void SetOrientation(const Quaternion& rOrientation)
2363  {
2364  m_Orientation = rOrientation;
2365  }
2366 
2371  inline std::string ToString()
2372  {
2373  std::stringstream converter;
2374  converter.precision(std::numeric_limits<double>::digits10);
2375 
2376  converter << GetPosition() << " " << GetOrientation();
2377 
2378  return converter.str();
2379  }
2380 
2381  public:
2385  inline Pose3& operator = (const Pose3& rOther)
2386  {
2387  m_Position = rOther.m_Position;
2388  m_Orientation = rOther.m_Orientation;
2389 
2390  return *this;
2391  }
2392 
2396  inline kt_bool operator == (const Pose3& rOther) const
2397  {
2398  return (m_Position == rOther.m_Position && m_Orientation == rOther.m_Orientation);
2399  }
2400 
2404  inline kt_bool operator != (const Pose3& rOther) const
2405  {
2406  return (m_Position != rOther.m_Position || m_Orientation != rOther.m_Orientation);
2407  }
2408 
2414  friend inline std::ostream& operator << (std::ostream& rStream, const Pose3& rPose)
2415  {
2416  rStream << rPose.GetPosition() << ", " << rPose.GetOrientation();
2417  return rStream;
2418  }
2419 
2424  friend inline std::istream& operator >> (std::istream& rStream, const Pose3& /*rPose*/)
2425  {
2426  // Implement me!!
2427  return rStream;
2428  }
2429 
2430  private:
2433  }; // Pose3
2434 
2438 
2442  class Matrix3
2443  {
2444  public:
2449  {
2450  Clear();
2451  }
2452 
2456  inline Matrix3(const Matrix3& rOther)
2457  {
2458  memcpy(m_Matrix, rOther.m_Matrix, 9*sizeof(kt_double));
2459  }
2460 
2461  public:
2466  {
2467  memset(m_Matrix, 0, 9*sizeof(kt_double));
2468 
2469  for (kt_int32s i = 0; i < 3; i++)
2470  {
2471  m_Matrix[i][i] = 1.0;
2472  }
2473  }
2474 
2478  void Clear()
2479  {
2480  memset(m_Matrix, 0, 9*sizeof(kt_double));
2481  }
2482 
2490  void FromAxisAngle(kt_double x, kt_double y, kt_double z, const kt_double radians)
2491  {
2492  kt_double cosRadians = cos(radians);
2493  kt_double sinRadians = sin(radians);
2494  kt_double oneMinusCos = 1.0 - cosRadians;
2495 
2496  kt_double xx = x * x;
2497  kt_double yy = y * y;
2498  kt_double zz = z * z;
2499 
2500  kt_double xyMCos = x * y * oneMinusCos;
2501  kt_double xzMCos = x * z * oneMinusCos;
2502  kt_double yzMCos = y * z * oneMinusCos;
2503 
2504  kt_double xSin = x * sinRadians;
2505  kt_double ySin = y * sinRadians;
2506  kt_double zSin = z * sinRadians;
2507 
2508  m_Matrix[0][0] = xx * oneMinusCos + cosRadians;
2509  m_Matrix[0][1] = xyMCos - zSin;
2510  m_Matrix[0][2] = xzMCos + ySin;
2511 
2512  m_Matrix[1][0] = xyMCos + zSin;
2513  m_Matrix[1][1] = yy * oneMinusCos + cosRadians;
2514  m_Matrix[1][2] = yzMCos - xSin;
2515 
2516  m_Matrix[2][0] = xzMCos - ySin;
2517  m_Matrix[2][1] = yzMCos + xSin;
2518  m_Matrix[2][2] = zz * oneMinusCos + cosRadians;
2519  }
2520 
2526  {
2527  Matrix3 transpose;
2528 
2529  for (kt_int32u row = 0; row < 3; row++)
2530  {
2531  for (kt_int32u col = 0; col < 3; col++)
2532  {
2533  transpose.m_Matrix[row][col] = m_Matrix[col][row];
2534  }
2535  }
2536 
2537  return transpose;
2538  }
2539 
2544  {
2545  Matrix3 kInverse = *this;
2546  kt_bool haveInverse = InverseFast(kInverse, 1e-14);
2547  if (haveInverse == false)
2548  {
2549  assert(false);
2550  }
2551  return kInverse;
2552  }
2553 
2558  kt_bool InverseFast(Matrix3& rkInverse, kt_double fTolerance = KT_TOLERANCE) const
2559  {
2560  // Invert a 3x3 using cofactors. This is about 8 times faster than
2561  // the Numerical Recipes code which uses Gaussian elimination.
2562  rkInverse.m_Matrix[0][0] = m_Matrix[1][1]*m_Matrix[2][2] - m_Matrix[1][2]*m_Matrix[2][1];
2563  rkInverse.m_Matrix[0][1] = m_Matrix[0][2]*m_Matrix[2][1] - m_Matrix[0][1]*m_Matrix[2][2];
2564  rkInverse.m_Matrix[0][2] = m_Matrix[0][1]*m_Matrix[1][2] - m_Matrix[0][2]*m_Matrix[1][1];
2565  rkInverse.m_Matrix[1][0] = m_Matrix[1][2]*m_Matrix[2][0] - m_Matrix[1][0]*m_Matrix[2][2];
2566  rkInverse.m_Matrix[1][1] = m_Matrix[0][0]*m_Matrix[2][2] - m_Matrix[0][2]*m_Matrix[2][0];
2567  rkInverse.m_Matrix[1][2] = m_Matrix[0][2]*m_Matrix[1][0] - m_Matrix[0][0]*m_Matrix[1][2];
2568  rkInverse.m_Matrix[2][0] = m_Matrix[1][0]*m_Matrix[2][1] - m_Matrix[1][1]*m_Matrix[2][0];
2569  rkInverse.m_Matrix[2][1] = m_Matrix[0][1]*m_Matrix[2][0] - m_Matrix[0][0]*m_Matrix[2][1];
2570  rkInverse.m_Matrix[2][2] = m_Matrix[0][0]*m_Matrix[1][1] - m_Matrix[0][1]*m_Matrix[1][0];
2571 
2572  kt_double fDet = m_Matrix[0][0]*rkInverse.m_Matrix[0][0] +
2573  m_Matrix[0][1]*rkInverse.m_Matrix[1][0] +
2574  m_Matrix[0][2]*rkInverse.m_Matrix[2][0];
2575 
2576  if (fabs(fDet) <= fTolerance)
2577  {
2578  return false;
2579  }
2580 
2581  kt_double fInvDet = 1.0/fDet;
2582  for (size_t row = 0; row < 3; row++)
2583  {
2584  for (size_t col = 0; col < 3; col++)
2585  {
2586  rkInverse.m_Matrix[row][col] *= fInvDet;
2587  }
2588  }
2589 
2590  return true;
2591  }
2592 
2597  inline std::string ToString() const
2598  {
2599  std::stringstream converter;
2600  converter.precision(std::numeric_limits<double>::digits10);
2601 
2602  for (int row = 0; row < 3; row++)
2603  {
2604  for (int col = 0; col < 3; col++)
2605  {
2606  converter << m_Matrix[row][col] << " ";
2607  }
2608  }
2609 
2610  return converter.str();
2611  }
2612 
2613  public:
2617  inline Matrix3& operator = (const Matrix3& rOther)
2618  {
2619  memcpy(m_Matrix, rOther.m_Matrix, 9*sizeof(kt_double));
2620  return *this;
2621  }
2622 
2630  {
2631  return m_Matrix[row][column];
2632  }
2633 
2640  inline kt_double operator()(kt_int32u row, kt_int32u column) const
2641  {
2642  return m_Matrix[row][column];
2643  }
2644 
2650  Matrix3 operator * (const Matrix3& rOther) const
2651  {
2652  Matrix3 product;
2653 
2654  for (size_t row = 0; row < 3; row++)
2655  {
2656  for (size_t col = 0; col < 3; col++)
2657  {
2658  product.m_Matrix[row][col] = m_Matrix[row][0]*rOther.m_Matrix[0][col] +
2659  m_Matrix[row][1]*rOther.m_Matrix[1][col] +
2660  m_Matrix[row][2]*rOther.m_Matrix[2][col];
2661  }
2662  }
2663 
2664  return product;
2665  }
2666 
2672  inline Pose2 operator * (const Pose2& rPose2) const
2673  {
2674  Pose2 pose2;
2675 
2676  pose2.SetX(m_Matrix[0][0] * rPose2.GetX() + m_Matrix[0][1] *
2677  rPose2.GetY() + m_Matrix[0][2] * rPose2.GetHeading());
2678  pose2.SetY(m_Matrix[1][0] * rPose2.GetX() + m_Matrix[1][1] *
2679  rPose2.GetY() + m_Matrix[1][2] * rPose2.GetHeading());
2680  pose2.SetHeading(m_Matrix[2][0] * rPose2.GetX() + m_Matrix[2][1] *
2681  rPose2.GetY() + m_Matrix[2][2] * rPose2.GetHeading());
2682 
2683  return pose2;
2684  }
2685 
2690  inline void operator += (const Matrix3& rkMatrix)
2691  {
2692  for (kt_int32u row = 0; row < 3; row++)
2693  {
2694  for (kt_int32u col = 0; col < 3; col++)
2695  {
2696  m_Matrix[row][col] += rkMatrix.m_Matrix[row][col];
2697  }
2698  }
2699  }
2700 
2706  friend inline std::ostream& operator << (std::ostream& rStream, const Matrix3& rMatrix)
2707  {
2708  rStream << rMatrix.ToString();
2709  return rStream;
2710  }
2711 
2712  private:
2713  kt_double m_Matrix[3][3];
2714  friend class boost::serialization::access;
2715  template<class Archive>
2716  void serialize(Archive &ar, const unsigned int version)
2717  {
2718  ar & BOOST_SERIALIZATION_NVP(m_Matrix);
2719  }
2720  }; // Matrix3
2721 
2725 
2729  class Matrix
2730  {
2731  public:
2735  Matrix(kt_int32u rows, kt_int32u columns)
2736  : m_Rows(rows)
2737  , m_Columns(columns)
2738  , m_pData(NULL)
2739  {
2740  Allocate();
2741 
2742  Clear();
2743  }
2744 
2748  virtual ~Matrix()
2749  {
2750  delete [] m_pData;
2751  }
2752 
2753  public:
2757  void Clear()
2758  {
2759  if (m_pData != NULL)
2760  {
2761  memset(m_pData, 0, sizeof(kt_double) * m_Rows * m_Columns);
2762  }
2763  }
2764 
2769  inline kt_int32u GetRows() const
2770  {
2771  return m_Rows;
2772  }
2773 
2778  inline kt_int32u GetColumns() const
2779  {
2780  return m_Columns;
2781  }
2782 
2790  {
2791  RangeCheck(row, column);
2792 
2793  return m_pData[row + column * m_Rows];
2794  }
2795 
2802  inline const kt_double& operator()(kt_int32u row, kt_int32u column) const
2803  {
2804  RangeCheck(row, column);
2805 
2806  return m_pData[row + column * m_Rows];
2807  }
2808 
2809  private:
2813  void Allocate()
2814  {
2815  try
2816  {
2817  if (m_pData != NULL)
2818  {
2819  delete[] m_pData;
2820  }
2821 
2822  m_pData = new kt_double[m_Rows * m_Columns];
2823  }
2824  catch (const std::bad_alloc& ex)
2825  {
2826  throw Exception("Matrix allocation error");
2827  }
2828 
2829  if (m_pData == NULL)
2830  {
2831  throw Exception("Matrix allocation error");
2832  }
2833  }
2834 
2840  inline void RangeCheck(kt_int32u row, kt_int32u column) const
2841  {
2842  if (math::IsUpTo(row, m_Rows) == false)
2843  {
2844  throw Exception("Matrix - RangeCheck ERROR!!!!");
2845  }
2846 
2847  if (math::IsUpTo(column, m_Columns) == false)
2848  {
2849  throw Exception("Matrix - RangeCheck ERROR!!!!");
2850  }
2851  }
2852 
2853  private:
2856 
2858  }; // Matrix
2859 
2863 
2868  {
2869  public:
2870  /*
2871  * Default constructor
2872  */
2874  : m_Minimum(999999999999999999.99999, 999999999999999999.99999)
2875  , m_Maximum(-999999999999999999.99999, -999999999999999999.99999)
2876  {
2877  }
2878 
2879  public:
2883  inline const Vector2<kt_double>& GetMinimum() const
2884  {
2885  return m_Minimum;
2886  }
2887 
2891  inline void SetMinimum(const Vector2<kt_double>& mMinimum)
2892  {
2893  m_Minimum = mMinimum;
2894  }
2895 
2899  inline const Vector2<kt_double>& GetMaximum() const
2900  {
2901  return m_Maximum;
2902  }
2903 
2907  inline void SetMaximum(const Vector2<kt_double>& rMaximum)
2908  {
2909  m_Maximum = rMaximum;
2910  }
2911 
2915  inline Size2<kt_double> GetSize() const
2916  {
2917  Vector2<kt_double> size = m_Maximum - m_Minimum;
2918 
2919  return Size2<kt_double>(size.GetX(), size.GetY());
2920  }
2921 
2925  inline void Add(const Vector2<kt_double>& rPoint)
2926  {
2927  m_Minimum.MakeFloor(rPoint);
2928  m_Maximum.MakeCeil(rPoint);
2929  }
2930 
2934  inline void Add(const BoundingBox2& rBoundingBox)
2935  {
2936  Add(rBoundingBox.GetMinimum());
2937  Add(rBoundingBox.GetMaximum());
2938  }
2939 
2945  inline kt_bool IsInBounds(const Vector2<kt_double>& rPoint) const
2946  {
2947  return (math::InRange(rPoint.GetX(), m_Minimum.GetX(), m_Maximum.GetX()) &&
2948  math::InRange(rPoint.GetY(), m_Minimum.GetY(), m_Maximum.GetY()));
2949  }
2950 
2954  friend class boost::serialization::access;
2955  template<class Archive>
2956  void serialize(Archive &ar, const unsigned int version)
2957  {
2958  ar & BOOST_SERIALIZATION_NVP(m_Minimum);
2959  ar & BOOST_SERIALIZATION_NVP(m_Maximum);
2960  }
2961 
2962  private:
2965  }; // BoundingBox2
2966 
2970 
2975  {
2976  public:
2981  Transform(const Pose2& rPose)
2982  {
2983  SetTransform(Pose2(), rPose);
2984  }
2985 
2991  Transform(const Pose2& rPose1, const Pose2& rPose2)
2992  {
2993  SetTransform(rPose1, rPose2);
2994  }
2995 
2996  public:
3002  inline Pose2 TransformPose(const Pose2& rSourcePose)
3003  {
3004  Pose2 newPosition = m_Transform + m_Rotation * rSourcePose;
3005  kt_double angle = math::NormalizeAngle(rSourcePose.GetHeading() + m_Transform.GetHeading());
3006 
3007  return Pose2(newPosition.GetPosition(), angle);
3008  }
3009 
3015  inline Pose2 InverseTransformPose(const Pose2& rSourcePose)
3016  {
3017  Pose2 newPosition = m_InverseRotation * (rSourcePose - m_Transform);
3018  kt_double angle = math::NormalizeAngle(rSourcePose.GetHeading() - m_Transform.GetHeading());
3019 
3020  // components of transform
3021  return Pose2(newPosition.GetPosition(), angle);
3022  }
3023 
3024  private:
3030  void SetTransform(const Pose2& rPose1, const Pose2& rPose2)
3031  {
3032  if (rPose1 == rPose2)
3033  {
3034  m_Rotation.SetToIdentity();
3035  m_InverseRotation.SetToIdentity();
3036  m_Transform = Pose2();
3037  return;
3038  }
3039 
3040  // heading transformation
3041  m_Rotation.FromAxisAngle(0, 0, 1, rPose2.GetHeading() - rPose1.GetHeading());
3042  m_InverseRotation.FromAxisAngle(0, 0, 1, rPose1.GetHeading() - rPose2.GetHeading());
3043 
3044  // position transformation
3045  Pose2 newPosition;
3046  if (rPose1.GetX() != 0.0 || rPose1.GetY() != 0.0)
3047  {
3048  newPosition = rPose2 - m_Rotation * rPose1;
3049  }
3050  else
3051  {
3052  newPosition = rPose2;
3053  }
3054 
3055  m_Transform = Pose2(newPosition.GetPosition(), rPose2.GetHeading() - rPose1.GetHeading());
3056  }
3057 
3058  private:
3059  // pose transformation
3061 
3064 
3065  friend class boost::serialization::access;
3066  template<class Archive>
3067  void serialize(Archive &ar, const unsigned int version)
3068  {
3069  ar & BOOST_SERIALIZATION_NVP(m_Transform);
3070  ar & BOOST_SERIALIZATION_NVP(m_Rotation);
3071  ar & BOOST_SERIALIZATION_NVP(m_InverseRotation);
3072  }
3073  }; // Transform
3074 
3078 
3082  typedef enum
3083  {
3085 
3089 
3093 
3097 
3102  {
3103 
3104  public:
3106  {
3107  }
3113  AbstractParameter(const std::string& rName, ParameterManager* pParameterManger = NULL)
3114  : m_Name(rName)
3115  {
3116  // if parameter manager is provided add myself to it!
3117  if (pParameterManger != NULL)
3118  {
3119  pParameterManger->Add(this);
3120  }
3121  }
3122 
3129  AbstractParameter(const std::string& rName,
3130  const std::string& rDescription,
3131  ParameterManager* pParameterManger = NULL)
3132  : m_Name(rName)
3133  , m_Description(rDescription)
3134  {
3135  // if parameter manager is provided add myself to it!
3136  if (pParameterManger != NULL)
3137  {
3138  pParameterManger->Add(this);
3139  }
3140  }
3141 
3146  {
3147  }
3148 
3149  public:
3154  inline const std::string& GetName() const
3155  {
3156  return m_Name;
3157  }
3158 
3163  inline const std::string& GetDescription() const
3164  {
3165  return m_Description;
3166  }
3167 
3172  virtual const std::string GetValueAsString() const = 0;
3173 
3178  virtual void SetValueFromString(const std::string& rStringValue) = 0;
3179 
3184  virtual AbstractParameter* Clone() = 0;
3185 
3186  public:
3192  friend std::ostream& operator << (std::ostream& rStream, const AbstractParameter& rParameter)
3193  {
3194  rStream.precision(6);
3195  rStream.flags(std::ios::fixed);
3196 
3197  rStream << rParameter.GetName() << " = " << rParameter.GetValueAsString();
3198  return rStream;
3199  }
3200 
3201  private:
3202  std::string m_Name;
3203  std::string m_Description;
3207  friend class boost::serialization::access;
3208  template<class Archive>
3209  void serialize(Archive &ar, const unsigned int version)
3210  {
3211  ar & BOOST_SERIALIZATION_NVP(m_Name);
3212  ar & BOOST_SERIALIZATION_NVP(m_Description);
3213  }
3214  }; // AbstractParameter
3215  BOOST_SERIALIZATION_ASSUME_ABSTRACT(AbstractParameter)
3216 
3217 
3218 
3224  template<typename T>
3226  {
3227  public:
3235  {
3236  }
3237  Parameter(const std::string& rName, T value, ParameterManager* pParameterManger = NULL)
3238  : AbstractParameter(rName, pParameterManger)
3239  , m_Value(value)
3240  {
3241  }
3242 
3250  Parameter(const std::string& rName,
3251  const std::string& rDescription,
3252  T value,
3253  ParameterManager* pParameterManger = NULL)
3254  : AbstractParameter(rName, rDescription, pParameterManger)
3255  , m_Value(value)
3256  {
3257  }
3258 
3262  virtual ~Parameter()
3263  {
3264  }
3265 
3266  public:
3271  inline const T& GetValue() const
3272  {
3273  return m_Value;
3274  }
3275 
3280  inline void SetValue(const T& rValue)
3281  {
3282  m_Value = rValue;
3283  }
3284 
3289  virtual const std::string GetValueAsString() const
3290  {
3291  std::stringstream converter;
3292  converter << m_Value;
3293  return converter.str();
3294  }
3295 
3300  virtual void SetValueFromString(const std::string& rStringValue)
3301  {
3302  std::stringstream converter;
3303  converter.str(rStringValue);
3304  converter >> m_Value;
3305  }
3306 
3311  virtual Parameter* Clone()
3312  {
3313  return new Parameter(GetName(), GetDescription(), GetValue());
3314  }
3315 
3316  public:
3320  Parameter& operator = (const Parameter& rOther)
3321  {
3322  m_Value = rOther.m_Value;
3323 
3324  return *this;
3325  }
3326 
3330  T operator = (T value)
3331  {
3332  m_Value = value;
3333 
3334  return m_Value;
3335  }
3336 
3340  friend class boost::serialization::access;
3341  template<class Archive>
3342  void serialize(Archive &ar, const unsigned int version)
3343  {
3344  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(AbstractParameter);
3345  ar & BOOST_SERIALIZATION_NVP(m_Value);
3346  }
3347 
3348  protected:
3353  }; // Parameter
3354  BOOST_SERIALIZATION_ASSUME_ABSTRACT(Parameter)
3355 
3356  template<>
3357  inline void Parameter<kt_double>::SetValueFromString(const std::string& rStringValue)
3358  {
3359  int precision = std::numeric_limits<double>::digits10;
3360  std::stringstream converter;
3361  converter.precision(precision);
3362 
3363  converter.str(rStringValue);
3364 
3365  m_Value = 0.0;
3366  converter >> m_Value;
3367  }
3368 
3369  template<>
3370  inline const std::string Parameter<kt_double>::GetValueAsString() const
3371  {
3372  std::stringstream converter;
3373  converter.precision(std::numeric_limits<double>::digits10);
3374  converter << m_Value;
3375  return converter.str();
3376  }
3377 
3378  template<>
3379  inline void Parameter<kt_bool>::SetValueFromString(const std::string& rStringValue)
3380  {
3381  if (rStringValue == "true" || rStringValue == "TRUE")
3382  {
3383  m_Value = true;
3384  }
3385  else
3386  {
3387  m_Value = false;
3388  }
3389  }
3390 
3391  template<>
3392  inline const std::string Parameter<kt_bool>::GetValueAsString() const
3393  {
3394  if (m_Value == true)
3395  {
3396  return "true";
3397  }
3398 
3399  return "false";
3400  }
3401 
3405 
3409  class ParameterEnum : public Parameter<kt_int32s>
3410  {
3411  typedef std::map<std::string, kt_int32s> EnumMap;
3412 
3413  public:
3420  ParameterEnum(const std::string& rName, kt_int32s value, ParameterManager* pParameterManger = NULL)
3421  : Parameter<kt_int32s>(rName, value, pParameterManger)
3422  {
3423  }
3425  {
3426  }
3427 
3431  virtual ~ParameterEnum()
3432  {
3433  }
3434 
3435  public:
3441  {
3442  ParameterEnum* pEnum = new ParameterEnum(GetName(), GetValue());
3443 
3444  pEnum->m_EnumDefines = m_EnumDefines;
3445 
3446  return pEnum;
3447  }
3448 
3453  virtual void SetValueFromString(const std::string& rStringValue)
3454  {
3455  if (m_EnumDefines.find(rStringValue) != m_EnumDefines.end())
3456  {
3457  m_Value = m_EnumDefines[rStringValue];
3458  }
3459  else
3460  {
3461  std::string validValues;
3462 
3463  const_forEach(EnumMap, &m_EnumDefines)
3464  {
3465  validValues += iter->first + ", ";
3466  }
3467 
3468  throw Exception("Unable to set enum: " + rStringValue + ". Valid values are: " + validValues);
3469  }
3470  }
3471 
3476  virtual const std::string GetValueAsString() const
3477  {
3478  const_forEach(EnumMap, &m_EnumDefines)
3479  {
3480  if (iter->second == m_Value)
3481  {
3482  return iter->first;
3483  }
3484  }
3485 
3486  throw Exception("Unable to lookup enum");
3487  }
3488 
3494  void DefineEnumValue(kt_int32s value, const std::string& rName)
3495  {
3496  if (m_EnumDefines.find(rName) == m_EnumDefines.end())
3497  {
3498  m_EnumDefines[rName] = value;
3499  }
3500  else
3501  {
3502  std::cerr << "Overriding enum value: " << m_EnumDefines[rName] << " with " << value << std::endl;
3503 
3504  m_EnumDefines[rName] = value;
3505 
3506  assert(false);
3507  }
3508  }
3509 
3510  public:
3514  ParameterEnum& operator = (const ParameterEnum& rOther)
3515  {
3516  SetValue(rOther.GetValue());
3517 
3518  return *this;
3519  }
3520 
3524  kt_int32s operator = (kt_int32s value)
3525  {
3526  SetValue(value);
3527 
3528  return m_Value;
3529  }
3530 
3531  private:
3532  EnumMap m_EnumDefines;
3533 
3534  friend class boost::serialization::access;
3535  template<class Archive>
3536  void serialize(Archive &ar, const unsigned int version)
3537  {
3538  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Parameter<kt_int32s>);
3539  ar & BOOST_SERIALIZATION_NVP(m_EnumDefines);
3540  }
3541  }; // ParameterEnum
3542  BOOST_SERIALIZATION_ASSUME_ABSTRACT(ParameterEnum)
3546 
3550  class Parameters : public Object
3551  {
3552  public:
3553  // @cond EXCLUDE
3555  // @endcond
3556 
3557  public:
3563  {
3564  }
3565  Parameters(const std::string& rName)
3566  : Object(rName)
3567  {
3568  }
3569 
3573  virtual ~Parameters()
3574  {
3575  }
3576 
3577  friend class boost::serialization::access;
3578  template<class Archive>
3579  void serialize(Archive &ar, const unsigned int version)
3580  {
3581  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Object);
3582  }
3583 
3584  private:
3585  Parameters(const Parameters&);
3586  const Parameters& operator=(const Parameters&);
3587  }; // Parameters
3588 
3592 
3593  class SensorData;
3594 
3598  class KARTO_EXPORT Sensor : public Object
3599  {
3600 
3604  public:
3606  {
3607  }
3608  // @cond EXCLUDE
3610  // @endcond
3611 
3612  protected:
3617  Sensor(const Name& rName);
3618 
3619  public:
3623  virtual ~Sensor();
3624 
3625  public:
3630  inline const Pose2& GetOffsetPose() const
3631  {
3632  return m_pOffsetPose->GetValue();
3633  }
3634 
3639  inline void SetOffsetPose(const Pose2& rPose)
3640  {
3641  m_pOffsetPose->SetValue(rPose);
3642  }
3643 
3648  virtual kt_bool Validate() = 0;
3649 
3655  virtual kt_bool Validate(SensorData* pSensorData) = 0;
3656 
3657  private:
3661  Sensor(const Sensor&);
3662 
3666  const Sensor& operator=(const Sensor&);
3667 
3668  private:
3673  friend class boost::serialization::access;
3674  template<class Archive>
3675  void serialize(Archive &ar, const unsigned int version)
3676  {
3677  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Object);
3678  ar & BOOST_SERIALIZATION_NVP(m_pOffsetPose);
3679  }
3680  }; // Sensor
3681  BOOST_SERIALIZATION_ASSUME_ABSTRACT(Sensor)
3685  typedef std::vector<Sensor*> SensorVector;
3686 
3690 
3694  typedef std::map<Name, Sensor*> SensorManagerMap;
3695 
3700  {
3701  public:
3706  {
3707  }
3708 
3712  virtual ~SensorManager()
3713  {
3714  }
3715 
3716  public:
3720  static SensorManager* GetInstance();
3721 
3722  public:
3730  void RegisterSensor(Sensor* pSensor, kt_bool override = false)
3731  {
3732  Validate(pSensor);
3733 
3734  if ((m_Sensors.find(pSensor->GetName()) != m_Sensors.end()) && !override)
3735  {
3736  throw Exception("Cannot register sensor: already registered: [" +
3737  pSensor->GetName().ToString() +
3738  "] (Consider setting 'override' to true)");
3739  }
3740 
3741  std::cout << "Registering sensor: [" << pSensor->GetName().ToString() << "]" << std::endl;
3742 
3743  m_Sensors[pSensor->GetName()] = pSensor;
3744  }
3745 
3750  void UnregisterSensor(Sensor* pSensor)
3751  {
3752  Validate(pSensor);
3753 
3754  if (m_Sensors.find(pSensor->GetName()) != m_Sensors.end())
3755  {
3756  std::cout << "Unregistering sensor: " << pSensor->GetName().ToString() << std::endl;
3757 
3758  m_Sensors.erase(pSensor->GetName());
3759  }
3760  else
3761  {
3762  throw Exception("Cannot unregister sensor: not registered: [" + pSensor->GetName().ToString() + "]");
3763  }
3764  }
3765 
3771  Sensor* GetSensorByName(const Name& rName)
3772  {
3773  if (m_Sensors.find(rName) != m_Sensors.end())
3774  {
3775  return m_Sensors[rName];
3776  }
3777 
3778  throw Exception("Sensor not registered: [" + rName.ToString() + "] (Did you add the sensor to the Dataset?)");
3779  }
3780 
3786  template<class T>
3787  T* GetSensorByName(const Name& rName)
3788  {
3789  Sensor* pSensor = GetSensorByName(rName);
3790 
3791  return dynamic_cast<T*>(pSensor);
3792  }
3793 
3799  {
3800  SensorVector sensors;
3801 
3802  forEach(SensorManagerMap, &m_Sensors)
3803  {
3804  sensors.push_back(iter->second);
3805  }
3806 
3807  return sensors;
3808  }
3809 
3810  protected:
3815  static void Validate(Sensor* pSensor)
3816  {
3817  if (pSensor == NULL)
3818  {
3819  throw Exception("Invalid sensor: NULL");
3820  }
3821  else if (pSensor->GetName().ToString() == "")
3822  {
3823  throw Exception("Invalid sensor: nameless");
3824  }
3825  }
3826 
3827  protected:
3832 
3833  friend class boost::serialization::access;
3834  template<class Archive>
3835  void serialize(Archive &ar, const unsigned int version)
3836  {
3837  ar & BOOST_SERIALIZATION_NVP(m_Sensors);
3838  }
3839  };
3840 
3844 
3851  class Drive : public Sensor
3852  {
3853  public:
3854  // @cond EXCLUDE
3856  // @endcond
3857 
3858  public:
3862  Drive(const std::string& rName)
3863  : Sensor(rName)
3864  {
3865  }
3869  virtual ~Drive()
3870  {
3871  }
3872 
3873  public:
3874  virtual kt_bool Validate()
3875  {
3876  return true;
3877  }
3878 
3879  virtual kt_bool Validate(SensorData* pSensorData)
3880  {
3881  if (pSensorData == NULL)
3882  {
3883  return false;
3884  }
3885 
3886  return true;
3887  }
3888 
3889  private:
3890  Drive(const Drive&);
3891  const Drive& operator=(const Drive&);
3892  friend class boost::serialization::access;
3893  template<class Archive>
3894  void serialize(Archive &ar, const unsigned int version)
3895  {
3896  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Sensor);
3897  }
3898  }; // class Drive
3899 
3900  BOOST_SERIALIZATION_ASSUME_ABSTRACT(Drive)
3904 
3905  class LocalizedRangeScan;
3906  class CoordinateConverter;
3907 
3921  {
3922  public:
3924  {
3925  }
3926  // @cond EXCLUDE
3928  // @endcond
3929 
3930  public:
3935  {
3936  }
3937 
3938  public:
3944  {
3945  return m_pMinimumRange->GetValue();
3946  }
3947 
3952  inline void SetMinimumRange(kt_double minimumRange)
3953  {
3954  m_pMinimumRange->SetValue(minimumRange);
3955 
3956  SetRangeThreshold(GetRangeThreshold());
3957  }
3958 
3964  {
3965  return m_pMaximumRange->GetValue();
3966  }
3967 
3972  inline void SetMaximumRange(kt_double maximumRange)
3973  {
3974  m_pMaximumRange->SetValue(maximumRange);
3975 
3976  SetRangeThreshold(GetRangeThreshold());
3977  }
3978 
3984  {
3985  return m_pRangeThreshold->GetValue();
3986  }
3987 
3992  inline void SetRangeThreshold(kt_double rangeThreshold)
3993  {
3994  // make sure rangeThreshold is within laser range finder range
3995  m_pRangeThreshold->SetValue(math::Clip(rangeThreshold, GetMinimumRange(), GetMaximumRange()));
3996 
3997  if (math::DoubleEqual(GetRangeThreshold(), rangeThreshold) == false)
3998  {
3999  std::cout << "Info: clipped range threshold to be within minimum and maximum range!" << std::endl;
4000  }
4001  }
4002 
4008  {
4009  return m_pMinimumAngle->GetValue();
4010  }
4011 
4016  inline void SetMinimumAngle(kt_double minimumAngle)
4017  {
4018  m_pMinimumAngle->SetValue(minimumAngle);
4019 
4020  Update();
4021  }
4022 
4028  {
4029  return m_pMaximumAngle->GetValue();
4030  }
4031 
4036  inline void SetMaximumAngle(kt_double maximumAngle)
4037  {
4038  m_pMaximumAngle->SetValue(maximumAngle);
4039 
4040  Update();
4041  }
4042 
4048  {
4049  return m_pAngularResolution->GetValue();
4050  }
4051 
4056  inline void SetAngularResolution(kt_double angularResolution)
4057  {
4058  if (m_pType->GetValue() == LaserRangeFinder_Custom)
4059  {
4060  m_pAngularResolution->SetValue(angularResolution);
4061  }
4062  else if (m_pType->GetValue() == LaserRangeFinder_Sick_LMS100)
4063  {
4064  if (math::DoubleEqual(angularResolution, math::DegreesToRadians(0.25)))
4065  {
4066  m_pAngularResolution->SetValue(math::DegreesToRadians(0.25));
4067  }
4068  else if (math::DoubleEqual(angularResolution, math::DegreesToRadians(0.50)))
4069  {
4070  m_pAngularResolution->SetValue(math::DegreesToRadians(0.50));
4071  }
4072  else
4073  {
4074  std::stringstream stream;
4075  stream << "Invalid resolution for Sick LMS100: ";
4076  stream << angularResolution;
4077  throw Exception(stream.str());
4078  }
4079  }
4080  else if (m_pType->GetValue() == LaserRangeFinder_Sick_LMS200 ||
4081  m_pType->GetValue() == LaserRangeFinder_Sick_LMS291)
4082  {
4083  if (math::DoubleEqual(angularResolution, math::DegreesToRadians(0.25)))
4084  {
4085  m_pAngularResolution->SetValue(math::DegreesToRadians(0.25));
4086  }
4087  else if (math::DoubleEqual(angularResolution, math::DegreesToRadians(0.50)))
4088  {
4089  m_pAngularResolution->SetValue(math::DegreesToRadians(0.50));
4090  }
4091  else if (math::DoubleEqual(angularResolution, math::DegreesToRadians(1.00)))
4092  {
4093  m_pAngularResolution->SetValue(math::DegreesToRadians(1.00));
4094  }
4095  else
4096  {
4097  std::stringstream stream;
4098  stream << "Invalid resolution for Sick LMS291: ";
4099  stream << angularResolution;
4100  throw Exception(stream.str());
4101  }
4102  }
4103  else
4104  {
4105  throw Exception("Can't set angular resolution, please create a LaserRangeFinder of type Custom");
4106  }
4107 
4108  Update();
4109  }
4110 
4115  {
4116  return m_pType->GetValue();
4117  }
4118 
4124  {
4125  return m_NumberOfRangeReadings;
4126  }
4127 
4128 
4133  inline kt_bool GetIs360Laser() const
4134  {
4135  return m_pIs360Laser->GetValue();
4136  }
4137 
4142  inline void SetIs360Laser(bool is_360_laser)
4143  {
4144  m_pIs360Laser->SetValue(is_360_laser);
4145 
4146  Update();
4147  }
4148 
4149 
4150  virtual kt_bool Validate()
4151  {
4152  Update();
4153 
4154  if (math::InRange(GetRangeThreshold(), GetMinimumRange(), GetMaximumRange()) == false)
4155  {
4156  std::cout << "Please set range threshold to a value between ["
4157  << GetMinimumRange() << ";" << GetMaximumRange() << "]" << std::endl;
4158  return false;
4159  }
4160 
4161  return true;
4162  }
4163 
4164  virtual kt_bool Validate(SensorData* pSensorData);
4165 
4173  const PointVectorDouble GetPointReadings(LocalizedRangeScan* pLocalizedRangeScan,
4174  CoordinateConverter* pCoordinateConverter,
4175  kt_bool ignoreThresholdPoints = true,
4176  kt_bool flipY = false) const;
4177 
4178  public:
4186  {
4187  LaserRangeFinder* pLrf = NULL;
4188 
4189  switch (type)
4190  {
4191  // see http://www.hizook.com/files/publications/SICK_LMS100.pdf
4192  // set range threshold to 18m
4194  {
4195  pLrf = new LaserRangeFinder((rName.GetName() != "") ? rName : Name("Sick LMS 100"));
4196 
4197  // Sensing range is 18 meters (at 10% reflectivity, max range of 20 meters), with an error of about 20mm
4198  pLrf->m_pMinimumRange->SetValue(0.0);
4199  pLrf->m_pMaximumRange->SetValue(20.0);
4200 
4201  // 270 degree range, 50 Hz
4204 
4205  // 0.25 degree angular resolution
4207 
4208  pLrf->m_NumberOfRangeReadings = 1081;
4209  }
4210  break;
4211 
4212  // see http://www.hizook.com/files/publications/SICK_LMS200-291_Tech_Info.pdf
4213  // set range threshold to 10m
4215  {
4216  pLrf = new LaserRangeFinder((rName.GetName() != "") ? rName : Name("Sick LMS 200"));
4217 
4218  // Sensing range is 80 meters
4219  pLrf->m_pMinimumRange->SetValue(0.0);
4220  pLrf->m_pMaximumRange->SetValue(80.0);
4221 
4222  // 180 degree range, 75 Hz
4225 
4226  // 0.5 degree angular resolution
4228 
4229  pLrf->m_NumberOfRangeReadings = 361;
4230  }
4231  break;
4232 
4233  // see http://www.hizook.com/files/publications/SICK_LMS200-291_Tech_Info.pdf
4234  // set range threshold to 30m
4236  {
4237  pLrf = new LaserRangeFinder((rName.GetName() != "") ? rName : Name("Sick LMS 291"));
4238 
4239  // Sensing range is 80 meters
4240  pLrf->m_pMinimumRange->SetValue(0.0);
4241  pLrf->m_pMaximumRange->SetValue(80.0);
4242 
4243  // 180 degree range, 75 Hz
4246 
4247  // 0.5 degree angular resolution
4249 
4250  pLrf->m_NumberOfRangeReadings = 361;
4251  }
4252  break;
4253 
4254  // see http://www.hizook.com/files/publications/Hokuyo_UTM_LaserRangeFinder_LIDAR.pdf
4255  // set range threshold to 30m
4257  {
4258  pLrf = new LaserRangeFinder((rName.GetName() != "") ? rName : Name("Hokuyo UTM-30LX"));
4259 
4260  // Sensing range is 30 meters
4261  pLrf->m_pMinimumRange->SetValue(0.1);
4262  pLrf->m_pMaximumRange->SetValue(30.0);
4263 
4264  // 270 degree range, 40 Hz
4267 
4268  // 0.25 degree angular resolution
4270 
4271  pLrf->m_NumberOfRangeReadings = 1081;
4272  }
4273  break;
4274 
4275  // see http://www.hizook.com/files/publications/HokuyoURG_Datasheet.pdf
4276  // set range threshold to 3.5m
4278  {
4279  pLrf = new LaserRangeFinder((rName.GetName() != "") ? rName : Name("Hokuyo URG-04LX"));
4280 
4281  // Sensing range is 4 meters. It has detection problems when
4282  // scanning absorptive surfaces (such as black trimming).
4283  pLrf->m_pMinimumRange->SetValue(0.02);
4284  pLrf->m_pMaximumRange->SetValue(4.0);
4285 
4286  // 240 degree range, 10 Hz
4289 
4290  // 0.352 degree angular resolution
4292 
4293  pLrf->m_NumberOfRangeReadings = 751;
4294  }
4295  break;
4296 
4298  {
4299  pLrf = new LaserRangeFinder((rName.GetName() != "") ? rName : Name("User-Defined LaserRangeFinder"));
4300 
4301  // Sensing range is 80 meters.
4302  pLrf->m_pMinimumRange->SetValue(0.0);
4303  pLrf->m_pMaximumRange->SetValue(80.0);
4304 
4305  // 180 degree range
4308 
4309  // 1.0 degree angular resolution
4311 
4312  pLrf->m_NumberOfRangeReadings = 181;
4313  }
4314  break;
4315  }
4316 
4317  if (pLrf != NULL)
4318  {
4319  pLrf->m_pType->SetValue(type);
4320 
4321  Pose2 defaultOffset;
4322  pLrf->SetOffsetPose(defaultOffset);
4323  }
4324 
4325  return pLrf;
4326  }
4327 
4328  private:
4332  LaserRangeFinder(const Name& rName)
4333  : Sensor(rName)
4334  , m_NumberOfRangeReadings(0)
4335  {
4336  m_pMinimumRange = new Parameter<kt_double>("MinimumRange", 0.0, GetParameterManager());
4337  m_pMaximumRange = new Parameter<kt_double>("MaximumRange", 80.0, GetParameterManager());
4338 
4339  m_pMinimumAngle = new Parameter<kt_double>("MinimumAngle", -KT_PI_2, GetParameterManager());
4340  m_pMaximumAngle = new Parameter<kt_double>("MaximumAngle", KT_PI_2, GetParameterManager());
4341 
4342  m_pAngularResolution = new Parameter<kt_double>("AngularResolution",
4344  GetParameterManager());
4345 
4346  m_pRangeThreshold = new Parameter<kt_double>("RangeThreshold", 12.0, GetParameterManager());
4347 
4348  m_pIs360Laser = new Parameter<kt_bool>("Is360DegreeLaser", false, GetParameterManager());
4349 
4350  m_pType = new ParameterEnum("Type", LaserRangeFinder_Custom, GetParameterManager());
4351  m_pType->DefineEnumValue(LaserRangeFinder_Custom, "Custom");
4352  m_pType->DefineEnumValue(LaserRangeFinder_Sick_LMS100, "Sick_LMS100");
4353  m_pType->DefineEnumValue(LaserRangeFinder_Sick_LMS200, "Sick_LMS200");
4354  m_pType->DefineEnumValue(LaserRangeFinder_Sick_LMS291, "Sick_LMS291");
4355  m_pType->DefineEnumValue(LaserRangeFinder_Hokuyo_UTM_30LX, "Hokuyo_UTM_30LX");
4356  m_pType->DefineEnumValue(LaserRangeFinder_Hokuyo_URG_04LX, "Hokuyo_URG_04LX");
4357  }
4358 
4363  void Update()
4364  {
4365  int residual = 1;
4366  if (GetIs360Laser())
4367  {
4368  // residual is 0 by 360 lidar conventions
4369  residual = 0;
4370  }
4371  m_NumberOfRangeReadings = static_cast<kt_int32u>(math::Round((GetMaximumAngle() -
4372  GetMinimumAngle())
4373  / GetAngularResolution()) + residual);
4374  }
4375 
4376  private:
4378  const LaserRangeFinder& operator=(const LaserRangeFinder&);
4379 
4380  private:
4381  // sensor m_Parameters
4384 
4386 
4389 
4391 
4393 
4395 
4397 
4398  // static std::string LaserRangeFinderTypeNames[6];
4399  friend class boost::serialization::access;
4400  template<class Archive>
4401  void serialize(Archive &ar, const unsigned int version)
4402  {
4403  if (Archive::is_loading::value)
4404  {
4405  m_pMinimumRange = new Parameter<kt_double>("MinimumRange", 0.0, GetParameterManager());
4406  m_pMaximumRange = new Parameter<kt_double>("MaximumRange", 80.0, GetParameterManager());
4407 
4408  m_pMinimumAngle = new Parameter<kt_double>("MinimumAngle", -KT_PI_2, GetParameterManager());
4409  m_pMaximumAngle = new Parameter<kt_double>("MaximumAngle", KT_PI_2, GetParameterManager());
4410 
4411  m_pAngularResolution = new Parameter<kt_double>("AngularResolution",
4413  GetParameterManager());
4414 
4415  m_pRangeThreshold = new Parameter<kt_double>("RangeThreshold", 12.0, GetParameterManager());
4416 
4417  m_pIs360Laser = new Parameter<kt_bool>("Is360DegreeLaser", false, GetParameterManager());
4418 
4419  m_pType = new ParameterEnum("Type", LaserRangeFinder_Custom, GetParameterManager());
4420  }
4421 
4422  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Sensor);
4423  ar & BOOST_SERIALIZATION_NVP(m_pMinimumAngle);
4424  ar & BOOST_SERIALIZATION_NVP(m_pMaximumAngle);
4425  ar & BOOST_SERIALIZATION_NVP(m_pAngularResolution);
4426  ar & BOOST_SERIALIZATION_NVP(m_pMinimumRange);
4427  ar & BOOST_SERIALIZATION_NVP(m_pMaximumRange);
4428  ar & BOOST_SERIALIZATION_NVP(m_pRangeThreshold);
4429  ar & BOOST_SERIALIZATION_NVP(m_pIs360Laser);
4430  ar & BOOST_SERIALIZATION_NVP(m_pType);
4431  ar & BOOST_SERIALIZATION_NVP(m_NumberOfRangeReadings);
4432  }
4433  }; // LaserRangeFinder
4434  BOOST_SERIALIZATION_ASSUME_ABSTRACT(LaserRangeFinder)
4438 
4442  typedef enum
4443  {
4447  } GridStates;
4448 
4452 
4459  {
4460  public:
4465  : m_Scale(20.0)
4466  {
4467  }
4468 
4469  public:
4476  {
4477  return value * m_Scale;
4478  }
4479 
4486  inline Vector2<kt_int32s> WorldToGrid(const Vector2<kt_double>& rWorld, kt_bool flipY = false) const
4487  {
4488  kt_double gridX = (rWorld.GetX() - m_Offset.GetX()) * m_Scale;
4489  kt_double gridY = 0.0;
4490 
4491  if (flipY == false)
4492  {
4493  gridY = (rWorld.GetY() - m_Offset.GetY()) * m_Scale;
4494  }
4495  else
4496  {
4497  gridY = (m_Size.GetHeight() / m_Scale - rWorld.GetY() + m_Offset.GetY()) * m_Scale;
4498  }
4499 
4500  return Vector2<kt_int32s>(static_cast<kt_int32s>(math::Round(gridX)), static_cast<kt_int32s>(math::Round(gridY)));
4501  }
4502 
4509  inline Vector2<kt_double> GridToWorld(const Vector2<kt_int32s>& rGrid, kt_bool flipY = false) const
4510  {
4511  kt_double worldX = m_Offset.GetX() + rGrid.GetX() / m_Scale;
4512  kt_double worldY = 0.0;
4513 
4514  if (flipY == false)
4515  {
4516  worldY = m_Offset.GetY() + rGrid.GetY() / m_Scale;
4517  }
4518  else
4519  {
4520  worldY = m_Offset.GetY() + (m_Size.GetHeight() - rGrid.GetY()) / m_Scale;
4521  }
4522 
4523  return Vector2<kt_double>(worldX, worldY);
4524  }
4525 
4530  inline kt_double GetScale() const
4531  {
4532  return m_Scale;
4533  }
4534 
4539  inline void SetScale(kt_double scale)
4540  {
4541  m_Scale = scale;
4542  }
4543 
4548  inline const Vector2<kt_double>& GetOffset() const
4549  {
4550  return m_Offset;
4551  }
4552 
4557  inline void SetOffset(const Vector2<kt_double>& rOffset)
4558  {
4559  m_Offset = rOffset;
4560  }
4561 
4566  inline void SetSize(const Size2<kt_int32s>& rSize)
4567  {
4568  m_Size = rSize;
4569  }
4570 
4575  inline const Size2<kt_int32s>& GetSize() const
4576  {
4577  return m_Size;
4578  }
4579 
4584  inline kt_double GetResolution() const
4585  {
4586  return 1.0 / m_Scale;
4587  }
4588 
4593  inline void SetResolution(kt_double resolution)
4594  {
4595  m_Scale = 1.0 / resolution;
4596  }
4597 
4603  {
4604  BoundingBox2 box;
4605 
4606  kt_double minX = GetOffset().GetX();
4607  kt_double minY = GetOffset().GetY();
4608  kt_double maxX = minX + GetSize().GetWidth() * GetResolution();
4609  kt_double maxY = minY + GetSize().GetHeight() * GetResolution();
4610 
4611  box.SetMinimum(GetOffset());
4612  box.SetMaximum(Vector2<kt_double>(maxX, maxY));
4613  return box;
4614  }
4615 
4616  private:
4619 
4621  friend class boost::serialization::access;
4622  template<class Archive>
4623  void serialize(Archive &ar, const unsigned int version)
4624  {
4625  ar & BOOST_SERIALIZATION_NVP(m_Size);
4626  ar & BOOST_SERIALIZATION_NVP(m_Scale);
4627  ar & BOOST_SERIALIZATION_NVP(m_Offset);
4628  }
4629 
4630  }; // CoordinateConverter
4631 
4635 
4639  template<typename T>
4640  class Grid
4641  {
4642  public:
4651  {
4652  }
4653  static Grid* CreateGrid(kt_int32s width, kt_int32s height, kt_double resolution)
4654  {
4655  Grid* pGrid = new Grid(width, height);
4656 
4657  pGrid->GetCoordinateConverter()->SetScale(1.0 / resolution);
4658 
4659  return pGrid;
4660  }
4661 
4665  virtual ~Grid()
4666  {
4667  if (m_pData)
4668  {
4669  delete [] m_pData;
4670  }
4671  if (m_pCoordinateConverter)
4672  {
4673  delete m_pCoordinateConverter;
4674  }
4675  }
4676 
4677  public:
4681  void Clear()
4682  {
4683  memset(m_pData, 0, GetDataSize() * sizeof(T));
4684  }
4685 
4691  {
4692  Grid* pGrid = CreateGrid(GetWidth(), GetHeight(), GetResolution());
4693  pGrid->GetCoordinateConverter()->SetOffset(GetCoordinateConverter()->GetOffset());
4694 
4695  memcpy(pGrid->GetDataPointer(), GetDataPointer(), GetDataSize());
4696 
4697  return pGrid;
4698  }
4699 
4705  virtual void Resize(kt_int32s width, kt_int32s height)
4706  {
4707  m_Width = width;
4708  m_Height = height;
4709  m_WidthStep = math::AlignValue<kt_int32s>(width, 8);
4710 
4711  if (m_pData != NULL)
4712  {
4713  delete[] m_pData;
4714  m_pData = NULL;
4715  }
4716 
4717  try
4718  {
4719  m_pData = new T[GetDataSize()];
4720 
4721  if (m_pCoordinateConverter == NULL)
4722  {
4723  m_pCoordinateConverter = new CoordinateConverter();
4724  }
4725 
4726  m_pCoordinateConverter->SetSize(Size2<kt_int32s>(width, height));
4727  }
4728  catch(...)
4729  {
4730  m_pData = NULL;
4731 
4732  m_Width = 0;
4733  m_Height = 0;
4734  m_WidthStep = 0;
4735  }
4736 
4737  Clear();
4738  }
4739 
4744  inline kt_bool IsValidGridIndex(const Vector2<kt_int32s>& rGrid) const
4745  {
4746  return (math::IsUpTo(rGrid.GetX(), m_Width) && math::IsUpTo(rGrid.GetY(), m_Height));
4747  }
4748 
4755  virtual kt_int32s GridIndex(const Vector2<kt_int32s>& rGrid, kt_bool boundaryCheck = true) const
4756  {
4757  if (boundaryCheck == true)
4758  {
4759  if (IsValidGridIndex(rGrid) == false)
4760  {
4761  std::stringstream error;
4762  error << "Index " << rGrid << " out of range. Index must be between [0; "
4763  << m_Width << ") and [0; " << m_Height << ")";
4764  throw Exception(error.str());
4765  }
4766  }
4767 
4768  kt_int32s index = rGrid.GetX() + (rGrid.GetY() * m_WidthStep);
4769 
4770  if (boundaryCheck == true)
4771  {
4772  assert(math::IsUpTo(index, GetDataSize()));
4773  }
4774 
4775  return index;
4776  }
4777 
4784  {
4785  Vector2<kt_int32s> grid;
4786 
4787  grid.SetY(index / m_WidthStep);
4788  grid.SetX(index - grid.GetY() * m_WidthStep);
4789 
4790  return grid;
4791  }
4792 
4799  inline Vector2<kt_int32s> WorldToGrid(const Vector2<kt_double>& rWorld, kt_bool flipY = false) const
4800  {
4801  return GetCoordinateConverter()->WorldToGrid(rWorld, flipY);
4802  }
4803 
4810  inline Vector2<kt_double> GridToWorld(const Vector2<kt_int32s>& rGrid, kt_bool flipY = false) const
4811  {
4812  return GetCoordinateConverter()->GridToWorld(rGrid, flipY);
4813  }
4814 
4821  {
4822  kt_int32s index = GridIndex(rGrid, true);
4823  return m_pData + index;
4824  }
4825 
4831  T* GetDataPointer(const Vector2<kt_int32s>& rGrid) const
4832  {
4833  kt_int32s index = GridIndex(rGrid, true);
4834  return m_pData + index;
4835  }
4836 
4841  inline kt_int32s GetWidth() const
4842  {
4843  return m_Width;
4844  };
4845 
4850  inline kt_int32s GetHeight() const
4851  {
4852  return m_Height;
4853  };
4854 
4859  inline const Size2<kt_int32s> GetSize() const
4860  {
4861  return Size2<kt_int32s>(m_Width, m_Height);
4862  }
4863 
4868  inline kt_int32s GetWidthStep() const
4869  {
4870  return m_WidthStep;
4871  }
4872 
4877  inline T* GetDataPointer()
4878  {
4879  return m_pData;
4880  }
4881 
4886  inline T* GetDataPointer() const
4887  {
4888  return m_pData;
4889  }
4890 
4895  inline kt_int32s GetDataSize() const
4896  {
4897  return m_WidthStep * m_Height;
4898  }
4899 
4905  inline T GetValue(const Vector2<kt_int32s>& rGrid) const
4906  {
4907  kt_int32s index = GridIndex(rGrid);
4908  return m_pData[index];
4909  }
4910 
4916  {
4917  return m_pCoordinateConverter;
4918  }
4919 
4924  inline kt_double GetResolution() const
4925  {
4926  return GetCoordinateConverter()->GetResolution();
4927  }
4928 
4934  {
4935  return GetCoordinateConverter()->GetBoundingBox();
4936  }
4937 
4947  void TraceLine(kt_int32s x0, kt_int32s y0, kt_int32s x1, kt_int32s y1, Functor* f = NULL)
4948  {
4949  kt_bool steep = abs(y1 - y0) > abs(x1 - x0);
4950  if (steep)
4951  {
4952  std::swap(x0, y0);
4953  std::swap(x1, y1);
4954  }
4955  if (x0 > x1)
4956  {
4957  std::swap(x0, x1);
4958  std::swap(y0, y1);
4959  }
4960 
4961  kt_int32s deltaX = x1 - x0;
4962  kt_int32s deltaY = abs(y1 - y0);
4963  kt_int32s error = 0;
4964  kt_int32s ystep;
4965  kt_int32s y = y0;
4966 
4967  if (y0 < y1)
4968  {
4969  ystep = 1;
4970  }
4971  else
4972  {
4973  ystep = -1;
4974  }
4975 
4976  kt_int32s pointX;
4977  kt_int32s pointY;
4978  for (kt_int32s x = x0; x <= x1; x++)
4979  {
4980  if (steep)
4981  {
4982  pointX = y;
4983  pointY = x;
4984  }
4985  else
4986  {
4987  pointX = x;
4988  pointY = y;
4989  }
4990 
4991  error += deltaY;
4992 
4993  if (2 * error >= deltaX)
4994  {
4995  y += ystep;
4996  error -= deltaX;
4997  }
4998 
4999  Vector2<kt_int32s> gridIndex(pointX, pointY);
5000  if (IsValidGridIndex(gridIndex))
5001  {
5002  kt_int32s index = GridIndex(gridIndex, false);
5003  T* pGridPointer = GetDataPointer();
5004  pGridPointer[index]++;
5005 
5006  if (f != NULL)
5007  {
5008  (*f)(index);
5009  }
5010  }
5011  }
5012  }
5013 
5014  protected:
5020  Grid(kt_int32s width, kt_int32s height)
5021  : m_pData(NULL)
5022  , m_pCoordinateConverter(NULL)
5023  {
5024  Resize(width, height);
5025  }
5026 
5027  private:
5028  kt_int32s m_Width; // width of grid
5029  kt_int32s m_Height; // height of grid
5030  kt_int32s m_WidthStep; // 8 bit aligned width of grid
5031  T* m_pData; // grid data
5032 
5033  // coordinate converter to convert between world coordinates and grid coordinates
5035  friend class boost::serialization::access;
5036  template<class Archive>
5037  void serialize(Archive &ar, const unsigned int version)
5038  {
5039  ar & BOOST_SERIALIZATION_NVP(m_Width);
5040  ar & BOOST_SERIALIZATION_NVP(m_Height);
5041  ar & BOOST_SERIALIZATION_NVP(m_WidthStep);
5042  ar & BOOST_SERIALIZATION_NVP(m_pCoordinateConverter);
5043 
5044 
5045  if (Archive::is_loading::value)
5046  {
5047  m_pData = new T[m_WidthStep * m_Height];
5048  }
5049  ar & boost::serialization::make_array<T>(m_pData, m_WidthStep * m_Height);
5050  }
5051 
5052  }; // Grid
5053  BOOST_SERIALIZATION_ASSUME_ABSTRACT(Grid)
5054 
5055 
5056 
5062  class CustomData : public Object
5063  {
5064  public:
5065  // @cond EXCLUDE
5067  // @endcond
5068 
5069  public:
5074  : Object()
5075  {
5076  }
5077 
5081  virtual ~CustomData()
5082  {
5083  }
5084 
5085  public:
5090  virtual const std::string Write() const = 0;
5091 
5096  virtual void Read(const std::string& rValue) = 0;
5097 
5098  private:
5099  CustomData(const CustomData&);
5100  const CustomData& operator=(const CustomData&);
5101 
5102  friend class boost::serialization::access;
5103  template<class Archive>
5104  void serialize(Archive &ar, const unsigned int version)
5105  {
5106  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Object);
5107  }
5108  };
5109  BOOST_SERIALIZATION_ASSUME_ABSTRACT(CustomData)
5110 
5111 
5114  typedef std::vector<CustomData*> CustomDataVector;
5115 
5119 
5124  {
5125  public:
5126  // @cond EXCLUDE
5128  // @endcond
5129 
5130  public:
5131 
5136  virtual ~SensorData();
5137 
5138  public:
5143  inline kt_int32s GetStateId() const
5144  {
5145  return m_StateId;
5146  }
5147 
5152  inline void SetStateId(kt_int32s stateId)
5153  {
5154  m_StateId = stateId;
5155  }
5156 
5161  inline kt_int32s GetUniqueId() const
5162  {
5163  return m_UniqueId;
5164  }
5165 
5170  inline void SetUniqueId(kt_int32u uniqueId)
5171  {
5172  m_UniqueId = uniqueId;
5173  }
5174 
5179  inline kt_double GetTime() const
5180  {
5181  return m_Time;
5182  }
5183 
5188  inline void SetTime(kt_double time)
5189  {
5190  m_Time = time;
5191  }
5192 
5197  inline const Name& GetSensorName() const
5198  {
5199  return m_SensorName;
5200  }
5201 
5206  inline void AddCustomData(CustomData* pCustomData)
5207  {
5208  m_CustomData.push_back(pCustomData);
5209  }
5210 
5215  inline const CustomDataVector& GetCustomData() const
5216  {
5217  return m_CustomData;
5218  }
5219 
5220  protected:
5224  SensorData(const Name& rSensorName);
5225 
5226  private:
5230  SensorData(const SensorData&);
5231 
5235  const SensorData& operator=(const SensorData&);
5236 
5237  private:
5242 
5247 
5252 
5257 
5259 
5260  friend class boost::serialization::access;
5261  template<class Archive>
5262  void serialize(Archive &ar, const unsigned int version)
5263  {
5264  ar & BOOST_SERIALIZATION_NVP(m_StateId);
5265  ar & BOOST_SERIALIZATION_NVP(m_UniqueId);
5266  ar & BOOST_SERIALIZATION_NVP(m_SensorName);
5267  ar & BOOST_SERIALIZATION_NVP(m_Time);
5268  ar & BOOST_SERIALIZATION_NVP(m_CustomData);
5269  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Object);
5270  }
5271 };
5272 
5273 
5277 
5281  typedef std::vector<kt_double> RangeReadingsVector;
5282 
5287  {
5288  public:
5289  // @cond EXCLUDE
5291  // @endcond
5292 
5293  public:
5298  LaserRangeScan(const Name& rSensorName)
5299  : SensorData(rSensorName)
5300  , m_pRangeReadings(NULL)
5301  , m_NumberOfRangeReadings(0)
5302  {
5303  }
5304 
5306  {
5307  }
5308 
5314  LaserRangeScan(const Name& rSensorName, const RangeReadingsVector& rRangeReadings)
5315  : SensorData(rSensorName)
5316  , m_pRangeReadings(NULL)
5317  , m_NumberOfRangeReadings(0)
5318  {
5319  assert(rSensorName.ToString() != "");
5320 
5321  SetRangeReadings(rRangeReadings);
5322  }
5323 
5328  {
5329  delete [] m_pRangeReadings;
5330  m_pRangeReadings = nullptr;
5331  }
5332 
5333  public:
5338  inline kt_double* GetRangeReadings() const
5339  {
5340  return m_pRangeReadings;
5341  }
5342 
5344  {
5345  return RangeReadingsVector(m_pRangeReadings, m_pRangeReadings + m_NumberOfRangeReadings);
5346  }
5347 
5352  inline void SetRangeReadings(const RangeReadingsVector& rRangeReadings)
5353  {
5354  // ignore for now! XXXMAE BUGUBUG 05/21/2010 << TODO(lucbettaieb): What the heck is this??
5355  // if (rRangeReadings.size() != GetNumberOfRangeReadings())
5356  // {
5357  // std::stringstream error;
5358  // error << "Given number of readings (" << rRangeReadings.size()
5359  // << ") does not match expected number of range finder (" << GetNumberOfRangeReadings() << ")";
5360  // throw Exception(error.str());
5361  // }
5362 
5363  if (!rRangeReadings.empty())
5364  {
5365  if (rRangeReadings.size() != m_NumberOfRangeReadings)
5366  {
5367  // delete old readings
5368  delete [] m_pRangeReadings;
5369 
5370  // store size of array!
5371  m_NumberOfRangeReadings = static_cast<kt_int32u>(rRangeReadings.size());
5372 
5373  // allocate range readings
5374  m_pRangeReadings = new kt_double[m_NumberOfRangeReadings];
5375  }
5376 
5377  // copy readings
5378  kt_int32u index = 0;
5379  const_forEach(RangeReadingsVector, &rRangeReadings)
5380  {
5381  m_pRangeReadings[index++] = *iter;
5382  }
5383  }
5384  else
5385  {
5386  delete [] m_pRangeReadings;
5387  m_pRangeReadings = NULL;
5388  }
5389  }
5390 
5396  {
5397  return SensorManager::GetInstance()->GetSensorByName<LaserRangeFinder>(GetSensorName());
5398  }
5399 
5405  {
5406  return m_NumberOfRangeReadings;
5407  }
5408 
5409  private:
5411  const LaserRangeScan& operator=(const LaserRangeScan&);
5412 
5413  private:
5416 
5417  friend class boost::serialization::access;
5418  template<class Archive>
5419  void serialize(Archive &ar, const unsigned int version)
5420  {
5421  ar & BOOST_SERIALIZATION_NVP(m_NumberOfRangeReadings);
5422  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(SensorData);
5423 
5424  if (Archive::is_loading::value)
5425  {
5426  m_pRangeReadings = new kt_double[m_NumberOfRangeReadings];
5427  }
5428  ar & boost::serialization::make_array<kt_double>(m_pRangeReadings, m_NumberOfRangeReadings);
5429  }
5430  }; // LaserRangeScan
5431 
5435 
5439  class DrivePose : public SensorData
5440  {
5441  public:
5442  // @cond EXCLUDE
5444  // @endcond
5445 
5446  public:
5451  DrivePose(const Name& rSensorName)
5452  : SensorData(rSensorName)
5453  {
5454  }
5455 
5459  virtual ~DrivePose()
5460  {
5461  }
5462 
5463  public:
5468  inline const Pose3& GetOdometricPose() const
5469  {
5470  return m_OdometricPose;
5471  }
5472 
5477  inline void SetOdometricPose(const Pose3& rPose)
5478  {
5479  m_OdometricPose = rPose;
5480  }
5481 
5482  private:
5483  DrivePose(const DrivePose&);
5484  const DrivePose& operator=(const DrivePose&);
5485 
5486  private:
5491  }; // class DrivePose
5492 
5496 
5504  {
5505  public:
5506  // @cond EXCLUDE
5508  // @endcond
5509 
5510  public:
5514  LocalizedRangeScan(const Name& rSensorName, const RangeReadingsVector& rReadings)
5515  : LaserRangeScan(rSensorName, rReadings)
5516  , m_IsDirty(true)
5517  {
5518  }
5519 
5521  {}
5522 
5527  {
5528  }
5529 
5530  private:
5531  mutable boost::shared_mutex m_Lock;
5532 
5533  public:
5538  inline const Pose2& GetOdometricPose() const
5539  {
5540  return m_OdometricPose;
5541  }
5542 
5547  inline void SetOdometricPose(const Pose2& rPose)
5548  {
5549  m_OdometricPose = rPose;
5550  }
5551 
5560  inline const Pose2& GetCorrectedPose() const
5561  {
5562  return m_CorrectedPose;
5563  }
5564 
5569  inline void SetCorrectedPose(const Pose2& rPose)
5570  {
5571  m_CorrectedPose = rPose;
5572 
5573  m_IsDirty = true;
5574  }
5575 
5580  inline void SetCorrectedPoseAndUpdate(const Pose2& rPose)
5581  {
5582  SetCorrectedPose(rPose);
5583 
5584  Update();
5585  }
5586 
5590  inline const Pose2& GetBarycenterPose() const
5591  {
5592  boost::shared_lock<boost::shared_mutex> lock(m_Lock);
5593  if (m_IsDirty)
5594  {
5595  // throw away constness and do an update!
5596  lock.unlock();
5597  boost::unique_lock<boost::shared_mutex> uniqueLock(m_Lock);
5598  const_cast<LocalizedRangeScan*>(this)->Update();
5599  }
5600 
5601  return m_BarycenterPose;
5602  }
5603 
5604  inline void SetBarycenterPose(Pose2& bcenter)
5605  {
5606  m_BarycenterPose = bcenter;
5607  }
5608 
5614  inline Pose2 GetReferencePose(kt_bool useBarycenter) const
5615  {
5616  boost::shared_lock<boost::shared_mutex> lock(m_Lock);
5617  if (m_IsDirty)
5618  {
5619  // throw away constness and do an update!
5620  lock.unlock();
5621  boost::unique_lock<boost::shared_mutex> uniqueLock(m_Lock);
5622  const_cast<LocalizedRangeScan*>(this)->Update();
5623  }
5624 
5625  return useBarycenter ? GetBarycenterPose() : GetSensorPose();
5626  }
5627 
5632  inline Pose2 GetSensorPose() const
5633  {
5634  return GetSensorAt(m_CorrectedPose);
5635  }
5636 
5637  inline void SetIsDirty(kt_bool& rIsDirty)
5638  {
5639  m_IsDirty = rIsDirty;
5640  }
5641 
5646  void SetSensorPose(const Pose2& rScanPose)
5647  {
5648  m_CorrectedPose = GetCorrectedAt(rScanPose);
5649 
5650  Update();
5651  }
5652 
5658  inline Pose2 GetSensorAt(const Pose2& rPose) const
5659  {
5660  return Transform(rPose).TransformPose(GetLaserRangeFinder()->GetOffsetPose());
5661  }
5662 
5668  inline Pose2 GetCorrectedAt(const Pose2& sPose) const
5669  {
5670  Pose2 deviceOffsetPose2 = GetLaserRangeFinder()->GetOffsetPose();
5671  kt_double offsetLength = deviceOffsetPose2.GetPosition().Length();
5672  kt_double offsetHeading = deviceOffsetPose2.GetHeading();
5673  kt_double angleoffset = atan2(deviceOffsetPose2.GetY(), deviceOffsetPose2.GetX());
5674  kt_double correctedHeading = math::NormalizeAngle(sPose.GetHeading());
5675  Pose2 worldSensorOffset = Pose2(offsetLength * cos(correctedHeading + angleoffset - offsetHeading),
5676  offsetLength * sin(correctedHeading + angleoffset - offsetHeading),
5677  offsetHeading);
5678 
5679  return sPose - worldSensorOffset;
5680  }
5681 
5686  inline const BoundingBox2& GetBoundingBox() const
5687  {
5688  boost::shared_lock<boost::shared_mutex> lock(m_Lock);
5689  if (m_IsDirty)
5690  {
5691  // throw away constness and do an update!
5692  lock.unlock();
5693  boost::unique_lock<boost::shared_mutex> uniqueLock(m_Lock);
5694  const_cast<LocalizedRangeScan*>(this)->Update();
5695  }
5696 
5697  return m_BoundingBox;
5698  }
5699 
5700  inline void SetBoundingBox(BoundingBox2& bbox)
5701  {
5702  m_BoundingBox = bbox;
5703  }
5704 
5708  inline const PointVectorDouble& GetPointReadings(kt_bool wantFiltered = false) const
5709  {
5710  boost::shared_lock<boost::shared_mutex> lock(m_Lock);
5711  if (m_IsDirty)
5712  {
5713  // throw away constness and do an update!
5714  lock.unlock();
5715  boost::unique_lock<boost::shared_mutex> uniqueLock(m_Lock);
5716  const_cast<LocalizedRangeScan*>(this)->Update();
5717  }
5718 
5719  if (wantFiltered == true)
5720  {
5721  return m_PointReadings;
5722  }
5723  else
5724  {
5725  return m_UnfilteredPointReadings;
5726  }
5727  }
5728 
5729  inline void SetPointReadings(PointVectorDouble& points, kt_bool setFiltered = false)
5730  {
5731  if (setFiltered)
5732  {
5733  m_PointReadings = points;
5734  }
5735  else
5736  {
5737  m_UnfilteredPointReadings = points;
5738  }
5739  }
5740 
5741  private:
5746  virtual void Update()
5747  {
5748  LaserRangeFinder* pLaserRangeFinder = GetLaserRangeFinder();
5749 
5750  if (pLaserRangeFinder != NULL)
5751  {
5752  m_PointReadings.clear();
5753  m_UnfilteredPointReadings.clear();
5754 
5755  kt_double rangeThreshold = pLaserRangeFinder->GetRangeThreshold();
5756  kt_double minimumAngle = pLaserRangeFinder->GetMinimumAngle();
5757  kt_double angularResolution = pLaserRangeFinder->GetAngularResolution();
5758  Pose2 scanPose = GetSensorPose();
5759 
5760  // compute point readings
5761  Vector2<kt_double> rangePointsSum;
5762  kt_int32u beamNum = 0;
5763  for (kt_int32u i = 0; i < pLaserRangeFinder->GetNumberOfRangeReadings(); i++, beamNum++)
5764  {
5765  kt_double rangeReading = GetRangeReadings()[i];
5766  if (!math::InRange(rangeReading, pLaserRangeFinder->GetMinimumRange(), rangeThreshold))
5767  {
5768  kt_double angle = scanPose.GetHeading() + minimumAngle + beamNum * angularResolution;
5769 
5770  Vector2<kt_double> point;
5771  point.SetX(scanPose.GetX() + (rangeReading * cos(angle)));
5772  point.SetY(scanPose.GetY() + (rangeReading * sin(angle)));
5773 
5774  m_UnfilteredPointReadings.push_back(point);
5775  continue;
5776  }
5777 
5778  kt_double angle = scanPose.GetHeading() + minimumAngle + beamNum * angularResolution;
5779 
5780  Vector2<kt_double> point;
5781  point.SetX(scanPose.GetX() + (rangeReading * cos(angle)));
5782  point.SetY(scanPose.GetY() + (rangeReading * sin(angle)));
5783 
5784  m_PointReadings.push_back(point);
5785  m_UnfilteredPointReadings.push_back(point);
5786 
5787  rangePointsSum += point;
5788  }
5789 
5790  // compute barycenter
5791  kt_double nPoints = static_cast<kt_double>(m_PointReadings.size());
5792  if (nPoints != 0.0)
5793  {
5794  Vector2<kt_double> averagePosition = Vector2<kt_double>(rangePointsSum / nPoints);
5795  m_BarycenterPose = Pose2(averagePosition, 0.0);
5796  }
5797  else
5798  {
5799  m_BarycenterPose = scanPose;
5800  }
5801 
5802  // calculate bounding box of scan
5803  m_BoundingBox = BoundingBox2();
5804  m_BoundingBox.Add(scanPose.GetPosition());
5805  forEach(PointVectorDouble, &m_PointReadings)
5806  {
5807  m_BoundingBox.Add(*iter);
5808  }
5809  }
5810 
5811  m_IsDirty = false;
5812  }
5813 
5817  friend class boost::serialization::access;
5818  template<class Archive>
5819  void serialize(Archive &ar, const unsigned int version)
5820  {
5821  ar & BOOST_SERIALIZATION_NVP(m_OdometricPose);
5822  ar & BOOST_SERIALIZATION_NVP(m_CorrectedPose);
5823  ar & BOOST_SERIALIZATION_NVP(m_BarycenterPose);
5824  ar & BOOST_SERIALIZATION_NVP(m_PointReadings);
5825  ar & BOOST_SERIALIZATION_NVP(m_UnfilteredPointReadings);
5826  ar & BOOST_SERIALIZATION_NVP(m_BoundingBox);
5827  ar & BOOST_SERIALIZATION_NVP(m_IsDirty);
5828  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(LaserRangeScan);
5829  }
5830 
5831 
5832  private:
5834  const LocalizedRangeScan& operator=(const LocalizedRangeScan&);
5835 
5836  private:
5841 
5846 
5847  protected:
5852 
5857 
5862 
5867 
5872  }; // LocalizedRangeScan
5873 
5877  typedef std::vector<LocalizedRangeScan*> LocalizedRangeScanVector;
5878  typedef std::map<int, LocalizedRangeScan*> LocalizedRangeScanMap;
5882 
5887  {
5888  public:
5889  // @cond EXCLUDE
5891  // @endcond
5892 
5893  public:
5898  LocalizedRangeScanWithPoints(const Name& rSensorName, const RangeReadingsVector& rReadings,
5899  const PointVectorDouble& rPoints)
5900  : m_Points(rPoints),
5901  LocalizedRangeScan(rSensorName, rReadings)
5902  {
5903  }
5904 
5909  {
5910  }
5911 
5912  private:
5916  void Update()
5917  {
5918  m_PointReadings.clear();
5919  m_UnfilteredPointReadings.clear();
5920 
5921  Pose2 scanPose = GetSensorPose();
5922  Pose2 robotPose = GetCorrectedPose();
5923 
5924  // update point readings
5925  Vector2<kt_double> rangePointsSum;
5926  for (kt_int32u i = 0; i < m_Points.size(); i++)
5927  {
5928  // check if this has a NaN
5929  if (!std::isfinite(m_Points[i].GetX()) || !std::isfinite(m_Points[i].GetY()))
5930  {
5931  Vector2<kt_double> point(m_Points[i].GetX(), m_Points[i].GetY());
5932  m_UnfilteredPointReadings.push_back(point);
5933 
5934  continue;
5935  }
5936 
5937  // transform into world coords
5938  Pose2 pointPose(m_Points[i].GetX(), m_Points[i].GetY(), 0);
5939  Pose2 result = Transform(robotPose).TransformPose(pointPose);
5940  Vector2<kt_double> point(result.GetX(), result.GetY());
5941 
5942  m_PointReadings.push_back(point);
5943  m_UnfilteredPointReadings.push_back(point);
5944 
5945  rangePointsSum += point;
5946  }
5947 
5948  // compute barycenter
5949  kt_double nPoints = static_cast<kt_double>(m_PointReadings.size());
5950  if (nPoints != 0.0)
5951  {
5952  Vector2<kt_double> averagePosition = Vector2<kt_double>(rangePointsSum / nPoints);
5953  m_BarycenterPose = Pose2(averagePosition, 0.0);
5954  }
5955  else
5956  {
5957  m_BarycenterPose = scanPose;
5958  }
5959 
5960  // calculate bounding box of scan
5961  m_BoundingBox = BoundingBox2();
5962  m_BoundingBox.Add(scanPose.GetPosition());
5963  forEach(PointVectorDouble, &m_PointReadings)
5964  {
5965  m_BoundingBox.Add(*iter);
5966  }
5967 
5968  m_IsDirty = false;
5969  }
5970 
5971  private:
5974 
5975  private:
5977  }; // LocalizedRangeScanWithPoints
5978 
5982 
5983  class OccupancyGrid;
5984 
5986  {
5987  public:
5989  : m_pOccupancyGrid(pGrid)
5990  {
5991  }
5992 
5997  virtual void operator() (kt_int32u index);
5998 
5999  private:
6001  }; // CellUpdater
6002 
6006  class OccupancyGrid : public Grid<kt_int8u>
6007  {
6008  friend class CellUpdater;
6009  friend class IncrementalOccupancyGrid;
6010 
6011  public:
6019  OccupancyGrid(kt_int32s width, kt_int32s height, const Vector2<kt_double>& rOffset, kt_double resolution)
6020  : Grid<kt_int8u>(width, height)
6021  , m_pCellPassCnt(Grid<kt_int32u>::CreateGrid(0, 0, resolution))
6022  , m_pCellHitsCnt(Grid<kt_int32u>::CreateGrid(0, 0, resolution))
6023  , m_pCellUpdater(NULL)
6024  {
6025  m_pCellUpdater = new CellUpdater(this);
6026 
6027  if (karto::math::DoubleEqual(resolution, 0.0))
6028  {
6029  throw Exception("Resolution cannot be 0");
6030  }
6031 
6032  m_pMinPassThrough = new Parameter<kt_int32u>("MinPassThrough", 2);
6033  m_pOccupancyThreshold = new Parameter<kt_double>("OccupancyThreshold", 0.1);
6034 
6035  GetCoordinateConverter()->SetScale(1.0 / resolution);
6036  GetCoordinateConverter()->SetOffset(rOffset);
6037  }
6038 
6042  virtual ~OccupancyGrid()
6043  {
6044  delete m_pCellUpdater;
6045 
6046  delete m_pCellPassCnt;
6047  delete m_pCellHitsCnt;
6048 
6049  delete m_pMinPassThrough;
6050  delete m_pOccupancyThreshold;
6051  }
6052 
6053  public:
6060  {
6061  if (rScans.empty())
6062  {
6063  return NULL;
6064  }
6065 
6066  kt_int32s width, height;
6067  Vector2<kt_double> offset;
6068  ComputeDimensions(rScans, resolution, width, height, offset);
6069  OccupancyGrid* pOccupancyGrid = new OccupancyGrid(width, height, offset, resolution);
6070  pOccupancyGrid->CreateFromScans(rScans);
6071 
6072  return pOccupancyGrid;
6073  }
6074 
6080  {
6081  OccupancyGrid* pOccupancyGrid = new OccupancyGrid(GetWidth(),
6082  GetHeight(),
6083  GetCoordinateConverter()->GetOffset(),
6084  1.0 / GetCoordinateConverter()->GetScale());
6085  memcpy(pOccupancyGrid->GetDataPointer(), GetDataPointer(), GetDataSize());
6086 
6087  pOccupancyGrid->GetCoordinateConverter()->SetSize(GetCoordinateConverter()->GetSize());
6088  pOccupancyGrid->m_pCellPassCnt = m_pCellPassCnt->Clone();
6089  pOccupancyGrid->m_pCellHitsCnt = m_pCellHitsCnt->Clone();
6090 
6091  return pOccupancyGrid;
6092  }
6093 
6099  virtual kt_bool IsFree(const Vector2<kt_int32s>& rPose) const
6100  {
6101  kt_int8u* pOffsets = reinterpret_cast<kt_int8u*>(GetDataPointer(rPose));
6102  if (*pOffsets == GridStates_Free)
6103  {
6104  return true;
6105  }
6106 
6107  return false;
6108  }
6109 
6117  virtual kt_double RayCast(const Pose2& rPose2, kt_double maxRange) const
6118  {
6119  double scale = GetCoordinateConverter()->GetScale();
6120 
6121  kt_double x = rPose2.GetX();
6122  kt_double y = rPose2.GetY();
6123  kt_double theta = rPose2.GetHeading();
6124 
6125  kt_double sinTheta = sin(theta);
6126  kt_double cosTheta = cos(theta);
6127 
6128  kt_double xStop = x + maxRange * cosTheta;
6129  kt_double xSteps = 1 + fabs(xStop - x) * scale;
6130 
6131  kt_double yStop = y + maxRange * sinTheta;
6132  kt_double ySteps = 1 + fabs(yStop - y) * scale;
6133 
6134  kt_double steps = math::Maximum(xSteps, ySteps);
6135  kt_double delta = maxRange / steps;
6136  kt_double distance = delta;
6137 
6138  for (kt_int32u i = 1; i < steps; i++)
6139  {
6140  kt_double x1 = x + distance * cosTheta;
6141  kt_double y1 = y + distance * sinTheta;
6142 
6143  Vector2<kt_int32s> gridIndex = WorldToGrid(Vector2<kt_double>(x1, y1));
6144  if (IsValidGridIndex(gridIndex) && IsFree(gridIndex))
6145  {
6146  distance = (i + 1) * delta;
6147  }
6148  else
6149  {
6150  break;
6151  }
6152  }
6153 
6154  return (distance < maxRange)? distance : maxRange;
6155  }
6156 
6163  {
6164  m_pMinPassThrough->SetValue(count);
6165  }
6166 
6172  {
6173  m_pOccupancyThreshold->SetValue(thresh);
6174  }
6175 
6176  protected:
6182  {
6183  return m_pCellHitsCnt;
6184  }
6185 
6191  {
6192  return m_pCellPassCnt;
6193  }
6194 
6195  protected:
6204  static void ComputeDimensions(const LocalizedRangeScanVector& rScans,
6205  kt_double resolution,
6206  kt_int32s& rWidth,
6207  kt_int32s& rHeight,
6208  Vector2<kt_double>& rOffset)
6209  {
6210  BoundingBox2 boundingBox;
6211 
6213  {
6214  if (*iter == nullptr)
6215  {
6216  continue;
6217  }
6218 
6219  boundingBox.Add((*iter)->GetBoundingBox());
6220  }
6221 
6222  kt_double scale = 1.0 / resolution;
6223  Size2<kt_double> size = boundingBox.GetSize();
6224 
6225  rWidth = static_cast<kt_int32s>(math::Round(size.GetWidth() * scale));
6226  rHeight = static_cast<kt_int32s>(math::Round(size.GetHeight() * scale));
6227  rOffset = boundingBox.GetMinimum();
6228  }
6229 
6234  virtual void CreateFromScans(const LocalizedRangeScanVector& rScans)
6235  {
6236  m_pCellPassCnt->Resize(GetWidth(), GetHeight());
6237  m_pCellPassCnt->GetCoordinateConverter()->SetOffset(GetCoordinateConverter()->GetOffset());
6238 
6239  m_pCellHitsCnt->Resize(GetWidth(), GetHeight());
6240  m_pCellHitsCnt->GetCoordinateConverter()->SetOffset(GetCoordinateConverter()->GetOffset());
6241 
6243  {
6244  if (*iter == nullptr)
6245  {
6246  continue;
6247  }
6248 
6249  LocalizedRangeScan* pScan = *iter;
6250  AddScan(pScan);
6251  }
6252 
6253  Update();
6254  }
6255 
6263  virtual kt_bool AddScan(LocalizedRangeScan* pScan, kt_bool doUpdate = false)
6264  {
6265  LaserRangeFinder* laserRangeFinder = pScan->GetLaserRangeFinder();
6266  kt_double rangeThreshold = laserRangeFinder->GetRangeThreshold();
6267  kt_double maxRange = laserRangeFinder->GetMaximumRange();
6268  kt_double minRange = laserRangeFinder->GetMinimumRange();
6269 
6270  Vector2<kt_double> scanPosition = pScan->GetSensorPose().GetPosition();
6271  // get scan point readings
6272  const PointVectorDouble& rPointReadings = pScan->GetPointReadings(false);
6273 
6274  kt_bool isAllInMap = true;
6275 
6276  // draw lines from scan position to all point readings
6277  int pointIndex = 0;
6278  const_forEachAs(PointVectorDouble, &rPointReadings, pointsIter)
6279  {
6280  Vector2<kt_double> point = *pointsIter;
6281  kt_double rangeReading = pScan->GetRangeReadings()[pointIndex];
6282  kt_bool isEndPointValid = rangeReading < (rangeThreshold - KT_TOLERANCE);
6283 
6284  if (rangeReading <= minRange || rangeReading >= maxRange || std::isnan(rangeReading))
6285  {
6286  // ignore these readings
6287  pointIndex++;
6288  continue;
6289  }
6290  else if (rangeReading >= rangeThreshold)
6291  {
6292  // trace up to range reading
6293  kt_double ratio = rangeThreshold / rangeReading;
6294  kt_double dx = point.GetX() - scanPosition.GetX();
6295  kt_double dy = point.GetY() - scanPosition.GetY();
6296  point.SetX(scanPosition.GetX() + ratio * dx);
6297  point.SetY(scanPosition.GetY() + ratio * dy);
6298  }
6299 
6300  kt_bool isInMap = RayTrace(scanPosition, point, isEndPointValid, doUpdate);
6301  if (!isInMap)
6302  {
6303  isAllInMap = false;
6304  }
6305 
6306  pointIndex++;
6307  }
6308 
6309  return isAllInMap;
6310  }
6311 
6321  virtual kt_bool RayTrace(const Vector2<kt_double>& rWorldFrom,
6322  const Vector2<kt_double>& rWorldTo,
6323  kt_bool isEndPointValid,
6324  kt_bool doUpdate = false)
6325  {
6326  assert(m_pCellPassCnt != NULL && m_pCellHitsCnt != NULL);
6327 
6328  Vector2<kt_int32s> gridFrom = m_pCellPassCnt->WorldToGrid(rWorldFrom);
6329  Vector2<kt_int32s> gridTo = m_pCellPassCnt->WorldToGrid(rWorldTo);
6330 
6331  CellUpdater* pCellUpdater = doUpdate ? m_pCellUpdater : NULL;
6332  m_pCellPassCnt->TraceLine(gridFrom.GetX(), gridFrom.GetY(), gridTo.GetX(), gridTo.GetY(), pCellUpdater);
6333 
6334  // for the end point
6335  if (isEndPointValid)
6336  {
6337  if (m_pCellPassCnt->IsValidGridIndex(gridTo))
6338  {
6339  kt_int32s index = m_pCellPassCnt->GridIndex(gridTo, false);
6340 
6341  kt_int32u* pCellPassCntPtr = m_pCellPassCnt->GetDataPointer();
6342  kt_int32u* pCellHitCntPtr = m_pCellHitsCnt->GetDataPointer();
6343 
6344  // increment cell pass through and hit count
6345  pCellPassCntPtr[index]++;
6346  pCellHitCntPtr[index]++;
6347 
6348  if (doUpdate)
6349  {
6350  (*m_pCellUpdater)(index);
6351  }
6352  }
6353  }
6354 
6355  return m_pCellPassCnt->IsValidGridIndex(gridTo);
6356  }
6357 
6364  virtual void UpdateCell(kt_int8u* pCell, kt_int32u cellPassCnt, kt_int32u cellHitCnt)
6365  {
6366  if (cellPassCnt > m_pMinPassThrough->GetValue())
6367  {
6368  kt_double hitRatio = static_cast<kt_double>(cellHitCnt) / static_cast<kt_double>(cellPassCnt);
6369 
6370  if (hitRatio > m_pOccupancyThreshold->GetValue())
6371  {
6372  *pCell = GridStates_Occupied;
6373  }
6374  else
6375  {
6376  *pCell = GridStates_Free;
6377  }
6378  }
6379  }
6380 
6384  virtual void Update()
6385  {
6386  assert(m_pCellPassCnt != NULL && m_pCellHitsCnt != NULL);
6387 
6388  // clear grid
6389  Clear();
6390 
6391  // set occupancy status of cells
6392  kt_int8u* pDataPtr = GetDataPointer();
6393  kt_int32u* pCellPassCntPtr = m_pCellPassCnt->GetDataPointer();
6394  kt_int32u* pCellHitCntPtr = m_pCellHitsCnt->GetDataPointer();
6395 
6396  kt_int32u nBytes = GetDataSize();
6397  for (kt_int32u i = 0; i < nBytes; i++, pDataPtr++, pCellPassCntPtr++, pCellHitCntPtr++)
6398  {
6399  UpdateCell(pDataPtr, *pCellPassCntPtr, *pCellHitCntPtr);
6400  }
6401  }
6402 
6408  virtual void Resize(kt_int32s width, kt_int32s height)
6409  {
6410  Grid<kt_int8u>::Resize(width, height);
6411  m_pCellPassCnt->Resize(width, height);
6412  m_pCellHitsCnt->Resize(width, height);
6413  }
6414 
6415  protected:
6420 
6425 
6426  private:
6430  OccupancyGrid(const OccupancyGrid&);
6431 
6435  const OccupancyGrid& operator=(const OccupancyGrid&);
6436 
6437  private:
6439 
6441  // NOTE: These two values are dependent on the resolution. If the resolution is too small,
6442  // then not many beams will hit the cell!
6443 
6444  // Number of beams that must pass through a cell before it will be considered to be occupied
6445  // or unoccupied. This prevents stray beams from messing up the map.
6447 
6448  // Minimum ratio of beams hitting cell to beams passing through cell for cell to be marked as occupied
6450  }; // OccupancyGrid
6451 
6455 
6460  class DatasetInfo : public Object
6461  {
6462  public:
6463  // @cond EXCLUDE
6465  // @endcond
6466 
6467  public:
6469  : Object()
6470  {
6471  m_pTitle = new Parameter<std::string>("Title", "", GetParameterManager());
6472  m_pAuthor = new Parameter<std::string>("Author", "", GetParameterManager());
6473  m_pDescription = new Parameter<std::string>("Description", "", GetParameterManager());
6474  m_pCopyright = new Parameter<std::string>("Copyright", "", GetParameterManager());
6475  }
6476 
6477  virtual ~DatasetInfo()
6478  {
6479  }
6480 
6481  public:
6485  const std::string& GetTitle() const
6486  {
6487  return m_pTitle->GetValue();
6488  }
6489 
6493  const std::string& GetAuthor() const
6494  {
6495  return m_pAuthor->GetValue();
6496  }
6497 
6501  const std::string& GetDescription() const
6502  {
6503  return m_pDescription->GetValue();
6504  }
6505 
6509  const std::string& GetCopyright() const
6510  {
6511  return m_pCopyright->GetValue();
6512  }
6513 
6518  private:
6519  DatasetInfo(const DatasetInfo&);
6520  const DatasetInfo& operator=(const DatasetInfo&);
6521 
6522  private:
6527  friend class boost::serialization::access;
6528  template<class Archive>
6529  void serialize(Archive &ar, const unsigned int version)
6530  {
6531  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Object);
6532  ar & BOOST_SERIALIZATION_NVP(*m_pTitle);
6533  ar & BOOST_SERIALIZATION_NVP(*m_pAuthor);
6534  ar & BOOST_SERIALIZATION_NVP(*m_pDescription);
6535  ar & BOOST_SERIALIZATION_NVP(*m_pCopyright);
6536  }
6537  }; // class DatasetInfo
6538 
6542 
6547  class Dataset
6548  {
6549  public:
6554  : m_pDatasetInfo(NULL)
6555  {
6556  }
6557 
6561  virtual ~Dataset()
6562  {
6563  Clear();
6564  }
6565 
6570  void SaveToFile(const std::string& filename)
6571  {
6572  printf("Save To File\n");
6573  std::ofstream ofs(filename.c_str());
6574  boost::archive::binary_oarchive oa(ofs, boost::archive::no_codecvt);
6575  oa << BOOST_SERIALIZATION_NVP(*this);
6576  }
6577 
6582  void LoadFromFile(const std::string& filename)
6583  {
6584  printf("Load From File\n");
6585  std::ifstream ifs(filename.c_str());
6586  boost::archive::binary_iarchive ia(ifs, boost::archive::no_codecvt); //no second arg?
6587  ia >> BOOST_SERIALIZATION_NVP(*this);
6588  }
6589 
6590  public:
6595  void Add(Object* pObject, kt_bool overrideSensorName = false)
6596  {
6597  if (pObject != NULL)
6598  {
6599  if (dynamic_cast<Sensor*>(pObject))
6600  {
6601  Sensor* pSensor = dynamic_cast<Sensor*>(pObject);
6602  if (pSensor != NULL)
6603  {
6604  m_SensorNameLookup[pSensor->GetName()] = pSensor;
6605  karto::SensorManager::GetInstance()->RegisterSensor(pSensor, overrideSensorName);
6606  }
6607 
6608  m_Lasers.push_back(pObject);
6609  }
6610  else if (dynamic_cast<SensorData*>(pObject))
6611  {
6612  SensorData* pSensorData = dynamic_cast<SensorData*>(pObject);
6613  m_Data.insert({pSensorData->GetUniqueId(), pSensorData});
6614  }
6615  else if (dynamic_cast<DatasetInfo*>(pObject))
6616  {
6617  m_pDatasetInfo = dynamic_cast<DatasetInfo*>(pObject);
6618  }
6619  else
6620  {
6621  std::cout << "Did not save object of non-data and non-sensor type" << std::endl;
6622  }
6623  }
6624  }
6625 
6630  inline const ObjectVector& GetLasers() const
6631  {
6632  return m_Lasers;
6633  }
6634 
6639  inline const DataMap& GetData() const
6640  {
6641  return m_Data;
6642  }
6643 
6648  inline void RemoveData(LocalizedRangeScan* scan)
6649  {
6650  auto iterator = m_Data.find(scan->GetUniqueId());
6651  if (iterator != m_Data.end())
6652  {
6653  delete iterator->second;
6654  iterator->second = nullptr;
6655  m_Data.erase(iterator);
6656  }
6657  else
6658  {
6659  std::cout << "Failed to remove data. Pointer to LocalizedRangeScan could not be found in dataset. "
6660  << "Most likely different pointer address but same object TODO STEVE." << std::endl;
6661  }
6662  }
6663 
6669  {
6670  return m_pDatasetInfo;
6671  }
6672 
6676  virtual void Clear()
6677  {
6678  for (std::map<Name, Sensor*>::iterator iter = m_SensorNameLookup.begin(); iter != m_SensorNameLookup.end(); ++iter)
6679  {
6681  }
6682 
6683  forEach(ObjectVector, &m_Lasers)
6684  {
6685  if(*iter)
6686  {
6687  delete *iter;
6688  *iter = NULL;
6689  }
6690  }
6691 
6692  for (auto iter = m_Data.begin(); iter != m_Data.end(); ++iter)
6693  {
6694  if(iter->second)
6695  {
6696  delete iter->second;
6697  iter->second = NULL;
6698  }
6699  }
6700 
6701  m_Lasers.clear();
6702  m_Data.clear();
6703 
6704  if (m_pDatasetInfo != NULL)
6705  {
6706  delete m_pDatasetInfo;
6707  m_pDatasetInfo = NULL;
6708  }
6709  }
6710 
6711  private:
6712  std::map<Name, Sensor*> m_SensorNameLookup;
6719  friend class boost::serialization::access;
6720  template<class Archive>
6721  void serialize(Archive &ar, const unsigned int version)
6722  {
6723  std::cout<<"**Serializing Dataset**\n";
6724  std::cout<<"Dataset <- m_SensorNameLookup\n";
6725  ar & BOOST_SERIALIZATION_NVP(m_SensorNameLookup);
6726  std::cout<<"Dataset <- m_Data\n";
6727  ar & BOOST_SERIALIZATION_NVP(m_Data);
6728  std::cout<<"Dataset <- m_Lasers\n";
6729  ar & BOOST_SERIALIZATION_NVP(m_Lasers);
6730  std::cout<<"Dataset <- m_pDatasetInfo\n";
6731  ar & BOOST_SERIALIZATION_NVP(m_pDatasetInfo);
6732  std::cout<<"**Finished serializing Dataset**\n";
6733  }
6734 
6735  }; // Dataset
6736  BOOST_SERIALIZATION_ASSUME_ABSTRACT(Dataset)
6740 
6746  {
6747  public:
6752  : m_pArray(NULL)
6753  , m_Capacity(0)
6754  , m_Size(0)
6755  {
6756  }
6757 
6761  virtual ~LookupArray()
6762  {
6763  assert(m_pArray != NULL);
6764 
6765  delete[] m_pArray;
6766  m_pArray = NULL;
6767  }
6768 
6769  public:
6773  void Clear()
6774  {
6775  memset(m_pArray, 0, sizeof(kt_int32s) * m_Capacity);
6776  }
6777 
6783  {
6784  return m_Size;
6785  }
6786 
6791  void SetSize(kt_int32u size)
6792  {
6793  assert(size != 0);
6794 
6795  if (size > m_Capacity)
6796  {
6797  if (m_pArray != NULL)
6798  {
6799  delete [] m_pArray;
6800  }
6801  m_Capacity = size;
6802  m_pArray = new kt_int32s[m_Capacity];
6803  }
6804 
6805  m_Size = size;
6806  }
6807 
6813  inline kt_int32s& operator [] (kt_int32u index)
6814  {
6815  assert(index < m_Size);
6816 
6817  return m_pArray[index];
6818  }
6819 
6825  inline kt_int32s operator [] (kt_int32u index) const
6826  {
6827  assert(index < m_Size);
6828 
6829  return m_pArray[index];
6830  }
6831 
6837  {
6838  return m_pArray;
6839  }
6840 
6845  inline kt_int32s* GetArrayPointer() const
6846  {
6847  return m_pArray;
6848  }
6849 
6850  private:
6854  friend class boost::serialization::access;
6855  template<class Archive>
6856  void serialize(Archive &ar, const unsigned int version)
6857  {
6858  ar & BOOST_SERIALIZATION_NVP(m_Capacity);
6859  ar & BOOST_SERIALIZATION_NVP(m_Size);
6860  if (Archive::is_loading::value)
6861  {
6862  m_pArray = new kt_int32s[m_Capacity];
6863  }
6864  ar & boost::serialization::make_array<kt_int32s >(m_pArray, m_Capacity);
6865 
6866 
6867  }
6868  }; // LookupArray
6869 
6873 
6887  template<typename T>
6889  {
6890  public:
6896  {
6897  }
6899  : m_pGrid(pGrid)
6900  , m_Capacity(0)
6901  , m_Size(0)
6902  , m_ppLookupArray(NULL)
6903  {
6904  }
6905 
6910  {
6911  DestroyArrays();
6912  }
6913 
6914  public:
6921  {
6922  assert(math::IsUpTo(index, m_Size));
6923 
6924  return m_ppLookupArray[index];
6925  }
6926 
6931  const std::vector<kt_double>& GetAngles() const
6932  {
6933  return m_Angles;
6934  }
6935 
6944  kt_double angleCenter,
6945  kt_double angleOffset,
6946  kt_double angleResolution)
6947  {
6948  assert(angleOffset != 0.0);
6949  assert(angleResolution != 0.0);
6950 
6951  kt_int32u nAngles = static_cast<kt_int32u>(math::Round(angleOffset * 2.0 / angleResolution) + 1);
6952  SetSize(nAngles);
6953 
6955  // convert points into local coordinates of scan pose
6956 
6957  const PointVectorDouble& rPointReadings = pScan->GetPointReadings();
6958 
6959  // compute transform to scan pose
6960  Transform transform(pScan->GetSensorPose());
6961 
6962  Pose2Vector localPoints;
6963  const_forEach(PointVectorDouble, &rPointReadings)
6964  {
6965  // do inverse transform to get points in local coordinates
6966  Pose2 vec = transform.InverseTransformPose(Pose2(*iter, 0.0));
6967  localPoints.push_back(vec);
6968  }
6969 
6971  // create lookup array for different angles
6972  kt_double angle = 0.0;
6973  kt_double startAngle = angleCenter - angleOffset;
6974  for (kt_int32u angleIndex = 0; angleIndex < nAngles; angleIndex++)
6975  {
6976  angle = startAngle + angleIndex * angleResolution;
6977  ComputeOffsets(angleIndex, angle, localPoints, pScan);
6978  }
6979  // assert(math::DoubleEqual(angle, angleCenter + angleOffset));
6980  }
6981 
6982  private:
6989  void ComputeOffsets(kt_int32u angleIndex, kt_double angle, const Pose2Vector& rLocalPoints, LocalizedRangeScan* pScan)
6990  {
6991  m_ppLookupArray[angleIndex]->SetSize(static_cast<kt_int32u>(rLocalPoints.size()));
6992  m_Angles.at(angleIndex) = angle;
6993 
6994  // set up point array by computing relative offsets to points readings
6995  // when rotated by given angle
6996 
6997  const Vector2<kt_double>& rGridOffset = m_pGrid->GetCoordinateConverter()->GetOffset();
6998 
6999  kt_double cosine = cos(angle);
7000  kt_double sine = sin(angle);
7001 
7002  kt_int32u readingIndex = 0;
7003 
7004  kt_int32s* pAngleIndexPointer = m_ppLookupArray[angleIndex]->GetArrayPointer();
7005 
7006  kt_double maxRange = pScan->GetLaserRangeFinder()->GetMaximumRange();
7007 
7008  const_forEach(Pose2Vector, &rLocalPoints)
7009  {
7010  const Vector2<kt_double>& rPosition = iter->GetPosition();
7011 
7012  if (std::isnan(pScan->GetRangeReadings()[readingIndex]) || std::isinf(pScan->GetRangeReadings()[readingIndex]))
7013  {
7014  pAngleIndexPointer[readingIndex] = INVALID_SCAN;
7015  readingIndex++;
7016  continue;
7017  }
7018 
7019 
7020  // counterclockwise rotation and that rotation is about the origin (0, 0).
7021  Vector2<kt_double> offset;
7022  offset.SetX(cosine * rPosition.GetX() - sine * rPosition.GetY());
7023  offset.SetY(sine * rPosition.GetX() + cosine * rPosition.GetY());
7024 
7025  // have to compensate for the grid offset when getting the grid index
7026  Vector2<kt_int32s> gridPoint = m_pGrid->WorldToGrid(offset + rGridOffset);
7027 
7028  // use base GridIndex to ignore ROI
7029  kt_int32s lookupIndex = m_pGrid->Grid<T>::GridIndex(gridPoint, false);
7030 
7031  pAngleIndexPointer[readingIndex] = lookupIndex;
7032 
7033  readingIndex++;
7034  }
7035  assert(readingIndex == rLocalPoints.size());
7036  }
7037 
7042  void SetSize(kt_int32u size)
7043  {
7044  assert(size != 0);
7045 
7046  if (size > m_Capacity)
7047  {
7048  if (m_ppLookupArray != NULL)
7049  {
7050  DestroyArrays();
7051  }
7052 
7053  m_Capacity = size;
7054  m_ppLookupArray = new LookupArray*[m_Capacity];
7055  for (kt_int32u i = 0; i < m_Capacity; i++)
7056  {
7057  m_ppLookupArray[i] = new LookupArray();
7058  }
7059  }
7060 
7061  m_Size = size;
7062 
7063  m_Angles.resize(size);
7064  }
7065 
7070  {
7071  if (m_ppLookupArray)
7072  {
7073  for (kt_int32u i = 0; i < m_Capacity; i++)
7074  {
7075  delete m_ppLookupArray[i];
7076  }
7077  }
7078  if (m_ppLookupArray)
7079  {
7080  delete[] m_ppLookupArray;
7081  m_ppLookupArray = NULL;
7082  }
7083  }
7084 
7085  private:
7087 
7090 
7092 
7093  // for sanity check
7094  std::vector<kt_double> m_Angles;
7095  friend class boost::serialization::access;
7096  template<class Archive>
7097  void serialize(Archive &ar, const unsigned int version)
7098  {
7099  ar & BOOST_SERIALIZATION_NVP(m_pGrid);
7100  ar & BOOST_SERIALIZATION_NVP(m_Capacity);
7101  ar & BOOST_SERIALIZATION_NVP(m_Size);
7102  ar & BOOST_SERIALIZATION_NVP(m_Angles);
7103  if (Archive::is_loading::value)
7104  {
7105  m_ppLookupArray = new LookupArray*[m_Capacity];
7106  for (kt_int32u i = 0; i < m_Capacity; i++)
7107  {
7108  m_ppLookupArray[i] = new LookupArray();
7109  }
7110  }
7111  ar & boost::serialization::make_array<LookupArray*>(m_ppLookupArray, m_Capacity);
7112  }
7113  }; // class GridIndexLookup
7114 
7118 
7119  inline Pose2::Pose2(const Pose3& rPose)
7120  : m_Position(rPose.GetPosition().GetX(), rPose.GetPosition().GetY())
7121  {
7122  kt_double t1, t2;
7123 
7124  // calculates heading from orientation
7125  rPose.GetOrientation().ToEulerAngles(m_Heading, t1, t2);
7126  }
7127 
7131 
7132  // @cond EXCLUDE
7133 
7134  template<typename T>
7135  inline void Object::SetParameter(const std::string& rName, T value)
7136  {
7137  AbstractParameter* pParameter = GetParameter(rName);
7138  if (pParameter != NULL)
7139  {
7140  std::stringstream stream;
7141  stream << value;
7142  pParameter->SetValueFromString(stream.str());
7143  }
7144  else
7145  {
7146  throw Exception("Parameter does not exist: " + rName);
7147  }
7148  }
7149 
7150  template<>
7151  inline void Object::SetParameter(const std::string& rName, kt_bool value)
7152  {
7153  AbstractParameter* pParameter = GetParameter(rName);
7154  if (pParameter != NULL)
7155  {
7156  pParameter->SetValueFromString(value ? "true" : "false");
7157  }
7158  else
7159  {
7160  throw Exception("Parameter does not exist: " + rName);
7161  }
7162  }
7163 
7164  // @endcond
7165 
7167 }; // namespace karto
7168 
7196 
7197 #endif // karto_sdk_KARTO_H
void Add(const BoundingBox2 &rBoundingBox)
Definition: Karto.h:2934
BoundingBox2 m_BoundingBox
Definition: Karto.h:5866
const Vector3< kt_double > & GetPosition() const
Definition: Karto.h:2335
std::vector< kt_double > m_Angles
Definition: Karto.h:7094
Parameters(const std::string &rName)
Definition: Karto.h:3565
const kt_objecttype ObjectType_Misc
Definition: Karto.h:69
AbstractParameter * GetParameter(const std::string &rName) const
Definition: Karto.h:687
T GetHeight() const
Definition: Karto.h:1923
std::string ToString() const
Definition: Karto.h:467
const kt_objecttype ObjectType_CustomData
Definition: Karto.h:68
LaserRangeFinder * GetLaserRangeFinder() const
Definition: Karto.h:5395
#define NULL
std::string m_Description
Definition: Karto.h:3203
kt_double * GetRangeReadings() const
Definition: Karto.h:5338
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:5419
kt_int32u m_Capacity
Definition: Karto.h:7088
void SetSize(const Size2< kt_int32s > &rSize)
Definition: Karto.h:4566
void SetX(T x)
Definition: Karto.h:1878
kt_double operator()(kt_int32u row, kt_int32u column) const
Definition: Karto.h:2640
const Pose2 & GetBarycenterPose() const
Definition: Karto.h:5590
DrivePose(const Name &rSensorName)
Definition: Karto.h:5451
AbstractParameter(const std::string &rName, const std::string &rDescription, ParameterManager *pParameterManger=NULL)
Definition: Karto.h:3129
std::string ToString() const
Definition: Karto.h:1427
int32_t kt_int32s
Definition: Types.h:51
PointVectorDouble m_UnfilteredPointReadings
Definition: Karto.h:5861
Matrix3(const Matrix3 &rOther)
Definition: Karto.h:2456
virtual kt_bool Validate()
Definition: Karto.h:4150
Size2< kt_int32s > m_Size
Definition: Karto.h:4617
kt_int32s GetWidthStep() const
Definition: Karto.h:4868
kt_int32u GetNumberOfRangeReadings() const
Definition: Karto.h:4123
Matrix3 Inverse() const
Definition: Karto.h:2543
void SetSize(const Size2< T > &rSize)
Definition: Karto.h:1978
Quaternion m_Orientation
Definition: Karto.h:2432
const kt_objecttype ObjectType_LocalizedRangeScan
Definition: Karto.h:77
kt_double SquaredDistance(const Pose2 &rOther) const
Definition: Karto.h:2169
std::vector< Sensor * > SensorVector
Definition: Karto.h:3685
virtual ~Singleton()
Definition: Karto.h:223
void SetHeight(T height)
Definition: Karto.h:1932
virtual kt_objecttype GetObjectType() const =0
Exception(const std::string &rMessage="Karto Exception", kt_int32s errorCode=0)
Definition: Karto.h:105
CellUpdater * m_pCellUpdater
Definition: Karto.h:6438
Parameter< kt_double > * m_pOccupancyThreshold
Definition: Karto.h:6449
kt_bool IsSensorData(Object *pObject)
Definition: Karto.h:754
void SetY(const T &y)
Definition: Karto.h:1360
Pose3(const Vector3< kt_double > &rPosition)
Definition: Karto.h:2296
virtual ~Name()
Definition: Karto.h:416
kt_int32s GetDataSize() const
Definition: Karto.h:4895
Pose2(kt_double x, kt_double y, kt_double heading)
Definition: Karto.h:2072
virtual ~ParameterManager()
Definition: Karto.h:300
LaserRangeScan(const Name &rSensorName)
Definition: Karto.h:5298
const kt_int32s INVALID_SCAN
Definition: Math.h:47
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:983
void SetMinimum(const Vector2< kt_double > &mMinimum)
Definition: Karto.h:2891
Name(const std::string &rName)
Definition: Karto.h:400
kt_double Round(kt_double value)
Definition: Math.h:87
void MakeCeil(const Vector2 &rOther)
Definition: Karto.h:1072
kt_double & operator()(kt_int32u row, kt_int32u column)
Definition: Karto.h:2629
void SetUniqueId(kt_int32u uniqueId)
Definition: Karto.h:5170
Pose2 GetSensorPose() const
Definition: Karto.h:5632
const Vector2< kt_double > & GetOffset() const
Definition: Karto.h:4548
static void Validate(Sensor *pSensor)
Definition: Karto.h:3815
const T & GetX() const
Definition: Karto.h:1333
kt_int32s GetStateId() const
Definition: Karto.h:5143
const Pose2 & GetOdometricPose() const
Definition: Karto.h:5538
std::string ToString()
Definition: Karto.h:2371
void SaveToFile(const std::string &filename)
Definition: Karto.h:6570
kt_double GetScale() const
Definition: Karto.h:4530
virtual void Update()
Definition: Karto.h:5746
void SetBarycenterPose(Pose2 &bcenter)
Definition: Karto.h:5604
std::vector< Vector2< kt_double > > PointVectorDouble
Definition: Karto.h:1281
const kt_objecttype ObjectType_DatasetInfo
Definition: Karto.h:83
f
virtual ~CustomData()
Definition: Karto.h:5081
void SetValue(const T &rValue)
Definition: Karto.h:3280
const kt_objecttype ObjectType_CameraImage
Definition: Karto.h:78
void SetX(kt_double x)
Definition: Karto.h:1631
Pose2(const Vector2< kt_double > &rPosition, kt_double heading)
Definition: Karto.h:2060
Matrix3 Transpose() const
Definition: Karto.h:2525
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:3209
kt_int32s GetWidth() const
Definition: Karto.h:4841
void FromEulerAngles(kt_double yaw, kt_double pitch, kt_double roll)
Definition: Karto.h:1734
Write
Pose2 m_Transform
Definition: Karto.h:3060
void DefineEnumValue(kt_int32s value, const std::string &rName)
Definition: Karto.h:3494
void SetWidth(T width)
Definition: Karto.h:917
void SetPosition(const T &rX, const T &rY)
Definition: Karto.h:1951
kt_double GetResolution() const
Definition: Karto.h:4584
kt_bool IsValidFirst(char c)
Definition: Karto.h:595
void SetRangeThreshold(kt_double rangeThreshold)
Definition: Karto.h:3992
const kt_objecttype ObjectType_Module
Definition: Karto.h:84
std::vector< Object * > ObjectVector
Definition: Karto.h:732
kt_int32u kt_objecttype
Definition: Karto.h:63
kt_int32s * GetArrayPointer()
Definition: Karto.h:6836
kt_int32u m_NumberOfRangeReadings
Definition: Karto.h:4396
T m_Values[2]
Definition: Karto.h:1275
const Pose2 & GetCorrectedPose() const
Definition: Karto.h:5560
kt_int32u GetNumberOfRangeReadings() const
Definition: Karto.h:5404
Vector2< kt_int32s > WorldToGrid(const Vector2< kt_double > &rWorld, kt_bool flipY=false) const
Definition: Karto.h:4799
const Vector2< kt_double > & GetPosition() const
Definition: Karto.h:2133
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:2956
Vector2< kt_double > m_Maximum
Definition: Karto.h:2964
uint8_t kt_int8u
Definition: Types.h:46
kt_bool IsLocalizedRangeScanWithPoints(Object *pObject)
Definition: Karto.h:784
const T & Maximum(const T &value1, const T &value2)
Definition: Math.h:111
Vector2< kt_int32s > WorldToGrid(const Vector2< kt_double > &rWorld, kt_bool flipY=false) const
Definition: Karto.h:4486
kt_double GetZ() const
Definition: Karto.h:1658
kt_double DegreesToRadians(kt_double degrees)
Definition: Math.h:56
void SetScope(const std::string &rScope)
Definition: Karto.h:458
const kt_objecttype ObjectType_None
Definition: Karto.h:65
AbstractParameter(const std::string &rName, ParameterManager *pParameterManger=NULL)
Definition: Karto.h:3113
const kt_objecttype ObjectType_Header
Definition: Karto.h:81
void SetX(const T &x)
Definition: Karto.h:1035
Parameter< kt_double > * m_pMinimumAngle
Definition: Karto.h:4382
virtual ~LaserRangeFinder()
Definition: Karto.h:3934
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:5262
kt_int32u GetSize() const
Definition: Karto.h:6782
void LoadFromFile(const std::string &filename)
Definition: Karto.h:6582
Grid< T > * m_pGrid
Definition: Karto.h:7086
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:6529
LaserRangeFinder(const Name &rName)
Definition: Karto.h:4332
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:2716
LocalizedRangeScanWithPoints(const Name &rSensorName, const RangeReadingsVector &rReadings, const PointVectorDouble &rPoints)
Definition: Karto.h:5898
virtual ~LookupArray()
Definition: Karto.h:6761
const PointVectorDouble & GetPointReadings(kt_bool wantFiltered=false) const
Definition: Karto.h:5708
Size2(const Size2 &rOther)
Definition: Karto.h:897
void SetY(T y)
Definition: Karto.h:1896
const T GetHeight() const
Definition: Karto.h:926
Size2< T > m_Size
Definition: Karto.h:2022
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:4401
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:196
Vector3(const Vector3 &rOther)
Definition: Karto.h:1321
Parameter(const std::string &rName, T value, ParameterManager *pParameterManger=NULL)
Definition: Karto.h:3237
void SetParameter(const std::string &rName, T value)
LaserRangeFinderType
Definition: Karto.h:3082
AbstractParameter * Get(const std::string &rName)
Definition: Karto.h:317
void SetStateId(kt_int32s stateId)
Definition: Karto.h:5152
std::map< kt_int32s, Object * > DataMap
Definition: Karto.h:733
void SetBoundingBox(BoundingBox2 &bbox)
Definition: Karto.h:5700
LaserRangeScan(const Name &rSensorName, const RangeReadingsVector &rRangeReadings)
Definition: Karto.h:5314
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:720
Parameter< Pose2 > * m_pOffsetPose
Definition: Karto.h:3672
Parameter(const std::string &rName, const std::string &rDescription, T value, ParameterManager *pParameterManger=NULL)
Definition: Karto.h:3250
virtual void UpdateCell(kt_int8u *pCell, kt_int32u cellPassCnt, kt_int32u cellHitCnt)
Definition: Karto.h:6364
const T & GetZ() const
Definition: Karto.h:1369
#define forEach(listtype, list)
Definition: Macros.h:66
kt_double * m_pData
Definition: Karto.h:2857
const kt_objecttype ObjectType_LaserRangeFinder
Definition: Karto.h:72
void SetW(kt_double w)
Definition: Karto.h:1685
boost::shared_mutex m_Lock
Definition: Karto.h:5531
kt_double GetResolution() const
Definition: Karto.h:4924
static void ComputeDimensions(const LocalizedRangeScanVector &rScans, kt_double resolution, kt_int32s &rWidth, kt_int32s &rHeight, Vector2< kt_double > &rOffset)
Definition: Karto.h:6204
virtual Grid< kt_int32u > * GetCellPassCounts()
Definition: Karto.h:6190
kt_double GetAngularResolution() const
Definition: Karto.h:4047
const PointVectorDouble m_Points
Definition: Karto.h:5976
Parameter< std::string > * m_pAuthor
Definition: Karto.h:6524
kt_double GetX() const
Definition: Karto.h:1622
void SetSensorPose(const Pose2 &rScanPose)
Definition: Karto.h:5646
virtual kt_double RayCast(const Pose2 &rPose2, kt_double maxRange) const
Definition: Karto.h:6117
void SetMinimumAngle(kt_double minimumAngle)
Definition: Karto.h:4016
Pose2 GetSensorAt(const Pose2 &rPose) const
Definition: Karto.h:5658
const std::string & GetName() const
Definition: Karto.h:425
void Add(const Vector2< kt_double > &rPoint)
Definition: Karto.h:2925
kt_int32u GetColumns() const
Definition: Karto.h:2778
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:3342
ObjectVector m_Lasers
Definition: Karto.h:6713
kt_int32s GetUniqueId() const
Definition: Karto.h:5161
void SetMaximumRange(kt_double maximumRange)
Definition: Karto.h:3972
Drive(const std::string &rName)
Definition: Karto.h:3862
void SetOffsetPose(const Pose2 &rPose)
Definition: Karto.h:3639
void SetToIdentity()
Definition: Karto.h:2465
Sensor * GetSensorByName(const Name &rName)
Definition: Karto.h:3771
void Add(const JntArray &src1, const JntArray &src2, JntArray &dest)
Parameter< std::string > * m_pDescription
Definition: Karto.h:6525
virtual const std::string GetValueAsString() const
Definition: Karto.h:3289
kt_int32s m_UniqueId
Definition: Karto.h:5246
Rectangle2(const Rectangle2 &rOther)
Definition: Karto.h:1858
virtual ~DatasetInfo()
Definition: Karto.h:6477
kt_int32s * GetArrayPointer() const
Definition: Karto.h:6845
kt_int32s m_Width
Definition: Karto.h:5028
Parameter< kt_double > * m_pAngularResolution
Definition: Karto.h:4385
kt_int32u m_Size
Definition: Karto.h:6853
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
Pose3(const Vector3< kt_double > &rPosition, const karto::Quaternion &rOrientation)
Definition: Karto.h:2306
void Clear()
Definition: Karto.h:4681
const Pose3 & GetOdometricPose() const
Definition: Karto.h:5468
const Size2< kt_int32s > & GetSize() const
Definition: Karto.h:4575
Vector2< kt_int32s > IndexToGrid(kt_int32s index) const
Definition: Karto.h:4783
Vector2< T > m_Position
Definition: Karto.h:2021
const kt_objecttype ObjectType_Sensor
Definition: Karto.h:66
void ComputeOffsets(kt_int32u angleIndex, kt_double angle, const Pose2Vector &rLocalPoints, LocalizedRangeScan *pScan)
Definition: Karto.h:6989
void SetPosition(const Vector2< T > &rPosition)
Definition: Karto.h:1960
Pose2(const Pose2 &rOther)
Definition: Karto.h:2086
const Size2< kt_int32s > GetSize() const
Definition: Karto.h:4859
kt_double SquaredLength() const
Definition: Karto.h:1082
const std::vector< kt_double > & GetAngles() const
Definition: Karto.h:6931
kt_double SquaredLength() const
Definition: Karto.h:1409
kt_double Length() const
Definition: Karto.h:1091
kt_double GetY() const
Definition: Karto.h:1640
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:6856
void SetResolution(kt_double resolution)
Definition: Karto.h:4593
kt_double & operator()(kt_int32u row, kt_int32u column)
Definition: Karto.h:2789
kt_int32s m_StateId
Definition: Karto.h:5241
kt_int32s GetHeight() const
Definition: Karto.h:4850
virtual kt_bool AddScan(LocalizedRangeScan *pScan, kt_bool doUpdate=false)
Definition: Karto.h:6263
kt_int32s * m_pArray
Definition: Karto.h:6851
std::vector< kt_double > RangeReadingsVector
Definition: Karto.h:5281
void SetAngularResolution(kt_double angularResolution)
Definition: Karto.h:4056
const kt_objecttype ObjectType_Camera
Definition: Karto.h:73
const kt_objecttype ObjectType_SensorData
Definition: Karto.h:67
Vector2(T x, T y)
Definition: Karto.h:1015
Parameter< std::string > * m_pTitle
Definition: Karto.h:6523
Pose3(const Pose3 &rOther)
Definition: Karto.h:2315
void ComputeOffsets(LocalizedRangeScan *pScan, kt_double angleCenter, kt_double angleOffset, kt_double angleResolution)
Definition: Karto.h:6943
std::string m_Message
Definition: Karto.h:167
const Quaternion & GetOrientation() const
Definition: Karto.h:2353
virtual ~LaserRangeScan()
Definition: Karto.h:5327
std::string m_Scope
Definition: Karto.h:612
Pose3 m_OdometricPose
Definition: Karto.h:5490
Parameter< kt_int32u > * m_pMinPassThrough
Definition: Karto.h:6446
void SetScale(kt_double scale)
Definition: Karto.h:4539
kt_double SquaredDistance(const Vector2 &rOther) const
Definition: Karto.h:1100
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:2028
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:2254
const Size2< T > & GetSize() const
Definition: Karto.h:1969
const std::string & GetDescription() const
Definition: Karto.h:6501
kt_double GetRangeThreshold() const
Definition: Karto.h:3983
Quaternion(const Quaternion &rQuaternion)
Definition: Karto.h:1609
kt_double GetMaximumRange() const
Definition: Karto.h:3963
kt_int32s m_WidthStep
Definition: Karto.h:5030
kt_bool IsValidGridIndex(const Vector2< kt_int32s > &rGrid) const
Definition: Karto.h:4744
void TraceLine(kt_int32s x0, kt_int32s y0, kt_int32s x1, kt_int32s y1, Functor *f=NULL)
Definition: Karto.h:4947
virtual kt_int32s GridIndex(const Vector2< kt_int32s > &rGrid, kt_bool boundaryCheck=true) const
Definition: Karto.h:4755
const Vector2< T > & GetPosition() const
Definition: Karto.h:1941
virtual kt_bool Validate()
Definition: Karto.h:3874
Quaternion(kt_double x, kt_double y, kt_double z, kt_double w)
Definition: Karto.h:1598
Vector2< kt_double > m_Position
Definition: Karto.h:2261
T m_Height
Definition: Karto.h:980
virtual ParameterManager * GetParameterManager()
Definition: Karto.h:677
Grid * Clone()
Definition: Karto.h:4690
const Name & GetSensorName() const
Definition: Karto.h:5197
void SetMaximumAngle(kt_double maximumAngle)
Definition: Karto.h:4036
T * m_pPointer
Definition: Karto.h:246
std::vector< CustomData * > CustomDataVector
Definition: Karto.h:5114
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:3067
virtual void Update()
Definition: Karto.h:6384
const T & Clip(const T &n, const T &minValue, const T &maxValue)
Definition: Math.h:124
void Clear()
Definition: Karto.h:2478
virtual ~OccupancyGrid()
Definition: Karto.h:6042
virtual ~Parameters()
Definition: Karto.h:3573
void SetX(const T &x)
Definition: Karto.h:1342
kt_bool IsLaserRangeFinder(Object *pObject)
Definition: Karto.h:764
const DataMap & GetData() const
Definition: Karto.h:6639
virtual void Clear()
Definition: Karto.h:6676
virtual ~Parameter()
Definition: Karto.h:3262
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:4623
const ParameterVector & GetParameters() const
Definition: Karto.h:704
kt_double GetMinimumAngle() const
Definition: Karto.h:4007
void SetIs360Laser(bool is_360_laser)
Definition: Karto.h:4142
virtual void Resize(kt_int32s width, kt_int32s height)
Definition: Karto.h:6408
Name(const Name &rOther)
Definition: Karto.h:408
SensorVector GetAllSensors()
Definition: Karto.h:3798
ParameterManager * m_pParameterManager
Definition: Karto.h:714
#define KARTO_Object(name)
Definition: Karto.h:59
void SetOccupancyThreshold(kt_double thresh)
Definition: Karto.h:6171
virtual ~AbstractParameter()
Definition: Karto.h:3145
RangeReadingsVector GetRangeReadingsVector() const
Definition: Karto.h:5343
virtual void Resize(kt_int32s width, kt_int32s height)
Definition: Karto.h:4705
T * GetSensorByName(const Name &rName)
Definition: Karto.h:3787
virtual ~Dataset()
Definition: Karto.h:6561
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:5104
void MakeFloor(const Vector2 &rOther)
Definition: Karto.h:1062
kt_bool IsDatasetInfo(Object *pObject)
Definition: Karto.h:804
INLINE Rall1d< T, V, S > asin(const Rall1d< T, V, S > &x)
static Grid * CreateGrid(kt_int32s width, kt_int32s height, kt_double resolution)
Definition: Karto.h:4653
void UnregisterSensor(Sensor *pSensor)
Definition: Karto.h:3750
std::map< std::string, kt_int32s > EnumMap
Definition: Karto.h:3411
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:3536
virtual ~ParameterEnum()
Definition: Karto.h:3431
kt_bool GetIs360Laser() const
Definition: Karto.h:4133
BOOST_CLASS_EXPORT_KEY(karto::NonCopyable)
Parameter< kt_double > * m_pRangeThreshold
Definition: Karto.h:4390
virtual kt_bool RayTrace(const Vector2< kt_double > &rWorldFrom, const Vector2< kt_double > &rWorldTo, kt_bool isEndPointValid, kt_bool doUpdate=false)
Definition: Karto.h:6321
void SetPosition(const Vector3< kt_double > &rPosition)
Definition: Karto.h:2344
kt_double GetX() const
Definition: Karto.h:2097
Grid< kt_int32u > * m_pCellPassCnt
Definition: Karto.h:6419
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:368
Parameter< kt_double > * m_pMinimumRange
Definition: Karto.h:4387
std::vector< Pose2 > Pose2Vector
Definition: Karto.h:2269
kt_bool IsInBounds(const Vector2< kt_double > &rPoint) const
Definition: Karto.h:2945
virtual const std::string GetValueAsString() const =0
void SetOffset(const Vector2< kt_double > &rOffset)
Definition: Karto.h:4557
DataMap m_Data
Definition: Karto.h:6714
kt_int32s GetErrorCode()
Definition: Karto.h:153
Matrix3 m_Rotation
Definition: Karto.h:3062
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:3675
const Vector2< T > GetCenter() const
Definition: Karto.h:1987
T * GetDataPointer()
Definition: Karto.h:4877
DatasetInfo * GetDatasetInfo()
Definition: Karto.h:6668
const T & GetValue() const
Definition: Karto.h:3271
virtual Parameter * Clone()
Definition: Karto.h:3311
const std::string & GetAuthor() const
Definition: Karto.h:6493
void ToEulerAngles(kt_double &rYaw, kt_double &rPitch, kt_double &rRoll) const
Definition: Karto.h:1697
std::string m_Name
Definition: Karto.h:3202
T GetWidth() const
Definition: Karto.h:1905
Rectangle2(const Vector2< T > &rPosition, const Size2< T > &rSize)
Definition: Karto.h:1849
T * GetDataPointer(const Vector2< kt_int32s > &rGrid)
Definition: Karto.h:4820
Size2(T width, T height)
Definition: Karto.h:887
kt_double * m_pRangeReadings
Definition: Karto.h:5414
T * GetDataPointer(const Vector2< kt_int32s > &rGrid) const
Definition: Karto.h:4831
std::map< std::string, AbstractParameter * > m_ParameterLookup
Definition: Karto.h:364
Name m_SensorName
Definition: Karto.h:5251
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
EnumMap m_EnumDefines
Definition: Karto.h:3532
kt_int32s m_Height
Definition: Karto.h:5029
virtual kt_bool IsFree(const Vector2< kt_int32s > &rPose) const
Definition: Karto.h:6099
kt_bool InRange(const T &value, const T &a, const T &b)
Definition: Math.h:172
kt_int32u GetRows() const
Definition: Karto.h:2769
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:7089
const T & GetX() const
Definition: Karto.h:1026
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:5037
kt_int32u m_NumberOfRangeReadings
Definition: Karto.h:5415
static SensorManager * GetInstance()
Definition: Karto.cpp:57
#define const_forEach(listtype, list)
Definition: Macros.h:72
Matrix(kt_int32u rows, kt_int32u columns)
Definition: Karto.h:2735
ParameterVector m_Parameters
Definition: Karto.h:363
virtual const std::string GetValueAsString() const
Definition: Karto.h:3476
static OccupancyGrid * CreateFromScans(const LocalizedRangeScanVector &rScans, kt_double resolution)
Definition: Karto.h:6059
kt_bool InverseFast(Matrix3 &rkInverse, kt_double fTolerance=KT_TOLERANCE) const
Definition: Karto.h:2558
CoordinateConverter * GetCoordinateConverter() const
Definition: Karto.h:4915
Parameter< kt_double > * m_pMaximumRange
Definition: Karto.h:4388
void SetSize(kt_int32u size)
Definition: Karto.h:7042
GridIndexLookup(Grid< T > *pGrid)
Definition: Karto.h:6898
virtual ~SensorManager()
Definition: Karto.h:3712
kt_int32s GetType()
Definition: Karto.h:4114
kt_bool IsParameters(Object *pObject)
Definition: Karto.h:794
Vector2< kt_double > m_Offset
Definition: Karto.h:4620
virtual void SetValueFromString(const std::string &rStringValue)=0
Pose2 TransformPose(const Pose2 &rSourcePose)
Definition: Karto.h:3002
Pose2 GetReferencePose(kt_bool useBarycenter) const
Definition: Karto.h:5614
BoundingBox2 GetBoundingBox() const
Definition: Karto.h:4602
void SetOdometricPose(const Pose2 &rPose)
Definition: Karto.h:5547
virtual void CreateFromScans(const LocalizedRangeScanVector &rScans)
Definition: Karto.h:6234
void Validate(const std::string &rName)
Definition: Karto.h:565
Parameter< kt_bool > * m_pIs360Laser
Definition: Karto.h:4392
virtual ~Grid()
Definition: Karto.h:4665
kt_double GetMaximumAngle() const
Definition: Karto.h:4027
void Clear()
Definition: Karto.h:2757
void SetHeight(T height)
Definition: Karto.h:935
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:7097
static LaserRangeFinder * CreateLaserRangeFinder(LaserRangeFinderType type, const Name &rName)
Definition: Karto.h:4185
bool kt_bool
Definition: Types.h:64
Vector2< kt_double > m_Minimum
Definition: Karto.h:2963
kt_double Distance(const Vector2 &rOther) const
Definition: Karto.h:1110
const kt_objecttype ObjectType_DrivePose
Definition: Karto.h:75
DatasetInfo * m_pDatasetInfo
Definition: Karto.h:6715
kt_double GetW() const
Definition: Karto.h:1676
kt_double GetTime() const
Definition: Karto.h:5179
const std::string & GetTitle() const
Definition: Karto.h:6485
Vector2< kt_double > GridToWorld(const Vector2< kt_int32s > &rGrid, kt_bool flipY=false) const
Definition: Karto.h:4509
virtual ~DrivePose()
Definition: Karto.h:5459
void SetName(const std::string &rName)
Definition: Karto.h:434
ParameterEnum * m_pType
Definition: Karto.h:4394
Size2< kt_double > GetSize() const
Definition: Karto.h:2915
virtual ~GridIndexLookup()
Definition: Karto.h:6909
Pose2 GetCorrectedAt(const Pose2 &sPose) const
Computes the pose of the robot if the sensor were at the given pose.
Definition: Karto.h:5668
Vector2< kt_double > GridToWorld(const Vector2< kt_int32s > &rGrid, kt_bool flipY=false) const
Definition: Karto.h:4810
T GetValue(const Vector2< kt_int32s > &rGrid) const
Definition: Karto.h:4905
virtual void SetValueFromString(const std::string &rStringValue)
Definition: Karto.h:3453
kt_int32s m_ErrorCode
Definition: Karto.h:168
virtual ~LocalizedRangeScan()
Definition: Karto.h:5526
LookupArray ** m_ppLookupArray
Definition: Karto.h:7091
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:3894
void SetPosition(const Vector2< kt_double > &rPosition)
Definition: Karto.h:2142
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
void SetCorrectedPoseAndUpdate(const Pose2 &rPose)
Definition: Karto.h:5580
void Parse(const std::string &rName)
Definition: Karto.h:540
virtual ~Drive()
Definition: Karto.h:3869
void SetSize(kt_int32u size)
Definition: Karto.h:6791
void SetMinimumRange(kt_double minimumRange)
Definition: Karto.h:3952
Read
kt_int32u m_Rows
Definition: Karto.h:2854
const Name & GetName() const
Definition: Karto.h:656
CustomDataVector m_CustomData
Definition: Karto.h:5258
void SetZ(kt_double z)
Definition: Karto.h:1667
void SetRangeReadings(const RangeReadingsVector &rRangeReadings)
Definition: Karto.h:5352
BoundingBox2 GetBoundingBox() const
Definition: Karto.h:4933
const std::string & GetName() const
Definition: Karto.h:3154
virtual Parameter< kt_int32s > * Clone()
Definition: Karto.h:3440
T GetX() const
Definition: Karto.h:1869
void SetCorrectedPose(const Pose2 &rPose)
Definition: Karto.h:5569
kt_double m_Matrix[3][3]
Definition: Karto.h:2713
Parameter< std::string > * m_pCopyright
Definition: Karto.h:6526
void SetWidth(T width)
Definition: Karto.h:1914
void SetY(kt_double y)
Definition: Karto.h:1649
virtual kt_bool Process(karto::Object *)
Definition: Karto.h:844
void SetTransform(const Pose2 &rPose1, const Pose2 &rPose2)
Definition: Karto.h:3030
Parameter< kt_double > * m_pMaximumAngle
Definition: Karto.h:4383
const T & GetY() const
Definition: Karto.h:1351
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
kt_bool IsValid(char c)
Definition: Karto.h:605
Rectangle2(T x, T y, T width, T height)
Definition: Karto.h:1838
std::string m_Name
Definition: Karto.h:611
Matrix3 m_InverseRotation
Definition: Karto.h:3063
T Square(T value)
Definition: Math.h:77
void MakeFloor(const Vector3 &rOther)
Definition: Karto.h:1387
OccupancyGrid * Clone() const
Definition: Karto.h:6079
void SetOdometricPose(const Pose3 &rPose)
Definition: Karto.h:5477
const std::string & GetScope() const
Definition: Karto.h:449
kt_bool IsSensor(Object *pObject)
Definition: Karto.h:744
const Pose2 & GetOffsetPose() const
Definition: Karto.h:3630
const kt_double & operator()(kt_int32u row, kt_int32u column) const
Definition: Karto.h:2802
PointVectorDouble m_PointReadings
Definition: Karto.h:5856
void SetTime(kt_double time)
Definition: Karto.h:5188
OccupancyGrid * m_pOccupancyGrid
Definition: Karto.h:6000
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:3835
kt_double m_Values[4]
Definition: Karto.h:1809
kt_bool DoubleEqual(kt_double a, kt_double b)
Definition: Math.h:135
Transform(const Pose2 &rPose1, const Pose2 &rPose2)
Definition: Karto.h:2991
Pose3(const Pose2 &rPose)
Definition: Karto.h:2324
void SetHeading(kt_double heading)
Definition: Karto.h:2160
CoordinateConverter * m_pCoordinateConverter
Definition: Karto.h:5034
const std::string & GetCopyright() const
Definition: Karto.h:6509
double kt_double
Definition: Types.h:67
void SetX(kt_double x)
Definition: Karto.h:2106
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:1268
const T GetWidth() const
Definition: Karto.h:908
void Add(Object *pObject, kt_bool overrideSensorName=false)
Definition: Karto.h:6595
const BoundingBox2 & GetBoundingBox() const
Definition: Karto.h:5686
Definition: Karto.h:86
SensorManagerMap m_Sensors
Definition: Karto.h:3831
void RegisterSensor(Sensor *pSensor, kt_bool override=false)
Definition: Karto.h:3730
Pose2 InverseTransformPose(const Pose2 &rSourcePose)
Definition: Karto.h:3015
const ParameterVector & GetParameterVector() const
Definition: Karto.h:338
const T & GetY() const
Definition: Karto.h:1044
T * GetDataPointer() const
Definition: Karto.h:4886
const kt_objecttype ObjectType_Parameters
Definition: Karto.h:82
virtual ~NonCopyable()
Definition: Karto.h:190
void SetIsDirty(kt_bool &rIsDirty)
Definition: Karto.h:5637
OccupancyGrid(kt_int32s width, kt_int32s height, const Vector2< kt_double > &rOffset, kt_double resolution)
Definition: Karto.h:6019
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
const std::string & GetDescription() const
Definition: Karto.h:3163
kt_double GetY() const
Definition: Karto.h:2115
const Vector2< kt_double > & GetMinimum() const
Definition: Karto.h:2883
const LookupArray * GetLookupArray(kt_int32u index) const
Definition: Karto.h:6920
Vector3(T x, T y, T z)
Definition: Karto.h:1310
kt_double GetMinimumRange() const
Definition: Karto.h:3943
void RemoveData(LocalizedRangeScan *scan)
Definition: Karto.h:6648
void SetMaximum(const Vector2< kt_double > &rMaximum)
Definition: Karto.h:2907
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:5819
const ObjectVector & GetLasers() const
Definition: Karto.h:6630
std::ostream & operator<<(std::ostream &rStream, Exception &rException)
Definition: Karto.cpp:151
void SetOrientation(const Quaternion &rOrientation)
Definition: Karto.h:2362
virtual ~Matrix()
Definition: Karto.h:2748
Grid< kt_int32u > * m_pCellHitsCnt
Definition: Karto.h:6424
const Vector2< kt_double > & GetMaximum() const
Definition: Karto.h:2899
void SetZ(const T &z)
Definition: Karto.h:1378
virtual Grid< kt_int32u > * GetCellHitsCounts()
Definition: Karto.h:6181
const std::string & GetErrorMessage() const
Definition: Karto.h:144
const kt_objecttype ObjectType_LaserRangeScan
Definition: Karto.h:76
const kt_double KT_PI_2
Definition: Math.h:34
kt_int32u m_Capacity
Definition: Karto.h:6852
GridStates
Definition: Karto.h:4442
LocalizedRangeScan(const Name &rSensorName, const RangeReadingsVector &rReadings)
Definition: Karto.h:5514
std::vector< AbstractParameter * > ParameterVector
Definition: Karto.h:277
void Allocate()
Definition: Karto.h:2813
void RangeCheck(kt_int32u row, kt_int32u column) const
Definition: Karto.h:2840
ParameterEnum(const std::string &rName, kt_int32s value, ParameterManager *pParameterManger=NULL)
Definition: Karto.h:3420
std::map< Name, Sensor * > m_SensorNameLookup
Definition: Karto.h:6712
kt_double m_Heading
Definition: Karto.h:2263
#define const_forEachAs(listtype, list, iter)
Definition: Macros.h:75
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:855
const kt_objecttype ObjectType_LocalizedRangeScanWithPoints
Definition: Karto.h:79
void SetY(const T &y)
Definition: Karto.h:1053
T * m_pData
Definition: Karto.h:5031
Transform(const Pose2 &rPose)
Definition: Karto.h:2981
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
virtual ~Exception()
Definition: Karto.h:123
virtual kt_bool Validate(SensorData *pSensorData)
Definition: Karto.h:3879
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:3579
uint32_t kt_int32u
Definition: Types.h:52
kt_double Length() const
Definition: Karto.h:1418
const CustomDataVector & GetCustomData() const
Definition: Karto.h:5215
T m_Values[3]
Definition: Karto.h:1549
CellUpdater(OccupancyGrid *pGrid)
Definition: Karto.h:5988
kt_double m_Time
Definition: Karto.h:5256
#define KARTO_EXPORT
Definition: Macros.h:56
kt_bool IsUpTo(const T &value, const T &maximum)
Definition: Math.h:147
std::string ToString() const
Definition: Karto.h:2597
Exception(const Exception &rException)
Definition: Karto.h:114
std::map< Name, Sensor * > SensorManagerMap
Definition: Karto.h:3694
void SetPointReadings(PointVectorDouble &points, kt_bool setFiltered=false)
Definition: Karto.h:5729
kt_bool IsLocalizedRangeScan(Object *pObject)
Definition: Karto.h:774
virtual void SetValueFromString(const std::string &rStringValue)
Definition: Karto.h:3300
void SetY(kt_double y)
Definition: Karto.h:2124
const kt_objecttype ObjectType_Drive
Definition: Karto.h:71
Grid(kt_int32s width, kt_int32s height)
Definition: Karto.h:5020
Name m_Name
Definition: Karto.h:713
kt_int32u m_Columns
Definition: Karto.h:2855
std::vector< LocalizedRangeScan * > LocalizedRangeScanVector
Definition: Karto.h:5877
void AddCustomData(CustomData *pCustomData)
Definition: Karto.h:5206
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:6721
void SetMinPassThrough(kt_int32u count)
Definition: Karto.h:6162
Vector3< kt_double > m_Position
Definition: Karto.h:2431
T GetY() const
Definition: Karto.h:1887
kt_double Transform(kt_double value)
Definition: Karto.h:4475
std::map< int, LocalizedRangeScan * > LocalizedRangeScanMap
Definition: Karto.h:5878
void serialize(Archive &ar, const unsigned int version)
Definition: Karto.h:618
kt_double GetHeading() const
Definition: Karto.h:2151
void FromAxisAngle(kt_double x, kt_double y, kt_double z, const kt_double radians)
Definition: Karto.h:2490
void MakeCeil(const Vector3 &rOther)
Definition: Karto.h:1398


slam_toolbox
Author(s): Steve Macenski
autogenerated on Mon Feb 28 2022 23:46:49