world_scoped_maps.cpp
Go to the documentation of this file.
1 #include <cfloat>
2 #include <tgmath.h>
3 #include <iomanip>
4 #include <boost/lexical_cast.hpp>
5 #include <opencv2/highgui/highgui.hpp>
6 #include <opencv2/imgproc/imgproc.hpp>
8 #include <tuw_geometry/utils.h>
9 
10 
11 using namespace tuw;
12 
14  width_pixel_ (-1),
15  height_pixel_(-1),
16  min_x_(0), max_x_(0), min_y_(0), max_y_(0) {
17 
18 }
19 
21  return ((width_pixel_ != -1) && (height_pixel_ != -1));
22 }
23 
25 
26  dx_ = max_x_ - min_x_;
27  dy_ = max_y_ - min_y_;
28  sx_ = width_pixel_ / dx_;
29  sy_ = height_pixel_ / dy_;
30  ox_ = width_pixel_ / 2.0;
31  oy_ = height_pixel_ / 2.0;
32  double ca = cos ( rotation_ ), sa = sin ( rotation_ );
33  mx_ = min_x_ + dx_/2.;
34  my_ = min_y_ + dy_/2.;
35  cv::Matx<double, 3, 3 > Tw ( 1, 0, -mx_, 0, 1, -my_, 0, 0, 1 ); // translation
36  cv::Matx<double, 3, 3 > Sc ( sx_, 0, 0, 0, sy_, 0, 0, 0, 1 ); // scaling
37  cv::Matx<double, 3, 3 > Sp ( -1, 0, 0, 0, 1, 0, 0, 0, 1 ); // mirroring
38  cv::Matx<double, 3, 3 > R ( ca, -sa, 0, sa, ca, 0, 0, 0, 1 ); // rotation
39  cv::Matx<double, 3, 3 > Tm ( 1, 0, ox_, 0, 1, oy_, 0, 0, 1 ); // translation
40  Mw2m_ = Tm * R * Sp * Sc * Tw;
41 
42  Mm2w_ = Mw2m_.inv();
43 }
44 void WorldScopedMaps::init ( int width_pixel, int height_pixel, double min_x, double max_x, double min_y, double max_y, double rotation ) {
45  width_pixel_ = width_pixel, height_pixel_ = height_pixel;
46  min_y_ = std::min ( min_y, max_y );
47  max_y_ = std::max ( min_y, max_y );
48  min_x_ = std::min ( min_x, max_x );
49  max_x_ = std::max ( min_x, max_x );
50  rotation_ = rotation;
51 
52  init();
53 }
54 
55 const cv::Matx33d &WorldScopedMaps::Mw2m () const {
56  return Mw2m_;
57 }
58 const cv::Matx33d &WorldScopedMaps::Mm2w () const {
59  return Mm2w_;
60 }
61 Point2D WorldScopedMaps::w2m ( const Point2D &src ) const {
62  return Mw2m_ * src;
63 }
64 Point2D WorldScopedMaps::w2m ( double x, double y ) const {
65  return w2m(Point2D(x,y));
66 }
67 Point2D &WorldScopedMaps::w2m ( const Point2D &src, Point2D &des ) const {
68  des = Mw2m_ * src;
69  return des;
70 }
71 Point2D WorldScopedMaps::m2w ( const Point2D &src ) const {
72  return Mm2w_ * src;
73 }
74 Point2D WorldScopedMaps::m2w ( double x, double y ) const {
75  return m2w(Point2D(x,y));
76 }
77 Point2D &WorldScopedMaps::m2w ( const Point2D &src, Point2D &des ) const {
78  des = Mm2w_ * src;
79  return des;
80 }
81 double WorldScopedMaps::max_x () const {
82  return max_x_;
83 }
84 double WorldScopedMaps::min_x () const {
85  return min_x_;
86 }
87 double WorldScopedMaps::scale_x () const {
88  return sx_;
89 }
90 double WorldScopedMaps::max_y () const {
91  return max_y_;
92 }
93 double WorldScopedMaps::min_y () const {
94  return min_y_;
95 }
96 double WorldScopedMaps::scale_y () const {
97  return sy_;
98 }
99 int WorldScopedMaps::width () const {
100  return width_pixel_;
101 }
103  return height_pixel_;
104 }
105 
106 double WorldScopedMaps::scale_w2m (double v) const {
107  return v * sx_;
108 }
109 std::string WorldScopedMaps::infoHeader() const{
110  char buffer[0x1FF];
111  Point2D p0 = m2w(0, 0);
113  sprintf(buffer, "%4i,%4i [px]; %6.2f, %6.2f [m] => %6.2f, %6.2f [px/m]; 0, 0 [px] = %6.2f, %6.2f [m] @ %3.2f [rad]; %4i, %4i [px] = %6.2f, %6.2f [m] @ %3.2f [rad]",
114  width_pixel_, height_pixel_, dx_, dy_, sx_, sy_, p0.x(), p0.y(), rotation_, width_pixel_/2, height_pixel_/2, p1.x(), p1.y(), rotation_);
115  return std::string(buffer);
116 }
const double & y() const
Definition: point2d.cpp:49
std::string infoHeader() const
cv::Matx33d Mm2w_
transformation map to world
int height_pixel_
dimensions of the canvas in pixel
double dy_
dimension of the visualized space
void init()
initializes the transformation matrices
Point2D w2m(const Point2D &src) const
double scale_w2m(double v) const
Definition: command.h:8
cv::Matx33d Mw2m_
transformation world to map
const cv::Matx33d & Mw2m() const
const cv::Matx33d & Mm2w() const
double oy_
image offset
double my_
offset of the visualized space
const double & x() const
Definition: point2d.cpp:35
Point2D m2w(const Point2D &src) const
double rotation_
area and rotation of the visualized space


tuw_geometry
Author(s): Markus Bader
autogenerated on Mon Jun 10 2019 15:33:09