Mapper.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_MAPPER_H
19 #define karto_sdk_MAPPER_H
20 
21 #include <map>
22 #include <vector>
23 #include <unordered_map>
24 #include <queue>
25 
26 #include <Eigen/Core>
27 
28 #include "tbb/parallel_for.h"
29 #include "tbb/blocked_range.h"
30 #include "tbb/tbb.h"
31 #include <algorithm>
32 #include <chrono>
33 
34 #include <karto_sdk/Karto.h>
35 
36 #include "nanoflann_adaptors.h"
37 
38 namespace karto
39 {
41  // Listener classes
42 
47  {
48  public:
52  virtual void Info(const std::string& /*rInfo*/) {};
53  friend class boost::serialization::access;
54  template<class Archive>
55  void serialize(Archive &ar, const unsigned int version)
56  {
57  }
58  };
59  BOOST_SERIALIZATION_ASSUME_ABSTRACT(MapperListener)
64  {
65  public:
69  virtual void Debug(const std::string& /*rInfo*/) {};
70  friend class boost::serialization::access;
71  template<class Archive>
72  void serialize(Archive &ar, const unsigned int version)
73  {
74  }
75  };
76  BOOST_SERIALIZATION_ASSUME_ABSTRACT(MapperDebugListener)
81  {
82  public:
86  virtual void LoopClosureCheck(const std::string& /*rInfo*/) {};
87 
91  virtual void BeginLoopClosure(const std::string& /*rInfo*/) {};
92 
96  virtual void EndLoopClosure(const std::string& /*rInfo*/) {};
97  friend class boost::serialization::access;
98  template<class Archive>
99  void serialize(Archive &ar, const unsigned int version)
100  {
101  }
102  }; // MapperLoopClosureListener
103  BOOST_SERIALIZATION_ASSUME_ABSTRACT(MapperLoopClosureListener)
107 
111  class EdgeLabel
112  {
113  public:
118  {
119  }
120 
124  virtual ~EdgeLabel()
125  {
126  }
127  friend class boost::serialization::access;
128  template<class Archive>
129  void serialize(Archive &ar, const unsigned int version)
130  {
131  }
132  }; // EdgeLabel
133 
137 
138  // A LinkInfo object contains the requisite information for the "spring"
139  // that links two scans together--the pose difference and the uncertainty
140  // (represented by a covariance matrix).
141  class LinkInfo : public EdgeLabel
142  {
143  public:
151  {
152  }
153  LinkInfo(const Pose2& rPose1, const Pose2& rPose2, const Matrix3& rCovariance)
154  {
155  Update(rPose1, rPose2, rCovariance);
156  }
157 
161  virtual ~LinkInfo()
162  {
163  }
164 
165  public:
172  void Update(const Pose2& rPose1, const Pose2& rPose2, const Matrix3& rCovariance)
173  {
174  m_Pose1 = rPose1;
175  m_Pose2 = rPose2;
176 
177  // transform second pose into the coordinate system of the first pose
178  Transform transform(rPose1, Pose2());
179  m_PoseDifference = transform.TransformPose(rPose2);
180 
181  // transform covariance into reference of first pose
182  Matrix3 rotationMatrix;
183  rotationMatrix.FromAxisAngle(0, 0, 1, -rPose1.GetHeading());
184 
185  m_Covariance = rotationMatrix * rCovariance * rotationMatrix.Transpose();
186  }
187 
192  inline const Pose2& GetPose1()
193  {
194  return m_Pose1;
195  }
196 
201  inline const Pose2& GetPose2()
202  {
203  return m_Pose2;
204  }
205 
210  inline const Pose2& GetPoseDifference()
211  {
212  return m_PoseDifference;
213  }
214 
219  inline const Matrix3& GetCovariance()
220  {
221  return m_Covariance;
222  }
223 
224  private:
229 
230  friend class boost::serialization::access;
231  template<class Archive>
232  void serialize(Archive &ar, const unsigned int version)
233  {
234  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(EdgeLabel);
235  ar & BOOST_SERIALIZATION_NVP(m_Pose1);
236  ar & BOOST_SERIALIZATION_NVP(m_Pose2);
237  ar & BOOST_SERIALIZATION_NVP(m_PoseDifference);
238  ar & BOOST_SERIALIZATION_NVP(m_Covariance);
239  }
240  }; // LinkInfo
241 
245 
246  template<typename T>
247  class Edge;
248 
252  template<typename T>
253  class Vertex
254  {
255  friend class Edge<T>;
256 
257  public:
263  : m_pObject(NULL), m_Score(1.0)
264  {
265  }
266  Vertex(T* pObject)
267  : m_pObject(pObject), m_Score(1.0)
268  {
269  }
270 
274  virtual ~Vertex()
275  {
276  }
277 
282  inline const std::vector<Edge<T>*>& GetEdges() const
283  {
284  return m_Edges;
285  }
286 
290  inline void RemoveEdge(const int& idx)
291  {
292  m_Edges[idx] = NULL;
293  m_Edges.erase(m_Edges.begin() + idx);
294  return;
295  }
296 
301  inline const double GetScore() const
302  {
303  return m_Score;
304  }
305 
310  inline void SetScore(const double score)
311  {
312  m_Score = score;
313  }
314 
319  inline T* GetObject() const
320  {
321  return m_pObject;
322  }
323 
327  inline void RemoveObject()
328  {
329  m_pObject = NULL;
330  }
331 
336  std::vector<Vertex<T>*> GetAdjacentVertices() const
337  {
338  std::vector<Vertex<T>*> vertices;
339 
340  const_forEach(typename std::vector<Edge<T>*>, &m_Edges)
341  {
342  Edge<T>* pEdge = *iter;
343 
344  if (pEdge == NULL)
345  {
346  continue;
347  }
348 
349  // check both source and target because we have a undirected graph
350  if (pEdge->GetSource() != this)
351  {
352  vertices.push_back(pEdge->GetSource());
353  }
354 
355  if (pEdge->GetTarget() != this)
356  {
357  vertices.push_back(pEdge->GetTarget());
358  }
359  }
360 
361  return vertices;
362  }
363 
364  private:
369  inline void AddEdge(Edge<T>* pEdge)
370  {
371  m_Edges.push_back(pEdge);
372  }
373 
375  std::vector<Edge<T>*> m_Edges;
377 
378  friend class boost::serialization::access;
379  template<class Archive>
380  void serialize(Archive &ar, const unsigned int version)
381  {
382  ar & BOOST_SERIALIZATION_NVP(m_pObject);
383  ar & BOOST_SERIALIZATION_NVP(m_Edges);
384  ar & BOOST_SERIALIZATION_NVP(m_Score);
385  }
386  }; // Vertex<T>
387 
391 
395  template<typename T>
396  class Edge
397  {
398  public:
405  : m_pSource(NULL)
406  , m_pTarget(NULL)
407  , m_pLabel(NULL)
408  {
409  }
410  Edge(Vertex<T>* pSource, Vertex<T>* pTarget)
411  : m_pSource(pSource)
412  , m_pTarget(pTarget)
413  , m_pLabel(NULL)
414  {
415  m_pSource->AddEdge(this);
416  m_pTarget->AddEdge(this);
417  }
418 
422  virtual ~Edge()
423  {
424  m_pSource = NULL;
425  m_pTarget = NULL;
426 
427  if (m_pLabel != NULL)
428  {
429  delete m_pLabel;
430  m_pLabel = NULL;
431  }
432  }
433 
434  public:
439  inline Vertex<T>* GetSource() const
440  {
441  return m_pSource;
442  }
443 
448  inline Vertex<T>* GetTarget() const
449  {
450  return m_pTarget;
451  }
452 
457  inline EdgeLabel* GetLabel()
458  {
459  return m_pLabel;
460  }
461 
466  inline void SetLabel(EdgeLabel* pLabel)
467  {
468  m_pLabel = pLabel;
469  }
470 
471  private:
475 
476  friend class boost::serialization::access;
477  template<class Archive>
478  void serialize(Archive &ar, const unsigned int version)
479  {
480  ar & BOOST_SERIALIZATION_NVP(m_pSource);
481  ar & BOOST_SERIALIZATION_NVP(m_pTarget);
482  ar & BOOST_SERIALIZATION_NVP(m_pLabel);
483  }
484  }; // class Edge<T>
485 
489 
493  template<typename T>
494  class Visitor
495  {
496  public:
502  virtual kt_bool Visit(Vertex<T>* pVertex) = 0;
503  friend class boost::serialization::access;
504  template<class Archive>
505  void serialize(Archive &ar, const unsigned int version)
506  {
507  }
508  }; // Visitor<T>
509  BOOST_SERIALIZATION_ASSUME_ABSTRACT(Visitor<LocalizedRangeScan>)
513 
514  template<typename T>
515  class Graph;
516 
520  template<typename T>
522  {
523  public:
525  {
526  }
528  : m_pGraph(pGraph)
529  {
530  }
531 
532  virtual ~GraphTraversal()
533  {
534  }
535 
536  public:
537 
538  virtual std::vector<T*> TraverseForScans(Vertex<T>* pStartVertex, Visitor<T>* pVisitor) = 0;
539  virtual std::vector<Vertex<T>*> TraverseForVertices(Vertex<T>* pStartVertex, Visitor<T>* pVisitor) = 0;
540 
541  protected:
543 
544  friend class boost::serialization::access;
545  template<class Archive>
546  void serialize(Archive &ar, const unsigned int version)
547  {
548  ar & BOOST_SERIALIZATION_NVP(m_pGraph);
549  }
550  }; // GraphTraversal<T>
551  BOOST_SERIALIZATION_ASSUME_ABSTRACT(GraphTraversal<LocalizedRangeScan>)
552 
553 
554 
560  template<typename T>
561  class Graph
562  {
563  public:
567  typedef std::map<Name, std::map<int, Vertex<T>*> > VertexMap;
568 
569  public:
574  {
575  }
576 
580  virtual ~Graph()
581  {
582  Clear();
583  }
584 
585  public:
591  inline void AddVertex(const Name& rName, Vertex<T>* pVertex)
592  {
593  m_Vertices[rName].insert({pVertex->GetObject()->GetStateId(), pVertex});
594  }
595 
601  inline void RemoveVertex(const Name& rName, const int& idx)
602  {
603  std::map<int, Vertex<LocalizedRangeScan>* >::iterator it = m_Vertices[rName].find(idx);
604  if (it != m_Vertices[rName].end())
605  {
606  it->second = NULL;
607  m_Vertices[rName].erase(it);
608  }
609  else
610  {
611  std::cout << "RemoveVertex: Failed to remove vertex " << idx
612  << " because it doesnt exist in m_Vertices." << std::endl;
613  }
614  }
615 
620  inline void AddEdge(Edge<T>* pEdge)
621  {
622  m_Edges.push_back(pEdge);
623  }
624 
629  inline void RemoveEdge(const int& idx)
630  {
631  m_Edges[idx] = NULL;
632  m_Edges.erase(m_Edges.begin() + idx);
633  }
634 
635 
639  void Clear()
640  {
641  forEachAs(typename VertexMap, &m_Vertices, indexIter)
642  {
643  // delete each vertex
644  typename std::map<int, Vertex<T>*>::iterator iter;
645  for (iter = indexIter->second.begin(); iter != indexIter->second.end(); ++iter)
646  {
647  delete iter->second;
648  iter->second = nullptr;
649  }
650  }
651  m_Vertices.clear();
652 
653  forEach(typename std::vector<Edge<T>*>, &m_Edges)
654  {
655  delete *iter;
656  *iter = nullptr;
657  }
658  m_Edges.clear();
659  }
660 
665  inline const std::vector<Edge<T>*>& GetEdges() const
666  {
667  return m_Edges;
668  }
669 
674  inline const VertexMap& GetVertices() const
675  {
676  return m_Vertices;
677  }
678 
679  protected:
683  VertexMap m_Vertices;
684 
688  std::vector<Edge<T>*> m_Edges;
692  friend class boost::serialization::access;
693  template<class Archive>
694  void serialize(Archive &ar, const unsigned int version)
695  {
696  std::cout << "Graph <- m_Edges; ";
697  ar & BOOST_SERIALIZATION_NVP(m_Edges);
698  std::cout << "Graph <- m_Vertices\n";
699  ar & BOOST_SERIALIZATION_NVP(m_Vertices);
700  }
701  }; // Graph<T>
702 
706 
707  class Mapper;
708  class ScanMatcher;
709 
713  class KARTO_EXPORT MapperGraph : public Graph<LocalizedRangeScan>
714  {
715  public:
721  MapperGraph(Mapper* pMapper, kt_double rangeThreshold);
723  {
724  }
728  virtual ~MapperGraph();
729 
730  public:
736 
745  Edge<LocalizedRangeScan>* AddEdge(LocalizedRangeScan* pSourceScan,
746  LocalizedRangeScan* pTargetScan,
747  kt_bool& rIsNewEdge);
748 
754  void AddEdges(LocalizedRangeScan* pScan, const Matrix3& rCovariance);
755 
761  kt_bool TryCloseLoop(LocalizedRangeScan* pScan, const Name& rSensorName);
762 
766  void CorrectPoses();
767 
773  LocalizedRangeScanVector FindNearLinkedScans(LocalizedRangeScan* pScan, kt_double maxDistance);
774 
780  std::vector<Vertex<LocalizedRangeScan>*> FindNearLinkedVertices(LocalizedRangeScan* pScan, kt_double maxDistance);
781 
787  LocalizedRangeScanVector FindNearByScans(Name name, const Pose2 refPose, kt_double maxDistance);
788 
794  std::vector<Vertex<LocalizedRangeScan>*> FindNearByVertices(Name name, const Pose2 refPose, kt_double maxDistance);
795 
800  Vertex<LocalizedRangeScan>* FindNearByScan(Name name, const Pose2 refPose);
801 
807  {
808  return m_pLoopScanMatcher;
809  }
810 
815  void UpdateLoopScanMatcher(kt_double rangeThreshold);
816 
817  private:
824  {
825  Name rName = pScan->GetSensorName();
826  std::map<int, Vertex<LocalizedRangeScan>* >::iterator it = m_Vertices[rName].find(pScan->GetStateId());
827  if (it != m_Vertices[rName].end())
828  {
829  return it->second;
830  }
831  else
832  {
833  std::cout << "GetVertex: Failed to get vertex, idx " << pScan->GetStateId() <<
834  " is not in m_Vertices." << std::endl;
835  return nullptr;
836  }
837  }
838 
844  LocalizedRangeScan* GetClosestScanToPose(const LocalizedRangeScanVector& rScans, const Pose2& rPose) const;
845 
853  void LinkScans(LocalizedRangeScan* pFromScan,
854  LocalizedRangeScan* pToScan,
855  const Pose2& rMean,
856  const Matrix3& rCovariance);
857 
864  void LinkNearChains(LocalizedRangeScan* pScan, Pose2Vector& rMeans, std::vector<Matrix3>& rCovariances);
865 
873  void LinkChainToScan(const LocalizedRangeScanVector& rChain,
874  LocalizedRangeScan* pScan,
875  const Pose2& rMean,
876  const Matrix3& rCovariance);
877 
883  std::vector<LocalizedRangeScanVector> FindNearChains(LocalizedRangeScan* pScan);
884 
891  Pose2 ComputeWeightedMean(const Pose2Vector& rMeans, const std::vector<Matrix3>& rCovariances) const;
892 
901  LocalizedRangeScanVector FindPossibleLoopClosure(LocalizedRangeScan* pScan,
902  const Name& rSensorName,
903  kt_int32u& rStartNum);
904 
905  private:
910 
915 
920 
924  friend class boost::serialization::access;
925  template<class Archive>
926  void serialize(Archive &ar, const unsigned int version)
927  {
928  std::cout << "MapperGraph <- Graph; ";
929  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Graph<LocalizedRangeScan>);
930  std::cout << "MapperGraph <- m_pMapper; ";
931  ar & BOOST_SERIALIZATION_NVP(m_pMapper);
932  std::cout << "MapperGraph <- m_pLoopScanMatcher; ";
933  ar & BOOST_SERIALIZATION_NVP(m_pLoopScanMatcher);
934  std::cout << "MapperGraph <- m_pTraversal\n";
935  ar & BOOST_SERIALIZATION_NVP(m_pTraversal);
936  }
937 
938  }; // MapperGraph
939 
943 
948  {
949  public:
953  typedef std::vector<std::pair<kt_int32s, Pose2> > IdPoseVector;
954 
959  {
960  }
961 
965  virtual ~ScanSolver()
966  {
967  }
968 
969  public:
973  virtual void Compute() = 0;
974 
979  virtual const IdPoseVector& GetCorrections() const = 0;
980 
984  virtual void AddNode(Vertex<LocalizedRangeScan>* /*pVertex*/)
985  {
986  }
987 
991  virtual void RemoveNode(kt_int32s /*id*/)
992  {
993  }
994 
998  virtual void AddConstraint(Edge<LocalizedRangeScan>* /*pEdge*/)
999  {
1000  }
1001 
1005  virtual void RemoveConstraint(kt_int32s /*sourceId*/, kt_int32s /*targetId*/)
1006  {
1007  }
1008 
1012  virtual void Clear()
1013  {
1014  }
1015 
1019  virtual void Reset()
1020  {
1021  }
1022 
1026  virtual std::unordered_map<int, Eigen::Vector3d>* getGraph()
1027  {
1028  std::cout << "getGraph method not implemented for this solver type. Graph visualization unavailable." << std::endl;
1029  }
1030 
1034  virtual void ModifyNode(const int& unique_id, Eigen::Vector3d pose)
1035  {
1036  std::cout << "ModifyNode method not implemented for this solver type. Manual loop closure unavailable." << std::endl;
1037  };
1041  virtual void GetNodeOrientation(const int& unique_id, double& pose)
1042  {
1043  std::cout << "GetNodeOrientation method not implemented for this solver type." << std::endl;
1044  };
1045 
1046  friend class boost::serialization::access;
1047  template<class Archive>
1048  void serialize(Archive &ar, const unsigned int version)
1049  {
1050  }
1051  }; // ScanSolver
1052  BOOST_SERIALIZATION_ASSUME_ABSTRACT(ScanSolver)
1056 
1061  {
1062  public:
1067  {
1068  if (m_pKernel)
1069  {
1070  delete [] m_pKernel;
1071  }
1072 
1073  }
1074 
1075  public:
1085  {
1086  }
1088  kt_int32s height,
1089  kt_double resolution,
1090  kt_double smearDeviation)
1091  {
1092  assert(resolution != 0.0);
1093 
1094  // +1 in case of roundoff
1095  kt_int32u borderSize = GetHalfKernelSize(smearDeviation, resolution) + 1;
1096 
1097  CorrelationGrid* pGrid = new CorrelationGrid(width, height, borderSize, resolution, smearDeviation);
1098 
1099  return pGrid;
1100  }
1101 
1108  virtual kt_int32s GridIndex(const Vector2<kt_int32s>& rGrid, kt_bool boundaryCheck = true) const
1109  {
1110  kt_int32s x = rGrid.GetX() + m_Roi.GetX();
1111  kt_int32s y = rGrid.GetY() + m_Roi.GetY();
1112 
1113  return Grid<kt_int8u>::GridIndex(Vector2<kt_int32s>(x, y), boundaryCheck);
1114  }
1115 
1120  inline const Rectangle2<kt_int32s>& GetROI() const
1121  {
1122  return m_Roi;
1123  }
1124 
1129  inline void SetROI(const Rectangle2<kt_int32s>& roi)
1130  {
1131  m_Roi = roi;
1132  }
1133 
1138  inline void SmearPoint(const Vector2<kt_int32s>& rGridPoint)
1139  {
1140  assert(m_pKernel != NULL);
1141 
1142  int gridIndex = GridIndex(rGridPoint);
1143  if (GetDataPointer()[gridIndex] != GridStates_Occupied)
1144  {
1145  return;
1146  }
1147 
1148  kt_int32s halfKernel = m_KernelSize / 2;
1149 
1150  // apply kernel
1151  for (kt_int32s j = -halfKernel; j <= halfKernel; j++)
1152  {
1153  kt_int8u* pGridAdr = GetDataPointer(Vector2<kt_int32s>(rGridPoint.GetX(), rGridPoint.GetY() + j));
1154 
1155  kt_int32s kernelConstant = (halfKernel) + m_KernelSize * (j + halfKernel);
1156 
1157  // if a point is on the edge of the grid, there is no problem
1158  // with running over the edge of allowable memory, because
1159  // the grid has margins to compensate for the kernel size
1160  for (kt_int32s i = -halfKernel; i <= halfKernel; i++)
1161  {
1162  kt_int32s kernelArrayIndex = i + kernelConstant;
1163 
1164  kt_int8u kernelValue = m_pKernel[kernelArrayIndex];
1165  if (kernelValue > pGridAdr[i])
1166  {
1167  // kernel value is greater, so set it to kernel value
1168  pGridAdr[i] = kernelValue;
1169  }
1170  }
1171  }
1172  }
1173 
1174  protected:
1183  CorrelationGrid(kt_int32u width, kt_int32u height, kt_int32u borderSize,
1184  kt_double resolution, kt_double smearDeviation)
1185  : Grid<kt_int8u>(width + borderSize * 2, height + borderSize * 2)
1186  , m_SmearDeviation(smearDeviation)
1187  , m_pKernel(NULL)
1188  {
1189  GetCoordinateConverter()->SetScale(1.0 / resolution);
1190 
1191  // setup region of interest
1192  m_Roi = Rectangle2<kt_int32s>(borderSize, borderSize, width, height);
1193 
1194  // calculate kernel
1195  CalculateKernel();
1196  }
1197 
1201  virtual void CalculateKernel()
1202  {
1203  kt_double resolution = GetResolution();
1204 
1205  assert(resolution != 0.0);
1206  assert(m_SmearDeviation != 0.0);
1207 
1208  // min and max distance deviation for smearing;
1209  // will smear for two standard deviations, so deviation must be at least 1/2 of the resolution
1210  const kt_double MIN_SMEAR_DISTANCE_DEVIATION = 0.5 * resolution;
1211  const kt_double MAX_SMEAR_DISTANCE_DEVIATION = 10 * resolution;
1212 
1213  // check if given value too small or too big
1214  if (!math::InRange(m_SmearDeviation, MIN_SMEAR_DISTANCE_DEVIATION, MAX_SMEAR_DISTANCE_DEVIATION))
1215  {
1216  std::stringstream error;
1217  error << "Mapper Error: Smear deviation too small: Must be between "
1218  << MIN_SMEAR_DISTANCE_DEVIATION
1219  << " and "
1220  << MAX_SMEAR_DISTANCE_DEVIATION;
1221  throw std::runtime_error(error.str());
1222  }
1223 
1224  // NOTE: Currently assumes a two-dimensional kernel
1225 
1226  // +1 for center
1227  m_KernelSize = 2 * GetHalfKernelSize(m_SmearDeviation, resolution) + 1;
1228 
1229  // allocate kernel
1230  m_pKernel = new kt_int8u[m_KernelSize * m_KernelSize];
1231  if (m_pKernel == NULL)
1232  {
1233  throw std::runtime_error("Unable to allocate memory for kernel!");
1234  }
1235 
1236  // calculate kernel
1237  kt_int32s halfKernel = m_KernelSize / 2;
1238  for (kt_int32s i = -halfKernel; i <= halfKernel; i++)
1239  {
1240  for (kt_int32s j = -halfKernel; j <= halfKernel; j++)
1241  {
1242 #ifdef WIN32
1243  kt_double distanceFromMean = _hypot(i * resolution, j * resolution);
1244 #else
1245  kt_double distanceFromMean = hypot(i * resolution, j * resolution);
1246 #endif
1247  kt_double z = exp(-0.5 * pow(distanceFromMean / m_SmearDeviation, 2));
1248 
1249  kt_int32u kernelValue = static_cast<kt_int32u>(math::Round(z * GridStates_Occupied));
1250  assert(math::IsUpTo(kernelValue, static_cast<kt_int32u>(255)));
1251 
1252  int kernelArrayIndex = (i + halfKernel) + m_KernelSize * (j + halfKernel);
1253  m_pKernel[kernelArrayIndex] = static_cast<kt_int8u>(kernelValue);
1254  }
1255  }
1256  }
1257 
1265  static kt_int32s GetHalfKernelSize(kt_double smearDeviation, kt_double resolution)
1266  {
1267  assert(resolution != 0.0);
1268 
1269  return static_cast<kt_int32s>(math::Round(2.0 * smearDeviation / resolution));
1270  }
1271 
1272  private:
1278 
1279  // Size of one side of the kernel
1281 
1282  // Cached kernel for smearing
1284 
1285  // region of interest
1290  friend class boost::serialization::access;
1291  template<class Archive>
1292  void serialize(Archive &ar, const unsigned int version)
1293  {
1294  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Grid<kt_int8u>);
1295  ar & BOOST_SERIALIZATION_NVP(m_SmearDeviation);
1296  ar & BOOST_SERIALIZATION_NVP(m_KernelSize);
1297  if (Archive::is_loading::value)
1298  {
1299  m_pKernel = new kt_int8u[m_KernelSize * m_KernelSize];
1300  }
1301  ar & boost::serialization::make_array<kt_int8u>(m_pKernel, m_KernelSize * m_KernelSize);
1302  ar & BOOST_SERIALIZATION_NVP(m_Roi);
1303  }
1304  }; // CorrelationGrid
1305  BOOST_SERIALIZATION_ASSUME_ABSTRACT(CorrelationGrid)
1309 
1314  {
1315  public:
1317  {
1318  }
1322  virtual ~ScanMatcher();
1323 
1324  public:
1328  void operator() (const kt_double& y) const;
1329 
1333  static ScanMatcher* Create(Mapper* pMapper,
1334  kt_double searchSize,
1335  kt_double resolution,
1336  kt_double smearDeviation,
1337  kt_double rangeThreshold);
1338 
1349  template<class T = LocalizedRangeScanVector>
1350  kt_double MatchScan(LocalizedRangeScan* pScan,
1351  const T& rBaseScans,
1352  Pose2& rMean, Matrix3& rCovariance,
1353  kt_bool doPenalize = true,
1354  kt_bool doRefineMatch = true);
1355 
1372  kt_double CorrelateScan(LocalizedRangeScan* pScan,
1373  const Pose2& rSearchCenter,
1374  const Vector2<kt_double>& rSearchSpaceOffset,
1375  const Vector2<kt_double>& rSearchSpaceResolution,
1376  kt_double searchAngleOffset,
1377  kt_double searchAngleResolution,
1378  kt_bool doPenalize,
1379  Pose2& rMean,
1380  Matrix3& rCovariance,
1381  kt_bool doingFineMatch);
1382 
1393  void ComputePositionalCovariance(const Pose2& rBestPose,
1394  kt_double bestResponse,
1395  const Pose2& rSearchCenter,
1396  const Vector2<kt_double>& rSearchSpaceOffset,
1397  const Vector2<kt_double>& rSearchSpaceResolution,
1398  kt_double searchAngleResolution,
1399  Matrix3& rCovariance);
1400 
1410  void ComputeAngularCovariance(const Pose2& rBestPose,
1411  kt_double bestResponse,
1412  const Pose2& rSearchCenter,
1413  kt_double searchAngleOffset,
1414  kt_double searchAngleResolution,
1415  Matrix3& rCovariance);
1416 
1422  {
1423  return m_pCorrelationGrid;
1424  }
1425 
1426  private:
1432  void AddScans(const LocalizedRangeScanVector& rScans, Vector2<kt_double> viewPoint);
1433  void AddScans(const LocalizedRangeScanMap& rScans, Vector2<kt_double> viewPoint);
1434 
1441  void AddScan(LocalizedRangeScan* pScan, const Vector2<kt_double>& rViewPoint, kt_bool doSmear = true);
1442 
1449  PointVectorDouble FindValidPoints(LocalizedRangeScan* pScan, const Vector2<kt_double>& rViewPoint) const;
1450 
1457  kt_double GetResponse(kt_int32u angleIndex, kt_int32s gridPositionIndex) const;
1458 
1459  protected:
1464  : m_pMapper(pMapper)
1465  , m_pCorrelationGrid(NULL)
1466  , m_pSearchSpaceProbs(NULL)
1467  , m_pGridLookup(NULL)
1468  , m_pPoseResponse(NULL)
1469  , m_doPenalize(false)
1470  {
1471  }
1472 
1473  private:
1478  std::pair<kt_double, Pose2>* m_pPoseResponse;
1479  std::vector<kt_double> m_xPoses;
1480  std::vector<kt_double> m_yPoses;
1486 
1490  friend class boost::serialization::access;
1491  template<class Archive>
1492  void serialize(Archive &ar, const unsigned int version)
1493  {
1494  ar & BOOST_SERIALIZATION_NVP(m_pMapper);
1495  ar & BOOST_SERIALIZATION_NVP(m_pCorrelationGrid);
1496  ar & BOOST_SERIALIZATION_NVP(m_pSearchSpaceProbs);
1497  ar & BOOST_SERIALIZATION_NVP(m_pGridLookup);
1498  ar & BOOST_SERIALIZATION_NVP(m_xPoses);
1499  ar & BOOST_SERIALIZATION_NVP(m_yPoses);
1500  ar & BOOST_SERIALIZATION_NVP(m_rSearchCenter);
1501  ar & BOOST_SERIALIZATION_NVP(m_searchAngleResolution);
1502  ar & BOOST_SERIALIZATION_NVP(m_nAngles);
1503  ar & BOOST_SERIALIZATION_NVP(m_searchAngleResolution);;
1504  ar & BOOST_SERIALIZATION_NVP(m_doPenalize);
1505 
1506  // Note - m_pPoseResponse is generally only ever defined within the
1507  // execution of ScanMatcher::CorrelateScan and used as a temporary
1508  // accumulator for multithreaded matching results. It would normally
1509  // not make sense to serialize, but we don't want to break compatibility
1510  // with previously serialized data. Gen some dummy data that we free
1511  // immediately after so that we don't alloc here and leak.
1512  kt_int32u poseResponseSize =
1513  static_cast<kt_int32u>(m_xPoses.size() * m_yPoses.size() * m_nAngles);
1514 
1515  // We could check first if m_pPoseResponse == nullptr for good measure, but
1516  // based on the codepaths it should always be freed and set to null outside of
1517  // any execution of ScanMatcher::CorrelateScan, so go ahead and alloc here.
1518  m_pPoseResponse = new std::pair<kt_double, Pose2>[poseResponseSize];
1519  ar & boost::serialization::make_array<std::pair<kt_double, Pose2>>(m_pPoseResponse,
1520  poseResponseSize);
1521 
1522  // Aaaand now, clean up the dummy data
1523  delete[] m_pPoseResponse;
1524  m_pPoseResponse = nullptr;
1525  }
1526 
1527  }; // ScanMatcher
1528 
1532 
1533  class ScanManager;
1534 
1538  class KARTO_EXPORT MapperSensorManager //: public SensorManager // was commented out, works with it in, but I'll leave out for now...
1539  {
1540  typedef std::map<Name, ScanManager*> ScanManagerMap;
1541 
1542  public:
1546  MapperSensorManager(kt_int32u runningBufferMaximumSize, kt_double runningBufferMaximumDistance)
1547  : m_RunningBufferMaximumSize(runningBufferMaximumSize)
1548  , m_RunningBufferMaximumDistance(runningBufferMaximumDistance)
1549  , m_NextScanId(0)
1550  {
1551  }
1552 
1554  }
1555 
1560  {
1561  Clear();
1562  }
1563 
1564  public:
1570  void RegisterSensor(const Name& rSensorName);
1571 
1578  LocalizedRangeScan* GetScan(const Name& rSensorName, kt_int32s scanIndex);
1579 
1584  inline std::vector<Name> GetSensorNames()
1585  {
1586  std::vector<Name> deviceNames;
1587  const_forEach(ScanManagerMap, &m_ScanManagers)
1588  {
1589  deviceNames.push_back(iter->first);
1590  }
1591 
1592  return deviceNames;
1593  }
1594 
1600  LocalizedRangeScan* GetLastScan(const Name& rSensorName);
1601 
1606  void SetLastScan(LocalizedRangeScan* pScan);
1607 
1612  void ClearLastScan(LocalizedRangeScan* pScan);
1613 
1618  void ClearLastScan(const Name& name);
1619 
1626  {
1627  std::map<int, LocalizedRangeScan*>::iterator it = m_Scans.find(id);
1628  if (it != m_Scans.end())
1629  {
1630  return it->second;
1631  }
1632  else
1633  {
1634  std::cout << "GetScan: id " << id <<
1635  " does not exist in m_scans, cannot retrieve it." << std::endl;
1636  return nullptr;
1637  }
1638  }
1639 
1644  void AddScan(LocalizedRangeScan* pScan);
1645 
1650  void AddRunningScan(LocalizedRangeScan* pScan);
1651 
1656  void RemoveScan(LocalizedRangeScan* pScan);
1657 
1663  LocalizedRangeScanMap& GetScans(const Name& rSensorName);
1664 
1670  LocalizedRangeScanVector& GetRunningScans(const Name& rSensorName);
1671 
1675  void ClearRunningScans(const Name& rSensorName);
1676 
1680  kt_int32u GetRunningScanBufferSize(const Name& rSensorName);
1681 
1686  void SetRunningScanBufferSize(kt_int32u rScanBufferSize);
1687 
1692  void SetRunningScanBufferMaximumDistance(kt_double rScanBufferMaxDistance);
1693 
1698  LocalizedRangeScanVector GetAllScans();
1699 
1703  void Clear();
1704 
1705  private:
1711  {
1712  return GetScanManager(pScan->GetSensorName());
1713  }
1714 
1720  inline ScanManager* GetScanManager(const Name& rSensorName)
1721  {
1722  if (m_ScanManagers.find(rSensorName) != m_ScanManagers.end())
1723  {
1724  return m_ScanManagers[rSensorName];
1725  }
1726 
1727  return NULL;
1728  }
1729 
1730  friend class boost::serialization::access;
1731  template<class Archive>
1732  void serialize(Archive &ar, const unsigned int version)
1733  {
1734  std::cout << "MapperSensorManager <- m_ScanManagers; ";
1735  ar & BOOST_SERIALIZATION_NVP(m_ScanManagers);
1736  ar & BOOST_SERIALIZATION_NVP(m_RunningBufferMaximumSize);
1737  ar & BOOST_SERIALIZATION_NVP(m_RunningBufferMaximumDistance);
1738  ar & BOOST_SERIALIZATION_NVP(m_NextScanId);
1739  std::cout << "MapperSensorManager <- m_Scans\n";
1740  ar & BOOST_SERIALIZATION_NVP(m_Scans);
1741  }
1742 
1743  private:
1744  // map from device ID to scan data
1745  ScanManagerMap m_ScanManagers;
1746 
1749 
1751 
1752  std::map<int, LocalizedRangeScan*> m_Scans;
1753  }; // MapperSensorManager
1754 
1758 
1918  {
1920  LocalizationScanVertex(const LocalizationScanVertex& obj){scan = obj.scan; vertex = obj.vertex;};
1923  };
1924 
1925  typedef std::queue<LocalizationScanVertex> LocalizationScanVertices;
1926 
1927  class KARTO_EXPORT Mapper : public Module
1928  {
1929  friend class MapperGraph;
1930  friend class ScanMatcher;
1931 
1932  public:
1936  Mapper();
1937 
1942  Mapper(const std::string& rName);
1943 
1947  virtual ~Mapper();
1948 
1949  public:
1954  void Initialize(kt_double rangeThreshold);
1955 
1960  void SaveToFile(const std::string& filename);
1961 
1966  void LoadFromFile(const std::string& filename);
1967 
1972  virtual void Reset();
1973 
1985  virtual kt_bool Process(LocalizedRangeScan* pScan);
1986 
1990  virtual kt_bool Process(Object* pObject);
1991 
1992  // processors
1993  kt_bool ProcessAtDock(LocalizedRangeScan* pScan);
1994  kt_bool ProcessAgainstNode(LocalizedRangeScan* pScan, const int& nodeId);
1995  kt_bool ProcessAgainstNodesNearBy(LocalizedRangeScan* pScan, kt_bool addScanToLocalizationBuffer = false);
1996  kt_bool ProcessLocalization(LocalizedRangeScan* pScan);
1997  kt_bool RemoveNodeFromGraph(Vertex<LocalizedRangeScan>*);
1998  void AddScanToLocalizationBuffer(LocalizedRangeScan* pScan, Vertex<LocalizedRangeScan>* scan_vertex);
1999  void ClearLocalizationBuffer();
2000 
2007  virtual const LocalizedRangeScanVector GetAllProcessedScans() const;
2008 
2013  void AddListener(MapperListener* pListener);
2014 
2019  void RemoveListener(MapperListener* pListener);
2020 
2025  void SetScanSolver(ScanSolver* pSolver);
2026 
2031  ScanSolver* getScanSolver();
2032 
2037  virtual MapperGraph* GetGraph() const;
2038 
2043  virtual ScanMatcher* GetSequentialScanMatcher() const;
2044 
2049  virtual ScanMatcher* GetLoopScanMatcher() const;
2050 
2056  {
2057  return m_pMapperSensorManager;
2058  }
2059 
2065  inline kt_bool TryCloseLoop(LocalizedRangeScan* pScan, const Name& rSensorName)
2066  {
2067  return m_pGraph->TryCloseLoop(pScan, rSensorName);
2068  }
2069 
2070  inline void CorrectPoses()
2071  {
2072  m_pGraph->CorrectPoses();
2073  }
2074 
2075  protected:
2076  void InitializeParameters();
2077 
2085  kt_bool HasMovedEnough(LocalizedRangeScan* pScan, LocalizedRangeScan* pLastScan) const;
2086 
2087  public:
2089  // fire information for listeners!!
2090 
2095  void FireInfo(const std::string& rInfo) const;
2096 
2101  void FireDebug(const std::string& rInfo) const;
2102 
2107  void FireLoopClosureCheck(const std::string& rInfo) const;
2108 
2113  void FireBeginLoopClosure(const std::string& rInfo) const;
2114 
2119  void FireEndLoopClosure(const std::string& rInfo) const;
2120 
2121  // FireRunningScansUpdated
2122 
2123  // FireCovarianceCalculated
2124 
2125  // FireLoopClosureChain
2126 
2127  private:
2131  Mapper(const Mapper&);
2132 
2136  const Mapper& operator=(const Mapper&);
2137 
2138  public:
2139  void SetUseScanMatching(kt_bool val) { m_pUseScanMatching->SetValue(val); }
2140 
2141  protected:
2144 
2146 
2148 
2152 
2153 
2154  std::vector<MapperListener*> m_Listeners;
2155 
2165 
2170 
2183 
2193 
2203 
2213 
2220 
2226 
2233 
2239 
2246 
2254 
2261 
2267 
2273 
2275  // CorrelationParameters correlationParameters;
2276 
2282 
2288 
2294 
2295 
2297  // CorrelationParameters loopCorrelationParameters;
2298 
2304 
2310 
2316 
2318  // ScanMatcherParameters;
2319 
2320  // Variance of penalty for deviating from odometry when scan-matching.
2321  // The penalty is a multiplier (less than 1.0) is a function of the
2322  // delta of the scan position being tested and the odometric pose
2325 
2326  // The range of angles to search during a coarse search and a finer search
2329 
2330  // Resolution of angles to search during a coarse search
2332 
2333  // Minimum value of the penalty multiplier so scores do not
2334  // become too small
2337 
2338  // whether to increase the search space if no good matches are initially found
2340 
2341  friend class boost::serialization::access;
2342  template<class Archive>
2343  void serialize(Archive &ar, const unsigned int version)
2344  {
2345  std::cout << "Mapper <- Module\n";
2346  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Module);
2347  ar & BOOST_SERIALIZATION_NVP(m_Initialized);
2348  std::cout << "Mapper <- m_pSequentialScanMatcher\n";
2349  ar & BOOST_SERIALIZATION_NVP(m_pSequentialScanMatcher);
2350  std::cout << "Mapper <- m_pGraph\n";
2351  ar & BOOST_SERIALIZATION_NVP(m_pGraph);
2352  std::cout << "Mapper <- m_pMapperSensorManager\n";
2353  ar & BOOST_SERIALIZATION_NVP(m_pMapperSensorManager);
2354  std::cout << "Mapper <- m_Listeners\n";
2355  ar & BOOST_SERIALIZATION_NVP(m_Listeners);
2356  ar & BOOST_SERIALIZATION_NVP(m_pUseScanMatching);
2357  ar & BOOST_SERIALIZATION_NVP(m_pUseScanBarycenter);
2358  ar & BOOST_SERIALIZATION_NVP(m_pMinimumTimeInterval);
2359  ar & BOOST_SERIALIZATION_NVP(m_pMinimumTravelDistance);
2360  ar & BOOST_SERIALIZATION_NVP(m_pMinimumTravelHeading);
2361  ar & BOOST_SERIALIZATION_NVP(m_pScanBufferSize);
2362  ar & BOOST_SERIALIZATION_NVP(m_pScanBufferMaximumScanDistance);
2363  ar & BOOST_SERIALIZATION_NVP(m_pLinkMatchMinimumResponseFine);
2364  ar & BOOST_SERIALIZATION_NVP(m_pLinkScanMaximumDistance);
2365  ar & BOOST_SERIALIZATION_NVP(m_pDoLoopClosing);
2366  ar & BOOST_SERIALIZATION_NVP(m_pLoopSearchMaximumDistance);
2367  ar & BOOST_SERIALIZATION_NVP(m_pLoopMatchMinimumChainSize);
2368  ar & BOOST_SERIALIZATION_NVP(m_pLoopMatchMaximumVarianceCoarse);
2369  ar & BOOST_SERIALIZATION_NVP(m_pLoopMatchMinimumResponseCoarse);
2370  ar & BOOST_SERIALIZATION_NVP(m_pLoopMatchMinimumResponseFine);
2371  ar & BOOST_SERIALIZATION_NVP(m_pCorrelationSearchSpaceDimension);
2372  ar & BOOST_SERIALIZATION_NVP(m_pCorrelationSearchSpaceResolution);
2373  ar & BOOST_SERIALIZATION_NVP(m_pCorrelationSearchSpaceSmearDeviation);
2374  ar & BOOST_SERIALIZATION_NVP(m_pLoopSearchSpaceDimension);
2375  ar & BOOST_SERIALIZATION_NVP(m_pLoopSearchSpaceResolution);
2376  ar & BOOST_SERIALIZATION_NVP(m_pLoopSearchSpaceSmearDeviation);
2377  ar & BOOST_SERIALIZATION_NVP(m_pDistanceVariancePenalty);
2378  ar & BOOST_SERIALIZATION_NVP(m_pAngleVariancePenalty);
2379  ar & BOOST_SERIALIZATION_NVP(m_pFineSearchAngleOffset);
2380  ar & BOOST_SERIALIZATION_NVP(m_pCoarseSearchAngleOffset);
2381  ar & BOOST_SERIALIZATION_NVP(m_pCoarseAngleResolution);
2382  ar & BOOST_SERIALIZATION_NVP(m_pMinimumAnglePenalty);
2383  ar & BOOST_SERIALIZATION_NVP(m_pMinimumDistancePenalty);
2384  ar & BOOST_SERIALIZATION_NVP(m_pUseResponseExpansion);
2385  std::cout << "**Finished serializing Mapper**\n";
2386  }
2387  public:
2388  /* Abstract methods for parameter setters and getters */
2389 
2390  /* Getters */
2391  // General Parameters
2392  bool getParamUseScanMatching();
2393  bool getParamUseScanBarycenter();
2394  double getParamMinimumTimeInterval();
2395  double getParamMinimumTravelDistance();
2396  double getParamMinimumTravelHeading();
2397  int getParamScanBufferSize();
2398  double getParamScanBufferMaximumScanDistance();
2399  double getParamLinkMatchMinimumResponseFine();
2400  double getParamLinkScanMaximumDistance();
2401  double getParamLoopSearchMaximumDistance();
2402  bool getParamDoLoopClosing();
2403  int getParamLoopMatchMinimumChainSize();
2404  double getParamLoopMatchMaximumVarianceCoarse();
2405  double getParamLoopMatchMinimumResponseCoarse();
2406  double getParamLoopMatchMinimumResponseFine();
2407 
2408  // Correlation Parameters - Correlation Parameters
2409  double getParamCorrelationSearchSpaceDimension();
2410  double getParamCorrelationSearchSpaceResolution();
2411  double getParamCorrelationSearchSpaceSmearDeviation();
2412 
2413  // Correlation Parameters - Loop Closure Parameters
2414  double getParamLoopSearchSpaceDimension();
2415  double getParamLoopSearchSpaceResolution();
2416  double getParamLoopSearchSpaceSmearDeviation();
2417 
2418  // Scan Matcher Parameters
2419  double getParamDistanceVariancePenalty();
2420  double getParamAngleVariancePenalty();
2421  double getParamFineSearchAngleOffset();
2422  double getParamCoarseSearchAngleOffset();
2423  double getParamCoarseAngleResolution();
2424  double getParamMinimumAnglePenalty();
2425  double getParamMinimumDistancePenalty();
2426  bool getParamUseResponseExpansion();
2427 
2428  /* Setters */
2429  // General Parameters
2430  void setParamUseScanMatching(bool b);
2431  void setParamUseScanBarycenter(bool b);
2432  void setParamMinimumTimeInterval(double d);
2433  void setParamMinimumTravelDistance(double d);
2434  void setParamMinimumTravelHeading(double d);
2435  void setParamScanBufferSize(int i);
2436  void setParamScanBufferMaximumScanDistance(double d);
2437  void setParamLinkMatchMinimumResponseFine(double d);
2438  void setParamLinkScanMaximumDistance(double d);
2439  void setParamLoopSearchMaximumDistance(double d);
2440  void setParamDoLoopClosing(bool b);
2441  void setParamLoopMatchMinimumChainSize(int i);
2442  void setParamLoopMatchMaximumVarianceCoarse(double d);
2443  void setParamLoopMatchMinimumResponseCoarse(double d);
2444  void setParamLoopMatchMinimumResponseFine(double d);
2445 
2446  // Correlation Parameters - Correlation Parameters
2447  void setParamCorrelationSearchSpaceDimension(double d);
2448  void setParamCorrelationSearchSpaceResolution(double d);
2449  void setParamCorrelationSearchSpaceSmearDeviation(double d);
2450 
2451  // Correlation Parameters - Loop Closure Parameters
2452  void setParamLoopSearchSpaceDimension(double d);
2453  void setParamLoopSearchSpaceResolution(double d);
2454  void setParamLoopSearchSpaceSmearDeviation(double d);
2455 
2456  // Scan Matcher Parameters
2457  void setParamDistanceVariancePenalty(double d);
2458  void setParamAngleVariancePenalty(double d);
2459  void setParamFineSearchAngleOffset(double d);
2460  void setParamCoarseSearchAngleOffset(double d);
2461  void setParamCoarseAngleResolution(double d);
2462  void setParamMinimumAnglePenalty(double d);
2463  void setParamMinimumDistancePenalty(double d);
2464  void setParamUseResponseExpansion(bool b);
2465  };
2466  BOOST_SERIALIZATION_ASSUME_ABSTRACT(Mapper)
2467 } // namespace karto
2468 
2469 #endif // karto_sdk_MAPPER_H
CorrelationGrid(kt_int32u width, kt_int32u height, kt_int32u borderSize, kt_double resolution, kt_double smearDeviation)
Definition: Mapper.h:1183
std::map< int, LocalizedRangeScan * > m_Scans
Definition: Mapper.h:1752
d
virtual void GetNodeOrientation(const int &unique_id, double &pose)
Definition: Mapper.h:1041
std::map< Name, ScanManager * > ScanManagerMap
Definition: Mapper.h:1540
virtual ~ScanSolver()
Definition: Mapper.h:965
#define NULL
EdgeLabel * m_pLabel
Definition: Mapper.h:474
ScanMatcher * m_pSequentialScanMatcher
Definition: Mapper.h:2145
T * m_pObject
Definition: Mapper.h:374
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:55
int32_t kt_int32s
Definition: Types.h:51
GraphTraversal(Graph< T > *pGraph)
Definition: Mapper.h:527
Matrix3 m_Covariance
Definition: Mapper.h:228
virtual ~CorrelationGrid()
Definition: Mapper.h:1066
Vertex< T > * m_pTarget
Definition: Mapper.h:473
EdgeLabel * GetLabel()
Definition: Mapper.h:457
Parameter< kt_double > * m_pLinkScanMaximumDistance
Definition: Mapper.h:2232
virtual void Info(const std::string &)
Definition: Mapper.h:52
kt_double Round(kt_double value)
Definition: Math.h:87
kt_bool TryCloseLoop(LocalizedRangeScan *pScan, const Name &rSensorName)
Definition: Mapper.h:2065
Mapper * m_pMapper
Definition: Mapper.h:1474
virtual void AddNode(Vertex< LocalizedRangeScan > *)
Definition: Mapper.h:984
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:380
Parameter< kt_double > * m_pCoarseAngleResolution
Definition: Mapper.h:2331
kt_int32s GetStateId() const
Definition: Karto.h:5143
Parameter< kt_double > * m_pLoopMatchMaximumVarianceCoarse
Definition: Mapper.h:2260
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:99
std::vector< Vector2< kt_double > > PointVectorDouble
Definition: Karto.h:1281
Parameter< kt_double > * m_pMinimumTravelHeading
Definition: Mapper.h:2202
virtual void EndLoopClosure(const std::string &)
Definition: Mapper.h:96
#define forEachAs(listtype, list, iter)
Definition: Macros.h:69
void AddEdge(Edge< T > *pEdge)
Definition: Mapper.h:620
Parameter< kt_double > * m_pMinimumAnglePenalty
Definition: Mapper.h:2335
Matrix3 Transpose() const
Definition: Karto.h:2525
std::vector< MapperListener * > m_Listeners
Definition: Mapper.h:2154
virtual void Clear()
Definition: Mapper.h:1012
virtual void RemoveNode(kt_int32s)
Definition: Mapper.h:991
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:478
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:129
Rectangle2< kt_int32s > m_Roi
Definition: Mapper.h:1286
uint8_t kt_int8u
Definition: Types.h:46
virtual void RemoveConstraint(kt_int32s, kt_int32s)
Definition: Mapper.h:1005
virtual ~GraphTraversal()
Definition: Mapper.h:532
std::map< Name, std::map< int, Vertex< T > * > > VertexMap
Definition: Mapper.h:567
std::vector< Name > GetSensorNames()
Definition: Mapper.h:1584
Vertex< LocalizedRangeScan > * vertex
Definition: Mapper.h:1922
virtual void LoopClosureCheck(const std::string &)
Definition: Mapper.h:86
Parameter< kt_double > * m_pLoopSearchSpaceSmearDeviation
Definition: Mapper.h:2315
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:2343
void Update(const Pose2 &rPose1, const Pose2 &rPose2, const Matrix3 &rCovariance)
Definition: Mapper.h:172
const std::vector< Edge< T > * > & GetEdges() const
Definition: Mapper.h:665
const Matrix3 & GetCovariance()
Definition: Mapper.h:219
virtual std::unordered_map< int, Eigen::Vector3d > * getGraph()
Definition: Mapper.h:1026
Parameter< kt_int32u > * m_pLoopMatchMinimumChainSize
Definition: Mapper.h:2253
INLINE Rall1d< T, V, S > hypot(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
Parameter< kt_double > * m_pCorrelationSearchSpaceResolution
Definition: Mapper.h:2287
void Clear()
Definition: Mapper.h:639
virtual kt_int32s GridIndex(const Vector2< kt_int32s > &rGrid, kt_bool boundaryCheck=true) const
Definition: Mapper.h:1108
Parameter< kt_double > * m_pMinimumDistancePenalty
Definition: Mapper.h:2336
void AddVertex(const Name &rName, Vertex< T > *pVertex)
Definition: Mapper.h:591
virtual void AddConstraint(Edge< LocalizedRangeScan > *)
Definition: Mapper.h:998
virtual ~Edge()
Definition: Mapper.h:422
Parameter< kt_double > * m_pDistanceVariancePenalty
Definition: Mapper.h:2323
MapperSensorManager * GetMapperSensorManager() const
Definition: Mapper.h:2055
Parameter< kt_bool > * m_pUseScanMatching
Definition: Mapper.h:2164
Vertex< T > * GetTarget() const
Definition: Mapper.h:448
#define forEach(listtype, list)
Definition: Macros.h:66
virtual void Reset()
Definition: Mapper.h:1019
std::vector< kt_double > m_xPoses
Definition: Mapper.h:1479
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:505
kt_double m_SmearDeviation
Definition: Mapper.h:1277
T * GetObject() const
Definition: Mapper.h:319
virtual void ModifyNode(const int &unique_id, Eigen::Vector3d pose)
Definition: Mapper.h:1034
Graph< T > * m_pGraph
Definition: Mapper.h:542
const double GetScore() const
Definition: Mapper.h:301
void SetROI(const Rectangle2< kt_int32s > &roi)
Definition: Mapper.h:1129
MapperSensorManager * m_pMapperSensorManager
Definition: Mapper.h:2147
kt_int32u m_RunningBufferMaximumSize
Definition: Mapper.h:1747
GraphTraversal< LocalizedRangeScan > * m_pTraversal
Definition: Mapper.h:919
Parameter< kt_bool > * m_pDoLoopClosing
Definition: Mapper.h:2238
friend class boost::serialization::access
Definition: Mapper.h:52
Parameter< kt_double > * m_pFineSearchAngleOffset
Definition: Mapper.h:2327
Parameter< kt_double > * m_pScanBufferMaximumScanDistance
Definition: Mapper.h:2219
ScanSolver * m_pScanOptimizer
Definition: Mapper.h:2150
kt_double m_Score
Definition: Mapper.h:376
LocalizedRangeScan * scan
Definition: Mapper.h:1920
const Pose2 & GetPose2()
Definition: Mapper.h:201
virtual void Debug(const std::string &)
Definition: Mapper.h:69
Parameter< kt_double > * m_pLoopSearchSpaceDimension
Definition: Mapper.h:2303
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:926
void RemoveEdge(const int &idx)
Definition: Mapper.h:290
virtual kt_int32s GridIndex(const Vector2< kt_int32s > &rGrid, kt_bool boundaryCheck=true) const
Definition: Karto.h:4755
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:72
const Name & GetSensorName() const
Definition: Karto.h:5197
void SmearPoint(const Vector2< kt_int32s > &rGridPoint)
Definition: Mapper.h:1138
CorrelationGrid * GetCorrelationGrid() const
Definition: Mapper.h:1421
void CorrectPoses()
Definition: Mapper.h:2070
Pose2 m_Pose2
Definition: Mapper.h:226
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:1732
Parameter< kt_double > * m_pMinimumTravelDistance
Definition: Mapper.h:2192
std::vector< Edge< T > * > m_Edges
Definition: Mapper.h:688
Mapper * m_pMapper
Definition: Mapper.h:909
kt_int8u * m_pKernel
Definition: Mapper.h:1283
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:1492
void SetScore(const double score)
Definition: Mapper.h:310
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:546
void AddEdge(Edge< T > *pEdge)
Definition: Mapper.h:369
void SetUseScanMatching(kt_bool val)
Definition: Mapper.h:2139
std::vector< Pose2 > Pose2Vector
Definition: Karto.h:2269
ScanMatcher * GetLoopScanMatcher() const
Definition: Mapper.h:806
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:232
virtual ~Vertex()
Definition: Mapper.h:274
void RemoveVertex(const Name &rName, const int &idx)
Definition: Mapper.h:601
virtual ~MapperSensorManager()
Definition: Mapper.h:1559
Vertex< T > * GetSource() const
Definition: Mapper.h:439
ScanMatcher(Mapper *pMapper)
Definition: Mapper.h:1463
kt_bool InRange(const T &value, const T &a, const T &b)
Definition: Math.h:172
kt_double m_RunningBufferMaximumDistance
Definition: Mapper.h:1748
kt_bool m_Deserialized
Definition: Mapper.h:2143
Pose2 m_PoseDifference
Definition: Mapper.h:227
const T & GetX() const
Definition: Karto.h:1026
#define const_forEach(listtype, list)
Definition: Macros.h:72
VertexMap m_Vertices
Definition: Mapper.h:683
Vertex< T > * m_pSource
Definition: Mapper.h:472
LocalizationScanVertices m_LocalizationScanVertices
Definition: Mapper.h:2151
virtual void BeginLoopClosure(const std::string &)
Definition: Mapper.h:91
INLINE Rall1d< T, V, S > exp(const Rall1d< T, V, S > &arg)
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:1292
Pose2 TransformPose(const Pose2 &rSourcePose)
Definition: Karto.h:3002
std::vector< Vertex< T > * > GetAdjacentVertices() const
Definition: Mapper.h:336
GridIndexLookup< kt_int8u > * m_pGridLookup
Definition: Mapper.h:1477
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:1048
bool kt_bool
Definition: Types.h:64
virtual ~Graph()
Definition: Mapper.h:580
static CorrelationGrid * CreateGrid(kt_int32s width, kt_int32s height, kt_double resolution, kt_double smearDeviation)
Definition: Mapper.h:1087
CorrelationGrid * m_pCorrelationGrid
Definition: Mapper.h:1475
Parameter< kt_double > * m_pLoopSearchSpaceResolution
Definition: Mapper.h:2309
kt_bool m_Initialized
Definition: Mapper.h:2142
void RemoveEdge(const int &idx)
Definition: Mapper.h:629
Parameter< kt_double > * m_pCorrelationSearchSpaceDimension
Definition: Mapper.h:2281
MapperSensorManager(kt_int32u runningBufferMaximumSize, kt_double runningBufferMaximumDistance)
Definition: Mapper.h:1546
const std::vector< Edge< T > * > & GetEdges() const
Definition: Mapper.h:282
LocalizedRangeScan * GetScan(kt_int32s id)
Definition: Mapper.h:1625
kt_int32s m_KernelSize
Definition: Mapper.h:1280
std::vector< std::pair< kt_int32s, Pose2 > > IdPoseVector
Definition: Mapper.h:953
void RemoveObject()
Definition: Mapper.h:327
Parameter< kt_double > * m_pLinkMatchMinimumResponseFine
Definition: Mapper.h:2225
Vertex< LocalizedRangeScan > * GetVertex(LocalizedRangeScan *pScan)
Definition: Mapper.h:823
const Pose2 & GetPose1()
Definition: Mapper.h:192
void serialize(Archive &ar, const unsigned int version)
Definition: Mapper.h:694
virtual ~EdgeLabel()
Definition: Mapper.h:124
Pose2 m_Pose1
Definition: Mapper.h:225
std::pair< kt_double, Pose2 > * m_pPoseResponse
Definition: Mapper.h:1478
Pose2 m_rSearchCenter
Definition: Mapper.h:1481
ScanMatcher * m_pLoopScanMatcher
Definition: Mapper.h:914
Vertex(T *pObject)
Definition: Mapper.h:266
void SetLabel(EdgeLabel *pLabel)
Definition: Mapper.h:466
ScanManagerMap m_ScanManagers
Definition: Mapper.h:1745
Grid< kt_double > * m_pSearchSpaceProbs
Definition: Mapper.h:1476
std::vector< kt_double > m_yPoses
Definition: Mapper.h:1480
static kt_int32s GetHalfKernelSize(kt_double smearDeviation, kt_double resolution)
Definition: Mapper.h:1265
Edge(Vertex< T > *pSource, Vertex< T > *pTarget)
Definition: Mapper.h:410
virtual ~LinkInfo()
Definition: Mapper.h:161
double kt_double
Definition: Types.h:67
Parameter< kt_double > * m_pCorrelationSearchSpaceSmearDeviation
Definition: Mapper.h:2293
Definition: Karto.h:86
const T & GetY() const
Definition: Karto.h:1044
MapperGraph * m_pGraph
Definition: Mapper.h:2149
Parameter< kt_double > * m_pLoopMatchMinimumResponseCoarse
Definition: Mapper.h:2266
const Rectangle2< kt_int32s > & GetROI() const
Definition: Mapper.h:1120
LinkInfo(const Pose2 &rPose1, const Pose2 &rPose2, const Matrix3 &rCovariance)
Definition: Mapper.h:153
const VertexMap & GetVertices() const
Definition: Mapper.h:674
Parameter< kt_double > * m_pCoarseSearchAngleOffset
Definition: Mapper.h:2328
Parameter< kt_double > * m_pLoopSearchMaximumDistance
Definition: Mapper.h:2245
kt_int32u m_nAngles
Definition: Mapper.h:1483
Parameter< kt_double > * m_pAngleVariancePenalty
Definition: Mapper.h:2324
uint32_t kt_int32u
Definition: Types.h:52
virtual void CalculateKernel()
Definition: Mapper.h:1201
Parameter< kt_double > * m_pMinimumTimeInterval
Definition: Mapper.h:2182
Parameter< kt_bool > * m_pUseResponseExpansion
Definition: Mapper.h:2339
kt_bool m_doPenalize
Definition: Mapper.h:1485
Parameter< kt_int32u > * m_pScanBufferSize
Definition: Mapper.h:2212
#define KARTO_EXPORT
Definition: Macros.h:56
kt_bool IsUpTo(const T &value, const T &maximum)
Definition: Math.h:147
kt_double m_searchAngleOffset
Definition: Mapper.h:1482
std::queue< LocalizationScanVertex > LocalizationScanVertices
Definition: Mapper.h:1925
std::vector< Edge< T > * > m_Edges
Definition: Mapper.h:375
ScanManager * GetScanManager(LocalizedRangeScan *pScan)
Definition: Mapper.h:1710
kt_double m_searchAngleResolution
Definition: Mapper.h:1484
std::vector< LocalizedRangeScan * > LocalizedRangeScanVector
Definition: Karto.h:5877
ScanManager * GetScanManager(const Name &rSensorName)
Definition: Mapper.h:1720
Parameter< kt_bool > * m_pUseScanBarycenter
Definition: Mapper.h:2169
std::map< int, LocalizedRangeScan * > LocalizedRangeScanMap
Definition: Karto.h:5878
const Pose2 & GetPoseDifference()
Definition: Mapper.h:210
Parameter< kt_double > * m_pLoopMatchMinimumResponseFine
Definition: Mapper.h:2272
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


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