Kstars

deepskyitem.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#include "deepskyitem.h"
7
8#include "deepskyobject.h"
9#include "deepstaritem.h"
10#include "labelsitem.h"
11#include "Options.h"
12#include "rootnode.h"
13#include "skymesh.h"
14#include "starblockfactory.h"
15#include "starcomponent.h"
16#include "htmesh/MeshIterator.h"
17#include "projections/projector.h"
18#include "skynodes/deepskynode.h"
19#include "skynodes/dsosymbolnode.h"
20
21DSOIndexNode::DSOIndexNode(DeepSkyIndex *index, LabelsItem::label_t labelType, QString color)
22 : m_index(index), m_trixels(new QSGNode), m_labelType(labelType), schemeColor(color)
23{
24 appendChildNode(m_trixels);
25}
26
28{
30 SkyMapLite::Instance()->rootNode()->labelsItem()->hideLabels(m_labelType);
31}
32
34{
36 SkyMapLite::Instance()->rootNode()->labelsItem()->showLabels(m_labelType);
37}
38
39DSOTrixelNode::DSOTrixelNode(Trixel trixelID) : TrixelNode(trixelID)
40{
41}
42
44{
46
47 while (i != m_nodes.end())
48 {
49 DeepSkyNode *node = static_cast<DeepSkyNode *>((*i).second);
50 if (node)
51 {
52 node->parent()->removeChildNode(node);
53 delete node->symbol();
54 delete node;
55
56 *i = QPair<SkyObject *, SkyNode *>((*i).first, 0);
57 }
58 ++i;
59 }
60}
61
63 : SkyItem(LabelsItem::label_t::DEEP_SKY_LABEL, rootNode), m_dsoComp(dsoComp), m_skyMesh(SkyMesh::Instance())
64{
65
66 m_other = new DSOIndexNode(&(m_dsoComp->m_OtherIndex), LabelsItem::label_t::DSO_OTHER_LABEL, "NGCColor");
67 appendChildNode(m_other);
68
69 QSGNode *n = firstChild();
70
71 while (n != 0)
72 {
73 DSOIndexNode *indexNode = static_cast<DSOIndexNode *>(n);
74 DeepSkyIndex *index = indexNode->m_index;
75
78
79 while (it.hasNext())
80 {
81 it.next();
82 result.insert(it.key(), it.value());
83 }
84
85 QMap<int, DeepSkyList *>::const_iterator i = result.constBegin();
86
87 while (i != result.constEnd())
88 {
89 DeepSkyList *dsoList = i.value();
90
91 DSOTrixelNode *trixel = new DSOTrixelNode(i.key());
92 trixel->m_labels = rootNode->labelsItem()->addTrixel(indexNode->m_labelType, i.key());
93
94 indexNode->m_trixels->appendChildNode(trixel);
95 QSGNode *symbols = new QSGNode;
96
97 for (int c = 0; c < dsoList->size(); ++c)
98 {
99 DeepSkyObject *dso = dsoList->at(c);
100 trixel->m_nodes.append(QPair<SkyObject *, SkyNode *>(dso, 0));
101 }
102
103 trixel->m_symbols = symbols;
104 trixel->appendChildNode(symbols);
105
106 ++i;
107 }
108 n = n->nextSibling();
109 }
110}
111
113{
114 if (!m_dsoComp->selected())
115 {
116 hide();
117 return;
118 }
119 show();
120
121 bool drawFlag;
122
123 MeshIterator region(m_skyMesh, DRAW_BUF);
124
125 drawFlag = Options::showMessier() && !(Options::hideOnSlew() && Options::hideMessier() && SkyMapLite::IsSlewing());
126
127 updateDeepSkyNode(m_other, drawFlag, &region);
128}
129
130void DeepSkyItem::updateDeepSkyNode(DSOIndexNode *indexNode, bool drawObject, MeshIterator *region, bool drawImage)
131{
132 if (!(drawObject || drawImage))
133 {
134 indexNode->hide();
135 return;
136 }
137
138 indexNode->show();
139
140 SkyMapLite *map = SkyMapLite::Instance();
141 const Projector *projector = map->projector();
142 KStarsData *data = KStarsData::Instance();
143
144 UpdateID updateID = data->updateID();
145 UpdateID updateNumID = data->updateNumID();
146
147 QColor schemeColor = data->colorScheme()->colorNamed(indexNode->schemeColor);
148
149 bool m_hideLabels = (map->isSlewing() && Options::hideOnSlew()) ||
150 !(Options::showDeepSkyMagnitudes() || Options::showDeepSkyNames());
151
152 double maglim = Options::magLimitDrawDeepSky();
153 bool showUnknownMagObjects = Options::showUnknownMagObjects();
154
155 //adjust maglimit for ZoomLevel
156 double lgmin = log10(MINZOOM);
157 double lgmax = log10(MAXZOOM);
158 double lgz = log10(Options::zoomFactor());
159 if (lgz <= 0.75 * lgmax)
160 maglim -= (Options::magLimitDrawDeepSky() - Options::magLimitDrawDeepSkyZoomOut()) * (0.75 * lgmax - lgz) /
161 (0.75 * lgmax - lgmin);
162
163 double labelMagLim = Options::deepSkyLabelDensity();
164 labelMagLim += (Options::magLimitDrawDeepSky() - labelMagLim) * (lgz - lgmin) / (lgmax - lgmin);
165 if (labelMagLim > Options::magLimitDrawDeepSky())
166 labelMagLim = Options::magLimitDrawDeepSky();
167
168 int regionID = 0;
169 if (region->hasNext())
170 {
171 regionID = region->next();
172 }
173
174 DSOTrixelNode *trixel = static_cast<DSOTrixelNode *>(indexNode->m_trixels->firstChild());
176
177 /*Unlike DeepStarItem and StarItem where all trixels are set, in DeepSkyItem number of trixels is different
178 across the catalogs. We are comparing trixelID and regionID to hide trixels that are not visible and skip
179 regionIDs that are not present in this catalog*/
180 while (trixel != 0)
181 {
182 //Hide all trixels that has smaller trixelID than the next visible trixel
183 if (trixel->trixelID() < regionID)
184 {
185 trixel->hide();
186 trixel->m_labels->hide();
187
188 if (trixel->hideCount() > delLim)
189 {
190 trixel->deleteAllChildNodes();
191 }
192 }
193 else if (trixel->trixelID() > regionID)
194 {
195 /*Keep iterating over regionID if current trixel's trixelID is larger than regionID. If there are no more
196 visible regions then hide/delete remaining trixels*/
197 if (region->hasNext())
198 {
199 regionID = region->next();
200 }
201 else
202 {
203 while (trixel != 0)
204 {
205 trixel->hide();
206 trixel->m_labels->hide();
207
208 if (trixel->hideCount() > delLim)
209 {
210 trixel->deleteAllChildNodes();
211 }
212 trixel = static_cast<DSOTrixelNode *>(trixel->nextSibling());
213 }
214 break;
215 }
216 continue;
217 }
218 else //Current trixelID is equal to regionID meaning that current trixel is visible
219 {
220 trixel->show();
221 trixel->m_labels->show();
222
223 if (region->hasNext())
224 {
225 regionID = region->next();
226 }
227
228 QLinkedList<QPair<SkyObject *, SkyNode *>>::iterator i = (&trixel->m_nodes)->begin();
229
230 while (i != (&trixel->m_nodes)->end())
231 {
232 DeepSkyObject *dsoObj = static_cast<DeepSkyObject *>((*i).first);
233 DeepSkyNode *dsoNode = static_cast<DeepSkyNode *>((*i).second);
234
235 if (dsoObj->updateID != updateID)
236 {
237 dsoObj->updateID = updateID;
238 if (dsoObj->updateNumID != updateNumID)
239 {
240 dsoObj->updateCoords(data->updateNum());
241 }
242 dsoObj->EquatorialToHorizontal(data->lst(), data->geo()->lat());
243 }
244
245 float mag = dsoObj->mag();
246 float size = dsoObj->a() * dms::PI * Options::zoomFactor() / 10800.0;
247
248 //only draw objects if flags set, it's bigger than 1 pixel (unless
249 //zoom > 2000.), and it's brighter than maglim (unless mag is
250 //undefined (=99.9)
251 bool sizeCriterion = (size > 1.0 || Options::zoomFactor() > 2000.);
252 bool magCriterion = (mag < (float)maglim) || (showUnknownMagObjects && (std::isnan(mag) || mag > FAINTEST_MAGNITUDE));
253
254 bool drawLabel = false;
255
256 if (!(m_hideLabels || mag > labelMagLim))
257 drawLabel = true;
258
259 if (dsoNode)
260 {
261 //Delete particular DSONode if its hideCount is larger than the limit
262 if (dsoNode->hideCount() > delLim)
263 {
264 trixel->removeChildNode(dsoNode);
265
266 delete dsoNode->symbol();
267 delete dsoNode;
268
269 *i = QPair<SkyObject *, SkyNode *>((*i).first, 0);
270 }
271 else
272 {
274 {
275 dsoNode->setColor(schemeColor, trixel);
276 dsoNode->update(drawImage, drawLabel);
277 }
278 else
279 {
280 dsoNode->hide();
281 }
282 }
283 }
284 else
285 {
286 if (sizeCriterion && magCriterion && projector->checkVisibility(dsoObj))
287 {
288 QPointF pos;
289
290 bool visible = false;
291 pos = projector->toScreen(dsoObj, true, &visible);
292 if (visible && projector->onScreen(pos))
293 {
294 //Create new DeepSkyNode and its symbol if it is currently visible
295 DSOSymbolNode *dsoSymbol = new DSOSymbolNode(dsoObj, schemeColor);
296 trixel->m_symbols->appendChildNode(dsoSymbol);
297
299 new DeepSkyNode(dsoObj, dsoSymbol, indexNode->m_labelType, trixel->trixelID());
300 trixel->appendChildNode(dsoNode);
301
302 *i = QPair<SkyObject *, SkyNode *>((*i).first, static_cast<SkyNode *>(dsoNode));
303 dsoNode->update(drawImage, drawLabel, pos);
304 }
305 }
306 }
307 ++i;
308 }
309 }
310 trixel = static_cast<DSOTrixelNode *>(trixel->nextSibling());
311 }
312
313 region->reset();
314}
QColor colorNamed(const QString &name) const
Retrieve a color by name.
This class represents DSOs from particular catalog.
Definition deepskyitem.h:24
virtual void show()
shows the catalog nodes and their labels
LabelsItem::label_t m_labelType
m_labelType holds label type of this catalog
Definition deepskyitem.h:37
virtual void hide()
hides the catalog nodes and their labels
A SkyNode derived class used for Deep Sky symbols in SkyMapLite.
The DSOTrixelNode class represents trixel.
Definition deepskyitem.h:47
virtual void deleteAllChildNodes()
Delete all childNodes and remove nodes from pairs in m_nodes.
virtual void update()
Call update on all DSOIndexNodes (catalogs)
DeepSkyItem(DeepSkyComponent *dsoComp, RootNode *rootNode)
Constructor.
void updateDeepSkyNode(DSOIndexNode *node, bool drawObject, MeshIterator *region, bool drawImage=false)
update all nodes needed to represent DSO in the given DSOIndexNode In this function we perform some t...
A SkyNode derived class used for displaying DeepSkyObjects.
Definition deepskynode.h:33
const CachingDms * lat() const
Definition geolocation.h:70
KStarsData is the backbone of KStars.
Definition kstarsdata.h:72
CachingDms * lst()
Definition kstarsdata.h:224
ColorScheme * colorScheme()
Definition kstarsdata.h:172
GeoLocation * geo()
Definition kstarsdata.h:230
This class is in charge of labels in SkyMapLite.
Definition labelsitem.h:53
label_t
The label_t enum.
Definition labelsitem.h:62
TrixelNode * addTrixel(label_t labelType, Trixel trixel)
adds trixel to the node corresponding to labelType
MeshIterator is a very lightweight class used to iterate over the result set of an HTMesh intersectio...
void reset() const
sets the count back to zero so you can use this iterator to iterate again over the same result set.
Trixel next() const
returns the next trixel
bool hasNext() const
true if there are more trixel to iterate over.
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
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
static double deleteLimit()
return limit of hides for the node to delete it
Provides an interface to the Hierarchical Triangular Mesh (HTM) library written by A.
Definition skymesh.h:74
Provides virtual functions for update of coordinates and nodes hiding.
Definition skynode.h:28
virtual void show()
makes this node visible
virtual void hide()
hides this node
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 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
static constexpr double PI
PI is a const static member; it's public so that it can be used anywhere, as long as dms....
Definition dms.h:385
void appendChildNode(QSGNode *node)
QSGNode * firstChild() const const
QSGNode * nextSibling() const const
QSGNode * parent() const const
void removeChildNode(QSGNode *node)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:49:22 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.