QGLMap.cpp
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2014, Southwest Research Institute® (SwRI®)
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Southwest Research Institute® (SwRI®) nor the
14 // names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 // *****************************************************************************
29 
30 #include <multires_image/QGLMap.h>
31 
32 // C++ standard libraries
33 #include <cmath>
34 
35 namespace multires_image
36 {
37 QGLMap::QGLMap(QWidget *parent) :
38  QGLWidget(parent),
39  m_initialized(false),
40  m_scale(1.0),
41  m_mouseDown(false),
42  m_mouseDownX(0),
43  m_mouseDownY(0),
44  m_tileView(NULL),
45  m_view_top_left(0, 0, 0),
46  m_view_bottom_right(0, 0, 0),
47  m_view_center(0, 0, 0),
48  m_scene_top_left(0, 0, 0),
49  m_scene_bottom_right(0, 0, 0),
50  m_scene_center(0, 0, 0)
51 {
52  ui.setupUi(this);
53 }
54 
56 {
57 }
58 
60 {
61  if (m_tileView != NULL)
62  {
63  m_tileView->Exit();
64  }
65 }
66 
68 {
69  if (m_initialized)
70  {
71  Recenter();
72 
73  if (m_tileView != NULL)
74  {
76  }
77 
78  glViewport(0, 0, width(), height());
79  glMatrixMode(GL_PROJECTION);
80  glLoadIdentity();
81  glOrtho(m_view_top_left.x(), m_view_bottom_right.x(),
82  m_view_bottom_right.y(), m_view_top_left.y(), -0.5f, 0.5f);
83 
84  update();
85 
86  // Signal a view change as occured. The minimap listens for this
87  // so that it can update its view box.
90  }
91 }
92 
94 {
95  double top, left, bottom, right;
96  tiles->GeoReference().GetCoordinate(0, 0, left, top);
97  tiles->GeoReference().GetCoordinate(tiles->GeoReference().Width(), tiles->GeoReference().Height(), right, bottom);
98 
99  m_scene_top_left = tf::Point(left, top, 0);
100  m_scene_bottom_right = tf::Point(right, bottom, 0);
102 
104 
105  m_tileView = new TileView(tiles, this);
106 
107  connect(m_tileView->Cache(), SIGNAL(SignalMemorySize(int64_t)),
108  SLOT(SetTextureMemory(int64_t)));
109 
110  // Create connections for the texture loading functions which must
111  // be executed on this object's thread.
112 
114 }
115 
116 void QGLMap::wheelEvent(QWheelEvent* e)
117 {
118  float numDegrees = e->delta() / -8;
119 
120  m_scale *= pow(1.1, numDegrees / 10.0);
121 
122  UpdateView();
123 }
124 
126 {
127  tile->LoadTexture();
128 }
129 
131 {
132  tile->UnloadTexture();
133 }
134 
135 void QGLMap::SetTextureMemory(int64_t bytes)
136 {
137  // Signal that the texture memory size has changed. The status bar listens
138  // to this so that the user can see how much memory the map is using.
139  emit SignalMemorySize(bytes);
140 }
141 
142 void QGLMap::ChangeCenter(double x, double y)
143 {
144  if (x != 0)
145  m_view_center.setX(x);
146 
147  if (y != 0)
148  m_view_center.setY(y);
149 
150  UpdateView();
151 }
152 
154 {
155  glClearColor(0.58f, 0.56f, 0.5f, 1);
156  glEnable(GL_POINT_SMOOTH);
157  glEnable(GL_LINE_SMOOTH);
158  glEnable(GL_POLYGON_SMOOTH);
159  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
160  glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
161  glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
162  glEnable(GL_BLEND);
163  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
164  glDepthFunc(GL_NEVER);
165  glDisable(GL_DEPTH_TEST);
166  m_initialized = true;
167 }
168 
169 void QGLMap::resizeGL(int w, int h)
170 {
171  UpdateView();
172 }
173 
175 {
176  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
177 
178  if (m_tileView != NULL)
179  {
180  m_tileView->Draw();
181  }
182 }
183 
184 void QGLMap::mousePressEvent(QMouseEvent* e)
185 {
186  m_mouseDownX = e->x();
187  m_mouseDownY = e->y();
188  m_mouseDown = true;
189 
190  update();
191 }
192 
193 void QGLMap::mouseDoubleClickEvent(QMouseEvent* e)
194 {
195  update();
196 }
197 
198 void QGLMap::mouseReleaseEvent(QMouseEvent* e)
199 {
200  m_mouseDown = false;
201 
202  update();
203 }
204 
205 void QGLMap::mouseMoveEvent(QMouseEvent* e)
206 {
207  if (m_mouseDown)
208  MousePan(e->x(), e->y());
209 }
210 
211 void QGLMap::MousePan(int x, int y)
212 {
213  bool changed = false;
214  if (m_mouseDown)
215  {
216  double diffX = ((m_mouseDownX - x) * m_scale);
217  double diffY = ((m_mouseDownY - y) * m_scale);
218 
219  if (diffX != 0)
220  {
221  m_view_center.setX(m_view_center.x() + diffX);
222  m_mouseDownX = x;
223  changed = true;
224  }
225  if (diffY != 0)
226  {
227  m_view_center.setY(m_view_center.y() + diffY);
228  m_mouseDownY = y;
229  changed = true;
230  }
231  }
232 
233  if (changed)
234  {
235  UpdateView();
236  }
237 }
238 
240 {
241  double scene_width = std::fabs(m_scene_top_left.x() - m_scene_bottom_right.x());
242  double scene_height = std::fabs(m_scene_top_left.y() - m_scene_bottom_right.y());
243  double view_width = width() * m_scale;
244  double view_height = height() * m_scale;
245 
246  m_view_top_left.setX(m_view_center.x() - (view_width * 0.5));
247  m_view_top_left.setY(m_view_center.y() - (view_width * 0.5));
248 
249  m_view_bottom_right.setX(m_view_center.x() + (view_width * 0.5));
250  m_view_bottom_right.setY(m_view_center.y() + (view_width * 0.5));
251 
252  if (view_width > scene_width)
253  {
254  m_view_center.setX(m_scene_center.x());
255  m_view_top_left.setX(m_view_center.x() - (view_width * 0.5));
256  m_view_bottom_right.setX(m_view_center.x() + (view_width * 0.5));
257  }
258  else
259  {
260  if (m_view_top_left.x() < m_scene_top_left.x())
261  {
263  m_view_bottom_right.setX(m_view_top_left.x() + view_width);
264  m_view_center.setX(m_view_top_left.x() + (view_width * 0.5));
265  }
266 
268  {
270  m_view_top_left.setX(m_view_bottom_right.x() - view_width);
271  m_view_center.setX(m_view_top_left.x() + (view_width * 0.5));
272  }
273  }
274 
275  if (view_height < scene_height)
276  {
277  m_view_center.setY(m_scene_center.y());
278  m_view_top_left.setY(m_scene_center.y() - (view_height * 0.5));
279  m_view_bottom_right.setY(m_scene_center.y() + (view_height * 0.5));
280  }
281  else
282  {
283  if (m_view_top_left.y() > m_scene_top_left.y())
284  {
286  m_view_bottom_right.setY(m_view_top_left.y() + (view_height));
287  m_view_center.setY(m_view_top_left.y() + (view_height * 0.5));
288  }
289 
291  {
293  m_view_top_left.setY(m_view_bottom_right.y() - (view_height));
294  m_view_center.setY(m_view_top_left.y() + (view_height * 0.5));
295  }
296  }
297 }
298 
299 }
300 
multires_image::TileView
Definition: tile_view.h:41
NULL
#define NULL
multires_image
Definition: multires_view_node.h:51
multires_image::QGLMap::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *e)
Definition: QGLMap.cpp:193
multires_image::TileView::Draw
void Draw()
Definition: tile_view.cpp:107
multires_image::QGLMap::mousePressEvent
void mousePressEvent(QMouseEvent *e)
Definition: QGLMap.cpp:184
multires_image::QGLMap::resizeGL
void resizeGL(int w, int h)
Definition: QGLMap.cpp:169
multires_image::TileView::Exit
void Exit()
Definition: tile_view.h:53
multires_image::Tile
Definition: tile.h:50
multires_image::QGLMap::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *e)
Definition: QGLMap.cpp:205
multires_image::TileSet::GeoReference
swri_transform_util::GeoReference & GeoReference()
Definition: tile_set.h:59
multires_image::QGLMap::m_mouseDownX
int m_mouseDownX
Definition: QGLMap.h:92
multires_image::QGLMap::QGLMap
QGLMap(QWidget *parent=0)
Definition: QGLMap.cpp:37
multires_image::QGLMap::~QGLMap
~QGLMap()
Definition: QGLMap.cpp:55
f
f
multires_image::QGLMap::m_mouseDownY
int m_mouseDownY
Definition: QGLMap.h:93
multires_image::QGLMap::m_scale
double m_scale
Definition: QGLMap.h:89
QGLMap.h
tf::Point
tf::Vector3 Point
multires_image::QGLMap::SetTextureMemory
void SetTextureMemory(int64_t bytes)
Definition: QGLMap.cpp:135
update
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
multires_image::QGLMap::DeleteTexture
void DeleteTexture(Tile *tile)
Definition: QGLMap.cpp:130
multires_image::Tile::UnloadTexture
void UnloadTexture()
Definition: tile.cpp:176
multires_image::QGLMap::Exit
void Exit()
Definition: QGLMap.cpp:59
multires_image::QGLMap::m_scene_center
tf::Point m_scene_center
Definition: QGLMap.h:103
swri_transform_util::GeoReference::GetCoordinate
void GetCoordinate(int x_pixel, int y_pixel, double &x_coordinate, double &y_coordinate) const
multires_image::QGLMap::LoadTexture
void LoadTexture(Tile *tile)
Definition: QGLMap.cpp:125
multires_image::QGLMap::m_view_top_left
tf::Point m_view_top_left
Definition: QGLMap.h:97
multires_image::QGLMap::m_tileView
TileView * m_tileView
Definition: QGLMap.h:95
multires_image::QGLMap::m_scene_top_left
tf::Point m_scene_top_left
Definition: QGLMap.h:101
multires_image::QGLMap::paintGL
void paintGL()
Definition: QGLMap.cpp:174
swri_transform_util::GeoReference::Height
unsigned int Height() const
multires_image::QGLMap::m_mouseDown
bool m_mouseDown
Definition: QGLMap.h:91
multires_image::TileView::Cache
const TileCache * Cache()
Definition: tile_view.h:47
multires_image::QGLMap::Recenter
void Recenter()
Definition: QGLMap.cpp:239
multires_image::QGLMap::initializeGL
void initializeGL()
Definition: QGLMap.cpp:153
multires_image::QGLMap::SignalMemorySize
void SignalMemorySize(int64_t bytes)
multires_image::QGLMap::wheelEvent
void wheelEvent(QWheelEvent *e)
Definition: QGLMap.cpp:116
multires_image::QGLMap::ChangeCenter
void ChangeCenter(double x, double y)
Definition: QGLMap.cpp:142
multires_image::QGLMap::UpdateView
void UpdateView()
Definition: QGLMap.cpp:67
multires_image::QGLMap::SignalViewChange
void SignalViewChange(double x1, double y1, double x2, double y2)
multires_image::QGLMap::m_initialized
bool m_initialized
Definition: QGLMap.h:87
multires_image::QGLMap::m_view_bottom_right
tf::Point m_view_bottom_right
Definition: QGLMap.h:98
multires_image::QGLMap::SetTiles
void SetTiles(TileSet *tiles)
Definition: QGLMap.cpp:93
multires_image::QGLMap::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *e)
Definition: QGLMap.cpp:198
multires_image::Tile::LoadTexture
bool LoadTexture()
Definition: tile.cpp:139
swri_transform_util::GeoReference::Width
unsigned int Width() const
multires_image::TileSet
Definition: tile_set.h:43
multires_image::QGLMap::ui
Ui::QGLMapClass ui
Definition: QGLMap.h:85
multires_image::QGLMap::m_scene_bottom_right
tf::Point m_scene_bottom_right
Definition: QGLMap.h:102
multires_image::QGLMap::m_view_center
tf::Point m_view_center
Definition: QGLMap.h:99
multires_image::QGLMap::MousePan
void MousePan(int x, int y)
Definition: QGLMap.cpp:211
multires_image::TileView::SetView
void SetView(double x, double y, double radius, double scale)
Definition: tile_view.cpp:63


multires_image
Author(s): Marc Alban
autogenerated on Sun Sep 8 2024 02:27:21