00001
00024 #ifndef _CLASSIFIER_H
00025 #define _CLASSIFIER_H
00026
00027 #ifdef _CLASSIFIER_EXPORT
00028 # define _FEATURE_EXPORT
00029 #endif
00030 #ifdef _CLASSIFIER_EXPORT_CLASS
00031 # define _FEATURE_EXPORT_CLASS
00032 #endif
00033
00034 #include "../FeatureContainer/FeatureContainer.h"
00035
00037
00038 #define CLASSIFIER_EXPORT FEATURE_EXPORT
00039 #define CLASSIFIER_EXPORT_CLASS FEATURE_EXPORT_CLASS
00040
00041
00052 #define EXPORT_CLASSIFIER(classifier) \
00053 \
00054 static classifier *clf; \
00055 void INIT_EXPORT library_initialize() { clf = NULL; } \
00056 void FINI_EXPORT library_finalize() { if (clf != NULL) delete clf; } \
00057 \
00063 extern "C" CLASSIFIER_EXPORT ClassifierAlgorithm* getClassifier(classifierparams ¶ms) { if (clf == NULL) clf = new classifier(params); return clf; }
00064
00077 typedef parametermap classifierparams;
00078
00087 class CLASSIFIER_EXPORT_CLASS ClassifierAlgorithm {
00088 public:
00090 virtual ~ClassifierAlgorithm() {}
00091
00110 virtual void init(FeatureContainer *fc) = 0;
00125 virtual membershiplist getClusterMembership(const featurevector *sample) = 0;
00136 virtual unsigned long nextSample() = 0;
00143 virtual unsigned long nextSample(const featurevector* sample) = 0;
00144
00150 virtual string serialize() const = 0;
00151
00157 virtual void unserialize(string data) = 0;
00158
00159 #if _DEBUG_CLASSIFIERS
00160
00161 virtual string toString() const = 0;
00162 #endif
00163 };
00164
00172 class Classifier : public ClassifierAlgorithm {
00173 private:
00175 FeatureContainer *f;
00177 ClassifierAlgorithm *ca;
00178
00179 #if defined(_WIN32_WCE) || defined (_WINDOWS)
00180 HMODULE dll;
00181 #else
00182
00183 void* dlHandle;
00184 #endif
00185
00186 public:
00193 Classifier(const string &name, const classifierparams ¶ms);
00195 virtual ~Classifier();
00196
00197 virtual void init(FeatureContainer *fc) { f = fc; ca->init(fc); }
00198 virtual membershiplist getClusterMembership(const featurevector *sample) { return ca->getClusterMembership(sample); }
00199 virtual unsigned long nextSample() { return ca->nextSample(); }
00200 virtual unsigned long nextSample(const featurevector* sample) { return ca->nextSample(sample); }
00201 virtual string serialize() const { return ca->serialize(); }
00202 virtual void unserialize(string data) { ca->unserialize(data); }
00203
00205 ClassifierAlgorithm* getCa() const { return ca; }
00206
00207 #if _DEBUG_CLASSIFIERS
00208
00209 virtual string toString() const { return ca->toString(); }
00210 #endif
00211 };
00212
00219 typedef ClassifierAlgorithm* (*getClassifier_t) (const classifierparams ¶ms);
00220
00221 #endif