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();
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  {
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  {
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  {
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  {
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 
tf::Point m_view_center
Definition: QGLMap.h:99
void DeleteTexture(Tile *tile)
Definition: QGLMap.cpp:130
#define NULL
tf::Point m_scene_bottom_right
Definition: QGLMap.h:102
void GetCoordinate(int x_pixel, int y_pixel, double &x_coordinate, double &y_coordinate) const
TFSIMD_FORCE_INLINE void setX(tfScalar x)
Ui::QGLMapClass ui
Definition: QGLMap.h:85
f
TFSIMD_FORCE_INLINE void setY(tfScalar y)
void mouseMoveEvent(QMouseEvent *e)
Definition: QGLMap.cpp:205
void wheelEvent(QWheelEvent *e)
Definition: QGLMap.cpp:116
swri_transform_util::GeoReference & GeoReference()
Definition: tile_set.h:59
void LoadTexture(Tile *tile)
Definition: QGLMap.cpp:125
tf::Point m_scene_top_left
Definition: QGLMap.h:101
void SetTextureMemory(int64_t bytes)
Definition: QGLMap.cpp:135
tf::Vector3 Point
void mouseReleaseEvent(QMouseEvent *e)
Definition: QGLMap.cpp:198
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
TFSIMD_FORCE_INLINE const tfScalar & x() const
void resizeGL(int w, int h)
Definition: QGLMap.cpp:169
void SignalMemorySize(int64_t bytes)
tf::Point m_view_bottom_right
Definition: QGLMap.h:98
TFSIMD_FORCE_INLINE const tfScalar & y() const
TileView * m_tileView
Definition: QGLMap.h:95
void mouseDoubleClickEvent(QMouseEvent *e)
Definition: QGLMap.cpp:193
unsigned int Height() const
tf::Point m_view_top_left
Definition: QGLMap.h:97
void SignalViewChange(double x1, double y1, double x2, double y2)
unsigned int Width() const
void mousePressEvent(QMouseEvent *e)
Definition: QGLMap.cpp:184
void ChangeCenter(double x, double y)
Definition: QGLMap.cpp:142
void UnloadTexture()
Definition: tile.cpp:176
void SetView(double x, double y, double radius, double scale)
Definition: tile_view.cpp:63
void SetTiles(TileSet *tiles)
Definition: QGLMap.cpp:93
const TileCache * Cache()
Definition: tile_view.h:47
bool LoadTexture()
Definition: tile.cpp:139
void MousePan(int x, int y)
Definition: QGLMap.cpp:211
tf::Point m_scene_center
Definition: QGLMap.h:103
QGLMap(QWidget *parent=0)
Definition: QGLMap.cpp:37


multires_image
Author(s): Marc Alban
autogenerated on Fri Mar 19 2021 02:44:42