home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 02 Useful Techniques / 08 Zarozinski / src / ffllapi / MemberFuncBase.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-13  |  3.7 KB  |  118 lines

  1. //
  2. // File:    MemberFuncBase.h
  3. //
  4. // Purpose:    This is the base class all the membership fucntions.  
  5. //
  6. // Copyright ⌐ 1999-2001 Louder Than A Bomb! Software
  7. //
  8. // This file is part of the FFLL (Free Fuzzy Logic Library) project (http://ffll.sourceforge.net)
  9. // It is released under the BSD license, see http://ffll.sourceforge.net/license.txt for the full text.
  10. //
  11.  
  12. #if !defined(AFX_MEMBERFUNC_H__A9B71344_61EC_11D3_B77F_906F59C10001__INCLUDED_)
  13. #define AFX_MEMBERFUNC_H__A9B71344_61EC_11D3_B77F_906F59C10001__INCLUDED_
  14.  
  15. #include "FFLLBase.h"
  16. #include <fstream>
  17. #include <math.h>
  18.  
  19. class FuzzySetBase;
  20.  
  21. // 
  22. // Class:    MemberFuncBase
  23. //
  24. // This is an abstract class that defines the type of "curve" a set has.
  25. //
  26.  
  27. class FFLL_API MemberFuncBase : virtual public FFLLBase  
  28. {
  29.      ////////////////////////////////////////
  30.     ////////// Member Functions ////////////
  31.     ////////////////////////////////////////
  32.  
  33.     public:
  34.  
  35.         // constructor/destructor funcs
  36.         virtual ~MemberFuncBase();
  37.          MemberFuncBase(); // No function body for this. Explicitly disallow auto-creation of it by the compiler
  38.         MemberFuncBase(FuzzySetBase* _parent);
  39.         void init();
  40.         virtual void init_nodes(int start_x, int term_width) = 0;
  41.  
  42.         // get functions
  43.         int get_end_x(void) const; 
  44.         int get_start_x(void) const ;
  45.         int get_node_x(int idx) const ;
  46.         int get_node_y(int idx) const;
  47.         int get_ramp() const;
  48.         NodePoint get_node(int idx) const;
  49.         DOMType get_value(int idx) const ;
  50.         DOMType get_dom(int idx);
  51.         FuzzySetBase* get_parent() const  ;
  52.         RealType get_left_x() const; 
  53.         virtual int get_center_x(void) const;
  54.         virtual int get_node_count() const = 0;
  55.         virtual int get_func_type() const = 0;
  56.  
  57.         // set functions
  58.  
  59.         virtual void set_node(int idx, int x, int y, bool validate = true) = 0;
  60.          virtual void set_ramp(int hi_lo_ind, int left_right_ind);
  61.         int set_value(int idx, DOMType val);
  62.         int set_value(int idx, RealType val);
  63.  
  64.         // misc functions
  65.  
  66.          void move(int x_delta);
  67.         void move_node(int idx, _point pt ) ;
  68.         virtual void move_node(int idx, int x, int y ) ;
  69.         virtual void calc() = 0;
  70.  
  71.           // save/load functions
  72.  
  73.         virtual void save_to_fcl_file(std::ofstream& file_contents);
  74.          virtual void expand(int x_delta) = 0;
  75.          virtual void shrink(int x_delta) = 0;
  76.  
  77.     protected:
  78.  
  79.         // misc functions
  80.  
  81.         virtual int alloc_values_array();
  82.         virtual void dealloc_values_array();
  83.          int alloc_nodes(int node_count);
  84.         void clear_values();
  85.  
  86.     ////////////////////////////////////////
  87.     ////////// Class Variables /////////////
  88.     ////////////////////////////////////////
  89.  
  90.     public:
  91.         static enum TYPE {S_CURVE, TRIANGLE, TRAPEZOID, SINGLETON};
  92.         static enum RAMP {NONE, LEFT, RIGHT, NA}; // NA is not applicable for singleton member funcs
  93.  
  94.     protected:
  95.  
  96.          NodePoint* nodes;    // array of "node" points for the curve
  97.         int            ramp;    // indicates if this term is a ramp. It can be one of the
  98.                             // RAMP enum types defined in this class. A ramp is a membership
  99.                             // function that has the 'y' axis as one of it's sides.
  100.                             // For example a normal trapezoid memberhip function would look like this:
  101.                             //                                       ___
  102.                             //              Normal Trapezoid:       /   \
  103.                             //                                       ___
  104.                             //              Left Ramp Trapezoid:    |   \ 
  105.                             //                                       ___
  106.                             //              Right Ramp Trapezoid:   /   |  
  107.                             //
  108.         DOMType*    values;    // This points to an array that holds the 'y' values for this term.
  109.                             // It has FuzzyVariableBase::x_array_count elements
  110.  
  111. }; // end class MemberFuncBase
  112.  
  113. #else
  114.  
  115. class MemberFuncBase; // already included
  116.  
  117. #endif // !defined(AFX_MEMBERFUNC_H__A9B71344_61EC_11D3_B77F_906F59C10001__INCLUDED_)
  118.