46 TYPE_AFFINE_SLANTX = 3,
47 TYPE_AFFINE_INTERPX = 4,
52 transform_type_t d_type = TYPE_INVALID;
62 std::vector<std::pair<double, double>> interpx_points;
63 std::vector<std::pair<std::pair<double, double>, std::pair<double, double>>> interp_xy_points;
64 std::shared_ptr<projection::VizGeorefSpline2D> interp_fwd_interpolator;
65 std::shared_ptr<projection::VizGeorefSpline2D> interp_rev_interpolator;
105 ChannelTransform &init_interp_xy(std::vector<std::pair<std::pair<double, double>, std::pair<double, double>>> interp_xy_points);
110 j[
"type"] = (int)v.d_type;
112 if (v.d_type == TYPE_AFFINE ||
113 v.d_type == TYPE_AFFINE_SLANTX ||
114 v.d_type == TYPE_AFFINE_INTERPX)
116 j[
"ax"] = v.affine_a_x;
117 j[
"ay"] = v.affine_a_y;
118 j[
"bx"] = v.affine_b_x;
119 j[
"by"] = v.affine_b_y;
122 if (v.d_type == TYPE_AFFINE_SLANTX)
124 j[
"slantx_center"] = v.slantx_center;
125 j[
"slantx_ampli"] = v.slantx_ampli;
128 if (v.d_type == TYPE_AFFINE_INTERPX)
130 j[
"interpx_points"] = v.interpx_points;
133 if (v.d_type == TYPE_INTERP_XY)
135 j[
"interp_xy_points"] = v.interp_xy_points;
141 v.d_type = (transform_type_t)j[
"type"].get<int>();
143 if (v.d_type == TYPE_AFFINE ||
144 v.d_type == TYPE_AFFINE_SLANTX ||
145 v.d_type == TYPE_AFFINE_INTERPX)
147 v.affine_a_x = j[
"ax"];
148 v.affine_a_y = j[
"ay"];
149 v.affine_b_x = j[
"bx"];
150 v.affine_b_y = j[
"by"];
153 if (v.d_type == TYPE_AFFINE_SLANTX)
155 v.slantx_center = j[
"slantx_center"];
156 v.slantx_ampli = j[
"slantx_ampli"];
159 if (v.d_type == TYPE_AFFINE_INTERPX)
161 v.interpx_points = j[
"interpx_points"].get<std::vector<std::pair<double, double>>>();
163 v.interp_fwd_interpolator = std::make_shared<projection::VizGeorefSpline2D>(1);
164 v.interp_rev_interpolator = std::make_shared<projection::VizGeorefSpline2D>(1);
166 for (
auto &p : v.interpx_points)
168 v.interp_fwd_interpolator->add_point(p.first, p.first, &p.second);
169 v.interp_rev_interpolator->add_point(p.second, p.second, &p.first);
172 v.interp_fwd_interpolator->solve();
173 v.interp_rev_interpolator->solve();
176 if (v.d_type == TYPE_INTERP_XY)
178 v.interp_xy_points = j[
"interp_xy_points"].get<std::vector<std::pair<std::pair<double, double>, std::pair<double, double>>>>();
180 v.interp_fwd_interpolator = std::make_shared<projection::VizGeorefSpline2D>(2);
181 v.interp_rev_interpolator = std::make_shared<projection::VizGeorefSpline2D>(2);
183 for (
auto &p : v.interp_xy_points)
185 printf(
"Point %f %f => %f %f\n", p.first.first, p.first.second, p.second.first, p.second.second);
186 double p1[2] = {p.second.first, p.second.second};
187 v.interp_fwd_interpolator->add_point(p.first.first, p.first.second, p1);
188 double p2[2] = {p.first.first, p.first.second};
189 v.interp_rev_interpolator->add_point(p.second.first, p.second.second, p2);
192 v.interp_fwd_interpolator->solve();
193 v.interp_rev_interpolator->solve();
215 inline void forward(
double *x,
double *y)
const
217 if (d_type == TYPE_NONE)
219 else if (d_type == TYPE_AFFINE)
221 *x = *x * affine_a_x + affine_b_x;
222 *y = *y * affine_a_y + affine_b_y;
224 else if (d_type == TYPE_AFFINE_SLANTX)
226 *y -= (*x - slantx_center) * slantx_ampli;
227 *x = *x * affine_a_x + affine_b_x;
228 *y = *y * affine_a_y + affine_b_y;
230 else if (d_type == TYPE_AFFINE_INTERPX)
232 *x = *x * affine_a_x + affine_b_x;
233 *y = *y * affine_a_y + affine_b_y;
234 interp_fwd_interpolator->get_point(*x, *x, x);
236 else if (d_type == TYPE_INTERP_XY)
239 printf(
"%f %f FWD => ", *x, *y);
240 interp_fwd_interpolator->get_point(*x, *y, out);
243 printf(
"%f %f\n ", *x, *y);
245 else if (d_type == TYPE_INVALID)
246 throw satdump_exception(
"Invalid Channel Transform!\n");
254 inline void reverse(
double *x,
double *y)
const
256 if (d_type == TYPE_NONE)
258 else if (d_type == TYPE_AFFINE)
260 *x = (*x - affine_b_x) / affine_a_x;
261 *y = (*y - affine_b_y) / affine_a_y;
263 else if (d_type == TYPE_AFFINE_SLANTX)
265 *x = (*x - affine_b_x) / affine_a_x;
266 *y = (*y - affine_b_y) / affine_a_y;
267 *y += (*x - slantx_center) * slantx_ampli;
269 else if (d_type == TYPE_AFFINE_INTERPX)
271 interp_rev_interpolator->get_point(*x, *x, x);
272 *x = (*x - affine_b_x) / affine_a_x;
273 *y = (*y - affine_b_y) / affine_a_y;
275 else if (d_type == TYPE_INTERP_XY)
278 printf(
"%f %f REV => ", *x, *y);
279 interp_rev_interpolator->get_point(*x, *y, out);
282 printf(
"%f %f\n ", *x, *y);
284 else if (d_type == TYPE_INVALID)
285 throw satdump_exception(
"Invalid Channel Transform!\n");