OpenCPN Partial API docs
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"
34 class OCPNRegion;
35 class LLRegion;
36 
37 #if !defined(NAN)
38 static const long long lNaN = 0xfff8000000000000;
39 #define NAN (*(double *)&lNaN)
40 #endif
41 
42 #if 0
43 // ChartType constants
44 typedef 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
58 typedef enum ChartFamilyEnum
59 {
60  CHART_FAMILY_UNKNOWN = 0,
61  CHART_FAMILY_RASTER,
62  CHART_FAMILY_VECTOR,
63  CHART_FAMILY_DONTCARE
64 }_ChartFamilyEnum;
65 
66 typedef 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 //----------------------------------------------------------------------------
81 class ViewPort {
82 public:
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  bool ContainsIDL();
120  void InvalidateTransformCache() { lat0_cache = NAN; }
121  void SetVPTransformMatrix();
122 
123  // Generic
124  double clat; // center point
125  double clon;
126  double view_scale_ppm;
127  double skew;
128  double rotation;
129  double tilt; // For perspective view
130 
131  double chart_scale; // conventional chart displayed scale
132  double
133  ref_scale; // the nominal scale of the "reference chart" for this view
134 
135  int pix_width;
136  int pix_height;
137 
138  bool b_quilt;
139  bool b_FullScreenQuilt;
140 
141  int m_projection_type;
142  bool b_MercatorProjectionOverride;
143  wxRect rv_rect;
144 
145 //#ifdef USE_ANDROID_GLES2
146  float vp_matrix_transform[16];
147  float norm_transform[16];
148 //#endif
149 
150  bool operator==(const ViewPort& rhs) const
151  {
152  return (clat == rhs.clat)
153  && (clon == rhs.clon)
154  && (view_scale_ppm == rhs.view_scale_ppm)
155  && (skew == rhs.skew)
156  && (rotation == rhs.rotation)
157  && (tilt == rhs.tilt)
158  && (chart_scale == rhs.chart_scale)
159  && (ref_scale == rhs.ref_scale)
160  && (pix_width == rhs.pix_width)
161  && (pix_height == rhs.pix_height)
162  && (b_quilt == rhs.b_quilt)
163  && (b_FullScreenQuilt == rhs.b_FullScreenQuilt)
164  && (m_projection_type == rhs.m_projection_type)
165  && (b_MercatorProjectionOverride == rhs.b_MercatorProjectionOverride);
166  }
167 private:
168  LLBBox vpBBox; // An un-skewed rectangular lat/lon bounding box
169  // which contains the entire vieport
170 
171  bool bValid; // This VP is valid
172 
173  double lat0_cache, cache0, cache1;
174 };
175 
176 #endif