tile_view.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 
31 
32 // C++ standard libraries
33 #include <cmath>
34 #include <iostream>
35 
36 namespace multires_image
37 {
38  TileView::TileView(TileSet* tiles, QGLWidget* widget) :
39  m_tiles(tiles),
40  m_cache(tiles, widget),
41  m_currentLayer(tiles->LayerCount() - 1),
42  m_startRow(0),
43  m_startColumn(0),
44  m_endRow(0),
45  m_endColumn(0)
46  {
47  double top, left, bottom, right;
48  tiles->GeoReference().GetCoordinate(0, 0, left, top);
49  tiles->GeoReference().GetCoordinate(tiles->GeoReference().Width(),tiles->GeoReference().Height(), right, bottom);
50 
51  double scale_x = std::abs(right - left) / tiles->GeoReference().Width();
52  double scale_y = std::abs(top - bottom) / tiles->GeoReference().Height();
53 
54  min_scale_ = scale_x;
55  if (scale_y > scale_x)
56  min_scale_ = scale_y;
57  }
58 
60  {
61  }
62 
63  void TileView::SetView(double x, double y, double radius, double scale)
64  {
65  int layer = 0;
66  while (min_scale_ * std::pow(2.0, layer + 1) < scale) layer++;
67 
68  if (layer >= m_tiles->LayerCount())
69  layer = m_tiles->LayerCount() - 1;
70 
71  if (layer != m_currentLayer)
72  {
73  m_currentLayer = layer;
74  m_cache.SetCurrentLayer(layer);
75  }
76 
77  int row, column;
78  m_tiles->GetLayer(m_currentLayer)->GetTileIndex(x, y, row, column);
79 
80  m_startRow = row - 2;
81  if (m_startRow < 0)
82  m_startRow = 0;
85 
86  m_endRow = row + 2;
87  if (m_endRow < 0)
88  m_endRow = 0;
91 
92  m_startColumn = column - 2;
93  if (m_startColumn < 0)
94  m_startColumn = 0;
97 
98  m_endColumn = column + 2;
99  if (m_endColumn < 0)
100  m_endColumn = 0;
103 
104  m_cache.Precache(x, y);
105  }
106 
108  {
109  glEnable(GL_TEXTURE_2D);
110 
111  glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
112 
113  // Always draw bottom layers
114  if (m_currentLayer != m_tiles->LayerCount() - 1)
115  {
116  TileSetLayer* baseLayer = m_tiles->GetLayer(m_tiles->LayerCount() - 1);
117  Tile* tile = baseLayer->GetTile(0, 0);
118  if (tile->TextureLoaded())
119  {
120  tile->Draw();
121  }
122  else
123  {
124  m_cache.Load(tile);
125  }
126  }
127 
128  if (m_tiles->LayerCount() >= 2 && m_currentLayer != m_tiles->LayerCount() - 2)
129  {
130  TileSetLayer* baseLayer = m_tiles->GetLayer(m_tiles->LayerCount() - 2);
131  for (int c = 0; c < baseLayer->ColumnCount(); c++)
132  {
133  for (int r = 0; r < baseLayer->RowCount(); r++)
134  {
135  Tile* tile = baseLayer->GetTile(c, r);
136  if (tile->TextureLoaded())
137  {
138  tile->Draw();
139  }
140  else
141  {
142  m_cache.Load(tile);
143  }
144  }
145  }
146  }
147 
149  if (m_endColumn < layer->ColumnCount() && m_endRow < layer->RowCount())
150  {
151  for (int c = m_startColumn; c <= m_endColumn; c++)
152  {
153  for (int r = m_startRow; r <= m_endRow; r++)
154  {
155  Tile* tile = layer->GetTile(c, r);
156  if (tile->TextureLoaded())
157  {
158  tile->Draw();
159  }
160  else
161  {
162  m_cache.Load(tile);
163  }
164  }
165  }
166  }
167 
168  glDisable(GL_TEXTURE_2D);
169  }
170 }
171 
void GetCoordinate(int x_pixel, int y_pixel, double &x_coordinate, double &y_coordinate) const
f
swri_transform_util::GeoReference & GeoReference()
Definition: tile_set.h:59
void SetCurrentLayer(int layer)
Definition: tile_cache.h:64
TileView(TileSet *tiles, QGLWidget *widget)
Definition: tile_view.cpp:38
unsigned int Height() const
unsigned int Width() const
void Precache(const tf::Point &position)
Definition: tile_cache.cpp:125
void SetView(double x, double y, double radius, double scale)
Definition: tile_view.cpp:63
TileSetLayer * GetLayer(int layer)
Definition: tile_set.h:61
Tile * GetTile(int column, int row)
void GetTileIndex(const tf::Point &position, int &row, int &column) const
void Load(Tile *tile)
Definition: tile_cache.cpp:97
bool TextureLoaded() const
Definition: tile.h:63


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