GL Studio C++ Runtime API
gls_map_view.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsMapView class.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2017 The DiSTI Corporation.<br>
7  11301 Corporate Blvd; Suite 100<br>
8  Orlando, Florida 32817<br>
9  USA<br>
10  <br>
11  All rights reserved.<br>
12 
13  This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36  The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38 
39 */
40 #ifndef INCLUDED_GLSMAPVIEW_H
41 #define INCLUDED_GLSMAPVIEW_H
42 
43 #include "group.h"
44 
45 #include "gls_map_util.h"
46 
47 //////////////////// Provides support for creating DLLs ////////////////////////
48 #if( defined( GLSGEN_EXPORT_GLSMAPVIEW ) || defined( GLSGEN_IMPORT_GLSMAPVIEW ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
49  && defined( _MSC_VER )
50 # if defined( GLSGEN_EXPORT_GLSMAPVIEW ) || defined( GLS_EXPORT_GENERATED )
51 # define GLSGEN_GLSMAPVIEW_EXPORT __declspec( dllexport )
52 # else
53 # define GLSGEN_GLSMAPVIEW_EXPORT __declspec( dllimport )
54 # endif
55 #else
56 # define GLSGEN_GLSMAPVIEW_EXPORT
57 #endif
58 ///////////////////////////////////////////////////////////////////////////////
59 
60 #define LIB_BASE_NAME "gls_map_toolkit"
61 #include "gls_auto_lib.h"
62 #undef LIB_BASE_NAME
63 
64 namespace disti
65 {
66 // SetValue enumerations
67 enum
68 {
69  GLS_GLSMAPVIEW_FIRST_VALUE = GLS_LAST_INITIALIZER + 1,
70 };
71 
72 enum ProjectionType
73 {
74  PROJECTION_TYPE_EQUIRECTANGULAR = 0,
75  PROJECTION_TYPE_MERCATOR,
76  PROJECTION_TYPE_TRANSVERSE_MERCATOR,
77  PROJECTION_TYPE_MAX,
78 };
79 
80 /** \brief The GlsMapView is a special group that controls the map view parameters.
81  * It contains all of the objects that are drawn into the map.
82  *
83  * A GLPolygon must be included as the first child under the GlsMapView.
84  * This defines a clipping area for the map display.
85  */
86 class GlsMapView : public Group
87 {
88 public:
89  DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
90  typedef Group _BaseClass;
91  typedef Group BaseClass;
92  friend class GlsMapViewEditor;
93 
94  /** Create a new GlsMapView.
95  * \param generateInstance Whether or not to generate an instance name
96  * for this inputdevice */
97  GLSGEN_GLSMAPVIEW_EXPORT GlsMapView( bool generateInstance = false );
98 
99  /** Destructs a GlsMapView object */
100  virtual GLSGEN_GLSMAPVIEW_EXPORT ~GlsMapView();
101 
102  static GLSGEN_GLSMAPVIEW_EXPORT DisplayObject* CreateInstance();
103 
104  //////////////////////////////////////////////////
105  // Overridden base class methods
106  //////////////////////////////////////////////////
107 
108  virtual GLSGEN_GLSMAPVIEW_EXPORT void SetAvailableAttributes( unsigned int value );
109  virtual GLSGEN_GLSMAPVIEW_EXPORT DisplayObject* CloneObject( bool generateNames = false );
110  virtual GLSGEN_GLSMAPVIEW_EXPORT void CopyProperties( DisplayObject* src );
111 
112  virtual GLSGEN_GLSMAPVIEW_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL );
113  virtual GLSGEN_GLSMAPVIEW_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array );
114 
115  virtual GLSGEN_GLSMAPVIEW_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler );
116  virtual GLSGEN_GLSMAPVIEW_EXPORT void Draw( void );
117 
118  virtual GLSGEN_GLSMAPVIEW_EXPORT DisplayObject* Pick3D( const Vector& winLoc,
119  const Vector& logicalCoords,
120  float scale,
121  const Vector& directionVector,
122  Vector& collisionWinLoc /*Returned*/,
123  const OpenGLMatrices& drawnMatrices );
124 
125  virtual GLSGEN_GLSMAPVIEW_EXPORT DisplayObject* handle( DisplayEvent* ev );
126 
127  virtual GLSGEN_GLSMAPVIEW_EXPORT void SetValue( int spec, va_list& args );
128 
129  //////////////////////////////////////////////////
130  // GlsMapView specific operations
131  //////////////////////////////////////////////////
132 
133  /** Selects the projection type for the map.
134  * Legacy behavior (unprojected / equirectangular / plate carree) is the default. */
135  GLSGEN_GLSMAPVIEW_EXPORT void SetProjectionType( ProjectionType value );
136  GLSGEN_GLSMAPVIEW_EXPORT ProjectionType GetProjectionType() const;
137 
138  /** Offset that is applied to the center of the map (in logical coordinates)
139  * This does not change the geographical location being displayed by the map,
140  * but rather moves the screen position that that map center is placed at.
141  * This is the point that the map rotates around when the ViewHeading changes. */
142  GLSGEN_GLSMAPVIEW_EXPORT void MapCenterOffset( const Vector& value );
143  Vector MapCenterOffset() { return _mapCenterOffset; }
144 
145  /** Set the geographical location that the map is viewing.
146  * \param value new geographic location for the map being viewed
147  */
148  GLSGEN_GLSMAPVIEW_EXPORT void ViewLocation( const GeoCoord& value );
149 
150  /** Get the geographical location that the map is viewing.
151  * \return GeoCoord current geographic location for the map being viewed
152  */
153  GeoCoord ViewLocation() { return _viewLocation; }
154 
155  /** Set the projection offset for this map.
156  * This does not change the geographical location being displayed by the map,
157  * but it does affect how each cell is projected.
158  * \param value the new offset to be used for projection */
159  GLSGEN_GLSMAPVIEW_EXPORT void SetProjectionOffset( const GeoCoord& value );
160 
161  /** Get the projection offset that the map is viewing.
162  * \return GeoCoord current projection offset for the map being viewed */
163  GeoCoord GetProjectionOffset() { return _projectionOffset; };
164 
165  /** Set the rotation of the map in degrees (true north).
166  * \param value desired map rotation
167  */
168  GLSGEN_GLSMAPVIEW_EXPORT void ViewHeading( const float& value );
169 
170  /** Get the rotation of the map in degrees (true north).
171  * \return float current rotation for the map being viewed
172  */
173  float ViewHeading() { return _viewHeading; }
174 
175  /** Set the height of the region that the map should display in degrees latitude.
176  * The width is determined from the height based on the aspect ratio of the view.
177  * Use this to control the the zoom level of the map
178  * Useful conversion factors:
179  * 1 degree latitude = 60 nautical miles = 111120 meters
180  */
181  GLSGEN_GLSMAPVIEW_EXPORT void ViewHeight( const double& value );
182  double ViewHeight() { return _viewHeight; }
183 
184  /** When true, the contents of the map will be clipped to
185  * draw only within the GlsMapView. You may want to disable this
186  * if you are using another method to clip/occlude the map. */
187  GLSGEN_GLSMAPVIEW_EXPORT void ClipMap( const bool& value );
188  bool ClipMap() { return _clipMapView; }
189 
190  /** \returns Pointer to the object that defines the plane of the map
191  * or NULL if the object is not found. */
193 
194  /** Return a GeoRect that encompasses the visible region.
195  * If an object is outside of the visible region, it will not be drawn.
196  */
197  const GeoRect& GetVisibleRegion() const
198  {
199  return _visibleRegion;
200  }
201 
202  /** Transform a lon/lat coordinate to the GlsMapView logical coordinates
203  * \param lon longitude in degrees
204  * \param lat latitude in degrees
205  * \param logical_out Pointer to a Vector to receive the transformed logical coordinate
206  */
207  GLSGEN_GLSMAPVIEW_EXPORT void LonLatToLogical( double lon, double lat, Vector* logical_out ) const;
208 
209  /** Transform a GeoCoord coordinate to the GlsMapView logical coordinates
210  * \param geo The GeoCoord to transform
211  * \param logical Pointer to a Vector to receive the transformed logical coordinate
212  */
213  void GeoCoordToLogical( const GeoCoord& geo, Vector* logical ) const
214  {
215  if( !_geoToLogicalMatricesValid )
216  {
218  }
219 
220  double lon, lat, alt;
221  geo.GetGeodetic( &lon, &lat, &alt );
222  LonLatToLogical( lon, lat, logical );
223  }
224 
225  /** Determine the GeoCoord for a given logical coordinate.
226  * \param geo Vector containing the logical coordinate to transform
227  * \param logical Pointer to a GeoCoord to receive the transformed coordinate
228  */
229  GLSGEN_GLSMAPVIEW_EXPORT void LogicalToGeoCoord( const Vector& logical, GeoCoord* geo ) const;
230 
231  /** \returns The matrix used by the GlsMapView to transform
232  * lon/lat coordinates to logical coordinates. This matrix may be used
233  * to transform Vectors or applied to the OpenGL modelview matrix to
234  * allow drawing by passing lon/lat coordinates directly to OpenGL.
235  * This matrix is recalculated whenever the GlsMapView is drawn. */
237  {
238  if( !_geoToLogicalMatricesValid )
239  {
241  }
242  return _geoToLogicalMatrix;
243  }
244 
245  /** Get the height in logical units of the background object that defines the plane of the map
246  * \return height in logical units of the background object that defines the plane of the map
247  */
248  double ViewLogicalHeight( void ) const
249  {
250  if( !_geoToLogicalMatricesValid )
251  {
253  }
254  return _viewLogicalHeight;
255  }
256 
257  /** This method not normally called by user.
258  * It may change in future versions of GlsMapView. */
259  void CalcGeoToLogicalMatrix() const;
260 
261  /** This method not normally called by user.
262  * It may change in future versions of GlsMapView. */
263  void CalcVisibleRegion() const;
264 
265 protected:
266  // GlsMapView attributes
267  ProjectionType _projectionType;
268  GeoCoord _projectionOffset;
269 
270  Vector _mapCenterOffset;
271  GeoCoord _viewLocation;
272  float _viewHeading;
273  double _viewHeight;
274  double _viewLogicalHeight;
275 
276  bool _clipMapView;
277 
278  // Internal attributes and utility methods
279  bool _geoToLogicalMatricesValid;
280  GlsMatrixAffineD _geoToLogicalMatrix;
281  GlsMatrixAffineD _logicalToGeoMatrix;
282 
283  GeoRect _visibleRegion;
284 
285  void VisibleRegionCheckVert( const Vector& v, GeoRect& rect ) const;
286 };
287 
288 /** Utility method to traverse up the object heirarchy
289  * and find the first GlsMapView parent for a given object. */
291 {
292  while( obj != NULL )
293  {
294  obj = obj->ParentGroup();
295 
296  if( dynamic_cast<GlsMapView*>( obj ) )
297  {
298  return (GlsMapView*)obj;
299  }
300  }
301 
302  return NULL;
303 }
304 
305 } // namespace disti
306 
307 #endif
Definition: cull.h:49
virtual DisplayObject * handle(DisplayEvent *ev)
void CalcVisibleRegion() const
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:436
virtual void SetValue(int spec, va_list &args)
void GetGeodetic(Vector *lonLatAlt, const EllipsoidParams &ellipsoid=GeoCoord::WGS84) const
Definition: gls_map_util.h:190
const GlsMatrixAffineD & GetGeoToLogicalMatrix() const
Definition: gls_map_view.h:236
Definition: dynamic_array.h:66
const GeoRect & GetVisibleRegion() const
Definition: gls_map_view.h:197
The disti::Group class. Implements groups of objects.
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:471
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
Definition: gls_map_util.h:414
void LogicalToGeoCoord(const Vector &logical, GeoCoord *geo) const
Definition: display.h:98
The GlsMapView is a special group that controls the map view parameters. It contains all of the objec...
Definition: gls_map_view.h:86
double ViewLogicalHeight(void) const
Definition: gls_map_view.h:248
Definition: gls_map_util.h:67
void SetProjectionOffset(const GeoCoord &value)
void LonLatToLogical(double lon, double lat, Vector *logical_out) const
Utility classes for GL Studio Map toolkit.
DisplayObject * FirstObject()
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler)
virtual ~GlsMapView()
virtual void ParentGroup(Group *group)
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
GeoCoord GetProjectionOffset()
Definition: gls_map_view.h:163
GlsMapView(bool generateInstance=false)
float ViewHeading()
Definition: gls_map_view.h:173
void GeoCoordToLogical(const GeoCoord &geo, Vector *logical) const
Definition: gls_map_view.h:213
virtual void Draw(void)
Definition: events.h:112
GlsMapView * GetParentMapView(DisplayObject *obj)
Definition: gls_map_view.h:290
void SetProjectionType(ProjectionType value)
GeoCoord ViewLocation()
Definition: gls_map_view.h:153
The gls_auto_lib.
Definition: group.h:52
Definition: vertex.h:84
void MapCenterOffset(const Vector &value)
virtual DisplayObject * CloneObject(bool generateNames=false)
virtual DisplayObject * Pick3D(const Vector &winLoc, const Vector &logicalCoords, float scale, const Vector &directionVector, Vector &collisionWinLoc, const OpenGLMatrices &drawnMatrices)
DisplayObject * GetBackgroundObject()
Definition: gls_map_view.h:192
void CalcGeoToLogicalMatrix() const
virtual void CopyProperties(DisplayObject *src)
virtual void SetAvailableAttributes(unsigned int value)
Definition: bmpimage.h:46