21 #ifndef EMODNET_QMGC_ZOOM_SCHEDULER_H 22 #define EMODNET_QMGC_ZOOM_SCHEDULER_H 45 virtual void initSchedule(
const ctb::TileBounds& zoomBounds) = 0 ;
48 void initRootSchedule() {
50 m_tilesToProcess.clear();
51 m_tilesToProcess.emplace_back(ctb::TilePoint(0,0));
52 m_tilesToProcess.emplace_back(ctb::TilePoint(1,0));
58 return ctb::TilePoint(0,0) ;
59 ctb::TilePoint tp = m_tilesToProcess[m_index] ;
65 int numTiles() {
return m_tilesToProcess.size() ; }
71 bool finished() {
return m_index >= m_tilesToProcess.size() ; }
75 std::vector<ctb::TilePoint> m_tilesToProcess ;
91 ZoomTilesScheduler( std::shared_ptr<ZoomTilesSchedulerStrategy> scheduler ) { m_scheduler = scheduler ;}
94 void setScheduler(std::shared_ptr<ZoomTilesSchedulerStrategy> scheduler ) { m_scheduler = scheduler ;}
97 void initSchedule(
const ctb::TileBounds& zoomBounds) { m_scheduler->initSchedule(zoomBounds) ; }
99 void initRootSchedule() { m_scheduler->initRootSchedule(); }
101 ctb::TilePoint
getNextTile() {
return m_scheduler->getNextTile(); }
102 bool finished() {
return m_scheduler->finished(); }
103 int numTiles() {
return m_scheduler->numTiles(); }
104 int currentIndex() {
return m_scheduler->currentIndex(); }
107 std::shared_ptr<ZoomTilesSchedulerStrategy> m_scheduler ;
125 m_tilesToProcess.clear() ;
126 for (
int ty = zoomBounds.getMinY(); ty <= zoomBounds.getMaxY(); ty++) {
127 for (
int tx = zoomBounds.getMinX(); tx <= zoomBounds.getMaxX(); tx++) {
128 m_tilesToProcess.push_back(ctb::TilePoint(tx, ty));
149 m_tilesToProcess.clear() ;
150 for (
int tx = zoomBounds.getMinX(); tx <= zoomBounds.getMaxX(); tx++) {
151 for (
int ty = zoomBounds.getMinY(); ty <= zoomBounds.getMaxY(); ty++) {
152 m_tilesToProcess.push_back(ctb::TilePoint(tx, ty));
175 m_tilesToProcess.clear() ;
176 for (
int ty = zoomBounds.getMinY(); ty <= zoomBounds.getMaxY(); ty++) {
178 for (
int tx = zoomBounds.getMinX(); tx <= zoomBounds.getMaxX(); tx+=2) {
179 m_tilesToProcess.push_back(ctb::TilePoint(tx, ty));
183 for (
int tx = zoomBounds.getMinX()+1; tx <= zoomBounds.getMaxX(); tx+=2) {
184 m_tilesToProcess.push_back(ctb::TilePoint(tx, ty));
189 for (
int ty = zoomBounds.getMinY(); ty <= zoomBounds.getMaxY(); ty++) {
191 for (
int tx = zoomBounds.getMinX()+1; tx <= zoomBounds.getMaxX(); tx+=2) {
192 m_tilesToProcess.push_back(ctb::TilePoint(tx, ty));
196 for (
int tx = zoomBounds.getMinX(); tx <= zoomBounds.getMaxX(); tx+=2) {
197 m_tilesToProcess.push_back(ctb::TilePoint(tx, ty));
214 typedef std::vector<std::vector<bool>> VisitedMatrix ;
220 m_tilesToProcess.clear() ;
222 unsigned int rows = zoomBounds.getMaxY()-zoomBounds.getMinY()+1 ;
223 unsigned int cols = zoomBounds.getMaxX()-zoomBounds.getMinX()+1 ;
225 VisitedMatrix visited;
226 visited.resize(rows);
228 for(
int i=0; i < rows; i++)
230 visited[i].resize(cols) ;
231 for(
int j=0; j < cols; j++)
232 visited[i][j] =
false ;
235 unsigned int midY = zoomBounds.getMinY() + ( (zoomBounds.getMaxY()-zoomBounds.getMinY())/2 ) ;
236 unsigned int midX = zoomBounds.getMinX() + ( (zoomBounds.getMaxX()-zoomBounds.getMinX())/2 ) ;
238 recursiveAddTiles( midX, midY, zoomBounds, visited ) ;
242 void recursiveAddTiles(
const int& tx,
const int& ty,
const ctb::TileBounds& zoomBounds, VisitedMatrix& visited ) {
243 if ( inBounds( tx, ty, zoomBounds ) ) {
244 m_tilesToProcess.push_back(ctb::TilePoint(tx, ty)) ;
246 int txx = tx-zoomBounds.getMinX() ;
247 int tyy = ty-zoomBounds.getMinY() ;
249 visited[tyy][txx] = true ;
251 if ( inBounds(tx+1, ty, zoomBounds) && !visited[tyy][txx+1] )
252 recursiveAddTiles(tx+1, ty, zoomBounds, visited ) ;
254 if ( inBounds(tx-1, ty, zoomBounds) && !visited[tyy][txx-1] )
255 recursiveAddTiles(tx-1, ty, zoomBounds, visited ) ;
257 if ( inBounds(tx, ty-1, zoomBounds) && !visited[tyy-1][txx] )
258 recursiveAddTiles(tx, ty-1, zoomBounds, visited ) ;
260 if ( inBounds(tx, ty+1, zoomBounds) && !visited[tyy+1][txx] )
261 recursiveAddTiles(tx, ty+1, zoomBounds, visited ) ;
265 bool inBounds(
const int& tx,
const int& ty,
const ctb::TileBounds& zoomBounds )
const {
266 return tx <= zoomBounds.getMaxX() && tx >= zoomBounds.getMinX() &&
267 ty <= zoomBounds.getMaxY() && ty >= zoomBounds.getMinY() ;
283 typedef std::vector<std::vector<bool>> VisitedMatrix ;
289 m_tilesToProcess.clear() ;
292 unsigned int rows = zoomBounds.getMaxY()-zoomBounds.getMinY()+1 ;
293 unsigned int cols = zoomBounds.getMaxX()-zoomBounds.getMinX()+1 ;
295 VisitedMatrix visited;
296 visited.resize(rows);
298 for(
int i=0; i < rows; i++)
300 visited[i].resize(cols) ;
301 for(
int j=0; j < cols; j++)
302 visited[i][j] =
false ;
306 unsigned int midY = zoomBounds.getMinY() + ( (zoomBounds.getMaxY()-zoomBounds.getMinY())/2 ) ;
307 unsigned int midX = zoomBounds.getMinX() + ( (zoomBounds.getMaxX()-zoomBounds.getMinX())/2 ) ;
308 ctb::TilePoint midPt( midX, midY ) ;
311 std::queue<ctb::TilePoint> queue ;
314 while (!queue.empty()) {
316 ctb::TilePoint tp = queue.front() ;
321 int txx = tx-zoomBounds.getMinX() ;
322 int tyy = ty-zoomBounds.getMinY() ;
324 if (!visited[tyy][txx]) {
326 m_tilesToProcess.push_back(tp) ;
327 visited[tyy][txx] = true ;
330 if ( inBounds(tx+1, ty, zoomBounds) && !visited[tyy][txx+1] )
331 queue.push(ctb::TilePoint(tx+1, ty)) ;
333 if ( inBounds(tx-1, ty, zoomBounds) && !visited[tyy][txx-1] )
334 queue.push(ctb::TilePoint(tx-1, ty)) ;
336 if ( inBounds(tx, ty-1, zoomBounds) && !visited[tyy-1][txx] )
337 queue.push(ctb::TilePoint(tx, ty-1)) ;
339 if ( inBounds(tx, ty+1, zoomBounds) && !visited[tyy+1][txx] )
340 queue.push(ctb::TilePoint(tx, ty+1)) ;
346 bool inBounds(
const int& tx,
const int& ty,
const ctb::TileBounds& zoomBounds )
const {
347 return tx <= zoomBounds.getMaxX() && tx >= zoomBounds.getMinX() &&
348 ty <= zoomBounds.getMaxY() && ty >= zoomBounds.getMinY() ;
352 #endif //EMODNET_QMGC_ZOOM_SCHEDULER_H void initSchedule(const ctb::TileBounds &zoomBounds)
Replication of the ZoomTilesSchedulerBase interphase.
Definition: zoom_tiles_scheduler.h:97
Row-wise scheduler.
Definition: zoom_tiles_scheduler.h:118
Chessboard scheduler.
Definition: zoom_tiles_scheduler.h:168
void initSchedule(const ctb::TileBounds &zoomBounds)
Initialize the schedule given the zoom bounds.
Definition: zoom_tiles_scheduler.h:217
Context class: Allows to change the algorithm at runtime.
Definition: zoom_tiles_scheduler.h:84
void initSchedule(const ctb::TileBounds &zoomBounds)
Initialize the schedule given the zoom bounds.
Definition: zoom_tiles_scheduler.h:286
ZoomTilesScheduler()
Default constructor (remember to set the strategy with setScheduler!)
Definition: zoom_tiles_scheduler.h:88
int numTiles()
Number of tiles in the schedule.
Definition: zoom_tiles_scheduler.h:65
An instance of a ZoomTilesSchedulerStrategy rules the desired order at which tiles in a given zoom sh...
Definition: zoom_tiles_scheduler.h:40
Recursive scheduler.
Definition: zoom_tiles_scheduler.h:280
Recursive scheduler.
Definition: zoom_tiles_scheduler.h:211
Column-wise scheduler.
Definition: zoom_tiles_scheduler.h:142
bool finished()
Marks if the current schedule is finished.
Definition: zoom_tiles_scheduler.h:71
void initSchedule(const ctb::TileBounds &zoomBounds)
Initialize the schedule given the zoom bounds.
Definition: zoom_tiles_scheduler.h:172
void initSchedule(const ctb::TileBounds &zoomBounds)
Initialize the schedule given the zoom bounds.
Definition: zoom_tiles_scheduler.h:146
void setScheduler(std::shared_ptr< ZoomTilesSchedulerStrategy > scheduler)
Allows to change the scheduler algorithm at runtime.
Definition: zoom_tiles_scheduler.h:94
ZoomTilesScheduler(std::shared_ptr< ZoomTilesSchedulerStrategy > scheduler)
Constructor from an scheduler strategy.
Definition: zoom_tiles_scheduler.h:91
ctb::TilePoint getNextTile()
Get the next tile to process.
Definition: zoom_tiles_scheduler.h:56
void initSchedule(const ctb::TileBounds &zoomBounds)
Initialize the schedule given the zoom bounds.
Definition: zoom_tiles_scheduler.h:122
int currentIndex()
The current index in the schedule.
Definition: zoom_tiles_scheduler.h:68