OpenCPN Partial API docs
Loading...
Searching...
No Matches
viewport.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2015 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 OCPNVIEWPORT_H_
25#define OCPNVIEWPORT_H_
26
27#include <wx/gdicmn.h>
28
29#include "bbox.h"
30#include "color_types.h"
31#include "LLRegion.h"
32#include "ocpn_region.h"
33
34extern ColorScheme global_color_scheme; // library dependency
35
36#if !defined(NAN)
37static const long long lNaN = 0xfff8000000000000;
38#define NAN (*(double *)&lNaN)
39#endif
40
41#define INVALID_COORD (-2147483647 - 1)
42
56class ViewPort {
57public:
58 ViewPort();
59
70 wxPoint GetPixFromLL(double lat, double lon);
80 void GetLLFromPix(const wxPoint &p, double *lat, double *lon) {
81 GetLLFromPix(wxPoint2DDouble(p), lat, lon);
82 }
90 void GetLLFromPix(const wxPoint2DDouble &p, double *lat, double *lon);
98 wxPoint2DDouble GetDoublePixFromLL(double lat, double lon);
99
100 LLRegion GetLLRegion(const OCPNRegion &region);
109 const LLRegion &llregion,
110 int chart_native_scale);
111
122 OCPNRegion GetVPRegionIntersect(const OCPNRegion &Region, int nPoints,
123 float *llpoints, int chart_native_scale,
124 wxPoint *ppoints);
131 wxRect GetVPRectIntersect(size_t n, float *llpoints);
132 ViewPort BuildExpandedVP(int width, int height);
133
163 void SetBoxes();
175 void SetPixelScale(double scale);
176
177 // Accessors
178 void Invalidate() { bValid = false; }
179 void Validate() { bValid = true; }
180 bool IsValid() const { return bValid; }
181
182 void SetRotationAngle(double angle_rad) { rotation = angle_rad; }
183 void SetProjectionType(int type) { m_projection_type = type; }
184
185 LLBBox &GetBBox() { return vpBBox; }
186
187 void SetBBoxDirect(const LLBBox &bbox) { vpBBox = bbox; }
188 void SetBBoxDirect(double latmin, double lonmin, double latmax,
189 double lonmax);
190
191 bool ContainsIDL();
192 void InvalidateTransformCache() { lat0_cache = NAN; }
193 void SetVPTransformMatrix();
194
195 // Generic
197 double clat;
199 double clon;
212 double skew;
214 double rotation;
216 double tilt;
217
221 double ref_scale;
222
234
235 bool b_quilt;
236 bool b_FullScreenQuilt;
237
238 int m_projection_type;
239 bool b_MercatorProjectionOverride;
240 wxRect rv_rect;
241
242 // #ifdef USE_ANDROID_GLES2
243 float vp_matrix_transform[16];
244 float norm_transform[16];
245 // #endif
246
247 bool operator==(const ViewPort &rhs) const {
248 return (clat == rhs.clat) && (clon == rhs.clon) &&
249 (view_scale_ppm == rhs.view_scale_ppm) && (skew == rhs.skew) &&
250 (rotation == rhs.rotation) && (tilt == rhs.tilt) &&
251 (chart_scale == rhs.chart_scale) && (ref_scale == rhs.ref_scale) &&
252 (pix_width == rhs.pix_width) && (pix_height == rhs.pix_height) &&
253 (b_quilt == rhs.b_quilt) &&
254 (b_FullScreenQuilt == rhs.b_FullScreenQuilt) &&
255 (m_projection_type == rhs.m_projection_type) &&
256 (b_MercatorProjectionOverride == rhs.b_MercatorProjectionOverride);
257 }
258
259private:
262 LLBBox vpBBox;
263
264 bool bValid; // This VP is valid
265
266 double lat0_cache, cache0, cache1;
267
269 double m_displayScale;
270};
271
272#endif
A wrapper class for wxRegion with additional functionality.
Definition ocpn_region.h:37
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:56
void SetBoxes()
Computes the bounding box coordinates for the current viewport.
Definition viewport.cpp:811
double view_scale_ppm
Requested view scale in physical pixels per meter (ppm), before applying projections.
Definition viewport.h:204
double ref_scale
The nominal scale of the "reference chart" for this view.
Definition viewport.h:221
int pix_height
Height of the viewport in physical pixels.
Definition viewport.h:233
double rotation
Rotation angle of the viewport in radians.
Definition viewport.h:214
void SetPixelScale(double scale)
Set the physical to logical pixel ratio for the display.
Definition viewport.cpp:121
wxRect GetVPRectIntersect(size_t n, float *llpoints)
Get the viewport rectangle intersecting with a set of lat/lon points.
Definition viewport.cpp:788
int pix_width
Width of the viewport in physical pixels.
Definition viewport.h:231
wxPoint2DDouble GetDoublePixFromLL(double lat, double lon)
Convert latitude and longitude on the ViewPort to physical pixel coordinates with double precision.
Definition viewport.cpp:133
double tilt
Tilt angle for perspective view in radians.
Definition viewport.h:216
double skew
Angular distortion (shear transform) applied to the viewport in radians.
Definition viewport.h:212
void GetLLFromPix(const wxPoint &p, double *lat, double *lon)
Convert physical pixel coordinates on the ViewPort to latitude and longitude.
Definition viewport.h:80
OCPNRegion GetVPRegionIntersect(const OCPNRegion &region, const LLRegion &llregion, int chart_native_scale)
Get the intersection of the viewport with a given region.
Definition viewport.cpp:409
double clon
Center longitude of the viewport in degrees.
Definition viewport.h:199
double clat
Center latitude of the viewport in degrees.
Definition viewport.h:197
wxPoint GetPixFromLL(double lat, double lon)
Convert latitude and longitude on the ViewPort to physical pixel coordinates.
Definition viewport.cpp:124
double chart_scale
Chart scale denominator (e.g., 50000 for a 1:50000 scale).
Definition viewport.h:219
OpenCPN region handling.