Kstars

highpmstarlist.cpp
1 /*
2  SPDX-FileCopyrightText: 2007 James B. Bowlin <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "highpmstarlist.h"
8 
9 #include "skymesh.h"
10 #include "skyobjects/starobject.h"
11 
12 #include <QDebug>
13 
14 typedef struct HighPMStar
15 {
16  HighPMStar(Trixel t, StarObject *s) : trixel(t), star(s) {}
17  Trixel trixel;
18  StarObject *star { nullptr };
19 
20 } HighPMStar;
21 
22 HighPMStarList::HighPMStarList(double threshold) : m_reindexNum(J2000), m_threshold(threshold)
23 {
24  m_skyMesh = SkyMesh::Instance();
25 }
26 
27 HighPMStarList::~HighPMStarList()
28 {
29  qDeleteAll(m_stars);
30  m_stars.clear();
31 }
32 
33 bool HighPMStarList::append(Trixel trixel, StarObject *star, double pm)
34 {
35  if (pm < m_threshold)
36  return false;
37 
38  if (trixel >= m_skyMesh->size())
39  qDebug() << Q_FUNC_INFO << "### Trixel ID out of range for the Mesh currently in use!" << trixel;
40 
41  m_stars.append(new HighPMStar(trixel, star));
42  if (m_maxPM >= pm)
43  return true;
44 
45  m_maxPM = pm;
46  m_reindexInterval = StarObject::reindexInterval(pm);
47 
48  return true;
49 }
50 
52 {
53  m_reindexNum = KSNumbers(*num);
54 }
55 
57 {
58  if (fabs(num->julianCenturies() - m_reindexNum.julianCenturies()) < m_reindexInterval)
59  return false;
60 
61  m_reindexNum = KSNumbers(*num);
62  m_skyMesh->setKSNumbers(num);
63 
64  int cnt(0);
65 
66  for (auto &HPStar : m_stars)
67  {
68  Trixel trixel = m_skyMesh->indexStar(HPStar->star);
69 
70  if (trixel == HPStar->trixel)
71  continue;
72  cnt++;
73  StarObject *star = HPStar->star;
74 
75  // out with the old ...
76  if (HPStar->trixel >= m_skyMesh->size())
77  {
78  qDebug() << Q_FUNC_INFO << "### Expect an Index out-of-range error. star->trixel =" << HPStar->trixel;
79  }
80 
81  StarList *old = starIndex->at(HPStar->trixel);
82  old->removeAt(old->indexOf(star));
83 
84  float mag = star->mag();
85  //printf("\n mag = %4.2f trixel %d -> %d\n", mag, HPStar->trixel, trixel );
86 
87  // in with the new ...
88  HPStar->trixel = trixel;
89  if (trixel >= m_skyMesh->size())
90  qDebug() << Q_FUNC_INFO << "### Expect an Index out-of-range error. trixel =" << trixel;
91 
92  StarList *list = starIndex->at(trixel);
93  int j;
94  for (j = 0; j < list->size(); j++)
95  {
96  if (list->at(j)->mag() < mag)
97  continue;
98  list->insert(j, star);
99  break;
100  }
101  if (j == list->size())
102  list->append(star);
103 
104  //for ( j = 0; j < list->size(); j++ ) {
105  // printf(" %4.2f\n", list->at(j)->mag() );
106  //}
107  }
108  return true;
109  //printf("Re-indexed %d stars at interval %6.1f\n", cnt, 100.0 * m_reindexInterval );
110 }
111 
113 {
114  printf("\n");
115  printf("maxPM: %6.1f threshold %5.1f\n", m_maxPM, m_threshold);
116  printf("stars: %d\n", size());
117  printf("Update Interval: %6.1f years\n", 100.0 * m_reindexInterval);
118  printf("Last Update: %6.1f\n", 2000.0 + 100.0 * (int)m_reindexNum.julianCenturies());
119 }
void setKSNumbers(KSNumbers *num)
sets the time for indexing StarObjects and CLines.
Definition: skymesh.h:145
void append(const T &value)
void append(const T &value)
float mag() const
Definition: skyobject.h:206
void removeAt(int i)
int size() const const
void clear()
Store several time-dependent astronomical quantities.
Definition: ksnumbers.h:42
Trixel indexStar(StarObject *star)
returns the trixel that contains the star at the set time with proper motion taken into account but n...
Definition: skymesh.cpp:91
subclass of SkyObject specialized for stars.
Definition: starobject.h:32
int indexOf(const T &value, int from) const const
const T & at(int i) const const
void setIndexTime(KSNumbers *num)
sets the time this list was last indexed to.
const T & at(int i) const const
int size() const
returns the total number of trixels in the HTM.
Definition: HTMesh.h:118
void insert(int i, const T &value)
static SkyMesh * Instance()
returns the default instance of SkyMesh or null if it has not yet been created.
Definition: skymesh.cpp:39
bool append(Trixel trixel, StarObject *star, double pm)
adds the star located at trixel to the list if the pm is greater than the threshold.
double julianCenturies() const
Definition: ksnumbers.h:88
HighPMStarList(double threshold)
Constructor.
void stats()
prints out some brief statistics.
static double reindexInterval(double pm)
returns the reindex interval (in centuries!) for the given magnitude of proper motion (in milliarcsec...
Definition: starobject.cpp:46
bool reindex(KSNumbers *num, StarIndex *starIndex)
if the date in num differs from the last time we indexed by more than our update interval then we re-...
int size() const
returns the number of stars in the list.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 03:59:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.