51 EigenObservationMatrix eigenObservation = getEigenObservationMatrix(&observations2D);
52 assert(eigenObservation.cols() == 4);
53 size_t nObservations = observations2D.
size();
58 Eigen::Matrix<double, Eigen::Dynamic, 2> points = eigenObservation.leftCols<2>();
60 Eigen::Matrix<double, 1, 2> pointMean;
63 pointMean << 0.0, 0.0;
66 pointMean = points.colwise().mean();
68 points = points.rowwise() - pointMean;
70 Eigen::Matrix<double, 2, 2> covarianceMatrix = points.transpose() * points;
72 Eigen::SelfAdjointEigenSolver< Eigen::Matrix<double, 2, 2> > eigensolver(covarianceMatrix);
74 if (eigensolver.info() != Eigen::Success)
75 B2WARNING(
"SelfAdjointEigenSolver could not compute the eigen values of the observation matrix");
80 Eigen::Matrix<double, 2, 1> normalToLine = eigensolver.eigenvectors().col(0);
82 double offset = -pointMean * normalToLine;
91 Eigen::Matrix<double, Eigen::Dynamic, 3> projectedPoints(nObservations, 3);
93 projectedPoints.col(0) = eigenObservation.col(0);
94 projectedPoints.col(1) = eigenObservation.col(1);
95 projectedPoints.col(2) = eigenObservation.leftCols<2>().rowwise().squaredNorm();
98 Eigen::Matrix<double, 1, 3> pointMean;
100 pointMean << 0.0, 0.0, 0.0;
103 pointMean = projectedPoints.colwise().mean();
105 projectedPoints = projectedPoints.rowwise() - pointMean;
108 Eigen::Matrix<double, 3, 3> covarianceMatrix = projectedPoints.transpose() * projectedPoints;
110 Eigen::SelfAdjointEigenSolver< Eigen::Matrix<double, 3, 3> > eigensolver(covarianceMatrix);
112 if (eigensolver.info() != Eigen::Success)
113 B2WARNING(
"Eigen::SelfAdjointEigenSolver could not compute the eigen values of the observation matrix");
118 Eigen::Matrix<double, 3, 1> normalToPlane = eigensolver.eigenvectors().col(0);
120 double offset = -pointMean * normalToPlane;
132 size_t voteForChangeSign = 0;
133 for (
size_t iPoint = 0; iPoint < nObservations; ++iPoint) {
134 double pointInSameDirection = eigenObservation(iPoint, 0) * directionAtCenter.
x() +
135 eigenObservation(iPoint, 1) * directionAtCenter.
y();
136 if (pointInSameDirection < 0) ++voteForChangeSign;
139 if (voteForChangeSign > nObservations / 2.0) trajectory2D.
reverse();
147 EigenObservationMatrix eigenObservation = getEigenObservationMatrix(&observations2D);
148 assert(eigenObservation.cols() == 4);
149 size_t nObservations = observations2D.
size();
159 Eigen::Matrix< double, Eigen::Dynamic, 1 > distances = eigenObservation.col(2);
166 Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > projectedPoints(nObservations, 2);
170 projectedPoints.col(0) = eigenObservation.col(0);
171 projectedPoints.col(1) = eigenObservation.col(1);
174 Eigen::Matrix<double, 2, 1> parameters =
175 projectedPoints.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(distances);
182 Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > projectedPoints(nObservations, 3);
186 projectedPoints.col(0) = eigenObservation.col(0);
187 projectedPoints.col(1) = eigenObservation.col(1);
188 projectedPoints.col(2) = eigenObservation.leftCols<2>().rowwise().squaredNorm() - distances.rowwise().squaredNorm();
190 Eigen::Matrix<double, 3, 1> parameters =
191 projectedPoints.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(distances);
198 Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > projectedPoints(nObservations, 3);
201 projectedPoints.col(0) = Eigen::Matrix<double, Eigen::Dynamic, 1>::Constant(nObservations, 1.0);
202 projectedPoints.col(1) = eigenObservation.col(0);
203 projectedPoints.col(2) = eigenObservation.col(1);
206 Eigen::Matrix<double, 3, 1> parameters =
207 projectedPoints.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(distances);
216 Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > projectedPoints(nObservations, 4);
219 projectedPoints.col(0) = Eigen::Matrix<double, Eigen::Dynamic, 1>::Constant(nObservations, 1.0);
220 projectedPoints.col(1) = eigenObservation.col(0);
221 projectedPoints.col(2) = eigenObservation.col(1);
222 projectedPoints.col(3) = eigenObservation.leftCols<2>().rowwise().squaredNorm() - distances.rowwise().squaredNorm();
226 Eigen::Matrix<double, 4, 1> parameters =
227 projectedPoints.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(distances);