• 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
linelistindex.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  linelistindex.cpp - K Desktop Planetarium
3  -------------------
4  begin : 2007-07-04
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 /****************************************************************************
19  * The filled polygon code in the innermost loops below in drawFilled*() below
20  * implements the Sutherland-Hodgman's Polygon clipping algorithm. Please
21  * don't mess with it unless you ensure that the Milky Way clipping continues
22  * to work. The line clipping uses a similar but slightly less complicated
23  * algorithm.
24  *
25  * Since the clipping code is a bit messy, there are four versions of the
26  * inner loop for Filled/Outline * Integer/Float. This moved these two
27  * decisions out of the inner loops to make them a bit faster and less
28  * messy.
29  *
30  * -- James B. Bowlin
31  *
32  ****************************************************************************/
33 
34 #include "linelistindex.h"
35 
36 #include <QBrush>
37 
38 #include <kdebug.h>
39 #include <klocale.h>
40 
41 #include "Options.h"
42 #include "kstarsdata.h"
43 #include "skyobjects/skyobject.h"
44 #include "skymap.h"
45 
46 #include "skymesh.h"
47 #include "linelist.h"
48 
49 #include "skypainter.h"
50 
51 
52 LineListIndex::LineListIndex( SkyComposite *parent, const QString& name ) :
53  SkyComponent( parent ),
54  m_name(name)
55 {
56  m_skyMesh = SkyMesh::Instance();
57  m_lineIndex = new LineListHash();
58  m_polyIndex = new LineListHash();
59 }
60 
61 LineListIndex::~LineListIndex()
62 {
63  delete m_lineIndex;
64  delete m_polyIndex;
65 }
66 
67 // This is a callback for the indexLines() function below
68 const IndexHash& LineListIndex::getIndexHash(LineList* lineList ) {
69  return skyMesh()->indexLine( lineList->points() );
70 }
71 
72 
73 void LineListIndex::appendLine( LineList* lineList, int debug)
74 {
75  if( debug < skyMesh()->debug() )
76  debug = skyMesh()->debug();
77 
78  const IndexHash& indexHash = getIndexHash( lineList );
79  IndexHash::const_iterator iter = indexHash.constBegin();
80  while ( iter != indexHash.constEnd() ) {
81  Trixel trixel = iter.key();
82  iter++;
83 
84  if ( ! m_lineIndex->contains( trixel ) ) {
85  m_lineIndex->insert(trixel, new LineListList() );
86  }
87  m_lineIndex->value( trixel )->append( lineList );
88  }
89 
90  m_listList.append( lineList);
91 }
92 
93 void LineListIndex::appendPoly(LineList* lineList, int debug)
94 {
95  if ( debug < skyMesh()->debug() ) debug = skyMesh()->debug();
96 
97  const IndexHash& indexHash = skyMesh()->indexPoly( lineList->points() );
98  IndexHash::const_iterator iter = indexHash.constBegin();
99  while ( iter != indexHash.constEnd() ) {
100  Trixel trixel = iter.key();
101  iter++;
102 
103  if ( ! m_polyIndex->contains( trixel ) ) {
104  m_polyIndex->insert( trixel, new LineListList() );
105  }
106  m_polyIndex->value( trixel )->append( lineList );
107  }
108 }
109 
110 void LineListIndex::appendBoth(LineList* lineList, int debug)
111 {
112  appendLine( lineList, debug );
113  appendPoly( lineList, debug );
114 }
115 
116 void LineListIndex::reindexLines()
117 {
118  LineListHash* oldIndex = m_lineIndex;
119  m_lineIndex = new LineListHash();
120 
121  DrawID drawID = skyMesh()->incDrawID();
122 
123  foreach (LineListList* listList, *oldIndex ) {
124  for ( int i = 0; i < listList->size(); i++) {
125  LineList* lineList = listList->at( i );
126  if ( lineList->drawID == drawID ) continue;
127  lineList->drawID = drawID;
128  appendLine( lineList );
129  }
130  delete listList;
131  }
132  delete oldIndex;
133 }
134 
135 
136 void LineListIndex::JITupdate( LineList* lineList )
137 {
138  KStarsData *data = KStarsData::Instance();
139  lineList->updateID = data->updateID();
140  SkyList* points = lineList->points();
141 
142  if ( lineList->updateNumID != data->updateNumID() ) {
143  lineList->updateNumID = data->updateNumID();
144  KSNumbers* num = data->updateNum();
145  for (int i = 0; i < points->size(); i++ ) {
146  points->at( i )->updateCoords( num );
147  }
148  }
149 
150  for (int i = 0; i < points->size(); i++ ) {
151  points->at( i )->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
152  }
153 }
154 
155 
156 // This is a callback used in draw() below
157 void LineListIndex::preDraw( SkyPainter *skyp )
158 {
159  skyp->setPen( QPen( QBrush( QColor( "white" ) ), 1, Qt::SolidLine ) );
160 }
161 
162 void LineListIndex::draw( SkyPainter *skyp )
163 {
164  if ( ! selected() )
165  return;
166  preDraw( skyp );
167  drawLines( skyp );
168 }
169 
170 // This is a callback used int drawLinesInt() and drawLinesFloat()
171 SkipList* LineListIndex::skipList( LineList *lineList )
172 {
173  Q_UNUSED(lineList)
174  return 0;
175 }
176 
177 void LineListIndex::drawLines( SkyPainter *skyp )
178 {
179  DrawID drawID = skyMesh()->drawID();
180  UpdateID updateID = KStarsData::Instance()->updateID();
181 
182  foreach ( LineListList* lineListList, m_lineIndex->values() ) {
183  for (int i = 0; i < lineListList->size(); i++) {
184  LineList* lineList = lineListList->at( i );
185 
186  if ( lineList->drawID == drawID )
187  continue;
188  lineList->drawID = drawID;
189 
190  if ( lineList->updateID != updateID )
191  JITupdate( lineList );
192 
193  skyp->drawSkyPolyline(lineList, skipList(lineList), label() );
194  }
195  }
196 }
197 
198 void LineListIndex::drawFilled( SkyPainter *skyp )
199 {
200  DrawID drawID = skyMesh()->drawID();
201  UpdateID updateID = KStarsData::Instance()->updateID();
202 
203  MeshIterator region( skyMesh(), drawBuffer() );
204  while ( region.hasNext() ) {
205 
206  LineListList* lineListList = m_polyIndex->value( region.next() );
207  if ( lineListList == 0 ) continue;
208 
209  for (int i = 0; i < lineListList->size(); i++) {
210  LineList* lineList = lineListList->at( i );
211 
212  // draw each Linelist at most once
213  if ( lineList->drawID == drawID ) continue;
214  lineList->drawID = drawID;
215 
216  if ( lineList->updateID != updateID )
217  JITupdate( lineList );
218 
219  skyp->drawSkyPolygon(lineList);
220  }
221  }
222 }
223 
224 void LineListIndex::intro()
225 {
226  emitProgressText( i18n( "Loading %1", m_name ));
227 
228  if ( skyMesh()->debug() >= 1 )
229  kDebug() << QString("Loading %1 ...").arg( m_name );
230 }
231 
232 void LineListIndex::summary()
233 {
234  if ( skyMesh()->debug() < 2 )
235  return;
236 
237  int total = skyMesh()->size();
238  int polySize = m_polyIndex->size();
239  int lineSize = m_lineIndex->size();
240 
241  if ( lineSize > 0 )
242  printf("%4d out of %4d trixels in line index %3d%%\n",
243  lineSize, total, 100 * lineSize / total );
244 
245  if ( polySize > 0 )
246  printf("%4d out of %4d trixels in poly index %3d%%\n",
247  polySize, total, 100 * polySize / total );
248 
249 }
LineList::at
SkyPoint * at(int i)
Definition: linelist.h:54
SkyMesh::indexPoly
const IndexHash & indexPoly(SkyList *points)
Definition: skymesh.cpp:241
SkyList
QVector< SkyPoint * > SkyList
Definition: skycomponents/typedef.h:45
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
KStarsData::updateID
unsigned int updateID()
Definition: kstarsdata.h:224
LineListIndex::appendPoly
void appendPoly(LineList *lineList, int debug=0)
Definition: linelistindex.cpp:93
LineList::drawID
DrawID drawID
Definition: linelist.h:46
LineListIndex::reindexLines
void reindexLines()
Definition: linelistindex.cpp:116
LineListIndex::getIndexHash
virtual const IndexHash & getIndexHash(LineList *lineList)
Definition: linelistindex.cpp:68
skyobject.h
LineListIndex::drawBuffer
virtual MeshBufNum_t drawBuffer()
Definition: linelistindex.h:134
SkyMesh::incDrawID
int incDrawID()
Definition: skymesh.h:284
KStarsData::lst
dms * lst()
Definition: kstarsdata.h:161
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
UpdateID
quint32 UpdateID
Definition: skycomponents/typedef.h:41
LineListIndex::listList
LineListList listList()
Definition: linelistindex.h:153
LineListIndex::skipList
virtual SkipList * skipList(LineList *lineList)
Also overridden by SkipListIndex.
Definition: linelistindex.cpp:171
SkyComponent
SkyComponent represents an object on the sky map.
Definition: skycomponent.h:44
skypainter.h
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
LineListIndex::preDraw
virtual void preDraw(SkyPainter *skyp)
Definition: linelistindex.cpp:157
KStarsData::updateNumID
unsigned int updateNumID()
Definition: kstarsdata.h:225
LineListIndex::label
virtual LineListLabel * label()
Definition: linelistindex.h:151
LineListHash
QHash< Trixel, LineListList * > LineListHash
Definition: skycomponents/typedef.h:51
HTMesh::size
int size() const
Definition: HTMesh.h:125
LineList
Definition: linelist.h:35
SkyMesh::debug
int debug()
Definition: skymesh.h:268
LineListIndex::intro
void intro()
Definition: linelistindex.cpp:224
LineListList
QVector< LineList * > LineListList
Definition: skycomponents/typedef.h:50
LineListIndex::appendLine
void appendLine(LineList *lineList, int debug=0)
Definition: linelistindex.cpp:73
KStarsData::updateNum
KSNumbers * updateNum()
Definition: kstarsdata.h:226
LineList::points
SkyList * points()
Definition: linelist.h:53
LineListIndex::JITupdate
virtual void JITupdate(LineList *lineList)
Definition: linelistindex.cpp:136
linelist.h
linelistindex.h
skymap.h
LineListIndex::~LineListIndex
~LineListIndex()
Definition: linelistindex.cpp:61
LineListIndex::LineListIndex
LineListIndex(SkyComposite *parent, const QString &name="")
Definition: linelistindex.cpp:52
LineListIndex::drawLines
void drawLines(SkyPainter *skyp)
Definition: linelistindex.cpp:177
SkyMesh::Instance
static SkyMesh * Instance()
Definition: skymesh.cpp:48
SkyComposite
SkyComposite is a kind of container class for SkyComponent objects.
Definition: skycomposite.h:43
SkyPainter::setPen
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
Trixel
unsigned int Trixel
Definition: htmesh/typedef.h:4
MeshIterator
Definition: MeshIterator.h:22
Options.h
MeshIterator::hasNext
bool hasNext() const
Definition: MeshIterator.h:29
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
SkyPainter::drawSkyPolygon
virtual void drawSkyPolygon(LineList *list)=0
Draw a polygon in the sky.
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
LineListIndex::skyMesh
SkyMesh * skyMesh()
Definition: linelistindex.h:92
LineListIndex::drawFilled
void drawFilled(SkyPainter *skyp)
Definition: linelistindex.cpp:198
LineListIndex::appendBoth
void appendBoth(LineList *lineList, int debug=0)
Definition: linelistindex.cpp:110
LineList::updateNumID
UpdateID updateNumID
Definition: linelist.h:48
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
LineListIndex::summary
void summary()
Definition: linelistindex.cpp:232
SkyComponent::emitProgressText
virtual void emitProgressText(const QString &message)
Emit signal about progress.
Definition: skycomponent.cpp:35
kstarsdata.h
skymesh.h
LineList::updateID
UpdateID updateID
Definition: linelist.h:47
DrawID
quint32 DrawID
Definition: skycomponents/typedef.h:38
SkyComponent::selected
virtual bool selected()
Definition: skycomponent.h:79
SkyPainter
Draws things on the sky, without regard to backend.
Definition: skypainter.h:47
LineListIndex::draw
virtual void draw(SkyPainter *skyp)
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
Definition: linelistindex.cpp:162
SkyMesh::drawID
DrawID drawID()
Definition: skymesh.h:277
SkipList
Definition: SkipList.h:17
SkyPainter::drawSkyPolyline
virtual void drawSkyPolyline(LineList *list, SkipList *skipList=0, LineListLabel *label=0)=0
Draw a polyline in the sky.
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 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