OpenCPN Partial API docs
Loading...
Searching...
No Matches
chartimg.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2010 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
24#ifndef _CHARTIMG_H_
25#define _CHARTIMG_H_
26
27#include "model/georef.h" // for GeoRef type
28
29#include "chartbase.h"
30#include "chartdb.h"
31#include "ocpn_region.h"
32#include "viewport.h"
33
34typedef enum ScaleTypeEnum {
35 RENDER_LODEF = 0,
36 RENDER_HIDEF,
37} _ScaleTypeEnum;
38
39class WXDLLEXPORT ChartImg;
40
41//-----------------------------------------------------------------------------
42// Constants, etc.
43//-----------------------------------------------------------------------------
44
45typedef enum PaletteDir { PaletteFwd, PaletteRev } _PaletteDir;
46
47typedef enum BSB_Color_Capability {
48 COLOR_RGB_DEFAULT = 0, // Default corresponds to bsb entries "RGB"
49 DAY,
50 DUSK,
51 NIGHT,
52 NIGHTRED,
53 GRAY,
54 PRC,
55 PRG,
56 N_BSB_COLORS
57} _BSB_Color_Capability;
58
59//-----------------------------------------------------------------------------
60// Fwd Refs
61//-----------------------------------------------------------------------------
62
63class ChartKAP;
64class ViewPort;
65class PixelCache;
66class ocpnBitmap;
67
68class wxFFileInputStream;
69
70//-----------------------------------------------------------------------------
71// Helper classes
72//-----------------------------------------------------------------------------
73
74class Refpoint {
75public:
76 int bXValid;
77 int bYValid;
78 float xr;
79 float yr;
80 float latr;
81 float lonr;
82 float xpl_error;
83 float xlp_error;
84 float ypl_error;
85 float ylp_error;
86};
87
89 int offset; // offset from start of line pointer
90 int pixel; // offset from current pixel
91};
92
94public:
95 unsigned char *pPix;
96 TileOffsetCache *pTileOffset; // entries for random access
97
98 bool bValid;
99 int size;
100};
101
103public:
106
107 int *FwdPalette;
108 int *RevPalette;
109 int nFwd;
110 int nRev;
111};
112
128class ChartBaseBSB : public ChartBase {
129public:
130 // Public methods
131
132 ChartBaseBSB();
133 virtual ~ChartBaseBSB();
134 void FreeLineCacheRows(int start = 0, int end = -1);
135 bool HaveLineCacheRow(int row);
136
137 // Accessors
138 virtual ThumbData *GetThumbData(int tnx, int tny, float lat, float lon);
139 virtual ThumbData *GetThumbData() { return pThumbData; }
140 virtual bool UpdateThumbData(double lat, double lon);
141
142 int GetNativeScale() { return m_Chart_Scale; }
143 double GetNormalScaleMin(double canvas_scale_factor, bool b_allow_overzoom);
144 double GetNormalScaleMax(double canvas_scale_factor, int canvas_width);
145
146 virtual InitReturn Init(const wxString &name, ChartInitFlag init_flags);
147
148 virtual int latlong_to_pix_vp(double lat, double lon, double &pixx,
149 double &pixy, ViewPort &vp);
150 virtual int vp_pix_to_latlong(ViewPort &vp, double pixx, double pixy,
151 double *lat, double *lon);
152
153 bool RenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
154 const OCPNRegion &Region);
155
156 virtual bool RenderRegionViewOnGL(const wxGLContext &glc,
157 const ViewPort &VPoint,
158 const OCPNRegion &RectRegion,
159 const LLRegion &Region);
160
161 virtual bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed);
172 virtual double GetNearestPreferredScalePPM(double target_scale_ppm);
173
174 virtual void GetValidCanvasRegion(const ViewPort &VPoint,
175 OCPNRegion *pValidRegion);
176 virtual LLRegion GetValidRegion();
177
178 virtual bool GetChartExtent(Extent *pext);
179
180 void SetColorScheme(ColorScheme cs, bool bApplyImmediate);
181
182 wxImage *GetImage();
183
184 void SetVPRasterParms(const ViewPort &vpt);
185
186 virtual void ComputeSourceRectangle(const ViewPort &vp, wxRect *pSourceRect);
187 virtual double GetRasterScaleFactor(const ViewPort &vp);
188 virtual bool GetChartBits(wxRect &source, unsigned char *pPix, int sub_samp);
189 virtual int GetSize_X() { return Size_X; }
190 virtual int GetSize_Y() { return Size_Y; }
191
192 virtual void latlong_to_chartpix(double lat, double lon, double &pixx,
193 double &pixy);
194 virtual void chartpix_to_latlong(double pixx, double pixy, double *plat,
195 double *plon);
196
197 double GetPPM() { return m_ppm_avg; }
198
199protected:
200 // Methods
201
202 wxRect GetSourceRect() { return Rsrc; }
203
204 virtual bool GetAndScaleData(unsigned char *ppn, size_t data_size,
205 wxRect &source, int source_stride, wxRect &dest,
206 int dest_stride, double scale_factor,
207 ScaleTypeEnum scale_type);
208 bool RenderViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint);
209
210 bool IsCacheValid() { return cached_image_ok; }
211 void InvalidateCache() { cached_image_ok = 0; }
212 bool IsRenderCacheable(wxRect &source, wxRect &dest);
213
214 void CreatePaletteEntry(char *buffer, int palette_index);
215 PaletteDir GetPaletteDir(void);
216 int *GetPalettePtr(BSB_Color_Capability);
217
229 double GetClosestValidNaturalScalePPM(double target_scale,
230 double scale_factor_min,
231 double scale_factor_max);
232
233 virtual void InvalidateLineCache();
234 virtual bool CreateLineIndex(void);
235
236 virtual wxBitmap *CreateThumbnail(int tnx, int tny, ColorScheme cs);
237 virtual int BSBGetScanline(unsigned char *pLineBuf, int y, int xs, int xl,
238 int sub_samp);
239
240 bool GetViewUsingCache(wxRect &source, wxRect &dest, const OCPNRegion &Region,
241 ScaleTypeEnum scale_type);
242 bool GetView(wxRect &source, wxRect &dest, ScaleTypeEnum scale_type);
243
244 virtual int BSBScanScanline(wxInputStream *pinStream);
245 virtual int ReadBSBHdrLine(wxInputStream *, char *, int);
246 virtual int AnalyzeRefpoints(bool b_testSolution = true);
247 virtual bool AnalyzeSkew(void);
248
249 virtual bool SetMinMax(void);
250
251 InitReturn PreInit(const wxString &name, ChartInitFlag init_flags,
252 ColorScheme cs);
253 InitReturn PostInit(void);
254
255 double AdjustLongitude(double lon);
256
257 // Protected Data
258 PixelCache *pPixCache;
259
260 int Size_X; // Chart native pixel dimensions
261 int Size_Y;
262 int m_Chart_DU;
263 double m_cph;
264 double m_proj_parameter; // Mercator: Projection Latitude
265 // Transverse Mercator: Central Meridian
266 double m_dx; // Pixel scale factors, from KAP header
267 double m_dy;
268
269 wxString m_bsb_ver;
270 bool m_b_SHOM;
271 bool m_b_apply_dtm;
272
273 int m_datum_index;
274 double m_dtm_lat;
275 double m_dtm_lon;
276
277 wxRect cache_rect;
278 wxRect cache_rect_scaled;
279 bool cached_image_ok;
280 ScaleTypeEnum cache_scale_method;
281 double m_cached_scale_ppm;
282 wxRect m_last_vprect;
283
284 wxRect Rsrc; // Current chart source rectangle
285 double m_raster_scale_factor;
286
287 int nRefpoint;
288 Refpoint *pRefTable;
289
290 int nColorSize;
291 int *pline_table; // pointer to Line offset table
292
293 CachedLine *pLineCache;
294
295 wxInputStream *ifs_hdr;
296 wxInputStream *ifss_bitmap;
297 wxBufferedInputStream *ifs_bitmap;
298
299 wxString *pBitmapFilePath;
300
301 unsigned char *ifs_buf;
302 unsigned char *ifs_bufend;
303 int ifs_bufsize;
304 unsigned char *ifs_lp;
305 int ifs_file_offset;
306 int nFileOffsetDataStart;
307 int m_nLineOffset;
308
309 GeoRef cPoints;
310
311 double wpx[12], wpy[12], pwx[12], pwy[12]; // Embedded georef coefficients
312 int wpx_type, wpy_type, pwx_type, pwy_type;
313 int n_wpx, n_wpy, n_pwx, n_pwy;
314 bool bHaveEmbeddedGeoref;
315
316 opncpnPalette *pPalettes[N_BSB_COLORS];
317
318 BSB_Color_Capability m_mapped_color_index;
319
320 // Integer digital scale value above which bilinear scaling is not allowed,
321 // and subsampled scaling must be performed
322 int m_bilinear_limit;
323
324 bool bUseLineCache;
325
326 float m_LonMax;
327 float m_LonMin;
328 float m_LatMax;
329 float m_LatMin;
330
331 int *pPalette;
332 PaletteDir palette_direction;
333
334 bool bGeoErrorSent;
335
336 double m_ppm_avg; // Calculated true scale factor of the 1X chart,
337 // pixels per meter
338 OCPNRegion m_last_region;
339
340 int m_b_cdebug;
341
342 double m_proj_lat, m_proj_lon;
343
344 ViewPort m_vp_render_last;
345
346 wxCriticalSection m_critSect;
347 wxULongLong m_filesize;
348};
349
353class ChartKAP : public ChartBaseBSB {
354public:
355 // Methods
356 ChartKAP();
357 ~ChartKAP();
358
359 InitReturn Init(const wxString &name, ChartInitFlag init_flags);
360};
361
362// ----------------------------------------------------------------------------
363// ChartGEO
364// ----------------------------------------------------------------------------
365
366class ChartGEO : public ChartBaseBSB {
367public:
368 // Methods
369 ChartGEO();
370 ~ChartGEO();
371
372 InitReturn Init(const wxString &name, ChartInitFlag init_flags);
373};
374
375// ----------------------------------------------------------------------------
376// ChartPlugInWrapper
377// This class is a wrapper/interface to PlugIn charts(PlugInChartBase) as
378// defined in ocpn_plugin.h
379// ----------------------------------------------------------------------------
380
381class PlugInChartBase; // found in ocpn_plugin.h
382
390public:
392 ChartPlugInWrapper(const wxString &chart_class);
393 virtual ~ChartPlugInWrapper();
394
395 virtual wxString GetFileSearchMask(void);
396
397 virtual InitReturn Init(const wxString &name, ChartInitFlag init_flags);
398
399 // Accessors
400 virtual ThumbData *GetThumbData(int tnx, int tny, float lat, float lon);
401 virtual ThumbData *GetThumbData();
402 virtual bool UpdateThumbData(double lat, double lon);
403
404 double GetNormalScaleMin(double canvas_scale_factor, bool b_allow_overzoom);
405 double GetNormalScaleMax(double canvas_scale_factor, int canvas_width);
406
407 virtual bool GetChartExtent(Extent *pext);
408
409 virtual bool RenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
410 const OCPNRegion &Region);
411
412 virtual bool RenderRegionViewOnGL(const wxGLContext &glc,
413 const ViewPort &VPoint,
414 const OCPNRegion &RectRegion,
415 const LLRegion &Region);
416
417 virtual bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed);
418
419 virtual void GetValidCanvasRegion(const ViewPort &VPoint,
420 OCPNRegion *pValidRegion);
421
422 virtual void SetColorScheme(ColorScheme cs, bool bApplyImmediate);
423
424 virtual double GetNearestPreferredScalePPM(double target_scale_ppm);
425
426 virtual PlugInChartBase *GetPlugInChart(void) { return m_ppicb; }
427
428 virtual int GetCOVREntries();
429 virtual int GetCOVRTablePoints(int iTable);
430 virtual int GetCOVRTablenPoints(int iTable);
431 virtual float *GetCOVRTableHead(int iTable);
432
433 virtual int GetNoCOVREntries();
434 virtual int GetNoCOVRTablePoints(int iTable);
435 virtual int GetNoCOVRTablenPoints(int iTable);
436 virtual float *GetNoCOVRTableHead(int iTable);
437
438 // The following set of methods apply to BSB (i.e. Raster) type PlugIn
439 // charts only and need not be implemented if the ChartFamily is not
440 // CHART_FAMILY_RASTER
441 virtual void ComputeSourceRectangle(const ViewPort &vp, wxRect *pSourceRect);
442 virtual double GetRasterScaleFactor(const ViewPort &vp);
443 virtual bool GetChartBits(wxRect &source, unsigned char *pPix, int sub_samp);
444 virtual int GetSize_X();
445 virtual int GetSize_Y();
446 virtual void latlong_to_chartpix(double lat, double lon, double &pixx,
447 double &pixy);
448 virtual void chartpix_to_latlong(double pixx, double pixy, double *plat,
449 double *plon);
450
451 // Added for API V 1.14, with PlugInChartBaseExtended
452 virtual bool RenderRegionViewOnDCNoText(wxMemoryDC &dc,
453 const ViewPort &VPoint,
454 const OCPNRegion &Region);
455
456 virtual bool RenderRegionViewOnDCTextOnly(wxMemoryDC &dc,
457 const ViewPort &VPoint,
458 const OCPNRegion &Region);
459
460 virtual bool RenderRegionViewOnGLNoText(const wxGLContext &glc,
461 const ViewPort &VPoint,
462 const OCPNRegion &RectRegion,
463 const LLRegion &Region);
464
465 virtual bool RenderRegionViewOnGLTextOnly(const wxGLContext &glc,
466 const ViewPort &VPoint,
467 const OCPNRegion &RectRegion);
468
469 virtual void ClearPLIBTextList();
470
471private:
472 PlugInChartBase *m_ppicb;
473 wxObject *m_ppo;
474 wxCriticalSection m_critSect;
475 bool m_overlayENC;
476 wxMask *m_pMask;
477};
478
479#endif
General chart base definitions.
Charts database management
Base class for BSB (Maptech/NOS) format nautical charts.
Definition chartimg.h:128
virtual double GetNearestPreferredScalePPM(double target_scale_ppm)
Find the nearest preferred viewport scale (in pixels/meter) for this chart.
double GetClosestValidNaturalScalePPM(double target_scale, double scale_factor_min, double scale_factor_max)
Find closest valid scale that's a power of 2 multiple of chart's native scale.
Base class for all chart types.
Definition chartbase.h:125
Represents a KAP format chart, derived from ChartBaseBSB.
Definition chartimg.h:353
Wrapper class for plugin-based charts.
Definition chartimg.h:389
virtual double GetNearestPreferredScalePPM(double target_scale_ppm)
Find the nearest preferred viewport scale (in pixels/meter) for this chart.
A wrapper class for wxRegion with additional functionality.
Definition ocpn_region.h:37
Base class for implementing custom chart types in OpenCPN plugins.
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:56
OpenCPN Georef utility.
OpenCPN region handling.
Structure containing georeferencing information for transforming between geographic and projected/pix...
Definition georef.h:63
Geographic projection and coordinate transformations.