OpenCPN Partial API docs
Loading...
Searching...
No Matches
viewport.h
1/******************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: OpenCPN ViewPort
5 * Author: David Register
6 *
7 ***************************************************************************
8 * Copyright (C) 2015 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
30#ifndef __OCPNVIEWPORT_H__
31#define __OCPNVIEWPORT_H__
32
33#include "bbox.h"
34class OCPNRegion;
35class LLRegion;
36
37#if !defined(NAN)
38static const long long lNaN = 0xfff8000000000000;
39#define NAN (*(double *)&lNaN)
40#endif
41
42#if 0
43// ChartType constants
44typedef enum ChartTypeEnum
45{
46 CHART_TYPE_UNKNOWN = 0,
47 CHART_TYPE_DUMMY,
48 CHART_TYPE_DONTCARE,
49 CHART_TYPE_KAP,
50 CHART_TYPE_GEO,
51 CHART_TYPE_S57,
52 CHART_TYPE_CM93,
53 CHART_TYPE_CM93COMP,
54 CHART_TYPE_PLUGIN
55}_ChartTypeEnum;
56
57// ChartFamily constants
58typedef enum ChartFamilyEnum
59{
60 CHART_FAMILY_UNKNOWN = 0,
61 CHART_FAMILY_RASTER,
62 CHART_FAMILY_VECTOR,
63 CHART_FAMILY_DONTCARE
64}_ChartFamilyEnum;
65
66typedef enum ColorScheme
67{
68 GLOBAL_COLOR_SCHEME_RGB,
69 GLOBAL_COLOR_SCHEME_DAY,
70 GLOBAL_COLOR_SCHEME_DUSK,
71 GLOBAL_COLOR_SCHEME_NIGHT,
72 N_COLOR_SCHEMES
73}_ColorScheme;
74#endif
75
76#define INVALID_COORD (-2147483647 - 1)
77
78//----------------------------------------------------------------------------
79// ViewPort Definition
80//----------------------------------------------------------------------------
81class ViewPort {
82public:
83 ViewPort();
84
85 wxPoint GetPixFromLL(double lat, double lon);
86 void GetLLFromPix(const wxPoint &p, double *lat, double *lon) {
87 GetLLFromPix(wxPoint2DDouble(p), lat, lon);
88 }
89 void GetLLFromPix(const wxPoint2DDouble &p, double *lat, double *lon);
90 wxPoint2DDouble GetDoublePixFromLL(double lat, double lon);
91
92 LLRegion GetLLRegion(const OCPNRegion &region);
93 OCPNRegion GetVPRegionIntersect(const OCPNRegion &region,
94 const LLRegion &llregion,
95 int chart_native_scale);
96 OCPNRegion GetVPRegionIntersect(const OCPNRegion &Region, int nPoints,
97 float *llpoints, int chart_native_scale,
98 wxPoint *ppoints);
99 wxRect GetVPRectIntersect(size_t n, float *llpoints);
100 ViewPort BuildExpandedVP(int width, int height);
101
102 void SetBoxes(void);
103 void PixelScale(float factor);
104
105 // Accessors
106 void Invalidate() { bValid = false; }
107 void Validate() { bValid = true; }
108 bool IsValid() const { return bValid; }
109
110 void SetRotationAngle(double angle_rad) { rotation = angle_rad; }
111 void SetProjectionType(int type) { m_projection_type = type; }
112
113 LLBBox &GetBBox() { return vpBBox; }
114
115 void SetBBoxDirect(const LLBBox &bbox) { vpBBox = bbox; }
116 void SetBBoxDirect(double latmin, double lonmin, double latmax,
117 double lonmax);
118
119 void InvalidateTransformCache() { lat0_cache = NAN; }
120
121 // Generic
122 double clat; // center point
123 double clon;
124 double view_scale_ppm;
125 double skew;
126 double rotation;
127 double tilt; // For perspective view
128
129 double chart_scale; // conventional chart displayed scale
130 double
131 ref_scale; // the nominal scale of the "reference chart" for this view
132
133 int pix_width;
134 int pix_height;
135
136 bool b_quilt;
137 bool b_FullScreenQuilt;
138
139 int m_projection_type;
140 bool b_MercatorProjectionOverride;
141 wxRect rv_rect;
142
143//#ifdef USE_ANDROID_GLES2
144 float vp_matrix_transform[16];
145 float norm_transform[16];
146//#endif
147
148 bool operator==(const ViewPort& rhs) const
149 {
150 return (clat == rhs.clat)
151 && (clon == rhs.clon)
152 && (view_scale_ppm == rhs.view_scale_ppm)
153 && (skew == rhs.skew)
154 && (rotation == rhs.rotation)
155 && (tilt == rhs.tilt)
156 && (chart_scale == rhs.chart_scale)
157 && (ref_scale == rhs.ref_scale)
158 && (pix_width == rhs.pix_width)
159 && (pix_height == rhs.pix_height)
160 && (b_quilt == rhs.b_quilt)
161 && (b_FullScreenQuilt == rhs.b_FullScreenQuilt)
162 && (m_projection_type == rhs.m_projection_type)
163 && (b_MercatorProjectionOverride == rhs.b_MercatorProjectionOverride);
164 }
165private:
166 LLBBox vpBBox; // An un-skewed rectangular lat/lon bounding box
167 // which contains the entire vieport
168
169 bool bValid; // This VP is valid
170
171 double lat0_cache, cache0, cache1;
172};
173
174#endif