3 import ij.plugin.filter.Analyzer;
14 public static final int MAX_COLUMNS = 50;
16 public static final int COLUMN_NOT_FOUND = -1;
17 public static final int COLUMN_IN_USE = -2;
18 public static final int TABLE_FULL = -3;
20 public static final int AREA=0, MEAN=1, STD_DEV=2, MODE=3, MIN=4, MAX=5,
21 X_CENTROID=6, Y_CENTROID=7, X_CENTER_OF_MASS=8, Y_CENTER_OF_MASS=9,
22 PERIMETER=10, ROI_X=11, ROI_Y=12, ROI_WIDTH=13, ROI_HEIGHT=14,
23 MAJOR=15, MINOR=16, ANGLE=17, CIRCULARITY=18, FERET=19;
25 private String[] headings =
new String[MAX_COLUMNS];
26 private String[] defaultHeadings = {
"Area",
"Mean",
"StdDev",
"Mode",
"Min",
"Max",
27 "X",
"Y",
"XM",
"YM",
"Perim.",
"BX",
"BY",
"Width",
"Height",
"Major",
"Minor",
"Angle",
30 private float[][] columns =
new float[MAX_COLUMNS][];
31 private String[] rowLabels;
32 private int maxRows = 100;
33 private int lastColumn = -1;
34 private StringBuffer sb;
35 private int precision = 3;
36 private String rowLabelHeading =
"";
40 for(
int i=0; i<defaultHeadings.length; i++)
41 headings[i] = defaultHeadings[i];
53 if (counter==maxRows) {
54 if (rowLabels!=null) {
55 String[] s =
new String[maxRows*2];
56 System.arraycopy(rowLabels, 0, s, 0, maxRows);
59 for (
int i=0; i<MAX_COLUMNS; i++) {
60 if (columns[i]!=null) {
61 float[] tmp =
new float[maxRows*2];
62 System.arraycopy(columns[i], 0, tmp, 0, maxRows);
76 public void addValue(
int column,
double value) {
77 if ((column<0) || (column>=MAX_COLUMNS))
78 throw new IllegalArgumentException(
"Index out of range: "+column);
80 throw new IllegalArgumentException(
"Counter==0");
81 if (columns[column]==null) {
82 columns[column] =
new float[maxRows];
83 if (headings[column]==null)
84 headings[column] =
"---";
85 if (column>lastColumn) lastColumn = column;
87 columns[column][counter-1] = (float)value;
92 public void addValue(String column,
double value) {
94 if (index==COLUMN_NOT_FOUND) {
96 if (index==TABLE_FULL)
97 throw new IllegalArgumentException(
"table is full");
103 public void addLabel(String columnHeading, String label) {
105 throw new IllegalArgumentException(
"Counter==0");
107 rowLabels =
new String[maxRows];
108 rowLabels[counter-1] = label;
109 if (columnHeading!=null)
110 rowLabelHeading = columnHeading;
121 if ((column<0) || (column>=MAX_COLUMNS))
122 throw new IllegalArgumentException(
"Index out of range: "+column);
123 if (columns[column]==null)
126 float[] data =
new float[counter];
127 for (
int i=0; i<counter; i++)
128 data[i] = columns[column][i];
135 if ((column<0) || (column>=MAX_COLUMNS))
138 return columns[column]!=null;
144 for(
int i=0; i<headings.length; i++) {
145 if (headings[i]==null)
146 return COLUMN_NOT_FOUND;
147 else if (headings[i].equals(heading))
150 return COLUMN_NOT_FOUND;
158 for(
int i=0; i<headings.length; i++) {
159 if (headings[i]==null) {
160 columns[i] =
new float[maxRows];
161 headings[i] = heading;
162 if (i>lastColumn) lastColumn = i;
165 if (headings[i].equals(heading))
166 return COLUMN_IN_USE;
176 if (columns[column]==null)
177 throw new IllegalArgumentException(
"Column not defined: "+column);
178 if (column>=MAX_COLUMNS || row>=counter)
179 throw new IllegalArgumentException(
"Index out of range: "+column+
","+row);
180 return columns[column][row];
190 throw new IllegalArgumentException(
"Row out of range");
192 if (col==COLUMN_NOT_FOUND)
193 throw new IllegalArgumentException(
"\""+column+
"\" column not found");
203 public void setValue(String column,
int row,
double value) {
205 if (col==COLUMN_NOT_FOUND) {
208 throw new IllegalArgumentException(
"Too many columns (>"+(MAX_COLUMNS-defaultHeadings.length)+
")");
215 public void setValue(
int column,
int row,
double value) {
216 if ((column<0) || (column>=MAX_COLUMNS))
217 throw new IllegalArgumentException(
"Column out of range: "+column);
219 throw new IllegalArgumentException(
"row>=counter");
220 if (columns[column]==null) {
221 columns[column] =
new float[maxRows];
222 if (column>lastColumn) lastColumn = column;
224 columns[column][row] = (float)value;
229 StringBuffer sb =
new StringBuffer(200);
232 sb.append(rowLabelHeading +
"\t");
234 for (
int i=0; i<=lastColumn; i++) {
235 if (columns[i]!=null) {
236 heading = headings[i];
237 if (heading==null) heading =
"---";
238 sb.append(heading +
"\t");
241 return new String(sb);
246 if ((column<0) || (column>=MAX_COLUMNS))
247 throw new IllegalArgumentException(
"Index out of range: "+column);
248 return headings[column];
254 if ((row<0) || (row>=counter))
255 throw new IllegalArgumentException(
"Row out of range: "+row);
257 sb =
new StringBuffer(200);
260 sb.append(Integer.toString(row+1));
262 if (rowLabels!=null) {
263 if (rowLabels[row]!=null)
264 sb.append(rowLabels[row]);
267 for (
int i=0; i<=lastColumn; i++) {
268 if (columns[i]!=null)
269 sb.append(n(columns[i][row]));
271 return new String(sb);
276 if ((column<0) || (column>=headings.length))
277 throw new IllegalArgumentException(
"Column out of range: "+column);
278 headings[column] = heading;
283 this.precision = precision;
288 if (Math.round(n)==n)
291 s =
IJ.
d2s(n,precision);
299 for (
int i=0; i<=lastColumn; i++) {
301 if (i<defaultHeadings.length)
302 headings[i] = defaultHeadings[i];
311 public void show(String windowTitle) {
314 if (windowTitle.equals(
"Results")) {
316 if (tp==null)
return;
325 StringBuffer sb =
new StringBuffer(n*tableHeadings.length());
326 for (
int i=0; i<n; i++)
328 tp.append(
new String(sb));
332 public String toString() {