Kstars

deepstaritem.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#include "deepstaritem.h"
7
8#include "deepstarcomponent.h"
9#include "labelsitem.h"
10#include "Options.h"
11#include "rootnode.h"
12#include "skymesh.h"
13#include "starblock.h"
14#include "starblockfactory.h"
15#include "starblocklist.h"
16#include "starcomponent.h"
17#include "htmesh/MeshIterator.h"
18#include "projections/projector.h"
19#include "skynodes/pointsourcenode.h"
20#include "skynodes/trixelnode.h"
21
23 : SkyItem(LabelsItem::label_t::NO_LABEL, rootNode), m_deepStarComp(deepStarComp),
24 m_staticStars(deepStarComp->staticStars)
25{
26 m_starBlockList = &m_deepStarComp->m_starBlockList;
27
28 if (m_staticStars)
29 {
30 for (int c = 0; c < m_starBlockList->size(); ++c)
31 {
32 TrixelNode *trixel = new TrixelNode(m_starBlockList->at(c)->getTrixel());
33 appendChildNode(trixel);
34 int blockCount = m_starBlockList->at(c)->getBlockCount();
35
36 for (int i = 0; i < blockCount; ++i)
37 {
38 std::shared_ptr<StarBlock> block = m_starBlockList->at(c)->block(i);
39 // qDebug() << "---> Drawing stars from block " << i << " of trixel " <<
40 // currentRegion << ". SB has " << block->getStarCount() << " stars" << endl;
41 int starCount = block->getStarCount();
42 for (int j = 0; j < starCount; j++)
43 {
44 StarObject *star = &(block->star(j)->star);
45
46 if (star)
47 {
48 trixel->m_nodes.append(QPair<SkyObject *, SkyNode *>(star, 0));
49 }
50 }
51 }
52 }
53 }
54
55 m_skyMesh = SkyMesh::Instance();
56 m_StarBlockFactory = StarBlockFactory::Instance();
57}
58
60{
61 if (m_staticStars) // dynamic stars under construction
62 {
63 SkyMapLite *map = SkyMapLite::Instance();
64 KStarsData *data = KStarsData::Instance();
65 UpdateID updateID = data->updateID();
66
67 //FIXME_FOV -- maybe not clamp like that...
68 float radius = map->projector()->fov();
69 if (radius > 90.0)
70 radius = 90.0;
71
72 if (m_skyMesh != SkyMesh::Instance() && m_skyMesh->inDraw())
73 {
74 printf("Warning: aborting concurrent DeepStarComponent::draw()");
75 }
76 bool checkSlewing = (map->isSlewing() && Options::hideOnSlew());
77
78 //shortcuts to inform whether to draw different objects
79 bool hideFaintStars(checkSlewing && Options::hideStars());
80 double hideStarsMag = Options::magLimitHideStar();
81
82 //adjust maglimit for ZoomLevel
83 // double lgmin = log10(MINZOOM);
84 // double lgmax = log10(MAXZOOM);
85 // double lgz = log10(Options::zoomFactor());
86 // TODO: Enable hiding of faint stars
87
88 float maglim = StarComponent::zoomMagnitudeLimit();
89
90 if (maglim < m_deepStarComp->triggerMag || !m_staticStars)
91 {
92 hide();
93 return;
94 }
95 else
96 {
97 show();
98 }
99
100 //float m_zoomMagLimit = maglim;
101
102 m_skyMesh->inDraw(true);
103
104 SkyPoint *focus = map->focus();
105 m_skyMesh->aperture(focus, radius + 1.0, DRAW_BUF); // divide by 2 for testing
106
107 MeshIterator region(m_skyMesh, DRAW_BUF);
108
109 // If we are to hide the fainter stars (eg: while slewing), we set the magnitude limit to hideStarsMag.
110 if (hideFaintStars && maglim > hideStarsMag)
111 maglim = hideStarsMag;
112
113 StarBlockFactory *m_StarBlockFactory = StarBlockFactory::Instance();
114 // m_StarBlockFactory->drawID = m_skyMesh->drawID();
115 // qDebug() << "Mesh size = " << m_skyMesh->size() << "; drawID = " << m_skyMesh->drawID();
116
117 /*t_dynamicLoad = 0;
118 t_updateCache = 0;
119 t_drawUnnamed = 0;*/
120
121 //visibleStarCount = 0;
122
123 // Mark used blocks in the LRU Cache. Not required for static stars
124 if (!m_staticStars)
125 {
126 //Under construction
127 // while( region.hasNext() ) {
128 // Trixel currentRegion = region.next();
129 // for( int i = 0; i < m_starBlockList->at( currentRegion )->getBlockCount(); ++i ) {
130 // StarBlock *prevBlock = ( ( i >= 1 ) ? m_starBlockList->at( currentRegion )->block( i - 1 ) : nullptr );
131 // StarBlock *block = m_starBlockList->at( currentRegion )->block( i );
132
133 // if( i == 0 && !m_StarBlockFactory->markFirst( block ) )
134 // qDebug() << "markFirst failed in trixel" << currentRegion;
135 // if( i > 0 && !m_StarBlockFactory->markNext( prevBlock, block ) )
136 // qDebug() << "markNext failed in trixel" << currentRegion << "while marking block" << i;
137 // if( i < m_starBlockList->at( currentRegion )->getBlockCount()
138 // && m_starBlockList->at( currentRegion )->block( i )->getFaintMag() < maglim )
139 // break;
140 // }
141 // }
142 // //t_updateCache = t.restart();
143 // region.reset();
144 }
145
146 m_StarBlockFactory->drawID = m_skyMesh->drawID();
147
148 int regionID = -1;
149 if (region.hasNext())
150 {
151 regionID = region.next();
152 }
153
154 int trixelID = 0;
155
156 QSGNode *firstTrixel = firstChild();
157 TrixelNode *trixel = static_cast<TrixelNode *>(firstTrixel);
158
159 while (trixel != 0)
160 {
161 if (m_staticStars)
162 {
163 const Projector *projector = SkyMapLite::Instance()->projector();
164 double delLim = SkyMapLite::deleteLimit();
165
166 if (trixelID != regionID)
167 {
168 trixel->hide();
169
170 if (trixel->hideCount() > delLim)
171 {
172 QLinkedList<QPair<SkyObject *, SkyNode *>>::iterator i = trixel->m_nodes.begin();
173
174 while (i != trixel->m_nodes.end())
175 {
176 SkyNode *node = (*i).second;
177 if (node)
178 {
179 trixel->removeChildNode(node);
180 delete node;
181
182 *i = QPair<SkyObject *, SkyNode *>((*i).first, 0);
183 }
184 ++i;
185 }
186 }
187
188 trixel = static_cast<TrixelNode *>(trixel->nextSibling());
189 ++trixelID;
190 continue;
191 }
192 else
193 {
194 trixel->show();
195
196 if (region.hasNext())
197 {
198 regionID = region.next();
199 }
200
201 QLinkedList<QPair<SkyObject *, SkyNode *>>::iterator i = (&trixel->m_nodes)->begin();
202
203 while (i != (&trixel->m_nodes)->end())
204 {
205 bool hide = false;
206 bool hideSlew = false;
207
208 bool drawLabel = false;
209
210 StarObject *starObj = static_cast<StarObject *>((*i).first);
211 SkyNode *node = (*i).second;
212
213 int mag = starObj->mag();
214
215 // break loop if maglim is reached
216 if (mag > maglim)
217 hide = true;
218 if (hideFaintStars && hideStarsMag)
219 hideSlew = true;
220 if (starObj->updateID != KStarsData::Instance()->updateID())
221 starObj->JITupdate();
222
223 if (node)
224 {
225 if (node->hideCount() > delLim || hide)
226 {
227 trixel->removeChildNode(node);
228 delete node;
229 *i = QPair<SkyObject *, SkyNode *>((*i).first, 0);
230 }
231 else
232 {
233 if (!hideSlew)
234 {
235 node->update(drawLabel);
236 }
237 else
238 {
239 node->hide();
240 }
241 }
242 }
243 else
244 {
245 if (!hide && !hideSlew && projector->checkVisibility(starObj))
246 {
247 QPointF pos;
248
249 bool visible = false;
250 pos = projector->toScreen(starObj, true, &visible);
251 if (visible && projector->onScreen(pos))
252 {
253 PointSourceNode *point =
254 new PointSourceNode(starObj, rootNode(), LabelsItem::label_t::STAR_LABEL,
255 starObj->spchar(), starObj->mag(), trixelID);
256 trixel->appendChildNode(point);
257
258 *i = QPair<SkyObject *, SkyNode *>((*i).first, static_cast<SkyNode *>(point));
259 point->updatePos(pos, drawLabel);
260 }
261 }
262 }
263 ++i;
264 }
265 }
266 }
267 else if (false)
268 {
269 //Dynamic stars are under construction
270 if (!m_staticStars && !m_starBlockList->at(regionID)->fillToMag(maglim) &&
271 maglim <= m_deepStarComp->m_FaintMagnitude * (1 - 1.5 / 16))
272 {
273 qDebug() << "SBL::fillToMag( " << maglim << " ) failed for trixel " << regionID << " !" << endl;
274 }
275
276 for (int i = 0; i < m_starBlockList->at(regionID)->getBlockCount(); ++i)
277 {
278 bool hide = false;
279
280 std::shared_ptr<StarBlock> block = m_starBlockList->at(regionID)->block(i);
281
282 for (int j = 0; j < block->getStarCount(); j++)
283 {
284 StarNode *star = block->star(j);
285 StarObject *curStar = &(star->star);
286 PointSourceNode *point = star->starNode;
287
288 if (curStar->updateID != updateID)
289 curStar->JITupdate();
290
291 float mag = curStar->mag();
292
293 if (!hide)
294 {
295 if (mag > maglim)
296 hide = true;
297 }
298
299 if (!hide)
300 {
301 if (!point)
302 {
303 star->starNode = new PointSourceNode(curStar, rootNode(), LabelsItem::label_t::NO_LABEL,
304 curStar->spchar(), curStar->mag(), regionID);
305 point = star->starNode;
306 trixel->appendChildNode(point);
307 }
308 //point->setSizeMagLim(m_zoomMagLimit);
309 point->update();
310 }
311 else
312 {
313 if (point)
314 point->hide();
315 }
316 }
317 }
318 }
319 trixel = static_cast<TrixelNode *>(trixel->nextSibling());
320 trixelID++;
321 }
322 m_skyMesh->inDraw(false);
323 }
324}
Stores and manages unnamed stars, most of which are dynamically loaded into memory.
DeepStarItem(DeepStarComponent *deepStarComp, RootNode *rootNode)
Constructor.
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
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.
virtual void hide() override
hides this node and its label.
virtual void update() override
update updates coordinates of this node based on the visibility of its 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
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:264
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
The sky coordinates of a point in the sky.
Definition skypoint.h:45
A factory that creates StarBlocks and recycles them in an LRU Cache.
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 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
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 Fri Jul 26 2024 11:59:52 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.