tile_set.cpp
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2014, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //
00028 // *****************************************************************************
00029 
00030 #include <multires_image/tile_set.h>
00031 
00032 // C++ standard libraries
00033 #include <cmath>
00034 #include <cstdlib>
00035 #include <algorithm>
00036 
00037 // QT libraries
00038 #include <QFile>
00039 #include <QFileInfo>
00040 #include <QDir>
00041 #include <QString>
00042 
00043 namespace multires_image
00044 {
00045   TileSet::TileSet(const std::string& geofile) :
00046     m_geo(geofile),
00047     m_extension("jpg")
00048   {
00049   }
00050 
00051   TileSet::TileSet(const std::string& geofile, const std::string extension) :
00052     m_geo(geofile),
00053     m_extension(extension)
00054   {
00055   }
00056 
00057   TileSet::TileSet(const swri_transform_util::GeoReference& georeference) :
00058     m_geo(georeference),
00059     m_extension("jpg")
00060   {
00061   }
00062 
00063   TileSet::TileSet(const swri_transform_util::GeoReference& georeference,
00064                    const std::string extension) :
00065     m_geo(georeference),
00066     m_extension(extension)
00067   {
00068   }
00069 
00070   TileSet::~TileSet(void)
00071   {
00072     // Free each of the layers.
00073     for (unsigned int i = 0; i < m_layers.size(); i++)
00074     {
00075       delete m_layers[i];
00076     }
00077   }
00078 
00079   bool TileSet::Load()
00080   {
00081     if (!m_geo.Load())
00082     {
00083       return false;
00084     }
00085 
00086     m_cacheDir = m_geo.Path();
00087     m_width = m_geo.Width();
00088     m_height = m_geo.Height();
00089     m_tileSize = m_geo.TileSize();
00090     m_extension = m_geo.Extension();
00091 
00092     float max_dim = std::max(m_width, m_height);
00093     m_layerCount = std::ceil(std::log(max_dim / m_tileSize) / std::log(2.0f)) + 1;
00094     m_layers.reserve(m_layerCount);
00095 
00096     // Check if the cache directory for this image exists.
00097     QDir directory(m_cacheDir.c_str());
00098     if (!directory.exists())
00099     {
00100       return false;
00101     }
00102 
00103     // Load each layer.
00104     for (int i = 0; i < m_layerCount; i++)
00105     {
00106       QString layerNum = QString::number(i);
00107 
00108       // Check if this layer exists in the cache.
00109       QDir layerDir(directory.absolutePath() + "/layer" + layerNum);
00110       if (!layerDir.exists(layerDir.absolutePath()))
00111       {
00112         return false;
00113       }
00114 
00115       // Load the base layer.
00116       m_layers.push_back(new TileSetLayer(m_geo, layerDir.absolutePath().toStdString(), m_tileSize, i));
00117 
00118       if (!m_layers[i]->Load(m_extension))
00119         return false;
00120     }
00121 
00122     return true;
00123   }
00124 }


multires_image
Author(s): Marc Alban
autogenerated on Thu Aug 24 2017 02:46:18