00001 #include <cmath> 00002 #include "Learn/WiimoteGR/Quantizer.h" 00003 #include "Learn/WiimoteGR/TimeSlot.h" 00004 00005 namespace WiimoteGR{ 00006 00007 void Quantizer::Quantize(const Gesture& gesture, TimeSlot& symbolSeq) const{ 00008 symbolSeq.gestureName = gesture.gestureName; 00009 symbolSeq.quantizerName = name; 00010 symbolSeq.M = M; 00011 symbolSeq.o.clear(); 00012 for(vector<Acceleration>::const_iterator i = gesture.data.begin(); i<gesture.data.end(); i++) 00013 symbolSeq.o.push_back(Quantize(*i)); 00014 } 00015 00016 size_t DefaultQuantizer::Quantize(const Acceleration& acc) const{ 00017 double rho = sqrt(acc.x*acc.x+acc.y*acc.y+acc.z*acc.z); 00018 return (rho>rho_threshold? 1<<3 : 0) 00019 + (acc.x>acc.y? 1<<2 : 0) 00020 + (acc.y>acc.z? 1<<1 : 0) 00021 + (acc.z>acc.x? 1 : 0); 00022 } 00023 00024 size_t M32Quantizer::Quantize(const Acceleration& acc) const{ 00025 double rho = sqrt(acc.x*acc.x+acc.y*acc.y+acc.z*acc.z); 00026 return (rho>3.0? 3<<3 : rho>2.0? 2<<3 : rho>1.0? 1<<3 :0) 00027 | (acc.x>acc.y? 1<<2 : 0) 00028 | (acc.y>acc.z? 1<<1 : 0) 00029 | (acc.z>acc.x? 1 : 0); 00030 } 00031 00032 }