LOST 0.0.1
LOST: Open-source Star Tracker
Loading...
Searching...
No Matches
star-utils.cpp
Go to the documentation of this file.
1#include "star-utils.hpp"
2
3#include <math.h>
4#include <assert.h>
5#include <algorithm>
6#include <set>
7
9
10namespace lost {
11
12// brightest star first
14 return a.magnitude < b.magnitude;
15}
16
19 for (int i = 0; i < (int)catalog.size(); i++) {
20 if (catalog[i].magnitude <= maxMagnitude) {
21 result.push_back(catalog[i]);
22 }
23 }
24
25 // remove stars that are too close to each other
26 std::set<int> tooCloseIndices;
27 // filter out stars that are too close together
28 // easy enough to n^2 brute force, the catalog isn't that big
29 for (int i = 0; i < (int)result.size(); i++) {
30 for (int j = i+1; j < (int)result.size(); j++) {
31 if (AngleUnit(result[i].spatial, result[j].spatial) < minSeparation) {
32 tooCloseIndices.insert(i);
33 tooCloseIndices.insert(j);
34 }
35 }
36 }
37
38 // Erase all the stars whose indices are in tooCloseIndices from the result.
39 // Loop backwards so indices don't get messed up as we iterate.
40 for (auto it = tooCloseIndices.rbegin(); it != tooCloseIndices.rend(); it++) {
41 result.erase(result.begin() + *it);
42 }
43
44 // and finally limit to n brightest stars
45 if (maxStars < (int)result.size()) {
46 std::sort(result.begin(), result.end(), CatalogStarMagnitudeCompare);
47 result.resize(maxStars);
48 }
49
50 return result;
51}
52
54Catalog::const_iterator FindNamedStar(const Catalog &catalog, int name) {
55 for (auto it = catalog.cbegin(); it != catalog.cend(); ++it) {
56 if (it->name == name) {
57 return it;
58 }
59 }
60 return catalog.cend();
61}
62
72 if (inclMagnitude) {
74 }
75 if (inclName) {
76 // TODO: double check that bools aren't some special bitwise thing in C++
78 }
79}
80
89 if (inclMagnitude) {
91 } else {
92 result.magnitude = -424242; // TODO, what to do about special values, since there's no good ones for ints.
93 }
94 if (inclName) {
96 } else {
97 result.name = -1;
98 }
99 return result;
100}
101
108 SerializePrimitive<int16_t>(ser, catalog.size());
109
110 // flags
111 int8_t flags = (inclMagnitude) | (inclName << 1);
113
114 for (const CatalogStar &catalogStar : catalog) {
116 }
117}
118
126
128
130 inclMagnitude = (flags) & 1;
131 inclName = (flags>>1) & 1;
132
133 if (inclMagnitudeReturn != NULL) {
135 }
136 if (inclNameReturn != NULL) {
138 }
139
140 for (int i = 0; i < numStars; i++) {
142 }
143
144 return result;
145}
146
148 return DECIMAL_POW(DECIMAL(10.0), -mag/DECIMAL(250.0));
149}
150
151}
A star from the Bright Star Catalog.
Vec3 spatial
The point on the unit sphere where the star lies.
double decimal
Definition decimal.hpp:11
#define DECIMAL(x)
Definition decimal.hpp:21
#define DECIMAL_POW(base, power)
Definition decimal.hpp:39
LOST starting point.
void SerializeCatalogStar(SerializeContext *ser, const CatalogStar &catalogStar, bool inclMagnitude, bool inclName)
Serialize a CatalogStar into a byte buffer.
void SerializeCatalog(SerializeContext *ser, const Catalog &catalog, bool inclMagnitude, bool inclName)
Serialize the catalog to buffer.
Catalog DeserializeCatalog(DeserializeContext *des, bool *inclMagnitudeReturn, bool *inclNameReturn)
Deserialize a catalog.
decimal MagToBrightness(int mag)
returns some relative brightness measure, which is proportional to the total number of photons receiv...
decimal AngleUnit(const Vec3 &vec1, const Vec3 &vec2)
Calculate the inner angle, in radians, between two /unit/ vectors.
bool CatalogStarMagnitudeCompare(const CatalogStar &a, const CatalogStar &b)
CatalogStar DeserializeCatalogStar(DeserializeContext *des, bool inclMagnitude, bool inclName)
Deserialize a catalog star.
Catalog NarrowCatalog(const Catalog &catalog, int maxMagnitude, int maxStars, decimal minSeparation)
Remove unwanted stars from an unfiltered catalog.
void SerializePrimitive(SerializeContext *ser, const T &val)
void SerializeVec3(SerializeContext *ser, const Vec3 &vec)
Serialize a Vec3 to buffer. Takes up space according to SerializeLengthVec3.
Vec3 DeserializeVec3(DeserializeContext *des)
Catalog::const_iterator FindNamedStar(const Catalog &catalog, int name)
Return a pointer to the star with the given name, or NULL if not found.
std::vector< CatalogStar > Catalog