LOST 0.0.1
LOST: Open-source Star Tracker
Loading...
Searching...
No Matches
star-utils.hpp
Go to the documentation of this file.
1#ifndef STAR_UTILS_H
2#define STAR_UTILS_H
3
4#include <algorithm>
5#include <vector>
6
7#include "attitude-utils.hpp"
9
10namespace lost {
11
42
71
77public:
80
83
84 // does not check weight
85 bool operator==(const StarIdentifier& other) const {
86 return starIndex == other.starIndex &&
88 }
89
96};
97
98typedef std::vector<CatalogStar> Catalog;
99typedef std::vector<Star> Stars;
100typedef std::vector<StarIdentifier> StarIdentifiers;
101
102void SerializeCatalog(SerializeContext *, const Catalog &, bool inclMagnitude, bool inclName);
103// sets magnited and name to whether the catalog in the database contained magnitude and name
104Catalog DeserializeCatalog(DeserializeContext *des, bool *inclMagnitudeReturn, bool *inclNameReturn);
105Catalog::const_iterator FindNamedStar(const Catalog &catalog, int name);
106
109
128Catalog NarrowCatalog(const Catalog &, decimal maxMagnitude, int maxStars, decimal minSeparation);
129
130// Hash binned edge ratios of a Tetra star pattern into an index in the pattern table.
131size_t TetraFindPatternIndex(const int* patternEdgeRatios,
132 size_t numRatios,
133 int numEdgeRatioBins,
134 size_t tableSize);
135
136// Generates all ways to choose k items from n, prioritizing patterns whose
137// dimmest star is as bright as possible (intuitively we want to avoid a bad centroid ruining a
138// pattern) E.g. for k=4, n=8: 0123, 0124, 0134, 0234, 1234, 0125, ... Formally, all combinations
139// using only items 0..m are exhausted before item m+1 appears
141 public:
142 CombinationIterator(int k, int n) : k_(k), n_(n), indices_(k), isFirst_(true) {
143 for (int i = 0; i < k; i++)
144 indices_[i] = i;
145 }
146
147 bool next() {
148 if (isFirst_) {
149 isFirst_ = false;
150 return n_ >= k_;
151 }
152 int i = 0;
153 // Find leftmost index that can be incremented
154 while (i < k_ && indices_[i] + 1 == (i + 1 < k_ ? indices_[i + 1] : n_)) {
155 i++;
156 }
157 if (i == k_) return false;
158 indices_[i]++;
159 // Reset everything before the index we just changed
160 for (int j = 0; j < i; j++)
161 indices_[j] = j;
162 return true;
163 }
164
165 const std::vector<int>& indices() const { return indices_; }
166
167 private:
168 int k_, n_;
169 std::vector<int> indices_;
170 bool isFirst_;
171};
172
174 static constexpr int numPatternStars = 4;
175};
176
177// Check whether all pairs of stars have angular distance within maxFov.
178// SpatialAccessor(int i) must return const Vec3&.
179template <typename SpatialAccessor>
180bool AllPairsWithinFov(int numStars, SpatialAccessor spatial, decimal cosMaxFov) {
181 for (int i = 0; i < numStars; i++) {
182 for (int j = i + 1; j < numStars; j++) {
183 if (spatial(i) * spatial(j) <= cosMaxFov) return false;
184 }
185 }
186 return true;
187}
188
189// Compute sorted edge ratios for a star pattern. SpatialAccessor(int i) must return const Vec3&.
190template <typename SpatialAccessor>
191std::vector<decimal> TetraEdgeRatios(int numStars, SpatialAccessor spatial) {
192 std::vector<decimal> edgeLengths;
193 for (int i = 0; i < numStars; i++) {
194 for (int j = i + 1; j < numStars; j++) {
195 edgeLengths.push_back((spatial(j) - spatial(i)).Magnitude());
196 }
197 }
198 std::sort(edgeLengths.begin(), edgeLengths.end());
199 decimal longestEdgeLen = edgeLengths.back();
200 std::vector<decimal> edgeRatios;
201 for (size_t i = 0; i < edgeLengths.size() - 1; i++) {
202 edgeRatios.push_back(edgeLengths[i] / longestEdgeLen);
203 }
204 return edgeRatios;
205}
206
207} // namespace lost
208
209#endif
CatalogStar(decimal raj2000, decimal dej2000, decimal magnitude, int name)
Create a CatalogStar using its celestial/spherical coordinates.
int name
A unique number which unambiguously identifies the catalog star.
decimal magnitude
The apparent magnitude of the star (e.g., Sirius = -1.46, Polaris = 1.98).
Vec3 spatial
The point on the unit sphere where the star lies.
CatalogStar(Vec3 spatial, decimal magnitude, int name)
CatalogStar()=default
CombinationIterator(int k, int n)
const std::vector< int > & indices() const
decimal weight
A weight indicating the confidence of this idenification. Often just 1.
bool operator==(const StarIdentifier &other) const
int catalogIndex
An index into an array of CatalogStar objects.
StarIdentifier(int starIndex, int catalogIndex, int weight)
StarIdentifier(int starIndex, int catalogIndex)
Sets StarIdentifier.weight = 1.
int starIndex
An index into an array of Star objects.
Star(decimal x, decimal y, decimal radiusX, decimal radiusY, decimal magnitude)
decimal radiusY
Approximate vertical radius of the bright area in pixels.
Star()
Create a zeroed-out star. Fields should be set immediately after construction.
Vec2 position
The (x,y) pixel coordinates in the image (top left is 0,0).
Star(decimal x, decimal y, decimal radiusX)
Convenience constructor that sets Star.radiusY = radiusX and Star.magnitude = 0.
decimal radiusX
Approximate horizontal radius of the bright area in pixels.
decimal magnitude
A relative measure of magnitude of the star.
Three dimensional vector with decimaling point components.
double decimal
Definition decimal.hpp:8
#define DECIMAL(x)
Definition decimal.hpp:18
LOST starting point.
bool AllPairsWithinFov(int numStars, SpatialAccessor spatial, decimal cosMaxFov)
std::vector< StarIdentifier > StarIdentifiers
void SerializeCatalog(SerializeContext *ser, const Catalog &catalog, bool inclMagnitude, bool inclName)
Serialize the catalog to buffer.
size_t TetraFindPatternIndex(const int *patternEdgeRatios, size_t numRatios, int numEdgeRatioBins, size_t tableSize)
Catalog DeserializeCatalog(DeserializeContext *des, bool *inclMagnitudeReturn, bool *inclNameReturn)
Deserialize a catalog.
std::vector< Star > Stars
Vec3 SphericalToSpatial(decimal ra, decimal de)
Convert from right ascension & declination to a 3d point on the unit sphere.
std::vector< decimal > TetraEdgeRatios(int numStars, SpatialAccessor spatial)
Catalog NarrowCatalog(const Catalog &catalog, decimal maxMagnitude, int maxStars, decimal minSeparation)
Remove unwanted stars from an unfiltered catalog.
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
decimal MagToBrightness(decimal mag)
returns some relative brightness measure, which is proportional to the total number of photons receiv...
static constexpr int numPatternStars
A two dimensional vector with decimaling point components.