00001
00002 package ImageStuff;
00003 import TxTPackage.*;
00004
00005 import java.awt.Dimension;
00006 import java.awt.image.*;
00007 import java.util.ArrayList;
00008
00009 import javax.media.jai.PlanarImage;
00010
00011 import ImageTools.ImportImage;
00012 import NormalMeshAlgorithm.Configuration;
00013
00014 public class Image {
00015
00016 public int xresolutie;
00017
00018 public int yresolutie;
00019
00020 private int MAXZ;
00021
00022 protected Pixel[][] pixelmatrix;
00023
00024 private static Image instance;
00025
00026 private static String NAAM_HUIDIG_BEELD = "no_name_yet";
00027
00028 public static Image getInstance() {
00029 if (instance != null)
00030 return instance;
00031 Debug.print("eerst beeld zetten alvorens te getten!!");
00032 System.exit(-1);
00033 return null;
00034 }
00035
00036 private static WritableRaster writableRaster;
00037
00038 public static WritableRaster getWritableRaster() {
00039 return writableRaster;
00040 }
00041
00042 private static void setWritableRaster(WritableRaster writableRaster1) {
00043 writableRaster = writableRaster1;
00044 }
00045
00046
00047 public static void setInstance(String path, Configuration conf){
00048 setInstance(ImportImage.Kleur_naar_grijs(ImportImage.leesBeeld(path)),conf);
00049 }
00050
00051
00052 public static void setInstance(WritableRaster r, Configuration conf) {
00053 setWritableRaster(r);
00054 int breedte = r.getWidth();
00055 int hoogte = r.getHeight();
00056 Pixel[][] static_pixelmatrix = new Pixel[breedte][hoogte];
00057 double[] grijswaarde = new double[1];
00058 for (int i = 0; i != breedte; i++) {
00059 for (int j = 0; j != hoogte; j++) {
00060 r.getPixel(i, j, grijswaarde);
00061 static_pixelmatrix[i][j] = new Pixel(i, j,
00062 (float) grijswaarde[0]);
00063 }
00064 }
00065 instance = new Image(static_pixelmatrix);
00066 }
00067
00068 public static void setInstance(Dimension d) {
00069 int breedte =(int) d.getWidth();
00070 int hoogte =(int) d.getHeight();
00071 Pixel[][] static_pixelmatrix = new Pixel[breedte][hoogte];
00072 for (int i = 0; i != breedte; i++) {
00073 for (int j = 0; j != hoogte; j++) {
00074 static_pixelmatrix[i][j] = new Pixel(i, j,0);
00075 }
00076 }
00077 instance = new Image(static_pixelmatrix);
00078 }
00079
00080
00081
00082 private Image(Pixel[][] pixelmatrix) {
00083 this.pixelmatrix = pixelmatrix;
00084 xresolutie = pixelmatrix.length;
00085 yresolutie = pixelmatrix[0].length;
00086 MAXZ = 300;
00087 }
00088
00089
00090
00091 public Image(int xresolutie, int yresolutie) {
00092 this.xresolutie = xresolutie;
00093 this.yresolutie = yresolutie;
00094 pixelmatrix = new Pixel[xresolutie][yresolutie];
00095 for (int i = 0; i != pixelmatrix.length; i++) {
00096 for (int j = 0; j != pixelmatrix[0].length; j++) {
00097 pixelmatrix[i][j] = new Pixel(i, j, 0);
00098 }
00099 }
00100
00101 }
00102
00103 public boolean isOnCorner(Loc l){
00104 if(( l.getX()==0 && l.getY()==this.getHoogte()-1)
00105 || (l.getX()==this.getBreedte()-1 && l.getY()==this.getHoogte()-1)
00106 || (l.getX()==0 && l.getY()==0)
00107 || (l.getX()==this.getBreedte()-1 && l.getY()==0)
00108 ){
00109 return true;
00110 }
00111 return false;
00112 }
00113
00114 public ArrayList<Pixel> getHoekPunten() {
00115 ArrayList<Pixel> hoekpunten = new ArrayList<Pixel>(4);
00116 hoekpunten.add(this.getPuntOpEnty(0, 0));
00117 hoekpunten.add(this.getPuntOpEnty(0, this.getHoogte() - 1));
00118 hoekpunten.add(this.getPuntOpEnty(this.getBreedte() - 1, 0));
00119 hoekpunten.add(this.getPuntOpEnty(this.getBreedte() - 1, this
00120 .getHoogte() - 1));
00121 return hoekpunten;
00122 }
00123
00124 public int getMaxZ() {
00125 return MAXZ;
00126 }
00127
00128 public int getBreedte() {
00129 return this.xresolutie;
00130 }
00131
00132 public int getHoogte() {
00133 return this.yresolutie;
00134 }
00135
00136 public final Pixel getPuntOpEnty(int i, int j) {
00137 return this.pixelmatrix[i][j];
00138 }
00139
00140 public final Pixel getPuntOpEnty(Loc loc) {
00141 Pixel p = this.getPuntOpEnty(loc.getX(), loc.getY());
00142 if (!p.isOn(loc)) {
00143 Debug.print("Major Error in Image-> getpunt op Entry");
00144 System.exit(-1);
00145 }
00146 return this.getPuntOpEnty(loc.getX(), loc.getY());
00147 }
00148
00149 public void setValue(Loc l, float value) {
00150 this.pixelmatrix[l.getX()][l.getY()].setZ(value);
00151 }
00152
00153 }
00154