OpenCPN Partial API docs
|
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 ®ion) |
OCPNRegion | GetVPRegionIntersect (const OCPNRegion ®ion, 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 () |
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] |
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 56 of file viewport.h.
ViewPort::ViewPort | ( | ) |
Definition at line 107 of file viewport.cpp.
ViewPort ViewPort::BuildExpandedVP | ( | int | width, |
int | height | ||
) |
Definition at line 965 of file viewport.cpp.
bool ViewPort::ContainsIDL | ( | ) |
Definition at line 958 of file viewport.cpp.
|
inline |
Definition at line 185 of file viewport.h.
wxPoint2DDouble ViewPort::GetDoublePixFromLL | ( | double | lat, |
double | lon | ||
) |
Convert latitude and longitude on the ViewPort to physical pixel coordinates with double precision.
lat | Latitude in degrees. |
lon | Longitude in degrees. |
Definition at line 133 of file viewport.cpp.
|
inline |
Convert physical pixel coordinates on the ViewPort to latitude and longitude.
p | Physical pixel coordinates. |
lat | Pointer to store resulting latitude. |
lon | Pointer to store resulting longitude. |
Definition at line 80 of file viewport.h.
void ViewPort::GetLLFromPix | ( | const wxPoint2DDouble & | p, |
double * | lat, | ||
double * | lon | ||
) |
Convert physical pixel coordinates on the ViewPort to latitude and longitude using double precision.
p | Physical pixel coordinates as wxPoint2DDouble. |
lat | Pointer to store resulting latitude. |
lon | Pointer to store resulting longitude. |
Definition at line 256 of file viewport.cpp.
LLRegion ViewPort::GetLLRegion | ( | const OCPNRegion & | region | ) |
Definition at line 333 of file viewport.cpp.
wxPoint ViewPort::GetPixFromLL | ( | double | lat, |
double | lon | ||
) |
Convert latitude and longitude on the ViewPort to physical pixel coordinates.
lat | Latitude in degrees. |
lon | Longitude in degrees. |
Definition at line 124 of file viewport.cpp.
wxRect ViewPort::GetVPRectIntersect | ( | size_t | n, |
float * | llpoints | ||
) |
Get the viewport rectangle intersecting with a set of lat/lon points.
n | Number of points |
llpoints | Array of lat/lon points |
Definition at line 788 of file viewport.cpp.
OCPNRegion ViewPort::GetVPRegionIntersect | ( | const OCPNRegion & | region, |
const LLRegion & | llregion, | ||
int | chart_native_scale | ||
) |
Get the intersection of the viewport with a given region.
region | OCPNRegion to intersect with |
llregion | LLRegion to use for the intersection |
chart_native_scale | Native scale of the chart |
Definition at line 409 of file viewport.cpp.
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.
Region | OCPNRegion to intersect with |
nPoints | Number of points in the polygon |
llpoints | Array of lat/lon points defining the polygon |
chart_native_scale | Native scale of the chart |
ppoints | Array to store resulting pixel coordinates |
Definition at line 470 of file viewport.cpp.
|
inline |
Definition at line 178 of file viewport.h.
|
inline |
Definition at line 192 of file viewport.h.
|
inline |
Definition at line 180 of file viewport.h.
|
inline |
Definition at line 247 of file viewport.h.
|
inline |
Definition at line 187 of file viewport.h.
void ViewPort::SetBBoxDirect | ( | double | latmin, |
double | lonmin, | ||
double | latmax, | ||
double | lonmax | ||
) |
Definition at line 954 of file viewport.cpp.
void ViewPort::SetBoxes | ( | ) |
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:
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.
Definition at line 811 of file viewport.cpp.
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:
scale | The ratio of physical pixels to logical pixels. |
Definition at line 121 of file viewport.cpp.
|
inline |
Definition at line 183 of file viewport.h.
|
inline |
Definition at line 182 of file viewport.h.
void ViewPort::SetVPTransformMatrix | ( | ) |
Definition at line 975 of file viewport.cpp.
|
inline |
Definition at line 179 of file viewport.h.
bool ViewPort::b_FullScreenQuilt |
Definition at line 236 of file viewport.h.
bool ViewPort::b_MercatorProjectionOverride |
Definition at line 239 of file viewport.h.
bool ViewPort::b_quilt |
Definition at line 235 of file viewport.h.
double ViewPort::chart_scale |
Chart scale denominator (e.g., 50000 for a 1:50000 scale).
Definition at line 219 of file viewport.h.
double ViewPort::clat |
Center latitude of the viewport in degrees.
Definition at line 197 of file viewport.h.
double ViewPort::clon |
Center longitude of the viewport in degrees.
Definition at line 199 of file viewport.h.
int ViewPort::m_projection_type |
Definition at line 238 of file viewport.h.
float ViewPort::norm_transform[16] |
Definition at line 244 of file viewport.h.
int ViewPort::pix_height |
Height of the viewport in physical pixels.
Definition at line 233 of file viewport.h.
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.
Definition at line 231 of file viewport.h.
double ViewPort::ref_scale |
The nominal scale of the "reference chart" for this view.
Definition at line 221 of file viewport.h.
double ViewPort::rotation |
Rotation angle of the viewport in radians.
Definition at line 214 of file viewport.h.
wxRect ViewPort::rv_rect |
Definition at line 240 of file viewport.h.
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 212 of file viewport.h.
double ViewPort::tilt |
Tilt angle for perspective view in radians.
Definition at line 216 of file viewport.h.
double ViewPort::view_scale_ppm |
Requested view scale in physical pixels per meter (ppm), before applying projections.
Definition at line 204 of file viewport.h.
float ViewPort::vp_matrix_transform[16] |
Definition at line 243 of file viewport.h.