• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • skycomponents
skymesh.h
Go to the documentation of this file.
1 /***************************************************************************
2  skymesh.h - K Desktop Planetarium
3  -------------------
4  begin : 2007-07-03
5  copyright : (C) 2007 by James B. Bowlin
6  email : bowlin@mindspring.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef SKYMESH_H
19 #define SKYMESH_H
20 
21 
22 #include <QHash>
23 #include <QList>
24 #include <QObject>
25 
26 #include <QPainter>
27 
28 #include "ksnumbers.h"
29 
30 #include "htmesh/HTMesh.h"
31 #include "htmesh/MeshIterator.h"
32 #include "htmesh/MeshBuffer.h"
33 
34 #include "typedef.h"
35 
36 class KSNumbers;
37 class StarObject;
38 
39 class SkyPoint;
40 class QPolygonF;
41 
42 class QPainter;
43 
44 // These enums control the trixel storage. Separate buffers are available for
45 // indexing and intersecting. Currently only one buffer is required. Multiple
46 // buffers could be used for intermingling drawing and searching or to have a
47 // non-precessed aperture for objects that don't precess. If a buffer number
48 // is greater than or equal to NUM_BUF a brief error message will be printed
49 // and then KStars will crash. This is a feature, not a bug.
50 
51 enum MeshBufNum_t {
52  DRAW_BUF = 0,
53  NO_PRECESS_BUF = 1,
54  OBJ_NEAREST_BUF = 2,
55  IN_CONSTELL_BUF = 3,
56  NUM_MESH_BUF
57 };
58 
59 /*@class SkyMesh
60  * Provides an interface to the Hierarchical Triangular Mesh (HTM) library
61  * written by A. Szalay, John Doug Reynolds, Jim Gray, and Peter Z. Kunszt.
62  *
63  * HTM divides the celestial sphere up into little triangles (trixels) and
64  * gives each triangle a unique integer id. We index objects by putting a
65  * pointer to the object in a data structure accessible by the id number, for
66  * example QList<QList<StarObject*> or QHash<int, QList<LineListComponent*>.
67  *
68  * Use aperture(centerPoint, radius) to get a list of trixels visible in the
69  * circle. Then use a MeshIterator to iterate over the indices of the visible
70  * trixels. Look up each index in the top level QHash or QList data structure
71  * and the union of all the elements of the QList's returned will contain all
72  * the objects visible in the circle in the sky specified in the aperture()
73  * call.
74  *
75  * The drawID is used for extended objects that may be covered by more than
76  * one trixel. Every time aperture() is called, drawID is incremented by one.
77  * Extended objects should each contain their own drawID. If an object's
78  * drawID is the same as the current drawID then it shouldn't be drawn again
79  * because it was already drawn in this draw cycle. If the drawID is
80  * different then it should be drawn and then the drawID should be set to the
81  * current drawID() so it doesn't get drawn again this cycle.
82  *
83  * The list of visible trixels found from an aperature() call or one of the
84  * primitive index() by creating a new MeshIterator instance:
85  *
86  * MeshIterator( HTMesh *mesh )
87  *
88  * The MeshIterator has its own bool hasNext(), int next(), and int size()
89  * methods for iterating through the integer indices of the found trixels or
90  * for just getting the total number of found trixels.
91  */
92 
93 class SkyMesh : public HTMesh
94 {
95 protected:
96 
97  SkyMesh( int level );
98  // FIXME: check copy ctor
99  SkyMesh( SkyMesh& skyMesh );
100 
101 public:
102  /* @short creates the single instance of SkyMesh. The level indicates
103  * how fine a mesh we will use. The number of triangles (trixels) in the
104  * mesh will be 8 * 4^level so a mesh of level 5 will have 8 * 4^5 = 8 *
105  * 2^10 = 8192 trixels. The size of the triangles are roughly pi / *
106  * 2^(level + 1) so a level 5 mesh will have triagles size roughly of
107  * .05 radians or 2.8 degrees.
108  */
109  static SkyMesh* Create( int level );
110 
111  /* @short returns the default instance of SkyMesh or null if it has not
112  * yet been created.
113  */
114  static SkyMesh* Instance();
115 
121  static SkyMesh* Instance( int level );
122 
136  void aperture( SkyPoint *center, double radius, MeshBufNum_t bufNum=DRAW_BUF );
137 
138  /* @short returns the index of the trixel containing p.
139  */
140  Trixel index( const SkyPoint *p );
141 
148  const SkyRegion& skyRegion( const SkyPoint& p1, const SkyPoint& p2 );
149 
150  //----- Stars and CLines -----
151 
152  // The follow four routines are used for indexing stars and CLines.
153  // They differ from the normal routines because they take proper motion
154  // into account while the normal routines always index the J2000
155  // position.
156  //
157  // Since the proper motion depends on time, it is essential to call
158  // setKSNumbers to set the time before doing the indexing. The default
159  // value is J2000.
160 
161  /* @short sets the time for indexing StarObjects and CLines.
162  */
163  void setKSNumbers( KSNumbers* num ) { m_KSNumbers = KSNumbers( *num ); }
164 
165  /* @short returns the trixel that contains the star at the set
166  * time with proper motion taken into account but not precession.
167  * This is a feature not a bug.
168  */
169  Trixel indexStar( StarObject *star );
170 
171  /* @short fills the default buffer with all the trixels needed to cover
172  * the line connecting the two stars.
173  */
174  void indexStar( StarObject* star1, StarObject* star2 );
175 
176  /* @short Fills a hash with all the trixels needed to cover all the line
177  * segments in the SkyList where each SkyPoint is assumed to be a star
178  * and proper motion is taken into account. Used only by
179  * ConstellationsLines.
180  */
181  const IndexHash& indexStarLine( SkyList* points );
182 
183 
184  //----- Here come index routines for various shapes -----
185 
186  //--- First the QPointF routines ---
187 
188  /* @short finds the indices of the trixels that cover the triangle
189  * specified by the three QPointF's.
190  */
191  void index( const QPointF &p1, const QPointF &p2, const QPointF &p3 );
192 
193  /* @short Finds the trixels needed to cover the quadrilateral specified
194  * by the four QPointF's.
195  */
196  void index( const QPointF &p1, const QPointF &p2, const QPointF &p3,
197  const QPointF &p4 );
198 
199 
200  //--- Now the SkyPoint Routines ---
201 
202  /* @short finds the indices of the trixels covering the circle specified
203  * by center and radius.
204  */
205  void index( const SkyPoint *center, double radius, MeshBufNum_t bufNum=DRAW_BUF );
206 
207  /* @short finds the indices of the trixels covering the line segment
208  * connecting p1 and p2.
209  */
210  void index( const SkyPoint* p1, const SkyPoint* p2 );
211 
212  /* @short finds the indices of the trixels covering the triangle
213  * specified by vertices: p1, p2, and p3.
214  */
215  void index( const SkyPoint* p1, const SkyPoint* p2, const SkyPoint* p3 );
216 
217  /* @short finds the indices of the trixels covering the quadralateral
218  * specified by the vertices: p1, p2, p3, and p4.
219  */
220  void index( const SkyPoint* p1, const SkyPoint* p2, const SkyPoint* p3, const SkyPoint* p4 );
221 
222 
223  //----- IndexHash Routines -----
224 
225  // The follow routines are used to index SkyList data structures. They
226  // fill a QHash with the indices of the trixels that cover the data
227  // structure. These are all used as callbacks in the LineListIndex
228  // subclasses so they can use the same indexing code to index differnt
229  // data structures. See also indexStarLine() above.
230 
231  /* @short fills a QHash with the trixel indices needed to cover all the
232  * line segments specified in the QVector<SkyPoints*> points.
233  *
234  * @param points the points of the line segment. @debug causes extra
235  * info to be printed.
236  */
237  const IndexHash& indexLine( SkyList* points );
238 
239  /* @short as above but allows for skipping the indexing of some of
240  * the points.
241  *
242  * @param points the line segment to be indexed.
243  * @param indexHash the hash to return the indices in.
244  * @param skip a hash indicating which points to skip
245  * @param debug optional flag to have the routine print out
246  * debugging info.
247  */
248  const IndexHash& indexLine( SkyList* points, IndexHash* skip );
249 
250  /* @short fills a QHash with the trixel indices needed to cover the
251  * polygon specified in the QList<SkyPoints*> points. There is no
252  * version with a skip parameter because it does not make sense to
253  * skip some of the edges of a filled polygon.
254  *
255  * @param points the points of the line segment.
256  * @debug causes extra info to be printed.
257  */
258  const IndexHash& indexPoly( SkyList* points );
259 
260  /* @short does the same as above but with a QPolygonF as the
261  * container for the points.
262  */
263  const IndexHash& indexPoly( const QPolygonF* points );
264 
265  /* @short Returns the debug level. This is used as a global debug level
266  * for LineListIndex and its subclasses.
267  */
268  int debug() { return m_debug; }
269 
270  /* @short Sets the debug level.
271  */
272  void debug( int debug ) { m_debug = debug; }
273 
274  /* @return the current drawID which gets incremented each time aperture()
275  * is called.
276  */
277  DrawID drawID( ) { return m_drawID; }
278 
279  /* @short increments the drawID and returns the new value. This is
280  * useful when you want to use the drawID to ensure you are not
281  * repeating yourself when iterating over the elements of an IndexHash.
282  * It is currently used in LineListIndex::reindex().
283  */
284  int incDrawID() { return ++m_drawID; }
285 
286  /* @short Draws the outline of all the trixels in the specified buffer.
287  * This was very useful during debugging. I don't precess the points
288  * because I mainly use it with the IN_CONSTELL_BUF which is not
289  * precessed. We will probably have buffers serve double and triple
290  * duty in the production code to save space in which case this function
291  * may become less useful.
292  */
293  void draw( QPainter& psky, MeshBufNum_t
294  bufNum=DRAW_BUF );
295 
296  bool inDraw() { return m_inDraw; }
297  void inDraw( bool inDraw ) { m_inDraw = inDraw; }
298 
299 private:
300  DrawID m_drawID;
301  int errLimit;
302  int m_debug;
303 
304  IndexHash indexHash;
305  KSNumbers m_KSNumbers;
306 
307  bool m_inDraw;
308  static int defaultLevel;
309  static QMap<int, SkyMesh *> pinstances;
310 };
311 
312 #endif
SkyMesh::indexPoly
const IndexHash & indexPoly(SkyList *points)
Definition: skymesh.cpp:241
SkyMesh::inDraw
void inDraw(bool inDraw)
Definition: skymesh.h:297
SkyMesh::inDraw
bool inDraw()
Definition: skymesh.h:296
SkyMesh::draw
void draw(QPainter &psky, MeshBufNum_t bufNum=DRAW_BUF)
Definition: skymesh.cpp:340
HTMesh.h
SkyList
QVector< SkyPoint * > SkyList
Definition: skycomponents/typedef.h:45
SkyRegion
QHash< Trixel, bool > SkyRegion
Definition: skycomponents/typedef.h:47
SkyMesh::incDrawID
int incDrawID()
Definition: skymesh.h:284
HTMesh
Definition: HTMesh.h:58
typedef.h
SkyMesh::Create
static SkyMesh * Create(int level)
Definition: skymesh.cpp:36
SkyMesh::SkyMesh
SkyMesh(int level)
Definition: skymesh.cpp:58
SkyMesh::indexStar
Trixel indexStar(StarObject *star)
Definition: skymesh.cpp:98
SkyMesh::debug
int debug()
Definition: skymesh.h:268
MeshBuffer.h
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
SkyMesh::debug
void debug(int debug)
Definition: skymesh.h:272
SkyMesh::aperture
void aperture(SkyPoint *center, double radius, MeshBufNum_t bufNum=DRAW_BUF)
finds the set of trixels that cover the circular aperture specified after first performing a reverse ...
Definition: skymesh.cpp:66
IN_CONSTELL_BUF
Definition: skymesh.h:55
ksnumbers.h
SkyMesh::Instance
static SkyMesh * Instance()
Definition: skymesh.cpp:48
MeshIterator.h
SkyMesh::skyRegion
const SkyRegion & skyRegion(const SkyPoint &p1, const SkyPoint &p2)
returns the sky region needed to cover the rectangle defined by two SkyPoints p1 and p2 ...
Definition: skymesh.cpp:372
DRAW_BUF
Definition: skymesh.h:52
Trixel
unsigned int Trixel
Definition: htmesh/typedef.h:4
SkyMesh::indexStarLine
const IndexHash & indexStarLine(SkyList *points)
Definition: skymesh.cpp:164
SkyMesh::setKSNumbers
void setKSNumbers(KSNumbers *num)
Definition: skymesh.h:163
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
OBJ_NEAREST_BUF
Definition: skymesh.h:54
MeshBufNum_t
MeshBufNum_t
Definition: skymesh.h:51
SkyMesh
Definition: skymesh.h:93
HTMesh::level
int level() const
Definition: HTMesh.h:129
NUM_MESH_BUF
Definition: skymesh.h:56
SkyMesh::indexLine
const IndexHash & indexLine(SkyList *points)
Definition: skymesh.cpp:159
IndexHash
QHash< Trixel, bool > IndexHash
Definition: skycomponents/typedef.h:46
DrawID
quint32 DrawID
Definition: skycomponents/typedef.h:38
StarObject
This is a subclass of SkyObject.
Definition: starobject.h:41
SkyMesh::index
Trixel index(const SkyPoint *p)
Definition: skymesh.cpp:93
SkyMesh::drawID
DrawID drawID()
Definition: skymesh.h:277
NO_PRECESS_BUF
Definition: skymesh.h:53
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal