[wadalabfont-kit] / jis2prim / Matchers.h  

View of /jis2prim/Matchers.h

Parent Directory | Revision Log
Revision: 1.3 - (download) (as text) (annotate)
Tue Mar 19 00:33:14 2002 UTC (22 years, 8 months ago) by ktanaka
Branch: MAIN
Changes since 1.2: +17 -6 lines
*** empty log message ***
#ifndef _MATCHERS_H
#define _MATCHERS_H

#include <vector>
#include <set>
/* Matchters */
#include "PatMatch.h"
#include "BitmapFont.h"

class MatchResult {
  friend ostream& operator<<(ostream &os,const MatchResult &mr);
 protected:
  int x,y;
  PatMatch pm;
 public:
  MatchResult(int xx, int yy,const PatMatch& p) :x(xx),y(yy),pm(p){}
  vector<pixel> getPixels() const {
    return pm.getPixels(x,y);
  }
};

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

ktanaka

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help