Kstars

deepskyitem.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
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 
21 DSOIndexNode::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 
39 DSOTrixelNode::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 
62 DeepSkyItem::DeepSkyItem(DeepSkyComponent *dsoComp, RootNode *rootNode)
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 
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);
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 
130 void 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());
175  double delLim = SkyMapLite::deleteLimit();
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  {
273  if (sizeCriterion && magCriterion)
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 
298  DeepSkyNode *dsoNode =
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 }
QMap::const_iterator constBegin() const const
virtual void show()
shows the catalog nodes and their labels
Definition: deepskyitem.cpp:33
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...
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:380
void append(const T &value)
A base class that is used for displaying SkyComponents on SkyMapLite.
Definition: skyitem.h:29
A container for nodes that holds collection of textures for stars and provides clipping.
Definition: rootnode.h:59
virtual void show()
makes this node visible
void showLabels(label_t labelType)
shows all labels of type labelType
Definition: labelsitem.cpp:196
DeepSkyItem(DeepSkyComponent *dsoComp, RootNode *rootNode)
Constructor.
Definition: deepskyitem.cpp:62
void appendChildNode(QSGNode *node)
QSGNode * firstChild() const const
CachingDms * lst()
Definition: kstarsdata.h:223
virtual void update()
Call update on all DSOIndexNodes (catalogs)
void setColor(QColor color, TrixelNode *symbolTrixel)
sets color of DSO symbol and label To not increase the code for symbols we just recreate the symbol p...
Definition: deepskynode.cpp:46
Handles labels in SkyMapLite.
Definition: labelsitem.h:52
const T & value() const const
virtual void hide() override
hides all child nodes (sets opacity of m_opacity to 0)
virtual void show() override
makes this node visible
Definition: skyitem.cpp:23
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition: projector.cpp:98
QMap::iterator insert(const Key &key, const T &value)
static double deleteLimit()
return limit of hides for the node to delete it
Definition: skymaplite.cpp:199
virtual void show() override
makes this node visible
Definition: trixelnode.cpp:40
QString schemeColor
schemeColor holds the color, with which nodes of this catalog should be drawn
Definition: deepskyitem.h:39
const CachingDms * lat() const
Definition: geolocation.h:70
void update(bool drawImage, bool drawLabel, QPointF pos=QPointF(-1, -1))
Update position and visibility of this node.
Definition: deepskynode.cpp:58
label_t
The label_t enum.
Definition: labelsitem.h:61
QMap::const_iterator constEnd() const const
QHashIterator::Item next()
ColorScheme * colorScheme()
Definition: kstarsdata.h:171
GeoLocation * geo()
Definition: kstarsdata.h:229
void hideLabels(label_t labelType)
hides all labels of type labelType
Definition: labelsitem.cpp:190
Convenience class that represents trixel in SkyMapLite.
Definition: trixelnode.h:20
virtual void deleteAllChildNodes()
Delete all childNodes and remove nodes from pairs in m_nodes.
Definition: deepskyitem.cpp:43
virtual void hide() override
hides this item and corresponding labels
Definition: skyitem.cpp:37
QLinkedList< QPair< SkyObject *, SkyNode * > > m_nodes
m_nodes - holds SkyNodes with corresponding SkyObjects
Definition: trixelnode.h:41
bool hasNext() const
true if there are more trixel to iterate over.
Definition: MeshIterator.h:27
QSGNode * parent() const const
bool hasNext() const const
virtual void hide()
hides the catalog nodes and their labels
Definition: deepskyitem.cpp:27
The DSOTrixelNode class represents trixel.
Definition: deepskyitem.h:46
Item for displaying sky objects; also handles user interaction events.
Definition: skymaplite.h:58
void reset() const
sets the count back to zero so you can use this iterator to iterate again over the same result set.
Definition: MeshIterator.h:40
QLinkedList::iterator begin()
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
QLinkedList::iterator end()
RootNode * rootNode()
Definition: skyitem.h:57
TrixelNode * addTrixel(label_t labelType, Trixel trixel)
adds trixel to the node corresponding to labelType
Definition: labelsitem.cpp:152
int hideCount()
m_hideCount is a counter of how much updates of SkyMapLite this trixel remained hidden.
Definition: trixelnode.h:30
LabelsItem::label_t m_labelType
m_labelType holds label type of this catalog
Definition: deepskyitem.h:37
virtual void hide() override
hides this node
Definition: trixelnode.cpp:34
Provides virtual functions for update of coordinates and nodes hiding.
Definition: skynode.h:27
This class represents DSOs from particular catalog.
Definition: deepskyitem.h:23
QSGNode * nextSibling() const const
virtual void hide()
hides this node
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:86
const Key & key() const const
A SkyNode derived class used for Deep Sky symbols in SkyMapLite.
bool checkVisibility(const SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
Definition: projector.cpp:183
void removeChildNode(QSGNode *node)
A SkyNode derived class used for displaying DeepSkyObjects.
Definition: deepskynode.h:32
Trixel next() const
returns the next trixel
Definition: MeshIterator.h:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.