00001 package baseMeshGeneration.utilities;
00002
00003 import java.beans.Encoder;
00004 import java.io.PrintStream;
00005 import java.util.ArrayList;
00006
00007 import Encoder.EncoderEdge;
00008 import ImageStuff.Image;
00009 import ImageStuff.Pixel;
00010 import ImageStuff.Vertex;
00011 import NormalMeshAlgorithm.Configuration;
00012
00018 public class RegularLatice {
00019 private int breedte, hoogte;
00020 ArrayList<EncoderEdge> edges;
00021 int K;
00022 private Image image;
00023 protected Configuration configuration;
00024 public RegularLatice(Image image,int K,Configuration configuration){
00025 this.configuration=configuration;
00026 this.breedte=Image.getInstance().getBreedte();
00027 this.hoogte=Image.getInstance().getHoogte();
00028 this.K=K;
00029 this.image=image;
00030 edges= new ArrayList<EncoderEdge>(K);
00031 make();
00032 }
00033
00034 private void make(){
00035
00036
00037 float opp_image=Image.getInstance().xresolutie*Image.getInstance().yresolutie;
00038 float opp_vierkantje=opp_image/this.K;
00039 float lengte_zijde=(float)Math.sqrt(opp_vierkantje);
00040 int aantal_vertikale_lijnen=(int)Math.floor(Image.getInstance().getHoogte()/lengte_zijde);
00041 int aantal_horizontale_lijnen=(int)Math.floor( Image.getInstance().getBreedte()/lengte_zijde);
00042 int aantal_vertikale_punten=aantal_vertikale_lijnen+1;
00043 int aantal_horizontale_punten=aantal_horizontale_lijnen+1;
00044 float vert_lengte=Image.getInstance().getHoogte()/aantal_vertikale_lijnen;
00045 float hor_lengte=Image.getInstance().getBreedte()/aantal_horizontale_lijnen;
00046
00047 Pixel p1,p2,p3,p4;
00048 for(int g=0;g!=aantal_vertikale_punten-1;g++){
00049 for(int h=0;h!=aantal_horizontale_punten-1;h++){
00050
00051
00052 int vert_plus_een=(int)((g+1)*vert_lengte);
00053 int hor_plus_een=(int)((h+1)*hor_lengte);
00054 if(h==aantal_horizontale_punten-2){
00055 hor_plus_een=Image.getInstance().xresolutie-1;
00056 }
00057 if(g==aantal_vertikale_punten-2){
00058 vert_plus_een=Image.getInstance().yresolutie-1;
00059 }
00060
00061 p1=Image.getInstance().getPuntOpEnty((int)(h*hor_lengte),(int)(g*vert_lengte));
00062 p2=Image.getInstance().getPuntOpEnty((int)(h*hor_lengte),vert_plus_een);
00063 p3=Image.getInstance().getPuntOpEnty(hor_plus_een,vert_plus_een);
00064 p4=Image.getInstance().getPuntOpEnty(hor_plus_een,(int)(g*vert_lengte));
00065 EncoderEdge een=new EncoderEdge(new Vertex(p1),new Vertex(p2),configuration);
00066 EncoderEdge twee=new EncoderEdge(new Vertex(p2),new Vertex(p3),configuration);
00067
00068
00069 EncoderEdge vijf=new EncoderEdge(new Vertex(p1),new Vertex(p3),configuration);
00070
00082 edges.add(een);
00083 edges.add(twee);
00084
00085
00086 edges.add(vijf);
00087 }
00088 }
00089
00090
00091 for(int g=0;g!=aantal_vertikale_punten-1;g++){
00092 int vert_plus_een=(int)((g+1)*vert_lengte);
00093
00094 if(g==aantal_vertikale_punten-2){
00095 vert_plus_een=Image.getInstance().yresolutie-1;
00096 }
00097
00098 p1=Image.getInstance().getPuntOpEnty(image.getBreedte()-1,(int)(g*vert_lengte));
00099 p2=Image.getInstance().getPuntOpEnty(image.getBreedte()-1,vert_plus_een);
00100 EncoderEdge een=new EncoderEdge(new Vertex(p1),new Vertex(p2),configuration);
00101 edges.add(een);
00102 }
00103 for(int h=0;h!=aantal_horizontale_punten-1;h++){
00104 int hor_plus_een=(int)((h+1)*hor_lengte);
00105 if(h==aantal_horizontale_punten-2){
00106 hor_plus_een=Image.getInstance().xresolutie-1;
00107 }
00108
00109
00110 p1=Image.getInstance().getPuntOpEnty((int)(h*hor_lengte),image.getHoogte()-1);
00111 p4=Image.getInstance().getPuntOpEnty(hor_plus_een,image.getHoogte()-1);
00112 EncoderEdge een=new EncoderEdge(new Vertex(p1),new Vertex(p4),configuration);
00113 edges.add(een);
00114 }
00115
00116 }
00117
00118 public ArrayList<EncoderEdge> getEncoderEgdes(){
00119 return edges;
00120 }
00121
00122 public void print(PrintStream out,String pre){
00123 out.println(pre+"edges=[");
00124 for(EncoderEdge e: edges){
00125 out.println("["+ e.getBegin().getX() + " " +e.getBegin().getY()+"]");
00126 out.println("["+ e.getEind().getX() + " " +e.getEind().getY()+"]");
00127 }
00128 out.println("]");
00129 }
00130
00131 public Image getImage() {
00132 return image;
00133 }
00134
00135 }