Kstars

staritem.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#include "staritem.h"
7
8#include "deepstaritem.h"
9#include "labelsitem.h"
10#include "Options.h"
11#include "rootnode.h"
12#include "skymesh.h"
13#include "skyopacitynode.h"
14#include "starblockfactory.h"
15#include "starcomponent.h"
16#include "htmesh/MeshIterator.h"
17#include "projections/projector.h"
18#include "skynodes/pointsourcenode.h"
19#include "skynodes/trixelnode.h"
20
21#include <QLinkedList>
22
24 : SkyItem(LabelsItem::label_t::STAR_LABEL, rootNode), m_starComp(starComp), m_stars(new SkyOpacityNode),
25 m_deepStars(new SkyOpacityNode), m_starLabels(rootNode->labelsItem()->getLabelNode(labelType()))
26
27{
28 StarIndex *trixels = m_starComp->m_starIndex.get();
29
30 appendChildNode(m_stars);
31
32 //Test
33 Options::setShowStarMagnitudes(false);
34 Options::setShowStarNames(true);
35
36 for (int i = 0; i < trixels->size(); ++i)
37 {
38 StarList *skyList = trixels->at(i);
39 TrixelNode *trixel = new TrixelNode(i);
40 m_stars->appendChildNode(trixel);
41
42 for (int c = 0; c < skyList->size(); ++c)
43 {
44 StarObject *star = skyList->at(c);
45 if (star)
46 {
47 trixel->m_nodes.append(QPair<SkyObject *, SkyNode *>(star, 0));
48 }
49 }
50 }
51
52 appendChildNode(m_deepStars);
53
54 QVector<DeepStarComponent *> deepStars = m_starComp->m_DeepStarComponents;
55 int deepSize = deepStars.size();
56
57 for (int i = 0; i < deepSize; ++i)
58 {
59 DeepStarItem *deepStar = new DeepStarItem(deepStars[i], rootNode);
60 rootNode->removeChildNode(deepStar);
61 m_deepStars->appendChildNode(deepStar);
62 }
63
64 m_skyMesh = SkyMesh::Instance();
65 m_StarBlockFactory = StarBlockFactory::Instance();
66}
67
69{
70 if (!m_starComp->selected())
71 {
72 hide();
73 return;
74 }
75 show();
76
77 SkyMapLite *map = SkyMapLite::Instance();
78 KStarsData *data = KStarsData::Instance();
79
80 bool checkSlewing = (map->isSlewing() && Options::hideOnSlew());
81 bool hideLabel = checkSlewing || !(Options::showStarMagnitudes() || Options::showStarNames());
82 if (hideLabel)
83 hideLabels();
84
85 //shortcuts to inform whether to draw different objects
86 bool hideFaintStars = checkSlewing && Options::hideStars();
87 double hideStarsMag = Options::magLimitHideStar();
88 bool reIndex = m_starComp->reindex(data->updateNum());
89
90 double lgmin = log10(MINZOOM);
91 double lgmax = log10(MAXZOOM);
92 double lgz = log10(Options::zoomFactor());
93
94 double maglim;
95 double m_zoomMagLimit; //Check it later. Needed for labels
96 m_zoomMagLimit = maglim = StarComponent::zoomMagnitudeLimit();
97 map->setSizeMagLim(m_zoomMagLimit);
98
99 double labelMagLim = Options::starLabelDensity() / 5.0;
100 labelMagLim += (12.0 - labelMagLim) * (lgz - lgmin) / (lgmax - lgmin);
101 if (labelMagLim > 8.0)
102 labelMagLim = 8.0;
103
104 //Calculate sizeMagLim
105 // Old formula:
106 // float sizeMagLim = ( 2.000 + 2.444 * Options::memUsage() / 10.0 ) * ( lgz - lgmin ) + 5.8;
107
108 // Using the maglim to compute the sizes of stars reduces
109 // discernability between brighter and fainter stars at high zoom
110 // levels. To fix that, we use an "arbitrary" constant in place of
111 // the variable star density.
112 // Not using this formula now.
113 // float sizeMagLim = 4.444 * ( lgz - lgmin ) + 5.0;
114
115 /*float sizeMagLim = zoomMagnitudeLimit();
116 if( sizeMagLim > faintMagnitude() * ( 1 - 1.5/16 ) )
117 sizeMagLim = faintMagnitude() * ( 1 - 1.5/16 );
118 skyp->setSizeMagLimit(sizeMagLim);*/
119
120 //Loop for drawing star images
121
122 float radius = map->projector()->fov();
123 if (radius > 90.0)
124 radius = 90.0;
125
126 m_skyMesh->inDraw(true);
127
128 SkyPoint *focus = map->focus();
129 m_skyMesh->aperture(focus, radius + 1.0, DRAW_BUF); // divide by 2 for testing
130
131 MeshIterator region(m_skyMesh, DRAW_BUF);
132
133 // If we are hiding faint stars, then maglim is really the brighter of hideStarsMag and maglim
134 if (hideFaintStars && maglim > hideStarsMag)
135 maglim = hideStarsMag;
136
137 m_StarBlockFactory->drawID = m_skyMesh->drawID();
138
139 int regionID = -1;
140 if (region.hasNext())
141 {
142 regionID = region.next();
143 }
144
145 int trixelID = 0;
146
147 QSGNode *firstTrixel = m_stars->firstChild();
148 TrixelNode *trixel = static_cast<TrixelNode *>(firstTrixel);
149
150 QSGNode *firstLabel = m_starLabels->firstChild();
151 TrixelNode *label = static_cast<TrixelNode *>(firstLabel);
152
153 StarIndex *index = m_starComp->m_starIndex.get();
154
155 if (reIndex)
156 rootNode()->labelsItem()->deleteLabels(labelType());
157
158 const Projector *projector = SkyMapLite::Instance()->projector();
159
160 double delLim = SkyMapLite::deleteLimit();
161
162 while (trixel != 0)
163 {
164 if (reIndex)
165 {
166 StarList *skyList = index->at(trixelID);
167
168 QSGNode *n = trixel->firstChild();
169
170 //Delete nodes
171 while (n != 0)
172 {
173 QSGNode *c = n;
174 n = n->nextSibling();
175
176 trixel->removeChildNode(c);
177 delete c;
178 }
179
180 //Delete all pairs that represent stars
181 trixel->m_nodes.clear();
182
183 for (int c = 0; c < skyList->size(); ++c)
184 {
185 StarObject *star = skyList->at(c);
186 if (star)
187 {
188 //Add new pair with reindexed star
189 trixel->m_nodes.append(QPair<SkyObject *, SkyNode *>(star, 0));
190 }
191 }
192 }
193
194 if (trixelID != regionID)
195 {
196 trixel->hide();
197 label->hide();
198
199 if (trixel->hideCount() > delLim)
200 {
201 trixel->deleteAllChildNodes();
202 }
203 }
204 else
205 {
206 trixel->show();
207 label->show();
208
209 if (region.hasNext())
210 {
211 regionID = region.next();
212 }
213
214 QLinkedList<QPair<SkyObject *, SkyNode *>> *nodes = &trixel->m_nodes;
215 QLinkedList<QPair<SkyObject *, SkyNode *>>::iterator i = nodes->begin();
216 bool hide = false;
217
218 while (i != nodes->end())
219 {
220 bool drawLabel = false;
221
222 StarObject *starObj = static_cast<StarObject *>((*i).first);
223 SkyNode *node = (*i).second;
224
225 int mag = starObj->mag();
226
227 // break loop if maglim is reached
228 if (mag > maglim)
229 hide = true;
230 if (!(hideLabel || mag > labelMagLim))
231 drawLabel = true;
232 if (starObj->updateID != KStarsData::Instance()->updateID())
233 starObj->JITupdate();
234
235 if (node)
236 {
237 if (node->hideCount() > delLim || hide)
238 {
239 trixel->removeChildNode(node);
240 delete node;
241 *i = QPair<SkyObject *, SkyNode *>((*i).first, 0);
242 }
243 else
244 {
245 if (!hide)
246 {
247 node->update(drawLabel);
248 }
249 else
250 {
251 node->hide();
252 }
253 }
254 }
255 else
256 {
257 if (!hide && projector->checkVisibility(starObj))
258 {
259 QPointF pos;
260
261 bool visible = false;
262 pos = projector->toScreen(starObj, true, &visible);
263 if (visible && projector->onScreen(pos))
264 {
265 PointSourceNode *point =
266 new PointSourceNode(starObj, rootNode(), LabelsItem::label_t::STAR_LABEL,
267 starObj->spchar(), starObj->mag(), trixelID);
268 trixel->appendChildNode(point);
269
270 *i = QPair<SkyObject *, SkyNode *>((*i).first, static_cast<SkyNode *>(point));
271 point->updatePos(pos, drawLabel);
272 }
273 }
274 }
275 ++i;
276 }
277 }
278 trixel = static_cast<TrixelNode *>(trixel->nextSibling());
279 label = static_cast<TrixelNode *>(label->nextSibling());
280
281 ++trixelID;
282 }
283
284 // Draw focusStar if not null
285 /*if( focusStar ) {
286 if ( focusStar->updateID != updateID )
287 focusStar->JITupdate();
288 float mag = focusStar->mag();
289 skyp->drawPointSource(focusStar, mag, focusStar->spchar() );
290 }*/
291
292 // Now draw each of our DeepStarComponents
293 QSGNode *deep = m_deepStars->firstChild();
294 while (deep != 0)
295 {
296 DeepStarItem *deepStars = static_cast<DeepStarItem *>(deep);
297 deep = deep->nextSibling();
298 deepStars->update();
299 }
300
301 QSGNode *n = m_stars->firstChild();
302 while (n != 0)
303 {
304 n = n->nextSibling();
305 }
306 m_skyMesh->inDraw(false);
307}
This class handles representation of unnamed stars in SkyMapLite.
virtual void update()
updates all trixels that contain stars
KStarsData is the backbone of KStars.
Definition kstarsdata.h:72
This class is in charge of labels in SkyMapLite.
Definition labelsitem.h:53
void deleteLabels(label_t labelType)
deletes all labels of type labelType
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.
A SkyNode derived class used for displaying PointNode with coordinates provided by SkyObject.
void updatePos(QPointF pos, bool drawLabel)
updatePos updates position of this node and its label.
The Projector class is the primary class that serves as an interface to handle projections.
Definition projector.h:58
QPointF toScreen(const SkyPoint *o, bool oRefract=true, bool *onVisibleHemisphere=nullptr) const
This is exactly the same as toScreenVec but it returns a QPointF.
Definition projector.cpp:93
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition projector.cpp:98
bool checkVisibility(const SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
A QSGClipNode derived class used as a container for holding pointers to nodes and for clipping.
Definition rootnode.h:60
This is an interface for implementing SkyItems that represent SkyComponent derived objects on the Sky...
Definition skyitem.h:30
virtual void hide() override
hides this item and corresponding labels
Definition skyitem.cpp:37
RootNode * rootNode()
Definition skyitem.h:57
LabelsItem::label_t labelType()
Definition skyitem.h:60
virtual void show() override
makes this node visible
Definition skyitem.cpp:23
This is the main item that displays all SkyItems.
Definition skymaplite.h:59
const Projector * projector() const
Get the current projector.
Definition skymaplite.h:323
static double deleteLimit()
return limit of hides for the node to delete it
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
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:56
Provides virtual functions for update of coordinates and nodes hiding.
Definition skynode.h:28
virtual void hide()
hides all child nodes (sets opacity of m_opacity to 0)
Definition skynode.cpp:21
virtual void update()
Updates coordinate of the object on SkyMapLite.
Definition skynode.h:48
float mag() const
Definition skyobject.h:206
A wrapper for QSGOpacityNode that provides hide() and show() functions.
The sky coordinates of a point in the sky.
Definition skypoint.h:45
Represents the stars on the sky map.
bool selected() override
StarItem(StarComponent *starComp, RootNode *rootNode)
Constructor.
Definition staritem.cpp:23
virtual void update()
Update positions of nodes that represent stars In this function we perform almost the same thing as i...
Definition staritem.cpp:68
This is a subclass of SkyObject.
Definition starobject.h:33
void JITupdate()
added for JIT updates from both StarComponent and ConstellationLines
char spchar() const
Returns just the first character of the spectral type string.
Convenience class that represents trixel in SkyMapLite.
Definition trixelnode.h:21
int hideCount()
m_hideCount is a counter of how much updates of SkyMapLite this trixel remained hidden.
Definition trixelnode.h:30
virtual void deleteAllChildNodes()
Delete all childNodes and remove nodes from pairs in m_nodes.
virtual void show() override
makes this node visible
virtual void hide() override
hides this node
QLinkedList< QPair< SkyObject *, SkyNode * > > m_nodes
m_nodes - holds SkyNodes with corresponding SkyObjects
Definition trixelnode.h:41
const_reference at(qsizetype i) const const
qsizetype size() const const
void appendChildNode(QSGNode *node)
QSGNode * firstChild() const const
QSGNode * nextSibling() const const
void removeChildNode(QSGNode *node)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.