4#include <cairo/cairo.h>
37 if (isBinary && isatty(fileno(stdout)) && (filePath ==
"stdout" || filePath ==
"-")) {
38 std::cerr <<
"WARNING: output contains binary contents. Not printed to terminal." << std::endl;
39 filePath =
"/dev/null";
42 if (filePath ==
"stdout" || filePath ==
"-") {
46 std::fstream *fs =
new std::fstream();
47 fs->open(filePath, std::fstream::out);
60std::vector<CatalogStar>
BscParse(std::string tsvPath) {
61 std::vector<CatalogStar> result;
68 file = fopen(tsvPath.c_str(),
"r");
71 printf(
"Error opening file: %s\n", strerror(errno));
77 std::string format =
"%f|%f|%d|%c|%f";
79 std::string format =
"%lf|%lf|%d|%c|%lf";
82 while (EOF != fscanf(file, format.c_str(), &raj2000, &dej2000, &name, &weird, &magnitude)) {
87 assert(result.size() > 9000);
91#ifndef DEFAULT_BSC_PATH
92#define DEFAULT_BSC_PATH "bright-star-catalog.tsv"
97 static bool readYet =
false;
98 static std::vector<CatalogStar> catalog;
102 char *tsvPath = getenv(
"LOST_BSC_PATH");
107 return a.spatial.x < b.spatial.x;
109 for (
int i = catalog.size()-1; i > 0; i--) {
110 if ((catalog[i].spatial - catalog[i-1].spatial).Magnitude() <
DECIMAL(5e-5)) {
111 if (catalog[i].magnitude > catalog[i-1].magnitude) {
112 catalog.erase(catalog.begin() + i);
114 catalog.erase(catalog.begin() + i - 1);
126 unsigned char *result;
127 uint32_t *cairoImage, pixel;
129 if (cairo_image_surface_get_format(cairoSurface) != CAIRO_FORMAT_ARGB32 &&
130 cairo_image_surface_get_format(cairoSurface) != CAIRO_FORMAT_RGB24) {
131 puts(
"Can't convert weird image formats to grayscale.");
135 width = cairo_image_surface_get_width(cairoSurface);
136 height = cairo_image_surface_get_height(cairoSurface);
138 result =
new unsigned char[width*height];
139 cairoImage = (uint32_t *)cairo_image_surface_get_data(cairoSurface);
141 for (
int i = 0; i < height * width; i++) {
142 pixel = cairoImage[i];
145 (pixel>>16 &0xFF) *0.21 +
146 (pixel>>8 &0xFF) *0.71 +
147 (pixel &0xFF) *0.07);
154 const int width,
const int height) {
156 cairo_surface_t *result = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
157 uint32_t *resultData = (uint32_t *)cairo_image_surface_get_data(result);
159 cairo_surface_flush(result);
160 for (
long i = 0; i < width * height; i++) {
162 resultData[i] = (image[i] << 16) + (image[i] << 8) + (image[i]);
164 cairo_surface_mark_dirty(result);
176 cairo_surface_t *cairoSurface,
186 bool rawStarIndexes =
false) {
188 std::string metadata = description +
" ";
190 cairoCtx = cairo_create(cairoSurface);
191 cairo_set_source_rgba(cairoCtx, red, green, blue, alpha);
192 cairo_set_line_width(cairoCtx, 1.0);
193 cairo_set_antialias(cairoCtx, CAIRO_ANTIALIAS_NONE);
194 cairo_font_options_t *cairoFontOptions = cairo_font_options_create();
195 cairo_font_options_set_antialias(cairoFontOptions, CAIRO_ANTIALIAS_NONE);
196 cairo_set_font_options(cairoCtx, cairoFontOptions);
197 cairo_text_extents_t cairoTextExtents;
198 cairo_text_extents(cairoCtx,
"1234567890", &cairoTextExtents);
199 decimal textHeight = cairoTextExtents.height;
201 for (
const Star ¢roid : stars) {
203 if (centroid.radiusX >
DECIMAL(0.0)) {
204 decimal radiusX = centroid.radiusX;
206 centroid.radiusY : radiusX;
210 cairo_rectangle(cairoCtx,
211 (
double) (centroid.position.x - radiusX),
212 (
double) (centroid.position.y - radiusY),
213 (
double) (radiusX * 2),
214 (
double) (radiusY * 2));
215 cairo_stroke(cairoCtx);
217 cairo_rectangle(cairoCtx,
221 cairo_fill(cairoCtx);
225 metadata += std::to_string(stars.size()) +
" centroids ";
227 if (starIds != NULL) {
228 assert(catalog != NULL);
231 const Star ¢roid = stars[starId.starIndex];
232 cairo_move_to(cairoCtx,
242 int plotName = rawStarIndexes ? starId.catalogIndex : (*catalog)[starId.catalogIndex].name;
243 cairo_show_text(cairoCtx, std::to_string(plotName).c_str());
245 metadata += std::to_string(starIds->size()) +
" identified ";
248 if (attitude != NULL) {
251 "RA: " + std::to_string(
RadToDeg(spherical.
ra)) +
" " +
252 "DE: " + std::to_string(
RadToDeg(spherical.
de)) +
" " +
253 "Roll: " + std::to_string(
RadToDeg(spherical.
roll)) +
" ";
257 cairo_move_to(cairoCtx, 3, (
double) (3 + textHeight));
258 cairo_show_text(cairoCtx, metadata.c_str());
260 cairo_font_options_destroy(cairoFontOptions);
261 cairo_destroy(cairoCtx);
290 std::vector<uint16_t> catalogPatternStarInds =
292 std::cerr <<
"Number of pattern stars: " << catalogPatternStarInds.size() << std::endl;
300 if (dbEntries.size() <= 1) {
301 std::cerr <<
"No database builder selected -- no database generated." << std::endl;
310 os <<
"camera_focal_length " << camera.
FocalLength() << std::endl
311 <<
"camera_fov " << camera.
Fov() << std::endl
312 <<
"camera_resolution_x " << camera.
XResolution() << std::endl
313 <<
"camera_resolution_y " << camera.
YResolution() << std::endl;
326 std::cerr <<
"ERROR: Exactly one of --pixel-size or --focal-length were set." << std::endl;
332 std::cerr <<
"ERROR: Both focal length and FOV were provided. We only need one of the two methods (pixel size + focal length, or fov) to determine fov, please only provide one." << std::endl;
372 : camera(camera), catalog(catalog) {
375 image.width = cairo_image_surface_get_width(cairoSurface);
376 image.height = cairo_image_surface_get_height(cairoSurface);
380 delete[] image.image;
384static std::unique_ptr<PipelineInput> ReadPngPipelineInput(
const std::string &pngPath,
const PipelineOptions &values) {
385 cairo_surface_t *cairoSurface = cairo_image_surface_create_from_png(pngPath.c_str());
386 std::cerr <<
"PNG Read status: " << cairo_status_to_string(cairo_surface_status(cairoSurface)) << std::endl;
387 if (cairoSurface == NULL || cairo_surface_status(cairoSurface) != CAIRO_STATUS_SUCCESS) {
388 std::cerr <<
"ERROR: Can't read " << pngPath <<
" as a PNG image." << std::endl;
392 int xResolution = cairo_image_surface_get_width(cairoSurface);
393 int yResolution = cairo_image_surface_get_height(cairoSurface);
395 Camera cam = Camera(focalLengthPixels, xResolution, yResolution);
397 std::unique_ptr<PipelineInput> result(
new PngPipelineInput(cairoSurface, cam,
CatalogRead()));
398 cairo_surface_destroy(cairoSurface);
404 for (
const std::string &pngPath : values.
png) {
405 result.push_back(ReadPngPipelineInput(pngPath, values));
411static PipelineInputList GetImageDirPipelineInput(
const PipelineOptions &values) {
412 DIR *dir = opendir(values.imageDir.c_str());
414 std::cerr <<
"ERROR: Can't open directory " << values.imageDir <<
": " << strerror(errno) << std::endl;
417 std::vector<std::string> names;
418 while (
struct dirent *entry = readdir(dir)) {
419 std::string name = entry->d_name;
420 std::string extension = name.size() > 4 ? name.substr(name.size() - 4) :
"";
421 std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
422 if (extension !=
".png") {
426 if (stat((values.imageDir +
"/" + name).c_str(), &status) != 0) {
428 std::cerr <<
"ERROR: Can't read " << values.imageDir <<
"/" << name <<
": " << strerror(errno) << std::endl;
432 if (S_ISREG(status.st_mode)) {
433 names.push_back(name);
438 std::cerr <<
"ERROR: No .png files in " << values.imageDir << std::endl;
441 std::sort(names.begin(), names.end());
444 for (
const std::string &name : names) {
445 result.push_back(ReadPngPipelineInput(values.imageDir +
"/" + name, values));
495 const Vec2 d0 = p0 - pixel;
504static decimal StaticPixelBrightness(
const Vec2 &pixel,
const GeneratedStar &generatedStar,
506 const Vec2 d0 = generatedStar.position - pixel;
507 return generatedStar.peakBrightness * t *
DECIMAL_EXP(-d0.MagnitudeSq() / (2 * stddev * stddev));
536 std::default_random_engine *rng,
554 : camera(camera), attitude(attitude), catalog(catalog), centroidsOnly(centroidsOnly) {
556 assert(falseStarMaxMagnitude <= falseStarMinMagnitude);
557 assert(perturbationStddev >=
DECIMAL(0.0));
559 image.width = camera.XResolution();
560 image.height = camera.YResolution();
563 assert(oversampling >= 1);
565 if (oversamplingPerAxis*oversamplingPerAxis != oversampling) {
566 std::cerr <<
"WARNING: oversampling was not a perfect square. Rounding up to "
567 << oversamplingPerAxis*oversamplingPerAxis <<
"." << std::endl;
569 assert(exposureTime > 0);
573 Quaternion currentAttitude = attitude.GetQuaternion();
575 Quaternion futureAttitude = motionBlurDirectionQ*currentAttitude;
576 std::vector<GeneratedStar> generatedStars;
580 decimal zeroMagPeakPhotonDensity = zeroMagTotalPhotons / (2*
DECIMAL_M_PI * starSpreadStdDev*starSpreadStdDev);
582 Catalog catalogWithFalse = catalog;
584 std::uniform_real_distribution<decimal> uniformDistribution(
DECIMAL(0.0),
DECIMAL(1.0));
585 std::uniform_real_distribution<decimal> magnitudeDistribution(falseStarMaxMagnitude,
586 falseStarMinMagnitude);
587 for (
int i = 0; i < numFalseStars; i++) {
591 decimal magnitude = magnitudeDistribution(*rng);
593 catalogWithFalse.push_back(
CatalogStar(ra, de, magnitude, -1));
596 for (
int i = 0; i < (int)catalogWithFalse.size(); i++) {
597 bool isTrueStar = i < (int)catalog.size();
599 const CatalogStar &catalogStar = catalogWithFalse[i];
600 Vec3 rotated = attitude.Rotate(catalogWithFalse[i].spatial);
601 if (rotated.
x <= 0) {
604 Vec2 camCoords = camera.SpatialToCamera(rotated);
606 if (camera.InSensor(camCoords)) {
607 Vec3 futureSpatial = futureAttitude.
Rotate(catalogWithFalse[i].spatial);
608 Vec2 delta = camera.SpatialToCamera(futureSpatial) - camCoords;
609 if (!motionBlurEnabled) {
625 generatedStars.push_back(
GeneratedStar(star, peakBrightnessPerTime, delta));
633 expectedStars.push_back(star);
636 expectedStarIds.push_back(
StarIdentifier(expectedStars.size()-1, i));
640 Star inputStar = star;
641 if (perturbationStddev >
DECIMAL(0.0)) {
642 std::normal_distribution<decimal> perturbation1DDistribution(
DECIMAL(0.0), perturbationStddev);
644 inputStar.
position.
x += std::max(std::min(perturbation1DDistribution(*rng), 2*perturbationStddev), -2*perturbationStddev);
645 inputStar.
position.
y += std::max(std::min(perturbation1DDistribution(*rng), 2*perturbationStddev), -2*perturbationStddev);
648 if (camera.InSensor(inputStar.
position)
652 || std::bernoulli_distribution((
double) CentroidImagingProbability(catalogStar.
magnitude, cutoffMag))(*rng))) {
653 inputStars.push_back(inputStar);
666 std::vector<decimal> photonsBuffer(image.width*image.height, 0);
670 Vec2 earliestPosition = star.position - star.delta*(exposureTime/
DECIMAL(2.0) + readoutTime/
DECIMAL(2.0));
671 Vec2 latestPosition = star.position + star.delta*(exposureTime/
DECIMAL(2.0) + readoutTime/
DECIMAL(2.0));
672 int xMin = std::max(0, (
int)std::min(earliestPosition.
x - star.radiusX, latestPosition.
x - star.radiusX));
673 int xMax = std::min(image.width-1, (
int)std::max(earliestPosition.
x + star.radiusX, latestPosition.
x + star.radiusX));
674 int yMin = std::max(0, (
int)std::min(earliestPosition.
y - star.radiusX, latestPosition.
y - star.radiusX));
675 int yMax = std::min(image.height-1, (
int)std::max(earliestPosition.
y + star.radiusX, latestPosition.
y + star.radiusX));
679 decimal oversamplingBrightnessFactor = oversamplingPerAxis*oversamplingPerAxis;
685 for (
int xPixel = xMin; xPixel <= xMax; xPixel++) {
686 for (
int yPixel = yMin; yPixel <= yMax; yPixel++) {
689 decimal readoutOffset = readoutTime * (yPixel - image.height/
DECIMAL(2.0)) / image.height;
694 for (
int xSample = 0; xSample < oversamplingPerAxis; xSample++) {
695 for (
int ySample = 0; ySample < oversamplingPerAxis; ySample++) {
700 if (motionBlurEnabled) {
702 (MotionBlurredPixelBrightness({x, y}, star, tEnd, starSpreadStdDev)
703 - MotionBlurredPixelBrightness({x, y}, star, tStart, starSpreadStdDev))
704 / oversamplingBrightnessFactor;
706 curPhotons = StaticPixelBrightness({x, y}, star, exposureTime, starSpreadStdDev)
707 / oversamplingBrightnessFactor;
710 assert(
DECIMAL(0.0) <= curPhotons);
712 photonsBuffer[xPixel + yPixel*image.width] += curPhotons;
719 std::normal_distribution<decimal> standardNormalDist(
DECIMAL(0.0),
DECIMAL(1.0));
722 imageData = std::vector<unsigned char>(image.width*image.height);
723 image.image = imageData.data();
724 for (
int i = 0; i < image.width * image.height; i++) {
728 curBrightness += darkCurrent;
731 curBrightness += readNoiseStdDev * standardNormalDist(*rng);
734 long quantizedPhotons;
740 decimal photons = photonsBuffer[i];
742 std::cout <<
"ERROR: One of the pixels had too many photons. Generated image would not be physically accurate, exiting." << std::endl;
747 std::poisson_distribution<long> shotNoiseDist((
double) photons);
748 quantizedPhotons = shotNoiseDist(*rng);
750 quantizedPhotons = 0;
753 quantizedPhotons = round(photonsBuffer[i]);
755 curBrightness += quantizedPhotons / saturationPhotons;
767static Attitude RandomAttitude(std::default_random_engine* pReng) {
768 std::uniform_real_distribution<decimal> randomAngleDistribution(0, 1);
798 std::default_random_engine attitudeRng(seed);
799 std::default_random_engine noiseRng(seed);
814 for (
int i = 0; i < values.
generate; i++) {
819 inputAttitude = RandomAttitude(&attitudeRng);
821 inputAttitude = attitude;
847 result.push_back(std::unique_ptr<PipelineInput>(curr));
860 if (!values.
png.empty()) {
863 return GetImageDirPipelineInput(values);
876 unsigned char *database)
878 if (centroidAlgorithm) {
879 this->centroidAlgorithm = std::unique_ptr<CentroidAlgorithm>(centroidAlgorithm);
881 if (starIdAlgorithm) {
882 this->starIdAlgorithm = std::unique_ptr<StarIdAlgorithm>(starIdAlgorithm);
884 if (attitudeEstimationAlgorithm) {
885 this->attitudeEstimationAlgorithm = std::unique_ptr<AttitudeEstimationAlgorithm>(attitudeEstimationAlgorithm);
888 this->database = std::unique_ptr<unsigned char[]>(database);
910 std::cout <<
"Illegal centroid algorithm." << std::endl;
921 fs.open(values.
databasePath, std::fstream::in | std::fstream::binary);
923 long length = fs.tellg();
926 std::cerr <<
"Error reading database! " << strerror(errno) << std::endl;
929 std::cerr <<
"Reading " << length <<
" bytes of database" << std::endl;
930 result.database = std::unique_ptr<unsigned char[]>(
new unsigned char[length]);
931 fs.read((
char *)result.database.get(), length);
932 std::cerr <<
"Done" << std::endl;
935 if (values.
idAlgo ==
"dummy") {
937 }
else if (values.
idAlgo ==
"gv") {
939 }
else if (values.
idAlgo ==
"py") {
943 }
else if (values.
idAlgo ==
"tetra") {
950 std::cerr <<
"Illegal tetra pairing mode: " << values.
tetraPairingMode << std::endl;
953 result.starIdAlgorithm = std::unique_ptr<StarIdAlgorithm>(
955 }
else if (values.
idAlgo !=
"") {
956 std::cout <<
"Illegal id algorithm." << std::endl;
961 result.attitudeEstimationAlgorithm = std::unique_ptr<AttitudeEstimationAlgorithm>(
new DavenportQAlgorithm());
963 result.attitudeEstimationAlgorithm = std::unique_ptr<AttitudeEstimationAlgorithm>(
new TriadAlgorithm());
965 result.attitudeEstimationAlgorithm = std::unique_ptr<AttitudeEstimationAlgorithm>(
new QuestAlgorithm());
967 std::cout <<
"Illegal attitude algorithm." << std::endl;
993 if (catalogBuffer != NULL) {
997 std::cerr <<
"WARNING: That database does not include a catalog. Proceeding with the full catalog." << std::endl;
1004 if (centroidAlgorithm && inputImage) {
1007 std::chrono::time_point<std::chrono::steady_clock> start = std::chrono::steady_clock::now();
1010 Stars unfilteredStars = centroidAlgorithm->Go(inputImage->
image, inputImage->
width, inputImage->
height);
1012 std::chrono::time_point<std::chrono::steady_clock> end = std::chrono::steady_clock::now();
1013 result.
centroidingTimeNs = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
1016 decimal minMagnitude = centroidMinMagnitude;
1017 if (centroidMinStars > 0
1019 && centroidMinStars < (
int)unfilteredStars.size()) {
1021 Stars magSortedStars = unfilteredStars;
1023 std::sort(magSortedStars.begin(), magSortedStars.end(), [](
const Star &a,
const Star &b) { return a.magnitude > b.magnitude; });
1024 minMagnitude = std::max(minMagnitude, magSortedStars[centroidMinStars - 1].magnitude);
1027 Stars *filteredStars =
new std::vector<Star>();
1028 for (
const Star &star : unfilteredStars) {
1029 assert(star.magnitude >= 0);
1031 if (star.magnitude >= minMagnitude) {
1032 filteredStars->push_back(star);
1035 result.
stars = std::unique_ptr<Stars>(filteredStars);
1036 inputStars = filteredStars;
1040 inputStarIds = NULL;
1042 }
else if (centroidAlgorithm) {
1043 std::cerr <<
"ERROR: Centroid algorithm specified, but no input image to run it on." << std::endl;
1047 if (starIdAlgorithm && database && inputStars && input.
InputCamera()) {
1049 std::chrono::time_point<std::chrono::steady_clock> start = std::chrono::steady_clock::now();
1051 result.
starIds = std::unique_ptr<StarIdentifiers>(
new std::vector<StarIdentifier>(
1052 starIdAlgorithm->Go(database.get(), *inputStars, result.
catalog, *input.
InputCamera())));
1054 std::chrono::time_point<std::chrono::steady_clock> end = std::chrono::steady_clock::now();
1055 result.
starIdTimeNs = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
1057 inputStarIds = result.
starIds.get();
1058 }
else if (starIdAlgorithm) {
1059 std::cerr <<
"ERROR: Star ID algorithm specified but cannot run because database, centroids, or camera are missing." << std::endl;
1063 if (attitudeEstimationAlgorithm && inputStarIds && input.
InputCamera()) {
1065 std::chrono::time_point<std::chrono::steady_clock> start = std::chrono::steady_clock::now();
1067 result.
attitude = std::unique_ptr<Attitude>(
1070 std::chrono::time_point<std::chrono::steady_clock> end = std::chrono::steady_clock::now();
1072 }
else if (attitudeEstimationAlgorithm) {
1073 std::cerr <<
"ERROR: Attitude estimation algorithm set, but either star IDs or camera are missing. One reason this can happen: Setting a centroid algorithm and attitude algorithm, but no star-id algorithm -- that can't work because the input star-ids won't properly correspond to the output centroids!" << std::endl;
1082 std::vector<PipelineOutput> result;
1085 for (
const std::unique_ptr<PipelineInput> &input : inputs) {
1086 result.push_back(
Go(*input));
1127static std::multimap<int, int> FindClosestCentroids(
decimal threshold,
1130 std::multimap<int, int> result;
1132 for (
int i = 0; i < (int)one.size(); i++) {
1133 std::vector<std::pair<decimal, int>> closest;
1134 for (
int k = 0; k < (int)two.size(); k++) {
1135 decimal currDistance = (one[i].position - two[k].position).Magnitude();
1136 if (currDistance <= threshold) {
1137 closest.emplace_back(currDistance, k);
1140 std::sort(closest.begin(), closest.end());
1141 for (
const std::pair<decimal, int> &pair : closest) {
1142 result.emplace(i, pair.second);
1155 const Stars &expected,
1156 const Stars &actual) {
1164 std::multimap<int, int> actualToExpected = FindClosestCentroids(threshold, actual, expected);
1166 for (
int i = 0; i < (int)actualToExpected.size(); i++) {
1167 auto closest = actualToExpected.find(i);
1168 if (closest == actualToExpected.end()) {
1171 result.
meanError += (actual[i].position - expected[closest->second].position).Magnitude();
1181 assert(comparisons.size() > 0);
1186 result.
meanError += comparison.meanError;
1203 const Stars &expectedStars,
const Stars &inputStars) {
1214 std::vector<int> expectedCatalogIndices(expectedStars.size(), -1);
1216 assert(0 <= starId.starIndex && starId.starIndex <= (
int)expectedStars.size());
1217 assert(0 <= starId.catalogIndex && starId.catalogIndex <= (
int)expectedCatalog.size());
1218 expectedCatalogIndices[starId.starIndex] = starId.catalogIndex;
1223 std::multimap<int, int> inputToExpectedCentroids = FindClosestCentroids(centroidThreshold, inputStars, expectedStars);
1228 for (
int i = 0; i < (int)inputStars.size(); i++) {
1230 auto closestRange = inputToExpectedCentroids.equal_range(i);
1232 for (
auto it = closestRange.first; it != closestRange.second; it++) {
1233 if (expectedCatalogIndices[it->second] != -1) {
1245 std::vector<bool> identifiedInputCentroids(inputStars.size(),
false);
1248 assert(!identifiedInputCentroids[starId.starIndex]);
1249 identifiedInputCentroids[starId.starIndex] =
true;
1250 assert(0 <= starId.starIndex && starId.starIndex <= (
int)inputStars.size());
1251 assert(0 <= starId.catalogIndex && starId.catalogIndex <= (
int)actualCatalog.size());
1254 auto expectedCentroidsInRange = inputToExpectedCentroids.equal_range(starId.starIndex);
1256 for (
auto it = expectedCentroidsInRange.first; it != expectedCentroidsInRange.second; it++) {
1257 int expectedCatalogIndex = expectedCatalogIndices[it->second];
1258 if (expectedCatalogIndex != -1
1259 && expectedCatalog[expectedCatalogIndex].name == actualCatalog[starId.catalogIndex].name) {
1282 const std::vector<PipelineOutput> &,
1286static cairo_status_t OstreamPlotter(
void *closure,
const unsigned char *data,
unsigned int length) {
1287 std::ostream *os = (std::ostream *)closure;
1288 os->write((
const char *)data, length);
1289 return CAIRO_STATUS_SUCCESS;
1293static void PipelineComparatorPlotRawInput(std::ostream &os,
1295 const std::vector<PipelineOutput> &,
1296 const PipelineOptions &) {
1298 cairo_surface_t *cairoSurface = expected[0]->InputImageSurface();
1299 cairo_surface_write_to_png_stream(cairoSurface, OstreamPlotter, &os);
1300 cairo_surface_destroy(cairoSurface);
1305static void PipelineComparatorPlotInput(std::ostream &os,
1307 const std::vector<PipelineOutput> &,
1309 cairo_surface_t *cairoSurface = expected[0]->InputImageSurface();
1310 assert(expected[0]->InputStars() != NULL);
1313 *expected[0]->InputStars(),
1314 expected[0]->InputStarIds(),
1315 &expected[0]->GetCatalog(),
1316 expected[0]->InputAttitude(),
1318 0.0, 1.0, 0.0, 0.6);
1319 cairo_surface_write_to_png_stream(cairoSurface, OstreamPlotter, &os);
1320 cairo_surface_destroy(cairoSurface);
1323static void PipelineComparatorPlotExpected(std::ostream &os,
1325 const std::vector<PipelineOutput> &,
1327 cairo_surface_t *cairoSurface = expected[0]->InputImageSurface();
1328 assert(expected[0]->ExpectedStars() != NULL);
1331 *expected[0]->ExpectedStars(),
1332 expected[0]->ExpectedStarIds(),
1333 &expected[0]->GetCatalog(),
1334 expected[0]->ExpectedAttitude(),
1336 0.2, 0.5, 1.0, 0.7);
1337 cairo_surface_write_to_png_stream(cairoSurface, OstreamPlotter, &os);
1338 cairo_surface_destroy(cairoSurface);
1342static void PipelineComparatorCentroids(std::ostream &os,
1344 const std::vector<PipelineOutput> &actual,
1346 int size = (int)expected.size();
1348 decimal threshold = values.centroidCompareThreshold;
1350 std::vector<CentroidComparison> comparisons;
1351 for (
int i = 0; i < size; i++) {
1353 *(expected[i]->ExpectedStars()),
1354 *(actual[i].stars)));
1358 os <<
"centroids_num_correct " << result.numCorrectCentroids << std::endl
1359 <<
"centroids_num_extra " << result.numExtraCentroids << std::endl
1360 <<
"centroids_mean_error " << result.meanError << std::endl;
1363static void PrintCentroids(
const std::string &prefix,
1366 const std::vector<Stars> &starses,
1369 assert(starses.size() > 0);
1371 for (
const Stars &stars : starses) {
1372 avgNumStars += stars.size();
1374 avgNumStars /= starses.size();
1376 os <<
"num_" << prefix <<
"_centroids " << avgNumStars << std::endl;
1377 if (starses.size() == 1) {
1378 const Stars &stars = starses[0];
1379 for (
int i = 0; i < (int)stars.size(); i++) {
1380 os << prefix <<
"_centroid_" << i <<
"_x " << stars[i].position.x << std::endl;
1381 os << prefix <<
"_centroid_" << i <<
"_y " << stars[i].position.y << std::endl;
1384 if (starId.starIndex == i) {
1385 os << prefix <<
"_centroid_" << i <<
"_id " << catalog[starId.catalogIndex].name << std::endl;
1394static void PipelineComparatorPrintExpectedCentroids(std::ostream &os,
1396 const std::vector<PipelineOutput> &,
1398 assert(expected.size() > 0);
1399 assert(expected[0]->ExpectedStars());
1401 std::vector<Stars> expectedStarses;
1402 for (
const auto &input : expected) {
1403 expectedStarses.push_back(*input->ExpectedStars());
1405 PrintCentroids(
"expected",
1407 expected[0]->GetCatalog(),
1409 expected[0]->ExpectedStarIds());
1412static void PipelineComparatorPrintInputCentroids(std::ostream &os,
1414 const std::vector<PipelineOutput> &,
1416 assert(expected.size() > 0);
1417 assert(expected[0]->InputStars());
1419 std::vector<Stars> inputStarses;
1420 for (
const auto &input : expected) {
1421 inputStarses.push_back(*input->InputStars());
1423 PrintCentroids(
"input",
1425 expected[0]->GetCatalog(),
1427 expected[0]->InputStarIds());
1430static void PipelineComparatorPrintActualCentroids(std::ostream &os,
1432 const std::vector<PipelineOutput> &actual,
1434 assert(actual.size() > 0);
1435 assert(actual[0].stars);
1437 std::vector<Stars> actualStarses;
1438 for (
const auto &output : actual) {
1439 actualStarses.push_back(*output.stars);
1441 PrintCentroids(
"actual",
1445 actual[0].starIds.get());
1447 if (expected.size() == 1 && expected[0]->ExpectedStars() && expected[0]->ExpectedStarIds()) {
1449 const Stars &actualStars = *actual[0].stars;
1450 const Stars &expectedStars = *expected[0]->ExpectedStars();
1451 std::multimap<int, int> actualToExpectedCentroids = FindClosestCentroids(values.centroidCompareThreshold, actualStars, expectedStars);
1452 for (
int i = 0; i < (int)actualStars.size(); i++) {
1453 auto range = actualToExpectedCentroids.equal_range(i);
1454 auto it = range.first;
1455 auto end = range.second;
1460 int expectedCentroidIndex = it->second;
1461 bool foundIt =
false;
1462 for (
const StarIdentifier &starId : *expected[0]->ExpectedStarIds()) {
1463 if (starId.starIndex == expectedCentroidIndex) {
1465 int expectedName = expected[0]->GetCatalog()[starId.catalogIndex].name;
1466 std::cout <<
"actual_centroid_" << i <<
"_expected_id_" << j <<
" " << expectedName << std::endl;
1479 const std::vector<PipelineOutput> &actual,
1481 const Stars &stars = actual[0].stars ? *actual[0].stars : *expected[0]->InputStars();
1483 for (
int i = 0; i < (int)stars.size(); i++) {
1486 cairo_surface_t *cairoSurface = expected[0]->InputImageSurface();
1497 cairo_surface_write_to_png_stream(cairoSurface, OstreamPlotter, &os);
1498 cairo_surface_destroy(cairoSurface);
1502static void PipelineComparatorPlotOutput(std::ostream &os,
1504 const std::vector<PipelineOutput> &actual,
1505 const PipelineOptions &) {
1507 cairo_surface_t *cairoSurface = expected[0]->InputImageSurface();
1510 actual[0].stars ? *actual[0].stars : *expected[0]->InputStars(),
1511 actual[0].starIds.get(),
1513 actual[0].attitude.get(),
1515 1.0, 0.0, 0.0, 0.5);
1516 cairo_surface_write_to_png_stream(cairoSurface, OstreamPlotter, &os);
1517 cairo_surface_destroy(cairoSurface);
1521static void PipelineComparatorStarIds(std::ostream &os,
1523 const std::vector<PipelineOutput> &actual,
1525 int numImagesCorrect = 0;
1526 int numImagesIncorrect = 0;
1527 int numImagesTotal = expected.size();
1528 for (
int i = 0; i < numImagesTotal; i++) {
1532 assert(actual[i].stars.get() || expected[i]->InputStars());
1534 const Stars &inputStars = actual[i].stars.get()
1535 ? *actual[i].stars.get()
1536 : *expected[i]->InputStars();
1538 StarIdsCompare(*expected[i]->ExpectedStarIds(), *actual[i].starIds,
1539 expected[i]->GetCatalog(), actual[i].catalog,
1540 values.centroidCompareThreshold, *expected[i]->ExpectedStars(), inputStars);
1542 if (numImagesTotal == 1) {
1543 os <<
"starid_num_correct " << comparison.numCorrect << std::endl;
1544 os <<
"starid_num_incorrect " << comparison.numIncorrect << std::endl;
1545 os <<
"starid_num_total " << comparison.numTotal << std::endl;
1548 if (comparison.numCorrect > 0 && comparison.numIncorrect == 0) {
1551 if (comparison.numIncorrect > 0) {
1552 numImagesIncorrect++;
1557 os <<
"starid_num_images_correct " << numImagesCorrect << std::endl;
1558 os <<
"starid_num_images_incorrect " << numImagesIncorrect << std::endl;
1561static void PrintAttitude(std::ostream &os,
const std::string &prefix,
const Attitude &attitude) {
1562 if (attitude.IsKnown()) {
1563 os << prefix <<
"attitude_known 1" << std::endl;
1566 os << prefix <<
"attitude_ra " <<
RadToDeg(spherical.ra) << std::endl;
1567 os << prefix <<
"attitude_de " <<
RadToDeg(spherical.de) << std::endl;
1568 os << prefix <<
"attitude_roll " <<
RadToDeg(spherical.roll) << std::endl;
1571 os << prefix <<
"attitude_i " << q.
i << std::endl;
1572 os << prefix <<
"attitude_j " << q.j << std::endl;
1573 os << prefix <<
"attitude_k " << q.k << std::endl;
1574 os << prefix <<
"attitude_real " << q.real << std::endl;
1577 os << prefix <<
"attitude_known 0" << std::endl;
1582static void PipelineComparatorPrintAttitude(std::ostream &os,
1584 const std::vector<PipelineOutput> &actual,
1587 assert(output.attitude);
1588 PrintAttitude(os,
"", *output.attitude);
1592static void PipelineComparatorPrintExpectedAttitude(std::ostream &os,
1594 const std::vector<PipelineOutput> &,
1596 assert(expected.size() == 1);
1597 assert(expected[0]->ExpectedAttitude());
1598 PrintAttitude(os,
"expected_", *expected[0]->ExpectedAttitude());
1602static void PipelineComparatorAttitude(std::ostream &os,
1604 const std::vector<PipelineOutput> &actual,
1612 decimal attitudeErrorSum = 0.0f;
1614 int numIncorrect = 0;
1616 for (
int i = 0; i < (int)expected.size(); i++) {
1617 if (actual[i].attitude->IsKnown()) {
1618 Quaternion expectedQuaternion = expected[i]->ExpectedAttitude()->GetQuaternion();
1619 Quaternion actualQuaternion = actual[i].attitude->GetQuaternion();
1621 assert(attitudeError >= 0);
1623 if (attitudeError <= angleThreshold) {
1624 attitudeErrorSum += attitudeError;
1632 decimal attitudeErrorMean =
DECIMAL(attitudeErrorSum) / numCorrect;
1634 decimal fractionIncorrect =
DECIMAL(numIncorrect) / expected.size();
1636 os <<
"attitude_error_mean " << attitudeErrorMean << std::endl;
1637 os <<
"attitude_availability " << fractionCorrect << std::endl;
1638 os <<
"attitude_error_rate " << fractionIncorrect << std::endl;
1641static void PrintTimeStats(std::ostream &os,
const std::string &prefix,
const std::vector<long long> ×) {
1642 assert(times.size() > 0);
1646 long long min = LONG_MAX;
1648 for (
int i = 0; i < (int)times.size(); i++) {
1649 assert(times[i] > 0);
1651 min = std::min(min, times[i]);
1652 max = std::max(max, times[i]);
1654 long average = sum / times.size();
1655 std::vector<long long> sortedTimes = times;
1656 std::sort(sortedTimes.begin(), sortedTimes.end());
1660 int ninetyFiveIndex = (int)std::ceil(0.95 * times.size()) - 1;
1661 assert(ninetyFiveIndex >= 0);
1662 long long ninetyFifthPercentile = sortedTimes[ninetyFiveIndex];
1664 os << prefix <<
"_average_ns " << average << std::endl;
1665 os << prefix <<
"_min_ns " << min << std::endl;
1666 os << prefix <<
"_max_ns " << max << std::endl;
1667 os << prefix <<
"_95%_ns " << ninetyFifthPercentile << std::endl;
1671static void PipelineComparatorPrintSpeed(std::ostream &os,
1673 const std::vector<PipelineOutput> &actual,
1675 std::vector<long long> centroidingTimes;
1676 std::vector<long long> starIdTimes;
1677 std::vector<long long> attitudeTimes;
1678 std::vector<long long> totalTimes;
1679 for (
int i = 0; i < (int)actual.size(); i++) {
1680 long long totalTime = 0;
1681 if (actual[i].centroidingTimeNs > 0) {
1682 centroidingTimes.push_back(actual[i].centroidingTimeNs);
1683 totalTime += actual[i].centroidingTimeNs;
1685 if (actual[i].starIdTimeNs > 0) {
1686 starIdTimes.push_back(actual[i].starIdTimeNs);
1687 totalTime += actual[i].starIdTimeNs;
1689 if (actual[i].attitudeEstimationTimeNs > 0) {
1690 attitudeTimes.push_back(actual[i].attitudeEstimationTimeNs);
1691 totalTime += actual[i].attitudeEstimationTimeNs;
1693 totalTimes.push_back(totalTime);
1695 if (centroidingTimes.size() > 0) {
1696 PrintTimeStats(os,
"centroiding", centroidingTimes);
1698 if (starIdTimes.size() > 0) {
1699 PrintTimeStats(os,
"starid", starIdTimes);
1701 if (attitudeTimes.size() > 0) {
1702 PrintTimeStats(os,
"attitude", attitudeTimes);
1704 if (centroidingTimes.size() > 0 || starIdTimes.size() > 0 || attitudeTimes.size() > 0) {
1705 PrintTimeStats(os,
"total", totalTimes);
1771 const std::vector<PipelineOutput> &actual,
1773 if (actual.size() == 0) {
1774 std::cerr <<
"ERROR: No output! Did you specify any input images? Try --png or --generate." << std::endl;
1778 assert(expected.size() == actual.size() && expected.size() > 0);
1782#define LOST_PIPELINE_COMPARE(precondition, errmsg, comparator, path, isBinary) do { \
1783 if (precondition) { \
1784 UserSpecifiedOutputStream pos(path, isBinary); \
1785 comparator(pos.Stream(), expected, actual, values); \
1787 std::cerr << "ERROR: Comparator not applicable: " << errmsg << std::endl; \
1794 "--plot-raw-input requires exactly 1 input image, but " + std::to_string(expected.size()) +
" many were provided.",
1795 PipelineComparatorPlotRawInput, values.
plotRawInput,
true);
1799 LOST_PIPELINE_COMPARE(expected[0]->InputImage() && expected.size() == 1 && expected[0]->InputStars(),
1800 "--plot-input requires exactly 1 input image, and for centroids to be available on that input image. " + std::to_string(expected.size()) +
" many input images were provided.",
1801 PipelineComparatorPlotInput, values.
plotInput,
true);
1804 LOST_PIPELINE_COMPARE(expected[0]->InputImage() && expected.size() == 1 && expected[0]->ExpectedStars(),
1805 "--plot-expected-input requires exactly 1 input image, and for expected centroids to be available on that input image. " + std::to_string(expected.size()) +
" many input images were provided.",
1806 PipelineComparatorPlotExpected, values.
plotExpected,
true);
1810 "--plot-output requires exactly 1 output image, and for either centroids or star IDs to be available on that output image. " + std::to_string(actual.size()) +
" many output images were provided.",
1811 PipelineComparatorPlotOutput, values.
plotOutput,
true);
1815 "--print-expected-centroids requires at least 1 input with expected centroids. " + std::to_string(expected.size()) +
" many input images were provided.",
1820 "--print-input-centroids requires at least 1 input with centroids. " + std::to_string(expected.size()) +
" many input images were provided.",
1825 "--print-actual-centroids requires at least 1 output image, and for centroids to be available on the output images. " + std::to_string(actual.size()) +
" many output images were provided.",
1830 "--plot-centroid-indices requires exactly 1 input with image. " + std::to_string(expected.size()) +
" many inputs were provided.",
1835 "--compare-centroids requires at least 1 output image, and for expected centroids to be available on the input image. " + std::to_string(actual.size()) +
" many output images were provided.",
1839 LOST_PIPELINE_COMPARE(expected[0]->ExpectedStarIds() && actual[0].starIds && expected[0]->ExpectedStars(),
1840 "--compare-star-ids requires at least 1 output image, and for expected star IDs and centroids to be available on the input image. " + std::to_string(actual.size()) +
" many output images were provided.",
1845 "--print-attitude requires attitude to be available on every output image. " + std::to_string(actual.size()) +
" many output images were provided.",
1846 PipelineComparatorPrintAttitude, values.
printAttitude,
false);
1850 "--print-expected-attitude requires exactly 1 input image, and for expected attitude to be available on that input image. " + std::to_string(expected.size()) +
" many input images were provided.",
1855 "--compare-attitudes requires at least 1 output image, and for expected attitude to be available on the input image. " + std::to_string(actual.size()) +
" many output images were provided.",
1861 "--print-speed requires at least 1 output image. " + std::to_string(actual.size()) +
" many output images were provided.",
1862 PipelineComparatorPrintSpeed, values.
printSpeed,
false);
1865#undef LOST_PIPELINE_COMPARE
An attitude estimation algorithm estimates the orientation of the camera based on identified stars.
The attitude (orientation) of a spacecraft.
EulerAngles ToSpherical() const
Get the euler angles from the attitude, converting from whatever format is stored.
Quaternion GetQuaternion() const
Get the quaternion representing the attitude, converting from whatever format is stored.
A full description of a camera. Enough information to reconstruct the camera matrix and then some.
int XResolution() const
Width of the sensor in pixels.
int YResolution() const
Height of the sensor in pixels.
decimal Fov() const
Horizontal field of view in radians.
decimal FocalLength() const
Focal length in pixels.
A star from the Bright Star Catalog.
decimal magnitude
The apparent magnitude of the star (e.g., Sirius = -1.46, Polaris = 1.98).
A simple, fast, and pretty decent centroid algorithm.
An algorithm that detects the (x,y) coordinates of bright points in an image, called "centroids".
The result of comparing actual and expected centroids Used for debugging and benchmarking.
decimal numExtraCentroids
Stars in actual but not expected.
decimal numCorrectCentroids
Number of actual stars within the centroiding threshold of an expected star.
decimal meanError
Average distance from actual to expected centroids (in pixels) Only correct centroids are considered ...
Command line options when using the database command.
int tetraPatternStarsPerFov
long kvectorNumDistanceBins
bool swapDecimalEndianness
decimal kvectorMaxDistance
decimal kvectorMinDistance
bool swapIntegerEndianness
A slow but reliable attitude estimation algorithm.
A centroid algorithm for debugging that returns random centroids.
A star-id algorithm that returns random results. For debugging.
A "human-readable" way to represent a 3d rotation or orientation.
decimal roll
How far we roll counterclockwise. Roll is performed last (after yaw and pitch).
decimal de
Declination. How far we pitch up (or down if negative). Pitch is performed second,...
decimal ra
Right ascension. How far we yaw left. Yaw is performed first.
A star used in simulated image generation. Contains extra data about how to simulate the star.
decimal peakBrightness
the brightness density per time unit at the center of the star. 0.0 is black, 1.0 is white.
GeneratedStar(Star star, decimal peakBrightness, Vec2 motionBlurDelta)
Vec2 delta
(only meaningful with motion blur) Where the star will appear one time unit in the future.
A star-id algorithm based on assigning votes for each centroid-catalog pair then choosing the highest...
An 8-bit grayscale 2d image.
unsigned char * image
The raw pixel data in the image.
A more complicated centroid algorithm which doesn't perform much better than CenterOfGravityAlgorithm...
const unsigned char * SubDatabasePointer(int32_t magicValue) const
MultiDatabase memory layout:
static const int32_t kMagicValue
Magic value to use when storing inside a MultiDatabase.
The command line options passed when running a pipeline.
std::string compareStarIds
std::string compareCentroids
bool generateCentroidsOnly
std::string compareAttitudes
int generateNumFalseStars
bool generateRandomAttitudes
decimal attitudeCompareThreshold
decimal generateFalseMaxMag
decimal generateSpreadStdDev
int centroidDummyNumStars
decimal generatePerturbationStddev
decimal generateSaturationPhotons
std::string printActualCentroids
decimal centroidMagFilter
decimal generateCutoffMag
int centroidFilterBrightest
std::string printExpectedAttitude
decimal centroidCompareThreshold
std::string printAttitude
decimal tetraPatternSearchRange
std::string plotCentroidIndices
std::vector< std::string > png
std::string printExpectedCentroids
decimal generateFalseMinMag
std::string tetraPairingMode
std::string printInputCentroids
int estimatedNumFalseStars
decimal generateReadoutTime
decimal tetraPatternMatchTolerance
decimal generateDarkCurrent
decimal generateZeroMagPhotons
decimal generateReadNoiseStdDev
PipelineOutput Go(const PipelineInput &)
Run all stages of a pipeline.
The "de facto" star-id algorithm used in many real-world missions.
A quaternion is a common way to represent a 3d rotation.
decimal Angle() const
How many radians the rotation represented by this quaternion has.
Vec3 Rotate(const Vec3 &) const
Rotate a 3d vector according to the rotation represented by the quaternion.
decimal SmallestAngle() const
Returns the smallest angle that can be used to represent the rotation represented by the quaternion.
A faster and just as accurate attitude estimator as the Davenport Q algorithm.
std::vector< unsigned char > buffer
A star idenification algorithm.
Records that a certain Star (detected in the image) corresponds to a certain CatalogStar.
A "centroid" detected in an image.
Star(decimal x, decimal y, decimal radiusX, decimal radiusY, decimal magnitude)
decimal radiusY
Approximate vertical radius of the bright area in pixels.
Vec2 position
The (x,y) pixel coordinates in the image (top left is 0,0).
decimal radiusX
Approximate horizontal radius of the bright area in pixels.
static const int32_t kMagicValue
Magic value to use when storing inside a MultiDatabase.
Tetra star identification algorithm based on the one originally proposed by Brown & Stubis Creates pa...
A fast attitude estimator which only takes into account information from two stars.
~UserSpecifiedOutputStream()
UserSpecifiedOutputStream(std::string filePath, bool isBinary)
Create a PromptedOutputStream which will output to the given file.
Three dimensional vector with decimaling point components.
#define DECIMAL_POW(base, power)
#define LOST_PIPELINE_COMPARE(precondition, errmsg, comparator, path, isBinary)
decimal FovToFocalLength(decimal xFov, decimal xResolution)
CentroidComparison CentroidComparisonsCombine(std::vector< CentroidComparison > comparisons)
unsigned char * SurfaceToGrayscaleImage(cairo_surface_t *cairoSurface)
Convert a colored Cairo image surface into a row-major array of grayscale pixels.
decimal FocalLengthFromOptions(const PipelineOptions &values, int xResolution)
Calculate the focal length, in pixels, based on the given command line options.
const int32_t kCatalogMagicValue
std::vector< StarIdentifier > StarIdentifiers
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.
const Catalog & CatalogRead()
Read and parse the full catalog from disk. If called multiple times, will re-use the first result.
std::vector< Star > Stars
decimal DegToRad(decimal deg)
Quaternion SphericalToQuaternion(decimal ra, decimal dec, decimal roll)
Return a quaternion that will reorient the coordinate axes so that the x-axis points at the given rig...
std::vector< MultiDatabaseEntry > MultiDatabaseDescriptor
decimal RadToDeg(decimal rad)
void PipelineComparatorPlotCentroidIndices(std::ostream &os, const PipelineInputList &expected, const std::vector< PipelineOutput > &actual, const PipelineOptions &)
Plot an annotated image where centroids are annotated with their centroid index.
void SerializeTetraDatabase(SerializeContext *ser, const Catalog &catalog, decimal maxFovDeg, const std::vector< uint16_t > &catalogPatternStarInds, int numEdgeRatioBins)
PipelineInputList GetPngPipelineInput(const PipelineOptions &values)
std::vector< CatalogStar > BscParse(std::string tsvPath)
Parse the bright star catalog from the TSV file on disk.
void SurfacePlot(std::string description, cairo_surface_t *cairoSurface, const Stars &stars, const StarIdentifiers *starIds, const Catalog *catalog, const Attitude *attitude, double red, double green, double blue, double alpha, bool rawStarIndexes=false)
Plot information about an image onto the image using Cairo.
StarIdComparison StarIdsCompare(const StarIdentifiers &expected, const StarIdentifiers &actual, const Catalog &expectedCatalog, const Catalog &actualCatalog, decimal centroidThreshold, const Stars &expectedStars, const Stars &inputStars)
Compare expected and actual star identifications.
void SerializePairDistanceKVector(SerializeContext *ser, const Catalog &catalog, decimal minDistance, decimal maxDistance, long numBins)
Serialize a pair-distance KVector into buffer.
std::vector< uint16_t > TetraPreprocessCatalog(const Catalog &catalog, const decimal maxFovDeg, int numPatternStarsPerFov)
void(* PipelineComparator)(std::ostream &os, const PipelineInputList &, const std::vector< PipelineOutput > &, const PipelineOptions &)
MultiDatabaseDescriptor GenerateDatabases(const Catalog &catalog, const DatabaseOptions &values)
Appropriately create descriptors for all requested databases according to command-line options.
SerializeContext serFromDbValues(const DatabaseOptions &values)
std::vector< std::unique_ptr< PipelineInput > > PipelineInputList
PipelineInputList GetPipelineInput(const PipelineOptions &values)
Come up with a list of pipeline inputs based on command line options.
void PipelineComparison(const PipelineInputList &expected, const std::vector< PipelineOutput > &actual, const PipelineOptions &values)
Print or otherwise analyze the results of (perhaps multiple) runs of a star tracking pipeline.
Pipeline SetPipeline(const PipelineOptions &values)
Create a pipeline from command line options.
CentroidComparison CentroidsCompare(decimal threshold, const Stars &expected, const Stars &actual)
Compare expected and actual centroids.
std::ostream & operator<<(std::ostream &output, const Vec2 &vec)
PipelineInputList GetGeneratedPipelineInput(const PipelineOptions &values)
Create a GeneratedPipelineInput based on the command line options in values.
std::vector< CatalogStar > Catalog
cairo_surface_t * GrayscaleImageToSurface(const unsigned char *image, const int width, const int height)
decimal MagToBrightness(decimal mag)
returns some relative brightness measure, which is proportional to the total number of photons receiv...
The result of running a pipeline.
Catalog catalog
The catalog that the indices in starIds refer to.
long long centroidingTimeNs
How many nanoseconds the centroiding stage of the pipeline took.
std::unique_ptr< Stars > stars
long long attitudeEstimationTimeNs
std::unique_ptr< Attitude > attitude
std::unique_ptr< StarIdentifiers > starIds
The result of comparing an actual star identification with the true star idenification,...
int numCorrect
The number of centroids in the image which are close to an expected centroid that had an expected ide...
int numTotal
The number of centroids sufficiently close to a true expected star.
int numIncorrect
The number of centroids which were either:
A two dimensional vector with decimaling point components.
decimal MagnitudeSq() const
The square of the magnitude.
decimal Magnitude() const