import java.util.*; import java.awt.*; public class Mametan { Vector root; Vector vect; Vector state; ArrayImage img; Database base; public Mametan(ArrayImage img,Point edge) { root = new Vector(); vect = new Vector(); state = new Vector(); base = new Database(); root.add(edge); this.img = img; } public Point getRoot(int i) { if( i < root.size()) { return root.get(i); } else { return null; } } private int kakudo(Point vec) { double x = vec.getX(); double y = vec.getY(); double s; s = Math.acos(x/Math.sqrt(x*x+y*y)); s=(s/3.14)*180.0; if (y<0) /* ƒÆ„ƒÎ‚ÌŽž */ s=360-s; return (int)Math.floor(s); } private int tikasa(Point gent,Point vect) { // System.out.println( // "tikasa"+ kakudo(gent)+" "+ kakudo(vect) // ); int gen = kakudo(gent); int vec = kakudo(vect); if(gen < 90 && vec >270) { return gen-(360 - vec); } else if(vec < 90 && gen >270) { return (360-gen)-vec; } return gen - vec; } public void startDeconvolution() { Vector temp = null; // root.removeAllElements(); //vect.removeAllElements(); temp = nominateNext(); if(temp == null) { System.out.println("earch lost");return; } for(int i=0; temp != null &&temp.size()!= 0;i++) { if(i >5) { vect.add( new Point( (int)(root.get(i-1).getX() - root.get(i-3).getX()) , (int)(root.get(i-1).getY() - root.get(i-3).getY()) )); int num= 0; int sum= 360; int tp=0; for(int j=0; j< temp.size();j++) { tp = tikasa( vect.get(vect.size()-1),new Point ( (int)(temp.get(j).getX()-root.get(i-1).getX()), (int)(temp.get(j).getY()-root.get(i-1).getY()) ) ); if(tp <0){tp *=-1;} if(sum > tp){num = j; sum = tp; } } if( i > 15 ) { // System.out.println("sdf"); int sa = tikasa(vect.get(i-6),vect.get(i-12)); if(sa < 0 ){sa*=-1;} if( 85 < sa) { // System.out.println("2"+sa); state.add(2); } else if( 25 < sa) { // System.out.println("1"+sa); state.add(1); } else { // System.out.println("0"+sa); state.add(0); } } root.add(temp.get(num)); temp = nominateNext(); } else { root.add(temp.get(0)); temp = nominateNext(); } } } private Vector nominateNext() { Point st = root.get(root.size()-1); int x = (int)st.getX(); int y = (int)st.getY(); Vector next = new Vector(); if(img.index(x,y+1) > 0 && !havePoint(x,y+1)) {next.add(new Point(x ,y+1));} if(img.index(x+1,y) > 0 && !havePoint(x+1,y)) {next.add(new Point(x+1,y));} if(img.index(x+1,y+1) > 0 && !havePoint(x+1,y+1)) {next.add(new Point(x+1,y+1 ));} if(img.index(x+1,y-1) > 0 && !havePoint(x+1,y-1)) {next.add(new Point(x+1,y-1));} if(img.index(x-1,y-1) > 0 && !havePoint(x-1,y-1)) {next.add(new Point(x-1,y-1));} if(img.index(x-1,y) > 0 && !havePoint(x-1,y)) {next.add(new Point(x-1,y ));} if(img.index(x-1,y+1) > 0 && !havePoint(x-1,y+1)) {next.add(new Point(x-1,y+1));} if(img.index(x,y-1) > 0 && !havePoint(x,y-1)) {next.add(new Point(x ,y-1));} return next; } public int getKakuNum() { int num = 0; int kazu = 0; for(int i= 0;i< state.size();i++) { if(state.get(i)== 2) { if(num +8 > i) { num = i; } else { num = i; kazu++; } } } return kazu; } public boolean haveKaku() { int sum = 0; for(int i= 0;i< state.size();i++) { if(state.get(i)== 2) { sum++; } } if(sum >= 5) { return true; } else { return false; } } public boolean haveMagaru() { int sum = 0; for(int i= 0;i< state.size();i++) { if(state.get(i)== 1) { sum++; } } if(sum > 10) { return true; } else { return false; } } public boolean haveMaxtusugu() { int sum = 0; for(int i= 0;i< state.size();i++) { if(state.get(i)== 0) { sum++; } } if(sum >= 20) { return true; } else { return false; } } private boolean havePoint(int x,int y) { for(int i= 0;i