-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathabstract_view.h
173 lines (142 loc) · 5.57 KB
/
abstract_view.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* @author Hauke Strasdat, Steven Lovegrove, Andrew J. Davison
*
* Copyright (C) 2010 Hauke Strasdat, Steven Lovegrove, Andrew J. Davison
* Imperial College London
*
* abstract_view.h is part of RobotVision.
*
* RobotVision is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* RobotVision is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RV_ABSTRACT_VIEW_H
#define RV_ABSTRACT_VIEW_H
#include <TooN/TooN.h>
#include <TooN/se3.h>
#include <cvd/glwindow.h>
#include <cvd/image_io.h>
#include "gui_window.h"
#include "quadtree.h"
#include "sim3.h"
namespace RobotVision
{
class GuiWindow;
class AbstractView : public Viewport
{
public:
AbstractView()
{}
~AbstractView(){
if (qtree!=0)
delete qtree;
}
AbstractView(const AbstractView & view);
AbstractView(const CVD::ImageRef & size);
AbstractView(const CVD::ImageRef & size,
const TooN::Vector<3>& axis_angle,
const TooN::Vector<3>& trans );
// Attach view to GuiWindow
void init(GuiWindow * win, const Rectangle & bounding_box);
// Return default event handler
CVD::GLWindow::EventHandler* get_handler();
// Set default event handler
void set_handler( CVD::GLWindow::EventHandler* handler );
// Return parent GuiWindow
GuiWindow* parent();
// Return true iff the view is currently active
bool isNavigating();
// Return intersection of image point ip with the rendered scene
// in frame of reference of the view's camera
TooN::Vector<3> intersectScene( const CVD::ImageRef& ip );
// Active Viewport
void activate();
virtual void activate2D() = 0;
virtual void activate3D() = 0;
virtual void activate3D(const TooN::SE3<double> & pose) = 0;
void drawTexture2D(const CVD::SubImage<CVD::byte> & img);
void drawTexture2D(const CVD::SubImage<float> & img);
void drawTexture2D(const CVD::SubImage<CVD::Rgb<CVD::byte> > & img);
void drawTexture2D(const CVD::SubImage<CVD::byte> & img,
const CVD::ImageRef & ir);
void drawTexture2D(const CVD::SubImage<CVD::Rgb<CVD::byte> > & img,
const CVD::ImageRef & ir);
void drawTexture2D(const CVD::SubImage<CVD::Rgba<CVD::byte> > & img);
void drawTexture2D(const CVD::SubImage<CVD::Rgba<CVD::byte> > & img,
const CVD::ImageRef & ir);
void drawCircle2D(const TooN::Vector<2> & p1,
double inner_radius,
double outer_radius);
void drawLine2D(const TooN::Vector<2> & p1,
const TooN::Vector<2> & p2);
void drawBox2D(const Rectangle & r);
void drawCovariance2D(const TooN::Vector<2> & mu,
const TooN::Matrix<2>& Sigma,
double number_of_sigma,
double ring_thickness );
void drawLine3D(const TooN::Vector<3> & p1, const TooN::Vector<3> & p2);
void drawBall3D(const TooN::Vector<3> & p1, double radius);
void drawPose3D(const TooN::SE3<double> & pose);
void drawSimilarity3D(const RobotVision::Sim3<double> & pose);
void drawCovariance3D(const TooN::Vector<3> & trans,
const TooN::Matrix<3> & pose_unc,
double number_of_sigma);
// Update pose given delta transformation Current to New.
void updatePose(const TooN::SE3<>& T_nc );
void updatePose(const TooN::SO3<>& R_nc );
// Set pose of camera, camera to world
void setPose(const TooN::SE3<>& T_wc );
// Return pose T_wc of virtual camera
TooN::SE3<> getPose();
inline CVD::ImageRef size() const {
return CVD::ImageRef(pixel_size[0],pixel_size[1]);
}
inline CVD::ImageRef viewSize() const {
return CVD::ImageRef(bounding_box.Width()*win->size().x,
bounding_box.Height()*win->size().y );
}
protected:
CVD::GLWindow::EventHandler* handler;
TooN::Matrix<4> glK;
TooN::SE3<double> T_cw_;
TooN::Vector<2> pixel2opengl(const TooN::Vector<2> & v);
int id;
TooN::QuadTree<int> * qtree;
};
class DoomViewHandler : public CVD::GLWindow::EventHandler
{
public:
DoomViewHandler( AbstractView* view ) : view(view), enabled(true) {}
virtual void on_key_down(CVD::GLWindow& /*win*/, int /*key*/);
void on_mouse_down(CVD::GLWindow& /*win*/,
CVD::ImageRef /*where*/,
int /*state*/,
int /*button*/);
void on_mouse_up(CVD::GLWindow& /*win*/,
CVD::ImageRef /*where*/,
int /*state*/,
int /*button*/);
void on_mouse_move(CVD::GLWindow& /*win*/,
CVD::ImageRef /*where*/,
int /*state*/);
void on_event(CVD::GLWindow& /*win*/,
int /*event_id*/);
void on_activated(CVD::GLWindow& /*win*/);
void on_deactivated(CVD::GLWindow& /*win*/);
protected:
AbstractView* view;
CVD::ImageRef last_pos;
bool enabled;
};
}
#endif // RV_ABSTRACT_VIEW_H