OpenCPN Partial API docs
Loading...
Searching...
No Matches
grib_overlay_factory.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, see <https://www.gnu.org/licenses/>. *
16 ***************************************************************************/
17
36#ifndef GRIBOVERLAYFACTORY_H_
37#define GRIBOVERLAYFACTORY_H_
38
39#include <map>
40
41#include "pi_gl.h"
42
43#include "pi_ocpndc.h"
44#include "pi_tex_font.h"
45#include "grib_ui_dlg.h"
54public:
55 GribOverlay() {
56 m_iTexture = 0;
57 m_pDCBitmap = nullptr, m_pRGBA = nullptr;
58 }
59
60 ~GribOverlay() {
61#ifdef ocpnUSE_GL
62 if (m_iTexture) {
63 glDeleteTextures(1, &m_iTexture);
64 }
65#endif
66 delete m_pDCBitmap, delete[] m_pRGBA;
67 }
68
69 unsigned int m_iTexture, m_iTextureDim[2]; /* opengl mode */
70 unsigned int m_iTexDataDim[2];
71
72 wxBitmap *m_pDCBitmap; /* dc mode */
73 unsigned char *m_pRGBA;
74
75 int m_width;
76 int m_height;
77
78 double m_dwidth, m_dheight;
79};
80
81#define MAX_PARTICLE_HISTORY 8
82#include <vector>
83#include <list>
90struct Particle {
93
94 // history is a ringbuffer.. because so many particles are
95 // used, it is a slight optimization over std::list
96 int m_HistoryPos, m_HistorySize, m_Run;
97 struct ParticleNode {
98 float m_Pos[2];
99 float m_Screen[2];
100 wxUint8 m_Color[3];
101 } m_History[MAX_PARTICLE_HISTORY];
102};
103
110public:
111 ParticleMap(int settings)
112 : m_Setting(settings),
113 history_size(0),
114 array_size(0),
115 color_array(nullptr),
116 vertex_array(nullptr),
117 color_float_array(nullptr) {
118 // XXX should be done in default PlugIn_ViewPort CTOR
119 last_viewport.bValid = false;
120 }
121
122 ~ParticleMap() {
123 delete[] color_array;
124 delete[] vertex_array;
125 delete[] color_float_array;
126 }
127
128 std::vector<Particle> m_Particles;
129
130 // particles are rebuilt whenever any of these fields change
131 time_t m_Reference_Time;
132 int m_Setting;
133 int history_size;
134
135 unsigned int array_size;
136 unsigned char *color_array;
137 float *vertex_array;
138 float *color_float_array;
139
140 PlugIn_ViewPort last_viewport;
141};
142
143class LineBuffer {
144public:
145 LineBuffer() {
146 count = 0;
147 lines = nullptr;
148 }
149 ~LineBuffer() { delete[] lines; }
150
151 void pushLine(float x0, float y0, float x1, float y1);
152 void pushPetiteBarbule(int b, int l);
153 void pushGrandeBarbule(int b, int l);
154 void pushTriangle(int b, int l);
155 void Finalize();
156
157 int count;
158 float *lines;
159
160private:
161 std::list<float> buffer;
162};
163
164class GRIBUICtrlBar;
165class GribRecord;
167
175class GRIBOverlayFactory : public wxEvtHandler {
176public:
178 ~GRIBOverlayFactory() override;
179
180 void SetSettings(bool hiDefGraphics, bool GradualColors,
181 bool BarbedArrowHead = true) {
182 m_hi_def_graphics = hiDefGraphics;
183 m_gradual_colors = GradualColors;
184 m_draw_barbed_arrow_head = BarbedArrowHead;
185 ClearCachedData();
186 }
187 void SetMessageFont();
188 void SetMessage(wxString message) { m_message = std::move(message); }
189 void SetParentSize(int w, int h) {
190 m_ParentSize.SetWidth(w);
191 m_ParentSize.SetHeight(h);
192 }
193
194 void SetGribTimelineRecordSet(GribTimelineRecordSet *pGribTimelineRecordSet1);
195 bool RenderGribOverlay(wxDC &dc, PlugIn_ViewPort *vp);
196 bool RenderGLGribOverlay(wxGLContext *pcontext, PlugIn_ViewPort *vp);
197
198 void Reset();
199 void ClearCachedData();
200 void ClearCachedLabel() { m_label_cache.clear(); }
201 void ClearParticles() {
202 delete m_particle_map;
203 m_particle_map = nullptr;
204 }
205
206 GribTimelineRecordSet *m_pGribTimelineRecordSet;
207
208 void DrawMessageZoomOut(PlugIn_ViewPort *vp);
209 void GetGraphicColor(int settings, double val, unsigned char &r,
210 unsigned char &g, unsigned char &b);
211 wxColour GetGraphicColor(int settings, double val);
212
213 wxSize m_ParentSize;
214
215 pi_ocpnDC *m_oDC;
216
217private:
218 void InitColorsTable();
219
220 void SettingsIdToGribId(int i, int &idx, int &idy, bool &polar);
221 bool DoRenderGribOverlay(PlugIn_ViewPort *vp);
235 void RenderGribBarbedArrows(int config, GribRecord **pGR,
236 PlugIn_ViewPort *vp);
251 void RenderGribIsobar(int config, GribRecord **pGR,
252 wxArrayPtrVoid **pIsobarArray, PlugIn_ViewPort *vp);
265 void RenderGribDirectionArrows(int config, GribRecord **pGR,
266 PlugIn_ViewPort *vp);
279 void RenderGribOverlayMap(int config, GribRecord **pGR, PlugIn_ViewPort *vp);
280
294 void RenderGribNumbers(int config, GribRecord **pGR, PlugIn_ViewPort *vp);
295
310 void RenderGribParticles(int settings, GribRecord **pGR, PlugIn_ViewPort *vp);
311 void DrawLineBuffer(LineBuffer &buffer);
312 void OnParticleTimer(wxTimerEvent &event);
313
314 void DrawMessageWindow(wxString msg, int x, int y, wxFont *mfont);
315
316 void DrawProjectedPosition(int x, int y);
317
318 void DrawDoubleArrow(int x, int y, double ang, wxColour arrowColor,
319 int arrowWidth, int arrowSizeIdx, double scale);
320 void DrawSingleArrow(int x, int y, double ang, wxColour arrowColor,
321 int arrowWidth, int arrowSizeIdx, double scale);
322 void DrawWindArrowWithBarbs(int settings, int x, int y, double vkn,
323 double ang, bool south, wxColour arrowColor,
324 double rotate_angle);
325 void DrawLineBuffer(LineBuffer &buffer, int x, int y, double ang,
326 double scale, bool south = false, bool head = true);
327
328 void DrawNumbers(wxPoint p, double value, int settings, wxColour back_color);
329 void FillGrid(GribRecord *pGR);
330
331 wxString GetLabelString(double value, int settings);
332 wxImage &GetLabel(double value, int settings, wxColour back_colour);
333
334#ifdef ocpnUSE_GL
335 void DrawGLTexture(GribOverlay *pGO, GribRecord *pGR, PlugIn_ViewPort *vp);
336 void GetCalibratedGraphicColor(int settings, double val_in,
337 unsigned char *data);
338 bool CreateGribGLTexture(GribOverlay *pGO, int config, GribRecord *pGR);
339 void DrawSingleGLTexture(GribOverlay *pGO, GribRecord *pGR, double uv[],
340 double x, double y, double xs, double ys);
341#endif
342 wxImage CreateGribImage(int config, GribRecord *pGR, PlugIn_ViewPort *vp,
343 int grib_pixel_size, const wxPoint &porg);
344
345 double m_last_vp_scale;
346
347 GribOverlay *m_pOverlay[GribOverlaySettings::SETTINGS_COUNT];
348
349 wxString m_message;
350 wxString m_message_hiden;
351
352 wxDC *m_pdc;
353#if wxUSE_GRAPHICS_CONTEXT
354 wxGraphicsContext *m_gdc;
355#endif
356
357 wxFont *m_Font_Message;
358
359 bool m_hi_def_graphics;
360 bool m_gradual_colors;
361 bool m_draw_barbed_arrow_head;
362
363 std::map<double, wxImage> m_label_cache;
364
365 TexFont m_tex_font_message;
366 TexFont m_tex_font_numbers;
367
368 GRIBUICtrlBar &m_dlg;
369 GribOverlaySettings &m_settings;
370
371 ParticleMap *m_particle_map;
372 wxTimer m_particle_time_timer;
373 bool m_update_particle_particles;
374
375 LineBuffer m_wind_arrow_cach_cache[14];
376 LineBuffer m_single_arrow[2];
377 LineBuffer m_double_arrow[2];
378
379 double m_pixel_mm;
380 int m_wind_arrow_size;
381};
382
383#endif // GRIBOVERLAYFACTORY_H_
Factory class for creating and managing GRIB data visualizations.
Container for rendered GRIB data visualizations in texture or bitmap form.
A meteorological data grid from a GRIB (Gridded Binary) file.
A specialized GribRecordSet that represents temporally interpolated weather data with isobar renderin...
Assembles input characters to lines.
Contains view parameters and status information for a chart display viewport.
bool bValid
True if this viewport is valid and can be used for rendering.
GRIB Weather Data Control Interface.
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.
Graphics abstraction layer on top of wxDC or OpenGL.
OpenGL text rendering.