LOST 0.0.1
LOST: Open-source Star Tracker
Loading...
Searching...
No Matches
io.hpp
Go to the documentation of this file.
1// I/O stuff, such as Cairo and star catalog interactions.
2
3#ifndef IO_H
4#define IO_H
5
6#include <cairo/cairo.h>
7
8#include <iostream>
9#include <memory>
10#include <random>
11#include <string>
12#include <vector>
13
14#ifndef CAIRO_HAS_PNG_FUNCTIONS
15#error LOST requires Cairo to be compiled with PNG support
16#endif
17
19#include "attitude-utils.hpp"
20#include "camera.hpp"
21#include "centroiders.hpp"
22#include "databases.hpp"
23#include "star-id.hpp"
24#include "star-utils.hpp"
25
26namespace lost {
27
28const char kNoDefaultArgument = 0;
29
32public:
33 explicit UserSpecifiedOutputStream(std::string filePath, bool isBinary);
35
37 std::ostream &Stream() { return *stream; };
38
39private:
40 bool isFstream;
41 std::ostream *stream;
42};
43
44// use the environment variable LOST_BSC_PATH, or read from ./bright-star-catalog.tsv
45const Catalog &CatalogRead();
46// Convert a cairo surface to array of grayscale bytes
47unsigned char *SurfaceToGrayscaleImage(cairo_surface_t *cairoSurface);
48cairo_surface_t *GrayscaleImageToSurface(const unsigned char *, const int width, const int height);
49
50// take an astrometry download from the bash script, and parse it into stuff.
51// void v_astrometry_parse(std::string
52// cairo_surface_t **pcairoSurface, // image data
53// Star **ppx_centroids, // centroids according to astrometry
54// int *pi_centroids_length); // TODO: fov, actual angle, etc
55
56// type for functions that create a centroid algorithm (by prompting the user usually)
57
59class Image {
60public:
65 unsigned char *image;
66
67 int width;
68 int height;
69};
70
72// PIPELINE INPUT //
74
75
78public:
79#define LOST_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg) \
80 type prop = defaultVal;
82#undef LOST_CLI_OPTION
83};
84
91public:
92 virtual ~PipelineInput(){};
93
94 virtual const Image *InputImage() const { return NULL; };
96 virtual const Catalog &GetCatalog() const = 0;
97 virtual const Stars *InputStars() const { return NULL; };
100 virtual const StarIdentifiers *InputStarIds() const { return NULL; };
102 virtual const Attitude *InputAttitude() const { return NULL; };
103 virtual const Camera *InputCamera() const { return NULL; };
105 cairo_surface_t *InputImageSurface() const;
106
107 virtual const Stars *ExpectedStars() const { return InputStars(); };
113 virtual const StarIdentifiers *ExpectedStarIds() const { return InputStarIds(); };
114 virtual const Attitude *ExpectedAttitude() const { return InputAttitude(); };
115};
116
122public:
123 GeneratedPipelineInput(const Catalog &, Attitude, Camera, std::default_random_engine *,
124
125 bool centroidsOnly,
126 decimal observedReferenceBrightness, decimal starSpreadStdDev,
127 decimal sensitivity, decimal darkCurrent, decimal readNoiseStdDev,
128 Attitude motionBlurDirection, decimal exposureTime, decimal readoutTime,
129 bool shotNoise, int oversampling,
130 int numFalseStars, int falseMinMagnitude, int falseMaxMagnitude,
131 int cutoffMag,
132 decimal perturbationStddev);
133
134
135 const Image *InputImage() const override { return &image; };
136 const Stars *InputStars() const override { return &inputStars; };
137 const Stars *ExpectedStars() const override { return &expectedStars; };
138 const Camera *InputCamera() const override { return &camera; };
139 const StarIdentifiers *InputStarIds() const override { return &inputStarIds; };
140 const StarIdentifiers *ExpectedStarIds() const override { return &expectedStarIds; };
141 const Attitude *InputAttitude() const override { return &attitude; };
142 const Catalog &GetCatalog() const override { return catalog; };
143
144private:
145 std::vector<unsigned char> imageData;
146 Image image;
148 Stars expectedStars;
150 Stars inputStars;
151 Camera camera;
152 Attitude attitude;
153 const Catalog &catalog;
154 StarIdentifiers inputStarIds;
155 StarIdentifiers expectedStarIds;
156};
157
158typedef std::vector<std::unique_ptr<PipelineInput>> PipelineInputList;
159
161
164public:
165 PngPipelineInput(cairo_surface_t *, Camera, const Catalog &);
167
168 const Image *InputImage() const override { return &image; };
169 const Camera *InputCamera() const override { return &camera; };
170 const Catalog &GetCatalog() const override { return catalog; };
171
172private:
173 Image image;
174 Camera camera;
175 const Catalog &catalog;
176};
177
179// PIPELINE OUTPUT //
181
187 std::unique_ptr<Stars> stars = nullptr;
188 std::unique_ptr<StarIdentifiers> starIds = nullptr;
189 std::unique_ptr<Attitude> attitude = nullptr;
190
193 long long centroidingTimeNs = -1;
194 long long starIdTimeNs = -1;
196
202};
203
209
214
217};
218
219std::ostream &operator<<(std::ostream &, const Camera &);
220
222// PIPELINE //
224
229class Pipeline {
230 friend Pipeline SetPipeline(const PipelineOptions &values);
231
232public:
233 Pipeline() = default;
236 std::vector<PipelineOutput> Go(const PipelineInputList &);
237
238private:
239 std::unique_ptr<CentroidAlgorithm> centroidAlgorithm;
240
241 // next two options are for magnitude filter:
242 int centroidMinMagnitude = 0;
243 int centroidMinStars = 0;
244
245 std::unique_ptr<StarIdAlgorithm> starIdAlgorithm;
246 std::unique_ptr<AttitudeEstimationAlgorithm> attitudeEstimationAlgorithm;
247 std::unique_ptr<unsigned char[]> database;
248};
249
251
252// TODO: rename. Do something with the output
253void PipelineComparison(const PipelineInputList &expected,
254 const std::vector<PipelineOutput> &actual,
255 const PipelineOptions &values);
256
272 // use these to map indices to names for the respective lists of StarIdentifiers
273 const Catalog &expectedCatalog, const Catalog &actualCatalog,
274 decimal centroidThreshold,
275 const Stars &expectedStars, const Stars &inputStars);
276
278// DB BUILDER //
280
283public:
284#define LOST_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg) \
285 type prop = defaultVal;
286#include "database-options.hpp"
287#undef LOST_CLI_OPTION
288};
289
291
295
297// INSPECT CATALOG //
299
301
302}
303
304#endif
An attitude estimation algorithm estimates the orientation of the camera based on identified stars.
The attitude (orientation) of a spacecraft.
A full description of a camera. Enough information to reconstruct the camera matrix and then some.
Definition camera.hpp:9
An algorithm that detects the (x,y) coordinates of bright points in an image, called "centroids".
Commannd line options when using the database command.
Definition io.hpp:282
const Stars * ExpectedStars() const override
Definition io.hpp:137
const Attitude * InputAttitude() const override
Only used in tracking mode, in which case it is an estimate of the current attitude based on the last...
Definition io.hpp:141
const StarIdentifiers * ExpectedStarIds() const override
Centroid indices in the StarIdentifiers returned from ExpectedStarIds should be indices into Expected...
Definition io.hpp:140
const Stars * InputStars() const override
Definition io.hpp:136
const StarIdentifiers * InputStarIds() const override
The centroid indices in the StarIdentifiers returned from InputStarIds should be indices into InputSt...
Definition io.hpp:139
GeneratedPipelineInput(const Catalog &, Attitude, Camera, std::default_random_engine *, bool centroidsOnly, decimal observedReferenceBrightness, decimal starSpreadStdDev, decimal sensitivity, decimal darkCurrent, decimal readNoiseStdDev, Attitude motionBlurDirection, decimal exposureTime, decimal readoutTime, bool shotNoise, int oversampling, int numFalseStars, int falseMinMagnitude, int falseMaxMagnitude, int cutoffMag, decimal perturbationStddev)
Create a generated pipeline input.
Definition io.cpp:500
const Catalog & GetCatalog() const override
The catalog to which catalog indexes returned from other methods refer.
Definition io.hpp:142
const Image * InputImage() const override
Definition io.hpp:135
const Camera * InputCamera() const override
Definition io.hpp:138
An 8-bit grayscale 2d image.
Definition io.hpp:59
unsigned char * image
The raw pixel data in the image.
Definition io.hpp:65
int height
Definition io.hpp:68
int width
Definition io.hpp:67
Represents the input and expected outputs of a pipeline run.
Definition io.hpp:90
virtual const Attitude * InputAttitude() const
Only used in tracking mode, in which case it is an estimate of the current attitude based on the last...
Definition io.hpp:102
virtual const Image * InputImage() const
Definition io.hpp:94
virtual const Catalog & GetCatalog() const =0
The catalog to which catalog indexes returned from other methods refer.
virtual const StarIdentifiers * InputStarIds() const
The centroid indices in the StarIdentifiers returned from InputStarIds should be indices into InputSt...
Definition io.hpp:100
virtual const Stars * InputStars() const
Definition io.hpp:97
virtual const Stars * ExpectedStars() const
Definition io.hpp:107
cairo_surface_t * InputImageSurface() const
Convert the InputImage() output into a cairo surface.
Definition io.cpp:355
virtual const Attitude * ExpectedAttitude() const
Definition io.hpp:114
virtual ~PipelineInput()
Definition io.hpp:92
virtual const StarIdentifiers * ExpectedStarIds() const
Centroid indices in the StarIdentifiers returned from ExpectedStarIds should be indices into Expected...
Definition io.hpp:113
virtual const Camera * InputCamera() const
Definition io.hpp:103
The command line options passed when running a pipeline.
Definition io.hpp:77
A set of algorithms that describes all or part of the star-tracking "pipeline".
Definition io.hpp:229
friend Pipeline SetPipeline(const PipelineOptions &values)
Create a pipeline from command line options.
Definition io.cpp:860
Pipeline()=default
PipelineOutput Go(const PipelineInput &)
Run all stages of a pipeline.
Definition io.cpp:945
const Catalog & GetCatalog() const override
The catalog to which catalog indexes returned from other methods refer.
Definition io.hpp:170
const Image * InputImage() const override
Definition io.hpp:168
const Camera * InputCamera() const override
Definition io.hpp:169
PngPipelineInput(cairo_surface_t *, Camera, const Catalog &)
Pipeline input for an image that's already been identified using Astrometry.net.
Definition io.cpp:381
A star idenification algorithm.
Definition star-id.hpp:14
UserSpecifiedOutputStream(std::string filePath, bool isBinary)
Create a PromptedOutputStream which will output to the given file.
Definition io.cpp:34
std::ostream & Stream()
return the inner output stream, suitable for use with <<
Definition io.hpp:37
double decimal
Definition decimal.hpp:8
LOST starting point.
unsigned char * SurfaceToGrayscaleImage(cairo_surface_t *cairoSurface)
Convert a colored Cairo image surface into a row-major array of grayscale pixels.
Definition io.cpp:127
std::vector< StarIdentifier > StarIdentifiers
const Catalog & CatalogRead()
Read and parse the full catalog from disk. If called multiple times, will re-use the first result.
Definition io.cpp:99
std::vector< Star > Stars
std::vector< MultiDatabaseEntry > MultiDatabaseDescriptor
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.
Definition io.cpp:1165
MultiDatabaseDescriptor GenerateDatabases(const Catalog &catalog, const DatabaseOptions &values)
Appropriately create descriptors for all requested databases according to command-line options.
Definition io.cpp:280
SerializeContext serFromDbValues(const DatabaseOptions &values)
Definition io.cpp:276
std::vector< std::unique_ptr< PipelineInput > > PipelineInputList
Definition io.hpp:158
PipelineInputList GetPipelineInput(const PipelineOptions &values)
Come up with a list of pipeline inputs based on command line options.
Definition io.cpp:826
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.
Definition io.cpp:1735
Pipeline SetPipeline(const PipelineOptions &values)
Create a pipeline from command line options.
Definition io.cpp:860
void InspectCatalog()
const char kNoDefaultArgument
Definition io.hpp:28
std::ostream & operator<<(std::ostream &output, const Vec2 &vec)
std::vector< CatalogStar > Catalog
cairo_surface_t * GrayscaleImageToSurface(const unsigned char *image, const int width, const int height)
Definition io.cpp:156
The result of running a pipeline.
Definition io.hpp:186
Catalog catalog
The catalog that the indices in starIds refer to.
Definition io.hpp:201
long long centroidingTimeNs
How many nanoseconds the centroiding stage of the pipeline took.
Definition io.hpp:193
std::unique_ptr< Stars > stars
Definition io.hpp:187
long long starIdTimeNs
Definition io.hpp:194
long long attitudeEstimationTimeNs
Definition io.hpp:195
std::unique_ptr< Attitude > attitude
Definition io.hpp:189
std::unique_ptr< StarIdentifiers > starIds
Definition io.hpp:188
The result of comparing an actual star identification with the true star idenification,...
Definition io.hpp:205
int numCorrect
The number of centroids in the image which are close to an expected centroid that had an expected ide...
Definition io.hpp:208
int numTotal
The number of centroids sufficiently close to a true expected star.
Definition io.hpp:216
int numIncorrect
The number of centroids which were either:
Definition io.hpp:213