tile_set.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 <cstdlib>
35 #include <algorithm>
36 
37 // QT libraries
38 #include <QFile>
39 #include <QFileInfo>
40 #include <QDir>
41 #include <QString>
42 
43 namespace multires_image
44 {
45  TileSet::TileSet(const std::string& geofile) :
46  m_geo(geofile),
47  m_extension("jpg")
48  {
49  }
50 
51  TileSet::TileSet(const std::string& geofile, const std::string extension) :
52  m_geo(geofile),
53  m_extension(extension)
54  {
55  }
56 
58  m_geo(georeference),
59  m_extension("jpg")
60  {
61  }
62 
64  const std::string extension) :
65  m_geo(georeference),
66  m_extension(extension)
67  {
68  }
69 
71  {
72  // Free each of the layers.
73  for (unsigned int i = 0; i < m_layers.size(); i++)
74  {
75  delete m_layers[i];
76  }
77  }
78 
80  {
81  if (!m_geo.Load())
82  {
83  return false;
84  }
85 
86  m_cacheDir = m_geo.Path();
87  m_width = m_geo.Width();
88  m_height = m_geo.Height();
91 
92  float max_dim = std::max(m_width, m_height);
93  m_layerCount = std::ceil(std::log(max_dim / m_tileSize) / std::log(2.0f)) + 1;
94  m_layers.reserve(m_layerCount);
95 
96  // Check if the cache directory for this image exists.
97  QDir directory(m_cacheDir.c_str());
98  if (!directory.exists())
99  {
100  return false;
101  }
102 
103  // Load each layer.
104  for (int i = 0; i < m_layerCount; i++)
105  {
106  QString layerNum = QString::number(i);
107 
108  // Check if this layer exists in the cache.
109  QDir layerDir(directory.absolutePath() + "/layer" + layerNum);
110  if (!layerDir.exists(layerDir.absolutePath()))
111  {
112  return false;
113  }
114 
115  // Load the base layer.
116  m_layers.push_back(new TileSetLayer(m_geo, layerDir.absolutePath().toStdString(), m_tileSize, i));
117 
118  if (!m_layers[i]->Load(m_extension))
119  return false;
120  }
121 
122  return true;
123  }
124 }
f
std::string m_extension
Definition: tile_set.h:70
TileSet(const std::string &geofile)
Definition: tile_set.cpp:45
std::string Extension() const
std::vector< TileSetLayer * > m_layers
Definition: tile_set.h:74
swri_transform_util::GeoReference m_geo
Definition: tile_set.h:64
std::string m_cacheDir
Definition: tile_set.h:69
unsigned int Height() const
unsigned int TileSize() const
unsigned int Width() const


multires_image
Author(s): Marc Alban
autogenerated on Mon Jun 10 2019 14:02:24