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