farm-ng-core
homogeneous.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 "sophus/common/common.h"
12 
13 namespace sophus {
14 
15 /// Projects 3-point (x,y,z) through the origin (0,0,0) onto the plane z=1.
16 /// Hence it returns (x/z, y/z).
17 ///
18 /// Precondition: z must not be close to 0.
19 template <class TPoint>
20 auto proj(Eigen::MatrixBase<TPoint> const& p)
21  -> Eigen::Vector<typename TPoint::Scalar, TPoint::RowsAtCompileTime - 1> {
22  static_assert(TPoint::ColsAtCompileTime == 1, "p must be a column-vector");
23  static_assert(TPoint::RowsAtCompileTime >= 2, "p must have at least 2 rows");
24  return p.template head<TPoint::RowsAtCompileTime - 1>() /
25  p[TPoint::RowsAtCompileTime - 1];
26 }
27 
28 /// Maps point on the z=1 plane (a,b) to homogeneous representation of the same
29 /// point: (z*a, z*b, z). Z defaults to 1.
30 template <class TPoint>
31 auto unproj(
32  Eigen::MatrixBase<TPoint> const& p, const typename TPoint::Scalar& z = 1.0)
33  -> Eigen::Vector<typename TPoint::Scalar, TPoint::RowsAtCompileTime + 1> {
34  using Scalar = typename TPoint::Scalar;
35  static_assert(TPoint::ColsAtCompileTime == 1, "p must be a column-vector");
36  Eigen::Vector<Scalar, TPoint::RowsAtCompileTime + 1> out;
37  out.template head<TPoint::RowsAtCompileTime>() = z * p;
38  out[TPoint::RowsAtCompileTime] = z;
39  return out;
40 }
41 
42 } // namespace sophus
sophus::unproj
auto unproj(Eigen::MatrixBase< TPoint > const &p, const typename TPoint::Scalar &z=1.0) -> Eigen::Vector< typename TPoint::Scalar, TPoint::RowsAtCompileTime+1 >
Maps point on the z=1 plane (a,b) to homogeneous representation of the same point: (z*a,...
Definition: homogeneous.h:31
sophus
Image MutImage, owning images types.
Definition: num_diff.h:20
common.h
sophus::proj
auto proj(InverseDepthPoint3< TT > const &inverse_depth_point) -> Eigen::Matrix< TT, 2, 1 >
Projects 3-point (a,b,psi) = (x/z,y/z,1/z) through the origin (0,0,0) onto the plane z=1....
Definition: point_transform.h:20