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);
237 void RenderGribBarbedArrows(int config, GribRecord **pGR,
238 PlugIn_ViewPort *vp);
253 void RenderGribIsobar(int config, GribRecord **pGR,
254 wxArrayPtrVoid **pIsobarArray, PlugIn_ViewPort *vp);
267 void RenderGribDirectionArrows(int config, GribRecord **pGR,
268 PlugIn_ViewPort *vp);
281 void RenderGribOverlayMap(int config, GribRecord **pGR, PlugIn_ViewPort *vp);
295 void RenderGribNumbers(int config, GribRecord **pGR, PlugIn_ViewPort *vp);
310 void RenderGribParticles(int settings, GribRecord **pGR, PlugIn_ViewPort *vp);
311 void DrawLineBuffer(LineBuffer &buffer);
312 void OnParticleTimer(wxTimerEvent &event);
313
314 wxString GetRefString(GribRecord *rec, int map);
315 void DrawMessageWindow(wxString msg, int x, int y, wxFont *mfont);
316
317 void DrawProjectedPosition(int x, int y);
318
319 void drawDoubleArrow(int x, int y, double ang, wxColour arrowColor,
320 int arrowWidth, int arrowSizeIdx, double scale);
321 void drawSingleArrow(int x, int y, double ang, wxColour arrowColor,
322 int arrowWidth, int arrowSizeIdx, double scale);
323 void drawWindArrowWithBarbs(int settings, int x, int y, double vkn,
324 double ang, bool south, wxColour arrowColor,
325 double rotate_angle);
326 void drawLineBuffer(LineBuffer &buffer, int x, int y, double ang,
327 double scale, bool south = false, bool head = true);
328
329 void DrawNumbers(wxPoint p, double value, int settings, wxColour back_color);
330 void FillGrid(GribRecord *pGR);
331
332 wxString getLabelString(double value, int settings);
333 wxImage &getLabel(double value, int settings, wxColour back_colour);
334
335#ifdef ocpnUSE_GL
336 void DrawGLTexture(GribOverlay *pGO, GribRecord *pGR, PlugIn_ViewPort *vp);
337 void GetCalibratedGraphicColor(int settings, double val_in,
338 unsigned char *data);
339 bool CreateGribGLTexture(GribOverlay *pGO, int config, GribRecord *pGR);
340 void DrawSingleGLTexture(GribOverlay *pGO, GribRecord *pGR, double uv[],
341 double x, double y, double xs, double ys);
342#endif
343 wxImage CreateGribImage(int config, GribRecord *pGR, PlugIn_ViewPort *vp,
344 int grib_pixel_size, const wxPoint &porg);
345
346 double m_last_vp_scale;
347
348 GribOverlay *m_pOverlay[GribOverlaySettings::SETTINGS_COUNT];
349
350 wxString m_Message;
351 wxString m_Message_Hiden;
352 int m_TimeZone;
353
354 wxDC *m_pdc;
355#if wxUSE_GRAPHICS_CONTEXT
356 wxGraphicsContext *m_gdc;
357#endif
358
359 wxFont *m_Font_Message;
360
361 bool m_hiDefGraphics;
362 bool m_bGradualColors;
363 bool m_bDrawBarbedArrowHead;
364
365 std::map<double, wxImage> m_labelCache;
366
367 TexFont m_TexFontMessage, m_TexFontNumbers;
368
369 GRIBUICtrlBar &m_dlg;
370 GribOverlaySettings &m_Settings;
371
372 ParticleMap *m_ParticleMap;
373 wxTimer m_tParticleTimer;
374 bool m_bUpdateParticles;
375
376 LineBuffer m_WindArrowCache[14];
377 LineBuffer m_SingleArrow[2], m_DoubleArrow[2];
378
379 double m_pixelMM;
380 int windArrowSize;
381};
382
383#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.
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.
OpenGL Texture Font System.
Device Context Abstraction Layer.
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.