OpenCPN Partial API docs
Loading...
Searching...
No Matches
magnetic_plot_map.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2013 by Sean D'Epagnier *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifndef MagNETiC_PlotMAP_H_
25#define MagNETiC_PlotMAP_H_
26
27#include <list>
28#include "pi_tex_font.h"
29#include "GeomagnetismHeader.h"
30#include "ocpn_plugin.h"
31
32/* must be a power of 2, and also divide 360 and 176;
33 really only 8 works without more modifications */
34#define ZONE_SIZE 8
35
36/* divisible by 8 and any closer to the pole than this plots
37 horribly anyway on a flattened earth. */
38#define MAX_LAT 88
39#define LATITUDE_ZONES (2 * MAX_LAT / ZONE_SIZE) /* perfectly divisible */
40#define LONGITUDE_ZONES (360 / ZONE_SIZE)
41
42enum MagneticPlotType {
43 DECLINATION_PLOT,
44 INCLINATION_PLOT,
45 FIELD_STRENGTH_PLOT
46};
47
48class pi_ocpnDC;
49
50/* a single line segment in the plot */
52public:
53 PlotLineSeg(double _lat1, double _lon1, double _lat2, double _lon2,
54 double _contour)
55 : lat1(_lat1), lon1(_lon1), lat2(_lat2), lon2(_lon2), contour(_contour) {}
56 double lat1, lon1, lat2, lon2;
57 double contour;
58};
59
60/* cache values computed from wmm to improve speed */
62public:
63 ParamCache() : values(NULL), m_step(0), m_lat(0.0) {}
64 ~ParamCache() { delete[] values; }
65 void Initialize(double step);
66 bool Read(double lat, double lon, double &value);
67
68 double *values;
69 double m_step;
70 double m_lat;
71};
72
73/* main model map suitable for a single plot type */
75public:
76 MagneticPlotMap(MagneticPlotType type, MAGtype_MagneticModel *&mm,
78 : m_type(type),
79 m_bEnabled(false),
80 m_Spacing(0.0),
81 m_Step(0.0),
82 m_PoleAccuracy(0.0),
83 MagneticModel(mm),
84 TimedMagneticModel(tmm),
85 Ellip(ellip),
86 lastx(0),
87 lasty(0) {
88 UserDate.Year = 2015;
89 UserDate.Month = 1;
90 UserDate.Day = 1;
91 UserDate.DecimalYear = 2015.0;
92 }
93
94 ~MagneticPlotMap() { ClearMap(); }
95
96 void ConfigureAccuracy(int stepsize, int poleaccuracy);
97 double CalcParameter(double lat, double lon);
98 void BuildParamCache(ParamCache &cache, double lat);
99 double CachedCalcParameter(double lat, double lon);
100 bool Interpolate(double x1, double x2, double y1, double y2, bool lat,
101 double lonval, double &rx, double &ry);
102 void PlotRegion(std::list<PlotLineSeg *> &region, double lat1, double lon1,
103 double lat2, double lon2);
104 bool Recompute(wxDateTime date);
105 void Plot(pi_ocpnDC *dc, PlugIn_ViewPort *vp, wxColour color);
106
107 void ClearMap();
108 void DrawContour(pi_ocpnDC *dc, PlugIn_ViewPort &VP, double contour,
109 double lat, double lon);
110
111 MagneticPlotType m_type;
112 bool m_bEnabled;
113 double m_Spacing;
114 double m_Step;
115 double m_PoleAccuracy;
116
117 /* two caches for all longitudes alternate
118 places (step over each other) to cover the two latitudes
119 currently being built */
120 ParamCache m_Cache[2];
121
122 MAGtype_MagneticModel *&MagneticModel;
123 MAGtype_MagneticModel *&TimedMagneticModel;
124 MAGtype_Ellipsoid *Ellip;
125 MAGtype_Date UserDate;
126
127 /* the line segments for the entire globe split into zones */
128 std::list<PlotLineSeg *> m_map[LATITUDE_ZONES][LONGITUDE_ZONES];
129
130 TexFont m_TexFont;
131 int lastx, lasty; /* when rendering to prevent overcluttering */
132};
133
134#endif // MagNETiC_PlotMAP_H_
Geomagnetism Library subroutines.
Contains view parameters and status information for a chart display viewport.
PlugIn Object Definition/API.
OpenGL text rendering.