A fuzzy logic C++ library
|
Root pure virtual class for PLOT_FS and PLOT_MF. Is NOT designed to be used by library end users,. More...
#include <plot_fuzzy.hpp>
Public Member Functions | |
void | Set_NbDec (int v) |
Assign nb of decimal points on which a value is printed on plot. | |
void | SetAutoScale (bool b) |
void | Set_ShowPointValues (bool b) |
Show or don't show the points values next to them on horizontal axis. | |
void | Set_ThickLine (bool b) |
This function is empty and is there only to provide a default implementation of the virtual function, see re-implementations. | |
void | Set_DrawVertLines (bool b) |
void | Set_ShowXValues (bool b) |
Show or don't show the points x values on horizontal axis. | |
bool | HasScale () const |
void | SetScale (PLOT_HSCALE s) |
Assigns the scale scale to the plot, and switch off autoscaling. | |
void | SetScale (const PLOT_FUZZY &other) |
Assigns the scale scale to the plot, and switch off autoscaling. | |
PLOT_HSCALE | GetScale () const |
This is used to fetch the scale of a previously scale of the plot. | |
void | TransformCoordS2R (int x, int y, double &real_x, double &real_y) |
Transform Screen coordinates (x,y) in pixel units, to "Real" coordinates (real_x, real_y), in user space. | |
void | TransformCoordR2S (int &x, int &y, double real_x, double real_y) |
Transform Real coordinates (real and fuzzy values) to Screen coordinates (pixel units) | |
bool | Draw () |
Computes scale and draws plot. | |
void | DrawPoint (slifis::FPOINT pt, GAPI_COLOR col=GAPI_BuildColor(50, 50, 50)) |
Draw point on plot. | |
void | DrawPoint (slifis::REALVAL x, slifis::FUZZYVAL y, GAPI_COLOR col=GAPI_BuildColor(50, 50, 50)) |
Draw point on plot. | |
void | SetCaption (std::string s) |
void | Resize (int w, int h) |
Changes size of plot. | |
virtual void | DrawValue (slifis::REALVAL x, GAPI_COLOR col)=0 |
virtual std::string | GetPlotName () const =0 |
Protected Member Functions | |
PLOT_FUZZY (size_t w, size_t h) | |
Constructor. | |
virtual | ~PLOT_FUZZY () |
void | P_DrawAxis () |
Draw axis. | |
void | P_DrawVLine2Point (const slifis::FPOINT &p) |
Draw vertical line between x axis and point p . | |
virtual bool | P_ComputeScale ()=0 |
virtual void | P_DrawPlot ()=0 |
void | P_DrawMembFunc (const slifis::MEMBFUNC &mf, const GAPI_COLOR col) |
Draws the function mf with color col ,. | |
const char * | P_GetXLabel (slifis::REALVAL val) |
Returns the text label according to value val and defined text format. | |
int | P_GetPixelCoord_x (slifis::REALVAL x) |
Returns pixel horizontal coordinates for real value x . | |
int | P_GetPixelCoord_y (slifis::FUZZYVAL y) |
Returns pixel vertical coordinates for fuzzy value y . | |
slifis::REALVAL | P_GetRealValue (int x) |
Returns real (horizontal) value from pixel coordinates. | |
slifis::FUZZYVAL | P_GetFuzzyValue (int y) |
Returns fuzzy (vertical) value from pixel coordinates. | |
Protected Attributes | |
int | x_yaxis |
Horizontal position of the 'y' axis (pixels) | |
PLOT_HSCALE | _hscale |
int | _x_range |
range in pixels used for the plot (distance between first and last point) | |
int | _x_first |
position in pixel used for first point | |
int | _x_last |
double | y_scale |
Vertical scale. Computed once in constructor. | |
int | y_0 |
vertical pixel position of fuzzy value "0.0" | |
int | y_1 |
vertical pixel position of fuzzy value "1.0" | |
bool | _AutoScale |
if flag is true (default), then each drawing of the plot will recompute the scale so it fits best | |
int | _NbDec |
Number of decimal values, default is 1. | |
char | _format [32] |
Format string. | |
bool | _ShowPointValues |
Show points values next to the points, default is true. | |
bool | _ShowXValues |
Show x values, default is true. | |
bool | _DrawVertLines |
Draw or not vertical lines on plot. | |
int | _LineWidth |
bool | _PreviousScaleAvailable |
std::string | _caption |
optional caption on plot | |
bool | _HasCaption |
Static Protected Attributes | |
Common parameters for drawing fuzzy plots | |
static GAPI_COLOR | col_axis = GAPI_BuildColor( 128 , 128 , 128 ) |
color of axis | |
static GAPI_COLOR | col_txt = GAPI_BuildColor( 0, 128 , 200 ) |
color of txt | |
static GAPI_COLOR | col_vline = GAPI_BuildColor( 200, 200, 200 ) |
color of vertical line to point | |
static GAPI_COLOR | col_xlabel = GAPI_BuildColor( 0, 128 , 50 ) |
color of text of horizontal labels | |
static GAPI_COLOR | col_xtic = GAPI_BuildColor( 30, 0, 0 ) |
color of x tic | |
static GAPI_COLOR | col_point_label = GAPI_BuildColor( 0, 0, 50 ) |
Private Member Functions | |
void | P_ComputeMargins () |
Computes all the margins needed for plotting (private). Depends on image size, so is called by constructor, or after a call to ChangeSize(). Implementation of pure virtual function PLOT::P_ComputeMargins() |
Root pure virtual class for PLOT_FS and PLOT_MF. Is NOT designed to be used by library end users,.
this is why the constructor is protected.
slifis_plot::PLOT_FUZZY::PLOT_FUZZY | ( | size_t | w, |
size_t | h | ||
) | [protected] |
Constructor.
References __IN__, __OUT__, _DrawVertLines, _HasCaption, _LineWidth, slifis_plot::PLOT::_margins, _PreviousScaleAvailable, _ShowPointValues, _ShowXValues, H2_MARGIN, H_FIRST, slifis_plot::PLOT_MARGINS::m_hl, slifis_plot::PLOT_MARGINS::m_hr, slifis_plot::PLOT_MARGINS::m_vb, slifis_plot::PLOT_MARGINS::m_vt, P_ComputeMargins(), slifis_plot::PLOT::s_LineWidth, and Set_NbDec().
slifis_plot::PLOT_FUZZY::~PLOT_FUZZY | ( | ) | [protected, virtual] |
void slifis_plot::PLOT_FUZZY::Set_NbDec | ( | int | v | ) | [virtual] |
Assign nb of decimal points on which a value is printed on plot.
Value is automatically truncated in the range [0-5]
Reimplemented from slifis_plot::PLOT.
References _format, and _NbDec.
Referenced by main(), and PLOT_FUZZY().
void slifis_plot::PLOT_FUZZY::SetAutoScale | ( | bool | b | ) | [inline] |
References _AutoScale.
void slifis_plot::PLOT_FUZZY::Set_ShowPointValues | ( | bool | b | ) | [inline, virtual] |
Show or don't show the points values next to them on horizontal axis.
Reimplemented from slifis_plot::PLOT.
References _ShowPointValues.
void slifis_plot::PLOT_FUZZY::Set_ThickLine | ( | bool | v | ) | [inline, virtual] |
This function is empty and is there only to provide a default implementation of the virtual function, see re-implementations.
Reimplemented from slifis_plot::PLOT.
References _LineWidth.
void slifis_plot::PLOT_FUZZY::Set_DrawVertLines | ( | bool | b | ) | [inline] |
References _DrawVertLines.
Referenced by main().
void slifis_plot::PLOT_FUZZY::Set_ShowXValues | ( | bool | b | ) | [inline] |
Show or don't show the points x values on horizontal axis.
References _ShowXValues.
Referenced by main().
bool slifis_plot::PLOT_FUZZY::HasScale | ( | ) | const [inline] |
References _PreviousScaleAvailable.
Referenced by TransformCoordS2R().
void slifis_plot::PLOT_FUZZY::SetScale | ( | PLOT_HSCALE | s | ) |
Assigns the scale scale
to the plot, and switch off autoscaling.
References _AutoScale, _hscale, and _PreviousScaleAvailable.
Referenced by DrawDefuzz(), main(), Process(), and SetScale().
void slifis_plot::PLOT_FUZZY::SetScale | ( | const PLOT_FUZZY & | other | ) |
Assigns the scale scale
to the plot, and switch off autoscaling.
References GetScale(), and SetScale().
PLOT_HSCALE slifis_plot::PLOT_FUZZY::GetScale | ( | ) | const |
This is used to fetch the scale of a previously scale of the plot.
References __IN__, __OUT__, _hscale, _PreviousScaleAvailable, slifis::ERR_PLOT_NOSCALE, and SLIFIS_ERROR.
Referenced by main(), and SetScale().
void slifis_plot::PLOT_FUZZY::TransformCoordS2R | ( | int | x, |
int | y, | ||
double & | real_x, | ||
double & | real_y | ||
) |
Transform Screen coordinates (x,y) in pixel units, to "Real" coordinates (real_x, real_y), in user space.
References __IN__, __OUT__, slifis::ERR_GAPI_NO_SCALE, HasScale(), P_GetFuzzyValue(), P_GetRealValue(), and SLIFIS_ERROR_1.
Referenced by Process().
void slifis_plot::PLOT_FUZZY::TransformCoordR2S | ( | int & | x, |
int & | y, | ||
double | real_x, | ||
double | real_y | ||
) |
Transform Real coordinates (real and fuzzy values) to Screen coordinates (pixel units)
References P_GetPixelCoord_x(), and P_GetPixelCoord_y().
Referenced by DrawPoint(), P_DrawMembFunc(), slifis_plot::PLOT_MF::P_DrawPlot(), and P_DrawVLine2Point().
bool slifis_plot::PLOT_FUZZY::Draw | ( | ) | [virtual] |
Computes scale and draws plot.
If in 'AutoScale' mode, then if scale is not computable, the previous scale is used (if there is one). If not, an warning is generated, and function returns false.
This function also does the common stuff, before calling the right function (clear image, draw axis, ...)
Implements slifis_plot::PLOT.
References __IN__, __OUT__, _AutoScale, _caption, slifis_plot::PLOT::_p_img, _PreviousScaleAvailable, col_txt, slifis_plot::GAPI_BuildPoint(), slifis_plot::GAPI_DrawText(), slifis_plot::PLOT::GetW(), P_ComputeScale(), P_DrawAxis(), P_DrawPlot(), slifis_plot::PLOT::P_InitDraw(), slifis_plot::plot_data(), and SLIFIS_WARNING.
Referenced by DrawDefuzz(), main(), Process(), and Show().
void slifis_plot::PLOT_FUZZY::DrawPoint | ( | slifis::FPOINT | pt, |
GAPI_COLOR | col = GAPI_BuildColor(50,50,50) |
||
) |
Draw point on plot.
References slifis::FPOINT::GetX(), and slifis::FPOINT::GetY().
Referenced by slifis_plot::PLOT_FS::DrawValue(), slifis_plot::PLOT_MF::DrawValue(), and main().
void slifis_plot::PLOT_FUZZY::DrawPoint | ( | slifis::REALVAL | x, |
slifis::FUZZYVAL | y, | ||
GAPI_COLOR | col = GAPI_BuildColor(50,50,50) |
||
) |
Draw point on plot.
References slifis_plot::PLOT::_margins, slifis_plot::PLOT::_p_img, slifis_plot::PLOT::_txtbuf, col_point_label, slifis_plot::GAPI_BuildPoint(), slifis_plot::GAPI_DrawLine(), slifis_plot::GAPI_DrawText(), slifis_plot::PLOT_MARGINS::m_hl, slifis_plot::plot_data(), TransformCoordR2S(), slifis_plot::GAPI_POINT::x, slifis_plot::GAPI_POINT::y, and y_0.
void slifis_plot::PLOT_FUZZY::SetCaption | ( | std::string | s | ) | [inline] |
References _caption, and _HasCaption.
void slifis_plot::PLOT_FUZZY::Resize | ( | int | w, |
int | h | ||
) |
Changes size of plot.
References __IN__, __OUT__, slifis_plot::PLOT::P_ChangeSize(), and P_ComputeMargins().
Referenced by main().
virtual void slifis_plot::PLOT_FUZZY::DrawValue | ( | slifis::REALVAL | x, |
GAPI_COLOR | col | ||
) | [pure virtual] |
Implemented in slifis_plot::PLOT_MF, and slifis_plot::PLOT_FS.
virtual std::string slifis_plot::PLOT_FUZZY::GetPlotName | ( | ) | const [pure virtual] |
Implements slifis_plot::PLOT.
Implemented in slifis_plot::PLOT_MF, and slifis_plot::PLOT_FS.
void slifis_plot::PLOT_FUZZY::P_DrawAxis | ( | ) | [protected] |
Draw axis.
Assumes font is initialised
References __IN__, __OUT__, slifis_plot::PLOT::_margins, slifis_plot::PLOT::_p_img, _x_last, col_axis, col_vline, col_xtic, slifis_plot::GAPI_BuildPoint(), slifis_plot::GAPI_DrawLine(), slifis_plot::GAPI_DrawText(), slifis_plot::PLOT::GetW(), H_FIRST, slifis_plot::PLOT_MARGINS::m_hl, slifis_plot::PLOT_MARGINS::m_vt, slifis_plot::plot_data(), x_yaxis, y_0, and y_1.
Referenced by Draw().
void slifis_plot::PLOT_FUZZY::P_DrawVLine2Point | ( | const slifis::FPOINT & | p | ) | [protected] |
Draw vertical line between x axis and point p
.
References __IN__, __OUT__, _DrawVertLines, slifis_plot::PLOT::_p_img, col_vline, slifis_plot::GAPI_BuildPoint(), slifis_plot::GAPI_DrawLine(), slifis::FPOINT::GetX(), slifis::FPOINT::GetY(), TransformCoordR2S(), and y_0.
Referenced by P_DrawMembFunc().
virtual bool slifis_plot::PLOT_FUZZY::P_ComputeScale | ( | ) | [protected, pure virtual] |
Implemented in slifis_plot::PLOT_MF, and slifis_plot::PLOT_FS.
Referenced by Draw().
virtual void slifis_plot::PLOT_FUZZY::P_DrawPlot | ( | ) | [protected, pure virtual] |
Implemented in slifis_plot::PLOT_MF, and slifis_plot::PLOT_FS.
Referenced by Draw().
void slifis_plot::PLOT_FUZZY::P_DrawMembFunc | ( | const slifis::MEMBFUNC & | mf, |
const GAPI_COLOR | col | ||
) | [protected] |
Draws the function mf
with color col
,.
References __IN__, __OUT__, _format, _LineWidth, slifis_plot::PLOT::_margins, slifis_plot::PLOT::_p_img, _ShowPointValues, _ShowXValues, slifis_plot::PLOT::_txtbuf, _x_last, col_axis, col_txt, col_xlabel, col_xtic, slifis_plot::en_aa_on, slifis_plot::GAPI_BuildPoint(), slifis_plot::GAPI_DrawLine(), slifis_plot::GAPI_DrawText(), slifis::MEMBFUNC::GetFirstPoint(), slifis::MEMBFUNC::GetMaxValue(), slifis::MEMBFUNC::GetName(), slifis::MEMBFUNC::GetNbPoints(), slifis::MEMBFUNC::GetPoint(), slifis::MEMBFUNC::GetRightValue(), slifis::FPOINT::GetX(), slifis::FPOINT::GetY(), H_FIRST, slifis::MEMBFUNC::IsEmpty(), slifis::MEMBFUNC::IsValid(), slifis_plot::PLOT_MARGINS::m_hl, P_DrawVLine2Point(), slifis_plot::plot_data(), SLIFIS_WARNING_1, TransformCoordR2S(), y_0, and y_scale.
Referenced by slifis_plot::PLOT_FS::P_DrawPlot(), and slifis_plot::PLOT_MF::P_DrawPlot().
const char * slifis_plot::PLOT_FUZZY::P_GetXLabel | ( | slifis::REALVAL | val | ) | [protected] |
Returns the text label according to value val
and defined text format.
Actually, returns the adress of the class buffer...
References _format, and slifis_plot::PLOT::_txtbuf.
Referenced by slifis_plot::PLOT_MF::P_DrawPlot().
int slifis_plot::PLOT_FUZZY::P_GetPixelCoord_x | ( | slifis::REALVAL | x | ) | [protected] |
Returns pixel horizontal coordinates for real value x
.
References _hscale, _x_first, slifis_plot::PLOT_HSCALE::scale, and slifis_plot::PLOT_HSCALE::x0.
Referenced by TransformCoordR2S().
int slifis_plot::PLOT_FUZZY::P_GetPixelCoord_y | ( | slifis::FUZZYVAL | y | ) | [protected] |
Returns pixel vertical coordinates for fuzzy value y
.
Referenced by TransformCoordR2S().
REALVAL slifis_plot::PLOT_FUZZY::P_GetRealValue | ( | int | x | ) | [protected] |
Returns real (horizontal) value from pixel coordinates.
References _hscale, _x_first, slifis_plot::PLOT_HSCALE::scale, and slifis_plot::PLOT_HSCALE::x0.
Referenced by slifis_plot::PLOT_MF::P_DrawPlot(), and TransformCoordS2R().
FUZZYVAL slifis_plot::PLOT_FUZZY::P_GetFuzzyValue | ( | int | y | ) | [protected] |
Returns fuzzy (vertical) value from pixel coordinates.
Referenced by TransformCoordS2R().
void slifis_plot::PLOT_FUZZY::P_ComputeMargins | ( | ) | [private] |
Computes all the margins needed for plotting (private). Depends on image size, so is called by constructor, or after a call to ChangeSize(). Implementation of pure virtual function PLOT::P_ComputeMargins()
References __IN__, __OUT__, _AutoScale, slifis_plot::PLOT::_margins, _PreviousScaleAvailable, _x_first, _x_last, _x_range, slifis_plot::PLOT::GetH(), slifis_plot::PLOT::GetW(), H2_MARGIN, H_FIRST, slifis_plot::PLOT_MARGINS::m_hl, slifis_plot::PLOT_MARGINS::m_vb, slifis_plot::PLOT_MARGINS::m_vt, V2_MARGIN, x_yaxis, y_0, y_1, and y_scale.
Referenced by PLOT_FUZZY(), and Resize().
int slifis_plot::PLOT_FUZZY::x_yaxis [protected] |
Horizontal position of the 'y' axis (pixels)
Referenced by P_ComputeMargins(), and P_DrawAxis().
PLOT_HSCALE slifis_plot::PLOT_FUZZY::_hscale [protected] |
int slifis_plot::PLOT_FUZZY::_x_range [protected] |
range in pixels used for the plot (distance between first and last point)
Referenced by P_ComputeMargins(), slifis_plot::PLOT_FS::P_ComputeScale(), and slifis_plot::PLOT_MF::P_ComputeScale().
int slifis_plot::PLOT_FUZZY::_x_first [protected] |
position in pixel used for first point
Referenced by P_ComputeMargins(), slifis_plot::PLOT_FS::P_DrawPlot(), slifis_plot::PLOT_MF::P_DrawPlot(), P_GetPixelCoord_x(), and P_GetRealValue().
int slifis_plot::PLOT_FUZZY::_x_last [protected] |
Referenced by P_ComputeMargins(), P_DrawAxis(), P_DrawMembFunc(), and slifis_plot::PLOT_MF::P_DrawPlot().
double slifis_plot::PLOT_FUZZY::y_scale [protected] |
Vertical scale. Computed once in constructor.
Referenced by P_ComputeMargins(), P_DrawMembFunc(), P_GetFuzzyValue(), and P_GetPixelCoord_y().
int slifis_plot::PLOT_FUZZY::y_0 [protected] |
vertical pixel position of fuzzy value "0.0"
Referenced by DrawPoint(), P_ComputeMargins(), P_DrawAxis(), P_DrawMembFunc(), slifis_plot::PLOT_MF::P_DrawPlot(), P_DrawVLine2Point(), P_GetFuzzyValue(), and P_GetPixelCoord_y().
int slifis_plot::PLOT_FUZZY::y_1 [protected] |
vertical pixel position of fuzzy value "1.0"
Referenced by P_ComputeMargins(), P_DrawAxis(), and slifis_plot::PLOT_MF::P_DrawPlot().
bool slifis_plot::PLOT_FUZZY::_AutoScale [protected] |
if flag is true (default), then each drawing of the plot will recompute the scale so it fits best
Referenced by Draw(), P_ComputeMargins(), SetAutoScale(), and SetScale().
int slifis_plot::PLOT_FUZZY::_NbDec [protected] |
Number of decimal values, default is 1.
Referenced by Set_NbDec().
char slifis_plot::PLOT_FUZZY::_format[32] [protected] |
Format string.
Referenced by P_DrawMembFunc(), P_GetXLabel(), and Set_NbDec().
bool slifis_plot::PLOT_FUZZY::_ShowPointValues [protected] |
Show points values next to the points, default is true.
Referenced by P_DrawMembFunc(), PLOT_FUZZY(), and Set_ShowPointValues().
bool slifis_plot::PLOT_FUZZY::_ShowXValues [protected] |
Show x values, default is true.
Referenced by P_DrawMembFunc(), PLOT_FUZZY(), and Set_ShowXValues().
bool slifis_plot::PLOT_FUZZY::_DrawVertLines [protected] |
Draw or not vertical lines on plot.
Referenced by P_DrawVLine2Point(), PLOT_FUZZY(), and Set_DrawVertLines().
int slifis_plot::PLOT_FUZZY::_LineWidth [protected] |
Referenced by P_DrawMembFunc(), PLOT_FUZZY(), and Set_ThickLine().
bool slifis_plot::PLOT_FUZZY::_PreviousScaleAvailable [protected] |
std::string slifis_plot::PLOT_FUZZY::_caption [protected] |
optional caption on plot
Referenced by Draw(), slifis_plot::PLOT_FS::GetPlotName(), slifis_plot::PLOT_MF::GetPlotName(), and SetCaption().
bool slifis_plot::PLOT_FUZZY::_HasCaption [protected] |
Referenced by slifis_plot::PLOT_FS::GetPlotName(), slifis_plot::PLOT_MF::GetPlotName(), PLOT_FUZZY(), and SetCaption().
GAPI_COLOR slifis_plot::PLOT_FUZZY::col_axis = GAPI_BuildColor( 128 , 128 , 128 ) [static, protected] |
color of axis
Referenced by P_DrawAxis(), and P_DrawMembFunc().
GAPI_COLOR slifis_plot::PLOT_FUZZY::col_txt = GAPI_BuildColor( 0, 128 , 200 ) [static, protected] |
color of txt
Referenced by Draw(), P_DrawMembFunc(), and slifis_plot::PLOT_MF::P_DrawPlot().
GAPI_COLOR slifis_plot::PLOT_FUZZY::col_vline = GAPI_BuildColor( 200, 200, 200 ) [static, protected] |
color of vertical line to point
Referenced by P_DrawAxis(), and P_DrawVLine2Point().
GAPI_COLOR slifis_plot::PLOT_FUZZY::col_xlabel = GAPI_BuildColor( 0, 128 , 50 ) [static, protected] |
color of text of horizontal labels
Referenced by P_DrawMembFunc(), and slifis_plot::PLOT_MF::P_DrawPlot().
GAPI_COLOR slifis_plot::PLOT_FUZZY::col_xtic = GAPI_BuildColor( 30, 0, 0 ) [static, protected] |
color of x tic
Referenced by P_DrawAxis(), P_DrawMembFunc(), and slifis_plot::PLOT_MF::P_DrawPlot().
GAPI_COLOR slifis_plot::PLOT_FUZZY::col_point_label = GAPI_BuildColor( 0, 0, 50 ) [static, protected] |
Referenced by DrawPoint().