00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef STLRECOGNISERINTERFACE_H
00026 #define STLRECOGNISERINTERFACE_H
00027
00028
00029 #include <algorithm>
00030 #include <list>
00031 #include <map>
00032 #include <set>
00033 #include <string>
00034
00035 #include "stlrecognitioncommon.h"
00036
00037
00038 #ifndef DECLARE_STL_RECOGNISER_KEY(KEY)
00039 #define DECLARE_STL_RECOGNISER_KEY(KEY) \
00040 static const std::string& classKey() { \
00041 static const std::string str(KEY); \
00042 return str; \
00043 } \
00044 virtual const std::string& key() const { return classKey(); }
00045 #endif
00046
00047 #ifndef DECLARE_STL_RECOGNISER_TITLE(TITLE)
00048 #define DECLARE_STL_RECOGNISER_TITLE(TITLE) \
00049 static const std::string& classTitle() { \
00050 static const std::string str(TITLE); \
00051 return str; \
00052 } \
00053 virtual const std::string& title() const { return classTitle(); }
00054 #endif
00055
00056 #ifndef DECLARE_STL_RECOGNISER_DESCRIPTION(DESCRIPTION)
00057 #define DECLARE_STL_RECOGNISER_DESCRIPTION(DESCRIPTION) \
00058 static const std::string& classDescription() { \
00059 static const std::string str(DESCRIPTION); \
00060 return str; \
00061 } \
00062 virtual const std::string& description() const { return classDescription(); }
00063 #endif
00064
00065
00066
00076 class StlRecogniserInterface {
00077
00078 public:
00079 virtual ~StlRecogniserInterface() {}
00080
00081 virtual const std::string& key() const = 0;
00082 virtual const std::string& title() const = 0;
00083 virtual const std::string& description() const = 0;
00084
00085 virtual const std::map<std::string, std::string>& defaultParams() const = 0;
00086
00087 virtual bool initTraining( const std::list<std::string>& featureKeys,
00088 const std::map<std::string, std::string>& params ) = 0;
00089 virtual bool examineSample( const StlFeatureVec& featureVec,
00090 const std::set<int>& classes ) = 0;
00091 virtual bool finaliseTraining() = 0;
00092
00093 virtual bool writeModelFile( const std::string& fileName ) = 0;
00094 virtual bool readModelFile( const std::string& fileName ) = 0;
00095
00096 virtual StlStroke flatten( const StlStrokeList& strokes ) {
00097 StlStroke stroke;
00098 StlStrokeList::const_iterator it = strokes.begin();
00099 while ( it != strokes.end() ) {
00100 std::copy( (*it).begin(), (*it).end(), back_inserter(stroke) );
00101 ++it;
00102 }
00103 return stroke;
00104 }
00105
00106 virtual StlClassProbabilities classify( const StlFeatureVec& featureVec ) = 0;
00107 };
00108
00109
00130 #endif // ! STLRECOGNISERINTERFACE_H