Kstars

starblocklist.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Akarsh Simha <akarshsimha@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "starblocklist.h"
8
9#include "binfilehelper.h"
10#include "deepstarcomponent.h"
11#include "starblock.h"
12#include "starcomponent.h"
13
14#ifdef KSTARS_LITE
15#include "skymaplite.h"
16#include "kstarslite/skyitems/skynodes/pointsourcenode.h"
17#endif
18
19#include <QDebug>
20
22{
23 trixel = tr;
24 this->parent = parent;
25 staticStars = parent->hasStaticStars();
26}
27
29{
30 if (block != blocks[nBlocks - 1].get())
31 qDebug() << Q_FUNC_INFO << "ERROR: Trying to release a block which is not the last block! Trixel = " << trixel;
32
33 else if (blocks.size() > 0)
34 {
35#ifdef KSTARS_LITE
36 for (int i = 0; i < block->getStarCount(); ++i)
37 {
38 PointSourceNode *node = block->star(i)->starNode;
39 if (node)
40 {
41 SkyMapLite::Instance()->deleteSkyNode(node);
42 block->star(i)->starNode = 0;
43 }
44 }
45#endif
46 blocks.removeLast();
47 nBlocks--;
48 nStars -= block->getStarCount();
49
50 readOffset -= parent->getStarReader()->guessRecordSize() * block->getStarCount();
51 if (nBlocks <= 0)
52 faintMag = -5.0;
53 else
54 faintMag = blocks[nBlocks - 1]->faintMag;
55
56 return 1;
57 }
58
59 return 0;
60}
61
62bool StarBlockList::fillToMag(float maglim)
63{
64 // TODO: Remove staticity of BinFileHelper
65 BinFileHelper *dSReader;
66 StarBlockFactory *SBFactory;
67 StarData stardata;
68 DeepStarData deepstardata;
69 FILE *dataFile;
70
71 dSReader = parent->getStarReader();
72 dataFile = dSReader->getFileHandle();
73 SBFactory = StarBlockFactory::Instance();
74
75 if (staticStars)
76 return false;
77
78 if (faintMag >= maglim)
79 return true;
80
81 if (!dataFile)
82 {
83 qDebug() << Q_FUNC_INFO << "dataFile not opened!";
84 return false;
85 }
86
87 Trixel trixelId =
88 trixel; //( ( trixel < 256 ) ? ( trixel + 256 ) : ( trixel - 256 ) ); // Trixel ID on datafile is assigned differently
89
90 if (readOffset <= 0)
91 readOffset = dSReader->getOffset(trixelId);
92
93 Q_ASSERT(nBlocks == (unsigned int)blocks.size());
94
95 BinFileHelper::unsigned_KDE_fseek(dataFile, readOffset, SEEK_SET);
96
97 /*
98 qDebug() << Q_FUNC_INFO << "Reading trixel" << trixel << ", id on disk =" << trixelId << ", currently nStars =" << nStars
99 << ", record count =" << dSReader->getRecordCount( trixelId ) << ", first block = " << blocks[0]->getStarCount()
100 << "to maglim =" << maglim << "with current faintMag =" << faintMag;
101 */
102
103 while (maglim >= faintMag && nStars < dSReader->getRecordCount(trixelId))
104 {
105 int ret = 0;
106
107 if (nBlocks == 0 || blocks[nBlocks - 1]->isFull())
108 {
109 std::shared_ptr<StarBlock> newBlock = SBFactory->getBlock();
110
111 if (!newBlock.get())
112 {
113 qWarning() << "ERROR: Could not get a new block from StarBlockFactory::getBlock() in trixel " << trixel
114 << ", while trying to create block #" << nBlocks + 1;
115 return false;
116 }
117 blocks.append(newBlock);
118 blocks[nBlocks]->parent = this;
119 if (nBlocks == 0)
120 SBFactory->markFirst(blocks[0]);
121 else if (!SBFactory->markNext(blocks[nBlocks - 1], blocks[nBlocks]))
122 qWarning() << "ERROR: markNext() failed on block #" << nBlocks + 1 << "in trixel" << trixel;
123
124 ++nBlocks;
125 }
126 // TODO: Make this more general
127 if (dSReader->guessRecordSize() == 32)
128 {
129 ret = fread(&stardata, sizeof(StarData), 1, dataFile);
130 if (dSReader->getByteSwap())
131 DeepStarComponent::byteSwap(&stardata);
132 readOffset += sizeof(StarData);
133 blocks[nBlocks - 1]->addStar(stardata);
134 }
135 else
136 {
137 ret = fread(&deepstardata, sizeof(DeepStarData), 1, dataFile);
138 if (dSReader->getByteSwap())
139 DeepStarComponent::byteSwap(&deepstardata);
140 readOffset += sizeof(DeepStarData);
141 blocks[nBlocks - 1]->addStar(deepstardata);
142 }
143
144 /*
145 if( faintMag > -5.0 && fabs(faintMag - blocks[nBlocks - 1]->getFaintMag()) > 0.2 ) {
146 qDebug() << Q_FUNC_INFO << "Encountered a jump from mag" << faintMag << "to mag"
147 << blocks[nBlocks - 1]->getFaintMag() << "in trixel" << trixel;
148 }
149 */
150 faintMag = blocks[nBlocks - 1]->getFaintMag();
151 nStars++;
152 }
153
154 return ((maglim < faintMag) ? true : false);
155}
156
157void StarBlockList::setStaticBlock(std::shared_ptr<StarBlock> &block)
158{
159 if (!block)
160 return;
161 if (nBlocks == 0)
162 {
163 blocks.append(block);
164 }
165 else
166 blocks[0] = block;
167
168 blocks[0]->parent = this;
169 faintMag = blocks[0]->faintMag;
170 nBlocks = 1;
171 staticStars = true;
172}
This class provides utility functions to handle binary data files in the format prescribed by KStars.
static int unsigned_KDE_fseek(FILE *stream, quint32 offset, int whence)
Wrapper around fseek for large offsets.
FILE * getFileHandle() const
Get the file handle corresponding to the currently open file.
bool getByteSwap() const
Should we do byte swapping?
long getOffset(int id) const
Returns the offset in the file corresponding to the given index ID.
int guessRecordSize() const
Return a guessed record size.
Stores and manages unnamed stars, most of which are dynamically loaded into memory.
bool hasStaticStars() const
A SkyNode derived class used for displaying PointNode with coordinates provided by SkyObject.
void deleteSkyNode(SkyNode *skyNode)
skyNode will be deleted on the next call to updatePaintNode (currently used only in StarNode(struct i...
A factory that creates StarBlocks and recycles them in an LRU Cache.
bool markNext(std::shared_ptr< StarBlock > &after, std::shared_ptr< StarBlock > &block)
Rank a given StarBlock after another given StarBlock in the LRU list and sync its drawID with the cur...
std::shared_ptr< StarBlock > getBlock()
Return a StarBlock available for use.
bool markFirst(std::shared_ptr< StarBlock > &block)
Mark a StarBlock as most recently used and sync its drawID with the current drawID.
std::shared_ptr< StarBlock > block(unsigned int i)
Returns the i-th block in this StarBlockList.
StarBlockList(const Trixel &trixel, DeepStarComponent *parent=nullptr)
Constructor for deep star catalogs.
void setStaticBlock(std::shared_ptr< StarBlock > &block)
Sets the first StarBlock in the list to point to the given StarBlock.
bool fillToMag(float maglim)
Ensures that the list is loaded with stars to given magnitude limit.
int releaseBlock(StarBlock *block)
Drops the StarBlock with the given pointer from the list.
Holds a block of stars and various peripheral variables to mark its place in data structures.
Definition starblock.h:43
void append(QList< T > &&value)
void removeLast()
qsizetype size() const const
A 16-byte structure that holds star data for really faint stars.
A 32-byte Structure that holds star data.
Definition stardata.h:18
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.