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 inline
101 void deriveMaxRange(const Hi5Tree & srcPolar){
102 maxRange = DataTools::getMaxRange(srcPolar);
103 }
104
106 inline
107 double getRange(double r=1.0){
108 if (r<-1.0){
109 return r;
110 }
111 else if (r<=1.0){
112 return r*maxRange;
113 }
114 else {
115 return r;
116 }
117 };
118
119
120
123
125
128 void updateRadarConf(const drain::VariableMap & where);
129
131
135 // template <class T>
136 // void updateCartesianConf(const drain::SmartMap<T> & where);
137 void updateCartesianConf(const drain::VariableMap & where);
138
139 void updateCartesianConf(const Composite & comp);
140
142 inline
144 getCubicBezierConf(conf, n);
145 radialBezierResolution = n;
146 }
147
151 /*
152 void getCubicCoeff(int n, double & radialCoeff, double & angularOffset) const {
153 double theta = 2.0*M_PI / static_cast<double>(n);
154 double k = 4.0/3.0 * ::tan(theta/4.0);
155 radialCoeff = sqrt(1.0 + k*k);
156 angularOffset = ::atan(k);
157 }
158 */
159
161 // int sectorCount;
163 double delta = 0.0;
164 double radialCoeff = 1.0;
165 double angularOffset = 0.0;
166 };
167
168 CubicBezierConf conf;
169
170 /***
171 * \param n -sectors
172 */
173 inline
174 void getCubicBezierConf(CubicBezierConf & conf, int n) const {
175 getCubicBezierConf(conf, 0.0, 2.0*M_PI / static_cast<double>(n));
176 }
177
178 void getCubicBezierConf(CubicBezierConf & conf, double angleStartR, double angleEndR) const;
179
180 // typedef DRAIN_SVG_ELEM_CLS(PATH) svgPath;
181 inline
182 void convert(double radius, double azimuth, drain::Point2D<int> & imgPoint) const {
183 drain::Point2D<double> geoPoint;
184 polarToMeters(radius, azimuth, geoPoint);
185 // radarProj.projectFwd(radius*::sin(azimuth), radius*::cos(azimuth), geoPoint.x, geoPoint.y);
186 geoFrame.m2pix(geoPoint, imgPoint);
187 };
188
189 inline
190 void polarToMeters(double radius, double azimuth, drain::Point2D<double> & geoPoint) const {
191 radarProj.projectFwd(radius*::sin(azimuth), radius*::cos(azimuth), geoPoint.x, geoPoint.y);
192 //geoFrame.m2pix(geoPoint, imgPoint);
193 };
194
195 inline
196 void radarGeoToCompositeImage(drain::Point2D<double> & radarPoint, drain::Point2D<int> & imagePoint) const {
197 drain::Point2D<double> compositePoint;
198 radarProj.projectFwd(radarPoint, compositePoint);
199 geoFrame.m2pix(compositePoint, imagePoint);
200 }
201
202
204
207 inline
208 void moveTo(drain::svgPATH & elem, drain::Point2D<int> & imgPoint, double radiusM, double azimuthR) const {
209 convert(radiusM, azimuthR, imgPoint);
210 elem.absolute<drain::svgPATH::MOVE>(imgPoint.x, imgPoint.y);
211 }
212
213 // Simple version not sharing end point.
217 inline
218 void moveTo(drain::svgPATH & elem, double radius, double azimuth) const {
219 drain::Point2D<int> imgPoint;
220 moveTo(elem, imgPoint, radius, azimuth);
221 }
222
223 inline
224 void lineTo(drain::svgPATH & elem, double radius, double azimuth) const {
225 drain::Point2D<int> imgPoint;
226 lineTo(elem, imgPoint, radius, azimuth);
227 }
228
229 inline
230 void lineTo(drain::svgPATH & elem, drain::Point2D<int> & imgPoint, double radiusM, double azimuthR) const {
231 convert(radiusM, azimuthR, imgPoint);
232 elem.absolute<drain::svgPATH::LINE>(imgPoint.x, imgPoint.y);
233 }
234
235
237
240 void cubicBezierTo(drain::svgPATH & elem, double radiusM, double azimuthStartR, double azimuthEndR) const ;
241
245 void cubicBezierTo(drain::svgPATH & elem, drain::Point2D<int> & imgPoint, double radiusM, double azimuthStartR, double azimuthEndR) const;
246
247 inline
248 void close(drain::svgPATH & elem){
249 elem.absolute<drain::svgPATH::CLOSE>();
250 }
251
252protected:
253
254 int radialBezierResolution;
255
256 // Maximum range of the latest radar input.
257 double maxRange = 0.0; // metres
258
259};
260
261/*
262template <class T>
263void RadarSVG::updateCartesianConf(const drain::SmartMap<T> & where) {
264
265 drain::Logger mout(__FILE__, __FUNCTION__);
266 // Todo: also support fully cartesian input (without single-site metadata)
267 // radarProj.setSiteLocationDeg(where["lon"], where["lat"]);
268
269 const int epsg = where.get("epsg", 0); // non-standard
270 if (epsg){
271 mout.attention("EPSG found: ", epsg);
272 geoFrame.setProjectionEPSG(epsg);
273 // radarProj.setProjectionDst(epsg);
274 }
275 else {
276 const std::string projdef = where.get("projdef", ""); // otherwise gets "null"
277 geoFrame.setProjection(projdef);
278 // radarProj.setProjectionDst(projdef);
279 }
280 geoFrame.setBoundingBoxD(where["LL_lon"], where["LL_lat"], where["UR_lon"], where["UR_lat"]);
281 geoFrame.setGeometry(where["xsize"], where["ysize"]);
282
283}
284*/
285
286} // rack::
287
288
289DRAIN_ENUM_DICT(rack::RadarSVG::StyleClasses);
290
291DRAIN_ENUM_OSTREAM(rack::RadarSVG::StyleClasses);
292
293namespace drain {
294
295template <> // for T (Tree class)
296template <> // for K (path elem arg)
297inline
298const image::TreeSVG & image::TreeSVG::operator[](const rack::RadarSVG::StyleClasses & cls) const {
299 return (*this)[EnumDict<rack::RadarSVG::StyleClasses>::dict.getKey(cls, false)];
300}
301
302template <> // for T (Tree class)
303template <> // for K (path elem arg)
304inline
305image::TreeSVG & image::TreeSVG::operator[](const rack::RadarSVG::StyleClasses & cls) {
306 return (*this)[EnumDict<rack::RadarSVG::StyleClasses>::dict.getKey(cls, false)];
307}
308
309template <> // for T (Tree class)
310template <> // for K (path elem arg)
311inline
312bool image::TreeSVG::hasChild(const rack::RadarSVG::StyleClasses & cls) const {
313 return hasChild(EnumDict<rack::RadarSVG::StyleClasses>::dict.getKey(cls, true)); // no error
314}
315
316}
317
318#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
static int getMaxRange(const Hi5Tree &src, bool projected=true)
Definition DataTools.cpp:326
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:143
drain::image::GeoFrame geoFrame
Geographic extent and projection (Cartesian)
Definition graphics-radar.h:122
static drain::image::TreeSVG & getOverlayGroup(drain::image::TreeSVG &svgDoc)
Get (create) group dedicated for layers drawn over radar data.
Definition graphics-radar.cpp:148
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:238
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:208
void cubicBezierTo(drain::svgPATH &elem, double radiusM, double azimuthStartR, double azimuthEndR) const
Single command to draw arc.
Definition graphics-radar.cpp:295
double getRange(double r=1.0)
If r is inside +/-100% = [-1.0,1.0], return that portion of maximum range, else the argument as such.
Definition graphics-radar.h:107
static drain::image::TreeSVG & getOverlayStyle(drain::image::TreeSVG &svgDoc)
Sets some CSS properties applicable in radar graphics (grids, sectors).
Definition graphics-radar.cpp:54
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:179
Definition DataSelector.cpp:1277
Definition DataSelector.cpp:44
Definition Point.h:48
Definition graphics-radar.h:160
double delta
Sector angle.
Definition graphics-radar.h:163