Instrument Neutral Distributed Interface INDI 2.2.5
sky_renderer.h
Go to the documentation of this file.
1#pragma once
2#include <indiccd.h>
3
4#include <cstdint>
5#include <vector>
6
7// A fixed sensor defect at full-sensor (unbinned) pixel coordinates.
9{
10 int x {0};
11 int y {0};
12 // Extra dark current of a hot pixel, in ADU per second of exposure. Unused for cold pixels.
13 float rate {0};
14 // A cold (dead) pixel reads half the bias level whatever the exposure.
15 bool cold {false};
16};
17
18// Configuration parameters for the sky renderer.
19// All fields have sensible defaults; update via setConfig() when INDI properties change.
21{
22 int maxVal = 65000; // ADU ceiling
23 float limitingMag = 11.5f; // magnitude that gives 1 ADU/s at reference aperture
24 float saturationMag = 2.0f; // magnitude that saturates in 1 s
25 float seeing = 3.5f; // atmospheric FWHM (arcsec)
26 float skyGlow = 19.5f; // sky background brightness (magnitudes)
27 float tiltLR = 0.0f; // Left-to-Right tilt: extra defocus (arcsec) at sensor edge
28 float tiltTB = 0.0f; // Top-to-Bottom tilt: extra defocus (arcsec) at sensor edge
29};
30
31// SkyRenderer renders a synthetic sky scene into an INDI::CCDChip frame buffer.
32// It has no INDI::CCD base class and can be used standalone in tests.
33// Both CCDSim and GuideSim own one as a member and delegate DrawCcdFrame work to it.
35{
36 public:
37 SkyRenderer() = default;
38 explicit SkyRenderer(const RenderConfig &cfg) : m_Cfg(cfg) {}
39
40 void setConfig(const RenderConfig &cfg)
41 {
42 m_Cfg = cfg;
43 }
44 const RenderConfig &getConfig() const
45 {
46 return m_Cfg;
47 }
48
49 int maxPix() const
50 {
51 return m_MaxPix;
52 }
53 int minPix() const
54 {
55 return m_MinPix;
56 }
57
58 // Render a complete sky scene into chip's frame buffer.
59 // Returns the number of stars drawn, 0 if the field is empty or renderStars is false,
60 // or -1 if the GSC catalog tool could not be launched.
61 // ra_j2000_deg: field center RA in J2000 degrees [0..360).
62 // dec_j2000_deg: field center Dec in J2000 degrees [-90..90].
63 // rotation_deg: camera position angle from North (degrees).
64 // renderStars: if false, skip GSC catalog lookup and star rendering (use for flat frames).
65 // minSearchRadiusArcmin: if > 0, GSC search radius is clamped to at least this value.
66 int renderFrame(INDI::CCDChip *chip,
67 double ra_j2000_deg,
68 double dec_j2000_deg,
69 double focal_length_mm,
70 double rotation_deg,
71 float exposure_s,
72 bool renderStars = true,
73 double minSearchRadiusArcmin = 0);
74
75 float imageScaleX() const
76 {
77 return m_ImageScaleX;
78 }
79 float imageScaleY() const
80 {
81 return m_ImageScaleY;
82 }
83 void setImageScale(float scaleX, float scaleY)
84 {
85 m_ImageScaleX = scaleX;
86 m_ImageScaleY = scaleY;
87 }
88
89 int drawImageStar(INDI::CCDChip *, float mag, float x, float y, float exp_s);
90
91 void applyReadoutNoise(INDI::CCDChip *chip, int bias, int maxNoise);
92
93 // Generate a reproducible defect layout for an xres x yres sensor: hotCount hot pixels and
94 // coldCount cold pixels, all at distinct positions. Hot pixel rates are spread uniformly over
95 // [0.5, 1.5) x hotRate so that defect detection thresholds have something to separate.
96 // The same arguments always produce the same layout on every platform.
97 static std::vector<SensorDefect> generateDefects(int xres, int yres, int hotCount, int coldCount,
98 float hotRate, uint32_t seed = 1);
99
100 // Apply the defects to the chip's (unbinned) subframe. Call it after applyReadoutNoise() so the
101 // defects survive in every frame type: hot pixels add rate * exposure_s ADU, cold pixels read bias / 2.
102 // Defects outside the current subframe are skipped.
103 void applyDefects(INDI::CCDChip *chip, const std::vector<SensorDefect> &defects, float exposure_s,
104 int bias) const;
105
106 private:
107 RenderConfig m_Cfg;
108 int m_MaxPix {0};
109 int m_MinPix {65000};
110 float m_ImageScaleX {1.0f};
111 float m_ImageScaleY {1.0f};
112
113 double flux(double mag) const;
114 int addToPixel(INDI::CCDChip *, int x, int y, int val);
115 void drawSkyGlow(INDI::CCDChip *, float exp_s);
116};
The CCDChip class provides functionality of a CCD Chip within a CCD.
Definition indiccdchip.h:39
void applyDefects(INDI::CCDChip *chip, const std::vector< SensorDefect > &defects, float exposure_s, int bias) const
int renderFrame(INDI::CCDChip *chip, double ra_j2000_deg, double dec_j2000_deg, double focal_length_mm, double rotation_deg, float exposure_s, bool renderStars=true, double minSearchRadiusArcmin=0)
void setImageScale(float scaleX, float scaleY)
void applyReadoutNoise(INDI::CCDChip *chip, int bias, int maxNoise)
int drawImageStar(INDI::CCDChip *, float mag, float x, float y, float exp_s)
SkyRenderer()=default
const RenderConfig & getConfig() const
int maxPix() const
void setConfig(const RenderConfig &cfg)
float imageScaleY() const
int minPix() const
SkyRenderer(const RenderConfig &cfg)
static std::vector< SensorDefect > generateDefects(int xres, int yres, int hotCount, int coldCount, float hotRate, uint32_t seed=1)
float imageScaleX() const
float limitingMag
float saturationMag