00001 00006 package watershed; 00007 00008 import java.util.ArrayList; 00009 00010 /* 00011 * Watershed algorithm 00012 * 00013 * Copyright (c) 2003 by Christopher Mei (christopher.mei@sophia.inria.fr) 00014 * 00015 * This plugin is free software; you can redistribute it and/or modify 00016 * it under the terms of the GNU General Public License version 2 00017 * as published by the Free Software Foundation. 00018 * 00019 * This program is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 * GNU General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU General Public License 00025 * along with this plugin; if not, write to the Free Software 00026 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00027 */ 00028 00029 00040 public class WatershedPixel implements Comparable { 00042 final static int INIT = -1; 00043 00048 final static int MASK = -2; 00049 00053 final static int WSHED = 0; 00054 00056 final static int FICTITIOUS = -3; 00057 00059 private int x; 00061 private int y; 00063 private short height; 00065 private int label; 00067 private int dist; 00068 00070 private ArrayList neighbours; 00071 00072 public WatershedPixel(int x, int y, short height) { 00073 this.x = x; 00074 this.y = y; 00075 this.height = height; 00076 label = INIT; 00077 dist = 0; 00078 neighbours = new ArrayList(8); 00079 } 00080 00081 public WatershedPixel() { 00082 label = FICTITIOUS; 00083 } 00084 00085 public void addNeighbour(WatershedPixel neighbour) { 00086 neighbours.add(neighbour); 00087 } 00088 00089 public ArrayList getNeighbours() { 00090 return neighbours; 00091 } 00092 00093 public final short getHeight() { 00094 return height; 00095 } 00096 00097 public final int getIntHeight() { 00098 return height & 0xff; 00099 } 00100 00101 public final int getX() { 00102 return x; 00103 } 00104 00105 public final int getY() { 00106 return y; 00107 } 00108 00110 public int compareTo(Object o) { 00111 WatershedPixel obj = (WatershedPixel) o; 00112 return (getIntHeight()) - (obj.getIntHeight()); 00113 } 00114 00115 public void setLabel(int label) { 00116 this.label = label; 00117 } 00118 00119 public void setLabelToINIT() { 00120 label = INIT; 00121 } 00122 00123 public void setLabelToMASK() { 00124 label = MASK; 00125 } 00126 00127 public void setLabelToWSHED() { 00128 label = WSHED; 00129 } 00130 00131 public boolean isLabelINIT() { 00132 return label == INIT; 00133 } 00134 00135 public boolean isLabelMASK() { 00136 return label == MASK; 00137 } 00138 00139 public boolean isLabelWSHED() { 00140 return label == WSHED; 00141 } 00142 00143 public int getLabel() { 00144 return label; 00145 } 00146 00147 public void setDistance(int distance) { 00148 dist = distance; 00149 } 00150 00151 public int getDistance() { 00152 return dist; 00153 } 00154 00155 public boolean isFICTITIOUS() { 00156 return label == FICTITIOUS; 00157 } 00158 00159 public boolean allNeighboursAreWSHED() { 00160 for (int i = 0; i < neighbours.size(); i++) { 00161 WatershedPixel r = (WatershedPixel) neighbours.get(i); 00162 00163 if (!r.isLabelWSHED()) 00164 return false; 00165 } 00166 return true; 00167 } 00168 }