EMODnet Quantized Mesh Generator for Cesium
zoom_tiles_border_vertices_cache.h
1 // Copyright (c) 2018 Coronis Computing S.L. (Spain)
2 // All rights reserved.
3 //
4 // This file is part of EMODnet Quantized Mesh Generator for Cesium.
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <https://www.gnu.org/licenses/>.
18 //
19 // Author: Ricard Campos (ricardcd@gmail.com)
20 
21 #ifndef EMODNET_QMGC_ZOOM_TILES_BORDER_VERTICES_CACHE_H
22 #define EMODNET_QMGC_ZOOM_TILES_BORDER_VERTICES_CACHE_H
23 
24 #include <ctb.hpp>
25 #include <unordered_map>
26 #include <boost/functional/hash.hpp>
27 #include "tile_border_vertices.h"
28 #include "tin_creation/tin_creation_cgal_types.h"
29 #include "borders_data.h"
30 
31 
39 {
40  // --- Private typedefs ---
41  typedef TinCreation::Point_3 Point_3;
42 
43 public:
49  ZoomTilesBorderVerticesCache( const ctb::TileBounds& zoomBounds, const int& tileMaxCoord)
50  : m_mapTileToBorderVertices()
51  , m_zoomBounds(zoomBounds)
52  , m_tileMaxCoord( tileMaxCoord )
53  , m_numProcessedTiles(0)
54  , m_tilesVisited()
55  , m_tilesBeingProcessed()
56  {
57  m_numTiles = (zoomBounds.getMaxY()-zoomBounds.getMinY()+1)*(zoomBounds.getMaxX()-zoomBounds.getMinX()+1) ;
58  }
59 
64  : m_mapTileToBorderVertices()
65  , m_zoomBounds()
66  , m_tileMaxCoord(0)
67  , m_numProcessedTiles(0)
68  , m_numTiles(0)
69  , m_tilesVisited() {}
70 
80  bool getConstrainedBorderVerticesForTile(const int& tileX, const int& tileY, BordersData& bd);
81 
93  bool setConstrainedBorderVerticesForTile( const int& tileX, const int& tileY,
94  const std::vector<Point_3>& easternVerticesToPreserve,
95  const std::vector<Point_3>& westernVerticesToPreserve,
96  const std::vector<Point_3>& northernVerticesToPreserve,
97  const std::vector<Point_3>& southernVerticesToPreserve ) ;
98 
104  int numCacheEntries() { return m_mapTileToBorderVertices.size(); }
105 
106  bool isTileVisited( const int& tileX, const int& tileY ) {
107  std::pair<int,int> tileInd = std::make_pair( tileX, tileY ) ;
108  return isTileVisited(tileInd) ;
109  }
110 
118  bool isTileVisited( const std::pair<int, int>& tileInd ) {
119  if (m_tilesVisited.count(tileInd) == 0)
120  return false;
121  else
122  return m_tilesVisited[tileInd];
123  }
124 
133  bool isTileBeingProcessed( const int& tileX, const int& tileY ) {
134  std::pair<int,int> tileInd = std::make_pair( tileX, tileY ) ;
135  return isTileBeingProcessed(tileInd) ;
136  }
137 
145  bool isTileBeingProcessed( const std::pair<int,int>& tileInd ) {
146  if (m_tilesBeingProcessed.count(tileInd) == 0)
147  return false;
148  else
149  return m_tilesBeingProcessed[tileInd] ;
150  }
151 
158  bool canTileStartProcessing( const int& tileX, const int& tileY ) ;
159 
163  bool allTilesProcessed() const { return m_numProcessedTiles >= m_numTiles ; }
164 
168  int getNumProcessed() const { return m_numProcessedTiles ; }
169 
173  int getNumTiles() const { return m_numTiles ; }
174 
175 private:
176  // --- Attributes ---
177  ctb::TileBounds m_zoomBounds ;
178  int m_tileMaxCoord ;
179  int m_numTiles ;
180  int m_numProcessedTiles ;
181  std::unordered_map<std::pair<int,int>, TileBorderVertices, boost::hash<std::pair<int, int>>> m_mapTileToBorderVertices;
182  std::unordered_map<std::pair<int,int>, bool, boost::hash<std::pair<int, int>>> m_tilesVisited;
183  std::unordered_map<std::pair<int,int>, bool, boost::hash<std::pair<int, int>>> m_tilesBeingProcessed;
184 
186  bool isTileInBounds( const std::pair<int, int>& tileInd ) const {
187  return isTileInBounds(tileInd.first, tileInd.second);
188  }
189 
191  bool isTileInBounds( const int& tileX, const int& tileY ) const {
192  return (tileX >= m_zoomBounds.getMinX() && tileX <= m_zoomBounds.getMaxX() &&
193  tileY >= m_zoomBounds.getMinY() && tileY <= m_zoomBounds.getMaxY());
194  }
195 };
196 
197 #endif //EMODNET_QMGC_ZOOM_TILES_BORDER_VERTICES_CACHE_H
ZoomTilesBorderVerticesCache(const ctb::TileBounds &zoomBounds, const int &tileMaxCoord)
Definition: zoom_tiles_border_vertices_cache.h:49
Structure storing the data for the borders of a tile. This includes the 4 east-west-north-south borde...
Definition: borders_data.h:30
bool allTilesProcessed() const
Checks if all the tiles in the zoom have been processed.
Definition: zoom_tiles_border_vertices_cache.h:163
int getNumTiles() const
Gets the total amount of tiles to be processed in the zoom.
Definition: zoom_tiles_border_vertices_cache.h:173
bool isTileBeingProcessed(const int &tileX, const int &tileY)
Checks if a tile is being processed.
Definition: zoom_tiles_border_vertices_cache.h:133
bool getConstrainedBorderVerticesForTile(const int &tileX, const int &tileY, BordersData &bd)
Definition: zoom_tiles_border_vertices_cache.cpp:26
Stores the vertices on the borders of a tile.
Definition: tile_border_vertices.h:53
Cache to store/reuse the vertices at the borders for tiles that have been already constructed for a g...
Definition: zoom_tiles_border_vertices_cache.h:38
bool isTileVisited(const std::pair< int, int > &tileInd)
Checks if a tile is visited.
Definition: zoom_tiles_border_vertices_cache.h:118
bool setConstrainedBorderVerticesForTile(const int &tileX, const int &tileY, const std::vector< Point_3 > &easternVerticesToPreserve, const std::vector< Point_3 > &westernVerticesToPreserve, const std::vector< Point_3 > &northernVerticesToPreserve, const std::vector< Point_3 > &southernVerticesToPreserve)
Definition: zoom_tiles_border_vertices_cache.cpp:171
bool canTileStartProcessing(const int &tileX, const int &tileY)
Checks if a tile can start processing.
Definition: zoom_tiles_border_vertices_cache.cpp:236
bool isTileBeingProcessed(const std::pair< int, int > &tileInd)
Checks if a tile is being processed.
Definition: zoom_tiles_border_vertices_cache.h:145
int numCacheEntries()
Definition: zoom_tiles_border_vertices_cache.h:104
int getNumProcessed() const
Gets the number of processed tiles.
Definition: zoom_tiles_border_vertices_cache.h:168
ZoomTilesBorderVerticesCache()
Definition: zoom_tiles_border_vertices_cache.h:63