Revision Log
Revision: 1.2 - (view) (download) (as text)
| 1 : | ktanaka | 1.1 | #ifndef _MATCHERS_H |
| 2 : | #define _MATCHERS_H | ||
| 3 : | |||
| 4 : | #include <vector> | ||
| 5 : | ktanaka | 1.2 | #include <set> |
| 6 : | ktanaka | 1.1 | /* Matchters */ |
| 7 : | #include "PatMatch.h" | ||
| 8 : | #include "BitmapFont.h" | ||
| 9 : | |||
| 10 : | class MatchResult { | ||
| 11 : | friend ostream& operator<<(ostream &os,const MatchResult &mr); | ||
| 12 : | protected: | ||
| 13 : | int x,y; | ||
| 14 : | PatMatch pm; | ||
| 15 : | public: | ||
| 16 : | MatchResult(int xx, int yy,PatMatch& p) :x(xx),y(yy),pm(p){} | ||
| 17 : | ktanaka | 1.2 | vector<pixel> getPixels() const { |
| 18 : | return pm.getPixels(x,y); | ||
| 19 : | } | ||
| 20 : | ktanaka | 1.1 | }; |
| 21 : | |||
| 22 : | class Matchers { | ||
| 23 : | friend ostream& operator<<(ostream &os,const Matchers &mt); | ||
| 24 : | protected: | ||
| 25 : | vector<PatMatch> pm; | ||
| 26 : | public: | ||
| 27 : | Matchers(){ | ||
| 28 : | pm.push_back(PatMatch(3,3, | ||
| 29 : | "..." | ||
| 30 : | ".@@" | ||
| 31 : | "...", | ||
| 32 : | Assumption() | ||
| 33 : | .add(SimpleAssumption(YokoMask,Start,1,1,0,0)) | ||
| 34 : | .add(SimpleAssumption(HidariMask,End,1,1,180,0)))); | ||
| 35 : | pm.push_back(PatMatch(3,3, | ||
| 36 : | "..." | ||
| 37 : | "@@@" | ||
| 38 : | "...", | ||
| 39 : | Assumption() | ||
| 40 : | .add(SimpleAssumption(YokoMask,Mid,1,1,0,0)) | ||
| 41 : | .add(SimpleAssumption(HidariMask,Mid,1,1,180,1)))); | ||
| 42 : | pm.push_back(PatMatch(4,3, | ||
| 43 : | "...." | ||
| 44 : | "@@@@" | ||
| 45 : | ".@@.", | ||
| 46 : | Assumption() | ||
| 47 : | .add(SimpleAssumption(YokoMask,Mid,1.5,1,0,0)) | ||
| 48 : | .add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointStart,1.5,1,270,2)))); | ||
| 49 : | pm.push_back(PatMatch(5,4, | ||
| 50 : | "....?" | ||
| 51 : | ".@@.." | ||
| 52 : | "@@@@." | ||
| 53 : | ".....", | ||
| 54 : | SimpleAssumption(YokoMask,End,3,2,0,2))); | ||
| 55 : | pm.push_back(PatMatch(4,2, | ||
| 56 : | ".@@." | ||
| 57 : | ".@@.", | ||
| 58 : | SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointStart,1.5,1,270,2))); | ||
| 59 : | pm.push_back(PatMatch(4,3, | ||
| 60 : | ".@@." | ||
| 61 : | "@@@@" | ||
| 62 : | ".@@.", | ||
| 63 : | Assumption() | ||
| 64 : | .add(SimpleAssumption(YokoMask,Mid,1.5,1,0,0)) | ||
| 65 : | .add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),Mid,1.5,1,270,2)))); | ||
| 66 : | pm.push_back(PatMatch(4,4, | ||
| 67 : | "...?" | ||
| 68 : | ".@.." | ||
| 69 : | ".@@@" | ||
| 70 : | ".@@.", | ||
| 71 : | Assumption() | ||
| 72 : | .add(SimpleAssumption(YokoMask,JointStart,1.5,2,0,0)) | ||
| 73 : | .add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointStart,1.5,2,270,2)))); | ||
| 74 : | pm.push_back(PatMatch(4,4, | ||
| 75 : | ".@@." | ||
| 76 : | ".@@@" | ||
| 77 : | ".@@." | ||
| 78 : | "....", | ||
| 79 : | Assumption() | ||
| 80 : | .add(SimpleAssumption(YokoMask,JointStart,1.5,2,0,0)) | ||
| 81 : | .add(SimpleAssumption(TateMask,JointEnd,1.5,1,270,2)))); | ||
| 82 : | pm.push_back(PatMatch(4,4, | ||
| 83 : | ".@@." | ||
| 84 : | "@@@." | ||
| 85 : | ".@@." | ||
| 86 : | "....", | ||
| 87 : | Assumption() | ||
| 88 : | .add(SimpleAssumption(YokoMask,JointEnd,1.5,2,0,0)) | ||
| 89 : | .add(SimpleAssumption(TateMask,JointEnd,1.5,1,270,2)))); | ||
| 90 : | } | ||
| 91 : | vector<MatchResult> findMatch(const BitmapFont& bf){ | ||
| 92 : | vector<MatchResult> mr; | ||
| 93 : | vector<PatMatch>::iterator it; | ||
| 94 : | for(it=pm.begin();it!=pm.end();it++) | ||
| 95 : | for(int y= -1; y<bf.getHeight(); y++) | ||
| 96 : | for(int x= -1;x<bf.getWidth();x++) | ||
| 97 : | if(it->isMatch(bf,x,y)) | ||
| 98 : | mr.push_back(MatchResult(x,y,*it)); | ||
| 99 : | return mr; | ||
| 100 : | } | ||
| 101 : | bool coverCheck(const BitmapFont& bf){ | ||
| 102 : | vector<MatchResult> mr=findMatch(bf); | ||
| 103 : | ktanaka | 1.2 | vector<set<int> > pixel2match(bf.getSize()); |
| 104 : | ktanaka | 1.1 | vector<set<int> > match2pixel(mr.size()); |
| 105 : | vector<MatchResult>::iterator it; | ||
| 106 : | for(it=mr.begin();it!=mr.end();it++){ | ||
| 107 : | ktanaka | 1.2 | int n= it-mr.begin(); |
| 108 : | vector<pixel> ps=(*it).getPixels(); | ||
| 109 : | vector<pixel>::iterator ips; | ||
| 110 : | for(ips=ps.begin();ips!=ps.end();ips++){ | ||
| 111 : | int m=bf.getIndex(*ips); | ||
| 112 : | assert(m != -1); | ||
| 113 : | match2pixel[n].insert(m); | ||
| 114 : | pixel2match[m].insert(n); | ||
| 115 : | } | ||
| 116 : | } | ||
| 117 : | for(int i=0;i<bf.getPixelSize();i++){ | ||
| 118 : | if(pixel2match[i].empty()) return false; | ||
| 119 : | ktanaka | 1.1 | } |
| 120 : | return true; | ||
| 121 : | } | ||
| 122 : | }; | ||
| 123 : | ostream& operator<<(ostream &os,const Matchers &mt){ | ||
| 124 : | os << "Matchers("; | ||
| 125 : | vector<PatMatch>::const_iterator it; | ||
| 126 : | for(it=mt.pm.begin();it!=mt.pm.end();it++){ | ||
| 127 : | os << *it << ','; | ||
| 128 : | } | ||
| 129 : | os << ')'; | ||
| 130 : | return os; | ||
| 131 : | } | ||
| 132 : | ostream& operator<<(ostream &os,const MatchResult &mr){ | ||
| 133 : | os << "MatchResult(" << mr.x << "," << mr.y << "," << mr.pm << ")"; | ||
| 134 : | return os; | ||
| 135 : | } | ||
| 136 : | #endif /* _MATCHERS_H */ |
|
ktanaka Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |