Revision: 1.4 - (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 : | ktanaka | 1.4 | int penalty; |
16 : | ktanaka | 1.1 | public: |
17 : | ktanaka | 1.4 | MatchResult(int xx, int yy,const PatMatch& p,int penalty) :x(xx),y(yy),pm(p),penalty(penalty){} |
18 : | std::vector<pixel> getPixels() const { | ||
19 : | ktanaka | 1.2 | return pm.getPixels(x,y); |
20 : | } | ||
21 : | ktanaka | 1.1 | }; |
22 : | |||
23 : | class Matchers { | ||
24 : | friend ostream& operator<<(ostream &os,const Matchers &mt); | ||
25 : | protected: | ||
26 : | ktanaka | 1.4 | std::vector<PatMatch> pm; |
27 : | ktanaka | 1.1 | public: |
28 : | Matchers(){ | ||
29 : | pm.push_back(PatMatch(3,3, | ||
30 : | "..." | ||
31 : | ".@@" | ||
32 : | "...", | ||
33 : | Assumption() | ||
34 : | .add(SimpleAssumption(YokoMask,Start,1,1,0,0)) | ||
35 : | .add(SimpleAssumption(HidariMask,End,1,1,180,0)))); | ||
36 : | pm.push_back(PatMatch(3,3, | ||
37 : | "..." | ||
38 : | "@@@" | ||
39 : | "...", | ||
40 : | Assumption() | ||
41 : | .add(SimpleAssumption(YokoMask,Mid,1,1,0,0)) | ||
42 : | .add(SimpleAssumption(HidariMask,Mid,1,1,180,1)))); | ||
43 : | pm.push_back(PatMatch(4,3, | ||
44 : | ktanaka | 1.4 | "...?" |
45 : | ktanaka | 1.1 | "@@@@" |
46 : | ".@@.", | ||
47 : | Assumption() | ||
48 : | .add(SimpleAssumption(YokoMask,Mid,1.5,1,0,0)) | ||
49 : | .add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointStart,1.5,1,270,2)))); | ||
50 : | ktanaka | 1.3 | pm.push_back(PatMatch(5,3, |
51 : | ".@@.." | ||
52 : | "@@@@@" | ||
53 : | ".....", | ||
54 : | Assumption() | ||
55 : | .add(SimpleAssumption(YokoMask,Mid,1.5,1,0,0)) | ||
56 : | .add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointEnd,1.5,1,270,2)))); | ||
57 : | ktanaka | 1.1 | pm.push_back(PatMatch(5,4, |
58 : | "....?" | ||
59 : | ".@@.." | ||
60 : | "@@@@." | ||
61 : | ktanaka | 1.4 | "?...?", |
62 : | ktanaka | 1.1 | SimpleAssumption(YokoMask,End,3,2,0,2))); |
63 : | pm.push_back(PatMatch(4,2, | ||
64 : | ".@@." | ||
65 : | ".@@.", | ||
66 : | SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointStart,1.5,1,270,2))); | ||
67 : | ktanaka | 1.4 | pm.push_back(PatMatch(5,2, |
68 : | "..@@." | ||
69 : | ".@@..", | ||
70 : | SimpleAssumption((PtypeMask)(TatehidariMask|HidariMask),JointStart,2,0.5,225,1.7))); | ||
71 : | pm.push_back(PatMatch(4,2, | ||
72 : | "?*@*" | ||
73 : | "*@*?", | ||
74 : | SimpleAssumption((PtypeMask)(TatehidariMask|HidariMask),JointStart,1.5,0.5,225,1))); | ||
75 : | pm.push_back(PatMatch(4,3, | ||
76 : | "?*@*" | ||
77 : | "*@@*" | ||
78 : | "*@*?", | ||
79 : | SimpleAssumption((PtypeMask)(TatehidariMask|HidariMask),JointStart,1.5,0.5,225,1))); | ||
80 : | ktanaka | 1.1 | pm.push_back(PatMatch(4,3, |
81 : | ".@@." | ||
82 : | "@@@@" | ||
83 : | ".@@.", | ||
84 : | Assumption() | ||
85 : | .add(SimpleAssumption(YokoMask,Mid,1.5,1,0,0)) | ||
86 : | .add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),Mid,1.5,1,270,2)))); | ||
87 : | ktanaka | 1.4 | pm.push_back(PatMatch(5,3, |
88 : | "..@@." | ||
89 : | "@@@@@" | ||
90 : | ".@@..", | ||
91 : | Assumption() | ||
92 : | .add(SimpleAssumption(YokoMask,Mid,2,1,0,0)) | ||
93 : | .add(SimpleAssumption((PtypeMask)(TatehidariMask|HidariMask),Mid,2,1,250,2)))); | ||
94 : | ktanaka | 1.1 | pm.push_back(PatMatch(4,4, |
95 : | ktanaka | 1.4 | "?.??" |
96 : | ktanaka | 1.1 | ".@.." |
97 : | ".@@@" | ||
98 : | ktanaka | 1.4 | "?@?.", |
99 : | ktanaka | 1.1 | Assumption() |
100 : | .add(SimpleAssumption(YokoMask,JointStart,1.5,2,0,0)) | ||
101 : | .add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointStart,1.5,2,270,2)))); | ||
102 : | ktanaka | 1.4 | pm.push_back(PatMatch(5,3, |
103 : | "?...?" | ||
104 : | ".@@@." | ||
105 : | ".@@.?", | ||
106 : | SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),Start,1.5,0.5,270,2))); | ||
107 : | pm.push_back(PatMatch(5,4, | ||
108 : | "*@@*?" | ||
109 : | "?.@@." | ||
110 : | "?.@@." | ||
111 : | "??..?", | ||
112 : | SimpleAssumption(TenMask,End,2.5,2.5,300,2))); | ||
113 : | pm.push_back(PatMatch(4,3, | ||
114 : | "*.??" | ||
115 : | "*@*?" | ||
116 : | "?*@*", | ||
117 : | SimpleAssumption(TenMask,Start,1,1,315,1))); | ||
118 : | ktanaka | 1.1 | pm.push_back(PatMatch(4,4, |
119 : | ".@@." | ||
120 : | ".@@@" | ||
121 : | ".@@." | ||
122 : | "....", | ||
123 : | Assumption() | ||
124 : | .add(SimpleAssumption(YokoMask,JointStart,1.5,2,0,0)) | ||
125 : | .add(SimpleAssumption(TateMask,JointEnd,1.5,1,270,2)))); | ||
126 : | ktanaka | 1.4 | pm.push_back(PatMatch(4,5, |
127 : | ".@@." | ||
128 : | ".@@@" | ||
129 : | ".@@." | ||
130 : | ".@@." | ||
131 : | "....", | ||
132 : | Assumption() | ||
133 : | .add(SimpleAssumption(YokoMask,JointStart,1.5,2,0,0)) | ||
134 : | .add(SimpleAssumption(TateMask,JointEnd,1.5,1,270,2)))); | ||
135 : | ktanaka | 1.1 | pm.push_back(PatMatch(4,4, |
136 : | ".@@." | ||
137 : | "@@@." | ||
138 : | ".@@." | ||
139 : | "....", | ||
140 : | Assumption() | ||
141 : | .add(SimpleAssumption(YokoMask,JointEnd,1.5,2,0,0)) | ||
142 : | .add(SimpleAssumption(TateMask,JointEnd,1.5,1,270,2)))); | ||
143 : | } | ||
144 : | ktanaka | 1.4 | std::vector<MatchResult> findMatch(const BitmapFont& bf) const{ |
145 : | std::vector<MatchResult> mr; | ||
146 : | std::vector<PatMatch>::const_iterator it; | ||
147 : | ktanaka | 1.1 | for(it=pm.begin();it!=pm.end();it++) |
148 : | for(int y= -1; y<bf.getHeight(); y++) | ||
149 : | ktanaka | 1.4 | for(int x= -1;x<bf.getWidth();x++){ |
150 : | int penalty=it->matchPenalty(bf,x,y); | ||
151 : | if(penalty>=0) | ||
152 : | mr.push_back(MatchResult(x,y,*it,penalty)); | ||
153 : | } | ||
154 : | ktanaka | 1.1 | return mr; |
155 : | } | ||
156 : | ktanaka | 1.4 | std::vector<pixel> notCovered(const BitmapFont& bf) const{ |
157 : | std::vector<MatchResult> mr=findMatch(bf); | ||
158 : | std::vector<std::set<int> > pixel2match(bf.getSize()); | ||
159 : | std::vector<std::set<int> > match2pixel(mr.size()); | ||
160 : | std::vector<MatchResult>::iterator it; | ||
161 : | ktanaka | 1.1 | for(it=mr.begin();it!=mr.end();it++){ |
162 : | ktanaka | 1.2 | int n= it-mr.begin(); |
163 : | ktanaka | 1.4 | std::vector<pixel> ps=(*it).getPixels(); |
164 : | std::vector<pixel>::iterator ips; | ||
165 : | ktanaka | 1.2 | for(ips=ps.begin();ips!=ps.end();ips++){ |
166 : | int m=bf.getIndex(*ips); | ||
167 : | ktanaka | 1.4 | std::cout << '(' << ips->first << ',' << ips->second << ")\n"; |
168 : | ktanaka | 1.2 | assert(m != -1); |
169 : | match2pixel[n].insert(m); | ||
170 : | pixel2match[m].insert(n); | ||
171 : | } | ||
172 : | } | ||
173 : | ktanaka | 1.4 | std::vector<pixel> ret; |
174 : | ktanaka | 1.2 | for(int i=0;i<bf.getPixelSize();i++){ |
175 : | ktanaka | 1.3 | if(pixel2match[i].empty()) { |
176 : | ret.push_back(bf.getPixelAt(i)); | ||
177 : | } | ||
178 : | ktanaka | 1.1 | } |
179 : | ktanaka | 1.3 | return ret; |
180 : | ktanaka | 1.1 | } |
181 : | }; | ||
182 : | ostream& operator<<(ostream &os,const Matchers &mt){ | ||
183 : | os << "Matchers("; | ||
184 : | ktanaka | 1.4 | std::vector<PatMatch>::const_iterator it; |
185 : | ktanaka | 1.1 | for(it=mt.pm.begin();it!=mt.pm.end();it++){ |
186 : | os << *it << ','; | ||
187 : | } | ||
188 : | os << ')'; | ||
189 : | return os; | ||
190 : | } | ||
191 : | ostream& operator<<(ostream &os,const MatchResult &mr){ | ||
192 : | ktanaka | 1.4 | os << "MatchResult(" << mr.x << "," << mr.y << "," << mr.pm |
193 : | << "," << mr.penalty << ")"; | ||
194 : | ktanaka | 1.1 | return os; |
195 : | } | ||
196 : | #endif /* _MATCHERS_H */ |
ktanaka Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |