multires_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 #include <ros/ros.h>
38 
39 namespace mapviz_plugins
40 {
42  m_tiles(tiles),
43  m_cache(tiles, widget),
44  m_currentLayer(tiles->LayerCount() - 1),
45  m_startRow(0),
46  m_startColumn(0),
47  m_endRow(0),
48  m_endColumn(0)
49  {
50  double top, left, bottom, right;
51 
52  tiles->GeoReference().GetCoordinate(0, 0, left, top);
53 
54  tiles->GeoReference().GetCoordinate(
55  tiles->GeoReference().Width(),
56  tiles->GeoReference().Height(),
57  right,
58  bottom);
59 
60  double width_m, height_m;
61  if (tiles->GeoReference().Projection() == "wgs84")
62  {
63  width_m = swri_transform_util::GreatCircleDistance(top, left, top, right);
64  height_m = swri_transform_util::GreatCircleDistance(top, left, bottom, left);
65  }
66  else
67  {
68  width_m = std::fabs(right - left);
69  height_m = std::fabs(top - bottom);
70  }
71 
72  double scale_x = width_m / tiles->GeoReference().Width();
73  double scale_y = height_m / tiles->GeoReference().Height();
74 
75  min_scale_ = scale_x;
76  if (scale_y > scale_x)
77  min_scale_ = scale_y;
78  }
79 
81  {
82  }
83 
84  void MultiresView::SetView(double x, double y, double radius, double scale)
85  {
86  int layer = 0;
87  while (min_scale_ * std::pow(2.0, layer + 1) < scale) layer++;
88 
89  if (layer >= m_tiles->LayerCount())
90  layer = m_tiles->LayerCount() - 1;
91 
92  if (layer != m_currentLayer)
93  {
94  m_currentLayer = layer;
95  m_cache.SetCurrentLayer(layer);
96  }
97 
98  int row, column;
99  m_tiles->GetLayer(m_currentLayer)->GetTileIndex(x, y, row, column);
100 
101  int size = 3;
102 
103  m_startRow = row - size;
104  if (m_startRow < 0)
105  m_startRow = 0;
108 
109  m_endRow = row + size;
110  if (m_endRow < 0)
111  m_endRow = 0;
114 
115  m_startColumn = column - size;
116  if (m_startColumn < 0)
117  m_startColumn = 0;
120 
121  m_endColumn = column + size;
122  if (m_endColumn < 0)
123  m_endColumn = 0;
126 
127  m_cache.Precache(x, y);
128  }
129 
131  {
132  glEnable(GL_TEXTURE_2D);
133 
134  glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
135 
136  // Always draw bottom layers
137 
139  multires_image::Tile* tile = baseLayer->GetTile(0, 0);
140  if (tile->TextureLoaded())
141  {
142  tile->Draw();
143  }
144  else
145  {
146  m_cache.Load(tile);
147  }
148 
149  if(m_tiles->LayerCount() >= 2)
150  {
151  baseLayer = m_tiles->GetLayer(m_tiles->LayerCount() - 2);
152  for (int c = 0; c < baseLayer->ColumnCount(); c++)
153  {
154  for (int r = 0; r < baseLayer->RowCount(); r++)
155  {
156  multires_image::Tile* tile = baseLayer->GetTile(c, r);
157  if (tile->TextureLoaded())
158  {
159  tile->Draw();
160  }
161  else
162  {
163  m_cache.Load(tile);
164  }
165  }
166  }
167  }
168 
169  if (m_tiles->LayerCount() >= 2 && m_currentLayer < m_tiles->LayerCount() - 2)
170  {
172  if (m_endColumn < layer->ColumnCount() && m_endRow < layer->RowCount())
173  {
174  for (int c = m_startColumn; c <= m_endColumn; c++)
175  {
176  for (int r = m_startRow; r <= m_endRow; r++)
177  {
178  multires_image::Tile* tile = layer->GetTile(c, r);
179  if (tile->TextureLoaded())
180  {
181  tile->Draw();
182  }
183  else
184  {
185  m_cache.Load(tile);
186  }
187  }
188  }
189  }
190  }
191 
192  glDisable(GL_TEXTURE_2D);
193  }
194 }
mapviz_plugins::MultiresView::Draw
void Draw()
Definition: multires_view.cpp:130
mapviz_plugins::MultiresView::m_tiles
multires_image::TileSet * m_tiles
Definition: multires_view.h:56
multires_image::TileSetLayer::GetTileIndex
void GetTileIndex(const tf::Point &position, int &row, int &column) const
Definition: tile_set_layer.cpp:144
mapviz_plugins::MultiresView::m_startRow
int m_startRow
Definition: multires_view.h:59
multires_image::TileSetLayer
Definition: tile_set_layer.h:45
mapviz_plugins::MultiresView::m_currentLayer
int m_currentLayer
Definition: multires_view.h:58
ros.h
multires_image::Tile
Definition: tile.h:50
multires_image::TileSet::GetLayer
TileSetLayer * GetLayer(int layer)
Definition: tile_set.h:61
multires_image::TileCache::Precache
void Precache(const tf::Point &position)
Definition: tile_cache.cpp:125
multires_image::TileSet::GeoReference
swri_transform_util::GeoReference & GeoReference()
Definition: tile_set.h:59
multires_image::TileSetLayer::GetTile
Tile * GetTile(int column, int row)
Definition: tile_set_layer.h:58
mapviz_plugins::MultiresView::m_endRow
int m_endRow
Definition: multires_view.h:61
mapviz_plugins::MultiresView::min_scale_
double min_scale_
Definition: multires_view.h:64
f
f
mapviz_plugins::MultiresView::m_endColumn
int m_endColumn
Definition: multires_view.h:62
multires_image::TileSet::LayerCount
int LayerCount()
Definition: tile_set.h:56
swri_transform_util::GreatCircleDistance
double GreatCircleDistance(const tf::Vector3 &src, const tf::Vector3 &dst)
mapviz_plugins::MultiresView::MultiresView
MultiresView(multires_image::TileSet *tiles, QGLWidget *widget)
Definition: multires_view.cpp:41
transform_util.h
swri_transform_util::GeoReference::GetCoordinate
void GetCoordinate(int x_pixel, int y_pixel, double &x_coordinate, double &y_coordinate) const
mapviz_plugins::MultiresView::m_cache
multires_image::TileCache m_cache
Definition: multires_view.h:57
mapviz_plugins::MultiresView::SetView
void SetView(double x, double y, double radius, double scale)
Definition: multires_view.cpp:84
swri_transform_util::GeoReference::Height
unsigned int Height() const
multires_image::TileCache::SetCurrentLayer
void SetCurrentLayer(int layer)
Definition: tile_cache.h:64
mapviz_plugins::MultiresView::~MultiresView
~MultiresView(void)
Definition: multires_view.cpp:80
swri_transform_util::GeoReference::Projection
std::string Projection() const
swri_transform_util::GeoReference::Width
unsigned int Width() const
multires_image::TileSetLayer::RowCount
int RowCount()
Definition: tile_set_layer.h:68
multires_image::TileCache::Load
void Load(Tile *tile)
Definition: tile_cache.cpp:97
multires_image::TileSet
Definition: tile_set.h:43
mapviz_plugins
Definition: multires_image_plugin.h:54
multires_image::TileSetLayer::ColumnCount
int ColumnCount()
Definition: tile_set_layer.h:69
multires_view.h
multires_image::Tile::TextureLoaded
bool TextureLoaded() const
Definition: tile.h:63
mapviz_plugins::MultiresView::m_startColumn
int m_startColumn
Definition: multires_view.h:60
multires_image::Tile::Draw
void Draw()
Definition: tile.cpp:191


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