LOST 0.0.1
LOST: Open-source Star Tracker
Loading...
Searching...
No Matches
databases.hpp
Go to the documentation of this file.
1#ifndef DATABASE_BUILDER_H
2#define DATABASE_BUILDER_H
3
4#include <stdlib.h>
5#include <inttypes.h>
6#include <vector>
7
8#include "star-utils.hpp"
10
11namespace lost {
12
13const int32_t kCatalogMagicValue = 0xF9A283BC;
14
16
22// TODO: QueryConservative, QueryExact, QueryTrapezoidal?
24public:
26
28
30 long NumValues() const { return numValues; };
31 long NumBins() const { return numBins; };
33 decimal Max() const { return max; };
34 // Lower bound on elements
35 decimal Min() const { return min; };
36private:
37 long BinFor(decimal dist) const;
38
39 long numValues;
40 decimal min;
41 decimal max;
42 decimal binWidth;
43 long numBins;
44 const int32_t *bins;
45};
46
47void SerializePairDistanceKVector(SerializeContext *, const Catalog &, decimal minDistance, decimal maxDistance, long numBins);
48
55public:
57
58 const int16_t *FindPairsLiberal(decimal min, decimal max, const int16_t **end) const;
59 const int16_t *FindPairsExact(const Catalog &, decimal min, decimal max, const int16_t **end) const;
60 std::vector<decimal> StarDistances(int16_t star, const Catalog &) const;
61
63 decimal MaxDistance() const { return index.Max(); };
65 decimal MinDistance() const { return index.Min(); };
67 long NumPairs() const;
68
70 static const int32_t kMagicValue; // 0x2536f009
71 // apparently you're supposed to not actually put the value of the static variables here, but
72 // rather in a cpp implementation file.
73private:
74 KVectorIndex index;
75 // TODO: endianness
76 const int16_t *pairs;
77};
78
79// /**
80// * @brief Stores "inner angles" between star triples
81// * @details Unsensitive to first-order error in basic camera
82// * parameters (eg, wrong FOV or principal point), can be sensitive to second-order errors (eg,
83// * camera distortion, which may cause the effective FOV or principal point to be different in
84// * different parts of the image). Used for Mortari's Non-Dimensional Star-ID
85// */
86// class TripleInnerKVectorDatabase {
87// public:
88// explicit TripleInnerKVectorDatabase(const unsigned char *databaseBytes);
89
90// void FindTriplesLiberal(decimal min, decimal max, long **begin, long **end) const;
91// private:
92// KVectorIndex index;
93// int16_t *triples;
94// };
95
102#define MULTI_DB_FLOAT_FLAG 0x0001 // By default, our DB is in double mode.
103
105public:
107 explicit MultiDatabase(const unsigned char *buffer) : buffer(buffer) { };
108 const unsigned char *SubDatabasePointer(int32_t magicValue) const;
109private:
110 const unsigned char *buffer;
111};
112
114public:
115 MultiDatabaseEntry(int32_t magicValue, std::vector<unsigned char> bytes) // I wonder if making `bytes` a reference would avoid making two copies, or maybe it would be worse by preventing copy-elision
117
120 std::vector<unsigned char> bytes;
121};
122
123typedef std::vector<MultiDatabaseEntry> MultiDatabaseDescriptor;
124
126
127}
128
129#endif
A data structure enabling constant-time range queries into fixed numerical data.
Definition databases.hpp:23
decimal Min() const
Definition databases.hpp:35
long QueryLiberal(decimal minQueryDistance, decimal maxQueryDistance, long *upperIndex) const
Finds all the entries in the given range, and possibly a few just outside the range on the ends.
long NumBins() const
Definition databases.hpp:31
decimal Max() const
Upper bound on elements.
Definition databases.hpp:33
long NumValues() const
The number of data points in the data referred to by the kvector.
Definition databases.hpp:30
std::vector< unsigned char > bytes
MultiDatabaseEntry(int32_t magicValue, std::vector< unsigned char > bytes)
uint32_t flags
int32_t magicValue
MultiDatabase(const unsigned char *buffer)
Create a multidatabase from a serialized multidatabase.
const unsigned char * SubDatabasePointer(int32_t magicValue) const
MultiDatabase memory layout:
A database storing distances between pairs of stars.
Definition databases.hpp:54
long NumPairs() const
Exact number of stored pairs.
std::vector< decimal > StarDistances(int16_t star, const Catalog &) const
Return the distances from the given star to each star it's paired with in the database (for debugging...
decimal MinDistance() const
Lower bound on stored star pair distances.
Definition databases.hpp:65
static const int32_t kMagicValue
Magic value to use when storing inside a MultiDatabase.
Definition databases.hpp:70
const int16_t * FindPairsExact(const Catalog &, decimal min, decimal max, const int16_t **end) const
const int16_t * FindPairsLiberal(decimal min, decimal max, const int16_t **end) const
Return at least all the star pairs whose inter-star distance is between min and max.
decimal MaxDistance() const
Upper bound on stored star pair distances.
Definition databases.hpp:63
double decimal
Definition decimal.hpp:11
LOST starting point.
const int32_t kCatalogMagicValue
Definition databases.hpp:13
void SerializePairDistanceKVector(SerializeContext *ser, const Catalog &catalog, decimal minDistance, decimal maxDistance, long numBins)
Serialize a pair-distance KVector into buffer.
bool isFlagSet(uint32_t dbFlags, uint32_t flag)
Definition databases.cpp:19
void SerializePrimitive(SerializeContext *ser, const T &val)
std::vector< MultiDatabaseEntry > MultiDatabaseDescriptor
void SerializeMultiDatabase(SerializeContext *ser, const MultiDatabaseDescriptor &dbs, uint32_t flags)
std::vector< CatalogStar > Catalog