Kstars

linelistindex.cpp
1/*
2 SPDX-FileCopyrightText: 2007 James B. Bowlin <bowlin@mindspring.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7/****************************************************************************
8 * The filled polygon code in the innermost loops below in drawFilled*() below
9 * implements the Sutherland-Hodgman's Polygon clipping algorithm. Please
10 * don't mess with it unless you ensure that the Milky Way clipping continues
11 * to work. The line clipping uses a similar but slightly less complicated
12 * algorithm.
13 *
14 * Since the clipping code is a bit messy, there are four versions of the
15 * inner loop for Filled/Outline * Integer/Float. This moved these two
16 * decisions out of the inner loops to make them a bit faster and less
17 * messy.
18 *
19 * -- James B. Bowlin
20 *
21 ****************************************************************************/
22
23#include "linelistindex.h"
24
25#include "Options.h"
26#include "kstarsdata.h"
27#include "linelist.h"
28#ifndef KSTARS_LITE
29#include "skymap.h"
30#endif
31#include "skypainter.h"
32#include "htmesh/MeshIterator.h"
33
34LineListIndex::LineListIndex(SkyComposite *parent, const QString &name) : SkyComponent(parent), m_name(name)
35{
36 m_skyMesh = SkyMesh::Instance();
37 m_lineIndex.reset(new LineListHash());
38 m_polyIndex.reset(new LineListHash());
39}
40
41// This is a callback for the indexLines() function below
43{
44 return skyMesh()->indexLine(lineList->points());
45}
46
47void LineListIndex::removeLine(const std::shared_ptr<LineList> &lineList)
48{
49 const IndexHash &indexHash = getIndexHash(lineList.get());
50 IndexHash::const_iterator iter = indexHash.constBegin();
51
52 while (iter != indexHash.constEnd())
53 {
54 Trixel trixel = iter.key();
55 iter++;
56
57 if (m_lineIndex->contains(trixel))
58 m_lineIndex->value(trixel)->removeOne(lineList);
59 }
60 m_listList.removeOne(lineList);
61}
62
63void LineListIndex::appendLine(const std::shared_ptr<LineList> &lineList)
64{
65 const IndexHash &indexHash = getIndexHash(lineList.get());
66 IndexHash::const_iterator iter = indexHash.constBegin();
67
68 while (iter != indexHash.constEnd())
69 {
70 Trixel trixel = iter.key();
71
72 iter++;
73 if (!m_lineIndex->contains(trixel))
74 {
75 m_lineIndex->insert(trixel, std::shared_ptr<LineListList>(new LineListList()));
76 }
77 m_lineIndex->value(trixel)->append(lineList);
78 }
79 m_listList.append(lineList);
80}
81
82void LineListIndex::appendPoly(const std::shared_ptr<LineList> &lineList)
83{
84 const IndexHash &indexHash = skyMesh()->indexPoly(lineList->points());
85 IndexHash::const_iterator iter = indexHash.constBegin();
86
87 while (iter != indexHash.constEnd())
88 {
89 Trixel trixel = iter.key();
90 iter++;
91
92 if (!m_polyIndex->contains(trixel))
93 {
94 m_polyIndex->insert(trixel, std::shared_ptr<LineListList>(new LineListList()));
95 }
96 m_polyIndex->value(trixel)->append(lineList);
97 }
98}
99
100void LineListIndex::appendBoth(const std::shared_ptr<LineList> &lineList)
101{
102 QMutexLocker m1(&mutex);
103
104 appendLine(lineList);
105 appendPoly(lineList);
106}
107
109{
110 LineListHash *oldIndex = m_lineIndex.release();
111 DrawID drawID = skyMesh()->incDrawID();
112
113 m_lineIndex.reset(new LineListHash());
114 for (auto &listList : *oldIndex)
115 {
116 for (auto &item : *listList)
117 {
118 if (item->drawID == drawID)
119 continue;
120
121 item->drawID = drawID;
122 appendLine(item);
123 }
124 listList.reset();
125 }
126 delete oldIndex;
127}
128
130{
131 KStarsData *data = KStarsData::Instance();
132 lineList->updateID = data->updateID();
133 SkyList *points = lineList->points();
134
135 if (lineList->updateNumID != data->updateNumID())
136 {
137 lineList->updateNumID = data->updateNumID();
138 KSNumbers *num = data->updateNum();
139
140 for (const auto &point : *points)
141 {
142 point->updateCoords(num);
143 }
144 }
145
146 for (const auto &point : *points)
147 {
148 point->EquatorialToHorizontal(data->lst(), data->geo()->lat());
149 }
150}
151
152// This is a callback used in draw() below
154{
155 skyp->setPen(QPen(QBrush(QColor("white")), 1, Qt::SolidLine));
156}
157
159{
160 if (!selected())
161 return;
162 preDraw(skyp);
163 drawLines(skyp);
164}
165
166#ifdef KSTARS_LITE
167MeshIterator LineListIndex::visibleTrixels()
168{
169 return MeshIterator(skyMesh(), drawBuffer());
170}
171#endif
172
173// This is a callback used int drawLinesInt() and drawLinesFloat()
174SkipHashList *LineListIndex::skipList(LineList *lineList)
175{
176 Q_UNUSED(lineList)
177 return nullptr;
178}
179
181{
182 DrawID drawID = skyMesh()->drawID();
183 UpdateID updateID = KStarsData::Instance()->updateID();
184
185 for (auto &lineListList : m_lineIndex->values())
186 {
187 for (int i = 0; i < lineListList->size(); i++)
188 {
189 std::shared_ptr<LineList> lineList = lineListList->at(i);
190
191 if (lineList->drawID == drawID)
192 continue;
193 lineList->drawID = drawID;
194
195 if (lineList->updateID != updateID)
196 JITupdate(lineList.get());
197
198 skyp->drawSkyPolyline(lineList.get(), skipList(lineList.get()), label());
199 }
200 }
201}
202
204{
205 DrawID drawID = skyMesh()->drawID();
206 UpdateID updateID = KStarsData::Instance()->updateID();
207
208 MeshIterator region(skyMesh(), drawBuffer());
209
210 while (region.hasNext())
211 {
212 std::shared_ptr<LineListList> lineListList = m_polyIndex->value(region.next());
213
214 if (lineListList == nullptr)
215 continue;
216
217 for (int i = 0; i < lineListList->size(); i++)
218 {
219 std::shared_ptr<LineList> lineList = lineListList->at(i);
220
221 // draw each Linelist at most once
222 if (lineList->drawID == drawID)
223 continue;
224 lineList->drawID = drawID;
225
226 if (lineList->updateID != updateID)
227 JITupdate(lineList.get());
228
229 skyp->drawSkyPolygon(lineList.get());
230 }
231 }
232}
233
235{
236 emitProgressText(i18n("Loading %1", m_name));
237 if (skyMesh()->debug() >= 1)
238 qDebug() << Q_FUNC_INFO << QString("Loading %1 ...").arg(m_name);
239}
240
242{
243 if (skyMesh()->debug() < 2)
244 return;
245
246 int total = skyMesh()->size();
247 int polySize = m_polyIndex->size();
248 int lineSize = m_lineIndex->size();
249
250 if (lineSize > 0)
251 printf("%4d out of %4d trixels in line index %3d%%\n", lineSize, total, 100 * lineSize / total);
252
253 if (polySize > 0)
254 printf("%4d out of %4d trixels in poly index %3d%%\n", polySize, total, 100 * polySize / total);
255}
const CachingDms * lat() const
Definition geolocation.h:70
int size() const
returns the total number of trixels in the HTM.
Definition HTMesh.h:118
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition ksnumbers.h:43
KStarsData is the backbone of KStars.
Definition kstarsdata.h:72
CachingDms * lst()
Definition kstarsdata.h:224
GeoLocation * geo()
Definition kstarsdata.h:230
void drawLines(SkyPainter *skyp)
Draws all the lines in m_listList as simple lines in float mode.
void intro()
displays a message that we are loading m_name.
void appendBoth(const std::shared_ptr< LineList > &lineList)
a convenience method that adds a lineList to both the lineIndex and the polyIndex.
virtual void preDraw(SkyPainter *skyp)
Gives the subclasses access to the top of the draw() method.
virtual void JITupdate(LineList *lineList)
this is called from within the draw routines when the updateID of the lineList is stale.
SkyMesh * skyMesh()
Returns the SkyMesh object.
void summary()
prints out some summary statistics if the skyMesh debug is greater than 1.
virtual MeshBufNum_t drawBuffer()
a callback overridden by NoPrecessIndex so it can use the drawing code with the non-reverse-precessed...
void draw(SkyPainter *skyp) override
The top level draw routine.
void appendPoly(const std::shared_ptr< LineList > &lineList)
Typically called from within a subclasses constructors.
void appendLine(const std::shared_ptr< LineList > &lineList)
Typically called from within a subclasses constructors.
void drawFilled(SkyPainter *skyp)
Draws all the lines in m_listList as filled polygons in float mode.
void reindexLines()
as the name says, recreates the lineIndex using the LineLists in the previous index.
virtual SkipHashList * skipList(LineList *lineList)
Also overridden by SkipListIndex.
LineListIndex(SkyComposite *parent, const QString &name="")
Constructor Simply set the internal skyMesh, parent, and name.
virtual const IndexHash & getIndexHash(LineList *lineList)
Returns an IndexHash from the SkyMesh that contains the set of trixels that cover lineList.
A simple data container used by LineListIndex.
Definition linelist.h:25
SkyList * points()
return the list of points for iterating or appending (or whatever).
Definition linelist.h:33
MeshIterator is a very lightweight class used to iterate over the result set of an HTMesh intersectio...
Trixel next() const
returns the next trixel
bool hasNext() const
true if there are more trixel to iterate over.
SkyComponent represents an object on the sky map.
virtual bool selected()
virtual void emitProgressText(const QString &message)
Emit signal about progress.
SkyComposite is a kind of container class for SkyComponent objects.
int incDrawID()
increments the drawID and returns the new value.
Definition skymesh.h:272
const IndexHash & indexLine(SkyList *points)
fills a QHash with the trixel indices needed to cover all the line segments specified in the QVector<...
Definition skymesh.cpp:126
static SkyMesh * Instance()
returns the default instance of SkyMesh or null if it has not yet been created.
Definition skymesh.cpp:39
DrawID drawID() const
Definition skymesh.h:265
const IndexHash & indexPoly(SkyList *points)
fills a QHash with the trixel indices needed to cover the polygon specified in the QList<SkyPoints*> ...
Definition skymesh.cpp:208
Draws things on the sky, without regard to backend.
Definition skypainter.h:40
virtual void drawSkyPolyline(LineList *list, SkipHashList *skipList=nullptr, LineListLabel *label=nullptr)=0
Draw a polyline in the sky.
virtual void drawSkyPolygon(LineList *list, bool forceClip=true)=0
Draw a polygon in the sky.
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
QString i18n(const char *text, const TYPE &arg...)
const_iterator constBegin() const const
const_iterator constEnd() const const
QString arg(Args &&... args) const const
SolidLine
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.