OpenCPN Partial API docs
Loading...
Searching...
No Matches
GribOverlayFactory.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2014 by David S. Register *
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, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
35#ifndef _GRIBOVERLAYFACTORY_H_
36#define _GRIBOVERLAYFACTORY_H_
37
38#include <map>
39
40#include <wx/geometry.h>
41
42#include "pi_gl.h"
43
44#include "pi_ocpndc.h"
45#include "pi_TexFont.h"
46
55public:
56 GribOverlay(void) {
57 m_iTexture = 0;
58 m_pDCBitmap = nullptr, m_pRGBA = nullptr;
59 }
60
61 ~GribOverlay(void) {
62#ifdef ocpnUSE_GL
63 if (m_iTexture) {
64 glDeleteTextures(1, &m_iTexture);
65 }
66#endif
67 delete m_pDCBitmap, delete[] m_pRGBA;
68 }
69
70 unsigned int m_iTexture, m_iTextureDim[2]; /* opengl mode */
71 unsigned int m_iTexDataDim[2];
72
73 wxBitmap *m_pDCBitmap; /* dc mode */
74 unsigned char *m_pRGBA;
75
76 int m_width;
77 int m_height;
78
79 double m_dwidth, m_dheight;
80};
81
82#define MAX_PARTICLE_HISTORY 8
83#include <vector>
84#include <list>
91struct Particle {
94
95 // history is a ringbuffer.. because so many particles are
96 // used, it is a slight optimization over std::list
97 int m_HistoryPos, m_HistorySize, m_Run;
98 struct ParticleNode {
99 float m_Pos[2];
100 float m_Screen[2];
101 wxUint8 m_Color[3];
102 } m_History[MAX_PARTICLE_HISTORY];
103};
104
111public:
112 ParticleMap(int settings)
113 : m_Setting(settings),
114 history_size(0),
115 array_size(0),
116 color_array(nullptr),
117 vertex_array(nullptr),
118 color_float_array(nullptr) {
119 // XXX should be done in default PlugIn_ViewPort CTOR
120 last_viewport.bValid = false;
121 }
122
123 ~ParticleMap() {
124 delete[] color_array;
125 delete[] vertex_array;
126 delete[] color_float_array;
127 }
128
129 std::vector<Particle> m_Particles;
130
131 // particles are rebuilt whenever any of these fields change
132 time_t m_Reference_Time;
133 int m_Setting;
134 int history_size;
135
136 unsigned int array_size;
137 unsigned char *color_array;
138 float *vertex_array;
139 float *color_float_array;
140
141 PlugIn_ViewPort last_viewport;
142};
143
144class LineBuffer {
145public:
146 LineBuffer() {
147 count = 0;
148 lines = nullptr;
149 }
150 ~LineBuffer() { delete[] lines; }
151
152 void pushLine(float x0, float y0, float x1, float y1);
153 void pushPetiteBarbule(int b, int l);
154 void pushGrandeBarbule(int b, int l);
155 void pushTriangle(int b, int l);
156 void Finalize();
157
158 int count;
159 float *lines;
160
161private:
162 std::list<float> buffer;
163};
164
165class GRIBUICtrlBar;
166class GribRecord;
168
176class GRIBOverlayFactory : public wxEvtHandler {
177public:
180
181 void SetSettings(bool hiDefGraphics, bool GradualColors,
182 bool BarbedArrowHead = true) {
183 m_hiDefGraphics = hiDefGraphics;
184 m_bGradualColors = GradualColors;
185 m_bDrawBarbedArrowHead = BarbedArrowHead;
186 ClearCachedData();
187 }
188 void SetMessageFont();
189 void SetMessage(wxString message) { m_Message = message; }
190 void SetTimeZone(int TimeZone) { m_TimeZone = TimeZone; }
191 void SetParentSize(int w, int h) {
192 m_ParentSize.SetWidth(w);
193 m_ParentSize.SetHeight(h);
194 }
195
196 void SetGribTimelineRecordSet(GribTimelineRecordSet *pGribTimelineRecordSet1);
197 bool RenderGribOverlay(wxDC &dc, PlugIn_ViewPort *vp);
198 bool RenderGLGribOverlay(wxGLContext *pcontext, PlugIn_ViewPort *vp);
199
200 void Reset();
201 void ClearCachedData(void);
202 void ClearCachedLabel(void) { m_labelCache.clear(); }
203 void ClearParticles() {
204 delete m_ParticleMap;
205 m_ParticleMap = nullptr;
206 }
207
208 GribTimelineRecordSet *m_pGribTimelineRecordSet;
209
210 void DrawMessageZoomOut(PlugIn_ViewPort *vp);
211 void GetGraphicColor(int settings, double val, unsigned char &r,
212 unsigned char &g, unsigned char &b);
213 wxColour GetGraphicColor(int settings, double val);
214
215 wxSize m_ParentSize;
216
217 pi_ocpnDC *m_oDC;
218
219private:
220 void InitColorsTable();
221
222 void SettingsIdToGribId(int i, int &idx, int &idy, bool &polar);
223 bool DoRenderGribOverlay(PlugIn_ViewPort *vp);
224 void RenderGribBarbedArrows(int config, GribRecord **pGR,
225 PlugIn_ViewPort *vp);
226 void RenderGribIsobar(int config, GribRecord **pGR,
227 wxArrayPtrVoid **pIsobarArray, PlugIn_ViewPort *vp);
228 void RenderGribDirectionArrows(int config, GribRecord **pGR,
229 PlugIn_ViewPort *vp);
230 void RenderGribOverlayMap(int config, GribRecord **pGR, PlugIn_ViewPort *vp);
231 void RenderGribNumbers(int config, GribRecord **pGR, PlugIn_ViewPort *vp);
232 void RenderGribParticles(int settings, GribRecord **pGR, PlugIn_ViewPort *vp);
233 void DrawLineBuffer(LineBuffer &buffer);
234 void OnParticleTimer(wxTimerEvent &event);
235
236 wxString GetRefString(GribRecord *rec, int map);
237 void DrawMessageWindow(wxString msg, int x, int y, wxFont *mfont);
238
239 void DrawProjectedPosition(int x, int y);
240
241 void drawDoubleArrow(int x, int y, double ang, wxColour arrowColor,
242 int arrowWidth, int arrowSizeIdx, double scale);
243 void drawSingleArrow(int x, int y, double ang, wxColour arrowColor,
244 int arrowWidth, int arrowSizeIdx, double scale);
245 void drawWindArrowWithBarbs(int settings, int x, int y, double vkn,
246 double ang, bool south, wxColour arrowColor,
247 double rotate_angle);
248 void drawLineBuffer(LineBuffer &buffer, int x, int y, double ang,
249 double scale, bool south = false, bool head = true);
250
251 void DrawNumbers(wxPoint p, double value, int settings, wxColour back_color);
252 void FillGrid(GribRecord *pGR);
253
254 wxString getLabelString(double value, int settings);
255 wxImage &getLabel(double value, int settings, wxColour back_colour);
256
257#ifdef ocpnUSE_GL
258 void DrawGLTexture(GribOverlay *pGO, GribRecord *pGR, PlugIn_ViewPort *vp);
259 void GetCalibratedGraphicColor(int settings, double val_in,
260 unsigned char *data);
261 bool CreateGribGLTexture(GribOverlay *pGO, int config, GribRecord *pGR);
262 void DrawSingleGLTexture(GribOverlay *pGO, GribRecord *pGR, double uv[],
263 double x, double y, double xs, double ys);
264#endif
265 wxImage CreateGribImage(int config, GribRecord *pGR, PlugIn_ViewPort *vp,
266 int grib_pixel_size, const wxPoint &porg);
267
268 double m_last_vp_scale;
269
270 GribOverlay *m_pOverlay[GribOverlaySettings::SETTINGS_COUNT];
271
272 wxString m_Message;
273 wxString m_Message_Hiden;
274 int m_TimeZone;
275
276 wxDC *m_pdc;
277#if wxUSE_GRAPHICS_CONTEXT
278 wxGraphicsContext *m_gdc;
279#endif
280
281 wxFont *m_Font_Message;
282
283 bool m_hiDefGraphics;
284 bool m_bGradualColors;
285 bool m_bDrawBarbedArrowHead;
286
287 std::map<double, wxImage> m_labelCache;
288
289 TexFont m_TexFontMessage, m_TexFontNumbers;
290
291 GRIBUICtrlBar &m_dlg;
292 GribOverlaySettings &m_Settings;
293
294 ParticleMap *m_ParticleMap;
295 wxTimer m_tParticleTimer;
296 bool m_bUpdateParticles;
297
298 LineBuffer m_WindArrowCache[14];
299 LineBuffer m_SingleArrow[2], m_DoubleArrow[2];
300
301 double m_pixelMM;
302 int windArrowSize;
303};
304
305#endif
Factory class for creating and managing GRIB data visualizations.
Container for rendered GRIB data visualizations in texture or bitmap form.
Represents a meteorological data grid from a GRIB (Gridded Binary) file.
Definition GribRecord.h:182
A specialized GribRecordSet that represents temporally interpolated weather data with isobar renderin...
Assembles input characters to lines.
OpenGL Platform Abstraction Layer.
Manager for particle animation system.
Individual particle for wind/current animation.
int m_Duration
Duration this particle should exist in animation cycles.