1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
//! Projections: image coordinates as a function of azimuth/elevation angle,
//! with symbolically pre-generated derivatives (see `codegen/`).
//!
//! Faithful port of gipfel's `ProjectionLSQ.{H,cxx}`, `ProjectionRectilinear.*`
//! and `ProjectionCylindrical.*`.
pub mod cylindrical;
pub mod rectilinear;
pub const NAN: f64 = f64::NAN;
/// The 7 fitted view parameters (radians where angular).
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct ViewParams {
/// azimuth of image center, radians
pub a_center: f64,
/// focal scale (pixels)
pub scale: f64,
/// pitch angle of image center (camera nose up), radians
pub a_pitch: f64,
/// camera roll, radians
pub a_roll: f64,
/// radial distortion coefficient 0
pub k0: f64,
/// radial distortion coefficient 1
pub k1: f64,
/// distortion center x, pixels
pub x0: f64,
}
impl ViewParams {
pub fn new() -> Self {
ViewParams {
a_center: 0.0,
scale: 3500.0,
a_pitch: 0.0,
a_roll: 0.0,
k0: 0.0,
k1: 0.0,
x0: 0.0,
}
}
}
/// The 9 arguments every generated macro function takes.
#[derive(Clone, Copy, Debug)]
pub struct ProjArgs {
pub c_view: f64,
pub c_pitch: f64,
pub c_roll: f64,
pub scale: f64,
pub k0: f64,
pub k1: f64,
pub x0: f64,
pub m_view: f64,
pub m_elev: f64,
}
impl ProjArgs {
pub fn from_params(p: &ViewParams, m_view: f64, m_elev: f64) -> Self {
ProjArgs {
c_view: p.a_center,
c_pitch: p.a_pitch,
c_roll: p.a_roll,
scale: p.scale,
k0: p.k0,
k1: p.k1,
x0: p.x0,
m_view,
m_elev,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ProjectionType {
Rectilinear = 0,
Cylindrical = 1,
}
/// A projection plus its symbolic partial derivatives w.r.t. the view
/// parameters. Methods default to `NAN`, matching the C++ base class.
pub trait Projection: Send + Sync {
/// half-width of the visible azimuth range, radians
fn get_view_angle(&self) -> f64;
fn mac_x(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_y(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_x_dc_view(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_x_dc_pitch(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_x_dc_roll(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_x_dscale(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_x_dk0(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_x_dk1(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_x_dx0(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_y_dc_view(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_y_dc_pitch(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_y_dc_roll(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_y_dscale(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_y_dk0(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_y_dk1(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
fn mac_y_dx0(&self, a: ProjArgs) -> f64 {
let _ = a;
NAN
}
/// Project azimuth/elevation to image coordinates (relative to image center),
/// normalizing azimuth around the view center like the C++ original.
fn get_coordinates(&self, alph: f64, elev: f64, parms: &ViewParams) -> (f64, f64) {
let mut alph = alph;
let pi = crate::hill::PI;
if alph - parms.a_center > pi {
alph -= 2.0 * pi;
} else if alph - parms.a_center < -pi {
alph += 2.0 * pi;
}
let args = ProjArgs::from_params(parms, alph, elev);
(self.mac_x(args), self.mac_y(args))
}
}
pub fn projection_from_type(t: ProjectionType) -> Box<dyn Projection> {
match t {
ProjectionType::Rectilinear => Box::new(rectilinear::ProjectionRectilinear),
ProjectionType::Cylindrical => Box::new(cylindrical::ProjectionCylindrical),
}
}
|