7#include <unordered_map>
17 const unsigned char *,
const Stars &stars,
const Catalog &catalog,
const Camera &)
const {
22 for (
int i = 0; i < (
int)stars.size(); i++) {
30 const unsigned char *database,
const Stars &stars,
const Catalog &catalog,
const Camera &camera)
const {
41 for (
int i = 0; i < (
int)stars.size(); i++) {
42 std::vector<int16_t>
votes(catalog.size(), 0);
44 for (
int j = 0; j < (
int)stars.size(); j++) {
47 std::vector<bool>
votedInPair(catalog.size(),
false);
185 : pairs(pairs), end(end), involving(involving) {
187 assert((end-pairs)%2 == 0);
188 ForwardUntilInvolving();
201 ForwardUntilInvolving();
229 void ForwardUntilInvolving() {
230 while (pairs != end) {
231 if (pairs[0] == involving) {
235 if (pairs[1] == involving) {
245 std::vector<int16_t>
result;
246 for (;
it.HasValue(); ++
it) {
260 std::unordered_multimap<int16_t, int16_t>
result;
261 for (
const int16_t *
p = pairs;
p != end;
p += 2) {
281 for (
const auto &
otherPair : identifiedStarsInRange) {
308 std::vector<std::vector<IRUnidentifiedCentroid *>::iterator>
result;
360 (*centroidIt)->AddIdentifiedStar(
starId, stars);
369 return std::find(nowBelowThreshold.begin(), nowBelowThreshold.end(), centroid->index) != nowBelowThreshold.end();
399 std::vector<int16_t>
result;
440 return a->bestAngleFrom90 < b->bestAngleFrom90;
467#ifdef LOST_DEBUG_PERFORMANCE
475 for (
size_t i = 0; i < stars.size(); i++) {
484 return identifier.starIndex == allUnidentifiedCentroids[i].index;
502 db.MinDistance(),
db.MaxDistance(),
542 std::cerr <<
"WARNING: Multiple catalog stars matched during identify remaining stars. This should be rare." << std::endl;
551 db.MinDistance(),
db.MaxDistance(),
563#ifdef LOST_DEBUG_PERFORMANCE
565 std::cout <<
"IdentifyRemainingStarsPairDistance took " << std::chrono::duration_cast<std::chrono::microseconds>(
endTimestamp -
startTimestamp).count() <<
"us" << std::endl;
572 const unsigned char *database,
const Stars &stars,
const Catalog &catalog,
const Camera &camera)
const {
578 std::cerr <<
"Not enough stars, or database missing." << std::endl;
592 int numStars = (
int)stars.size();
598 int jMax = numStars - 3;
616 std::cerr <<
"Cutoff reached." << std::endl;
624 assert(i != j && j != k && k !=
r && i != k && i !=
r && j !=
r);
646 std::cout <<
"skip: mismatch prob." << std::endl;
667#define _CHECK_DISTANCE(_dist) if (_dist < vectorDatabase.MinDistance() + tolerance || _dist > vectorDatabase.MaxDistance() - tolerance) { continue; }
673#undef _CHECK_DISTANCE
738 std::cerr <<
"Pyramid not unique, skipping..." << std::endl;
748 std::cout.precision(6);
749 std::cout <<
"Matched unique pyramid!" << std::endl <<
"Expected mismatches: " << std::scientific <<
expectedMismatches << std::endl << std::fixed;
768 std::cerr <<
"Tried all pyramids; none matched." << std::endl;
A full description of a camera. Enough information to reconstruct the camera matrix and then some.
Vec3 CameraToSpatial(const Vec2 &) const
Gives a point in 3d space that could correspond to the given vector, using the same coordinate system...
A star from the Bright Star Catalog.
StarIdentifiers Go(const unsigned char *database, const Stars &, const Catalog &, const Camera &) const
Actualy perform the star idenification. This is the "main" function for StarIdAlgorithm.
StarIdentifiers Go(const unsigned char *database, const Stars &, const Catalog &, const Camera &) const
Actualy perform the star idenification. This is the "main" function for StarIdAlgorithm.
unidentified centroid used in IdentifyRemainingStarsPairDistance The "angles" through here are "trian...
const Star * star
Index into list of all centroids.
StarIdentifier bestStar1
For the pair of other centroids forming the triangular angle closest to 90 degrees,...
void AddIdentifiedStar(const StarIdentifier &starId, const Stars &stars)
When a centroid within range of this centroid is identified, call this function.
StarIdentifier bestStar2
One star corresponding to bestAngleFrom90.
Given a list of star pairs, finds all those pairs which involve a certain star.
PairDistanceInvolvingIterator(const int16_t *pairs, const int16_t *end, int16_t involving)
The main constructor.
PairDistanceInvolvingIterator & operator++()
Move to the next matching pair.
int16_t operator*() const
Access the curent pair.
bool HasValue()
Whether the iterator is currently on a value. (false if iteration is complete)
PairDistanceInvolvingIterator()
Create a "past-the-end" iterator.
A database storing distances between pairs of stars.
static const int32_t kMagicValue
Magic value to use when storing inside a MultiDatabase.
StarIdentifiers Go(const unsigned char *database, const Stars &, const Catalog &, const Camera &) const
Actualy perform the star idenification. This is the "main" function for StarIdAlgorithm.
A "centroid" detected in an image.
Vec2 position
The (x,y) pixel coordinates in the image (top left is 0,0)
Records that a certain Star (detected in the image) corresponds to a certain CatalogStar.
Three dimensional vector with decimaling point components.
Vec3 Normalize() const
Create a vector pointing in the same direction with magnitude 1.
Vec3 CrossProduct(const Vec3 &) const
Usual vector cross product.
#define DECIMAL_POW(base, power)
#define DECIMAL_ATAN2(x, y)
std::vector< std::vector< IRUnidentifiedCentroid * >::iterator > FindUnidentifiedCentroidsInRange(std::vector< IRUnidentifiedCentroid * > *centroids, const Star &star, const Camera &camera, decimal minDistance, decimal maxDistance)
Return all the unidentified centroids within the requested distance bounds from star
const decimal kAngleFrom90SoftThreshold
std::vector< StarIdentifier > StarIdentifiers
IRUnidentifiedCentroid * SelectNextUnidentifiedCentroid(std::vector< IRUnidentifiedCentroid * > *aboveThresholdCentroids, std::vector< IRUnidentifiedCentroid * > *belowThresholdCentroids)
std::vector< Star > Stars
decimal AngleUnit(const Vec3 &vec1, const Vec3 &vec2)
Calculate the inner angle, in radians, between two /unit/ vectors.
decimal Angle(const Vec3 &vec1, const Vec3 &vec2)
Calculate the inner angle, in radians, between two vectors.
std::vector< int16_t > ConsumeInvolvingIterator(PairDistanceInvolvingIterator it)
int IdentifyRemainingStarsPairDistance(StarIdentifiers *, const Stars &, const PairDistanceKVectorDatabase &, const Catalog &, const Camera &, decimal tolerance)
Given some identified stars, attempt to identify the rest.
decimal DecimalModulo(decimal x, decimal mod)
Given a decimal, find it "modulo" another decimal, in the true mathematical sense (not remainder).
std::vector< int16_t > IdentifyThirdStar(const PairDistanceKVectorDatabase &db, const Catalog &catalog, int16_t catalogIndex1, int16_t catalogIndex2, decimal distance1, decimal distance2, decimal tolerance)
Given two already-identified centroids, and the distance from each to an as-yet unidentified third ce...
void SerializePrimitive(SerializeContext *ser, const T &val)
std::unordered_multimap< int16_t, int16_t > PairDistanceQueryToMap(const int16_t *pairs, const int16_t *end)
Given the result of a pair-distance kvector query, build a hashmultimap of stars to other stars that ...
std::vector< CatalogStar > Catalog
void AddToAllUnidentifiedCentroids(const StarIdentifier &starId, const Stars &stars, std::vector< IRUnidentifiedCentroid * > *aboveThresholdCentroids, std::vector< IRUnidentifiedCentroid * > *belowThresholdCentroids, decimal minDistance, decimal maxDistance, decimal angleFrom90Threshold, const Camera &camera)
Given a list of unidentified centroids not yet at the soft threshold, and a list of unidentified cent...
#define _CHECK_DISTANCE(_dist)
A two dimensional vector with decimaling point components.