• 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
constellationboundarylines.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  constellationboundarylines.cpp - K Desktop Planetarium
3  -------------------
4  begin : 25 Oct. 2005
5  copyright : (C) 2005 by Jason Harris
6  email : kstars@30doradus.org
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 "constellationboundarylines.h"
19 
20 #include <cstdio>
21 
22 #include <QPen>
23 #include <kstandarddirs.h>
24 
25 #include <kdebug.h>
26 #include <klocale.h>
27 
28 #include "Options.h"
29 #include "kstarsdata.h"
30 #include "skymap.h"
31 #include "skyobjects/skyobject.h"
32 #include "ksfilereader.h"
33 
34 #include "typedef.h"
35 #include "linelist.h"
36 #include "polylist.h"
37 #include "linelistindex.h"
38 #include "skycomponents/skymapcomposite.h"
39 
40 #include "skymesh.h"
41 
42 #include "skypainter.h"
43 
44 ConstellationBoundaryLines::ConstellationBoundaryLines( SkyComposite *parent )
45  : NoPrecessIndex( parent, i18n("Constellation Boundaries") )
46 {
47  m_skyMesh = SkyMesh::Instance();
48  m_polyIndexCnt = 0;
49  for(int i = 0; i < m_skyMesh->size(); i++) {
50  m_polyIndex.append( new PolyListList() );
51  }
52 
53  KStarsData *data = KStarsData::Instance();
54  int verbose = 0; // -1 => create cbounds-$x.idx on stdout
55  // 0 => normal
56  const char* fname = "cbounds.dat";
57  int flag;
58  double ra, dec, lastRa, lastDec;
59  LineList *lineList = 0;
60  PolyList *polyList = 0;
61  bool ok;
62 
63  intro();
64 
65  // Open the .idx file and skip past the first line
66  KSFileReader idxReader, *idxFile = 0;
67  QString idxFname = QString("cbounds-%1.idx").arg( SkyMesh::Instance()->level() );
68  if ( idxReader.open( idxFname ) ) {
69  idxReader.readLine();
70  idxFile = &idxReader;
71  }
72 
73  // now open the file that contains the points
74  KSFileReader fileReader;
75  if ( ! fileReader.open( fname ) ) return;
76 
77  fileReader.setProgress( i18n("Loading Constellation Boundaries"), 13124, 10 );
78 
79  lastRa = lastDec = -1000.0;
80 
81  while ( fileReader.hasMoreLines() ) {
82  QString line = fileReader.readLine();
83  fileReader.showProgress();
84 
85  if ( line.at( 0 ) == '#' ) continue; // ignore comments
86  if ( line.at( 0 ) == ':' ) { // :constellation line
87 
88  if ( lineList ) appendLine( lineList );
89  lineList = 0;
90 
91  if ( polyList )
92  appendPoly( polyList, idxFile, verbose );
93  QString cName = line.mid(1);
94  polyList = new PolyList( cName );
95  if ( verbose == -1 ) printf(":\n");
96  lastRa = lastDec = -1000.0;
97  continue;
98  }
99 
100  // read in the data from the line
101  ra = line.mid( 0, 12 ).toDouble( &ok );
102  if ( ok ) dec = line.mid( 13, 12 ).toDouble( &ok );
103  if ( ok ) flag = line.mid( 26, 1 ).toInt(&ok);
104  if ( !ok ) {
105  fprintf(stderr, "%s: conversion error on line: %d\n",
106  fname, fileReader.lineNumber() );
107  continue;
108  }
109 
110  if ( ra == lastRa && dec == lastDec ) {
111  fprintf(stderr, "%s: tossing dupe on line %4d: (%f, %f)\n",
112  fname, fileReader.lineNumber(), ra, dec);
113  continue;
114  }
115 
116  // always add the point to the boundary (and toss dupes)
117 
118  // By the time we come here, we should have polyList. Else we aren't doing good
119  Q_ASSERT( polyList ); // Is this the right fix?
120 
121  polyList->append( QPointF( ra, dec ) );
122  if ( ra < 0 )
123  polyList->setWrapRA( true );
124 
125  if ( flag ) {
126 
127  if ( ! lineList ) lineList = new LineList();
128 
129  SkyPoint* point = new SkyPoint( ra, dec );
130  point->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
131  lineList->append( point );
132  lastRa = ra;
133  lastDec = dec;
134  }
135  else {
136  if ( lineList ) appendLine( lineList );
137  lineList = 0;
138  lastRa = lastDec = -1000.0;
139  }
140  }
141 
142  if( lineList )
143  appendLine( lineList );
144  if( polyList )
145  appendPoly( polyList, idxFile, verbose );
146 }
147 
148 bool ConstellationBoundaryLines::selected()
149 {
150  return Options::showCBounds() &&
151  ! ( Options::hideOnSlew() && Options::hideCBounds() && SkyMap::IsSlewing() );
152 }
153 
154 void ConstellationBoundaryLines::preDraw( SkyPainter* skyp )
155 {
156  QColor color = KStarsData::Instance()->colorScheme()->colorNamed( "CBoundColor" );
157  skyp->setPen( QPen( QBrush( color ), 1, Qt::SolidLine ) );
158 }
159 
160 void ConstellationBoundaryLines::appendPoly( PolyList* polyList, KSFileReader* file, int debug)
161 {
162  if ( ! file || debug == -1)
163  return appendPoly( polyList, debug );
164 
165  while ( file->hasMoreLines() ) {
166  QString line = file->readLine();
167  if ( line.at( 0 ) == ':' ) return;
168  Trixel trixel = line.toInt();
169  m_polyIndex[ trixel ]->append( polyList );
170  }
171 }
172 
173 void ConstellationBoundaryLines::appendPoly( PolyList* polyList, int debug)
174 {
175  if ( debug >= 0 && debug < m_skyMesh->debug() ) debug = m_skyMesh->debug();
176 
177  const IndexHash& indexHash = m_skyMesh->indexPoly( polyList->poly() );
178  IndexHash::const_iterator iter = indexHash.constBegin();
179  while ( iter != indexHash.constEnd() ) {
180  Trixel trixel = iter.key();
181  iter++;
182 
183  if ( debug == -1 ) printf("%d\n", trixel );
184 
185  m_polyIndex[ trixel ]->append( polyList );
186  }
187 
188  if ( debug > 9 )
189  printf("PolyList: %3d: %d\n", ++m_polyIndexCnt, indexHash.size() );
190 }
191 
192 PolyList* ConstellationBoundaryLines::ContainingPoly( SkyPoint *p )
193 {
194  //printf("called ContainingPoly(p)\n");
195 
196  // we save the pointers in a hash because most often there is only one
197  // constellation and we can avoid doing the expensive boundary calculations
198  // and just return it if we know it is unique. We can avoid this minor
199  // complication entirely if we use index(p) instead of aperture(p, r)
200  // because index(p) always returns a single trixel index.
201 
202  QHash<PolyList*, bool> polyHash;
203  QHash<PolyList*, bool>::const_iterator iter;
204 
205  //printf("\n");
206 
207  // the boundaries don't precess so we use index() not aperture()
208  m_skyMesh->index( p, 1.0, IN_CONSTELL_BUF );
209  MeshIterator region( m_skyMesh, IN_CONSTELL_BUF );
210  while ( region.hasNext() ) {
211 
212  Trixel trixel = region.next();
213  //printf("Trixel: %4d %s\n", trixel, m_skyMesh->indexToName( trixel ) );
214 
215  PolyListList *polyListList = m_polyIndex[ trixel ];
216 
217  //printf(" size: %d\n", polyListList->size() );
218 
219  for (int i = 0; i < polyListList->size(); i++) {
220  PolyList* polyList = polyListList->at( i );
221  polyHash.insert( polyList, true );
222  }
223  }
224 
225  iter = polyHash.constBegin();
226 
227  // Don't bother with boundaries if there is only one
228  if ( polyHash.size() == 1 ) return iter.key();
229 
230  QPointF point( p->ra().Hours(), p->dec().Degrees() );
231  QPointF wrapPoint( p->ra().Hours() - 24.0, p->dec().Degrees() );
232  bool wrapRA = p->ra().Hours() > 12.0;
233 
234  while ( iter != polyHash.constEnd() ) {
235 
236  PolyList* polyList = iter.key();
237  iter++;
238 
239  //kDebug() << QString("checking %1 boundary\n").arg( polyList->name() );
240 
241  const QPolygonF* poly = polyList->poly();
242  if ( wrapRA && polyList->wrapRA() ) {
243  if ( poly->containsPoint( wrapPoint, Qt::OddEvenFill ) )
244  return polyList;
245  }
246  else {
247  if ( poly->containsPoint( point, Qt::OddEvenFill ) )
248  return polyList;
249  }
250  }
251 
252  return 0;
253 }
254 
255 
256 //-------------------------------------------------------------------
257 // The routines for providing public access to the boundary index
258 // start here. (Some of them may not be needed (or working)).
259 //-------------------------------------------------------------------
260 
261 QString ConstellationBoundaryLines::constellationName( SkyPoint *p )
262 {
263  PolyList *polyList = ContainingPoly( p );
264  if ( polyList ) {
265  return ( Options::useLocalConstellNames() ?
266  i18nc( "Constellation name (optional)", polyList->name().toUpper().toLocal8Bit().data() ) :
267  polyList->name() );
268  }
269  return i18n("Unknown");
270 }
SkyMesh::indexPoly
const IndexHash & indexPoly(SkyList *points)
Definition: skymesh.cpp:241
ConstellationBoundaryLines::preDraw
virtual void preDraw(SkyPainter *skyp)
Definition: constellationboundarylines.cpp:154
KSFileReader::hasMoreLines
bool hasMoreLines()
Definition: ksfilereader.h:108
PolyList::poly
const QPolygonF * poly()
Definition: polylist.h:41
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
ConstellationBoundaryLines::selected
virtual bool selected()
Definition: constellationboundarylines.cpp:148
KStarsData::colorScheme
ColorScheme * colorScheme()
Definition: kstarsdata.h:149
skyobject.h
PolyList::wrapRA
bool wrapRA()
Definition: polylist.h:51
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
typedef.h
PolyList::setWrapRA
void setWrapRA(bool wrap)
Definition: polylist.h:53
PolyList
Definition: polylist.h:32
polylist.h
ColorScheme::colorNamed
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:97
skypainter.h
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
HTMesh::size
int size() const
Definition: HTMesh.h:125
Options::hideOnSlew
static bool hideOnSlew()
Get Hide objects while moving?
Definition: Options.h:1094
LineList
Definition: linelist.h:35
SkyMesh::debug
int debug()
Definition: skymesh.h:268
NoPrecessIndex
Definition: noprecessindex.h:28
LineListIndex::intro
void intro()
Definition: linelistindex.cpp:224
LineListIndex::appendLine
void appendLine(LineList *lineList, int debug=0)
Definition: linelistindex.cpp:73
KSFileReader::open
bool open(const QString &fname)
Definition: ksfilereader.cpp:46
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
linelist.h
skymapcomposite.h
linelistindex.h
Options::showCBounds
static bool showCBounds()
Get Draw constellation boundaries in the sky map?
Definition: Options.h:1550
IN_CONSTELL_BUF
Definition: skymesh.h:55
skymap.h
i18nc
i18nc("string from libindi, used in the config dialog","100x")
KSFileReader::showProgress
void showProgress()
Definition: ksfilereader.cpp:83
SkyMesh::Instance
static SkyMesh * Instance()
Definition: skymesh.cpp:48
SkyComposite
SkyComposite is a kind of container class for SkyComponent objects.
Definition: skycomposite.h:43
SkyPoint::dec
const dms & dec() const
Definition: skypoint.h:174
dms::Hours
double Hours() const
Definition: dms.h:125
ConstellationBoundaryLines::ConstellationBoundaryLines
ConstellationBoundaryLines(SkyComposite *parent)
Constructor Simply adds all of the coordinate grid circles (meridians and parallels) parent Pointer t...
Definition: constellationboundarylines.cpp:44
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
constellationboundarylines.h
SkyPainter::setPen
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
Trixel
unsigned int Trixel
Definition: htmesh/typedef.h:4
PolyListList
QVector< PolyList * > PolyListList
Definition: constellationboundarylines.h:28
MeshIterator
Definition: MeshIterator.h:22
Options.h
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
ksfilereader.h
KSFileReader::readLine
QString readLine()
Definition: ksfilereader.h:113
KSFileReader
Definition: ksfilereader.h:65
PolyList::name
const QString & name()
Definition: polylist.h:49
KSFileReader::setProgress
void setProgress(QString label, unsigned int lastLine, unsigned int numUpdates=10)
Definition: ksfilereader.cpp:69
SkyMap::IsSlewing
static bool IsSlewing()
Definition: skymap.h:91
IndexHash
QHash< Trixel, bool > IndexHash
Definition: skycomponents/typedef.h:46
Options::hideCBounds
static bool hideCBounds()
Get Hide constellation boundaries while moving?
Definition: Options.h:1113
PolyList::append
void append(const QPointF &p)
Definition: polylist.h:46
LineList::append
void append(SkyPoint *p)
Definition: linelist.h:55
kstarsdata.h
skymesh.h
ConstellationBoundaryLines::constellationName
QString constellationName(SkyPoint *p)
Definition: constellationboundarylines.cpp:261
SkyMesh::index
Trixel index(const SkyPoint *p)
Definition: skymesh.cpp:93
SkyPainter
Draws things on the sky, without regard to backend.
Definition: skypainter.h:47
Options::useLocalConstellNames
static bool useLocalConstellNames()
Get Use localized constellation names?
Definition: Options.h:2367
KSFileReader::lineNumber
int lineNumber()
Definition: ksfilereader.h:120
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