tile_cache.h
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 #ifndef MULTIRES_IMAGE_TILE_CACHE_H_
00031 #define MULTIRES_IMAGE_TILE_CACHE_H_
00032 
00033 // C++ standard libraries
00034 #include <vector>
00035 #include <stack>
00036 #include <queue>
00037 #include <map>
00038 
00039 // QT libraries
00040 #include <QObject>
00041 #include <QThread>
00042 #include <QMutex>
00043 #include <QGLWidget>
00044 
00045 #include <tf/transform_datatypes.h>
00046 
00047 #include <multires_image/tile_set.h>
00048 #include <multires_image/tile.h>
00049 
00050 namespace multires_image
00051 {
00052   class TileCache : public QObject
00053   {
00054   Q_OBJECT
00055 
00056   public:
00057     TileCache(TileSet* tileSet, QGLWidget* widget);
00058     ~TileCache(void);
00059 
00060     void Load(Tile* tile);
00061     void Precache(const tf::Point& position);
00062     void Precache(double x, double y);
00063 
00064     void SetCurrentLayer(int layer) { m_currentLayer = layer; }
00065 
00066     void Exit();
00067 
00068   public Q_SLOTS:
00069     void LoadTextureSlot(Tile*);
00070     void DeleteTextureSlot(Tile*);
00071 
00072   Q_SIGNALS:
00073     void SignalLoadTexture(Tile*);
00074     void SignalDeleteTexture(Tile*);
00075     void SignalMemorySize(int64_t);
00076 
00077   private:
00078     TileSet*                  m_tileSet;
00079     QGLWidget*                m_widget;
00080     int32_t                   m_currentLayer;
00081     tf::Point                 m_currentPosition;
00082     bool                      m_exit;
00083     int64_t                   m_memorySize;
00084 
00085     std::vector<std::queue<Tile*> > m_precacheRequests;
00086     std::stack<Tile*>               m_renderRequests;
00087     std::map<int64_t, Tile*>        m_textureLoaded;
00088     std::map<int64_t, Tile*>        m_renderRequestSet;
00089     std::map<int64_t, Tile*>        m_precacheRequestSet;
00090 
00091     void PrecacheLayer(int layer, const tf::Point& position, int size);
00092     void LoadTexture(Tile* tile);
00093     void UnloadTexture(Tile* tile);
00094 
00095     class CacheThread : public QThread
00096     {
00097     public:
00098       explicit CacheThread(TileCache* parent) : p(parent) {}
00099       virtual void run();
00100 
00101     private:
00102       TileCache* p;
00103     };
00104     friend class CacheThread;
00105 
00106     class FreeThread : public QThread
00107     {
00108     public:
00109       explicit FreeThread(TileCache* parent) : p(parent) {}
00110       virtual void run();
00111 
00112     private:
00113       TileCache* p;
00114     };
00115     friend class FreeThread;
00116 
00117     CacheThread m_cacheThread;
00118     FreeThread  m_freeThread;
00119 
00120     QMutex      m_renderRequestsLock;
00121     QMutex      m_renderRequestSetLock;
00122     QMutex      m_precacheRequestsLock;
00123     QMutex      m_precacheRequestSetLock;
00124     QMutex      m_textureLoadedLock;
00125   };
00126 }
00127 
00128 #endif  // MULTIRES_IMAGE_TILE_CACHE_H_


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