Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <multires_image/tile_view.h>
00031
00032
00033 #include <cmath>
00034 #include <iostream>
00035
00036 namespace multires_image
00037 {
00038 TileView::TileView(TileSet* tiles, QGLWidget* widget) :
00039 m_tiles(tiles),
00040 m_cache(tiles, widget),
00041 m_currentLayer(tiles->LayerCount() - 1),
00042 m_startRow(0),
00043 m_startColumn(0),
00044 m_endRow(0),
00045 m_endColumn(0)
00046 {
00047 double top, left, bottom, right;
00048 tiles->GeoReference().GetCoordinate(0, 0, left, top);
00049 tiles->GeoReference().GetCoordinate(tiles->GeoReference().Width(),tiles->GeoReference().Height(), right, bottom);
00050
00051 double scale_x = std::abs(right - left) / tiles->GeoReference().Width();
00052 double scale_y = std::abs(top - bottom) / tiles->GeoReference().Height();
00053
00054 min_scale_ = scale_x;
00055 if (scale_y > scale_x)
00056 min_scale_ = scale_y;
00057 }
00058
00059 TileView::~TileView(void)
00060 {
00061 }
00062
00063 void TileView::SetView(double x, double y, double radius, double scale)
00064 {
00065 int layer = 0;
00066 while (min_scale_ * std::pow(2.0, layer + 1) < scale) layer++;
00067
00068 if (layer >= m_tiles->LayerCount())
00069 layer = m_tiles->LayerCount() - 1;
00070
00071 if (layer != m_currentLayer)
00072 {
00073 m_currentLayer = layer;
00074 m_cache.SetCurrentLayer(layer);
00075 }
00076
00077 int row, column;
00078 m_tiles->GetLayer(m_currentLayer)->GetTileIndex(x, y, row, column);
00079
00080 m_startRow = row - 2;
00081 if (m_startRow < 0)
00082 m_startRow = 0;
00083 if (m_startRow >= m_tiles->GetLayer(m_currentLayer)->RowCount())
00084 m_startRow = m_tiles->GetLayer(m_currentLayer)->RowCount() - 1;
00085
00086 m_endRow = row + 2;
00087 if (m_endRow < 0)
00088 m_endRow = 0;
00089 if (m_endRow >= m_tiles->GetLayer(m_currentLayer)->RowCount())
00090 m_endRow = m_tiles->GetLayer(m_currentLayer)->RowCount() - 1;
00091
00092 m_startColumn = column - 2;
00093 if (m_startColumn < 0)
00094 m_startColumn = 0;
00095 if (m_startColumn >= m_tiles->GetLayer(m_currentLayer)->ColumnCount())
00096 m_startColumn = m_tiles->GetLayer(m_currentLayer)->ColumnCount() - 1;
00097
00098 m_endColumn = column + 2;
00099 if (m_endColumn < 0)
00100 m_endColumn = 0;
00101 if (m_endColumn >= m_tiles->GetLayer(m_currentLayer)->ColumnCount())
00102 m_endColumn = m_tiles->GetLayer(m_currentLayer)->ColumnCount() - 1;
00103
00104 m_cache.Precache(x, y);
00105 }
00106
00107 void TileView::Draw()
00108 {
00109 glEnable(GL_TEXTURE_2D);
00110
00111 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00112
00113
00114 if (m_currentLayer != m_tiles->LayerCount() - 1)
00115 {
00116 TileSetLayer* baseLayer = m_tiles->GetLayer(m_tiles->LayerCount() - 1);
00117 Tile* tile = baseLayer->GetTile(0, 0);
00118 if (tile->TextureLoaded())
00119 {
00120 tile->Draw();
00121 }
00122 else
00123 {
00124 m_cache.Load(tile);
00125 }
00126 }
00127
00128 if (m_tiles->LayerCount() >= 2 && m_currentLayer != m_tiles->LayerCount() - 2)
00129 {
00130 TileSetLayer* baseLayer = m_tiles->GetLayer(m_tiles->LayerCount() - 2);
00131 for (int c = 0; c < baseLayer->ColumnCount(); c++)
00132 {
00133 for (int r = 0; r < baseLayer->RowCount(); r++)
00134 {
00135 Tile* tile = baseLayer->GetTile(c, r);
00136 if (tile->TextureLoaded())
00137 {
00138 tile->Draw();
00139 }
00140 else
00141 {
00142 m_cache.Load(tile);
00143 }
00144 }
00145 }
00146 }
00147
00148 TileSetLayer* layer = m_tiles->GetLayer(m_currentLayer);
00149 if (m_endColumn < layer->ColumnCount() && m_endRow < layer->RowCount())
00150 {
00151 for (int c = m_startColumn; c <= m_endColumn; c++)
00152 {
00153 for (int r = m_startRow; r <= m_endRow; r++)
00154 {
00155 Tile* tile = layer->GetTile(c, r);
00156 if (tile->TextureLoaded())
00157 {
00158 tile->Draw();
00159 }
00160 else
00161 {
00162 m_cache.Load(tile);
00163 }
00164 }
00165 }
00166 }
00167
00168 glDisable(GL_TEXTURE_2D);
00169 }
00170 }
00171