protected: |
protected: |
int x,y; |
int x,y; |
PatMatch pm; |
PatMatch pm; |
|
int penalty; |
public: |
public: |
MatchResult(int xx, int yy,const PatMatch& p) :x(xx),y(yy),pm(p){} |
MatchResult(int xx, int yy,const PatMatch& p,int penalty) :x(xx),y(yy),pm(p),penalty(penalty){} |
vector<pixel> getPixels() const { |
std::vector<pixel> getPixels() const { |
return pm.getPixels(x,y); |
return pm.getPixels(x,y); |
} |
} |
}; |
}; |
class Matchers { |
class Matchers { |
friend ostream& operator<<(ostream &os,const Matchers &mt); |
friend ostream& operator<<(ostream &os,const Matchers &mt); |
protected: |
protected: |
vector<PatMatch> pm; |
std::vector<PatMatch> pm; |
public: |
public: |
Matchers(){ |
Matchers(){ |
pm.push_back(PatMatch(3,3, |
pm.push_back(PatMatch(3,3, |
.add(SimpleAssumption(YokoMask,Mid,1,1,0,0)) |
.add(SimpleAssumption(YokoMask,Mid,1,1,0,0)) |
.add(SimpleAssumption(HidariMask,Mid,1,1,180,1)))); |
.add(SimpleAssumption(HidariMask,Mid,1,1,180,1)))); |
pm.push_back(PatMatch(4,3, |
pm.push_back(PatMatch(4,3, |
"...." |
"...?" |
"@@@@" |
"@@@@" |
".@@.", |
".@@.", |
Assumption() |
Assumption() |
"....?" |
"....?" |
".@@.." |
".@@.." |
"@@@@." |
"@@@@." |
".....", |
"?...?", |
SimpleAssumption(YokoMask,End,3,2,0,2))); |
SimpleAssumption(YokoMask,End,3,2,0,2))); |
pm.push_back(PatMatch(4,2, |
pm.push_back(PatMatch(4,2, |
".@@." |
".@@." |
".@@.", |
".@@.", |
SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointStart,1.5,1,270,2))); |
SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointStart,1.5,1,270,2))); |
|
pm.push_back(PatMatch(5,2, |
|
"..@@." |
|
".@@..", |
|
SimpleAssumption((PtypeMask)(TatehidariMask|HidariMask),JointStart,2,0.5,225,1.7))); |
|
pm.push_back(PatMatch(4,2, |
|
"?*@*" |
|
"*@*?", |
|
SimpleAssumption((PtypeMask)(TatehidariMask|HidariMask),JointStart,1.5,0.5,225,1))); |
|
pm.push_back(PatMatch(4,3, |
|
"?*@*" |
|
"*@@*" |
|
"*@*?", |
|
SimpleAssumption((PtypeMask)(TatehidariMask|HidariMask),JointStart,1.5,0.5,225,1))); |
pm.push_back(PatMatch(4,3, |
pm.push_back(PatMatch(4,3, |
".@@." |
".@@." |
"@@@@" |
"@@@@" |
Assumption() |
Assumption() |
.add(SimpleAssumption(YokoMask,Mid,1.5,1,0,0)) |
.add(SimpleAssumption(YokoMask,Mid,1.5,1,0,0)) |
.add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),Mid,1.5,1,270,2)))); |
.add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),Mid,1.5,1,270,2)))); |
|
pm.push_back(PatMatch(5,3, |
|
"..@@." |
|
"@@@@@" |
|
".@@..", |
|
Assumption() |
|
.add(SimpleAssumption(YokoMask,Mid,2,1,0,0)) |
|
.add(SimpleAssumption((PtypeMask)(TatehidariMask|HidariMask),Mid,2,1,250,2)))); |
pm.push_back(PatMatch(4,4, |
pm.push_back(PatMatch(4,4, |
"...?" |
"?.??" |
".@.." |
".@.." |
".@@@" |
".@@@" |
".@@.", |
"?@?.", |
Assumption() |
Assumption() |
.add(SimpleAssumption(YokoMask,JointStart,1.5,2,0,0)) |
.add(SimpleAssumption(YokoMask,JointStart,1.5,2,0,0)) |
.add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointStart,1.5,2,270,2)))); |
.add(SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),JointStart,1.5,2,270,2)))); |
|
pm.push_back(PatMatch(5,3, |
|
"?...?" |
|
".@@@." |
|
".@@.?", |
|
SimpleAssumption((PtypeMask)(TateMask|TatehaneMask|TatehidariMask|HidariMask),Start,1.5,0.5,270,2))); |
|
pm.push_back(PatMatch(5,4, |
|
"*@@*?" |
|
"?.@@." |
|
"?.@@." |
|
"??..?", |
|
SimpleAssumption(TenMask,End,2.5,2.5,300,2))); |
|
pm.push_back(PatMatch(4,3, |
|
"*.??" |
|
"*@*?" |
|
"?*@*", |
|
SimpleAssumption(TenMask,Start,1,1,315,1))); |
pm.push_back(PatMatch(4,4, |
pm.push_back(PatMatch(4,4, |
".@@." |
".@@." |
".@@@" |
".@@@" |
Assumption() |
Assumption() |
.add(SimpleAssumption(YokoMask,JointStart,1.5,2,0,0)) |
.add(SimpleAssumption(YokoMask,JointStart,1.5,2,0,0)) |
.add(SimpleAssumption(TateMask,JointEnd,1.5,1,270,2)))); |
.add(SimpleAssumption(TateMask,JointEnd,1.5,1,270,2)))); |
|
pm.push_back(PatMatch(4,5, |
|
".@@." |
|
".@@@" |
|
".@@." |
|
".@@." |
|
"....", |
|
Assumption() |
|
.add(SimpleAssumption(YokoMask,JointStart,1.5,2,0,0)) |
|
.add(SimpleAssumption(TateMask,JointEnd,1.5,1,270,2)))); |
pm.push_back(PatMatch(4,4, |
pm.push_back(PatMatch(4,4, |
".@@." |
".@@." |
"@@@." |
"@@@." |
.add(SimpleAssumption(YokoMask,JointEnd,1.5,2,0,0)) |
.add(SimpleAssumption(YokoMask,JointEnd,1.5,2,0,0)) |
.add(SimpleAssumption(TateMask,JointEnd,1.5,1,270,2)))); |
.add(SimpleAssumption(TateMask,JointEnd,1.5,1,270,2)))); |
} |
} |
vector<MatchResult> findMatch(const BitmapFont& bf) const{ |
std::vector<MatchResult> findMatch(const BitmapFont& bf) const{ |
vector<MatchResult> mr; |
std::vector<MatchResult> mr; |
vector<PatMatch>::const_iterator it; |
std::vector<PatMatch>::const_iterator it; |
for(it=pm.begin();it!=pm.end();it++) |
for(it=pm.begin();it!=pm.end();it++) |
for(int y= -1; y<bf.getHeight(); y++) |
for(int y= -1; y<bf.getHeight(); y++) |
for(int x= -1;x<bf.getWidth();x++) |
for(int x= -1;x<bf.getWidth();x++){ |
if(it->isMatch(bf,x,y)) |
int penalty=it->matchPenalty(bf,x,y); |
mr.push_back(MatchResult(x,y,*it)); |
if(penalty>=0) |
|
mr.push_back(MatchResult(x,y,*it,penalty)); |
|
} |
return mr; |
return mr; |
} |
} |
vector<pixel> notCovered(const BitmapFont& bf) const{ |
std::vector<pixel> notCovered(const BitmapFont& bf) const{ |
vector<MatchResult> mr=findMatch(bf); |
std::vector<MatchResult> mr=findMatch(bf); |
vector<set<int> > pixel2match(bf.getSize()); |
std::vector<std::set<int> > pixel2match(bf.getSize()); |
vector<set<int> > match2pixel(mr.size()); |
std::vector<std::set<int> > match2pixel(mr.size()); |
vector<MatchResult>::iterator it; |
std::vector<MatchResult>::iterator it; |
for(it=mr.begin();it!=mr.end();it++){ |
for(it=mr.begin();it!=mr.end();it++){ |
int n= it-mr.begin(); |
int n= it-mr.begin(); |
vector<pixel> ps=(*it).getPixels(); |
std::vector<pixel> ps=(*it).getPixels(); |
vector<pixel>::iterator ips; |
std::vector<pixel>::iterator ips; |
for(ips=ps.begin();ips!=ps.end();ips++){ |
for(ips=ps.begin();ips!=ps.end();ips++){ |
int m=bf.getIndex(*ips); |
int m=bf.getIndex(*ips); |
cout << '(' << ips->first << ',' << ips->second << ")\n"; |
std::cout << '(' << ips->first << ',' << ips->second << ")\n"; |
assert(m != -1); |
assert(m != -1); |
match2pixel[n].insert(m); |
match2pixel[n].insert(m); |
pixel2match[m].insert(n); |
pixel2match[m].insert(n); |
} |
} |
} |
} |
vector<pixel> ret; |
std::vector<pixel> ret; |
for(int i=0;i<bf.getPixelSize();i++){ |
for(int i=0;i<bf.getPixelSize();i++){ |
if(pixel2match[i].empty()) { |
if(pixel2match[i].empty()) { |
ret.push_back(bf.getPixelAt(i)); |
ret.push_back(bf.getPixelAt(i)); |
}; |
}; |
ostream& operator<<(ostream &os,const Matchers &mt){ |
ostream& operator<<(ostream &os,const Matchers &mt){ |
os << "Matchers("; |
os << "Matchers("; |
vector<PatMatch>::const_iterator it; |
std::vector<PatMatch>::const_iterator it; |
for(it=mt.pm.begin();it!=mt.pm.end();it++){ |
for(it=mt.pm.begin();it!=mt.pm.end();it++){ |
os << *it << ','; |
os << *it << ','; |
} |
} |
return os; |
return os; |
} |
} |
ostream& operator<<(ostream &os,const MatchResult &mr){ |
ostream& operator<<(ostream &os,const MatchResult &mr){ |
os << "MatchResult(" << mr.x << "," << mr.y << "," << mr.pm << ")"; |
os << "MatchResult(" << mr.x << "," << mr.y << "," << mr.pm |
|
<< "," << mr.penalty << ")"; |
return os; |
return os; |
} |
} |
#endif /* _MATCHERS_H */ |
#endif /* _MATCHERS_H */ |