• 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
  • htmesh
HTMesh.h
Go to the documentation of this file.
1 /***************************************************************************
2  HTMesh.h - K Desktop Planetarium
3  -------------------
4  begin : 2007-06-14
5  copyright : (C) 2007 James B. Bowlin
6  email : bowlin@mindspring.com
7 ***************************************************************************/
8 
9 // FIXME? We are needlessly copying the trixel data into the buffer during
10 // indexing. One way to fix this is to give HTMesh next() and hasNext()
11 // methods. This would also involve moving the convex and the range off the
12 // stack and back to the heap when the indexing methods are called for indexing
13 // and not drawing. Let's wait.
14 
15 #ifndef HTMESH_H
16 #define HTMESH_H
17 
18 #include <cstdio>
19 #include "typedef.h"
20 
21 class SpatialIndex;
22 class RangeConvex;
23 class MeshIterator;
24 class MeshBuffer;
25 
26 
27 /* @class HTMesh was originally intended to be a simple interface to the HTM
28  * library for the KStars project that would hide some of the complexity. But
29  * it has gained some complexity of its own.
30  *
31  * The most complex addition was the routine that performs an intersection on a
32  * line segment, finding all the trixels that cover the line. Perhaps there is
33  * an easier and faster way to do it. Right now we convert to cartesian
34  * coordinates to take the cross product of the two input vectors in order to
35  * create a perpendicular which is used to form a very narrow triangle that
36  * contains the original line segment as one of its long legs.
37  *
38  * Error detection and prevention added a little bit more complexity. The raw
39  * HTM library is vulnerable to misbehavior if the polygon intersection routines
40  * are given duplicate consecutive points, including the first point of a
41  * polygon duplicating the last point. We test for duplicated points now. If
42  * they are found, we drop down to the intersection routine with one fewer
43  * vertices, ending at the line segment. If the two ends of a line segment are
44  * much close together than the typical edge of a trixel then we simply index
45  * each point separately and the result set is consists of the union of these
46  * two trixels.
47  *
48  * The final (I hope) level of complexity was the addition of multiple results
49  * buffers. You can set the number of results buffers in the HTMesh
50  * constructor. Since each buffer has to be able to hold one integer for each
51  * trixel in the mesh, multiple buffers can quickly eat up memory. The default
52  * is just one buffer and all routines that use the buffers default to using the
53  * just the first buffer.
54  *
55  * NOTE: all Right Ascensions (ra) and Declinations (dec) are in degrees.
56  */
57 
58 class HTMesh {
59 public:
60  /* @short constructor.
61  * @param level is passed on to the underlying SpatialIndex
62  * @param buildLevvel is also passed on to the SpatialIndex
63  * @param numBuffers controls how many output buffers are created. Don't
64  * use more than require because they eat up mucho RAM. The default is
65  * just one output buffer.
66  */
67  HTMesh(int level, int buildLevel, int numBuffers=1);
68 
69  ~HTMesh();
70 
71  /* @short returns the index of the trixel that contains the specified
72  * point.
73  */
74  Trixel index(double ra, double dec) const;
75 
76  /* NOTE: The intersect() routines below are all used to find the trixels
77  * needed to cover a geometric object: circle, line, triangle, and
78  * quadrilateral. Since the number of trixels needed can be large and is
79  * not known a priori, you must construct a MeshIterator to iterate over
80  * the trixels that are the result of any of these 4 calculations.
81  *
82  * The HTMesh is created with one or more output buffers used for storing
83  * the results. You can specify which output buffer is to be used to hold
84  * the results by supplying an optional integer bufNum parameter.
85  */
86 
96  void intersect(double ra, double dec, double radius,
97  BufNum bufNum=0);
98 
99 
100  /* @short finds the trixels that cover the specified line segment
101  */
102  void intersect(double ra1, double dec1, double ra2, double dec2,
103  BufNum bufNum=0);
104 
105 
106  /* @short find the trixels that cover the specified triangle
107  */
108  void intersect(double ra1, double dec1, double ra2, double dec2,
109  double ra3, double dec3, BufNum bufNum=0);
110 
111 
112  /* @short finds the trixels that cover the specified quadrilateral
113  */
114  void intersect(double ra1, double dec1, double ra2, double dec2,
115  double ra3, double dec3, double ra4, double dec4,
116  BufNum bufNum=0);
117 
118  /* @short returns the number of trixels in the result buffer bufNum.
119  */
120  int intersectSize(BufNum bufNum=0);
121 
122  /* @short returns the total number of trixels in the HTM. This number
123  * is 8 * 4^level.
124  */
125  int size() const { return numTrixels; }
126 
127  /* @short returns the mesh level.
128  */
129  int level() const { return m_level; }
130 
131  /* @short sets the debug level which is used to print out intermediate
132  * results in the line intersection routine.
133  */
134  void setDebug(int debug) { htmDebug = debug; }
135 
136  /* @short returns a pointer to the MeshBuffer specified by bufNum.
137  * Currently this is only used in the MeshIterator constructor.
138  */
139  MeshBuffer* meshBuffer(BufNum bufNum=0);
140 
141  void vertices(Trixel id, double *ra1, double *dec1,
142  double *ra2, double *dec2,
143  double *ra3, double *dec3);
144  private:
145  const char *name;
146  SpatialIndex *htm;
147  int m_level, m_buildLevel;
148  int numTrixels, magicNum;
149 
150  // These store the result sets:
151  MeshBuffer** m_meshBuffer;
152  BufNum m_numBuffers;
153 
154  double degree2Rad;
155  double edge, edge10, eps;
156 
157  int htmDebug;
158 
159  /* @short fills the specified buffer with the intersection results in the
160  * RangeConvex.
161  */
162  bool performIntersection(RangeConvex* convex, BufNum bufNum=0);
163 
164  /* @short users can only use the allocated buffers
165  */
166  inline bool validBufNum(BufNum bufNum)
167  {
168  if (bufNum < m_numBuffers) return true;
169  fprintf(stderr, "%s: bufNum: %d >= numBuffers: %d\n",
170  name, bufNum, m_numBuffers);
171  return false;
172  }
173 
174  /* @short used by the line intersection routine. Maybe there is a
175  * simpler and faster approach that does not require this conversion.
176  */
177  void toXYZ( double ra, double dec, double *x, double *y, double *z);
178 
179 };
180 
181 
182 #endif
typedef.h
HTMesh::~HTMesh
~HTMesh()
Definition: HTMesh.cpp:60
HTMesh::index
Trixel index(double ra, double dec) const
Definition: HTMesh.cpp:68
SpatialIndex
The Spatial Index is a quad tree of spherical triangles.
Definition: SpatialIndex.h:59
HTMesh::intersectSize
int intersectSize(BufNum bufNum=0)
Definition: HTMesh.cpp:264
HTMesh
Definition: HTMesh.h:58
MeshBuffer
Definition: MeshBuffer.h:25
HTMesh::size
int size() const
Definition: HTMesh.h:125
HTMesh::meshBuffer
MeshBuffer * meshBuffer(BufNum bufNum=0)
Definition: HTMesh.cpp:256
HTMesh::intersect
void intersect(double ra, double dec, double radius, BufNum bufNum=0)
finds the trixels that cover the specified circle
Definition: HTMesh.cpp:99
HTMesh::vertices
void vertices(Trixel id, double *ra1, double *dec1, double *ra2, double *dec2, double *ra3, double *dec3)
Definition: HTMesh.cpp:271
BufNum
unsigned short BufNum
Definition: htmesh/typedef.h:5
Trixel
unsigned int Trixel
Definition: htmesh/typedef.h:4
MeshIterator
Definition: MeshIterator.h:22
HTMesh::level
int level() const
Definition: HTMesh.h:129
RangeConvex
A spatial convex is composed of spatial constraints.
Definition: RangeConvex.h:59
HTMesh::setDebug
void setDebug(int debug)
Definition: HTMesh.h:134
HTMesh::HTMesh
HTMesh(int level, int buildLevel, int numBuffers=1)
Definition: HTMesh.cpp:23
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 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