Stellarium  0.90.0
StelToast.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 _STELTOAST_HPP_
21 #define _STELTOAST_HPP_
22 
23 #include <QCache>
24 #include <QObject>
25 #include <QString>
26 #include <QTimeLine>
27 #include <QVector>
28 
29 #include "StelSphereGeometry.hpp"
30 #include "StelTexture.hpp"
31 #include "StelTextureTypes.hpp"
32 #include "VecMath.hpp"
33 #include "StelToastGrid.hpp"
34 
35 class StelPainter;
36 class ToastSurvey;
37 
41 class ToastTile
42 {
43 public:
45  struct Coord
46  {
47  int level;
48  int x;
49  int y;
50 
51  bool operator==(const Coord& b) const
52  {
53  return level == b.level && x == b.x && y == b.y;
54  }
55  bool operator!=(const Coord& b) const
56  {
57  return !(*this == b);
58  }
59  };
60 
61  ToastTile(ToastSurvey *survey, int level, int x, int y);
62  virtual ~ToastTile();
63  Coord getCoord() const { Coord c = { level, x, y }; return c; }
64  void draw(StelPainter* painter, const SphericalCap& viewportShape, int maxVisibleLevel);
65  bool isTransparent();
66 
67 protected:
68  void drawTile(StelPainter* painter);
70  const ToastSurvey* getSurvey() const;
72  const ToastGrid* getGrid() const;
74  bool isVisible(const SphericalCap& viewportShape, int maxVisibleLevel) const;
77  bool isCovered(const SphericalCap& viewportShape) const;
78  void prepareDraw();
79 
80 private:
82  ToastSurvey* survey;
84  int level;
86  int x;
88  int y;
90  QString imagePath;
92  bool empty;
96  bool prepared;
98  bool readyDraw;
100  StelTextureSP texture;
102  SphericalCap boundingCap;
103 
104  QList<ToastTile*> subTiles;
105 
106  // QList<SphericalRegionP> skyConvexPolygons;
108  QVector<Vec3d> vertexArray;
109  QVector<Vec2f> textureArray;
110  QVector<unsigned short> indexArray;
111 
112  // Used for smooth fade in
113  QTimeLine texFader;
114 };
115 
117 inline uint qHash(const ToastTile::Coord& key, uint seed = 0)
118 {
119  //with a maximum level of 11, the x/y coords may be up to 4^11
120  return qHash(key.level << 28 |
121  key.x << 14 |
122  key.y,
123  seed);
124 }
125 
126 
129 class ToastSurvey : public QObject
130 {
131  Q_OBJECT
132 
133 public:
134  ToastSurvey(const QString& path, int maxLevel);
135  virtual ~ToastSurvey();
136  QString getTilePath(int level, int x, int y) const;
137  void draw(StelPainter* sPainter);
138  const ToastGrid* getGrid() const {return &grid;}
139  int getMaxLevel() const {return maxLevel;}
140  int getTilesSize() const {return 256;}
141 
144  ToastTile* getCachedTile(int level, int x, int y);
146  void putIntoCache(ToastTile* tile);
147 
148 private:
149  ToastGrid grid;
150  QString path;
151  ToastTile* rootTile;
152  int maxLevel;
153 
154  typedef QCache<ToastTile::Coord, ToastTile> ToastCache;
155  ToastCache toastCache;
156 };
157 
158 #endif // _STELTOAST_HPP_
const ToastSurvey * getSurvey() const
Return the survey the tile belongs to.
const ToastGrid * getGrid() const
Return the toast grid used by the tile.
Triple struct for a coordinate of a ToastTile.
Definition: StelToast.hpp:45
Define the StelTextureSP type.
A SphericalCap is defined by a direction and an aperture.
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
Represents a full Toast survey.
Definition: StelToast.hpp:129
Convenience class that can be used to compute the TOAST grid points.
bool isCovered(const SphericalCap &viewportShape) const
return whether the tile is covered by its children tiles This is used to avoid drawing tiles that wil...
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
Represents a tile in a TOAST image.
Definition: StelToast.hpp:41
Define all SphericalGeometry primitives as well as the SphericalRegionP type.
bool isVisible(const SphericalCap &viewportShape, int maxVisibleLevel) const
Return whether the tile should be drawn.