A fuzzy logic C++ library
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
slifis_plot::PLOT_FUZZY Class Reference

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>

+ Inheritance diagram for slifis_plot::PLOT_FUZZY:
+ Collaboration diagram for slifis_plot::PLOT_FUZZY:

List of all members.

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()

Detailed Description

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.


Constructor & Destructor Documentation

slifis_plot::PLOT_FUZZY::PLOT_FUZZY ( size_t  w,
size_t  h 
) [protected]
slifis_plot::PLOT_FUZZY::~PLOT_FUZZY ( ) [protected, virtual]

References __IN__, and __OUT__.


Member Function Documentation

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().

Assigns the scale scale to the plot, and switch off autoscaling.

References _AutoScale, _hscale, and _PreviousScaleAvailable.

Referenced by DrawDefuzz(), main(), Process(), and SetScale().

Assigns the scale scale to the plot, and switch off autoscaling.

References GetScale(), and SetScale().

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.

Warning:
This function requires an available scale factor ! (see Scaling issues.)

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::SetCaption ( std::string  s) [inline]

References _caption, and _HasCaption.

Referenced by main(), and Show().

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]
virtual std::string slifis_plot::PLOT_FUZZY::GetPlotName ( ) const [pure virtual]
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]
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().

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().

Returns pixel vertical coordinates for fuzzy value y.

References y_0, and y_scale.

Referenced by TransformCoordR2S().

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().

Returns fuzzy (vertical) value from pixel coordinates.

References y_0, and y_scale.

Referenced by TransformCoordS2R().

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().


Member Data Documentation

Horizontal position of the 'y' axis (pixels)

Referenced by P_ComputeMargins(), and P_DrawAxis().

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().

Vertical scale. Computed once in constructor.

Referenced by P_ComputeMargins(), P_DrawMembFunc(), P_GetFuzzyValue(), and P_GetPixelCoord_y().

vertical pixel position of fuzzy value "1.0"

Referenced by P_ComputeMargins(), P_DrawAxis(), and slifis_plot::PLOT_MF::P_DrawPlot().

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().

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().

Show points values next to the points, default is true.

Referenced by P_DrawMembFunc(), PLOT_FUZZY(), and Set_ShowPointValues().

Show x values, default is true.

Referenced by P_DrawMembFunc(), PLOT_FUZZY(), and Set_ShowXValues().

Draw or not vertical lines on plot.

Referenced by P_DrawVLine2Point(), PLOT_FUZZY(), and Set_DrawVertLines().

std::string slifis_plot::PLOT_FUZZY::_caption [protected]
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().

Referenced by DrawPoint().