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