• 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
starcomponent.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  starcomponent.cpp - K Desktop Planetarium
3  -------------------
4  begin : 2005/14/08
5  copyright : (C) 2005 by Thomas Kabelmann
6  email : thomas.kabelmann@gmx.de
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 #ifdef _WIN32
19 #include <windows.h>
20 #endif
21 #include "starcomponent.h"
22 
23 #include <kglobal.h>
24 
25 #include "Options.h"
26 #include "kstarsdata.h"
27 #include "skymap.h"
28 #include "skyobjects/starobject.h"
29 #include "skyqpainter.h"
30 #include "skypainter.h"
31 
32 #include "skymesh.h"
33 #include "skylabel.h"
34 #include "skylabeler.h"
35 #include "kstarssplash.h"
36 
37 #include "binfilehelper.h"
38 #include "starblockfactory.h"
39 
40 #include "projections/projector.h"
41 
42 
43 #if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
44 #include <sys/endian.h>
45 #define bswap_16(x) bswap16(x)
46 #define bswap_32(x) bswap32(x)
47 #else
48 #include "byteorder.h"
49 #endif
50 
51 #include <kde_file.h>
52 
53 StarComponent *StarComponent::pinstance = 0;
54 
55 StarComponent::StarComponent(SkyComposite *parent )
56  : ListComponent(parent), m_reindexNum(J2000), m_FaintMagnitude(-5.0),
57  starsLoaded(false), focusStar(NULL)
58 {
59  m_skyMesh = SkyMesh::Instance();
60  m_StarBlockFactory = StarBlockFactory::Instance();
61 
62  m_starIndex = new StarIndex();
63  for (int i = 0; i < m_skyMesh->size(); i++)
64  m_starIndex->append( new StarList() );
65  m_highPMStars.append( new HighPMStarList( 840.0 ) );
66  m_highPMStars.append( new HighPMStarList( 304.0 ) );
67  m_reindexInterval = StarObject::reindexInterval( 304.0 );
68 
69  m_zoomMagLimit = 0.0;
70 
71  for ( int i = 0; i <= MAX_LINENUMBER_MAG; i++ )
72  m_labelList[ i ] = new LabelList;
73 
74  // Actually load data
75  emitProgressText( i18n("Loading stars" ) );
76  loadStaticData();
77  // Load any deep star catalogs that are available
78  loadDeepStarCatalogs();
79  SkyQPainter::initStarImages();
80 }
81 
82 StarComponent::~StarComponent() {
83  // Empty
84 }
85 
86 StarComponent *StarComponent::Create( SkyComposite *parent ) {
87  delete pinstance;
88  pinstance = new StarComponent( parent );
89  return pinstance;
90 }
91 
92 bool StarComponent::selected() {
93  return Options::showStars();
94 }
95 
96 bool StarComponent::addDeepStarCatalogIfExists( const QString &fileName, float trigMag, bool staticstars ) {
97  if( BinFileHelper::testFileExists( fileName ) ) {
98  m_DeepStarComponents.append( new DeepStarComponent( parent(), fileName, trigMag, staticstars ) );
99  return true;
100  }
101  return false;
102 }
103 
104 
105 int StarComponent::loadDeepStarCatalogs() {
106 
107  // Look for the basic unnamed star catalog to mag 8.0
108  if( !addDeepStarCatalogIfExists( "unnamedstars.dat", -5.0, true ) )
109  return 0;
110 
111  // Look for the Tycho-2 add-on with 2.5 million stars to mag 12.5
112  if( !addDeepStarCatalogIfExists( "tycho2.dat" , 8.0 ) && !addDeepStarCatalogIfExists( "deepstars.dat", 8.0 ) )
113  return 1;
114 
115  // Look for the USNO NOMAD 1e8 star catalog add-on with stars to mag 16
116  if( !addDeepStarCatalogIfExists( "USNO-NOMAD-1e8.dat", 11.0 ) )
117  return 2;
118 
119  return 3;
120 }
121 
122 //This function is empty for a reason; we override the normal
123 //update function in favor of JiT updates for stars.
124 void StarComponent::update( KSNumbers*)
125 {}
126 
127 // We use the update hook to re-index all the stars when the date has changed by
128 // more than 150 years.
129 
130 void StarComponent::reindex( KSNumbers *num )
131 {
132  if ( ! num ) return;
133 
134  // for large time steps we re-index all points
135  if ( fabs( num->julianCenturies() -
136  m_reindexNum.julianCenturies() ) > m_reindexInterval ) {
137  reindexAll( num );
138  return;
139  }
140 
141  // otherwise we just re-index fast movers as needed
142  for ( int j = 0; j < m_highPMStars.size(); j++ )
143  m_highPMStars.at( j )->reindex( num, m_starIndex );
144 }
145 
146 void StarComponent::reindexAll( KSNumbers *num )
147 {
148  if ( 0 && ! m_reindexSplash ) {
149  m_reindexSplash = new KStarsSplash(
150  i18n("Please wait while re-indexing stars ...") );
151  QObject::connect( KStarsData::Instance(),
152  SIGNAL( progressText( QString ) ),
153  m_reindexSplash, SLOT( setMessage( QString ) ) );
154 
155  m_reindexSplash->show();
156  m_reindexSplash->raise();
157  return;
158  }
159 
160  printf("Re-indexing Stars to year %4.1f...\n",
161  2000.0 + num->julianCenturies() * 100.0);
162 
163  m_reindexNum = KSNumbers( *num );
164  m_skyMesh->setKSNumbers( num );
165 
166  // clear out the old index
167  for ( int i = 0; i < m_starIndex->size(); i++ ) {
168  m_starIndex->at( i )->clear();
169  }
170 
171  // re-populate it from the objectList
172  int size = m_ObjectList.size();
173  for ( int i = 0; i < size; i++ ) {
174  StarObject* star = (StarObject*) m_ObjectList[ i ];
175  Trixel trixel = m_skyMesh->indexStar( star );
176  m_starIndex->at( trixel )->append( star );
177  }
178 
179  // Let everyone else know we have re-indexed to num
180  for ( int j = 0; j < m_highPMStars.size(); j++ ) {
181  m_highPMStars.at( j )->setIndexTime( num );
182  }
183 
184  //delete m_reindexSplash;
185  //m_reindexSplash = 0;
186 
187  printf("Done.\n");
188 }
189 
190 float StarComponent::faintMagnitude() const {
191  float faintmag = m_FaintMagnitude;
192  for( int i =0; i < m_DeepStarComponents.size(); ++i ) {
193  if( faintmag < m_DeepStarComponents.at( i )->faintMagnitude() )
194  faintmag = m_DeepStarComponents.at( i )->faintMagnitude();
195  }
196  return faintmag;
197 }
198 
199 float StarComponent::zoomMagnitudeLimit() {
200 
201  //adjust maglimit for ZoomLevel
202  double lgmin = log10(MINZOOM);
203  double lgz = log10(Options::zoomFactor());
204 
205  // Old formula:
206  // float maglim = ( 2.000 + 2.444 * Options::memUsage() / 10.0 ) * ( lgz - lgmin ) + Options::magLimitDrawStarZoomOut();
207 
208  /*
209  Explanation for the following formula:
210  --------------------------------------
211  Estimates from a sample of 125000 stars shows that, magnitude
212  limit vs. number of stars follows the formula:
213  nStars = 10^(.45 * maglim + .95)
214  (A better formula is available here: http://www.astro.uu.nl/~strous/AA/en/antwoorden/magnituden.html
215  which we do not implement for simplicity)
216  We want to keep the star density on screen a constant. This is directly proportional to the number of stars
217  and directly proportional to the area on screen. The area is in turn inversely proportional to the square
218  of the zoom factor ( zoomFactor / MINZOOM ). This means that (taking logarithms):
219  0.45 * maglim + 0.95 - 2 * log( ZoomFactor ) - log( Star Density ) - log( Some proportionality constant )
220  hence the formula. We've gathered together all the constants and set it to 3.5, so as to set the minimum
221  possible value of maglim to 3.5
222  */
223 
224  // float maglim = 4.444 * ( lgz - lgmin ) + 2.222 * log10( Options::starDensity() ) + 3.5;
225 
226  // Reducing the slope w.r.t zoom factor to avoid the extremely fast increase in star density with zoom
227  // that 4.444 gives us (although that is what the derivation gives us)
228 
229  return 3.5 + 3.7*( lgz - lgmin ) + 2.222*log10( static_cast<float>(Options::starDensity()) );
230 }
231 
232 void StarComponent::draw( SkyPainter *skyp )
233 {
234  if( !selected() )
235  return;
236 
237  SkyMap *map = SkyMap::Instance();
238  const Projector *proj = map->projector();
239  KStarsData* data = KStarsData::Instance();
240  UpdateID updateID = data->updateID();
241 
242  bool checkSlewing = ( map->isSlewing() && Options::hideOnSlew() );
243  m_hideLabels = checkSlewing || !( Options::showStarMagnitudes() || Options::showStarNames() );
244 
245  //shortcuts to inform whether to draw different objects
246  bool hideFaintStars = checkSlewing && Options::hideStars();
247  double hideStarsMag = Options::magLimitHideStar();
248  reindex( data->updateNum() );
249 
250  double lgmin = log10(MINZOOM);
251  double lgmax = log10(MAXZOOM);
252  double lgz = log10(Options::zoomFactor());
253 
254  double maglim;
255  m_zoomMagLimit = maglim = zoomMagnitudeLimit();
256 
257  double labelMagLim = Options::starLabelDensity() / 5.0;
258  labelMagLim += ( 12.0 - labelMagLim ) * ( lgz - lgmin) / (lgmax - lgmin );
259  if( labelMagLim > 8.0 )
260  labelMagLim = 8.0;
261 
262  //Calculate sizeMagLim
263  // Old formula:
264  // float sizeMagLim = ( 2.000 + 2.444 * Options::memUsage() / 10.0 ) * ( lgz - lgmin ) + 5.8;
265 
266  // Using the maglim to compute the sizes of stars reduces
267  // discernability between brighter and fainter stars at high zoom
268  // levels. To fix that, we use an "arbitrary" constant in place of
269  // the variable star density.
270  // Not using this formula now.
271  // float sizeMagLim = 4.444 * ( lgz - lgmin ) + 5.0;
272 
273  float sizeMagLim = zoomMagnitudeLimit();
274  if( sizeMagLim > faintMagnitude() * ( 1 - 1.5/16 ) )
275  sizeMagLim = faintMagnitude() * ( 1 - 1.5/16 );
276  skyp->setSizeMagLimit(sizeMagLim);
277 
278  //Loop for drawing star images
279 
280  MeshIterator region(m_skyMesh, DRAW_BUF);
281  magLim = maglim;
282 
283  // If we are hiding faint stars, then maglim is really the brighter of hideStarsMag and maglim
284  if( hideFaintStars && maglim > hideStarsMag )
285  maglim = hideStarsMag;
286 
287  m_StarBlockFactory->drawID = m_skyMesh->drawID();
288 
289  int nTrixels = 0;
290 
291  while( region.hasNext() ) {
292  ++nTrixels;
293  Trixel currentRegion = region.next();
294  StarList* starList = m_starIndex->at( currentRegion );
295 
296  for (int i=0; i < starList->size(); ++i) {
297  StarObject *curStar = starList->at( i );
298  if( !curStar )
299  continue;
300 
301  float mag = curStar->mag();
302 
303  // break loop if maglim is reached
304  if ( mag > maglim )
305  break;
306 
307  if ( curStar->updateID != updateID )
308  curStar->JITupdate();
309 
310  bool drawn = skyp->drawPointSource( curStar, mag, curStar->spchar() );
311 
312  //FIXME_SKYPAINTER: find a better way to do this.
313  if ( drawn && !(m_hideLabels || mag > labelMagLim) )
314  addLabel( proj->toScreen(curStar), curStar );
315  }
316  }
317 
318  // Draw focusStar if not null
319  if( focusStar ) {
320  if ( focusStar->updateID != updateID )
321  focusStar->JITupdate();
322  float mag = focusStar->mag();
323  skyp->drawPointSource(focusStar, mag, focusStar->spchar() );
324  }
325 
326  // Now draw each of our DeepStarComponents
327  for( int i =0; i < m_DeepStarComponents.size(); ++i ) {
328  m_DeepStarComponents.at( i )->draw( skyp );
329  }
330 }
331 
332 void StarComponent::addLabel( const QPointF& p, StarObject *star )
333 {
334  int idx = int( star->mag() * 10.0 );
335  if ( idx < 0 ) idx = 0;
336  if ( idx > MAX_LINENUMBER_MAG ) idx = MAX_LINENUMBER_MAG;
337  m_labelList[ idx ]->append( SkyLabel( p, star ) );
338 }
339 
340 void StarComponent::drawLabels()
341 {
342  if( m_hideLabels )
343  return;
344 
345  SkyLabeler *labeler = SkyLabeler::Instance();
346  labeler->setPen( QColor( KStarsData::Instance()->colorScheme()->colorNamed( "SNameColor" ) ) );
347 
348  int max = int( m_zoomMagLimit * 10.0 );
349  if ( max < 0 ) max = 0;
350  if ( max > MAX_LINENUMBER_MAG ) max = MAX_LINENUMBER_MAG;
351 
352  for ( int i = 0; i <= max; i++ ) {
353  LabelList* list = m_labelList[ i ];
354  for ( int j = 0; j < list->size(); j++ ) {
355  labeler->drawNameLabel( list->at(j).obj, list->at(j).o );
356  }
357  list->clear();
358  }
359 
360 }
361 
362 bool StarComponent::loadStaticData()
363 {
364  // We break from Qt / KDE API and use traditional file handling here, to obtain speed.
365  // We also avoid C++ constructors for the same reason.
366  KStarsData* data = KStarsData::Instance();
367  FILE *dataFile, *nameFile;
368  bool swapBytes = false;
369  BinFileHelper dataReader, nameReader;
370  QString name, gname, visibleName;
371  StarObject plainStarTemplate;
372  StarObject *star;
373 
374  if(starsLoaded)
375  return true;
376 
377  // prepare to index stars to this date
378  m_skyMesh->setKSNumbers( &m_reindexNum );
379 
380  /* Open the data files */
381  // TODO: Maybe we don't want to hardcode the filename?
382  if((dataFile = dataReader.openFile("namedstars.dat")) == NULL) {
383  kDebug() << "Could not open data file namedstars.dat" << endl;
384  return false;
385  }
386 
387  if(!(nameFile = nameReader.openFile("starnames.dat"))) {
388  kDebug() << "Could not open data file starnames.dat" << endl;
389  return false;
390  }
391 
392  if(!dataReader.readHeader()) {
393  kDebug() << "Error reading namedstars.dat header : " << dataReader.getErrorNumber() << " : " << dataReader.getError() << endl;
394  return false;
395  }
396 
397  if(!nameReader.readHeader()) {
398  kDebug() << "Error reading starnames.dat header : " << nameReader.getErrorNumber() << " : " << nameReader.getError() << endl;
399  return false;
400  }
401  KDE_fseek(nameFile, nameReader.getDataOffset(), SEEK_SET);
402  swapBytes = dataReader.getByteSwap();
403 
404  long int nstars = 0;
405 
406  KDE_fseek(dataFile, dataReader.getDataOffset(), SEEK_SET);
407 
408  qint16 faintmag;
409  quint8 htm_level;
410  quint16 t_MSpT;
411 
412  fread( &faintmag, 2, 1, dataFile );
413  if( swapBytes )
414  faintmag = bswap_16( faintmag );
415  fread( &htm_level, 1, 1, dataFile );
416  fread( &t_MSpT, 2, 1, dataFile ); // Unused
417  if( swapBytes )
418  faintmag = bswap_16( faintmag );
419 
420 
421  if( faintmag / 100.0 > m_FaintMagnitude )
422  m_FaintMagnitude = faintmag / 100.0;
423 
424  if( htm_level != m_skyMesh->level() )
425  kDebug() << "WARNING: HTM Level in shallow star data file and HTM Level in m_skyMesh do not match. EXPECT TROUBLE" << endl;
426 
427  for(int i = 0; i < m_skyMesh -> size(); ++i) {
428 
429  Trixel trixel = i;// = ( ( i >= 256 ) ? ( i - 256 ) : ( i + 256 ) );
430  for(unsigned long j = 0; j < (unsigned long)dataReader.getRecordCount(i); ++j) {
431  if(!fread(&stardata, sizeof(starData), 1, dataFile)){
432  kDebug() << "FILE FORMAT ERROR: Could not read starData structure for star #" << j << " under trixel #" << trixel << endl;
433  }
434 
435  /* Swap Bytes when required */
436  if(swapBytes)
437  byteSwap( &stardata );
438 
439  if(stardata.flags & 0x01) {
440  /* Named Star - Read the nameFile */
441  visibleName = "";
442  if(!fread(&starname, sizeof( starName ), 1, nameFile))
443  kDebug() << "ERROR: fread() call on nameFile failed in trixel " << trixel << " star " << j << endl;
444  name = QByteArray(starname.longName, 32);
445  gname = QByteArray(starname.bayerName, 8);
446  if ( ! gname.isEmpty() && gname.at(0) != '.')
447  visibleName = gname;
448  if(! name.isEmpty() ) {
449  // HEV: look up star name in internationalization filesource
450  name = i18nc("star name", name.toLocal8Bit().data());
451  } else {
452  name = i18n("star");
453  }
454  }
455  else
456  kDebug() << "ERROR: Named star file contains unnamed stars! Expect trouble." << endl;
457 
458  /* Create the new StarObject */
459  star = new StarObject;
460  star->init( &stardata );
461  star->setNames( name, visibleName );
462  star->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
463  ++nstars;
464 
465  if ( ! gname.isEmpty() ) m_genName.insert( gname, star );
466 
467  if ( ! name.isEmpty() ) {
468  objectNames(SkyObject::STAR).append( name );
469  }
470  if ( ! gname.isEmpty() && gname != name ) {
471  objectNames(SkyObject::STAR).append( star -> gname(false) );
472  }
473 
474  m_ObjectList.append( star );
475 
476  m_starIndex->at( trixel )->append( star );
477  double pm = star->pmMagnitude();
478  for (int j = 0; j < m_highPMStars.size(); j++ ) {
479  HighPMStarList* list = m_highPMStars.at( j );
480  if ( list->append( trixel, star, pm ) ) break;
481  }
482 
483  if( star->getHDIndex() != 0 )
484  m_HDHash.insert( star->getHDIndex(), star );
485 
486  }
487 
488  }
489 
490  dataReader.closeFile();
491  nameReader.closeFile();
492 
493  starsLoaded = true;
494  return true;
495 
496 }
497 
498 SkyObject* StarComponent::findStarByGenetiveName( const QString name ) {
499  return m_genName.value( name );
500 }
501 
502 // Overrides ListComponent::findByName() to include genetive name and HD index also in the search
503 SkyObject* StarComponent::findByName( const QString &name ) {
504  foreach(SkyObject* o, m_ObjectList) {
505  if ( QString::compare( o->name(), name, Qt::CaseInsensitive ) == 0 ||
506  QString::compare( o->longname(), name, Qt::CaseInsensitive ) == 0 ||
507  QString::compare( o->name2(), name, Qt::CaseInsensitive ) == 0 ||
508  QString::compare( ((StarObject *)o)->gname(false), name, Qt::CaseInsensitive ) == 0)
509  return o;
510  }
511  return 0;
512 }
513 
514 void StarComponent::objectsInArea( QList<SkyObject*>& list, const SkyRegion& region )
515 {
516  for( SkyRegion::const_iterator it = region.constBegin(); it != region.constEnd(); ++it )
517  {
518  Trixel trixel = it.key();
519  StarList* starlist = m_starIndex->at( trixel );
520  for( int i = 0; starlist && i < starlist->size(); i++ )
521  if( starlist->at(i) && starlist->at(i)->name() != QString("star") )
522  list.push_back( starlist->at(i) );
523  }
524 }
525 
526 SkyObject *StarComponent::findByHDIndex( int HDnum ) {
527  KStarsData* data = KStarsData::Instance();
528  SkyObject *o;
529  BinFileHelper hdidxReader;
530  // First check the hash to see if we have a corresponding StarObject already
531  if( ( o = m_HDHash.value( HDnum, NULL ) ) )
532  return o;
533  // If we don't have the StarObject here, try it in the DeepStarComponents' hashes
534  if( m_DeepStarComponents.size() >= 1 )
535  if( ( o = m_DeepStarComponents.at( 0 )->findByHDIndex( HDnum ) ) )
536  return o;
537  if( m_DeepStarComponents.size() >= 2 ) {
538  qint32 offset;
539  FILE *hdidxFile = hdidxReader.openFile( "Henry-Draper.idx" );
540  if( !hdidxFile )
541  return 0;
542  FILE *dataFile;
543  KDE_fseek( hdidxFile, (HDnum - 1) * 4, SEEK_SET );
544  // TODO: Offsets need to be byteswapped if this is a big endian machine.
545  // This means that the Henry Draper Index needs a endianness indicator.
546  fread( &offset, 4, 1, hdidxFile );
547  if( offset <= 0 )
548  return 0;
549  dataFile = m_DeepStarComponents.at( 1 )->getStarReader()->getFileHandle();
550  KDE_fseek( dataFile, offset, SEEK_SET );
551  fread( &stardata, sizeof( starData ), 1, dataFile );
552  if( m_DeepStarComponents.at( 1 )->getStarReader()->getByteSwap() ) {
553  byteSwap( &stardata );
554  }
555  m_starObject.init( &stardata );
556  m_starObject.EquatorialToHorizontal( data->lst(), data->geo()->lat() );
557  m_starObject.JITupdate();
558  focusStar = &m_starObject;
559  hdidxReader.closeFile();
560  return focusStar;
561  }
562 
563  return 0;
564 }
565 
566 // This uses the main star index for looking up nearby stars but then
567 // filters out objects with the generic name "star". We could easily
568 // build an index for just the named stars which would make this go
569 // much faster still. -jbb
570 //
571 SkyObject* StarComponent::objectNearest( SkyPoint *p, double &maxrad )
572 {
573  SkyObject *oBest = 0;
574 
575  MeshIterator region( m_skyMesh, OBJ_NEAREST_BUF );
576 
577  while ( region.hasNext() ) {
578  Trixel currentRegion = region.next();
579  StarList* starList = m_starIndex->at( currentRegion );
580  for (int i=0; i < starList->size(); ++i) {
581  StarObject* star = starList->at( i );
582  if( !star ) continue;
583  if ( star->mag() > m_zoomMagLimit ) continue;
584 
585  double r = star->angularDistanceTo( p ).Degrees();
586  if ( r < maxrad ) {
587  oBest = star;
588  maxrad = r;
589  }
590  }
591  }
592 
593  // Check up with our Deep Star Components too!
594  double rTry, rBest;
595  SkyObject *oTry;
596  rBest = maxrad;
597  rTry = maxrad;
598  for( int i = 0; i < m_DeepStarComponents.size(); ++i ) {
599  oTry = m_DeepStarComponents.at( i )->objectNearest( p, rTry );
600  // TODO: Should we multiply rBest by a factor < 1, so that we give higher priority to named stars?
601  if( rTry < rBest ) {
602  rBest = rTry;
603  oBest = oTry;
604  }
605  }
606  maxrad = rBest;
607 
608  return oBest;
609 }
610 
611 void StarComponent::starsInAperture( QList<StarObject*> &list, const SkyPoint &center, float radius, float maglim )
612 {
613  // Ensure that we have deprecessed the (RA, Dec) to (RA0, Dec0)
614  Q_ASSERT( center.ra0().Degrees() >= 0.0 );
615  Q_ASSERT( center.dec0().Degrees() <= 90.0 );
616 
617  m_skyMesh->intersect( center.ra0().Degrees(), center.dec0().Degrees(), radius, (BufNum) OBJ_NEAREST_BUF );
618 
619  MeshIterator region( m_skyMesh, OBJ_NEAREST_BUF );
620 
621  if( maglim < -28 )
622  maglim = m_FaintMagnitude;
623 
624  while ( region.hasNext() ) {
625  Trixel currentRegion = region.next();
626  StarList* starList = m_starIndex->at( currentRegion );
627  for (int i=0; i < starList->size(); ++i) {
628  StarObject* star = starList->at( i );
629  if( !star ) continue;
630  if ( star->mag() > m_FaintMagnitude ) continue;
631  if( star->angularDistanceTo( &center ).Degrees() <= radius )
632  list.append( star );
633  }
634  }
635 
636  // Add stars from the DeepStarComponents as well
637  for( int i =0; i < m_DeepStarComponents.size(); ++i ) {
638  m_DeepStarComponents.at( i )->starsInAperture( list, center, radius, maglim );
639  }
640 }
641 
642 void StarComponent::byteSwap( starData *stardata ) {
643  stardata->RA = bswap_32( stardata->RA );
644  stardata->Dec = bswap_32( stardata->Dec );
645  stardata->dRA = bswap_32( stardata->dRA );
646  stardata->dDec = bswap_32( stardata->dDec );
647  stardata->parallax = bswap_32( stardata->parallax );
648  stardata->HD = bswap_32( stardata->HD );
649  stardata->mag = bswap_16( stardata->mag );
650  stardata->bv_index = bswap_16( stardata->bv_index );
651 }
652 /*
653 void StarComponent::printDebugInfo() {
654 
655  int nTrixels = 0;
656  int nBlocks = 0;
657  long int nStars = 0;
658  float faintMag = -5.0;
659 
660  MeshIterator trixels( m_skyMesh, DRAW_BUF );
661  Trixel trixel;
662 
663  while( trixels.hasNext() ) {
664  trixel = trixels.next();
665  nTrixels++;
666  for(int i = 0; i < m_starBlockList[ trixel ]->getBlockCount(); ++i) {
667  nBlocks++;
668  StarBlock *block = m_starBlockList[ trixel ]->block( i );
669  for(int j = 0; j < block->getStarCount(); ++j) {
670  nStars++;
671  }
672  if( block->getFaintMag() > faintMag ) {
673  faintMag = block->getFaintMag();
674  }
675  }
676  }
677 
678  printf( "========== UNNAMED STAR MEMORY ALLOCATION INFORMATION ==========\n" );
679  printf( "Number of visible trixels = %8d\n", nTrixels );
680  printf( "Number of visible StarBlocks = %8d\n", nBlocks );
681  printf( "Number of StarBlocks allocated via SBF = %8d\n", m_StarBlockFactory.getBlockCount() );
682  printf( "Number of unnamed stars in memory = %8ld\n", nStars );
683  printf( "Magnitude of the faintest star in memory = %8.2f\n", faintMag );
684  printf( "Target magnitude limit = %8.2f\n", magLim );
685  printf( "Size of each StarBlock = %8d bytes\n", sizeof( StarBlock ) );
686  printf( "Size of each StarObject = %8d bytes\n", sizeof( StarObject ) );
687  printf( "Memory use due to visible unnamed stars = %8.2f MB\n", ( sizeof( StarObject ) * nStars / 1048576.0 ) );
688  printf( "Memory use due to visible StarBlocks = %8d bytes\n", sizeof( StarBlock ) * nBlocks );
689  printf( "Memory use due to StarBlocks in SBF = %8d bytes\n", sizeof( StarBlock ) * m_StarBlockFactory.getBlockCount() );
690  printf( "=============== STAR DRAW LOOP TIMING INFORMATION ==============\n" );
691  printf( "Time taken for drawing named stars = %8ld ms\n", t_drawNamed );
692  printf( "Time taken for dynamic load of data = %8ld ms\n", t_dynamicLoad );
693  printf( "Time taken for updating LRU cache = %8ld ms\n", t_updateCache );
694  printf( "Time taken for drawing unnamed stars = %8ld ms\n", t_drawUnnamed );
695  printf( "================================================================\n" );
696 }
697 
698 bool StarComponent::verifySBLIntegrity() {
699 
700  float faintMag = -5.0;
701  bool integrity = true;
702  for(Trixel trixel = 0; trixel < m_skyMesh->size(); ++trixel) {
703  for(int i = 0; i < m_starBlockList[ trixel ]->getBlockCount(); ++i) {
704  StarBlock *block = m_starBlockList[ trixel ]->block( i );
705  if( i == 0 )
706  faintMag = block->getBrightMag();
707  // NOTE: Assumes 2 decimal places in magnitude field. TODO: Change if it ever does change
708  if( block->getBrightMag() != faintMag && ( block->getBrightMag() - faintMag ) > 0.016) {
709  kDebug() << "Trixel " << trixel << ": ERROR: faintMag of prev block = " << faintMag
710  << ", brightMag of block #" << i << " = " << block->getBrightMag();
711  integrity = false;
712  }
713  if( i > 1 && ( !block->prev ) )
714  kDebug() << "Trixel " << trixel << ": ERROR: Block" << i << "is unlinked in LRU Cache";
715  if( block->prev && block->prev->parent == m_starBlockList[ trixel ]
716  && block->prev != m_starBlockList[ trixel ]->block( i - 1 ) ) {
717  kDebug() << "Trixel " << trixel << ": ERROR: SBF LRU Cache linked list seems to be broken at before block " << i << endl;
718  integrity = false;
719  }
720  faintMag = block->getFaintMag();
721  }
722  }
723  return integrity;
724 }
725 */
SkyQPainter::initStarImages
static void initStarImages()
Recalculates the star pixmaps.
Definition: skyqpainter.cpp:140
starData::mag
qint16 mag
Definition: stardata.h:35
StarBlockFactory::drawID
quint32 drawID
Definition: starblockfactory.h:99
SkyPainter::drawPointSource
virtual bool drawPointSource(SkyPoint *loc, float mag, char sp= 'A')=0
Draw a point source (e.g., a star).
starData
Structure that holds star data.
Definition: stardata.h:28
SkyPoint::dec0
const dms & dec0() const
Definition: skypoint.h:168
StarObject::JITupdate
void JITupdate()
added for JIT updates from both StarComponent and ConstellationLines
Definition: starobject.cpp:317
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
SkyComponent::parent
SkyComposite * parent()
Definition: skycomponent.h:82
HighPMStarList::append
bool append(Trixel trixel, StarObject *star, double pm)
Definition: highpmstarlist.cpp:46
starData::RA
qint32 RA
Definition: stardata.h:29
DeepStarComponent
Stores and manages unnamed stars, most of which are dynamically loaded into memory.
Definition: deepstarcomponent.h:49
StarObject::reindexInterval
static double reindexInterval(double pm)
returns the reindex interval (in centuries!) for the given magnitude of proper motion (in milliarcsec...
Definition: starobject.cpp:49
KStarsData::updateID
unsigned int updateID()
Definition: kstarsdata.h:224
SkyRegion
QHash< Trixel, bool > SkyRegion
Definition: skycomponents/typedef.h:47
StarComponent::drawLabels
void drawLabels()
Definition: starcomponent.cpp:340
Options::hideStars
static bool hideStars()
Get Hide faint stars while moving?
Definition: Options.h:1322
SkyObject::longname
virtual QString longname(void) const
Definition: skyobject.h:140
ListComponent::m_ObjectList
QList< SkyObject * > m_ObjectList
Definition: listcomponent.h:64
starData::dRA
qint32 dRA
Definition: stardata.h:31
MAX_LINENUMBER_MAG
#define MAX_LINENUMBER_MAG
Definition: deepskycomponent.h:41
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
starcomponent.h
UpdateID
quint32 UpdateID
Definition: skycomponents/typedef.h:41
BinFileHelper::closeFile
void closeFile()
Close the binary data file.
Definition: binfilehelper.cpp:223
skypainter.h
Options::starDensity
static int starDensity()
Get Density of stars in the field of view.
Definition: Options.h:2626
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
skylabel.h
StarObject::setNames
void setNames(QString name, QString name2)
Sets the name, genetive name, and long name.
Definition: starobject.cpp:225
StarComponent::objectNearest
virtual SkyObject * objectNearest(SkyPoint *p, double &maxrad)
Find the SkyObject nearest the given SkyPoint.
Definition: starcomponent.cpp:571
HTMesh::size
int size() const
Definition: HTMesh.h:125
SkyPoint::ra0
const dms & ra0() const
Definition: skypoint.h:165
ListComponent
An abstract parent class, to be inherited by SkyComponents that store a QList of SkyObjects.
Definition: listcomponent.h:36
Options::hideOnSlew
static bool hideOnSlew()
Get Hide objects while moving?
Definition: Options.h:1094
SkyMesh::indexStar
Trixel indexStar(StarObject *star)
Definition: skymesh.cpp:98
MAXZOOM
#define MAXZOOM
Definition: kstarsdata.h:39
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
BinFileHelper::getRecordCount
unsigned int getRecordCount(int id)
Returns the number of records under the given index ID.
Definition: binfilehelper.h:146
BinFileHelper::getError
QString getError()
Get error string.
Definition: binfilehelper.cpp:234
SkyLabeler::Instance
static SkyLabeler * Instance()
Definition: skylabeler.cpp:49
KStarsData::updateNum
KSNumbers * updateNum()
Definition: kstarsdata.h:226
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
Projector
This class serves as an interface to handle projections.
Definition: projector.h:49
StarComponent::objectsInArea
virtual void objectsInArea(QList< SkyObject * > &list, const SkyRegion &region)
Searches the region(s) and appends the SkyObjects found to the list of sky objects.
Definition: starcomponent.cpp:514
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
BinFileHelper::testFileExists
static bool testFileExists(const QString &fileName)
Checks if a file exists.
Definition: binfilehelper.cpp:56
BinFileHelper
This class provides utility functions to handle binary data files in the format prescribed by KStars...
Definition: binfilehelper.h:52
StarObject::updateID
quint64 updateID
Definition: starobject.h:265
BinFileHelper::openFile
FILE * openFile(const QString &fileName)
WARNING: This function may not be compatible in other locales, because it calls QString::toAscii.
Definition: binfilehelper.cpp:69
starData::Dec
qint32 Dec
Definition: stardata.h:30
BinFileHelper::getErrorNumber
int getErrorNumber()
Get error number.
Definition: binfilehelper.cpp:228
MINZOOM
#define MINZOOM
Definition: kstarsdata.h:38
bswap_32
#define bswap_32(x)
Definition: byteorder.h:52
BinFileHelper::getDataOffset
long getDataOffset()
Returns the offset at which the data begins.
Definition: binfilehelper.h:194
starData::bv_index
qint16 bv_index
Definition: stardata.h:36
StarComponent::zoomMagnitudeLimit
static float zoomMagnitudeLimit()
Definition: starcomponent.cpp:199
StarObject::getHDIndex
int getHDIndex() const
Definition: starobject.h:226
SkyMap::isSlewing
bool isSlewing() const
Definition: skymap.cpp:1133
SkyPainter::setSizeMagLimit
void setSizeMagLimit(float sizeMagLim)
Definition: skypainter.cpp:45
skymap.h
i18nc
i18nc("string from libindi, used in the config dialog","100x")
kstarssplash.h
starblockfactory.h
starData::dDec
qint32 dDec
Definition: stardata.h:32
StarComponent::draw
void draw(SkyPainter *skyp)
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
Definition: starcomponent.cpp:232
HighPMStarList
Definition: highpmstarlist.h:40
SkyMesh::Instance
static SkyMesh * Instance()
Definition: skymesh.cpp:48
SkyComposite
SkyComposite is a kind of container class for SkyComponent objects.
Definition: skycomposite.h:43
BinFileHelper::getByteSwap
bool getByteSwap()
Should we do byte swapping?
Definition: binfilehelper.h:159
StarComponent::Create
static StarComponent * Create(SkyComposite *)
Create an instance of StarComponent.
Definition: starcomponent.cpp:86
StarComponent::update
virtual void update(KSNumbers *num)
Update the sky positions of this component.
Definition: starcomponent.cpp:124
SkyLabel
Definition: skylabel.h:28
BufNum
unsigned short BufNum
Definition: htmesh/typedef.h:5
StarObject::spchar
char spchar() const
Returns just the first character of the spectral type string.
Definition: starobject.cpp:344
byteorder.h
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
BinFileHelper::readHeader
bool readHeader()
Read the header and index table from the file and fill up the QVector s with the entries.
Definition: binfilehelper.cpp:200
MeshIterator
Definition: MeshIterator.h:22
Options.h
SkyObject::name2
QString name2(void) const
Definition: skyobject.h:132
MeshIterator::hasNext
bool hasNext() const
Definition: MeshIterator.h:29
binfilehelper.h
SkyObject::mag
float mag(void) const
Definition: skyobject.h:182
SkyMesh::setKSNumbers
void setKSNumbers(KSNumbers *num)
Definition: skymesh.h:163
StarObject::pmMagnitude
double pmMagnitude()
returns the magnitude of the proper motion correction in milliarcsec/year
Definition: starobject.h:180
Options::starLabelDensity
static double starLabelDensity()
Get Relative density for star name labels and/or magnitudes.
Definition: Options.h:2664
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
StarComponent::findByHDIndex
SkyObject * findByHDIndex(int HDnum)
Find stars by HD catalog index.
Definition: starcomponent.cpp:526
OBJ_NEAREST_BUF
Definition: skymesh.h:54
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
KStarsSplash
The KStars Splash Screen.
Definition: kstarssplash.h:30
StarComponent::selected
bool selected()
Definition: starcomponent.cpp:92
StarIndex
QVector< StarList * > StarIndex
Definition: skycomponents/typedef.h:49
J2000
#define J2000
Definition: kstarsdatetime.h:21
StarComponent::starsInAperture
void starsInAperture(QList< StarObject * > &list, const SkyPoint &center, float radius, float maglim=-29)
Add to the given list, the stars from this component, that lie within the specified circular aperture...
Definition: starcomponent.cpp:611
Options::magLimitHideStar
static double magLimitHideStar()
Get Faint limit for stars when slewing.
Definition: Options.h:2645
StarObject::init
void init(const starData *stardata)
Initializes a StarObject to given data.
Definition: starobject.cpp:133
StarBlockFactory::Instance
static StarBlockFactory * Instance()
Definition: starblockfactory.cpp:29
Options::zoomFactor
static double zoomFactor()
Get Zoom Factor, in pixels per radian.
Definition: Options.h:2531
skyqpainter.h
HTMesh::level
int level() const
Definition: HTMesh.h:129
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
SkyLabeler::setPen
void setPen(const QPen &pen)
sets the pen used for drawing labels on the sky.
Definition: skylabeler.cpp:173
SkyLabeler::drawNameLabel
bool drawNameLabel(SkyObject *obj, const QPointF &_p)
Tries to draw a label for an object.
Definition: skylabeler.cpp:151
starData::HD
qint32 HD
Definition: stardata.h:34
MeshIterator::next
Trixel next() const
Definition: MeshIterator.h:33
SkyComponent::emitProgressText
virtual void emitProgressText(const QString &message)
Emit signal about progress.
Definition: skycomponent.cpp:35
Options::showStars
static bool showStars()
Get Draw stars in the sky map?
Definition: Options.h:2177
kstarsdata.h
StarComponent::byteSwap
static void byteSwap(starData *stardata)
Definition: starcomponent.cpp:642
skylabeler.h
skymesh.h
SkyLabeler
The purpose of this class is to prevent labels from overlapping.
Definition: skylabeler.h:112
starData::flags
char flags
Definition: stardata.h:38
StarComponent::StarComponent
StarComponent(SkyComposite *)
Definition: starcomponent.cpp:55
SkyObject::name
virtual QString name(void) const
Definition: skyobject.h:124
Options::showStarNames
static bool showStarNames()
Get Label star names in the sky map?
Definition: Options.h:2215
starData::parallax
qint32 parallax
Definition: stardata.h:33
bswap_16
#define bswap_16(x)
Definition: byteorder.h:47
KSNumbers::julianCenturies
double julianCenturies() const
Definition: ksnumbers.h:90
SkyComponent::objectNames
QHash< int, QStringList > & objectNames()
Definition: skycomponent.h:127
StarObject
This is a subclass of SkyObject.
Definition: starobject.h:41
SkyObject::STAR
Definition: skyobject.h:108
SkyObject
Provides all necessary information about an object in the sky: its coordinates, name(s), type, magnitude, and QStringLists of URLs for images and webpages regarding the object.
Definition: skyobject.h:46
SkyMap::projector
const Projector * projector() const
Get the current projector.
Definition: skymap.h:264
SkyPainter
Draws things on the sky, without regard to backend.
Definition: skypainter.h:47
SkyPoint::angularDistanceTo
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=0) const
Computes the angular distance between two SkyObjects.
Definition: skypoint.cpp:608
StarComponent
Represents the stars on the sky map.
Definition: starcomponent.h:59
StarComponent::findStarByGenetiveName
virtual SkyObject * findStarByGenetiveName(const QString name)
Definition: starcomponent.cpp:498
SkyMesh::drawID
DrawID drawID()
Definition: skymesh.h:277
QList
StarComponent::findByName
virtual SkyObject * findByName(const QString &name)
Find stars by name (including genetive name)
Definition: starcomponent.cpp:503
Options::showStarMagnitudes
static bool showStarMagnitudes()
Get Label star magnitudes in the sky map?
Definition: Options.h:2196
StarComponent::~StarComponent
virtual ~StarComponent()
Definition: starcomponent.cpp:82
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