29 #ifndef __OccGridMapUtil_h_ 30 #define __OccGridMapUtil_h_ 34 #include "../scan/DataPointContainer.h" 35 #include "../util/UtilFunctions.h" 39 template<
typename ConcreteOccGr
idMap,
typename ConcreteCacheMethod>
49 cacheMethod.setMapSize(gridMap->getMapDimensions());
57 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
70 float sinRot =
sin(pose[2]);
71 float cosRot =
cos(pose[2]);
73 H = Eigen::Matrix3f::Zero();
74 dTr = Eigen::Vector3f::Zero();
76 for (
int i = 0; i <
size; ++i) {
78 const Eigen::Vector2f& currPoint (dataPoints.
getVecEntry(i));
82 float funVal = 1.0f - transformedPointData[0];
84 dTr[0] += transformedPointData[1] * funVal;
85 dTr[1] += transformedPointData[2] * funVal;
87 float rotDeriv = ((-sinRot * currPoint.x() - cosRot * currPoint.y()) * transformedPointData[1] + (cosRot * currPoint.x() - sinRot * currPoint.y()) * transformedPointData[2]);
89 dTr[2] += rotDeriv * funVal;
91 H(0, 0) +=
util::sqr(transformedPointData[1]);
92 H(1, 1) +=
util::sqr(transformedPointData[2]);
95 H(0, 1) += transformedPointData[1] * transformedPointData[2];
96 H(0, 2) += transformedPointData[1] * rotDeriv;
97 H(1, 2) += transformedPointData[2] * rotDeriv;
109 float deltaTransX = 1.5f;
110 float deltaTransY = 1.5f;
111 float deltaAng = 0.05f;
113 float x = mapPose[0];
114 float y = mapPose[1];
115 float ang = mapPose[2];
117 Eigen::Matrix<float, 3, 7> sigmaPoints;
119 sigmaPoints.block<3, 1>(0, 0) = Eigen::Vector3f(x + deltaTransX, y, ang);
120 sigmaPoints.block<3, 1>(0, 1) = Eigen::Vector3f(x - deltaTransX, y, ang);
121 sigmaPoints.block<3, 1>(0, 2) = Eigen::Vector3f(x, y + deltaTransY, ang);
122 sigmaPoints.block<3, 1>(0, 3) = Eigen::Vector3f(x, y - deltaTransY, ang);
123 sigmaPoints.block<3, 1>(0, 4) = Eigen::Vector3f(x, y, ang + deltaAng);
124 sigmaPoints.block<3, 1>(0, 5) = Eigen::Vector3f(x, y, ang - deltaAng);
125 sigmaPoints.block<3, 1>(0, 6) = mapPose;
127 Eigen::Matrix<float, 7, 1> likelihoods;
137 float invLhNormalizer = 1 / likelihoods.sum();
139 std::cout <<
"\n lhs:\n" << likelihoods;
141 Eigen::Vector3f mean(Eigen::Vector3f::Zero());
143 for (
int i = 0; i < 7; ++i) {
144 mean += (sigmaPoints.block<3, 1>(0, i) * likelihoods[i]);
147 mean *= invLhNormalizer;
149 Eigen::Matrix3f covMatrixMap(Eigen::Matrix3f::Zero());
151 for (
int i = 0; i < 7; ++i) {
152 Eigen::Vector3f sigPointMinusMean(sigmaPoints.block<3, 1>(0, i) - mean);
153 covMatrixMap += (likelihoods[i] * invLhNormalizer) * (sigPointMinusMean * (sigPointMinusMean.transpose()));
167 Eigen::Matrix3f covMatWorld;
170 float scaleTransSq =
util::sqr(scaleTrans);
172 covMatWorld(0, 0) = covMatMap(0, 0) * scaleTransSq;
173 covMatWorld(1, 1) = covMatMap(1, 1) * scaleTransSq;
175 covMatWorld(1, 0) = covMatMap(1, 0) * scaleTransSq;
176 covMatWorld(0, 1) = covMatWorld(1, 0);
178 covMatWorld(2, 0) = covMatMap(2, 0) * scaleTrans;
179 covMatWorld(0, 2) = covMatWorld(2, 0);
181 covMatWorld(2, 1) = covMatMap(2, 1) * scaleTrans;
182 covMatWorld(1, 2) = covMatWorld(2, 1);
184 covMatWorld(2, 2) = covMatMap(2, 2);
198 float numDataPointsA =
static_cast<int>(numDataPoints);
199 float sizef =
static_cast<float>(numDataPointsA);
201 return 1 - (residual / sizef);
209 float residual = 0.0f;
214 for (
int i = 0; i <
size; i += stepSize) {
225 return (
concreteGridMap->getGridProbabilityMap(gridCoords.x(), gridCoords.y()));
241 Eigen::Vector2i indMin(coords.cast<
int>());
244 Eigen::Vector2f factors(coords - indMin.cast<
float>());
248 int index = indMin[1] * sizeX + indMin[0];
278 float xFacInv = (1.0f - factors[0]);
279 float yFacInv = (1.0f - factors[1]);
291 return Eigen::Vector3f(0.0
f, 0.0
f, 0.0
f);
295 Eigen::Vector2i indMin(coords.cast<
int>());
298 Eigen::Vector2f factors(coords - indMin.cast<
float>());
302 int index = indMin[1] * sizeX + indMin[0];
333 float dx2 = intensities[2] - intensities[3];
335 float dy1 = intensities[0] - intensities[2];
336 float dy2 = intensities[1] - intensities[3];
338 float xFacInv = (1.0f - factors[0]);
339 float yFacInv = (1.0f - factors[1]);
341 return Eigen::Vector3f(
342 ((intensities[0] * xFacInv + intensities[1] * factors[0]) * (yFacInv)) +
343 ((intensities[2] * xFacInv + intensities[3] * factors[0]) * (factors[1])),
344 -((dx1 * xFacInv) + (dx2 * factors[0])),
345 -((dy1 * yFacInv) + (dy2 * factors[1]))
351 return Eigen::Translation2f(transVector[0], transVector[1]) * Eigen::Rotation2Df(transVector[2]);
356 return Eigen::Translation2f(transVector[0], transVector[1]);
const std::vector< Eigen::Vector3f > & getSamplePoints() const
Eigen::Vector2f getWorldCoordsPoint(const Eigen::Vector2f &mapPoint) const
std::vector< Eigen::Vector3f > samplePoints
float getUnfilteredGridPoint(Eigen::Vector2i &gridCoords) const
float mapObstacleThreshold
static float sqr(float val)
Eigen::Vector3f getMapCoordsPose(const Eigen::Vector3f &worldPose) const
float getLikelihoodForResidual(float residual, int numDataPoints)
const ConcreteOccGridMap * concreteGridMap
TFSIMD_FORCE_INLINE const tfScalar & y() const
ConcreteCacheMethod cacheMethod
Eigen::Vector3f interpMapValueWithDerivatives(const Eigen::Vector2f &coords)
float getLikelihoodForState(const Eigen::Vector3f &state, const DataContainer &dataPoints)
float interpMapValue(const Eigen::Vector2f &coords)
const DataPointType & getVecEntry(int index) const
Eigen::Affine2f getTransformForState(const Eigen::Vector3f &transVector) const
Eigen::Matrix3f getCovarianceForPose(const Eigen::Vector3f &mapPose, const DataContainer &dataPoints)
Eigen::Translation2f getTranslationForState(const Eigen::Vector3f &transVector) const
Eigen::Matrix3f getCovMatrixWorldCoords(const Eigen::Matrix3f &covMatMap)
TFSIMD_FORCE_INLINE const tfScalar & x() const
float getResidualForState(const Eigen::Vector3f &state, const DataContainer &dataPoints)
float getUnfilteredGridPoint(int index) const
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Vector3f getWorldCoordsPose(const Eigen::Vector3f &mapPose) const
Eigen::Vector4f intensities
void getCompleteHessianDerivs(const Eigen::Vector3f &pose, const DataContainer &dataPoints, Eigen::Matrix3f &H, Eigen::Vector3f &dTr)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
OccGridMapUtil(const ConcreteOccGridMap *gridMap)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)