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/multires_view.h>
00031
00032
00033 #include <cmath>
00034 #include <iostream>
00035
00036 #include <ros/ros.h>
00037
00038 namespace mapviz_plugins
00039 {
00040 MultiresView::MultiresView(multires_image::TileSet* tiles, QGLWidget* widget) :
00041 m_tiles(tiles),
00042 m_cache(tiles, widget),
00043 m_currentLayer(tiles->LayerCount() - 1),
00044 m_startRow(0),
00045 m_startColumn(0),
00046 m_endRow(0),
00047 m_endColumn(0)
00048 {
00049 double top, left, bottom, right;
00050 tiles->GeoReference().GetCoordinate(0, 0, left, top);
00051
00052 tiles->GeoReference().GetCoordinate(
00053 tiles->GeoReference().Width(),
00054 tiles->GeoReference().Height(),
00055 right,
00056 bottom);
00057
00058 double scale_x = std::fabs(right - left) / tiles->GeoReference().Width();
00059 double scale_y = std::fabs(top - bottom) / tiles->GeoReference().Height();
00060
00061 min_scale_ = scale_x;
00062 if (scale_y > scale_x)
00063 min_scale_ = scale_y;
00064 }
00065
00066 MultiresView::~MultiresView(void)
00067 {
00068 }
00069
00070 void MultiresView::SetView(double x, double y, double radius, double scale)
00071 {
00072 int layer = 0;
00073 while (min_scale_ * std::pow(2.0, layer + 1) < scale) layer++;
00074
00075 if (layer >= m_tiles->LayerCount())
00076 layer = m_tiles->LayerCount() - 1;
00077
00078 if (layer != m_currentLayer)
00079 {
00080 m_currentLayer = layer;
00081 m_cache.SetCurrentLayer(layer);
00082 }
00083
00084 int row, column;
00085 m_tiles->GetLayer(m_currentLayer)->GetTileIndex(x, y, row, column);
00086
00087 int size = 3;
00088
00089 m_startRow = row - size;
00090 if (m_startRow < 0)
00091 m_startRow = 0;
00092 if (m_startRow >= m_tiles->GetLayer(m_currentLayer)->RowCount())
00093 m_startRow = m_tiles->GetLayer(m_currentLayer)->RowCount() - 1;
00094
00095 m_endRow = row + size;
00096 if (m_endRow < 0)
00097 m_endRow = 0;
00098 if (m_endRow >= m_tiles->GetLayer(m_currentLayer)->RowCount())
00099 m_endRow = m_tiles->GetLayer(m_currentLayer)->RowCount() - 1;
00100
00101 m_startColumn = column - size;
00102 if (m_startColumn < 0)
00103 m_startColumn = 0;
00104 if (m_startColumn >= m_tiles->GetLayer(m_currentLayer)->ColumnCount())
00105 m_startColumn = m_tiles->GetLayer(m_currentLayer)->ColumnCount() - 1;
00106
00107 m_endColumn = column + size;
00108 if (m_endColumn < 0)
00109 m_endColumn = 0;
00110 if (m_endColumn >= m_tiles->GetLayer(m_currentLayer)->ColumnCount())
00111 m_endColumn = m_tiles->GetLayer(m_currentLayer)->ColumnCount() - 1;
00112
00113 m_cache.Precache(x, y);
00114 }
00115
00116 void MultiresView::Draw()
00117 {
00118 glEnable(GL_TEXTURE_2D);
00119
00120 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00121
00122
00123
00124 multires_image::TileSetLayer* baseLayer = m_tiles->GetLayer(m_tiles->LayerCount() - 1);
00125 multires_image::Tile* tile = baseLayer->GetTile(0, 0);
00126 if (tile->TextureLoaded())
00127 {
00128 tile->Draw();
00129 }
00130 else
00131 {
00132 m_cache.Load(tile);
00133 }
00134
00135 if(m_tiles->LayerCount() >= 2)
00136 {
00137 baseLayer = m_tiles->GetLayer(m_tiles->LayerCount() - 2);
00138 for (int c = 0; c < baseLayer->ColumnCount(); c++)
00139 {
00140 for (int r = 0; r < baseLayer->RowCount(); r++)
00141 {
00142 multires_image::Tile* tile = baseLayer->GetTile(c, r);
00143 if (tile->TextureLoaded())
00144 {
00145 tile->Draw();
00146 }
00147 else
00148 {
00149 m_cache.Load(tile);
00150 }
00151 }
00152 }
00153 }
00154
00155 if (m_tiles->LayerCount() >= 2 && m_currentLayer < m_tiles->LayerCount() - 2)
00156 {
00157 multires_image::TileSetLayer* layer = m_tiles->GetLayer(m_currentLayer);
00158 if (m_endColumn < layer->ColumnCount() && m_endRow < layer->RowCount())
00159 {
00160 for (int c = m_startColumn; c <= m_endColumn; c++)
00161 {
00162 for (int r = m_startRow; r <= m_endRow; r++)
00163 {
00164 multires_image::Tile* tile = layer->GetTile(c, r);
00165 if (tile->TextureLoaded())
00166 {
00167 tile->Draw();
00168 }
00169 else
00170 {
00171 m_cache.Load(tile);
00172 }
00173 }
00174 }
00175 }
00176 }
00177
00178 glDisable(GL_TEXTURE_2D);
00179 }
00180 }