Loading...
Searching...
No Matches
graphics-radar.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31
32
33#ifndef RACK_GRAPHICS_RADAR
34#define RACK_GRAPHICS_RADAR
35
36
37//#include "resources-image.h"
38//#include "resources.h"
39
40#include <drain/image/GeoFrame.h>
41#include <drain/image/TreeElemUtilsSVG.h>
42
43#include "radar/Composite.h"
44#include "radar/RadarProj.h"
45
46
47namespace rack {
48
50
57class RadarSVG {
58public:
59
60
61 inline
62 RadarSVG(int radialBezierResolution = 8){
63 setRadialResolution(radialBezierResolution);
64 };
65
66 inline
67 RadarSVG(const RadarSVG & radarSvg){
68 setRadialResolution(radialBezierResolution);
69 };
70
71
72
73 enum StyleClasses {
74 VECTOR_OVERLAY, // this is more for group ID/name
75 HIGHLIGHT, // CSS: activated on tool tip
76 // ^ rename VECTORS VECTOR_GRAPHICS
77 GRID, // CSS
78 };
79
81
86 static
87 drain::image::TreeSVG & getOverlayStyle(drain::image::TreeSVG & svgDoc);
88
90
93 static
94 drain::image::TreeSVG & getOverlayGroup(drain::image::TreeSVG & svgDoc);
95
96
97 // Projection of the latest radar input.
98 RadarProj radarProj;
99
100 // Maximum range of the latest radar input.
101 int maxRange = 0; // metres
102
105
107
110 void updateRadarConf(const drain::VariableMap & where);
111
113
117 // template <class T>
118 // void updateCartesianConf(const drain::SmartMap<T> & where);
119 void updateCartesianConf(const drain::VariableMap & where);
120
121 void updateCartesianConf(const Composite & comp);
122
124 inline
126 getCubicBezierConf(conf, n);
127 radialBezierResolution = n;
128 }
129
133 /*
134 void getCubicCoeff(int n, double & radialCoeff, double & angularOffset) const {
135 double theta = 2.0*M_PI / static_cast<double>(n);
136 double k = 4.0/3.0 * ::tan(theta/4.0);
137 radialCoeff = sqrt(1.0 + k*k);
138 angularOffset = ::atan(k);
139 }
140 */
141
143 // int sectorCount;
145 double delta = 0.0;
146 double radialCoeff = 1.0;
147 double angularOffset = 0.0;
148 };
149
150 CubicBezierConf conf;
151
152 /***
153 * \param n -sectors
154 */
155 inline
156 void getCubicBezierConf(CubicBezierConf & conf, int n) const {
157 getCubicBezierConf(conf, 0.0, 2.0*M_PI / static_cast<double>(n));
158 }
159
160 void getCubicBezierConf(CubicBezierConf & conf, double angleStartR, double angleEndR) const;
161
162 // typedef DRAIN_SVG_ELEM_CLS(PATH) svgPath;
163 inline
164 void convert(double radius, double azimuth, drain::Point2D<int> & imgPoint) const {
165 drain::Point2D<double> geoPoint;
166 polarToMeters(radius, azimuth, geoPoint);
167 // radarProj.projectFwd(radius*::sin(azimuth), radius*::cos(azimuth), geoPoint.x, geoPoint.y);
168 geoFrame.m2pix(geoPoint, imgPoint);
169 };
170
171 inline
172 void polarToMeters(double radius, double azimuth, drain::Point2D<double> & geoPoint) const {
173 radarProj.projectFwd(radius*::sin(azimuth), radius*::cos(azimuth), geoPoint.x, geoPoint.y);
174 //geoFrame.m2pix(geoPoint, imgPoint);
175 };
176
177 inline
178 void radarGeoToCompositeImage(drain::Point2D<double> & radarPoint, drain::Point2D<int> & imagePoint) const {
179 drain::Point2D<double> compositePoint;
180 radarProj.projectFwd(radarPoint, compositePoint);
181 geoFrame.m2pix(compositePoint, imagePoint);
182 }
183
184
186
189 inline
190 void moveTo(drain::svgPATH & elem, drain::Point2D<int> & imgPoint, double radiusM, double azimuthR) const {
191 convert(radiusM, azimuthR, imgPoint);
192 elem.absolute<drain::svgPATH::MOVE>(imgPoint.x, imgPoint.y);
193 }
194
195 // Simple version not sharing end point.
199 inline
200 void moveTo(drain::svgPATH & elem, double radius, double azimuth) const {
201 drain::Point2D<int> imgPoint;
202 moveTo(elem, imgPoint, radius, azimuth);
203 }
204
205 inline
206 void lineTo(drain::svgPATH & elem, double radius, double azimuth) const {
207 drain::Point2D<int> imgPoint;
208 lineTo(elem, imgPoint, radius, azimuth);
209 }
210
211 inline
212 void lineTo(drain::svgPATH & elem, drain::Point2D<int> & imgPoint, double radiusM, double azimuthR) const {
213 convert(radiusM, azimuthR, imgPoint);
214 elem.absolute<drain::svgPATH::LINE>(imgPoint.x, imgPoint.y);
215 }
216
217
219
222 void cubicBezierTo(drain::svgPATH & elem, double radiusM, double azimuthStartR, double azimuthEndR) const ;
223
227 void cubicBezierTo(drain::svgPATH & elem, drain::Point2D<int> & imgPoint, double radiusM, double azimuthStartR, double azimuthEndR) const;
228
229 inline
230 void close(drain::svgPATH & elem){
231 elem.absolute<drain::svgPATH::CLOSE>();
232 }
233
234protected:
235
236 int radialBezierResolution;
237
238};
239
240/*
241template <class T>
242void RadarSVG::updateCartesianConf(const drain::SmartMap<T> & where) {
243
244 drain::Logger mout(__FILE__, __FUNCTION__);
245 // Todo: also support fully cartesian input (without single-site metadata)
246 // radarProj.setSiteLocationDeg(where["lon"], where["lat"]);
247
248 const int epsg = where.get("epsg", 0); // non-standard
249 if (epsg){
250 mout.attention("EPSG found: ", epsg);
251 geoFrame.setProjectionEPSG(epsg);
252 // radarProj.setProjectionDst(epsg);
253 }
254 else {
255 const std::string projdef = where.get("projdef", ""); // otherwise gets "null"
256 geoFrame.setProjection(projdef);
257 // radarProj.setProjectionDst(projdef);
258 }
259 geoFrame.setBoundingBoxD(where["LL_lon"], where["LL_lat"], where["UR_lon"], where["UR_lat"]);
260 geoFrame.setGeometry(where["xsize"], where["ysize"]);
261
262}
263*/
264
265} // rack::
266
267
268DRAIN_ENUM_DICT(rack::RadarSVG::StyleClasses);
269
270DRAIN_ENUM_OSTREAM(rack::RadarSVG::StyleClasses);
271
272namespace drain {
273
274template <> // for T (Tree class)
275template <> // for K (path elem arg)
276inline
277const image::TreeSVG & image::TreeSVG::operator[](const rack::RadarSVG::StyleClasses & cls) const {
278 return (*this)[EnumDict<rack::RadarSVG::StyleClasses>::dict.getKey(cls, false)];
279}
280
281template <> // for T (Tree class)
282template <> // for K (path elem arg)
283inline
284image::TreeSVG & image::TreeSVG::operator[](const rack::RadarSVG::StyleClasses & cls) {
285 return (*this)[EnumDict<rack::RadarSVG::StyleClasses>::dict.getKey(cls, false)];
286}
287
288template <> // for T (Tree class)
289template <> // for K (path elem arg)
290inline
291bool image::TreeSVG::hasChild(const rack::RadarSVG::StyleClasses & cls) const {
292 return hasChild(EnumDict<rack::RadarSVG::StyleClasses>::dict.getKey(cls, true)); // no error
293}
294
295}
296
297#endif
void projectFwd(double &x, double &y) const
Forward projection (in-place)
Definition Proj6.h:191
A map of Variables.
Definition VariableMap.h:61
Array with georeferencing support.
Definition GeoFrame.h:58
virtual void m2pix(double x, double y, int &i, int &j) const
Scales geographic map coordinates to image coordinates.
Definition GeoFrame.h:345
Cartesian composite (mosaic) of data from several radars.
Definition Composite.h:102
Definition RadarProj.h:99
Vector graphics for both composites and single radar data (polar coordinates).
Definition graphics-radar.h:57
void setRadialResolution(int n)
Number of "sectors" in a sphere.
Definition graphics-radar.h:125
drain::image::GeoFrame geoFrame
Geographic extent and projection (Cartesian)
Definition graphics-radar.h:104
static drain::image::TreeSVG & getOverlayGroup(drain::image::TreeSVG &svgDoc)
Get (create) group dedicated for layers drawn over radar data.
Definition graphics-radar.cpp:138
void updateCartesianConf(const drain::VariableMap &where)
Read meta data related to Cartesian data, that is, geographic configuration of a radar composite.
Definition graphics-radar.cpp:228
void moveTo(drain::svgPATH &elem, drain::Point2D< int > &imgPoint, double radiusM, double azimuthR) const
Move to image point at (radius, azimuth)
Definition graphics-radar.h:190
void cubicBezierTo(drain::svgPATH &elem, double radiusM, double azimuthStartR, double azimuthEndR) const
Single command to draw arc.
Definition graphics-radar.cpp:285
static drain::image::TreeSVG & getOverlayStyle(drain::image::TreeSVG &svgDoc)
Sets some CSS properties applicable in radar graphics (grids, sectors).
Definition graphics-radar.cpp:68
void updateRadarConf(const drain::VariableMap &where)
Read meta data related to polar coordinates, that is, geographic configuration of a single radar.
Definition graphics-radar.cpp:169
Definition DataSelector.cpp:1277
Definition DataSelector.cpp:44
Definition Point.h:48
Definition graphics-radar.h:142
double delta
Sector angle.
Definition graphics-radar.h:145