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