20 #ifndef __OpenKarto_Mapper_h__ 21 #define __OpenKarto_Mapper_h__ 24 #include <tbb/mutex.h> 25 #include <tbb/parallel_for.h> 26 #include <tbb/blocked_range.h> 27 #include <tbb/blocked_range3d.h> 130 Update(rPose1, rPose2, rCovariance);
160 m_Covariance = rotationMatrix * rCovariance * rotationMatrix.
Transpose();
187 return m_PoseDifference;
318 m_pSource->AddEdge(
this);
319 m_pTarget->AddEdge(
this);
330 if (m_pLabel != NULL)
489 m_Vertices.Add(pVertex);
637 return m_pLoopScanMatcher;
767 virtual void Compute() = 0;
773 virtual const IdPoseVector& GetCorrections()
const = 0;
840 assert(resolution != 0.0);
843 kt_int32u borderSize = GetHalfKernelSize(smearDeviation, resolution) + 1;
888 assert(m_pKernel != NULL);
890 int gridIndex = GridIndex(rGridPoint);
899 for (
kt_int32s j = -halfKernel; j <= halfKernel; j++)
903 kt_int32s kernelConstant = (halfKernel) + m_KernelSize * (j + halfKernel);
908 SmearInternal(halfKernel, kernelConstant, pGridAdr);
922 :
Grid<
kt_int8u>(width + borderSize * 2, height + borderSize * 2)
923 , m_SmearDeviation(smearDeviation)
926 GetCoordinateConverter()->SetScale(1.0 / resolution);
942 assert(resolution != 0.0);
943 assert(m_SmearDeviation != 0.0);
947 const kt_double MIN_SMEAR_DISTANCE_DEVIATION = 0.5 * resolution;
948 const kt_double MAX_SMEAR_DISTANCE_DEVIATION = 10 * resolution;
951 if (!
math::InRange(m_SmearDeviation, MIN_SMEAR_DISTANCE_DEVIATION, MAX_SMEAR_DISTANCE_DEVIATION))
954 error <<
"Mapper Error: Smear deviation too small: Must be between " << MIN_SMEAR_DISTANCE_DEVIATION <<
" and " << MAX_SMEAR_DISTANCE_DEVIATION;
961 m_KernelSize = 2 * GetHalfKernelSize(m_SmearDeviation, resolution) + 1;
964 m_pKernel =
new kt_int8u[m_KernelSize * m_KernelSize];
965 if (m_pKernel == NULL)
967 throw Exception(
"Unable to allocate memory for kernel!");
972 for (
kt_int32s i = -halfKernel; i <= halfKernel; i++)
974 for (
kt_int32s j = -halfKernel; j <= halfKernel; j++)
977 kt_double distanceFromMean = _hypot(i * resolution, j * resolution);
979 kt_double distanceFromMean = hypot(i * resolution, j * resolution);
981 kt_double z = exp(-0.5 * pow(distanceFromMean / m_SmearDeviation, 2));
984 assert(
math::IsUpTo(kernelValue, static_cast<kt_int32u>(255)));
986 int kernelArrayIndex = (i + halfKernel) + m_KernelSize * (j + halfKernel);
987 m_pKernel[kernelArrayIndex] =
static_cast<kt_int8u>(kernelValue);
1001 assert(resolution != 0.0);
1014 for (i = -halfKernel; i <= halfKernel; i++)
1016 kernelArrayIndex = i + kernelConstant;
1018 kernelValue = m_pKernel[kernelArrayIndex];
1019 if (kernelValue > pGridAdr[i])
1022 pGridAdr[i] = kernelValue;
1053 : m_pCorrelationGrid(pCorrelationGrid)
1054 , m_pSearchSpaceProbs(pSearchSpaceProbs)
1055 , m_pGridLookup(pGridLookup)
1061 delete m_pGridLookup;
1143 const Vector2d& rSearchSpaceOffset,
const Vector2d& rSearchSpaceResolution,
1217 : m_pOpenMapper(pOpenMapper)
1218 , m_pScanMatcherGridSet(NULL)
1219 , m_pScanMatcherGridSetBank(NULL)
1261 void RegisterSensor(
const Identifier& rSensorName);
1294 void ClearLastScan(
const Identifier& rSensorName);
1591 return m_MultiThreaded;
1599 void Initialize(
kt_double rangeThreshold);
1668 return m_pMapperSensorManager;
1679 return m_pGraph->TryCloseLoop(pScan, rSensorName);
1696 void InitializeParameters();
1716 return m_Initialized;
1795 #endif // __OpenKarto_Mapper_h__ CorrelationGrid(kt_int32u width, kt_int32u height, kt_int32u borderSize, kt_double resolution, kt_double smearDeviation)
MapperSensorManager * GetMapperSensorManager() const
GraphTraversal(Graph< T > *pGraph)
List< Edge< T > * > EdgeList
kt_double GetHeading() const
const VertexList & GetVertices() const
Parameter< kt_double > * m_pLoopSearchSpaceResolution
List< Pair< kt_int32s, Pose2 > > IdPoseVector
Parameter< kt_double > * m_pLoopSearchSpaceSmearDeviation
void AddEdge(Edge< T > *pEdge)
SmartPointer< CorrelationGrid > m_pCorrelationGrid
virtual void AddNode(Vertex< LocalizedObjectPtr > *)
virtual void RemoveNode(kt_int32s)
virtual ~ScanMatcherGridSet()
Rectangle2< kt_int32s > m_Roi
virtual void RemoveConstraint(kt_int32s, kt_int32s)
Parameter< kt_double > * m_pMinimumTravelHeading
virtual ~GraphTraversal()
Parameter< kt_double > * m_pLoopMatchMinimumResponseFine
T GetVertexObject() const
Parameter< kt_double > * m_pMinimumDistancePenalty
Parameter< kt_double > * m_pLinkScanMaximumDistance
Parameter< kt_double > * m_pAngleVariancePenalty
void Update(const Pose2 &rPose1, const Pose2 &rPose2, const Matrix3 &rCovariance)
Parameter< kt_double > * m_pLoopMatchMaximumVarianceCoarse
kt_bool IsUpTo(const T &value, const T &maximum)
const Matrix3 & GetCovariance()
SensorDataManager * GetSensorDataManager(LocalizedObject *pObject)
virtual void Add(const T &rValue)
Matrix3 Transpose() const
kt_double Round(kt_double value)
Parameter< kt_double > * m_pMinimumTravelDistance
TFSIMD_FORCE_INLINE const tfScalar & y() const
kt_double m_SmearDeviation
Parameter< kt_double > * m_pLoopMatchMinimumResponseCoarse
SmartPointer< ScanMatcherGridSet > m_pScanMatcherGridSet
Parameter< kt_double > * m_pScanBufferMaximumScanDistance
virtual kt_int32s GridIndex(const Vector2i &rGrid, kt_bool boundaryCheck=true) const
void SetROI(const Rectangle2< kt_int32s > &roi)
List< Edge< T > * > m_Edges
BasicEvent< EventArguments > ScansUpdated
ScanMatcherGridSet(CorrelationGrid *pCorrelationGrid, Grid< kt_double > *pSearchSpaceProbs, GridIndexLookup< kt_int8u > *pGridLookup)
const Rectangle2< kt_int32s > & GetROI() const
Parameter< kt_bool > * m_pUseScanBarycenter
virtual void ScanMatchingEnd(LocalizedLaserScan *pScan)
const String & GetEventMessage() const
Parameter< kt_double > * m_pLinkMatchMinimumResponseFine
List< Vertex< T > * > GetAdjacentVertices() const
virtual void AddConstraint(Edge< LocalizedObjectPtr > *)
Parameter< kt_int32u > * m_pScanBufferSize
const EdgeList & GetEdges() const
MapperSensorManager * m_pMapperSensorManager
const Identifier & GetSensorIdentifier() const
Parameter< kt_double > * m_pMinimumAnglePenalty
ScanMatcher * GetLoopScanMatcher() const
virtual void ScanMatched(LocalizedLaserScan *pScan)
kt_int32s GetUniqueId() const
void SmearPoint(const Vector2i &rGridPoint)
Parameter< kt_double > * m_pCoarseSearchAngleOffset
GridIndexLookup< kt_int8u > * m_pGridLookup
BasicEvent< MapperEventArguments > PreLoopClosed
void AddEdge(Edge< T > *pEdge)
OpenMapper * m_pOpenMapper
ScanMatcher * m_pSequentialScanMatcher
SmartPointer< ScanSolver > m_pScanSolver
void SmearInternal(kt_int32s halfKernel, kt_int32s kernelConstant, kt_int8u *pGridAdr)
Parameter< kt_bool > * m_pUseScanMatching
TFSIMD_FORCE_INLINE const tfScalar & x() const
Parameter< kt_double > * m_pDistanceVariancePenalty
BasicEvent< MapperEventArguments > PostLoopClosed
List< Vertex< T > * > VertexList
MapperSensorManagerPrivate * m_pMapperSensorManagerPrivate
const String & ToString() const
virtual kt_int32s GridIndex(const Vector2i &rGrid, kt_bool boundaryCheck=true) const
TFSIMD_FORCE_INLINE const tfScalar & z() const
void AddVertex(Vertex< T > *pVertex)
static CorrelationGrid * CreateGrid(kt_int32s width, kt_int32s height, kt_double resolution, kt_double smearDeviation)
ScanMatcherGridSetBank * m_pScanMatcherGridSetBank
Parameter< kt_double > * m_pCorrelationSearchSpaceResolution
kt_bool TryCloseLoop(LocalizedLaserScan *pScan, const Identifier &rSensorName)
Parameter< kt_double > * m_pCoarseAngleResolution
kt_bool InRange(const T &value, const T &a, const T &b)
Parameter< kt_double > * m_pLoopSearchSpaceDimension
Parameter< kt_double > * m_pCorrelationSearchSpaceSmearDeviation
ScanMatcher * m_pLoopScanMatcher
const List< Edge< T > * > & GetEdges() const
void SetLabel(EdgeLabel *pLabel)
SmartPointer< Grid< kt_double > > m_pSearchSpaceProbs
kt_bool IsMultiThreaded()
static kt_int32s GetHalfKernelSize(kt_double smearDeviation, kt_double resolution)
Edge(Vertex< T > *pSource, Vertex< T > *pTarget)
ScanMatcher(OpenMapper *pOpenMapper)
Vertex< T > * GetSource() const
Parameter< kt_double > * m_pFineSearchAngleOffset
Vertex< LocalizedObjectPtr > * GetVertex(LocalizedObject *pObject)
Parameter< kt_bool > * m_pUseResponseExpansion
Parameter< kt_double > * m_pCorrelationSearchSpaceDimension
Vertex< T > * GetTarget() const
Parameter< kt_int32u > * m_pLoopMatchMinimumChainSize
OpenMapper * m_pOpenMapper
Vector2< kt_int32s > Vector2i
LinkInfo(const Pose2 &rPose1, const Pose2 &rPose2, const Matrix3 &rCovariance)
virtual ~MapperEventArguments()
MapperEventArguments(const String &rMessage)
Parameter< kt_double > * m_pLoopSearchMaximumDistance
GraphTraversal< LocalizedObjectPtr > * m_pTraversal
virtual void CalculateKernel()
#define karto_const_forEach(listtype, list)
const Pose2 & GetPoseDifference()
BasicEvent< MapperEventArguments > Message
void FromAxisAngle(kt_double x, kt_double y, kt_double z, const kt_double radians)