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 "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};
103
105public:
108
109 int *FwdPalette;
110 int *RevPalette;
111 int nFwd;
112 int nRev;
113};
114
115// ----------------------------------------------------------------------------
116// ChartBaseBSB
117// ----------------------------------------------------------------------------
118
119class ChartBaseBSB : public ChartBase {
120public:
121 // Public methods
122
123 ChartBaseBSB();
124 virtual ~ChartBaseBSB();
125 void FreeLineCacheRows(int start = 0, int end = -1);
126 bool HaveLineCacheRow(int row);
127
128 // Accessors
129 virtual ThumbData *GetThumbData(int tnx, int tny, float lat, float lon);
130 virtual ThumbData *GetThumbData() { return pThumbData; }
131 virtual bool UpdateThumbData(double lat, double lon);
132
133 int GetNativeScale() { return m_Chart_Scale; }
134 double GetNormalScaleMin(double canvas_scale_factor, bool b_allow_overzoom);
135 double GetNormalScaleMax(double canvas_scale_factor, int canvas_width);
136
137 virtual InitReturn Init(const wxString &name, ChartInitFlag init_flags);
138
139 virtual int latlong_to_pix_vp(double lat, double lon, double &pixx,
140 double &pixy, ViewPort &vp);
141 virtual int vp_pix_to_latlong(ViewPort &vp, double pixx, double pixy,
142 double *lat, double *lon);
143
144 bool RenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
145 const OCPNRegion &Region);
146
147 virtual bool RenderRegionViewOnGL(const wxGLContext &glc,
148 const ViewPort &VPoint,
149 const OCPNRegion &RectRegion,
150 const LLRegion &Region);
151
152 virtual bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed);
153 virtual double GetNearestPreferredScalePPM(double target_scale_ppm);
154
155 virtual void GetValidCanvasRegion(const ViewPort &VPoint,
156 OCPNRegion *pValidRegion);
157 virtual LLRegion GetValidRegion();
158
159 virtual bool GetChartExtent(Extent *pext);
160
161 void SetColorScheme(ColorScheme cs, bool bApplyImmediate);
162
163 wxImage *GetImage();
164
165 void SetVPRasterParms(const ViewPort &vpt);
166
167 virtual void ComputeSourceRectangle(const ViewPort &vp, wxRect *pSourceRect);
168 virtual double GetRasterScaleFactor(const ViewPort &vp);
169 virtual bool GetChartBits(wxRect &source, unsigned char *pPix, int sub_samp);
170 virtual int GetSize_X() { return Size_X; }
171 virtual int GetSize_Y() { return Size_Y; }
172
173 virtual void latlong_to_chartpix(double lat, double lon, double &pixx,
174 double &pixy);
175 virtual void chartpix_to_latlong(double pixx, double pixy, double *plat,
176 double *plon);
177
178 double GetPPM() { return m_ppm_avg; }
179
180protected:
181 // Methods
182
183 wxRect GetSourceRect() { return Rsrc; }
184
185 virtual bool GetAndScaleData(unsigned char *ppn, size_t data_size,
186 wxRect &source, int source_stride, wxRect &dest,
187 int dest_stride, double scale_factor,
188 ScaleTypeEnum scale_type);
189 bool RenderViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint);
190
191 bool IsCacheValid() { return cached_image_ok; }
192 void InvalidateCache() { cached_image_ok = 0; }
193 bool IsRenderCacheable(wxRect &source, wxRect &dest);
194
195 void CreatePaletteEntry(char *buffer, int palette_index);
196 PaletteDir GetPaletteDir(void);
197 int *GetPalettePtr(BSB_Color_Capability);
198
199 double GetClosestValidNaturalScalePPM(double target_scale,
200 double scale_factor_min,
201 double scale_factor_max);
202
203 virtual void InvalidateLineCache();
204 virtual bool CreateLineIndex(void);
205
206 virtual wxBitmap *CreateThumbnail(int tnx, int tny, ColorScheme cs);
207 virtual int BSBGetScanline(unsigned char *pLineBuf, int y, int xs, int xl,
208 int sub_samp);
209
210 bool GetViewUsingCache(wxRect &source, wxRect &dest, const OCPNRegion &Region,
211 ScaleTypeEnum scale_type);
212 bool GetView(wxRect &source, wxRect &dest, ScaleTypeEnum scale_type);
213
214 virtual int BSBScanScanline(wxInputStream *pinStream);
215 virtual int ReadBSBHdrLine(wxInputStream *, char *, int);
216 virtual int AnalyzeRefpoints(bool b_testSolution = true);
217 virtual bool AnalyzeSkew(void);
218
219 virtual bool SetMinMax(void);
220
221 InitReturn PreInit(const wxString &name, ChartInitFlag init_flags,
222 ColorScheme cs);
223 InitReturn PostInit(void);
224
225 double AdjustLongitude(double lon);
226
227 // Protected Data
228 PixelCache *pPixCache;
229
230 int Size_X; // Chart native pixel dimensions
231 int Size_Y;
232 int m_Chart_DU;
233 double m_cph;
234 double m_proj_parameter; // Mercator: Projection Latitude
235 // Transverse Mercator: Central Meridian
236 double m_dx; // Pixel scale factors, from KAP header
237 double m_dy;
238
239 wxString m_bsb_ver;
240 bool m_b_SHOM;
241 bool m_b_apply_dtm;
242
243 int m_datum_index;
244 double m_dtm_lat;
245 double m_dtm_lon;
246
247 wxRect cache_rect;
248 wxRect cache_rect_scaled;
249 bool cached_image_ok;
250 ScaleTypeEnum cache_scale_method;
251 double m_cached_scale_ppm;
252 wxRect m_last_vprect;
253
254 wxRect Rsrc; // Current chart source rectangle
255 double m_raster_scale_factor;
256
257 int nRefpoint;
258 Refpoint *pRefTable;
259
260 int nColorSize;
261 int *pline_table; // pointer to Line offset table
262
263 CachedLine *pLineCache;
264
265 wxInputStream *ifs_hdr;
266 wxInputStream *ifss_bitmap;
267 wxBufferedInputStream *ifs_bitmap;
268
269 wxString *pBitmapFilePath;
270
271 unsigned char *ifs_buf;
272 unsigned char *ifs_bufend;
273 int ifs_bufsize;
274 unsigned char *ifs_lp;
275 int ifs_file_offset;
276 int nFileOffsetDataStart;
277 int m_nLineOffset;
278
279 GeoRef cPoints;
280
281 double wpx[12], wpy[12], pwx[12], pwy[12]; // Embedded georef coefficients
282 int wpx_type, wpy_type, pwx_type, pwy_type;
283 int n_wpx, n_wpy, n_pwx, n_pwy;
284 bool bHaveEmbeddedGeoref;
285
286 opncpnPalette *pPalettes[N_BSB_COLORS];
287
288 BSB_Color_Capability m_mapped_color_index;
289
290 // Integer digital scale value above which bilinear scaling is not allowed,
291 // and subsampled scaling must be performed
292 int m_bilinear_limit;
293
294 bool bUseLineCache;
295
296 float m_LonMax;
297 float m_LonMin;
298 float m_LatMax;
299 float m_LatMin;
300
301 int *pPalette;
302 PaletteDir palette_direction;
303
304 bool bGeoErrorSent;
305
306 double m_ppm_avg; // Calculated true scale factor of the 1X chart,
307 // pixels per meter
308 OCPNRegion m_last_region;
309
310 int m_b_cdebug;
311
312 double m_proj_lat, m_proj_lon;
313
314 ViewPort m_vp_render_last;
315
316 wxCriticalSection m_critSect;
317 wxULongLong m_filesize;
318};
319
320// ----------------------------------------------------------------------------
321// ChartKAP
322// ----------------------------------------------------------------------------
323
324class ChartKAP : public ChartBaseBSB {
325public:
326 // Methods
327 ChartKAP();
328 ~ChartKAP();
329
330 InitReturn Init(const wxString &name, ChartInitFlag init_flags);
331};
332
333// ----------------------------------------------------------------------------
334// ChartGEO
335// ----------------------------------------------------------------------------
336
337class ChartGEO : public ChartBaseBSB {
338public:
339 // Methods
340 ChartGEO();
341 ~ChartGEO();
342
343 InitReturn Init(const wxString &name, ChartInitFlag init_flags);
344};
345
346// ----------------------------------------------------------------------------
347// ChartPlugInWrapper
348// This class is a wrapper/interface to PlugIn charts(PlugInChartBase) as
349// defined in ocpn_plugin.h
350// ----------------------------------------------------------------------------
351
352class PlugInChartBase; // found in ocpn_plugin.h
353
355public:
357 ChartPlugInWrapper(const wxString &chart_class);
358 virtual ~ChartPlugInWrapper();
359
360 virtual wxString GetFileSearchMask(void);
361
362 virtual InitReturn Init(const wxString &name, ChartInitFlag init_flags);
363
364 // Accessors
365 virtual ThumbData *GetThumbData(int tnx, int tny, float lat, float lon);
366 virtual ThumbData *GetThumbData();
367 virtual bool UpdateThumbData(double lat, double lon);
368
369 double GetNormalScaleMin(double canvas_scale_factor, bool b_allow_overzoom);
370 double GetNormalScaleMax(double canvas_scale_factor, int canvas_width);
371
372 virtual bool GetChartExtent(Extent *pext);
373
374 virtual bool RenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
375 const OCPNRegion &Region);
376
377 virtual bool RenderRegionViewOnGL(const wxGLContext &glc,
378 const ViewPort &VPoint,
379 const OCPNRegion &RectRegion,
380 const LLRegion &Region);
381
382 virtual bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed);
383
384 virtual void GetValidCanvasRegion(const ViewPort &VPoint,
385 OCPNRegion *pValidRegion);
386
387 virtual void SetColorScheme(ColorScheme cs, bool bApplyImmediate);
388
389 virtual double GetNearestPreferredScalePPM(double target_scale_ppm);
390
391 virtual PlugInChartBase *GetPlugInChart(void) { return m_ppicb; }
392
393 virtual int GetCOVREntries();
394 virtual int GetCOVRTablePoints(int iTable);
395 virtual int GetCOVRTablenPoints(int iTable);
396 virtual float *GetCOVRTableHead(int iTable);
397
398 virtual int GetNoCOVREntries();
399 virtual int GetNoCOVRTablePoints(int iTable);
400 virtual int GetNoCOVRTablenPoints(int iTable);
401 virtual float *GetNoCOVRTableHead(int iTable);
402
403 // The following set of methods apply to BSB (i.e. Raster) type PlugIn
404 // charts only and need not be implemented if the ChartFamily is not
405 // CHART_FAMILY_RASTER
406 virtual void ComputeSourceRectangle(const ViewPort &vp, wxRect *pSourceRect);
407 virtual double GetRasterScaleFactor(const ViewPort &vp);
408 virtual bool GetChartBits(wxRect &source, unsigned char *pPix, int sub_samp);
409 virtual int GetSize_X();
410 virtual int GetSize_Y();
411 virtual void latlong_to_chartpix(double lat, double lon, double &pixx,
412 double &pixy);
413 virtual void chartpix_to_latlong(double pixx, double pixy, double *plat,
414 double *plon);
415
416 // Added for API V 1.14, with PlugInChartBaseExtended
417 virtual bool RenderRegionViewOnDCNoText(wxMemoryDC &dc,
418 const ViewPort &VPoint,
419 const OCPNRegion &Region);
420
421 virtual bool RenderRegionViewOnDCTextOnly(wxMemoryDC &dc,
422 const ViewPort &VPoint,
423 const OCPNRegion &Region);
424
425 virtual bool RenderRegionViewOnGLNoText(const wxGLContext &glc,
426 const ViewPort &VPoint,
427 const OCPNRegion &RectRegion,
428 const LLRegion &Region);
429
430 virtual bool RenderRegionViewOnGLTextOnly(const wxGLContext &glc,
431 const ViewPort &VPoint,
432 const OCPNRegion &RectRegion);
433
434 virtual void ClearPLIBTextList();
435
436private:
437 PlugInChartBase *m_ppicb;
438 wxObject *m_ppo;
439 wxCriticalSection m_critSect;
440 bool m_overlayENC;
441 wxMask *m_pMask;
442};
443
444#endif
Definition: georef.h:55