00001 #include "GestureFinder.h"
00002 #include "../framedata/VectorFrameData.h"
00003 #include "../framedata/SignalFrameData.h"
00004 #include "../visualizer/GestureFinderGUI.h"
00005 #include "../util/Error.h"
00006 #include <iostream>
00007
00008 GestureFinder::GestureFinder(size_t maxFramesDropped, double threshold, AbstractModule *successor) :
00009 ProcessModule(successor),
00010 m_droppedVectors(maxFramesDropped+1),
00011 m_maxFramesDropped(maxFramesDropped),
00012 m_threshold(threshold)
00013 {
00014 setGUI(new GestureFinderGUI(this));
00015 }
00016
00017 GestureFinder::GestureFinder(ConfigSection *config, AbstractModule *successor) :
00018 ProcessModule(successor)
00019 {
00020 if (config == NULL) {
00021 throw Error("GestureFinder::GestureFinder(): Pointer to ConfigSection is NULL");
00022 }
00023 try {
00024 m_maxFramesDropped = config->get<int>("max frames dropped");
00025 } catch (Error e) {
00026 config->setItem("max frames dropped", "5");
00027 m_maxFramesDropped = 5;
00028 }
00029 m_droppedVectors = m_maxFramesDropped+1;
00030 try {
00031 m_threshold = config->get<double>("threshold");
00032 } catch (Error e) {
00033 config->setItem("threshold", "1.2");
00034 m_threshold = 1.2;
00035 }
00036
00037 setGUI(new GestureFinderGUI(this));
00038 }
00039
00040 void GestureFinder::processFrameData(IFrameData *data)
00041 {
00042 if (isSignal(data)) {
00043 passSignal(data);
00044 return;
00045 }
00046
00047 assertFramedataType(data, "Vector3D", "GestureFinder::processFrameData");
00048
00049 Vector3d acc = static_cast<VectorFrameData*>(data)->getData();
00050
00051
00052 if ((acc[0] * acc[0] + acc[1] * acc[1] + acc[2] * acc[2]) > m_threshold * m_threshold) {
00053
00054 if (m_droppedVectors > m_maxFramesDropped) {
00055 std::cout << "send Signal start gesture" << std::endl;
00056 ProcessModule::processFrameData(new SignalFrameData(SignalFrameData::SIG_START_GESTURE));
00057 }
00058 m_droppedVectors = 0;
00059 ProcessModule::processFrameData(data);
00060 return;
00061 }
00062
00063
00064 delete data;
00065 ++m_droppedVectors;
00066 if (m_droppedVectors == m_maxFramesDropped) {
00067 std::cout << "send Signal stop gesture" << std::endl;
00068 ProcessModule::processFrameData(new SignalFrameData(SignalFrameData::SIG_STOP_GESTURE));
00069 }
00070 }
00071