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 () override
 Check whether this layer has a bounding box. More...
 
virtual double GetMinX () override
 Get inclusive left border of bounding box. More...
 
virtual double GetMaxX () override
 Get inclusive right border of bounding box. More...
 
virtual double GetMinY () override
 Get inclusive bottom border of bounding box. More...
 
virtual double GetMaxY () 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 ()
 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)
 Get a small square bitmap filled with the colour of the pen used in the layer. More...
 
mpLayerType GetLayerType ()
 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 ()
 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 1807 of file mathplot.h.

Constructor & Destructor Documentation

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 1813 of file mathplot.h.

References mpLAYER_PLOT.

1818  :
1819  m_cov_00( cov_00 ),
1820  m_cov_11( cov_11 ),
1821  m_cov_01( cov_01 ),
1822  m_quantiles( quantiles ),
1823  m_segments( segments )
1824  {
1825  m_continuous = true;
1826  m_name = layerName;
1827  RecalculateShape();
1828  m_type = mpLAYER_PLOT;
1829  }
bool m_continuous
Definition: mathplot.h:317
void RecalculateShape()
Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes.
Definition: mathplot.cpp:3756
int m_segments
The number of line segments that build up the ellipse.
Definition: mathplot.h:1873
mpLayerType m_type
Definition: mathplot.h:320
wxString m_name
Definition: mathplot.h:316
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:1868
virtual mpCovarianceEllipse::~mpCovarianceEllipse ( )
inlinevirtual

Definition at line 1831 of file mathplot.h.

1831 {}

Member Function Documentation

const wxBrush& mpLayer::GetBrush ( ) const
inlineinherited

Get brush set for this layer.

Returns
brush.

Definition at line 305 of file mathplot.h.

305 { return m_brush; };
wxBrush m_brush
Definition: mathplot.h:315
wxBitmap mpLayer::GetColourSquare ( int  side = 16)
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 83 of file mathplot.cpp.

References mpLayer::m_pen.

84 {
85  wxBitmap square( side, side, -1 );
86  wxColour filler = m_pen.GetColour();
87  wxBrush brush( filler, wxBRUSHSTYLE_SOLID );
88  wxMemoryDC dc;
89 
90  dc.SelectObject( square );
91  dc.SetBackground( brush );
92  dc.Clear();
93  dc.SelectObject( wxNullBitmap );
94  return square;
95 }
wxPen m_pen
Definition: mathplot.h:314
bool mpLayer::GetContinuity ( ) const
inlineinherited

Gets the 'continuity' property of the layer.

See also
SetContinuity

Definition at line 257 of file mathplot.h.

257 { return m_continuous; }
bool m_continuous
Definition: mathplot.h:317
void mpMovableObject::GetCoordinateBase ( double &  x,
double &  y,
double &  phi 
) const
inlineinherited

Get the current coordinate transformation.

Definition at line 1716 of file mathplot.h.

1717  {
1718  x = m_reference_x;
1719  y = m_reference_y;
1720  phi = m_reference_phi;
1721  }
double m_reference_x
The coordinates of the object (orientation "phi" is in radians).
Definition: mathplot.h:1764
double m_reference_y
Definition: mathplot.h:1764
double m_reference_phi
Definition: mathplot.h:1764
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 1848 of file mathplot.h.

1849  {
1850  cov_00 = m_cov_00;
1851  cov_01 = m_cov_01;
1852  cov_11 = m_cov_11;
1853  }
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:1868
bool mpLayer::GetDrawOutsideMargins ( )
inlineinherited

Get Draw mode: inside or outside margins.

Returns
The draw mode

Definition at line 284 of file mathplot.h.

284 { return m_drawOutsideMargins; };
bool m_drawOutsideMargins
Definition: mathplot.h:319
const wxFont& mpLayer::GetFont ( ) const
inlineinherited

Get font set for this layer.

Returns
Font

Definition at line 242 of file mathplot.h.

242 { return m_font; }
wxFont m_font
Definition: mathplot.h:309
mpLayerType mpLayer::GetLayerType ( )
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 293 of file mathplot.h.

Referenced by mpInfoLegend::Plot().

293 { return m_type; };
mpLayerType m_type
Definition: mathplot.h:320
virtual double mpMovableObject::GetMaxX ( )
inlineoverridevirtualinherited

Get inclusive right border of bounding box.

Reimplemented from mpLayer.

Definition at line 1742 of file mathplot.h.

1742 { return m_bbox_max_x; }
double m_bbox_max_x
Definition: mathplot.h:1784
virtual double mpMovableObject::GetMaxY ( )
inlineoverridevirtualinherited

Get inclusive top border of bounding box.

Reimplemented from mpLayer.

Definition at line 1750 of file mathplot.h.

1750 { return m_bbox_max_y; }
double m_bbox_max_y
Definition: mathplot.h:1784
virtual double mpMovableObject::GetMinX ( )
inlineoverridevirtualinherited

Get inclusive left border of bounding box.

Reimplemented from mpLayer.

Definition at line 1738 of file mathplot.h.

1738 { return m_bbox_min_x; }
double m_bbox_min_x
The precomputed bounding box:
Definition: mathplot.h:1784
virtual double mpMovableObject::GetMinY ( )
inlineoverridevirtualinherited

Get inclusive bottom border of bounding box.

Reimplemented from mpLayer.

Definition at line 1746 of file mathplot.h.

1746 { return m_bbox_min_y; }
double m_bbox_min_y
Definition: mathplot.h:1784
const wxString& mpLayer::GetName ( void  ) const
inlineinherited

Get layer name.

Returns
Name

Definition at line 237 of file mathplot.h.

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

237 { return m_name; }
wxString m_name
Definition: mathplot.h:316
const wxPen& mpLayer::GetPen ( ) const
inlineinherited

Get pen set for this layer.

Returns
Pen

Definition at line 247 of file mathplot.h.

Referenced by mpInfoLegend::Plot().

247 { return m_pen; }
wxPen m_pen
Definition: mathplot.h:314
double mpCovarianceEllipse::GetQuantiles ( ) const
inline

Definition at line 1833 of file mathplot.h.

1833 { return m_quantiles; }
int mpCovarianceEllipse::GetSegments ( ) const
inline

Definition at line 1844 of file mathplot.h.

1844 { return m_segments; }
int m_segments
The number of line segments that build up the ellipse.
Definition: mathplot.h:1873
virtual bool mpMovableObject::HasBBox ( )
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 1734 of file mathplot.h.

1734 { 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:1779
virtual bool mpLayer::IsInfo ( )
inlinevirtualinherited

Check whether the layer is an info box.

The default implementation returns FALSE. It is overrided 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 169 of file mathplot.h.

169 { return false; };
bool mpLayer::IsVisible ( )
inlineinherited

Checks whether the layer is visible or not.

Returns
true if visible

Definition at line 297 of file mathplot.h.

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

297 { return m_visible; };
bool m_visible
Definition: mathplot.h:321
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 3651 of file mathplot.cpp.

References mpWindow::GetPosX(), mpWindow::GetPosY(), mpWindow::GetScaleX(), mpWindow::GetScaleY(), mpWindow::GetScrX(), mpWindow::GetScrY(), mpALIGN_NE, mpALIGN_NW, mpALIGN_SW, mpALIGNMASK, mpWindow::x2p(), and mpWindow::y2p().

3652 {
3653  if( m_visible )
3654  {
3655  dc.SetPen( m_pen );
3656 
3657 
3658  std::vector<double>::iterator itX = m_trans_shape_xs.begin();
3659  std::vector<double>::iterator itY = m_trans_shape_ys.begin();
3660 
3661  if( !m_continuous )
3662  {
3663  // for some reason DrawPoint does not use the current pen,
3664  // so we use DrawLine for fat pens
3665  if( m_pen.GetWidth() <= 1 )
3666  {
3667  while( itX!=m_trans_shape_xs.end() )
3668  {
3669  dc.DrawPoint( w.x2p( *(itX++) ), w.y2p( *(itY++) ) );
3670  }
3671  }
3672  else
3673  {
3674  while( itX!=m_trans_shape_xs.end() )
3675  {
3676  wxCoord cx = w.x2p( *(itX++) );
3677  wxCoord cy = w.y2p( *(itY++) );
3678  dc.DrawLine( cx, cy, cx, cy );
3679  }
3680  }
3681  }
3682  else
3683  {
3684  wxCoord cx0 = 0, cy0 = 0;
3685  bool first = true;
3686 
3687  while( itX!=m_trans_shape_xs.end() )
3688  {
3689  wxCoord cx = w.x2p( *(itX++) );
3690  wxCoord cy = w.y2p( *(itY++) );
3691 
3692  if( first )
3693  {
3694  first = false;
3695  cx0 = cx; cy0 = cy;
3696  }
3697 
3698  dc.DrawLine( cx0, cy0, cx, cy );
3699  cx0 = cx; cy0 = cy;
3700  }
3701  }
3702 
3703  if( !m_name.IsEmpty() && m_showName )
3704  {
3705  dc.SetFont( m_font );
3706 
3707  wxCoord tx, ty;
3708  dc.GetTextExtent( m_name, &tx, &ty );
3709 
3710  if( HasBBox() )
3711  {
3712  wxCoord sx = (wxCoord) ( ( m_bbox_max_x - w.GetPosX() ) * w.GetScaleX() );
3713  wxCoord sy = (wxCoord) ( (w.GetPosY() - m_bbox_max_y ) * w.GetScaleY() );
3714 
3715  tx = sx - tx - 8;
3716  ty = sy - 8 - ty;
3717  }
3718  else
3719  {
3720  const int sx = w.GetScrX() >> 1;
3721  const int sy = w.GetScrY() >> 1;
3722 
3723  if( (m_flags & mpALIGNMASK) == mpALIGN_NE )
3724  {
3725  tx = sx - tx - 8;
3726  ty = -sy + 8;
3727  }
3728  else if( (m_flags & mpALIGNMASK) == mpALIGN_NW )
3729  {
3730  tx = -sx + 8;
3731  ty = -sy + 8;
3732  }
3733  else if( (m_flags & mpALIGNMASK) == mpALIGN_SW )
3734  {
3735  tx = -sx + 8;
3736  ty = sy - 8 - ty;
3737  }
3738  else
3739  {
3740  tx = sx - tx - 8;
3741  ty = sy - 8 - ty;
3742  }
3743  }
3744 
3745  dc.DrawText( m_name, tx, ty );
3746  }
3747  }
3748 }
bool m_continuous
Definition: mathplot.h:317
#define mpALIGN_NW
Aligns label to north-west.
Definition: mathplot.h:506
std::vector< double > m_trans_shape_ys
Definition: mathplot.h:1779
int GetScrY(void) const
Get current view&#39;s Y dimension in device context units.
Definition: mathplot.h:1140
double GetPosY(void) const
Definition: mathplot.h:1123
bool m_visible
Definition: mathplot.h:321
double m_bbox_max_y
Definition: mathplot.h:1784
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1200
virtual bool HasBBox() override
Check whether this layer has a bounding box.
Definition: mathplot.h:1734
double GetPosX(void) const
Definition: mathplot.h:1116
wxFont m_font
Definition: mathplot.h:309
#define mpALIGN_NE
Aligns label to north-east.
Definition: mathplot.h:504
int GetScrX(void) const
Get current view&#39;s X dimension in device context units.
Definition: mathplot.h:1131
double GetScaleY(void) const
Definition: mathplot.h:1109
double GetScaleX(void) const
Definition: mathplot.h:1102
#define mpALIGNMASK
Definition: mathplot.h:474
bool m_showName
Definition: mathplot.h:318
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1195
wxPen m_pen
Definition: mathplot.h:314
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:1779
wxString m_name
Definition: mathplot.h:316
double m_bbox_max_x
Definition: mathplot.h:1784
#define mpALIGN_SW
Aligns label to south-west.
Definition: mathplot.h:508
void mpCovarianceEllipse::RecalculateShape ( )
protected

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

Definition at line 3756 of file mathplot.cpp.

References D, and i.

3757 {
3758  m_shape_xs.clear();
3759  m_shape_ys.clear();
3760 
3761  // Preliminar checks:
3762  if( m_quantiles<0 )
3763  {
3764  wxLogError( wxT( "[mpCovarianceEllipse] Error: quantiles must be non-negative" ) ); return;
3765  }
3766 
3767  if( m_cov_00<0 )
3768  {
3769  wxLogError( wxT( "[mpCovarianceEllipse] Error: cov(0,0) must be non-negative" ) ); return;
3770  }
3771 
3772  if( m_cov_11<0 )
3773  {
3774  wxLogError( wxT( "[mpCovarianceEllipse] Error: cov(1,1) must be non-negative" ) ); return;
3775  }
3776 
3777  m_shape_xs.resize( m_segments, 0 );
3778  m_shape_ys.resize( m_segments, 0 );
3779 
3780  // Compute the two eigenvalues of the covariance:
3781  // -------------------------------------------------
3782  double b = -m_cov_00 - m_cov_11;
3783  double c = m_cov_00 * m_cov_11 - m_cov_01 * m_cov_01;
3784 
3785  double D = b * b - 4 * c;
3786 
3787  if( D<0 )
3788  {
3789  wxLogError( wxT( "[mpCovarianceEllipse] Error: cov is not positive definite" ) ); return;
3790  }
3791 
3792  double eigenVal0 = 0.5 * ( -b + sqrt( D ) );
3793  double eigenVal1 = 0.5 * ( -b - sqrt( D ) );
3794 
3795  // Compute the two corresponding eigenvectors:
3796  // -------------------------------------------------
3797  double eigenVec0_x, eigenVec0_y;
3798  double eigenVec1_x, eigenVec1_y;
3799 
3800  if( fabs( eigenVal0 - m_cov_00 )>1e-6 )
3801  {
3802  double k1x = m_cov_01 / ( eigenVal0 - m_cov_00 );
3803  eigenVec0_y = 1;
3804  eigenVec0_x = eigenVec0_y * k1x;
3805  }
3806  else
3807  {
3808  double k1y = m_cov_01 / ( eigenVal0 - m_cov_11 );
3809  eigenVec0_x = 1;
3810  eigenVec0_y = eigenVec0_x * k1y;
3811  }
3812 
3813  if( fabs( eigenVal1 - m_cov_00 )>1e-6 )
3814  {
3815  double k2x = m_cov_01 / ( eigenVal1 - m_cov_00 );
3816  eigenVec1_y = 1;
3817  eigenVec1_x = eigenVec1_y * k2x;
3818  }
3819  else
3820  {
3821  double k2y = m_cov_01 / ( eigenVal1 - m_cov_11 );
3822  eigenVec1_x = 1;
3823  eigenVec1_y = eigenVec1_x * k2y;
3824  }
3825 
3826  // Normalize the eigenvectors:
3827  double len = sqrt( eigenVec0_x * eigenVec0_x + eigenVec0_y * eigenVec0_y );
3828  eigenVec0_x /= len; // It *CANNOT* be zero
3829  eigenVec0_y /= len;
3830 
3831  len = sqrt( eigenVec1_x * eigenVec1_x + eigenVec1_y * eigenVec1_y );
3832  eigenVec1_x /= len; // It *CANNOT* be zero
3833  eigenVec1_y /= len;
3834 
3835 
3836  // Take the sqrt of the eigenvalues (required for the ellipse scale):
3837  eigenVal0 = sqrt( eigenVal0 );
3838  eigenVal1 = sqrt( eigenVal1 );
3839 
3840  // Compute the 2x2 matrix M = diag(eigVal) * (~eigVec) (each eigen vector is a row):
3841  double M_00 = eigenVec0_x * eigenVal0;
3842  double M_01 = eigenVec0_y * eigenVal0;
3843 
3844  double M_10 = eigenVec1_x * eigenVal1;
3845  double M_11 = eigenVec1_y * eigenVal1;
3846 
3847  // The points of the 2D ellipse:
3848  double ang;
3849  double Aang = 6.283185308 / (m_segments - 1);
3850  int i;
3851 
3852  for( i = 0, ang = 0; i<m_segments; i++, ang += Aang )
3853  {
3854  double ccos = cos( ang );
3855  double csin = sin( ang );
3856 
3857  m_shape_xs[i] = m_quantiles * (ccos * M_00 + csin * M_10 );
3858  m_shape_ys[i] = m_quantiles * (ccos * M_01 + csin * M_11 );
3859  } // end for points on ellipse
3860 
3861  ShapeUpdated();
3862 }
int m_segments
The number of line segments that build up the ellipse.
Definition: mathplot.h:1873
void ShapeUpdated()
Must be called by the descendent class after updating the shape (m_shape_xs/ys), or when the transfor...
Definition: mathplot.cpp:3603
#define D(x)
Definition: ptree.cpp:41
size_t i
Definition: json11.cpp:597
std::vector< double > m_shape_ys
Definition: mathplot.h:1774
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:1868
std::vector< double > m_shape_xs
This contains the object points, in local coordinates (to be transformed by the current transformatio...
Definition: mathplot.h:1774
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 1757 of file mathplot.h.

1757 { m_flags = align; };
void mpLayer::SetBrush ( wxBrush  brush)
inlineinherited

Set layer brush.

Parameters
brushbrush, will be copied to internal class member

Definition at line 309 of file mathplot.h.

309 { m_brush = brush; };
wxBrush m_brush
Definition: mathplot.h:315
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 252 of file mathplot.h.

Referenced by TRACE::TRACE().

252 { m_continuous = continuity; }
bool m_continuous
Definition: mathplot.h:317
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 1725 of file mathplot.h.

References mpALIGN_NE.

1726  {
1727  m_reference_x = x;
1728  m_reference_y = y;
1729  m_reference_phi = phi;
1730  m_flags = mpALIGN_NE;
1731  ShapeUpdated();
1732  }
double m_reference_x
The coordinates of the object (orientation "phi" is in radians).
Definition: mathplot.h:1764
void ShapeUpdated()
Must be called by the descendent class after updating the shape (m_shape_xs/ys), or when the transfor...
Definition: mathplot.cpp:3603
double m_reference_y
Definition: mathplot.h:1764
#define mpALIGN_NE
Aligns label to north-east.
Definition: mathplot.h:504
double m_reference_phi
Definition: mathplot.h:1764
void mpCovarianceEllipse::SetCovarianceMatrix ( double  cov_00,
double  cov_01,
double  cov_11 
)
inline

Changes the covariance matrix:

Definition at line 1857 of file mathplot.h.

1858  {
1859  m_cov_00 = cov_00;
1860  m_cov_01 = cov_01;
1861  m_cov_11 = cov_11;
1862  RecalculateShape();
1863  }
void RecalculateShape()
Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes.
Definition: mathplot.cpp:3756
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:1868
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 280 of file mathplot.h.

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

280 { m_drawOutsideMargins = drawModeOutside; };
bool m_drawOutsideMargins
Definition: mathplot.h:319
void mpLayer::SetFont ( wxFont &  font)
inlineinherited

Set layer font.

Parameters
fontFont, will be copied to internal class member

Definition at line 271 of file mathplot.h.

Referenced by mpScaleXBase::mpScaleXBase(), and mpScaleY::mpScaleY().

271 { m_font = font; }
wxFont m_font
Definition: mathplot.h:309
void mpLayer::SetName ( wxString  name)
inlineinherited

Set layer name.

Parameters
nameName, will be copied to internal class member

Definition at line 266 of file mathplot.h.

References name.

Referenced by mpFX::mpFX(), mpFXY::mpFXY(), mpFY::mpFY(), mpProfile::mpProfile(), mpScaleXBase::mpScaleXBase(), mpScaleY::mpScaleY(), and mpText::mpText().

266 { m_name = name; }
const char * name
Definition: DXF_plotter.cpp:61
wxString m_name
Definition: mathplot.h:316
void mpLayer::SetPen ( wxPen  pen)
inlineinherited

Set layer pen.

Parameters
penPen, will be copied to internal class member

Definition at line 276 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::AddTrace(), mpScaleXBase::mpScaleXBase(), and mpScaleY::mpScaleY().

276 { m_pen = pen; }
wxPen m_pen
Definition: mathplot.h:314
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 1837 of file mathplot.h.

1838  {
1839  m_quantiles = q;
1840  RecalculateShape();
1841  }
void RecalculateShape()
Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes.
Definition: mathplot.cpp:3756
void mpCovarianceEllipse::SetSegments ( int  segments)
inline

Definition at line 1843 of file mathplot.h.

1843 { m_segments = segments; }
int m_segments
The number of line segments that build up the ellipse.
Definition: mathplot.h:1873
void mpLayer::SetVisible ( bool  show)
inlineinherited

Sets layer visibility.

Parameters
showvisibility bool.

Definition at line 301 of file mathplot.h.

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

301 { m_visible = show; };
bool m_visible
Definition: mathplot.h:321
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 3603 of file mathplot.cpp.

3604 {
3605  // Just in case...
3606  if( m_shape_xs.size()!=m_shape_ys.size() )
3607  {
3608  wxLogError( wxT(
3609  "[mpMovableObject::ShapeUpdated] Error, m_shape_xs and m_shape_ys have different lengths!" ) );
3610  }
3611  else
3612  {
3613  double ccos = cos( m_reference_phi ); // Avoid computing cos/sin twice.
3614  double csin = sin( m_reference_phi );
3615 
3616  m_trans_shape_xs.resize( m_shape_xs.size() );
3617  m_trans_shape_ys.resize( m_shape_xs.size() );
3618 
3619  std::vector<double>::iterator itXi, itXo;
3620  std::vector<double>::iterator itYi, itYo;
3621 
3622  m_bbox_min_x = 1e300;
3623  m_bbox_max_x = -1e300;
3624  m_bbox_min_y = 1e300;
3625  m_bbox_max_y = -1e300;
3626 
3627  for( itXo = m_trans_shape_xs.begin(),
3628  itYo = m_trans_shape_ys.begin(), itXi = m_shape_xs.begin(), itYi = m_shape_ys.begin();
3629  itXo!=m_trans_shape_xs.end(); itXo++, itYo++, itXi++, itYi++ )
3630  {
3631  *itXo = m_reference_x + ccos * (*itXi) - csin * (*itYi);
3632  *itYo = m_reference_y + csin * (*itXi) + ccos * (*itYi);
3633 
3634  // Keep BBox:
3635  if( *itXo < m_bbox_min_x )
3636  m_bbox_min_x = *itXo;
3637 
3638  if( *itXo > m_bbox_max_x )
3639  m_bbox_max_x = *itXo;
3640 
3641  if( *itYo < m_bbox_min_y )
3642  m_bbox_min_y = *itYo;
3643 
3644  if( *itYo > m_bbox_max_y )
3645  m_bbox_max_y = *itYo;
3646  }
3647  }
3648 }
std::vector< double > m_trans_shape_ys
Definition: mathplot.h:1779
double m_reference_x
The coordinates of the object (orientation "phi" is in radians).
Definition: mathplot.h:1764
double m_bbox_max_y
Definition: mathplot.h:1784
double m_bbox_min_x
The precomputed bounding box:
Definition: mathplot.h:1784
double m_reference_y
Definition: mathplot.h:1764
std::vector< double > m_shape_ys
Definition: mathplot.h:1774
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:1779
double m_reference_phi
Definition: mathplot.h:1764
double m_bbox_max_x
Definition: mathplot.h:1784
std::vector< double > m_shape_xs
This contains the object points, in local coordinates (to be transformed by the current transformatio...
Definition: mathplot.h:1774
double m_bbox_min_y
Definition: mathplot.h:1784
void mpLayer::ShowName ( bool  show)
inlineinherited

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

Definition at line 261 of file mathplot.h.

Referenced by TRACE::TRACE().

261 { m_showName = show; };
bool m_showName
Definition: mathplot.h:318
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 3592 of file mathplot.cpp.

3593 {
3594  double ccos = cos( m_reference_phi ); // Avoid computing cos/sin twice.
3595  double csin = sin( m_reference_phi );
3596 
3597  out_x = m_reference_x + ccos * x - csin * y;
3598  out_y = m_reference_y + csin * x + ccos * y;
3599 }
double m_reference_x
The coordinates of the object (orientation "phi" is in radians).
Definition: mathplot.h:1764
double m_reference_y
Definition: mathplot.h:1764
double m_reference_phi
Definition: mathplot.h:1764

Member Data Documentation

double mpMovableObject::m_bbox_max_x
protectedinherited

Definition at line 1784 of file mathplot.h.

double mpMovableObject::m_bbox_max_y
protectedinherited

Definition at line 1784 of file mathplot.h.

double mpMovableObject::m_bbox_min_x
protectedinherited

The precomputed bounding box:

See also
ShapeUpdated

Definition at line 1784 of file mathplot.h.

double mpMovableObject::m_bbox_min_y
protectedinherited

Definition at line 1784 of file mathplot.h.

wxBrush mpLayer::m_brush
protectedinherited

Definition at line 315 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer().

bool mpLayer::m_continuous
protectedinherited

Definition at line 317 of file mathplot.h.

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

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 1868 of file mathplot.h.

double mpCovarianceEllipse::m_cov_01
protected

Definition at line 1868 of file mathplot.h.

double mpCovarianceEllipse::m_cov_11
protected

Definition at line 1868 of file mathplot.h.

int mpMovableObject::m_flags
protectedinherited

Definition at line 1757 of file mathplot.h.

wxFont mpLayer::m_font
protectedinherited
wxString mpLayer::m_name
protectedinherited
double mpCovarianceEllipse::m_quantiles
protected

Definition at line 1869 of file mathplot.h.

double mpMovableObject::m_reference_phi
protectedinherited

Definition at line 1764 of file mathplot.h.

double mpMovableObject::m_reference_x
protectedinherited

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

Definition at line 1764 of file mathplot.h.

double mpMovableObject::m_reference_y
protectedinherited

Definition at line 1764 of file mathplot.h.

int mpCovarianceEllipse::m_segments
protected

The number of line segments that build up the ellipse.

Definition at line 1873 of file mathplot.h.

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 1774 of file mathplot.h.

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

Definition at line 1774 of file mathplot.h.

bool mpLayer::m_showName
protectedinherited

Definition at line 318 of file mathplot.h.

Referenced by mpFX::Plot(), mpFY::Plot(), and mpFXY::Plot().

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 1779 of file mathplot.h.

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

Definition at line 1779 of file mathplot.h.


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