KiCad PCB EDA Suite
mpCovarianceEllipse Class Reference

A 2D ellipse, described by a 2x2 covariance matrix. More...

#include <mathplot.h>

Inheritance diagram for mpCovarianceEllipse:
mpMovableObject mpLayer

Public Member Functions

 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. More...
 
virtual ~mpCovarianceEllipse ()
 
double GetQuantiles () const
 
void SetQuantiles (double q)
 Set how many "quantiles" to draw, that is, the confidence interval of the ellipse (see above). More...
 
void SetSegments (int segments)
 
int GetSegments () const
 
void GetCovarianceMatrix (double &cov_00, double &cov_01, double &cov_11) const
 Returns the elements of the current covariance matrix: More...
 
void SetCovarianceMatrix (double cov_00, double cov_01, double cov_11)
 Changes the covariance matrix: More...
 
void GetCoordinateBase (double &x, double &y, double &phi) const
 Get the current coordinate transformation. More...
 
void SetCoordinateBase (double x, double y, double phi=0)
 Set the coordinate transformation (phi in radians, 0 means no rotation). More...
 
virtual bool HasBBox () const override
 Check whether this layer has a bounding box. More...
 
virtual double GetMinX () const override
 Get inclusive left border of bounding box. More...
 
virtual double GetMaxX () const override
 Get inclusive right border of bounding box. More...
 
virtual double GetMinY () const override
 Get inclusive bottom border of bounding box. More...
 
virtual double GetMaxY () const override
 Get inclusive top border of bounding box. More...
 
virtual void Plot (wxDC &dc, mpWindow &w) override
 Plot given view of layer to the given device context. More...
 
void SetAlign (int align)
 Set label axis alignment. More...
 
virtual bool IsInfo () const
 Check whether the layer is an info box. More...
 
const wxString & GetName () const
 Get layer name. More...
 
const wxFont & GetFont () const
 Get font set for this layer. More...
 
const wxPen & GetPen () const
 Get pen set for this layer. More...
 
void SetContinuity (bool continuity)
 Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points). More...
 
bool GetContinuity () const
 Gets the 'continuity' property of the layer. More...
 
void ShowName (bool show)
 Shows or hides the text label with the name of the layer (default is visible). More...
 
void SetName (wxString name)
 Set layer name. More...
 
void SetFont (wxFont &font)
 Set layer font. More...
 
void SetPen (wxPen pen)
 Set layer pen. More...
 
void SetDrawOutsideMargins (bool drawModeOutside)
 Set Draw mode: inside or outside margins. More...
 
bool GetDrawOutsideMargins ()
 Get Draw mode: inside or outside margins. More...
 
wxBitmap GetColourSquare (int side=16) const
 Get a small square bitmap filled with the colour of the pen used in the layer. More...
 
mpLayerType GetLayerType () const
 Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value. More...
 
bool IsVisible () const
 Checks whether the layer is visible or not. More...
 
void SetVisible (bool show)
 Sets layer visibility. More...
 
const wxBrush & GetBrush () const
 Get brush set for this layer. More...
 
void SetBrush (wxBrush brush)
 Set layer brush. More...
 

Protected Member Functions

void RecalculateShape ()
 Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes. More...
 
void TranslatePoint (double x, double y, double &out_x, double &out_y)
 A method for 2D translation and rotation, using the current transformation stored in m_reference_x,m_reference_y,m_reference_phi. More...
 
void ShapeUpdated ()
 Must be called by the descendent class after updating the shape (m_shape_xs/ys), or when the transformation changes. More...
 

Protected Attributes

double m_cov_00
 The elements of the matrix (only 3 since cov(0,1)=cov(1,0) in any positive definite matrix). More...
 
double m_cov_11
 
double m_cov_01
 
double m_quantiles
 
int m_segments
 The number of line segments that build up the ellipse. More...
 
int m_flags
 
double m_reference_x
 The coordinates of the object (orientation "phi" is in radians). More...
 
double m_reference_y
 
double m_reference_phi
 
std::vector< double > m_shape_xs
 This contains the object points, in local coordinates (to be transformed by the current transformation). More...
 
std::vector< double > m_shape_ys
 
std::vector< double > m_trans_shape_xs
 The buffer for the translated & rotated points (to avoid recomputing them with each mpWindow refresh). More...
 
std::vector< double > m_trans_shape_ys
 
double m_bbox_min_x
 The precomputed bounding box: More...
 
double m_bbox_max_x
 
double m_bbox_min_y
 
double m_bbox_max_y
 
wxFont m_font
 
wxPen m_pen
 
wxBrush m_brush
 
wxString m_name
 
bool m_continuous
 
bool m_showName
 
bool m_drawOutsideMargins
 
mpLayerType m_type
 
bool m_visible
 

Detailed Description

A 2D ellipse, described by a 2x2 covariance matrix.

The relation between the multivariate Gaussian confidence interval and the "quantiles" in this class is:

The ellipse will be always centered at the origin. Use mpMovableObject::SetCoordinateBase to move it.

Definition at line 1842 of file mathplot.h.

Constructor & Destructor Documentation

◆ mpCovarianceEllipse()

mpCovarianceEllipse::mpCovarianceEllipse ( double  cov_00 = 1,
double  cov_11 = 1,
double  cov_01 = 0,
double  quantiles = 2,
int  segments = 32,
const wxString &  layerName = wxT("") 
)
inline

Default constructor.

Initializes to a unity diagonal covariance matrix, a 95% confidence interval (2 sigmas), 32 segments, and a continuous plot (m_continuous=true).

Definition at line 1849 of file mathplot.h.

1854  :
1855  m_cov_00( cov_00 ),
1856  m_cov_11( cov_11 ),
1857  m_cov_01( cov_01 ),
1858  m_quantiles( quantiles ),
1859  m_segments( segments )
1860  {
1861  m_continuous = true;
1862  m_name = layerName;
1863  RecalculateShape();
1864  m_type = mpLAYER_PLOT;
1865  }
bool m_continuous
Definition: mathplot.h:318
void RecalculateShape()
Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes.
Definition: mathplot.cpp:3228
int m_segments
The number of line segments that build up the ellipse.
Definition: mathplot.h:1909
mpLayerType m_type
Definition: mathplot.h:321
wxString m_name
Definition: mathplot.h:317
double m_cov_00
The elements of the matrix (only 3 since cov(0,1)=cov(1,0) in any positive definite matrix).
Definition: mathplot.h:1904

References mpLAYER_PLOT.

◆ ~mpCovarianceEllipse()

virtual mpCovarianceEllipse::~mpCovarianceEllipse ( )
inlinevirtual

Definition at line 1867 of file mathplot.h.

1867 {}

Member Function Documentation

◆ GetBrush()

const wxBrush& mpLayer::GetBrush ( ) const
inlineinherited

Get brush set for this layer.

Returns
brush.

Definition at line 306 of file mathplot.h.

306 { return m_brush; };
wxBrush m_brush
Definition: mathplot.h:316

◆ GetColourSquare()

wxBitmap mpLayer::GetColourSquare ( int  side = 16) const
inherited

Get a small square bitmap filled with the colour of the pen used in the layer.

Useful to create legends or similar reference to the layers.

Parameters
sideside length in pixels
Returns
a wxBitmap filled with layer's colour

Definition at line 74 of file mathplot.cpp.

75 {
76  wxBitmap square( side, side, -1 );
77  wxColour filler = m_pen.GetColour();
78  wxBrush brush( filler, wxBRUSHSTYLE_SOLID );
79  wxMemoryDC dc;
80 
81  dc.SelectObject( square );
82  dc.SetBackground( brush );
83  dc.Clear();
84  dc.SelectObject( wxNullBitmap );
85  return square;
86 }
wxPen m_pen
Definition: mathplot.h:315
double square(double x)

References mpLayer::m_pen, and square().

◆ GetContinuity()

bool mpLayer::GetContinuity ( ) const
inlineinherited

Gets the 'continuity' property of the layer.

See also
SetContinuity

Definition at line 258 of file mathplot.h.

258 { return m_continuous; }
bool m_continuous
Definition: mathplot.h:318

◆ GetCoordinateBase()

void mpMovableObject::GetCoordinateBase ( double &  x,
double &  y,
double &  phi 
) const
inlineinherited

Get the current coordinate transformation.

Definition at line 1751 of file mathplot.h.

1752  {
1753  x = m_reference_x;
1754  y = m_reference_y;
1755  phi = m_reference_phi;
1756  }
double m_reference_x
The coordinates of the object (orientation "phi" is in radians).
Definition: mathplot.h:1799
double m_reference_y
Definition: mathplot.h:1799
double m_reference_phi
Definition: mathplot.h:1799

◆ GetCovarianceMatrix()

void mpCovarianceEllipse::GetCovarianceMatrix ( double &  cov_00,
double &  cov_01,
double &  cov_11 
) const
inline

Returns the elements of the current covariance matrix:

Definition at line 1884 of file mathplot.h.

1885  {
1886  cov_00 = m_cov_00;
1887  cov_01 = m_cov_01;
1888  cov_11 = m_cov_11;
1889  }
double m_cov_00
The elements of the matrix (only 3 since cov(0,1)=cov(1,0) in any positive definite matrix).
Definition: mathplot.h:1904

◆ GetDrawOutsideMargins()

bool mpLayer::GetDrawOutsideMargins ( )
inlineinherited

Get Draw mode: inside or outside margins.

Returns
The draw mode

Definition at line 285 of file mathplot.h.

285 { return m_drawOutsideMargins; };
bool m_drawOutsideMargins
Definition: mathplot.h:320

◆ GetFont()

const wxFont& mpLayer::GetFont ( ) const
inlineinherited

Get font set for this layer.

Returns
Font

Definition at line 243 of file mathplot.h.

243 { return m_font; }
wxFont m_font
Definition: mathplot.h:310

◆ GetLayerType()

mpLayerType mpLayer::GetLayerType ( ) const
inlineinherited

Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value.

Returns
An integer indicating layer type

Definition at line 294 of file mathplot.h.

294 { return m_type; };
mpLayerType m_type
Definition: mathplot.h:321

Referenced by mpInfoLegend::Plot().

◆ GetMaxX()

virtual double mpMovableObject::GetMaxX ( ) const
inlineoverridevirtualinherited

Get inclusive right border of bounding box.

Reimplemented from mpLayer.

Definition at line 1777 of file mathplot.h.

1777 { return m_bbox_max_x; }
double m_bbox_max_x
Definition: mathplot.h:1819

◆ GetMaxY()

virtual double mpMovableObject::GetMaxY ( ) const
inlineoverridevirtualinherited

Get inclusive top border of bounding box.

Reimplemented from mpLayer.

Definition at line 1785 of file mathplot.h.

1785 { return m_bbox_max_y; }
double m_bbox_max_y
Definition: mathplot.h:1819

◆ GetMinX()

virtual double mpMovableObject::GetMinX ( ) const
inlineoverridevirtualinherited

Get inclusive left border of bounding box.

Reimplemented from mpLayer.

Definition at line 1773 of file mathplot.h.

1773 { return m_bbox_min_x; }
double m_bbox_min_x
The precomputed bounding box:
Definition: mathplot.h:1819

◆ GetMinY()

virtual double mpMovableObject::GetMinY ( ) const
inlineoverridevirtualinherited

Get inclusive bottom border of bounding box.

Reimplemented from mpLayer.

Definition at line 1781 of file mathplot.h.

1781 { return m_bbox_min_y; }
double m_bbox_min_y
Definition: mathplot.h:1819

◆ GetName()

const wxString& mpLayer::GetName ( void  ) const
inlineinherited

Get layer name.

Returns
Name

Definition at line 238 of file mathplot.h.

238 { return m_name; }
wxString m_name
Definition: mathplot.h:317

Referenced by SIM_PLOT_PANEL::GetLabelX(), SIM_PLOT_PANEL::GetLabelY1(), SIM_PLOT_PANEL::GetLabelY2(), mpInfoLegend::Plot(), and mpText::Plot().

◆ GetPen()

const wxPen& mpLayer::GetPen ( ) const
inlineinherited

Get pen set for this layer.

Returns
Pen

Definition at line 248 of file mathplot.h.

248 { return m_pen; }
wxPen m_pen
Definition: mathplot.h:315

Referenced by CURSOR::Plot(), and mpInfoLegend::Plot().

◆ GetQuantiles()

double mpCovarianceEllipse::GetQuantiles ( ) const
inline

Definition at line 1869 of file mathplot.h.

1869 { return m_quantiles; }

◆ GetSegments()

int mpCovarianceEllipse::GetSegments ( ) const
inline

Definition at line 1880 of file mathplot.h.

1880 { return m_segments; }
int m_segments
The number of line segments that build up the ellipse.
Definition: mathplot.h:1909

◆ HasBBox()

virtual bool mpMovableObject::HasBBox ( ) const
inlineoverridevirtualinherited

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.

Return values
trueHas bounding box
falseHas not bounding box

Reimplemented from mpLayer.

Definition at line 1769 of file mathplot.h.

1769 { return m_trans_shape_xs.size()!=0; }
std::vector< double > m_trans_shape_xs
The buffer for the translated & rotated points (to avoid recomputing them with each mpWindow refresh)...
Definition: mathplot.h:1814

Referenced by mpMovableObject::Plot().

◆ IsInfo()

virtual bool mpLayer::IsInfo ( ) const
inlinevirtualinherited

Check whether the layer is an info box.

The default implementation returns false. It is overridden to true for mpInfoLayer class and its derivative. It is necessary to define mouse actions behaviour over info boxes.

Returns
whether the layer is an info boxes
See also
mpInfoLayer::IsInfo

Reimplemented in mpInfoLayer.

Definition at line 170 of file mathplot.h.

170 { return false; };

◆ IsVisible()

bool mpLayer::IsVisible ( ) const
inlineinherited

Checks whether the layer is visible or not.

Returns
true if visible

Definition at line 298 of file mathplot.h.

298 { return m_visible; };
bool m_visible
Definition: mathplot.h:322

Referenced by mpWindow::IsLayerVisible(), SIM_PLOT_PANEL::IsLegendShown(), and mpInfoLegend::Plot().

◆ Plot()

void mpMovableObject::Plot ( wxDC &  dc,
mpWindow w 
)
overridevirtualinherited

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
Parameters
dcDevice context to plot to.
wView to plot. The visible area can be retrieved from this object.
See also
mpWindow::p2x,mpWindow::p2y,mpWindow::x2p,mpWindow::y2p

Implements mpLayer.

Definition at line 3123 of file mathplot.cpp.

3124 {
3125  if( m_visible )
3126  {
3127  dc.SetPen( m_pen );
3128 
3129 
3130  std::vector<double>::iterator itX = m_trans_shape_xs.begin();
3131  std::vector<double>::iterator itY = m_trans_shape_ys.begin();
3132 
3133  if( !m_continuous )
3134  {
3135  // for some reason DrawPoint does not use the current pen,
3136  // so we use DrawLine for fat pens
3137  if( m_pen.GetWidth() <= 1 )
3138  {
3139  while( itX!=m_trans_shape_xs.end() )
3140  {
3141  dc.DrawPoint( w.x2p( *(itX++) ), w.y2p( *(itY++) ) );
3142  }
3143  }
3144  else
3145  {
3146  while( itX!=m_trans_shape_xs.end() )
3147  {
3148  wxCoord cx = w.x2p( *(itX++) );
3149  wxCoord cy = w.y2p( *(itY++) );
3150  dc.DrawLine( cx, cy, cx, cy );
3151  }
3152  }
3153  }
3154  else
3155  {
3156  wxCoord cx0 = 0, cy0 = 0;
3157  bool first = true;
3158 
3159  while( itX != m_trans_shape_xs.end() )
3160  {
3161  wxCoord cx = w.x2p( *(itX++) );
3162  wxCoord cy = w.y2p( *(itY++) );
3163 
3164  if( first )
3165  {
3166  first = false;
3167  cx0 = cx; cy0 = cy;
3168  }
3169 
3170  dc.DrawLine( cx0, cy0, cx, cy );
3171  cx0 = cx; cy0 = cy;
3172  }
3173  }
3174 
3175  if( !m_name.IsEmpty() && m_showName )
3176  {
3177  dc.SetFont( m_font );
3178 
3179  wxCoord tx, ty;
3180  dc.GetTextExtent( m_name, &tx, &ty );
3181 
3182  if( HasBBox() )
3183  {
3184  wxCoord sx = (wxCoord) ( ( m_bbox_max_x - w.GetPosX() ) * w.GetScaleX() );
3185  wxCoord sy = (wxCoord) ( (w.GetPosY() - m_bbox_max_y ) * w.GetScaleY() );
3186 
3187  tx = sx - tx - 8;
3188  ty = sy - 8 - ty;
3189  }
3190  else
3191  {
3192  const int sx = w.GetScrX() >> 1;
3193  const int sy = w.GetScrY() >> 1;
3194 
3195  if( (m_flags & mpALIGNMASK) == mpALIGN_NE )
3196  {
3197  tx = sx - tx - 8;
3198  ty = -sy + 8;
3199  }
3200  else if( (m_flags & mpALIGNMASK) == mpALIGN_NW )
3201  {
3202  tx = -sx + 8;
3203  ty = -sy + 8;
3204  }
3205  else if( (m_flags & mpALIGNMASK) == mpALIGN_SW )
3206  {
3207  tx = -sx + 8;
3208  ty = sy - 8 - ty;
3209  }
3210  else
3211  {
3212  tx = sx - tx - 8;
3213  ty = sy - 8 - ty;
3214  }
3215  }
3216 
3217  dc.DrawText( m_name, tx, ty );
3218  }
3219  }
3220 }
bool m_continuous
Definition: mathplot.h:318
#define mpALIGN_NW
Aligns label to north-west.
Definition: mathplot.h:507
double GetPosY(void) const
Definition: mathplot.h:1130
double GetScaleX(void) const
Definition: mathplot.h:1109
std::vector< double > m_trans_shape_ys
Definition: mathplot.h:1814
double GetScaleY(void) const
Definition: mathplot.h:1116
double GetPosX(void) const
Definition: mathplot.h:1123
bool m_visible
Definition: mathplot.h:322
virtual bool HasBBox() const override
Check whether this layer has a bounding box.
Definition: mathplot.h:1769
double m_bbox_max_y
Definition: mathplot.h:1819
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
Definition: mathplot.h:1207
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1138
wxFont m_font
Definition: mathplot.h:310
#define mpALIGN_NE
Aligns label to north-east.
Definition: mathplot.h:505
#define mpALIGNMASK
Definition: mathplot.h:475
bool m_showName
Definition: mathplot.h:319
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
Definition: mathplot.h:1202
wxPen m_pen
Definition: mathplot.h:315
std::vector< double > m_trans_shape_xs
The buffer for the translated & rotated points (to avoid recomputing them with each mpWindow refresh)...
Definition: mathplot.h:1814
wxString m_name
Definition: mathplot.h:317
double m_bbox_max_x
Definition: mathplot.h:1819
int GetScrY(void) const
Get current view's Y dimension in device context units.
Definition: mathplot.h:1147
#define mpALIGN_SW
Aligns label to south-west.
Definition: mathplot.h:509

References mpWindow::GetPosX(), mpWindow::GetPosY(), mpWindow::GetScaleX(), mpWindow::GetScaleY(), mpWindow::GetScrX(), mpWindow::GetScrY(), mpMovableObject::HasBBox(), mpMovableObject::m_bbox_max_x, mpMovableObject::m_bbox_max_y, mpLayer::m_continuous, mpMovableObject::m_flags, mpLayer::m_font, mpLayer::m_name, mpLayer::m_pen, mpLayer::m_showName, mpMovableObject::m_trans_shape_xs, mpMovableObject::m_trans_shape_ys, mpLayer::m_visible, mpALIGN_NE, mpALIGN_NW, mpALIGN_SW, mpALIGNMASK, mpWindow::x2p(), and mpWindow::y2p().

◆ RecalculateShape()

void mpCovarianceEllipse::RecalculateShape ( )
protected

Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes.

Definition at line 3228 of file mathplot.cpp.

3229 {
3230  m_shape_xs.clear();
3231  m_shape_ys.clear();
3232 
3233  // Preliminary checks:
3234  if( m_quantiles < 0 )
3235  return;
3236 
3237  if( m_cov_00 < 0 )
3238  return;
3239 
3240  if( m_cov_11 < 0 )
3241  return;
3242 
3243  m_shape_xs.resize( m_segments, 0 );
3244  m_shape_ys.resize( m_segments, 0 );
3245 
3246  // Compute the two eigenvalues of the covariance:
3247  // -------------------------------------------------
3248  double b = -m_cov_00 - m_cov_11;
3249  double c = m_cov_00 * m_cov_11 - m_cov_01 * m_cov_01;
3250 
3251  double D = b * b - 4 * c;
3252 
3253  if( D < 0 )
3254  return;
3255 
3256  double eigenVal0 = 0.5 * ( -b + sqrt( D ) );
3257  double eigenVal1 = 0.5 * ( -b - sqrt( D ) );
3258 
3259  // Compute the two corresponding eigenvectors:
3260  // -------------------------------------------------
3261  double eigenVec0_x, eigenVec0_y;
3262  double eigenVec1_x, eigenVec1_y;
3263 
3264  if( fabs( eigenVal0 - m_cov_00 ) > 1e-6 )
3265  {
3266  double k1x = m_cov_01 / ( eigenVal0 - m_cov_00 );
3267  eigenVec0_y = 1;
3268  eigenVec0_x = eigenVec0_y * k1x;
3269  }
3270  else
3271  {
3272  double k1y = m_cov_01 / ( eigenVal0 - m_cov_11 );
3273  eigenVec0_x = 1;
3274  eigenVec0_y = eigenVec0_x * k1y;
3275  }
3276 
3277  if( fabs( eigenVal1 - m_cov_00 ) > 1e-6 )
3278  {
3279  double k2x = m_cov_01 / ( eigenVal1 - m_cov_00 );
3280  eigenVec1_y = 1;
3281  eigenVec1_x = eigenVec1_y * k2x;
3282  }
3283  else
3284  {
3285  double k2y = m_cov_01 / ( eigenVal1 - m_cov_11 );
3286  eigenVec1_x = 1;
3287  eigenVec1_y = eigenVec1_x * k2y;
3288  }
3289 
3290  // Normalize the eigenvectors:
3291  double len = sqrt( eigenVec0_x * eigenVec0_x + eigenVec0_y * eigenVec0_y );
3292  eigenVec0_x /= len; // It *CANNOT* be zero
3293  eigenVec0_y /= len;
3294 
3295  len = sqrt( eigenVec1_x * eigenVec1_x + eigenVec1_y * eigenVec1_y );
3296  eigenVec1_x /= len; // It *CANNOT* be zero
3297  eigenVec1_y /= len;
3298 
3299 
3300  // Take the sqrt of the eigenvalues (required for the ellipse scale):
3301  eigenVal0 = sqrt( eigenVal0 );
3302  eigenVal1 = sqrt( eigenVal1 );
3303 
3304  // Compute the 2x2 matrix M = diag(eigVal) * (~eigVec) (each eigen vector is a row):
3305  double M_00 = eigenVec0_x * eigenVal0;
3306  double M_01 = eigenVec0_y * eigenVal0;
3307 
3308  double M_10 = eigenVec1_x * eigenVal1;
3309  double M_11 = eigenVec1_y * eigenVal1;
3310 
3311  // The points of the 2D ellipse:
3312  double ang;
3313  double Aang = 6.283185308 / (m_segments - 1);
3314  int i;
3315 
3316  for( i = 0, ang = 0; i < m_segments; i++, ang += Aang )
3317  {
3318  double ccos = cos( ang );
3319  double csin = sin( ang );
3320 
3321  m_shape_xs[i] = m_quantiles * (ccos * M_00 + csin * M_10 );
3322  m_shape_ys[i] = m_quantiles * (ccos * M_01 + csin * M_11 );
3323  } // end for points on ellipse
3324 
3325  ShapeUpdated();
3326 }
int m_segments
The number of line segments that build up the ellipse.
Definition: mathplot.h:1909
void ShapeUpdated()
Must be called by the descendent class after updating the shape (m_shape_xs/ys), or when the transfor...
Definition: mathplot.cpp:3077
std::vector< double > m_shape_ys
Definition: mathplot.h:1809
double m_cov_00
The elements of the matrix (only 3 since cov(0,1)=cov(1,0) in any positive definite matrix).
Definition: mathplot.h:1904
std::vector< double > m_shape_xs
This contains the object points, in local coordinates (to be transformed by the current transformatio...
Definition: mathplot.h:1809

References m_cov_00, m_cov_01, m_cov_11, m_quantiles, m_segments, mpMovableObject::m_shape_xs, mpMovableObject::m_shape_ys, and mpMovableObject::ShapeUpdated().

◆ SetAlign()

void mpMovableObject::SetAlign ( int  align)
inlineinherited

Set label axis alignment.

Parameters
alignalignment (choose between mpALIGN_NE, mpALIGN_NW, mpALIGN_SW, mpALIGN_SE

Definition at line 1792 of file mathplot.h.

1792 { m_flags = align; };

◆ SetBrush()

void mpLayer::SetBrush ( wxBrush  brush)
inlineinherited

Set layer brush.

Parameters
brushbrush, will be copied to internal class member

Definition at line 310 of file mathplot.h.

310 { m_brush = brush; };
wxBrush m_brush
Definition: mathplot.h:316

◆ SetContinuity()

void mpLayer::SetContinuity ( bool  continuity)
inlineinherited

Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points).

See also
GetContinuity

Definition at line 253 of file mathplot.h.

253 { m_continuous = continuity; }
bool m_continuous
Definition: mathplot.h:318

Referenced by TRACE::TRACE().

◆ SetCoordinateBase()

void mpMovableObject::SetCoordinateBase ( double  x,
double  y,
double  phi = 0 
)
inlineinherited

Set the coordinate transformation (phi in radians, 0 means no rotation).

Definition at line 1760 of file mathplot.h.

1761  {
1762  m_reference_x = x;
1763  m_reference_y = y;
1764  m_reference_phi = phi;
1765  m_flags = mpALIGN_NE;
1766  ShapeUpdated();
1767  }
double m_reference_x
The coordinates of the object (orientation "phi" is in radians).
Definition: mathplot.h:1799
void ShapeUpdated()
Must be called by the descendent class after updating the shape (m_shape_xs/ys), or when the transfor...
Definition: mathplot.cpp:3077
double m_reference_y
Definition: mathplot.h:1799
#define mpALIGN_NE
Aligns label to north-east.
Definition: mathplot.h:505
double m_reference_phi
Definition: mathplot.h:1799

References mpALIGN_NE.

◆ SetCovarianceMatrix()

void mpCovarianceEllipse::SetCovarianceMatrix ( double  cov_00,
double  cov_01,
double  cov_11 
)
inline

Changes the covariance matrix:

Definition at line 1893 of file mathplot.h.

1894  {
1895  m_cov_00 = cov_00;
1896  m_cov_01 = cov_01;
1897  m_cov_11 = cov_11;
1898  RecalculateShape();
1899  }
void RecalculateShape()
Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes.
Definition: mathplot.cpp:3228
double m_cov_00
The elements of the matrix (only 3 since cov(0,1)=cov(1,0) in any positive definite matrix).
Definition: mathplot.h:1904

◆ SetDrawOutsideMargins()

void mpLayer::SetDrawOutsideMargins ( bool  drawModeOutside)
inlineinherited

Set Draw mode: inside or outside margins.

Default is outside, which allows the layer to draw up to the mpWindow border.

Parameters
drawModeOutsideThe draw mode to be set

Definition at line 281 of file mathplot.h.

281 { m_drawOutsideMargins = drawModeOutside; };
bool m_drawOutsideMargins
Definition: mathplot.h:320

Referenced by CURSOR::CURSOR(), and TRACE::TRACE().

◆ SetFont()

void mpLayer::SetFont ( wxFont &  font)
inlineinherited

Set layer font.

Parameters
fontFont, will be copied to internal class member

Definition at line 272 of file mathplot.h.

272 { m_font = font; }
wxFont m_font
Definition: mathplot.h:310

◆ SetName()

void mpLayer::SetName ( wxString  name)
inlineinherited

Set layer name.

Parameters
nameName, will be copied to internal class member

Definition at line 267 of file mathplot.h.

267 { m_name = name; }
const char * name
Definition: DXF_plotter.cpp:56
wxString m_name
Definition: mathplot.h:317

References name.

◆ SetPen()

void mpLayer::SetPen ( wxPen  pen)
inlineinherited

Set layer pen.

Parameters
penPen, will be copied to internal class member

Definition at line 277 of file mathplot.h.

277 { m_pen = pen; }
wxPen m_pen
Definition: mathplot.h:315

Referenced by SIM_PLOT_PANEL::EnableCursor(), and SIM_PLOT_PANEL::UpdateTraceStyle().

◆ SetQuantiles()

void mpCovarianceEllipse::SetQuantiles ( double  q)
inline

Set how many "quantiles" to draw, that is, the confidence interval of the ellipse (see above).

Definition at line 1873 of file mathplot.h.

1874  {
1875  m_quantiles = q;
1876  RecalculateShape();
1877  }
void RecalculateShape()
Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes.
Definition: mathplot.cpp:3228

◆ SetSegments()

void mpCovarianceEllipse::SetSegments ( int  segments)
inline

Definition at line 1879 of file mathplot.h.

1879 { m_segments = segments; }
int m_segments
The number of line segments that build up the ellipse.
Definition: mathplot.h:1909

◆ SetVisible()

void mpLayer::SetVisible ( bool  show)
inlineinherited

Sets layer visibility.

Parameters
showvisibility bool.

Definition at line 302 of file mathplot.h.

302 { m_visible = show; };
bool m_visible
Definition: mathplot.h:322

Referenced by mpWindow::SetLayerVisible(), SIM_PLOT_PANEL::ShowLegend(), and SIM_PLOT_PANEL::SIM_PLOT_PANEL().

◆ ShapeUpdated()

void mpMovableObject::ShapeUpdated ( )
protectedinherited

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.

Definition at line 3077 of file mathplot.cpp.

3078 {
3079  // Just in case...
3080  if( m_shape_xs.size() != m_shape_ys.size() )
3081  {
3082  }
3083  else
3084  {
3085  double ccos = cos( m_reference_phi ); // Avoid computing cos/sin twice.
3086  double csin = sin( m_reference_phi );
3087 
3088  m_trans_shape_xs.resize( m_shape_xs.size() );
3089  m_trans_shape_ys.resize( m_shape_xs.size() );
3090 
3091  std::vector<double>::iterator itXi, itXo;
3092  std::vector<double>::iterator itYi, itYo;
3093 
3094  m_bbox_min_x = 1e300;
3095  m_bbox_max_x = -1e300;
3096  m_bbox_min_y = 1e300;
3097  m_bbox_max_y = -1e300;
3098 
3099  for( itXo = m_trans_shape_xs.begin(),
3100  itYo = m_trans_shape_ys.begin(), itXi = m_shape_xs.begin(), itYi = m_shape_ys.begin();
3101  itXo!=m_trans_shape_xs.end(); itXo++, itYo++, itXi++, itYi++ )
3102  {
3103  *itXo = m_reference_x + ccos * (*itXi) - csin * (*itYi);
3104  *itYo = m_reference_y + csin * (*itXi) + ccos * (*itYi);
3105 
3106  // Keep BBox:
3107  if( *itXo < m_bbox_min_x )
3108  m_bbox_min_x = *itXo;
3109 
3110  if( *itXo > m_bbox_max_x )
3111  m_bbox_max_x = *itXo;
3112 
3113  if( *itYo < m_bbox_min_y )
3114  m_bbox_min_y = *itYo;
3115 
3116  if( *itYo > m_bbox_max_y )
3117  m_bbox_max_y = *itYo;
3118  }
3119  }
3120 }
std::vector< double > m_trans_shape_ys
Definition: mathplot.h:1814
double m_reference_x
The coordinates of the object (orientation "phi" is in radians).
Definition: mathplot.h:1799
double m_bbox_max_y
Definition: mathplot.h:1819
double m_bbox_min_x
The precomputed bounding box:
Definition: mathplot.h:1819
double m_reference_y
Definition: mathplot.h:1799
std::vector< double > m_shape_ys
Definition: mathplot.h:1809
std::vector< double > m_trans_shape_xs
The buffer for the translated & rotated points (to avoid recomputing them with each mpWindow refresh)...
Definition: mathplot.h:1814
double m_reference_phi
Definition: mathplot.h:1799
double m_bbox_max_x
Definition: mathplot.h:1819
std::vector< double > m_shape_xs
This contains the object points, in local coordinates (to be transformed by the current transformatio...
Definition: mathplot.h:1809
double m_bbox_min_y
Definition: mathplot.h:1819

References mpMovableObject::m_bbox_max_x, mpMovableObject::m_bbox_max_y, mpMovableObject::m_bbox_min_x, mpMovableObject::m_bbox_min_y, mpMovableObject::m_reference_phi, mpMovableObject::m_reference_x, mpMovableObject::m_reference_y, mpMovableObject::m_shape_xs, mpMovableObject::m_shape_ys, mpMovableObject::m_trans_shape_xs, and mpMovableObject::m_trans_shape_ys.

Referenced by RecalculateShape(), and mpPolygon::setPoints().

◆ ShowName()

void mpLayer::ShowName ( bool  show)
inlineinherited

Shows or hides the text label with the name of the layer (default is visible).

Definition at line 262 of file mathplot.h.

262 { m_showName = show; };
bool m_showName
Definition: mathplot.h:319

Referenced by TRACE::TRACE().

◆ TranslatePoint()

void mpMovableObject::TranslatePoint ( double  x,
double  y,
double &  out_x,
double &  out_y 
)
protectedinherited

A method for 2D translation and rotation, using the current transformation stored in m_reference_x,m_reference_y,m_reference_phi.

Definition at line 3066 of file mathplot.cpp.

3067 {
3068  double ccos = cos( m_reference_phi ); // Avoid computing cos/sin twice.
3069  double csin = sin( m_reference_phi );
3070 
3071  out_x = m_reference_x + ccos * x - csin * y;
3072  out_y = m_reference_y + csin * x + ccos * y;
3073 }
double m_reference_x
The coordinates of the object (orientation "phi" is in radians).
Definition: mathplot.h:1799
double m_reference_y
Definition: mathplot.h:1799
double m_reference_phi
Definition: mathplot.h:1799

References mpMovableObject::m_reference_phi, mpMovableObject::m_reference_x, and mpMovableObject::m_reference_y.

Member Data Documentation

◆ m_bbox_max_x

double mpMovableObject::m_bbox_max_x
protectedinherited

Definition at line 1819 of file mathplot.h.

Referenced by mpMovableObject::Plot(), and mpMovableObject::ShapeUpdated().

◆ m_bbox_max_y

double mpMovableObject::m_bbox_max_y
protectedinherited

Definition at line 1819 of file mathplot.h.

Referenced by mpMovableObject::Plot(), and mpMovableObject::ShapeUpdated().

◆ m_bbox_min_x

double mpMovableObject::m_bbox_min_x
protectedinherited

The precomputed bounding box:

See also
ShapeUpdated

Definition at line 1819 of file mathplot.h.

Referenced by mpMovableObject::ShapeUpdated().

◆ m_bbox_min_y

double mpMovableObject::m_bbox_min_y
protectedinherited

Definition at line 1819 of file mathplot.h.

Referenced by mpMovableObject::ShapeUpdated().

◆ m_brush

wxBrush mpLayer::m_brush
protectedinherited

Definition at line 316 of file mathplot.h.

◆ m_continuous

bool mpLayer::m_continuous
protectedinherited

Definition at line 318 of file mathplot.h.

Referenced by CURSOR::Plot(), mpFXY::Plot(), and mpMovableObject::Plot().

◆ m_cov_00

double mpCovarianceEllipse::m_cov_00
protected

The elements of the matrix (only 3 since cov(0,1)=cov(1,0) in any positive definite matrix).

Definition at line 1904 of file mathplot.h.

Referenced by RecalculateShape().

◆ m_cov_01

double mpCovarianceEllipse::m_cov_01
protected

Definition at line 1904 of file mathplot.h.

Referenced by RecalculateShape().

◆ m_cov_11

double mpCovarianceEllipse::m_cov_11
protected

Definition at line 1904 of file mathplot.h.

Referenced by RecalculateShape().

◆ m_drawOutsideMargins

◆ m_flags

int mpMovableObject::m_flags
protectedinherited

Definition at line 1792 of file mathplot.h.

Referenced by mpMovableObject::Plot().

◆ m_font

◆ m_name

wxString mpLayer::m_name
protectedinherited

◆ m_pen

◆ m_quantiles

double mpCovarianceEllipse::m_quantiles
protected

Definition at line 1905 of file mathplot.h.

Referenced by RecalculateShape().

◆ m_reference_phi

double mpMovableObject::m_reference_phi
protectedinherited

Definition at line 1799 of file mathplot.h.

Referenced by mpMovableObject::ShapeUpdated(), and mpMovableObject::TranslatePoint().

◆ m_reference_x

double mpMovableObject::m_reference_x
protectedinherited

The coordinates of the object (orientation "phi" is in radians).

Definition at line 1799 of file mathplot.h.

Referenced by mpMovableObject::ShapeUpdated(), and mpMovableObject::TranslatePoint().

◆ m_reference_y

double mpMovableObject::m_reference_y
protectedinherited

Definition at line 1799 of file mathplot.h.

Referenced by mpMovableObject::ShapeUpdated(), and mpMovableObject::TranslatePoint().

◆ m_segments

int mpCovarianceEllipse::m_segments
protected

The number of line segments that build up the ellipse.

Definition at line 1909 of file mathplot.h.

Referenced by RecalculateShape().

◆ m_shape_xs

std::vector<double> mpMovableObject::m_shape_xs
protectedinherited

This contains the object points, in local coordinates (to be transformed by the current transformation).

Definition at line 1809 of file mathplot.h.

Referenced by RecalculateShape(), mpPolygon::setPoints(), and mpMovableObject::ShapeUpdated().

◆ m_shape_ys

std::vector<double> mpMovableObject::m_shape_ys
protectedinherited

◆ m_showName

bool mpLayer::m_showName
protectedinherited

◆ m_trans_shape_xs

std::vector<double> mpMovableObject::m_trans_shape_xs
protectedinherited

The buffer for the translated & rotated points (to avoid recomputing them with each mpWindow refresh).

Definition at line 1814 of file mathplot.h.

Referenced by mpMovableObject::Plot(), and mpMovableObject::ShapeUpdated().

◆ m_trans_shape_ys

std::vector<double> mpMovableObject::m_trans_shape_ys
protectedinherited

Definition at line 1814 of file mathplot.h.

Referenced by mpMovableObject::Plot(), and mpMovableObject::ShapeUpdated().

◆ m_type

mpLayerType mpLayer::m_type
protectedinherited

Definition at line 321 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer().

◆ m_visible


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