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