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 <opencv2/core/core.hpp>
4 #include <opencv2/core/core_c.h>
5 #include <opencv2/imgproc/imgproc.hpp>
6 #include <tuw_geometry/pose2d.h>
7 
8 namespace tuw {
9 class WorldScopedMaps;
10 using WorldScopedMapsPtr = std::shared_ptr< WorldScopedMaps > ;
11 using WorldScopedMapsConstPtr = std::shared_ptr< WorldScopedMaps const>;
12 
17  cv::Matx33d Mw2m_;
18  cv::Matx33d Mm2w_;
21  double dx_, dy_;
22  double ox_, oy_;
23  double mx_, my_;
24  double sx_, sy_;
25 
26  void init();
27 public:
28 
29  //special class member functions
30  WorldScopedMaps ( );
31  virtual ~WorldScopedMaps() = default;
32  WorldScopedMaps (const WorldScopedMaps&) = default;
33  WorldScopedMaps& operator=(const WorldScopedMaps&) = default;
34  WorldScopedMaps (WorldScopedMaps&&) = default;
36 
47  void init ( int width_pixel, int height_pixel, double min_y, double max_y, double min_x, double max_x, double rotation = 0 );
48 
53  template <typename T> void init(const T &metadata){
54  width_pixel_ = metadata.width, height_pixel_ = metadata.height;
55  dx_ = metadata.resolution * (double) metadata.width;
56  dy_ = metadata.resolution * (double) metadata.height;
57  sx_ = 1.0/metadata.resolution;
58  sy_ = 1.0/metadata.resolution;
59  ox_ = 0.;
60  oy_ = 0.;
61  double roll = 0, pitch = 0, yaw = 0;
62  QuaternionToEuler ( metadata.origin.orientation, roll, pitch, yaw );
63  rotation_ = -yaw;
64  rotation_ = 0;
65  double ca = cos ( rotation_ ), sa = sin ( rotation_ );
66  mx_ = metadata.origin.position.x;
67  my_ = metadata.origin.position.y;
68  cv::Matx<double, 3, 3 > Tw ( 1, 0, -mx_, 0, 1, -my_, 0, 0, 1 ); // translation
69  cv::Matx<double, 3, 3 > Sc ( sx_, 0, 0, 0, sy_, 0, 0, 0, 1 ); // scaling
70  cv::Matx<double, 3, 3 > R ( ca, -sa, 0, sa, ca, 0, 0, 0, 1 ); // rotation
71  Mw2m_ = R * Sc * Tw;
72  Mm2w_ = Mw2m_.inv();
74  min_y_ = mx_;
75  min_x_ = my_;
76  max_x_ = p.x();
77  max_y_ = p.y();
78  }
79 
83  bool initialized();
93  template <typename T>
94  void line ( T &map, const Point2D &p0, const Point2D &p1, const cv::Scalar &color, int thickness=1, int lineType = cv::LINE_AA ) const {
95  cv::line ( map, w2m ( p0 ).cv(), w2m ( p1 ).cv(), color, thickness, lineType );
96  }
106  template <typename T>
107  void circle ( T &map, const Point2D &p, int radius, const cv::Scalar &color, int thickness=1, int lineType = cv::LINE_AA ) const{
108  cv::circle ( map, w2m ( p ).cv(), radius, color, thickness, lineType );
109  }
110 
116  template <typename T>
117  cv::Scalar_<T> get ( cv::Mat_<T> &map, const Point2D &p) const{
118  return map.at(w2m ( p ).cv() );
119  }
120 
124  const cv::Matx33d &Mw2m () const;
128  const cv::Matx33d &Mm2w () const;
129 
135  Point2D w2m ( const Point2D &src ) const ;
142  Point2D w2m ( double x, double y ) const ;
149  Point2D &w2m ( const Point2D &src, Point2D &des ) const;
155  Point2D m2w ( const Point2D &src ) const ;
162  Point2D m2w ( double x, double y ) const ;
169  Point2D &m2w ( const Point2D &src, Point2D &des ) const;
170 
174  int width () const ;
178  int height () const ;
182  double scale_x () const ;
186  double scale_y () const ;
190  double min_x () const ;
194  double max_x () const ;
198  double min_y () const ;
202  double max_y () const ;
208  double scale_w2m (double v) const ;
214  std::string infoHeader() const;
215 };
216 
217 }
218 #endif // WORLD_SCOPED_MAPS_H
tuw::WorldScopedMaps::dx_
double dx_
Definition: world_scoped_maps.h:21
tuw::WorldScopedMaps::height
int height() const
Definition: world_scoped_maps.cpp:102
tuw::WorldScopedMaps::width_pixel_
int width_pixel_
Definition: world_scoped_maps.h:19
tuw::WorldScopedMaps::min_y_
double min_y_
Definition: world_scoped_maps.h:20
tuw::WorldScopedMaps::line
void line(T &map, const Point2D &p0, const Point2D &p1, const cv::Scalar &color, int thickness=1, int lineType=cv::LINE_AA) const
Definition: world_scoped_maps.h:94
tuw::WorldScopedMaps::min_x_
double min_x_
Definition: world_scoped_maps.h:20
tuw::WorldScopedMaps::min_y
double min_y() const
Definition: world_scoped_maps.cpp:93
pose2d.h
tuw::WorldScopedMaps::operator=
WorldScopedMaps & operator=(const WorldScopedMaps &)=default
tuw::WorldScopedMaps::ox_
double ox_
Definition: world_scoped_maps.h:22
tuw::WorldScopedMaps::min_x
double min_x() const
Definition: world_scoped_maps.cpp:84
tuw::WorldScopedMaps::scale_y
double scale_y() const
Definition: world_scoped_maps.cpp:96
tuw::WorldScopedMaps::scale_w2m
double scale_w2m(double v) const
Definition: world_scoped_maps.cpp:106
tuw::WorldScopedMaps::max_x
double max_x() const
Definition: world_scoped_maps.cpp:81
tuw::WorldScopedMapsConstPtr
std::shared_ptr< WorldScopedMaps const > WorldScopedMapsConstPtr
Definition: world_scoped_maps.h:11
test_point2d.p
p
Definition: test_point2d.py:20
tuw::WorldScopedMaps::my_
double my_
offset of the visualized space
Definition: world_scoped_maps.h:23
tuw::WorldScopedMaps::get
cv::Scalar_< T > get(cv::Mat_< T > &map, const Point2D &p) const
Definition: world_scoped_maps.h:117
tuw::WorldScopedMaps::height_pixel_
int height_pixel_
dimensions of the canvas in pixel
Definition: world_scoped_maps.h:19
tuw::WorldScopedMapsPtr
std::shared_ptr< WorldScopedMaps > WorldScopedMapsPtr
Prototype.
Definition: world_scoped_maps.h:10
tuw::QuaternionToEuler
void QuaternionToEuler(const Quaternion &q, double &roll, double &pitch, double &yaw)
Definition: utils.h:179
tuw::WorldScopedMaps::max_x_
double max_x_
Definition: world_scoped_maps.h:20
tuw::WorldScopedMaps::Mm2w_
cv::Matx33d Mm2w_
transformation map to world
Definition: world_scoped_maps.h:18
tuw::WorldScopedMaps::width
int width() const
Definition: world_scoped_maps.cpp:99
tuw::WorldScopedMaps::mx_
double mx_
Definition: world_scoped_maps.h:23
tuw
Definition: command.h:8
tuw::WorldScopedMaps::sy_
double sy_
scale
Definition: world_scoped_maps.h:24
tuw::WorldScopedMaps::scale_x
double scale_x() const
Definition: world_scoped_maps.cpp:87
tuw::WorldScopedMaps::Mm2w
const cv::Matx33d & Mm2w() const
Definition: world_scoped_maps.cpp:58
tuw::WorldScopedMaps::Mw2m
const cv::Matx33d & Mw2m() const
Definition: world_scoped_maps.cpp:55
tuw::WorldScopedMaps::max_y
double max_y() const
Definition: world_scoped_maps.cpp:90
tuw::WorldScopedMaps::infoHeader
std::string infoHeader() const
Definition: world_scoped_maps.cpp:109
tuw::Point2D
Definition: point2d.h:19
tuw::WorldScopedMaps::w2m
Point2D w2m(const Point2D &src) const
Definition: world_scoped_maps.cpp:61
tuw::WorldScopedMaps::m2w
Point2D m2w(const Point2D &src) const
Definition: world_scoped_maps.cpp:71
tuw::WorldScopedMaps::rotation_
double rotation_
area and rotation of the visualized space
Definition: world_scoped_maps.h:20
tuw::WorldScopedMaps::WorldScopedMaps
WorldScopedMaps()
Definition: world_scoped_maps.cpp:13
tuw::WorldScopedMaps::oy_
double oy_
image offset
Definition: world_scoped_maps.h:22
tuw::WorldScopedMaps::sx_
double sx_
Definition: world_scoped_maps.h:24
tuw::WorldScopedMaps::initialized
bool initialized()
Definition: world_scoped_maps.cpp:20
tuw::WorldScopedMaps
Definition: world_scoped_maps.h:16
tuw::WorldScopedMaps::init
void init(const T &metadata)
Definition: world_scoped_maps.h:53
tuw::WorldScopedMaps::~WorldScopedMaps
virtual ~WorldScopedMaps()=default
cv
Definition: point2d.h:208
tuw::WorldScopedMaps::dy_
double dy_
dimension of the visualized space
Definition: world_scoped_maps.h:21
tuw::WorldScopedMaps::max_y_
double max_y_
Definition: world_scoped_maps.h:20
tuw::WorldScopedMaps::Mw2m_
cv::Matx33d Mw2m_
transformation world to map
Definition: world_scoped_maps.h:17
tuw::WorldScopedMaps::init
void init()
initializes the transformation matrices
Definition: world_scoped_maps.cpp:24
tuw::WorldScopedMaps::circle
void circle(T &map, const Point2D &p, int radius, const cv::Scalar &color, int thickness=1, int lineType=cv::LINE_AA) const
Definition: world_scoped_maps.h:107


tuw_geometry
Author(s): Markus Bader
autogenerated on Sun Feb 26 2023 03:25:40