Stellarium 0.15.2
StelToastGrid.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2010 Guillaume Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19 
20 #ifndef STELTOASTGRID_HPP
21 #define STELTOASTGRID_HPP
22 
23 #include <QVector>
24 #include "VecMath.hpp"
25 
27 inline int pow2(int x) {return 1 << x;}
28 
34 class ToastGrid
35 {
36 public:
37  ToastGrid(int maxLevel);
44  QVector<Vec3d> getVertexArray(int level, int x, int y, int resolution) const;
51  QVector<Vec2f> getTextureArray(int level, int x, int y, int resolution) const;
57  QVector<unsigned short> getTrianglesIndex(int level, int x, int y, int resolution) const;
62  QVector<Vec3d> getPolygon(int level, int x, int y) const;
64  int getMaxLevel() const {return maxLevel;}
65 
66 private:
68  const Vec3d& at(int x, int y) const {return grid[y * size + x];}
70  Vec3d& at(int x, int y) {return grid[y * size + x];}
72  const Vec3d& at(int level, int x, int y) const
73  {int scale = pow2(maxLevel - level); return at(scale * x, scale * y);}
75  Vec3d& at(int level, int x, int y)
76  {int scale = pow2(maxLevel - level); return at(scale * x, scale * y);}
77 
79  void init_grid();
80  void init_grid(int level, int x, int y, bool side);
81 
83  int maxLevel;
85  int size;
87  QVector<Vec3d> grid;
88 };
89 
90 #endif // STELTOASTGRID_HPP
QVector< unsigned short > getTrianglesIndex(int level, int x, int y, int resolution) const
Get the index of the vertex from getVertexArray sorted as a list of triangles.
QVector< Vec3d > getPolygon(int level, int x, int y) const
Returns the polygon contouring a given tile.
int getMaxLevel() const
Return the max TOAST level of this grid.
Convenience class that can be used to compute the TOAST grid points.
QVector< Vec2f > getTextureArray(int level, int x, int y, int resolution) const
Get the texture array for a given tile.
QVector< Vec3d > getVertexArray(int level, int x, int y, int resolution) const
Get the vertex array for a given tile.