00001 #include "ClassificationChain.h" 00002 00003 #include "modules/Smoother.h" 00004 #include "modules/GestureFinder.h" 00005 #include "modules/DirectionFilter.h" 00006 #include "modules/HMMModule.h" 00007 #include "modules/OutputModule.h" 00008 00009 #include "framedata/VectorFrameData.h" 00010 00011 #include "util/Warning.h" 00012 #include "util/WarningWrongFrameDataType.h" 00013 #include <iostream> 00014 00015 ClassificationChain::ClassificationChain(AbstractMotionReceiver *r, ConfigManager *cfgManager) : 00016 m_classificationChain(NULL) 00017 { 00018 // Set section config and default values if not present 00019 if (!cfgManager->hasSection("Smoother")) { 00020 cfgManager->addEmptySection("Smoother"); 00021 cfgManager->getSection("Smoother").setItem("window size", "10"); 00022 } 00023 if (!cfgManager->hasSection("Direction Filter")) { 00024 cfgManager->addEmptySection("Direction Filter"); 00025 cfgManager->getSection("Direction Filter").setItem("threshold", "0.2"); 00026 } 00027 if (!cfgManager->hasSection("Gesture Finder")) { 00028 cfgManager->addEmptySection("Gesture Finder"); 00029 cfgManager->getSection("Gesture Finder").setItem("window size", "10"); 00030 cfgManager->getSection("Gesture Finder").setItem("threshold", "0.3"); 00031 } 00032 00033 r->addObserver(this); 00034 m_classificationChain = new Smoother(&cfgManager->getSection("Smoother"), 00035 new GestureFinder(&cfgManager->getSection("Gesture Finder"), 00036 new DirectionFilter(&cfgManager->getSection("Direction Filter"), 00037 new HMMModule( 00038 new OutputModule() 00039 ) 00040 ) 00041 ) 00042 ); 00043 } 00044 00045 ClassificationChain::~ClassificationChain() 00046 { 00047 if (m_classificationChain != NULL) 00048 delete m_classificationChain; 00049 } 00050 00051 void ClassificationChain::update(const Vector3d& v) 00052 { 00053 try { 00054 m_classificationChain->processFrameData(new VectorFrameData(v)); 00055 } catch (WarningWrongFrameDataType &w) { 00056 std::cerr << std::endl << w.what() << std::endl; 00057 } catch (Warning &w) { 00058 std::cerr << std::endl << "Warning:" << std::endl << w.what() << std::endl; 00059 } 00060 }