GeoDesk  0.1.3
 All Classes Namespaces Files Functions Typedefs Pages
projection.hpp
Go to the documentation of this file.
1 #ifndef PROJECTION_HPP
2 #define PROJECTION_HPP
3 
4 /**
5  * \file projection.hpp
6  * \brief Utilities for conversion from coordinates in an image to
7  * geographical coordinates.
8  * \author Le Bars, Yoann
9  * \version 1.0
10  * \date 2013/06/27
11  * \date 2013/06/28
12  * \date 2014/03/06
13  */
14 
15 #include <boost/concept_check.hpp>
16 #include <cassert>
17 #include <vector>
18 #include <eigen3/Eigen/Dense>
19 
20 /// \brief Namespace for projection computations.
21 namespace Projection {
22  /// \brief Class for 2D points.
23  class Point2D {
24  public:
25  /**
26  * \brief Construct a point with two double.
27  * \param _x Abscissa.
28  * \param _y Ordinate.
29  */
30  Point2D (double _x = 0., double _y = 0.): x_ (_x), y_ (_y) {}
31 
32  /**
33  * \brief Copy constructor.
34  * \param p Point2D to be copied.
35  */
36  Point2D (const Point2D &p): x_ (p.x_), y_ (p.y_) {}
37 
38  /// \brief Destructor.
39  ~Point2D () {}
40 
41  /// \brief Access to abscissa, modification is not possible.
42  double x () const {return x_;}
43 
44  /// \brief Access to abscissa, modification is possible.
45  double &x () {return x_;}
46 
47  /// \brief Access to ordinate, modification is not possible.
48  double y () const {return y_;}
49 
50  /// \brief Access to ordinate, modification is possible.
51  double &y () {return y_;}
52 
53  /**
54  * \brief Copy operator.
55  * \param p Point2D to be copied.
56  * \return A reference to current point.
57  */
59  x_ = p.x_;
60  y_ = p.y_;
61  return *this;
62  }
63 
64  private:
65  /// \brief Abscissa.
66  double x_;
67 
68  /// \brief Ordinate;
69  double y_;
70  };
71 
72  /// \brief Type for projection coefficients.
73  typedef Eigen::Matrix<double, 3, 2> Coefficients;
74 
75  /**
76  * \brief Compute the projection coefficients.
77  * \param r1 Vector containing reference points in image coordinates.
78  * \param r2 Vector containing reference points in geographical coordinates.
79  * \return Vector containing projection coefficients.
80  *
81  * Information on coefficients can be found at:
82  * <http://en.wikipedia.org/wiki/World_file>
83  */
84  inline Coefficients computeCoefficients (const std::vector<Point2D> &r1,
85  const std::vector<Point2D> &r2) {
86  assert(r1.size() == 3);
87  assert(r2.size() == 3);
88  /* Matrix to compute coefficients. */
89  Eigen::Matrix3d a;
90  a << r1[0].x(), r1[0].y(), 1.,
91  r1[1].x(), r1[1].y(), 1.,
92  r1[2].x(), r1[2].y(), 1.;
93  /* Matrix of points in geographical coordinates. */
94  Coefficients b;
95  b << r2[0].x(), r2[0].y(),
96  r2[1].x(), r2[1].y(),
97  r2[2].x(), r2[2].y();
98 // return a.fullPivLu().solve(b);
99  return a.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(b);
100  }
101 }
102 
103 #endif // #ifndef PROJECTION_HPP
Point2D(double _x=0., double _y=0.)
Construct a point with two double.
Definition: projection.hpp:30
Class for 2D points.
Definition: projection.hpp:23
double & y()
Access to ordinate, modification is possible.
Definition: projection.hpp:51
double & x()
Access to abscissa, modification is possible.
Definition: projection.hpp:45
Eigen::Matrix< double, 3, 2 > Coefficients
Type for projection coefficients.
Definition: projection.hpp:73
Coefficients computeCoefficients(const std::vector< Point2D > &r1, const std::vector< Point2D > &r2)
Compute the projection coefficients.
Definition: projection.hpp:84
double y() const
Access to ordinate, modification is not possible.
Definition: projection.hpp:48
~Point2D()
Destructor.
Definition: projection.hpp:39
Point2D(const Point2D &p)
Copy constructor.
Definition: projection.hpp:36
Point2D & operator=(const Point2D &p)
Copy operator.
Definition: projection.hpp:58
double x() const
Access to abscissa, modification is not possible.
Definition: projection.hpp:42