world_scoped_maps.h
Go to the documentation of this file.
1 #ifndef WORLD_SCOPED_MAPS_H
2 #define WORLD_SCOPED_MAPS_H
3 #include <opencv/cv.h>
4 #include <opencv2/core/core.hpp>
5 #include <opencv2/core/core_c.h>
6 #include <opencv2/imgproc/imgproc.hpp>
7 #include <tuw_geometry/pose2d.h>
8 
9 namespace tuw {
10 class WorldScopedMaps;
11 using WorldScopedMapsPtr = std::shared_ptr< WorldScopedMaps > ;
12 using WorldScopedMapsConstPtr = std::shared_ptr< WorldScopedMaps const>;
13 
18  cv::Matx33d Mw2m_;
19  cv::Matx33d Mm2w_;
22  double dx_, dy_;
23  double ox_, oy_;
24  double mx_, my_;
25  double sx_, sy_;
26 
27  void init();
28 public:
29 
30  //special class member functions
31  WorldScopedMaps ( );
32  virtual ~WorldScopedMaps() = default;
33  WorldScopedMaps (const WorldScopedMaps&) = default;
34  WorldScopedMaps& operator=(const WorldScopedMaps&) = default;
35  WorldScopedMaps (WorldScopedMaps&&) = default;
37 
48  void init ( int width_pixel, int height_pixel, double min_y, double max_y, double min_x, double max_x, double rotation = 0 );
49 
54  template <typename T> void init(const T &metadata){
55  width_pixel_ = metadata.width, height_pixel_ = metadata.height;
56  dx_ = metadata.resolution * (double) metadata.width;
57  dy_ = metadata.resolution * (double) metadata.height;
58  sx_ = 1.0/metadata.resolution;
59  sy_ = 1.0/metadata.resolution;
60  ox_ = 0.;
61  oy_ = 0.;
62  double roll = 0, pitch = 0, yaw = 0;
63  QuaternionToEuler ( metadata.origin.orientation, roll, pitch, yaw );
64  rotation_ = -yaw;
65  rotation_ = 0;
66  double ca = cos ( rotation_ ), sa = sin ( rotation_ );
67  mx_ = metadata.origin.position.x;
68  my_ = metadata.origin.position.y;
69  cv::Matx<double, 3, 3 > Tw ( 1, 0, -mx_, 0, 1, -my_, 0, 0, 1 ); // translation
70  cv::Matx<double, 3, 3 > Sc ( sx_, 0, 0, 0, sy_, 0, 0, 0, 1 ); // scaling
71  cv::Matx<double, 3, 3 > R ( ca, -sa, 0, sa, ca, 0, 0, 0, 1 ); // rotation
72  Mw2m_ = R * Sc * Tw;
73  Mm2w_ = Mw2m_.inv();
74  Point2D p = m2w(width_pixel_, height_pixel_);
75  min_y_ = mx_;
76  min_x_ = my_;
77  max_x_ = p.x();
78  max_y_ = p.y();
79  }
80 
84  bool initialized();
94  template <typename T>
95  void line ( T &map, const Point2D &p0, const Point2D &p1, const cv::Scalar &color, int thickness=1, int lineType = CV_AA ) const {
96  cv::line ( map, w2m ( p0 ).cv(), w2m ( p1 ).cv(), color, thickness, lineType );
97  }
107  template <typename T>
108  void circle ( T &map, const Point2D &p, int radius, const cv::Scalar &color, int thickness=1, int lineType = CV_AA ) const{
109  cv::circle ( map, w2m ( p ).cv(), radius, color, thickness, lineType );
110  }
111 
117  template <typename T>
118  cv::Scalar_<T> get ( cv::Mat_<T> &map, const Point2D &p) const{
119  return map.at(w2m ( p ).cv() );
120  }
121 
125  const cv::Matx33d &Mw2m () const;
129  const cv::Matx33d &Mm2w () const;
130 
136  Point2D w2m ( const Point2D &src ) const ;
143  Point2D w2m ( double x, double y ) const ;
150  Point2D &w2m ( const Point2D &src, Point2D &des ) const;
156  Point2D m2w ( const Point2D &src ) const ;
163  Point2D m2w ( double x, double y ) const ;
170  Point2D &m2w ( const Point2D &src, Point2D &des ) const;
171 
175  int width () const ;
179  int height () const ;
183  double scale_x () const ;
187  double scale_y () const ;
191  double min_x () const ;
195  double max_x () const ;
199  double min_y () const ;
203  double max_y () const ;
209  double scale_w2m (double v) const ;
215  std::string infoHeader() const;
216 };
217 
218 }
219 #endif // WORLD_SCOPED_MAPS_H
void circle(T &map, const Point2D &p, int radius, const cv::Scalar &color, int thickness=1, int lineType=CV_AA) const
const double & y() const
Definition: point2d.cpp:49
void init(const T &metadata)
std::string infoHeader() const
virtual ~WorldScopedMaps()=default
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
void line(T &map, const Point2D &p0, const Point2D &p1, const cv::Scalar &color, int thickness=1, int lineType=CV_AA) const
Point2D w2m(const Point2D &src) const
Definition: point2d.h:208
double scale_w2m(double v) const
WorldScopedMaps & operator=(const WorldScopedMaps &)=default
Definition: command.h:8
cv::Matx33d Mw2m_
transformation world to map
const cv::Matx33d & Mw2m() const
const cv::Matx33d & Mm2w() const
void QuaternionToEuler(const Quaternion &q, double &roll, double &pitch, double &yaw)
Definition: utils.h:179
std::shared_ptr< WorldScopedMaps > WorldScopedMapsPtr
Prototype.
double oy_
image offset
double my_
offset of the visualized space
std::shared_ptr< WorldScopedMaps const > WorldScopedMapsConstPtr
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