#include <mathplot.h>
Public Member Functions | |
mpMovableObject () | |
virtual | ~mpMovableObject () |
void | GetCoordinateBase (double &x, double &y, double &phi) const |
void | SetCoordinateBase (double x, double y, double phi=0) |
virtual bool | HasBBox () |
virtual double | GetMinX () |
virtual double | GetMaxX () |
virtual double | GetMinY () |
virtual double | GetMaxY () |
virtual void | Plot (wxDC &dc, mpWindow &w) |
void | SetAlign (int align) |
Protected Member Functions | |
void | TranslatePoint (double x, double y, double &out_x, double &out_y) |
void | ShapeUpdated () |
Protected Attributes | |
int | m_flags |
Holds label alignment. | |
double | m_reference_x |
double | m_reference_y |
double | m_reference_phi |
std::vector< double > | m_shape_xs |
std::vector< double > | m_shape_ys |
std::vector< double > | m_trans_shape_xs |
std::vector< double > | m_trans_shape_ys |
double | m_bbox_min_x |
double | m_bbox_max_x |
double | m_bbox_min_y |
double | m_bbox_max_y |
This virtual class represents objects that can be moved to an arbitrary 2D location+rotation. The current transformation is set through SetCoordinateBase. To ease the implementation of descendent classes, mpMovableObject will be in charge of Bounding Box computation and layer rendering, assuming that the object updates its shape in m_shape_xs & m_shape_ys.
mpMovableObject::mpMovableObject | ( | ) | [inline] |
Default constructor (sets location and rotation to (0,0,0))
References mpLAYER_PLOT.
virtual mpMovableObject::~mpMovableObject | ( | ) | [inline, virtual] |
void mpMovableObject::GetCoordinateBase | ( | double & | x, | |
double & | y, | |||
double & | phi | |||
) | const [inline] |
Get the current coordinate transformation.
virtual double mpMovableObject::GetMaxX | ( | ) | [inline, virtual] |
Get inclusive right border of bounding box.
Reimplemented from mpLayer.
virtual double mpMovableObject::GetMaxY | ( | ) | [inline, virtual] |
Get inclusive top border of bounding box.
Reimplemented from mpLayer.
virtual double mpMovableObject::GetMinX | ( | ) | [inline, virtual] |
Get inclusive left border of bounding box.
Reimplemented from mpLayer.
virtual double mpMovableObject::GetMinY | ( | ) | [inline, virtual] |
Get inclusive bottom border of bounding box.
Reimplemented from mpLayer.
virtual bool mpMovableObject::HasBBox | ( | ) | [inline, virtual] |
Check whether this layer has a bounding box. The default implementation returns TRUE. Override and return FALSE if your mpLayer implementation should be ignored by the calculation of the global bounding box for all layers in a mpWindow.
TRUE | Has bounding box | |
FALSE | Has not bounding box |
Reimplemented from mpLayer.
Referenced by Plot().
void mpMovableObject::Plot | ( | wxDC & | dc, | |
mpWindow & | w | |||
) | [virtual] |
Plot given view of layer to the given device context. An implementation of this function has to transform layer coordinates to wxDC coordinates based on the view parameters retrievable from the mpWindow passed in w. Note that the public methods of mpWindow: x2p,y2p and p2x,p2y are already provided which transform layer coordinates to DC pixel coordinates, and user code should rely on them for portability and future changes to be applied transparently, instead of implementing the following formulas manually.
The passed device context dc has its coordinate origin set to the top-left corner of the visible area (the default). The coordinate orientation is as shown in the following picture:
(wxDC origin 0,0) x-------------> ascending X ----------------+ | | | | V ascending Y | | | | | | | +-------------------------------------------+ <-- right-bottom corner of the mpWindow visible area.
Note that Y ascends in downward direction, whereas the usual vertical orientation for mathematical plots is vice versa. Thus Y-orientation will be swapped usually, when transforming between wxDC and mpLayer coordinates. This change of coordinates is taken into account in the methods p2x,p2y,x2p,y2p.
Rules for transformation between mpLayer and wxDC coordinates
dc_X = (layer_X - mpWindow::GetPosX()) * mpWindow::GetScaleX() dc_Y = (mpWindow::GetPosY() - layer_Y) * mpWindow::GetScaleY() // swapping Y-orientation layer_X = (dc_X / mpWindow::GetScaleX()) + mpWindow::GetPosX() // scale guaranteed to be not 0 layer_Y = mpWindow::GetPosY() - (dc_Y / mpWindow::GetScaleY()) // swapping Y-orientation
dc | Device context to plot to. | |
w | View to plot. The visible area can be retrieved from this object. |
Implements mpLayer.
References mpWindow::GetPosX(), mpWindow::GetPosY(), mpWindow::GetScaleX(), mpWindow::GetScaleY(), mpWindow::GetScrX(), mpWindow::GetScrY(), HasBBox(), m_bbox_max_x, m_bbox_max_y, mpLayer::m_continuous, m_flags, mpLayer::m_font, mpLayer::m_name, mpLayer::m_pen, mpLayer::m_showName, m_trans_shape_xs, m_trans_shape_ys, mpLayer::m_visible, mpALIGN_NE, mpALIGN_NW, mpALIGN_SW, mpALIGNMASK, mpWindow::x2p(), and mpWindow::y2p().
void mpMovableObject::SetAlign | ( | int | align | ) | [inline] |
Set label axis alignment.
align | alignment (choose between mpALIGN_NE, mpALIGN_NW, mpALIGN_SW, mpALIGN_SE |
void mpMovableObject::SetCoordinateBase | ( | double | x, | |
double | y, | |||
double | phi = 0 | |||
) | [inline] |
Set the coordinate transformation (phi in radians, 0 means no rotation).
References mpALIGN_NE.
void mpMovableObject::ShapeUpdated | ( | ) | [protected] |
Must be called by the descendent class after updating the shape (m_shape_xs/ys), or when the transformation changes. This method updates the buffers m_trans_shape_xs/ys, and the precomputed bounding box.
References m_bbox_max_x, m_bbox_max_y, m_bbox_min_x, m_bbox_min_y, m_reference_phi, m_reference_x, m_reference_y, m_shape_xs, m_shape_ys, m_trans_shape_xs, and m_trans_shape_ys.
Referenced by mpCovarianceEllipse::RecalculateShape(), and mpPolygon::setPoints().
void mpMovableObject::TranslatePoint | ( | double | x, | |
double | y, | |||
double & | out_x, | |||
double & | out_y | |||
) | [protected] |
A method for 2D translation and rotation, using the current transformation stored in m_reference_x,m_reference_y,m_reference_phi.
References m_reference_phi, m_reference_x, and m_reference_y.
double mpMovableObject::m_bbox_max_x [protected] |
Referenced by Plot(), and ShapeUpdated().
double mpMovableObject::m_bbox_max_y [protected] |
Referenced by Plot(), and ShapeUpdated().
double mpMovableObject::m_bbox_min_x [protected] |
double mpMovableObject::m_bbox_min_y [protected] |
Referenced by ShapeUpdated().
int mpMovableObject::m_flags [protected] |
Holds label alignment.
Referenced by Plot().
double mpMovableObject::m_reference_phi [protected] |
Referenced by ShapeUpdated(), and TranslatePoint().
double mpMovableObject::m_reference_x [protected] |
The coordinates of the object (orientation "phi" is in radians).
Referenced by ShapeUpdated(), and TranslatePoint().
double mpMovableObject::m_reference_y [protected] |
Referenced by ShapeUpdated(), and TranslatePoint().
std::vector<double> mpMovableObject::m_shape_xs [protected] |
This contains the object points, in local coordinates (to be transformed by the current transformation).
Referenced by mpCovarianceEllipse::RecalculateShape(), mpPolygon::setPoints(), and ShapeUpdated().
std::vector<double> mpMovableObject::m_shape_ys [protected] |
Referenced by mpCovarianceEllipse::RecalculateShape(), mpPolygon::setPoints(), and ShapeUpdated().
std::vector<double> mpMovableObject::m_trans_shape_xs [protected] |
The buffer for the translated & rotated points (to avoid recomputing them with each mpWindow refresh).
Referenced by Plot(), and ShapeUpdated().
std::vector<double> mpMovableObject::m_trans_shape_ys [protected] |
Referenced by Plot(), and ShapeUpdated().