• 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.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  skymesh.cpp - K Desktop Planetarium
3  -------------------
4  begin : 200-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 #include "skymesh.h"
19 #include "skyobjects/skypoint.h"
20 #include "skyobjects/starobject.h"
21 #include "projections/projector.h"
22 #include "ksnumbers.h"
23 
24 #include <QHash>
25 #include <QPolygonF>
26 #include <QPointF>
27 
28 // these are just for the draw routine:
29 #include <QPainter>
30 #include "kstarsdata.h"
31 #include "skymap.h"
32 
33 QMap<int, SkyMesh *> SkyMesh::pinstances;
34 int SkyMesh::defaultLevel = -1;
35 
36 SkyMesh* SkyMesh::Create( int level )
37 {
38  SkyMesh *newInstance;
39  newInstance = pinstances.value( level, NULL );
40  delete newInstance;
41  newInstance = new SkyMesh( level );
42  pinstances.insert( level, newInstance );
43  if( defaultLevel < 0 )
44  defaultLevel = newInstance->level();
45  return newInstance;
46 }
47 
48 SkyMesh* SkyMesh::Instance( )
49 {
50  return pinstances.value( defaultLevel, NULL );
51 }
52 
53 SkyMesh* SkyMesh::Instance( int level )
54 {
55  return pinstances.value( level, NULL );
56 }
57 
58 SkyMesh::SkyMesh( int level) :
59  HTMesh(level, level, NUM_MESH_BUF),
60  m_drawID(0), m_KSNumbers( 0 )
61 {
62  errLimit = HTMesh::size() / 4;
63  m_inDraw = false;
64 }
65 
66 void SkyMesh::aperture(SkyPoint *p0, double radius, MeshBufNum_t bufNum)
67 {
68  KStarsData* data = KStarsData::Instance();
69  // FIXME: simple copying leads to incorrect results because RA0 && dec0 are both zero sometimes
70  SkyPoint p1( p0->ra(), p0->dec() );
71  long double now = data->updateNum()->julianDay();
72  p1.apparentCoord( now, J2000 );
73 
74  if ( radius == 1.0 ) {
75  printf("\n ra0 = %8.4f dec0 = %8.4f\n", p0->ra().Degrees(), p0->dec().Degrees() );
76  printf(" ra1 = %8.4f dec1 = %8.4f\n", p1.ra().Degrees(), p1.dec().Degrees() );
77 
78  SkyPoint p2 = p1;
79  p2.updateCoords( data->updateNum() );
80  printf(" ra2 = %8.4f dec2 = %8.4f\n", p2.ra().Degrees(), p2.dec().Degrees() );
81  printf("p0 - p1 = %6.4f degrees\n", p0->angularDistanceTo( &p1 ).Degrees() );
82  printf("p0 - p2 = %6.4f degrees\n", p0->angularDistanceTo( &p2 ).Degrees() );
83  }
84 
85  HTMesh::intersect( p1.ra().Degrees(), p1.dec().Degrees(), radius, (BufNum) bufNum);
86  m_drawID++;
87 
88  return;
89  if ( m_inDraw && bufNum != DRAW_BUF )
90  printf("Warining: overlapping buffer: %d\n", bufNum);
91 }
92 
93 Trixel SkyMesh::index(const SkyPoint* p)
94 {
95  return HTMesh::index( p->ra0().Degrees(), p->dec0().Degrees() );
96 }
97 
98 Trixel SkyMesh::indexStar( StarObject *star )
99 {
100  double ra, dec;
101  star->getIndexCoords( &m_KSNumbers, &ra, &dec );
102  return HTMesh::index( ra, dec );
103 }
104 
105 void SkyMesh::indexStar( StarObject* star1, StarObject* star2 )
106 {
107  double ra1, ra2, dec1, dec2;
108  star1->getIndexCoords( &m_KSNumbers, &ra1, &dec1 );
109  star2->getIndexCoords( &m_KSNumbers, &ra2, &dec2 );
110  HTMesh::intersect( ra1, dec1, ra2, dec2 );
111 }
112 
113 
114 void SkyMesh::index(const SkyPoint *p, double radius, MeshBufNum_t bufNum )
115 {
116  HTMesh::intersect( p->ra().Degrees(), p->dec().Degrees(), radius, (BufNum) bufNum );
117 
118  return;
119  if ( m_inDraw && bufNum != DRAW_BUF )
120  printf("Warining: overlapping buffer: %d\n", bufNum);
121 }
122 
123 void SkyMesh::index( const SkyPoint* p1, const SkyPoint* p2 )
124 {
125  HTMesh::intersect( p1->ra0().Degrees(), p1->dec0().Degrees(),
126  p2->ra0().Degrees(), p2->dec0().Degrees() );
127 }
128 
129 void SkyMesh::index( const SkyPoint* p1, const SkyPoint* p2, const SkyPoint* p3 )
130 {
131  HTMesh::intersect( p1->ra0().Degrees(), p1->dec0().Degrees(),
132  p2->ra0().Degrees(), p2->dec0().Degrees(),
133  p3->ra0().Degrees(), p3->dec0().Degrees() );
134 }
135 
136 void SkyMesh::index( const SkyPoint* p1, const SkyPoint* p2, const SkyPoint* p3, const SkyPoint* p4 )
137 {
138  HTMesh::intersect( p1->ra0().Degrees(), p1->dec0().Degrees(),
139  p2->ra0().Degrees(), p2->dec0().Degrees(),
140  p3->ra0().Degrees(), p3->dec0().Degrees(),
141  p4->ra0().Degrees(), p4->dec0().Degrees() );
142 }
143 
144 void SkyMesh::index( const QPointF &p1, const QPointF &p2, const QPointF &p3 )
145 {
146  HTMesh::intersect( p1.x() * 15.0, p1.y(),
147  p2.x() * 15.0, p2.y(),
148  p3.x() * 15.0, p3.y() );
149 }
150 
151 void SkyMesh::index( const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4 )
152 {
153  HTMesh::intersect( p1.x() * 15.0, p1.y(),
154  p2.x() * 15.0, p2.y(),
155  p3.x() * 15.0, p3.y(),
156  p4.x() * 15.0, p4.y() );
157 }
158 
159 const IndexHash& SkyMesh::indexLine( SkyList* points )
160 {
161  return indexLine( points, NULL );
162 }
163 
164 const IndexHash& SkyMesh::indexStarLine( SkyList* points )
165 {
166  SkyPoint *pThis, *pLast;
167 
168  indexHash.clear();
169 
170  if ( points->size() == 0 ) return indexHash;
171 
172  pLast = points->at( 0 );
173  for ( int i=1 ; i < points->size() ; i++ ) {
174  pThis = points->at( i );
175 
176  indexStar( (StarObject*) pThis, (StarObject*) pLast );
177  MeshIterator region( this );
178 
179  while ( region.hasNext() ) {
180  indexHash[ region.next() ] = true;
181  }
182  pLast = pThis;
183  }
184 
185  //printf("indexStarLine %d -> %d\n", points->size(), indexHash.size() );
186  return indexHash;
187 }
188 
189 
190 const IndexHash& SkyMesh::indexLine( SkyList* points, IndexHash* skip )
191 {
192  SkyPoint *pThis, *pLast;
193 
194  indexHash.clear();
195 
196  if ( points->size() == 0 ) return indexHash;
197 
198  pLast = points->at( 0 );
199  for ( int i=1 ; i < points->size() ; i++ ) {
200  pThis = points->at( i );
201 
202  if (skip != NULL && skip->contains( i ) ) {
203  pLast = pThis;
204  continue;
205  }
206 
207  index( pThis, pLast );
208  MeshIterator region( this );
209 
210  if ( region.size() > errLimit ) {
211  printf("\nSkyMesh::indexLine: too many trixels: %d\n", region.size() );
212  printf(" ra1 = %f;\n", pThis->ra0().Degrees());
213  printf(" ra2 = %f;\n", pLast->ra0().Degrees());
214  printf(" dec1 = %f;\n", pThis->dec0().Degrees());
215  printf(" dec2 = %f;\n", pLast->dec0().Degrees());
216  HTMesh::setDebug( 10 );
217  index( pThis, pLast );
218  HTMesh::setDebug ( 0 );
219  }
220 
221  // This was used to track down a bug in my HTMesh code. The bug was caught
222  // and fixed but I've left this debugging code in for now. -jbb
223 
224  else {
225  while ( region.hasNext() ) {
226  indexHash[ region.next() ] = true;
227  }
228  }
229  pLast = pThis;
230  }
231  return indexHash;
232 }
233 
234 
235 // ----- Create HTMesh Index for Polygons -----
236 // Create (mostly) 4-point polygons that cover the mw polygon and
237 // all share the same first vertex. Use indexHash to eliminate
238 // the many duplicate indices that are generated with this procedure.
239 // There are probably faster and better ways to do this.
240 
241 const IndexHash& SkyMesh::indexPoly( SkyList *points )
242 {
243 
244  indexHash.clear();
245 
246  if (points->size() < 3) return indexHash;
247 
248  SkyPoint* startP = points->first();
249 
250  int end = points->size() - 2; // 1) size - 1 -> last index,
251  // 2) minimum of 2 points
252 
253  for( int p = 1; p <= end; p+= 2 ) {
254 
255  if ( p == end ) {
256  index( startP, points->at(p), points->at(p+1) );
257  }
258  else {
259  index( startP, points->at(p), points->at(p+1), points->at(p+2) );
260  }
261 
262  MeshIterator region( this );
263 
264  if ( region.size() > errLimit ) {
265  printf("\nSkyMesh::indexPoly: too many trixels: %d\n", region.size() );
266 
267  printf(" ra1 = %f;\n", startP->ra0().Degrees());
268  printf(" ra2 = %f;\n", points->at(p)->ra0().Degrees());
269  printf(" ra3 = %f;\n", points->at(p+1)->ra0().Degrees());
270  if ( p < end )
271  printf(" ra4 = %f;\n", points->at(p+2)->ra0().Degrees());
272 
273  printf(" dec1 = %f;\n", startP->dec0().Degrees());
274  printf(" dec2 = %f;\n", points->at(p)->dec0().Degrees());
275  printf(" dec3 = %f;\n", points->at(p+1)->dec0().Degrees());
276  if ( p < end )
277  printf(" dec4 = %f;\n", points->at(p+2)->dec0().Degrees());
278 
279  printf("\n");
280 
281  }
282  while ( region.hasNext() ) {
283  indexHash[ region.next() ] = true;
284  }
285  }
286  return indexHash;
287 }
288 
289 const IndexHash& SkyMesh::indexPoly( const QPolygonF* points )
290 {
291  indexHash.clear();
292 
293  if (points->size() < 3) return indexHash;
294 
295  const QPointF startP = points->first();
296 
297  int end = points->size() - 2; // 1) size - 1 -> last index,
298  // 2) minimum of 2 points
299  for( int p = 1; p <= end; p+= 2 ) {
300 
301  if ( p == end ) {
302  index( startP, points->at(p), points->at(p+1) );
303  }
304  else {
305  index( startP, points->at(p), points->at(p+1), points->at(p+2) );
306  }
307 
308  MeshIterator region( this );
309 
310  if ( region.size() > errLimit ) {
311  printf("\nSkyMesh::indexPoly: too many trixels: %d\n", region.size() );
312 
313  printf(" ra1 = %f;\n", startP.x() );
314  printf(" ra2 = %f;\n", points->at(p).x() );
315  printf(" ra3 = %f;\n", points->at(p+1).x()) ;
316  if ( p < end )
317  printf(" ra4 = %f;\n", points->at(p+2).x() );
318 
319  printf(" dec1 = %f;\n", startP.y() );
320  printf(" dec2 = %f;\n", points->at(p).y() );
321  printf(" dec3 = %f;\n", points->at(p+1).y() );
322  if ( p < end )
323  printf(" dec4 = %f;\n", points->at(p+2).y());
324 
325  printf("\n");
326 
327  }
328  while ( region.hasNext() ) {
329  indexHash[ region.next() ] = true;
330  }
331  }
332  return indexHash;
333 }
334 
335 // NOTE: SkyMesh::draw() is primarily used for debugging purposes, to
336 // show the trixels to enable visualizing them. Thus, it is not
337 // necessary that this be compatible with GL unless we abandon the
338 // QPainter some day, or the need arises to use this for some other
339 // purpose. -- asimha
340 void SkyMesh::draw(QPainter &psky, MeshBufNum_t bufNum)
341 {
342 
343  SkyMap* map = SkyMap::Instance();
344  KStarsData* data = KStarsData::Instance();
345 
346  double r1, d1, r2, d2, r3, d3;
347 
348  MeshIterator region( this, bufNum );
349  while ( region.hasNext() ) {
350  Trixel trixel = region.next();
351  vertices( trixel, &r1, &d1, &r2, &d2, &r3, &d3 );
352  SkyPoint s1( r1 / 15.0, d1 );
353  SkyPoint s2( r2 / 15.0, d2 );
354  SkyPoint s3( r3 / 15.0, d3 );
355  s1.EquatorialToHorizontal( data->lst(), data->geo()->lat() );
356  s2.EquatorialToHorizontal( data->lst(), data->geo()->lat() );
357  s3.EquatorialToHorizontal( data->lst(), data->geo()->lat() );
358  QPointF q1 = map->projector()->toScreen( &s1 );
359  QPointF q2 = map->projector()->toScreen( &s2 );
360  QPointF q3 = map->projector()->toScreen( &s3 );
361  psky.drawLine( q1, q2 );
362  psky.drawLine( q2, q3 );
363  psky.drawLine( q3, q1 );
364  // Draw the name of the trixel
365  QString TrixelNumberString;
366  TrixelNumberString.setNum( trixel );
367  psky.drawText( (q1 + q2 + q3 ) / 3.0, TrixelNumberString );
368  }
369 
370 }
371 
372 const SkyRegion& SkyMesh::skyRegion( const SkyPoint& _p1, const SkyPoint& _p2 )
373 {
374  SkyPoint p1( _p1 ), p2( _p2 );
375  SkyPoint p3( p1.ra(), p2.dec() ), p4( p2.ra(), p1.dec() );
376  SkyList skylist;
377  skylist << &p1 << &p2 << &p3 << &p4;
378  return indexPoly( &skylist );
379 }
SkyMesh::indexPoly
const IndexHash & indexPoly(SkyList *points)
Definition: skymesh.cpp:241
HTMesh::index
Trixel index(double ra, double dec) const
Definition: HTMesh.cpp:68
SkyMesh::draw
void draw(QPainter &psky, MeshBufNum_t bufNum=DRAW_BUF)
Definition: skymesh.cpp:340
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
SkyPoint::dec0
const dms & dec0() const
Definition: skypoint.h:168
SkyList
QVector< SkyPoint * > SkyList
Definition: skycomponents/typedef.h:45
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
SkyRegion
QHash< Trixel, bool > SkyRegion
Definition: skycomponents/typedef.h:47
HTMesh
Definition: HTMesh.h:58
KStarsData::lst
dms * lst()
Definition: kstarsdata.h:161
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
SkyMesh::Create
static SkyMesh * Create(int level)
Definition: skymesh.cpp:36
SkyPoint::updateCoords
virtual void updateCoords(KSNumbers *num, bool includePlanets=true, const dms *lat=0, const dms *LST=0, bool forceRecompute=false)
Determine the current coordinates (RA, Dec) from the catalog coordinates (RA0, Dec0), accounting for both precession and nutation.
Definition: skypoint.cpp:317
SkyMesh::SkyMesh
SkyMesh(int level)
Definition: skymesh.cpp:58
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
HTMesh::size
int size() const
Definition: HTMesh.h:125
SkyPoint::ra0
const dms & ra0() const
Definition: skypoint.h:165
SkyMesh::indexStar
Trixel indexStar(StarObject *star)
Definition: skymesh.cpp:98
StarObject::getIndexCoords
void getIndexCoords(KSNumbers *num, double *ra, double *dec)
Definition: starobject.cpp:268
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
KStarsData::updateNum
KSNumbers * updateNum()
Definition: kstarsdata.h:226
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
Projector::toScreen
QPointF toScreen(const SkyPoint *o, bool oRefract=true, bool *onVisibleHemisphere=0) const
This is exactly the same as toScreenVec but it returns a QPointF.
Definition: projector.cpp:93
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
HTMesh::vertices
void vertices(Trixel id, double *ra1, double *dec1, double *ra2, double *dec2, double *ra3, double *dec3)
Definition: HTMesh.cpp:271
skymap.h
KSNumbers::julianDay
long double julianDay() const
Definition: ksnumbers.h:93
ksnumbers.h
SkyMesh::Instance
static SkyMesh * Instance()
Definition: skymesh.cpp:48
SkyPoint::dec
const dms & dec() const
Definition: skypoint.h:174
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
skypoint.h
BufNum
unsigned short BufNum
Definition: htmesh/typedef.h:5
MeshIterator::size
int size() const
Definition: MeshIterator.h:37
SkyPoint::EquatorialToHorizontal
void EquatorialToHorizontal(const dms *LST, const dms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:55
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
MeshIterator
Definition: MeshIterator.h:22
MeshIterator::hasNext
bool hasNext() const
Definition: MeshIterator.h:29
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
J2000
#define J2000
Definition: kstarsdatetime.h:21
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
starobject.h
SkyMap
This is the canvas on which the sky is painted.
Definition: skymap.h:72
projector.h
SkyMap::Instance
static SkyMap * Instance()
Definition: skymap.cpp:141
SkyMesh::indexLine
const IndexHash & indexLine(SkyList *points)
Definition: skymesh.cpp:159
IndexHash
QHash< Trixel, bool > IndexHash
Definition: skycomponents/typedef.h:46
MeshIterator::next
Trixel next() const
Definition: MeshIterator.h:33
kstarsdata.h
skymesh.h
HTMesh::setDebug
void setDebug(int debug)
Definition: HTMesh.h:134
StarObject
This is a subclass of SkyObject.
Definition: starobject.h:41
SkyMesh::index
Trixel index(const SkyPoint *p)
Definition: skymesh.cpp:93
SkyMap::projector
const Projector * projector() const
Get the current projector.
Definition: skymap.h:264
SkyPoint::angularDistanceTo
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=0) const
Computes the angular distance between two SkyObjects.
Definition: skypoint.cpp:608
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