21 #ifndef _MP_MATHPLOT_H_
22 #define _MP_MATHPLOT_H_
27 #pragma warning(disable:4251)
77 #define WXDLLIMPEXP_MATHPLOT GUI_IMPEXP
80 #if defined(__GNUG__) && !defined(__clang__)
81 #pragma interface "mathplot.h"
89 #include <wx/scrolwin.h>
91 #include <wx/dynarray.h>
93 #include <wx/dcmemory.h>
94 #include <wx/string.h>
105 #define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)
107 #define DEBUG_NEW new
112 #define X_BORDER_SEPARATION 40
113 #define Y_BORDER_SEPARATION 60
249 virtual void Plot(wxDC & dc,
mpWindow & w) = 0;
259 const wxFont&
GetFont()
const {
return m_font; }
264 const wxPen&
GetPen()
const {
return m_pen; }
283 void SetName(wxString name) { m_name = name; }
306 wxBitmap GetColourSquare(
int side = 16);
322 const wxBrush&
GetBrush()
const {
return m_brush; };
359 mpInfoLayer(wxRect rect,
const wxBrush* brush = wxTRANSPARENT_BRUSH);
368 virtual void UpdateInfo(
mpWindow& w, wxEvent& event);
388 virtual bool Inside(wxPoint& point);
392 virtual void Move(wxPoint delta);
395 virtual void UpdateReference();
399 wxPoint GetPosition();
407 const wxRect& GetRectangle() {
return m_dim; };
429 mpInfoCoords(wxRect rect,
const wxBrush* brush = wxTRANSPARENT_BRUSH);
462 mpInfoLegend(wxRect rect,
const wxBrush* brush = wxTRANSPARENT_BRUSH);
491 #define mpALIGNMASK 0x03
493 #define mpALIGN_RIGHT 0x00
495 #define mpALIGN_CENTER 0x01
497 #define mpALIGN_LEFT 0x02
499 #define mpALIGN_TOP mpALIGN_RIGHT
501 #define mpALIGN_BOTTOM mpALIGN_LEFT
503 #define mpALIGN_BORDER_BOTTOM 0x04
505 #define mpALIGN_BORDER_TOP 0x05
507 #define mpX_NORMAL 0x00
509 #define mpX_TIME 0x01
511 #define mpX_HOURS 0x02
513 #define mpX_DATE 0x03
515 #define mpX_DATETIME 0x04
517 #define mpALIGN_BORDER_LEFT mpALIGN_BORDER_BOTTOM
519 #define mpALIGN_BORDER_RIGHT mpALIGN_BORDER_TOP
521 #define mpALIGN_NE 0x00
523 #define mpALIGN_NW 0x01
525 #define mpALIGN_SW 0x02
527 #define mpALIGN_SE 0x03
552 virtual double GetY(
double x ) = 0;
563 DECLARE_DYNAMIC_CLASS(
mpFX)
584 virtual double GetX(
double y ) = 0;
595 DECLARE_DYNAMIC_CLASS(
mpFY)
615 virtual void Rewind() = 0;
622 virtual bool GetNextXY(
double & x,
double & y) = 0;
642 void UpdateViewBoundary(wxCoord xnew, wxCoord ynew);
644 DECLARE_DYNAMIC_CLASS(
mpFXY)
666 virtual double GetY(
double x ) = 0;
810 #define mpMOUSEMODE_DRAG 0
812 #define mpMOUSEMODE_ZOOMBOX 1
845 mpWindow( wxWindow *parent, wxWindowID
id,
846 const wxPoint &pos = wxDefaultPosition,
847 const wxSize &
size = wxDefaultSize,
863 bool AddLayer(
mpLayer* layer,
bool refreshDisplay =
true);
873 bool DelLayer(
mpLayer* layer,
bool alsoDeleteObject =
false,
bool refreshDisplay =
true);
879 void DelAllLayers(
bool alsoDeleteObject,
bool refreshDisplay =
true);
887 mpLayer* GetLayer(
int position);
893 mpLayer* GetLayerByName(
const wxString &name);
944 void SetScaleX(
double scaleX);
949 void SetScaleY(
double scaleY) {
if (scaleY!=0) m_scaleY=scaleY; UpdateAll(); }
954 void SetPosX(
double posX) { m_posX=posX; UpdateAll(); }
959 void SetPosY(
double posY) { m_posY=posY; UpdateAll(); }
965 void SetPos(
double posX,
double posY) { m_posX=posX; m_posY=posY; UpdateAll(); }
972 void SetScr(
int scrX,
int scrY) { m_scrX=scrX; m_scrY=scrY; }
977 inline double p2x(wxCoord pixelCoordX ) {
return m_posX + pixelCoordX/m_scaleX; }
982 inline double p2y(wxCoord pixelCoordY ) {
return m_posY - pixelCoordY/m_scaleY; }
987 inline wxCoord
x2p(
double x) {
return (wxCoord) ( (x-m_posX) * m_scaleX); }
992 inline wxCoord
y2p(
double y) {
return (wxCoord) ( (m_posY-y) * m_scaleY); }
1008 void LockAspect(
bool enable = TRUE);
1028 void Fit(
double xMin,
double xMax,
double yMin,
double yMax,wxCoord *printSizeX=NULL,wxCoord *printSizeY=NULL);
1033 void ZoomIn(
const wxPoint& centerPoint = wxDefaultPosition );
1038 void ZoomOut(
const wxPoint& centerPoint = wxDefaultPosition );
1050 void ZoomRect(wxPoint p0, wxPoint p1);
1060 unsigned int CountLayers();
1099 void GetBoundingBox(
double* bbox);
1103 void SetMPScrollbars(
bool status);
1114 bool SaveScreenshot(
const wxString& filename,
int type = wxBITMAP_TYPE_BMP, wxSize imageSize = wxDefaultSize,
bool fit =
false);
1125 void SetMargins(
int top,
int right,
int bottom,
int left);
1158 void SetLayerVisible(
const wxString &name,
bool viewable);
1163 bool IsLayerVisible(
const wxString &name );
1168 void SetLayerVisible(
const unsigned int position,
bool viewable);
1173 bool IsLayerVisible(
const unsigned int position );
1179 void SetColourTheme(
const wxColour& bgColour,
const wxColour& drawColour,
const wxColour& axesColour);
1188 virtual bool UpdateBBox();
1191 void OnPaint (wxPaintEvent &event);
1192 void OnSize (wxSizeEvent &event);
1194 void OnShowPopupMenu (wxMouseEvent &event);
1195 void OnMouseRightDown(wxMouseEvent &event);
1196 void OnCenter (wxCommandEvent &event);
1197 void OnFit (wxCommandEvent &event);
1198 void OnZoomIn (wxCommandEvent &event);
1199 void OnZoomOut (wxCommandEvent &event);
1200 void OnLockAspect (wxCommandEvent &event);
1201 void OnMouseHelp (wxCommandEvent &event);
1202 void OnPrintMenu (wxCommandEvent &event);
1203 void OnMouseWheel (wxMouseEvent &event);
1204 void OnMouseMove (wxMouseEvent &event);
1205 void OnMouseLeftDown (wxMouseEvent &event);
1206 void OnMouseLeftRelease (wxMouseEvent &event);
1207 void OnScrollThumbTrack (wxScrollWinEvent &event);
1208 void OnScrollPageUp (wxScrollWinEvent &event);
1209 void OnScrollPageDown (wxScrollWinEvent &event);
1210 void OnScrollLineUp (wxScrollWinEvent &event);
1211 void OnScrollLineDown (wxScrollWinEvent &event);
1212 void OnScrollTop (wxScrollWinEvent &event);
1213 void OnScrollBottom (wxScrollWinEvent &event);
1215 void DoScrollCalc (
const int position,
const int orientation);
1217 void DoZoomInXCalc (
const int staticXpixel);
1218 void DoZoomInYCalc (
const int staticYpixel);
1219 void DoZoomOutXCalc (
const int staticXpixel);
1220 void DoZoomOutYCalc (
const int staticYpixel);
1263 DECLARE_EVENT_TABLE()
1301 void SetData(
const std::vector<double> &xs,
const std::vector<double> &ys);
1307 void SetData(
const std::vector<float> &xs,
const std::vector<float> &ys);
1325 void AppendDataPoint(
float x,
float y);
1350 bool GetNextXY(
double & x,
double & y);
1391 mpText(wxString name = wxT(
"Title"),
int offsetx = 5,
int offsety = 50);
1404 DECLARE_DYNAMIC_CLASS(
mpText)
1419 mpPrintout(
mpWindow* drawWindow,
const wxChar *title = _T(
"wxMathPlot print output"));
1423 bool OnPrintPage(
int page);
1424 bool HasPage(
int page);
1464 phi = m_reference_phi;
1473 m_reference_phi = phi;
1478 virtual bool HasBBox() {
return m_trans_shape_xs.size()!=0; }
1512 void TranslatePoint(
double x,
double y,
double &out_x,
double &out_y );
1531 void ShapeUpdated();
1559 double quantiles = 2,
1561 const wxString & layerName = wxT(
"") ) :
1565 m_quantiles(quantiles),
1566 m_segments(segments)
1568 m_continuous =
true;
1620 void RecalculateShape();
1637 m_continuous =
true;
1649 const std::vector<double>& points_xs,
1650 const std::vector<double>& points_ys,
1651 bool closedShape=
true );
1659 const std::vector<float>& points_xs,
1660 const std::vector<float>& points_ys,
1661 bool closedShape=
true );
1684 m_min_y = m_max_y = 0;
1693 void GetBitmapCopy( wxImage &outBmp )
const;
1702 void SetBitmap(
const wxImage &inBmp,
double x,
double y,
double lx,
double ly );
1753 #if defined(_MSC_VER)
1754 #pragma warning(pop)
1758 #endif // _MP_MATHPLOT_H_
void SetPos(double posX, double posY)
Set current view's X and Y position and refresh display.
int m_offsety
Holds offset for Y in percentage.
int m_flags
Holds label alignment.
wxMemoryDC m_buff_dc
For double buffering.
double m_posY
Current view's Y position.
void SetAlign(int align)
Set Y axis alignment.
class WXDLLIMPEXP_MATHPLOT mpWindow
bool GetMPScrollbars()
Get scrollbars status.
int GetMarginRight()
Get the right margin.
bool m_showName
States whether the name of the layer must be shown (default is true).
double m_minX
Global layer bounding box, left border incl.
int m_flags
Holds label alignment.
virtual double GetMaxY()
Get inclusive top border of bounding box.
bool IsVisible()
Checks whether the layer is visible or not.
Zoom into view at clickposition / window center.
double GetYscl() const
Get current view's Y scale.
An arbitrary polygon, descendant of mpMovableObject.
virtual double GetMinY()
Get inclusive bottom border of bounding box.
A class providing graphs functionality for a 2D plot (either continuous or a set of points)...
int m_clickedX
Last mouse click X position, for centering and zooming the view.
This virtual class represents objects that can be moved to an arbitrary 2D location+rotation.
double GetMinX()
Returns the actual minimum X data (loaded in SetData).
bool m_ticks
Flag to toggle between ticks or grid.
bool m_mouseMovedAfterRightClick
class WXDLLIMPEXP_MATHPLOT mpFXYVector
wxString m_name
Layer's name.
double GetYpos() const
Get current view's Y position.
wxString GetName() const
Get layer name.
int m_offsetx
Holds offset for X in percentage.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
virtual bool HasBBox()
Check whether this layer has a bounding box.
Canvas for plotting mpLayer implementations.
void SetTicks(bool ticks)
Set X axis ticks or grid.
double m_scaleY
Current view's Y scale.
std::vector< double > m_ys
void SetCoordinateBase(double x, double y, double phi=0)
Set the coordinate transformation (phi in radians, 0 means no rotation).
void SetAlign(int align)
Set label axis alignment.
mpPolygon(const wxString &layerName=wxT(""))
Default constructor.
int m_winY
Holds the mpWindow size. Used to rescale position when window is resized.
int GetXScreen(void) const
double GetScaleY(void) const
mpLayerType m_type
Define layer type, which is assigned by constructor.
virtual bool HasBBox()
mpText should not be used for scaling decisions.
virtual double GetMinX()
Get inclusive left border of bounding box.
void SetDrawOutsideMargins(bool drawModeOutside)
Set Draw mode: inside or outside margins.
int m_flags
Holds label alignment.
double GetXscl()
Get current view's X scale.
#define mpALIGN_RIGHT
Aligns label to the right.
virtual double GetMinY()
Get inclusive bottom border of bounding box.
const wxBrush & GetBrush() const
Get brush set for this layer.
void SetMarginRight(int right)
Set the right margin.
double GetDesiredXmin()
Returns the left-border layer coordinate that the user wants the mpWindow to show (it may be not exac...
wxMenu m_popmenu
Canvas' context menu.
Abstract base class providing plot and labeling functionality for functions F:Y->X.
Abstract base class providing plot and labeling functionality for a locus plot F:N->X,Y.
wxColour m_axColour
Axes Colour.
wxBrush m_brush
The brush to be used for the background.
bool m_visible
Toggles layer visibility.
Implements the legend to be added to the plot This layer allows you to add a legend to describe the p...
Plot layer implementing a x-scale ruler.
size_t CountAllLayers()
Counts the number of plot layers, whether or not they have a bounding box.
int GetMarginLeft()
Get the left margin.
Shows information about the mouse commands.
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
virtual void Plot(wxDC &dc, mpWindow &w)=0
Plot given view of layer to the given device context.
void SetPosX(double posX)
Set current view's X position and refresh display.
int m_mouseLClick_Y
Starting coords for rectangular zoom selection.
virtual double GetMinX()
Get inclusive left border of bounding box.
mpInfoLayer * m_movingInfoLayer
For moving info layers over the window area.
std::deque< mpLayer * > wxLayerList
Define the type for the list of layers inside mpWindow.
virtual bool IsInfo()
Specifies that this is an Info box layer.
std::vector< double > m_trans_shape_ys
void GetCoordinateBase(double &x, double &y, double &phi) const
Get the current coordinate transformation.
void SetDrawState(bool drawState)
bool GetTicks()
Get Y axis ticks or grid.
void EnableMousePanZoom(bool enabled)
Enable/disable the feature of pan/zoom with the mouse (default=enabled)
wxImage m_bitmap
The internal copy of the Bitmap:
int m_flags
Holds label alignment.
const wxString & SetLabelFormat()
Get Y axis Label format.
void SetAlign(int align)
Set X axis alignment.
#define mpX_NORMAL
Set label for X axis in normal mode.
size_t m_index
The internal counter for the "GetNextXY" interface.
virtual double GetMaxX()
Get inclusive right border of bounding box.
void SetCovarianceMatrix(double cov_00, double cov_01, double cov_11)
Changes the covariance matrix:
#define WXDLLIMPEXP_MATHPLOT
Printout class used by mpWindow to draw in the objects to be printed.
int m_last_ly
For double buffering.
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
int m_flags
Holds label alignment.
wxBitmap * m_buff_bmp
For double buffering.
int GetScrX(void) const
Get current view's X dimension in device context units.
void SetBrush(wxBrush brush)
Set layer brush.
This virtual class represents objects that can be moved to an arbitrary 2D location+rotation.
const wxPen & GetPen() const
Get pen set for this layer.
double m_scaleX
Current view's X scale.
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
void GetCovarianceMatrix(double &cov_00, double &cov_01, double &cov_11) const
Returns the elements of the current covariance matrix:
void ShowPrintDialog()
Draws the mpWindow on a page for printing.
void EnableDoubleBuffer(bool enabled)
Enable/disable the double-buffering of the window, eliminating the flicker (default=disabled).
wxLayerList m_layers
List of attached plot layers.
void SetFont(wxFont &font)
Set layer font.
unsigned int m_labelType
Select labels mode: mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds.
double m_minY
Global layer bounding box, bottom border incl.
class WXDLLIMPEXP_MATHPLOT mpScaleY
class WXDLLIMPEXP_MATHPLOT mpLayer
double GetXpos() const
Get current view's X position.
#define mpALIGN_TOP
Aligns label to the top.
wxString m_content
string holding the coordinates to be drawn.
void SetMarginBottom(int bottom)
Set the bottom margin.
wxString m_labelFormat
Format string used to print labels.
virtual double GetMinY()
Get inclusive bottom border of bounding box.
#define mpALIGN_NE
Aligns label to north-east.
long m_mouseRClick_Y
For the right button "drag" feature.
void SetScaleY(double scaleY)
Set current view's Y scale and refresh display.
Base class to create small rectangular info boxes mpInfoLayer is the base class to create a small rec...
size_t GetDataLength() const
Returns the number of data points currently hold in X & Y.
double GetPosX(void) const
bool IsAspectLocked()
Checks whether the X/Y scale aspect is locked.
virtual bool HasBBox()
Check whether this layer has a bounding box.
bool GetContinuity() const
Gets the 'continuity' property of the layer.
void SetLabelFormat(const wxString &format)
Set X axis Label format (used for mpX_NORMAL draw mode).
virtual bool HasBBox()
mpInfoLayer has not bounding box.
void ShowName(bool show)
Shows or hides the text label with the name of the layer (default is visible).
Implements an overlay box which shows the mouse coordinates in plot units.
void SetContinuity(bool continuity)
Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points...
int m_scrY
Current view's Y dimension.
void SetName(wxString name)
Set layer name.
double GetMaxX()
Returns the actual maximum X data (loaded in SetData).
const wxString & SetLabelFormat()
Get X axis Label format (used for mpX_NORMAL draw mode).
wxColour m_bgColour
Background Colour.
int GetMarginBottom()
Get the bottom margin.
bool m_enableDoubleBuffer
For double buffering.
Abstract base class providing plot and labeling functionality for functions F:X->Y.
double GetDesiredYmin()
Returns the bottom-border layer coordinate that the user wants the mpWindow to show (it may be not ex...
Plot layer implementing a y-scale ruler.
virtual bool HasBBox()
Check whether this layer has a bounding box.
virtual void Plot(wxDC &dc, mpWindow &w)
Plot method.
bool m_drawOutsideMargins
select if the layer should draw only inside margins or over all DC
size_t size(const MATRIXLIKE &m, int dim)
bool GetDrawOutsideMargins()
Get Draw mode: inside or outside margins.
mpCovarianceEllipse(double cov_00=1, double cov_11=1, double cov_01=0, double quantiles=2, int segments=32, const wxString &layerName=wxT(""))
Default constructor.
unsigned int GetLabelMode()
Get X axis label view mode.
double GetDesiredXmax()
Returns the right-border layer coordinate that the user wants the mpWindow to show (it may be not exa...
bool m_continuous
Specify if the layer will be plotted as a continuous line or a set of points.
bool m_lockaspect
Scale aspect is locked or not.
int m_segments
The number of line segments that build up the ellipse.
enum __mp_Layer_Type mpLayerType
mpLayerType GetLayerType()
Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value.
class WXDLLIMPEXP_MATHPLOT mpFXY
wxString m_labelFormat
Format string used to print labels.
void SetPosY(double posY)
Set current view's Y position and refresh display.
Fit view to match bounding box of all layers.
class WXDLLIMPEXP_MATHPLOT mpPrintout
virtual ~mpMovableObject()
A 2D ellipse, described by a 2x2 covariance matrix.
double GetQuantiles() const
class WXDLLIMPEXP_MATHPLOT mpFX
static double zoomIncrementalFactor
This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse...
int GetMarginTop()
Get the top margin.
bool m_enableMouseNavigation
For pan/zoom with the mouse.
virtual ~mpCovarianceEllipse()
void SetScr(int scrX, int scrY)
Set current view's dimensions in device context units.
void SetLabelFormat(const wxString &format)
Set Y axis Label format.
double GetMinY()
Returns the actual minimum Y data (loaded in SetData).
bool m_ticks
Flag to toggle between ticks or grid.
virtual void UpdateInfo(mpWindow &w, wxEvent &event)
Updates the content of the info box.
#define mpALIGN_CENTER
Aligns label to the center.
mpMovableObject()
Default constructor (sets location and rotation to (0,0,0))
const wxFont & GetFont() const
Get font set for this layer.
double m_maxX
Global layer bounding box, right border incl.
double GetDesiredYmax()
Returns the top layer-border coordinate that the user wants the mpWindow to show (it may be not exact...
wxCoord m_scaledBitmap_offset_y
virtual double GetMaxY()
Get inclusive top border of bounding box.
Plot layer implementing a text string.
const wxColour & GetAxesColour()
Get axes draw colour.
virtual bool HasBBox()
Check whether this layer has a bounding box.
virtual double GetMaxY()
Get inclusive top border of bounding box.
wxBrush m_brush
Layer's brush.
virtual double GetMaxX()
Get inclusive right border of bounding box.
wxPoint m_reference
Holds the reference point for movements.
void SetMarginTop(int top)
Set the top margin.
wxColour m_fgColour
Foreground Colour.
int GetYScreen(void) const
void SetPen(wxPen pen)
Set layer pen.
void SetQuantiles(double q)
Set how many "quantiles" to draw, that is, the confidence interval of the ellipse (see above)...
void SetSegments(int segments)
void SetLabelMode(unsigned int mode)
Set X axis label view mode.
Center view on click position.
int GetScrY(void) const
Get current view's Y dimension in device context units.
int m_clickedY
Last mouse click Y position, for centering and zooming the view.
double GetMaxY()
Returns the actual maximum Y data (loaded in SetData).
virtual double GetMinX()
Get inclusive left border of bounding box.
Plot layer, abstract base class.
std::vector< double > m_shape_ys
class WXDLLIMPEXP_MATHPLOT mpScaleX
double m_maxY
Global layer bounding box, top border incl.
class WXDLLIMPEXP_MATHPLOT mpFY
class WXDLLIMPEXP_MATHPLOT mpText
void SetTicks(bool ticks)
Set Y axis ticks or grid.
double m_posX
Current view's X position.
int m_scrX
Current view's X dimension.
void SetAlign(int align)
Set label axis alignment.
bool GetTicks()
Get X axis ticks or grid.
void SetMarginLeft(int left)
Set the left margin.
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
Abstract base class providing plot and labeling functionality for functions F:Y->X.
virtual bool IsInfo()
Check whether the layer is an info box.
virtual double GetMaxX()
Get inclusive right border of bounding box.
void SetVisible(bool show)
Sets layer visibility.
double GetPosY(void) const
virtual bool HasBBox()
Check whether this layer has a bounding box.
mpBitmapLayer()
Default constructor.
wxMenu * GetPopupMenu()
Get reference to context menu of the plot canvas.
double GetScaleX(void) const