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