Revision: 1.3 - (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 : | ktanaka | 1.3 | MatchResult(int xx, int yy,const 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 : | ktanaka | 1.3 | pm.push_back(PatMatch(5,3, |
50 : | ".@@.." | ||
51 : | "@@@@@" | ||
52 : | ".....", | ||
53 : | Assumption() | ||
54 : | .add(SimpleAssumption(YokoMask,Mid,1.5,1,0,0)) | ||
55 : | .add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointEnd,1.5,1,270,2)))); | ||
56 : | ktanaka | 1.1 | pm.push_back(PatMatch(5,4, |
57 : | "....?" | ||
58 : | ".@@.." | ||
59 : | "@@@@." | ||
60 : | ".....", | ||
61 : | SimpleAssumption(YokoMask,End,3,2,0,2))); | ||
62 : | pm.push_back(PatMatch(4,2, | ||
63 : | ".@@." | ||
64 : | ".@@.", | ||
65 : | SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointStart,1.5,1,270,2))); | ||
66 : | pm.push_back(PatMatch(4,3, | ||
67 : | ".@@." | ||
68 : | "@@@@" | ||
69 : | ".@@.", | ||
70 : | Assumption() | ||
71 : | .add(SimpleAssumption(YokoMask,Mid,1.5,1,0,0)) | ||
72 : | .add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),Mid,1.5,1,270,2)))); | ||
73 : | pm.push_back(PatMatch(4,4, | ||
74 : | "...?" | ||
75 : | ".@.." | ||
76 : | ".@@@" | ||
77 : | ".@@.", | ||
78 : | Assumption() | ||
79 : | .add(SimpleAssumption(YokoMask,JointStart,1.5,2,0,0)) | ||
80 : | .add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointStart,1.5,2,270,2)))); | ||
81 : | pm.push_back(PatMatch(4,4, | ||
82 : | ".@@." | ||
83 : | ".@@@" | ||
84 : | ".@@." | ||
85 : | "....", | ||
86 : | Assumption() | ||
87 : | .add(SimpleAssumption(YokoMask,JointStart,1.5,2,0,0)) | ||
88 : | .add(SimpleAssumption(TateMask,JointEnd,1.5,1,270,2)))); | ||
89 : | pm.push_back(PatMatch(4,4, | ||
90 : | ".@@." | ||
91 : | "@@@." | ||
92 : | ".@@." | ||
93 : | "....", | ||
94 : | Assumption() | ||
95 : | .add(SimpleAssumption(YokoMask,JointEnd,1.5,2,0,0)) | ||
96 : | .add(SimpleAssumption(TateMask,JointEnd,1.5,1,270,2)))); | ||
97 : | } | ||
98 : | ktanaka | 1.3 | vector<MatchResult> findMatch(const BitmapFont& bf) const{ |
99 : | ktanaka | 1.1 | vector<MatchResult> mr; |
100 : | ktanaka | 1.3 | vector<PatMatch>::const_iterator it; |
101 : | ktanaka | 1.1 | for(it=pm.begin();it!=pm.end();it++) |
102 : | for(int y= -1; y<bf.getHeight(); y++) | ||
103 : | for(int x= -1;x<bf.getWidth();x++) | ||
104 : | if(it->isMatch(bf,x,y)) | ||
105 : | mr.push_back(MatchResult(x,y,*it)); | ||
106 : | return mr; | ||
107 : | } | ||
108 : | ktanaka | 1.3 | vector<pixel> notCovered(const BitmapFont& bf) const{ |
109 : | ktanaka | 1.1 | vector<MatchResult> mr=findMatch(bf); |
110 : | ktanaka | 1.2 | vector<set<int> > pixel2match(bf.getSize()); |
111 : | ktanaka | 1.1 | vector<set<int> > match2pixel(mr.size()); |
112 : | vector<MatchResult>::iterator it; | ||
113 : | for(it=mr.begin();it!=mr.end();it++){ | ||
114 : | ktanaka | 1.2 | int n= it-mr.begin(); |
115 : | vector<pixel> ps=(*it).getPixels(); | ||
116 : | vector<pixel>::iterator ips; | ||
117 : | for(ips=ps.begin();ips!=ps.end();ips++){ | ||
118 : | int m=bf.getIndex(*ips); | ||
119 : | ktanaka | 1.3 | cout << '(' << ips->first << ',' << ips->second << ")\n"; |
120 : | ktanaka | 1.2 | assert(m != -1); |
121 : | match2pixel[n].insert(m); | ||
122 : | pixel2match[m].insert(n); | ||
123 : | } | ||
124 : | } | ||
125 : | ktanaka | 1.3 | vector<pixel> ret; |
126 : | ktanaka | 1.2 | for(int i=0;i<bf.getPixelSize();i++){ |
127 : | ktanaka | 1.3 | if(pixel2match[i].empty()) { |
128 : | ret.push_back(bf.getPixelAt(i)); | ||
129 : | } | ||
130 : | ktanaka | 1.1 | } |
131 : | ktanaka | 1.3 | return ret; |
132 : | ktanaka | 1.1 | } |
133 : | }; | ||
134 : | ostream& operator<<(ostream &os,const Matchers &mt){ | ||
135 : | os << "Matchers("; | ||
136 : | vector<PatMatch>::const_iterator it; | ||
137 : | for(it=mt.pm.begin();it!=mt.pm.end();it++){ | ||
138 : | os << *it << ','; | ||
139 : | } | ||
140 : | os << ')'; | ||
141 : | return os; | ||
142 : | } | ||
143 : | ostream& operator<<(ostream &os,const MatchResult &mr){ | ||
144 : | os << "MatchResult(" << mr.x << "," << mr.y << "," << mr.pm << ")"; | ||
145 : | return os; | ||
146 : | } | ||
147 : | #endif /* _MATCHERS_H */ |
ktanaka Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |