OpenCPN Partial API docs
Loading...
Searching...
No Matches
ViewPort Class Reference

ViewPort - Core geographic projection and coordinate transformation engine. More...

#include <viewport.h>

Public Member Functions

wxPoint GetPixFromLL (double lat, double lon)
 Convert latitude and longitude on the ViewPort to physical pixel coordinates.
 
void GetLLFromPix (const wxPoint &p, double *lat, double *lon)
 Convert physical pixel coordinates on the ViewPort to latitude and longitude.
 
void GetLLFromPix (const wxPoint2DDouble &p, double *lat, double *lon)
 Convert physical pixel coordinates on the ViewPort to latitude and longitude using double precision.
 
wxPoint2DDouble GetDoublePixFromLL (double lat, double lon)
 Convert latitude and longitude on the ViewPort to physical pixel coordinates with double precision.
 
LLRegion GetLLRegion (const OCPNRegion &region)
 
OCPNRegion GetVPRegionIntersect (const OCPNRegion &region, const LLRegion &llregion, int chart_native_scale)
 Get the intersection of the viewport with a given region.
 
OCPNRegion GetVPRegionIntersect (const OCPNRegion &Region, int nPoints, float *llpoints, int chart_native_scale, wxPoint *ppoints)
 Get the intersection of the viewport with a polygon defined by lat/lon points.
 
wxRect GetVPRectIntersect (size_t n, float *llpoints)
 Get the viewport rectangle intersecting with a set of lat/lon points.
 
ViewPort BuildExpandedVP (int width, int height)
 
void SetBoxes (void)
 Computes the bounding box coordinates for the current viewport.
 
void SetPixelScale (double scale)
 Set the physical to logical pixel ratio for the display.
 
void Invalidate ()
 
void Validate ()
 
bool IsValid () const
 
void SetRotationAngle (double angle_rad)
 
void SetProjectionType (int type)
 
LLBBox & GetBBox ()
 
void SetBBoxDirect (const LLBBox &bbox)
 
void SetBBoxDirect (double latmin, double lonmin, double latmax, double lonmax)
 
bool ContainsIDL ()
 
void InvalidateTransformCache ()
 
void SetVPTransformMatrix ()
 
bool operator== (const ViewPort &rhs) const
 

Public Attributes

double clat
 Center latitude of the viewport in degrees.
 
double clon
 Center longitude of the viewport in degrees.
 
double view_scale_ppm
 Requested view scale in physical pixels per meter (ppm), before applying projections.
 
double skew
 Angular distortion (shear transform) applied to the viewport in radians.
 
double rotation
 Rotation angle of the viewport in radians.
 
double tilt
 Tilt angle for perspective view in radians.
 
double chart_scale
 Chart scale denominator (e.g., 50000 for a 1:50000 scale).
 
double ref_scale
 The nominal scale of the "reference chart" for this view.
 
int pix_width
 Width of the viewport in physical pixels.
 
int pix_height
 Height of the viewport in physical pixels.
 
bool b_quilt
 
bool b_FullScreenQuilt
 
int m_projection_type
 
bool b_MercatorProjectionOverride
 
wxRect rv_rect
 
float vp_matrix_transform [16]
 
float norm_transform [16]
 

Detailed Description

ViewPort - Core geographic projection and coordinate transformation engine.

Represents the fundamental viewing parameters and coordinate transformations for chart display. This class serves as the mathematical foundation for mapping between geographic coordinates (latitude/longitude) and screen coordinates (pixels). It encapsulates all parameters that define how a chart section is viewed, including position, scale, rotation, and projection.

ViewPort is designed to be a relatively lightweight, data-focused class that handles the complex mathematical operations needed for accurate chart rendering without direct dependencies on UI components.

Definition at line 81 of file viewport.h.

Constructor & Destructor Documentation

◆ ViewPort()

ViewPort::ViewPort ( )

Definition at line 119 of file viewport.cpp.

Member Function Documentation

◆ BuildExpandedVP()

ViewPort ViewPort::BuildExpandedVP ( int  width,
int  height 
)

Definition at line 977 of file viewport.cpp.

◆ ContainsIDL()

bool ViewPort::ContainsIDL ( )

Definition at line 970 of file viewport.cpp.

◆ GetBBox()

LLBBox & ViewPort::GetBBox ( )
inline

Definition at line 210 of file viewport.h.

◆ GetDoublePixFromLL()

wxPoint2DDouble ViewPort::GetDoublePixFromLL ( double  lat,
double  lon 
)

Convert latitude and longitude on the ViewPort to physical pixel coordinates with double precision.

Parameters
latLatitude in degrees.
lonLongitude in degrees.
Returns
wxPoint2DDouble Physical pixel coordinates.

Definition at line 145 of file viewport.cpp.

◆ GetLLFromPix() [1/2]

void ViewPort::GetLLFromPix ( const wxPoint &  p,
double *  lat,
double *  lon 
)
inline

Convert physical pixel coordinates on the ViewPort to latitude and longitude.

Parameters
pPhysical pixel coordinates.
latPointer to store resulting latitude.
lonPointer to store resulting longitude.
See also
ChartCanvas::GetCanvasPixPoint() for the canvas-level implementation.

Definition at line 105 of file viewport.h.

◆ GetLLFromPix() [2/2]

void ViewPort::GetLLFromPix ( const wxPoint2DDouble &  p,
double *  lat,
double *  lon 
)

Convert physical pixel coordinates on the ViewPort to latitude and longitude using double precision.

Parameters
pPhysical pixel coordinates as wxPoint2DDouble.
latPointer to store resulting latitude.
lonPointer to store resulting longitude.

Definition at line 268 of file viewport.cpp.

◆ GetLLRegion()

LLRegion ViewPort::GetLLRegion ( const OCPNRegion region)

Definition at line 345 of file viewport.cpp.

◆ GetPixFromLL()

wxPoint ViewPort::GetPixFromLL ( double  lat,
double  lon 
)

Convert latitude and longitude on the ViewPort to physical pixel coordinates.

Parameters
latLatitude in degrees.
lonLongitude in degrees.
Returns
wxPoint Pixel coordinates.
See also
ChartCanvas::GetCanvasPointPix() for the canvas-level implementation.

Definition at line 136 of file viewport.cpp.

◆ GetVPRectIntersect()

wxRect ViewPort::GetVPRectIntersect ( size_t  n,
float *  llpoints 
)

Get the viewport rectangle intersecting with a set of lat/lon points.

Parameters
nNumber of points
llpointsArray of lat/lon points
Returns
wxRect Intersecting rectangle

Definition at line 800 of file viewport.cpp.

◆ GetVPRegionIntersect() [1/2]

OCPNRegion ViewPort::GetVPRegionIntersect ( const OCPNRegion region,
const LLRegion &  llregion,
int  chart_native_scale 
)

Get the intersection of the viewport with a given region.

Parameters
regionOCPNRegion to intersect with
llregionLLRegion to use for the intersection
chart_native_scaleNative scale of the chart
Returns
OCPNRegion Resulting intersected region

Definition at line 421 of file viewport.cpp.

◆ GetVPRegionIntersect() [2/2]

OCPNRegion ViewPort::GetVPRegionIntersect ( const OCPNRegion Region,
int  nPoints,
float *  llpoints,
int  chart_native_scale,
wxPoint *  ppoints 
)

Get the intersection of the viewport with a polygon defined by lat/lon points.

Parameters
RegionOCPNRegion to intersect with
nPointsNumber of points in the polygon
llpointsArray of lat/lon points defining the polygon
chart_native_scaleNative scale of the chart
ppointsArray to store resulting pixel coordinates
Returns
OCPNRegion Resulting intersected region

Definition at line 482 of file viewport.cpp.

◆ Invalidate()

void ViewPort::Invalidate ( )
inline

Definition at line 203 of file viewport.h.

◆ InvalidateTransformCache()

void ViewPort::InvalidateTransformCache ( )
inline

Definition at line 217 of file viewport.h.

◆ IsValid()

bool ViewPort::IsValid ( ) const
inline

Definition at line 205 of file viewport.h.

◆ operator==()

bool ViewPort::operator== ( const ViewPort rhs) const
inline

Definition at line 272 of file viewport.h.

◆ SetBBoxDirect() [1/2]

void ViewPort::SetBBoxDirect ( const LLBBox &  bbox)
inline

Definition at line 212 of file viewport.h.

◆ SetBBoxDirect() [2/2]

void ViewPort::SetBBoxDirect ( double  latmin,
double  lonmin,
double  latmax,
double  lonmax 
)

Definition at line 966 of file viewport.cpp.

◆ SetBoxes()

void ViewPort::SetBoxes ( void  )

Computes the bounding box coordinates for the current viewport.

This function is responsible for determining the lat/lon boundaries of the current viewport, which are used for various purposes including plugin rendering.

The function calculates a larger "virtual" pixel window size when rotation is applied to ensure that enough chart data is fetched to fill the rotated screen. It then computes the viewport lat/lon reference points based on screen coordinates.

Different algorithms are used depending on the projection type (POLAR, ORTHOGRAPHIC, STEREOGRAPHIC, GNOMONIC, MERCATOR, EQUIRECTANGULAR).

Edge cases are handled such as:

  • IDL (International Date Line) crossings
  • Poles being visible on screen
  • Non-rectangular mappings between screen space and geographical coordinates

The computed bounding box is stored in vpBBox and is used by various parts of the program to determine which chart features should be rendered and which are outside the visible area.

Note
When rotation or skew is applied, the function creates a larger rectangle that encompasses the rotated viewport, which can lead to data being fetched and rendered for areas that may be just outside the visible part of the screen.

Definition at line 823 of file viewport.cpp.

◆ SetPixelScale()

void ViewPort::SetPixelScale ( double  scale)

Set the physical to logical pixel ratio for the display.

On standard displays, one logical pixel equals one physical pixel, so this value is 1.0. On high-DPI/Retina displays, one logical pixel may equal multiple physical pixels:

  • MacBook Pro Retina: 2.0 (2x2 physical pixels per logical pixel)
  • Other HiDPI displays: May be 1.5, 1.75, etc.
Parameters
scaleThe ratio of physical pixels to logical pixels.

Definition at line 133 of file viewport.cpp.

◆ SetProjectionType()

void ViewPort::SetProjectionType ( int  type)
inline

Definition at line 208 of file viewport.h.

◆ SetRotationAngle()

void ViewPort::SetRotationAngle ( double  angle_rad)
inline

Definition at line 207 of file viewport.h.

◆ SetVPTransformMatrix()

void ViewPort::SetVPTransformMatrix ( )

Definition at line 987 of file viewport.cpp.

◆ Validate()

void ViewPort::Validate ( )
inline

Definition at line 204 of file viewport.h.

Member Data Documentation

◆ b_FullScreenQuilt

bool ViewPort::b_FullScreenQuilt

Definition at line 261 of file viewport.h.

◆ b_MercatorProjectionOverride

bool ViewPort::b_MercatorProjectionOverride

Definition at line 264 of file viewport.h.

◆ b_quilt

bool ViewPort::b_quilt

Definition at line 260 of file viewport.h.

◆ chart_scale

double ViewPort::chart_scale

Chart scale denominator (e.g., 50000 for a 1:50000 scale).

Definition at line 244 of file viewport.h.

◆ clat

double ViewPort::clat

Center latitude of the viewport in degrees.

Definition at line 222 of file viewport.h.

◆ clon

double ViewPort::clon

Center longitude of the viewport in degrees.

Definition at line 224 of file viewport.h.

◆ m_projection_type

int ViewPort::m_projection_type

Definition at line 263 of file viewport.h.

◆ norm_transform

float ViewPort::norm_transform[16]

Definition at line 269 of file viewport.h.

◆ pix_height

int ViewPort::pix_height

Height of the viewport in physical pixels.

Definition at line 258 of file viewport.h.

◆ pix_width

int ViewPort::pix_width

Width of the viewport in physical pixels.

This may be larger than the actual screen width if the viewport is expanded for operations like text rendering or to accommodate rotation.

See also
BuildExpandedVP() for how this is modified for text rendering

Definition at line 256 of file viewport.h.

◆ ref_scale

double ViewPort::ref_scale

The nominal scale of the "reference chart" for this view.

Definition at line 246 of file viewport.h.

◆ rotation

double ViewPort::rotation

Rotation angle of the viewport in radians.

Definition at line 239 of file viewport.h.

◆ rv_rect

wxRect ViewPort::rv_rect

Definition at line 265 of file viewport.h.

◆ skew

double ViewPort::skew

Angular distortion (shear transform) applied to the viewport in radians.

The skew parameter represents a shear transformation applied to the viewport, which maintains parallel lines while changing their angles relative to the axes.

Definition at line 237 of file viewport.h.

◆ tilt

double ViewPort::tilt

Tilt angle for perspective view in radians.

Definition at line 241 of file viewport.h.

◆ view_scale_ppm

double ViewPort::view_scale_ppm

Requested view scale in physical pixels per meter (ppm), before applying projections.

Definition at line 229 of file viewport.h.

◆ vp_matrix_transform

float ViewPort::vp_matrix_transform[16]

Definition at line 268 of file viewport.h.


The documentation for this class was generated from the following files: