farm-ng-core
fit_plane.h
Go to the documentation of this file.
1 // Copyright (c) 2011, Hauke Strasdat
2 // Copyright (c) 2012, Steven Lovegrove
3 // Copyright (c) 2021, farm-ng, inc.
4 //
5 // Use of this source code is governed by an MIT-style
6 // license that can be found in the LICENSE file or at
7 // https://opensource.org/licenses/MIT.
8 
9 #pragma once
10 
11 #include <Eigen/Dense>
12 #include <Eigen/Geometry>
13 
14 namespace sophus {
15 
16 inline auto fitPlaneToPoints(Eigen::Matrix3Xd const& points)
17  -> Eigen::Hyperplane<double, 3> {
18  Eigen::Vector3d mean = points.rowwise().mean();
19  Eigen::Matrix3Xd points_centered = points.colwise() - mean;
20  Eigen::JacobiSVD<Eigen::Matrix3Xd> svd(
21  points_centered, Eigen::ComputeFullU | Eigen::ComputeThinV);
22  Eigen::Vector3d normal = svd.matrixU().col(2);
23  return Eigen::Hyperplane<double, 3>(normal, mean);
24 }
25 
26 // convenience overloads
27 auto fitPlaneToPoints(std::vector<Eigen::Vector3d> const& points)
28  -> Eigen::Hyperplane<double, 3> {
29  Eigen::Map<const Eigen::Matrix3Xd> map(
30  points.data()->data(), 3, points.size());
31  return fitPlaneToPoints(map.eval());
32 }
33 
34 auto fitPlaneToPoints(std::vector<Eigen::Vector3f> const& points)
35  -> Eigen::Hyperplane<double, 3> {
36  Eigen::Map<const Eigen::Matrix3Xf> map(
37  points.data()->data(), 3, points.size());
38  return fitPlaneToPoints(map.cast<double>().eval());
39 }
40 
41 } // namespace sophus
sophus
Image MutImage, owning images types.
Definition: num_diff.h:20
sophus::SegmentCase::normal
@ normal
sophus::fitPlaneToPoints
auto fitPlaneToPoints(Eigen::Matrix3Xd const &points) -> Eigen::Hyperplane< double, 3 >
Definition: fit_plane.h:16