Revision 12504
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/colortable/panels/ColorTTable.java | ||
---|---|---|
26 | 26 |
import org.gvsig.gui.beans.table.TableContainer; |
27 | 27 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
28 | 28 |
|
29 |
import com.iver.andami.PluginServices; |
|
29 | 30 |
/** |
30 | 31 |
* |
31 | 32 |
* @version 27/06/2007 |
... | ... | |
33 | 34 |
*/ |
34 | 35 |
public class ColorTTable extends JPanel { |
35 | 36 |
private static final long serialVersionUID = -6971866166164473789L; |
36 |
private TableContainer table = null; |
|
37 |
private TableContainer tableContainer = null;
|
|
37 | 38 |
|
38 | 39 |
public ColorTTable() { |
39 | 40 |
initialize(); |
40 | 41 |
} |
41 | 42 |
|
42 | 43 |
private void initialize() { |
43 |
String[] columnNames = { "Bot?n", "columna2", "columna3", "columna 4", "col5" }; |
|
44 |
int[] columnWidths = { 54, 114, 94, 114, 60 }; |
|
45 |
table = new TableContainer(columnNames, columnWidths); |
|
46 |
table.setModel("TableButtonModel"); |
|
47 |
table.initialize(); |
|
44 |
setLayout(new BorderLayout()); |
|
45 |
add(getTableContainer(), BorderLayout.CENTER); |
|
46 |
} |
|
48 | 47 |
|
49 |
Object[] row = { Color.GREEN, "texto 0", "texto 0", "texto 0", "125" }; |
|
50 |
Object[] row1 = { Color.BLUE, "texto 1", "texto 1", "texto 1", "255" }; |
|
51 |
Object[] row2 = { Color.RED, "texto 2", "texto 2", "texto 2", "80" }; |
|
48 |
/** |
|
49 |
* Borra todas las filas de la tabla. |
|
50 |
*/ |
|
51 |
public void clearTable() { |
|
52 | 52 |
try { |
53 |
table.addRow(row); |
|
54 |
|
|
55 |
table.addRow(row1); |
|
56 |
table.addRow(row2); |
|
53 |
getTableContainer().removeAllRows(); |
|
57 | 54 |
} catch (NotInitializeException e) { |
58 | 55 |
e.printStackTrace(); |
59 | 56 |
} |
57 |
} |
|
60 | 58 |
|
61 |
setLayout(new BorderLayout());
|
|
62 |
add(table, BorderLayout.CENTER);
|
|
59 |
private String getColorString(Color c) {
|
|
60 |
return c.getRed() + ", " + c.getGreen() + ", " + c.getBlue();
|
|
63 | 61 |
} |
62 |
|
|
63 |
/** |
|
64 |
* A?ade una fila a la tabla asignando el color por par?metro. Este |
|
65 |
* color asignado ser? el que aparezca en el bot?n y en el texto RGB |
|
66 |
* @param color |
|
67 |
*/ |
|
68 |
public void addRowToTable(Color color, String name, Double fromRange, Double toRange, String alpha){ |
|
69 |
try { |
|
70 |
getTableContainer().addRow(new Object[] { color, name, getColorString(color), fromRange, toRange, alpha }); |
|
71 |
} catch (NotInitializeException e1) { |
|
72 |
return; |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
public TableContainer getTableContainer() { |
|
77 |
if (tableContainer == null) { |
|
78 |
String[] columnNames = {PluginServices.getText(this, "selec"), PluginServices.getText(this, "clase"), "RGB", PluginServices.getText(this, "valor"), PluginServices.getText(this, "hasta"), PluginServices.getText(this, "alpha")}; |
|
79 |
int[] columnWidths = {50, 90, 94, 95, 95, 65}; |
|
80 |
tableContainer = new TableContainer(columnNames, columnWidths); |
|
81 |
tableContainer.setModel("TableColorModel"); |
|
82 |
tableContainer.initialize(); |
|
83 |
} |
|
84 |
return tableContainer; |
|
85 |
} |
|
64 | 86 |
} |
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/colortable/ui/ColorTablePanel.java | ||
---|---|---|
42 | 42 |
import org.gvsig.gui.beans.graphic.listview.ListViewComponent; |
43 | 43 |
import org.gvsig.gui.beans.graphic.listview.ListViewItem; |
44 | 44 |
import org.gvsig.gui.beans.imagenavigator.ImageNavigator; |
45 |
import org.gvsig.raster.datastruct.ColorItem; |
|
45 | 46 |
import org.gvsig.rastertools.colortable.ColorTableListener; |
46 | 47 |
import org.gvsig.rastertools.colortable.panels.ColorTInterpolated; |
47 | 48 |
import org.gvsig.rastertools.colortable.panels.ColorTTable; |
... | ... | |
263 | 264 |
} |
264 | 265 |
|
265 | 266 |
public void valueChanged(ListSelectionEvent e) { |
266 |
System.out.println(listViewComponent.getSelectedValue().getName()); |
|
267 |
// PalettePersistence.loadPalette(palettesPath, listViewComponent.getSelectedValue().getName()); |
|
267 |
// System.out.println(listViewComponent.getSelectedValue().getName()); |
|
268 |
ArrayList colorItems = ((ColorTableIconPainter) listViewComponent.getSelectedValue().getIcon()).getColorItems(); |
|
269 |
getColorTTable().clearTable(); |
|
270 |
for (int i=0; i<colorItems.size(); i++) { |
|
271 |
ColorItem c1 = (ColorItem) colorItems.get(i); |
|
272 |
Double toRange = null; |
|
273 |
if (i+1 < colorItems.size()) |
|
274 |
toRange = Double.valueOf(((ColorItem) colorItems.get(i + 1)).getValue()); |
|
275 |
getColorTTable().addRowToTable(c1.getColor(), c1.getNameClass(), Double.valueOf(c1.getValue()), toRange, c1.getColor().getAlpha() + ""); |
|
276 |
} |
|
268 | 277 |
} |
269 | 278 |
|
270 | 279 |
public void actionPerformed(ActionEvent e) { |
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/colortable/ui/ColorTableIconPainter.java | ||
---|---|---|
48 | 48 |
colorTable.setInterpolated(value); |
49 | 49 |
} |
50 | 50 |
|
51 |
public ArrayList getColorItems() { |
|
52 |
return colorItems; |
|
53 |
} |
|
54 |
|
|
51 | 55 |
public void paint(Graphics2D g, boolean isSelected) { |
52 | 56 |
Shape clip = g.getClip(); |
53 | 57 |
Rectangle area = clip.getBounds(); |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/table/models/TableColorModel.java | ||
---|---|---|
32 | 32 |
private static final long serialVersionUID = 5126848457976272945L; |
33 | 33 |
|
34 | 34 |
boolean[] canEdit = new boolean[] { true, true, false, true, false, true }; |
35 |
Class[] types = new Class[] { JButton.class, String.class, String.class, Double.class, Double.class, JButton.class }; |
|
35 | 36 |
|
36 | 37 |
public TableColorModel(String[] columnNames) { |
37 | 38 |
super(new Object[0][4], columnNames); |
38 | 39 |
} |
39 | 40 |
|
40 |
public Class getColumnClass(int c) { |
|
41 |
if ((c < 1) || (c == 5)) |
|
42 |
return JButton.class; |
|
43 |
|
|
44 |
return String.class; |
|
45 |
} |
|
46 |
|
|
41 |
/* |
|
42 |
* (non-Javadoc) |
|
43 |
* @see javax.swing.table.DefaultTableModel#removeRow(int) |
|
44 |
*/ |
|
45 |
/* |
|
47 | 46 |
public void removeRow(int row) { |
48 | 47 |
super.setValueAt(null, row, 0); |
49 | 48 |
super.setValueAt("", row, 1); |
... | ... | |
52 | 51 |
super.setValueAt("", row, 4); |
53 | 52 |
super.setValueAt(null, row, 5); |
54 | 53 |
super.removeRow(row); |
55 |
} |
|
54 |
}*/
|
|
56 | 55 |
|
56 |
/* |
|
57 |
* (non-Javadoc) |
|
58 |
* @see javax.swing.table.DefaultTableModel#setValueAt(java.lang.Object, int, int) |
|
59 |
*/ |
|
57 | 60 |
public void setValueAt(Object value, int row, int col) { |
58 | 61 |
super.setValueAt(value, row, col); |
59 | 62 |
} |
60 | 63 |
|
64 |
/* |
|
65 |
* (non-Javadoc) |
|
66 |
* @see org.gvsig.gui.beans.table.models.IModel#getNewLine() |
|
67 |
*/ |
|
61 | 68 |
public Object[] getNewLine() { |
62 |
return new Object[] { Color.WHITE, "", "", "", "", "255" };
|
|
69 |
return new Object[] {Color.WHITE, "", "", null, null, "255"};
|
|
63 | 70 |
} |
64 | 71 |
|
72 |
/* |
|
73 |
* (non-Javadoc) |
|
74 |
* @see javax.swing.table.DefaultTableModel#addRow(java.lang.Object[]) |
|
75 |
*/ |
|
65 | 76 |
public void addRow(Object[] list) { |
66 | 77 |
super.addRow(new Object[] { list[0], list[1], list[2], list[3], list[4], list[5] }); |
67 | 78 |
} |
68 | 79 |
|
80 |
/* |
|
81 |
* (non-Javadoc) |
|
82 |
* @see javax.swing.table.AbstractTableModel#getColumnClass(int) |
|
83 |
*/ |
|
84 |
public Class getColumnClass(int columnIndex) { |
|
85 |
return types [columnIndex]; |
|
86 |
} |
|
87 |
|
|
88 |
/* |
|
89 |
* (non-Javadoc) |
|
90 |
* @see javax.swing.table.DefaultTableModel#isCellEditable(int, int) |
|
91 |
*/ |
|
69 | 92 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
70 | 93 |
return canEdit [columnIndex]; |
71 | 94 |
} |
trunk/libraries/libRaster/src/org/gvsig/raster/RasterLibrary.java | ||
---|---|---|
55 | 55 |
* clases en las que se hace la divisi?n. |
56 | 56 |
*/ |
57 | 57 |
public static int defaultNumberOfClasses = 64; |
58 |
|
|
58 | 59 |
/** |
60 |
* En la genraci?n de las paletas de color, esta variable representa el n?mero |
|
61 |
* de colores en las que se hace la divisi?n para generar la paleta nueva. |
|
62 |
* Con esto conseguimos velocidad de procesamiento. Cuanto menor sea, peor |
|
63 |
* ser? la calidad representada de la imagen. |
|
64 |
*/ |
|
65 |
public static int defaultNumberOfColors = 256; |
|
66 |
/** |
|
59 | 67 |
* Tama?o de bloque en los procesos que recorren un raster completo a base de ventanas con recorrido |
60 | 68 |
* descendente. Esta variable indica la altura de dicho bloque. Por lo tanto cada bloque ser? de |
61 | 69 |
* raster.width X blockHeight. Tipicamente recorridos de este tipo se usan para el calculo de estad?sticas, |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/GridPalette.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package org.gvsig.raster.grid; |
20 | 20 |
|
21 |
import org.gvsig.raster.dataset.IBuffer; |
|
22 | 21 |
import org.gvsig.raster.datastruct.ColorTable; |
23 |
|
|
24 | 22 |
/** |
25 | 23 |
* Tabla de color asociada a un grid |
26 | 24 |
* |
... | ... | |
37 | 35 |
* @param fp |
38 | 36 |
*/ |
39 | 37 |
public GridPalette(ColorTable fp){ |
40 |
if(fp == null) |
|
38 |
if (fp == null)
|
|
41 | 39 |
return; |
42 |
this.type = fp.getType(); |
|
43 |
this.intRange = fp.getIntRange(); |
|
44 |
this.doubleRange = fp.getDoubleRange(); |
|
45 |
this.palette = fp.getColorTable(); |
|
40 |
this.range = fp.getRange(); |
|
41 |
this.transparencyRange = fp.getTransparencyRange(); |
|
46 | 42 |
this.paletteByBand = fp.getColorTableByBand(); |
47 | 43 |
this.nameClass = fp.getNameClass(); |
48 | 44 |
this.name = fp.getName(); |
49 |
if(type != IBuffer.TYPE_UNDEFINED)
|
|
50 |
paletteActive = true;
|
|
45 |
this.filePath = fp.getFilePath();
|
|
46 |
paletteActive = true; |
|
51 | 47 |
} |
52 | 48 |
|
53 | 49 |
/** |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/bands/ColorTableListManager.java | ||
---|---|---|
112 | 112 |
filters.remove(0); |
113 | 113 |
for(int prop = 0; prop < filters.size() ; prop++) { |
114 | 114 |
String elem = (String) filters.get(prop); |
115 |
if(elem.startsWith("filter.colortable.type")) { |
|
116 |
colorTable.setType(Integer.parseInt(RasterFilterListManager.getValue(elem))); |
|
117 |
filters.remove(prop); |
|
118 |
prop--; |
|
119 |
} |
|
120 | 115 |
|
121 | 116 |
if(elem.startsWith("filter.colortable.values")) { |
122 | 117 |
String[] listString = RasterFilterListManager.getValue(elem).split(" "); |
... | ... | |
127 | 122 |
filters.remove(prop); |
128 | 123 |
prop--; |
129 | 124 |
} |
125 |
/* |
|
126 |
if(elem.startsWith("filter.colortable.type")) { |
|
127 |
colorTable.setType(Integer.parseInt(RasterFilterListManager.getValue(elem))); |
|
128 |
filters.remove(prop); |
|
129 |
prop--; |
|
130 |
} |
|
130 | 131 |
|
131 | 132 |
if(elem.startsWith("filter.colortable.range")) { |
132 | 133 |
String[] listString = RasterFilterListManager.getValue(elem).split(" "); |
... | ... | |
145 | 146 |
filters.remove(prop); |
146 | 147 |
prop--; |
147 | 148 |
} |
149 |
*/ |
|
148 | 150 |
|
149 | 151 |
if(elem.startsWith("filter.colortable.names")) { |
150 | 152 |
String[] listString = RasterFilterListManager.getValue(elem).split(" "); |
... | ... | |
177 | 179 |
filterList.add("filter.colortable.active=true"); |
178 | 180 |
else |
179 | 181 |
filterList.add("filter.colortable.active=false"); |
182 |
/* |
|
180 | 183 |
filterList.add("filter.colortable.type=" + colorTable.getType()); |
181 | 184 |
|
182 | 185 |
String range = ""; |
... | ... | |
193 | 196 |
for(int i = 0; i < colorTable.getColorTable().length; i++) |
194 | 197 |
values += colorTable.getColorTable()[i] + " "; |
195 | 198 |
filterList.add("filter.colortable.values=" + values); |
199 |
*/ |
|
196 | 200 |
|
197 | 201 |
String names = ""; |
198 | 202 |
for(int i = 0; i < colorTable.getNameClass().length; i++) |
trunk/libraries/libRaster/src/org/gvsig/raster/datastruct/serializer/ColorTableRmfSerializer.java | ||
---|---|---|
32 | 32 |
/** |
33 | 33 |
* <P> |
34 | 34 |
* Clase para convertir a XML una tabla de color y obtener la tabla desde XML. |
35 |
* Esta clase implementa el interfaz IRmfBlock con los m?todos de escritura y
|
|
35 |
* Esta clase implementa el interfaz IRmfBlock con los m?todos de escritura y |
|
36 | 36 |
* lectura. Estos ser?n utilizados por el gestor de ficheros RMF para escribir y |
37 | 37 |
* leer datos. |
38 | 38 |
* </P> |
... | ... | |
53 | 53 |
* |
54 | 54 |
*/ |
55 | 55 |
public class ColorTableRmfSerializer extends ClassSerializer { |
56 |
|
|
56 |
|
|
57 | 57 |
//TAGS |
58 | 58 |
public static final String MAIN_TAG = "ColorTable"; |
59 | 59 |
public static final String TYPE = "Type"; |
... | ... | |
61 | 61 |
public static final String NAMES = "Names"; |
62 | 62 |
public static final String RANGE = "Range"; |
63 | 63 |
public static final String NAME = "PaletteName"; |
64 |
|
|
64 |
|
|
65 | 65 |
private ColorTable colorTable = null; |
66 | 66 |
|
67 | 67 |
/** |
... | ... | |
71 | 71 |
public ColorTableRmfSerializer(ColorTable colorTable) { |
72 | 72 |
this.colorTable = colorTable; |
73 | 73 |
} |
74 |
|
|
74 |
|
|
75 | 75 |
/** |
76 |
* Constructor.
|
|
76 |
* Constructor. |
|
77 | 77 |
*/ |
78 | 78 |
public ColorTableRmfSerializer() { |
79 | 79 |
} |
80 |
|
|
80 |
|
|
81 | 81 |
/* |
82 | 82 |
* (non-Javadoc) |
83 | 83 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#read(java.lang.String) |
... | ... | |
88 | 88 |
int[] rgb = null; |
89 | 89 |
double[] range = null; |
90 | 90 |
String[] names = null; |
91 |
|
|
91 |
|
|
92 | 92 |
KXmlParser parser = new KXmlParser(); |
93 | 93 |
Reader reader = new StringReader(xml); |
94 | 94 |
try { |
... | ... | |
98 | 98 |
} |
99 | 99 |
try { |
100 | 100 |
int tag = parser.nextTag(); |
101 |
|
|
102 |
if ( parser.getEventType() != KXmlParser.END_DOCUMENT ){
|
|
103 |
parser.require(KXmlParser.START_TAG, null, MAIN_TAG);
|
|
101 |
|
|
102 |
if ( parser.getEventType() != KXmlParser.END_DOCUMENT ){ |
|
103 |
parser.require(KXmlParser.START_TAG, null, MAIN_TAG); |
|
104 | 104 |
while(tag != KXmlParser.END_DOCUMENT) { |
105 | 105 |
switch(tag) { |
106 | 106 |
case KXmlParser.START_TAG: |
107 |
if(parser.getName() != null) {
|
|
107 |
if(parser.getName() != null) { |
|
108 | 108 |
if (parser.getName().compareTo(MAIN_TAG) == 0) { |
109 | 109 |
type = Integer.parseInt(parserString(parser, TYPE, null)); |
110 | 110 |
paletteName = parserString(parser, NAME, null); |
... | ... | |
124 | 124 |
rangeList = null; |
125 | 125 |
} |
126 | 126 |
} |
127 |
}
|
|
127 |
} |
|
128 | 128 |
break; |
129 |
case KXmlParser.END_TAG:
|
|
129 |
case KXmlParser.END_TAG: |
|
130 | 130 |
break; |
131 |
case KXmlParser.TEXT:
|
|
131 |
case KXmlParser.TEXT: |
|
132 | 132 |
break; |
133 | 133 |
} |
134 | 134 |
tag = parser.next(); |
135 | 135 |
} |
136 | 136 |
parser.require(KXmlParser.END_DOCUMENT, null, null); |
137 | 137 |
} |
138 |
|
|
138 |
|
|
139 | 139 |
} catch (XmlPullParserException e) { |
140 | 140 |
throw new ParsingException(xml); |
141 | 141 |
} catch (IOException e) { |
142 | 142 |
throw new ParsingException(xml); |
143 | 143 |
} |
144 |
|
|
144 |
|
|
145 | 145 |
colorTable = new ColorTable(paletteName); |
146 | 146 |
colorTable.setNameClass(names); |
147 | 147 |
colorTable.setColorTable(rgb); |
148 |
/* |
|
148 | 149 |
colorTable.setType(type); |
149 | 150 |
if(colorTable.getType() == IBuffer.TYPE_FLOAT || colorTable.getType() == IBuffer.TYPE_DOUBLE) |
150 | 151 |
colorTable.setDoubleRange(range); |
... | ... | |
154 | 155 |
r[i] = (int)range[i]; |
155 | 156 |
colorTable.setIntRange(r); |
156 | 157 |
} |
158 |
*/ |
|
157 | 159 |
} |
158 | 160 |
|
159 | 161 |
/* |
... | ... | |
161 | 163 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#write() |
162 | 164 |
*/ |
163 | 165 |
public String write() { |
166 |
|
|
164 | 167 |
StringBuffer b = new StringBuffer(); |
165 |
|
|
168 |
|
|
166 | 169 |
b.append("<" + MAIN_TAG + ">\n"); |
167 |
|
|
170 |
|
|
171 |
/* |
|
168 | 172 |
putProperty(b, TYPE, colorTable.getType(), 1); |
169 | 173 |
putProperty(b, NAME, colorTable.getName(), 1); |
170 |
|
|
174 |
|
|
171 | 175 |
b.append("\t<" + RGB + ">"); |
172 | 176 |
if(colorTable.getType() == IBuffer.TYPE_BYTE || colorTable.getType() == IBuffer.TYPE_SHORT || colorTable.getType() == IBuffer.TYPE_INT) { |
173 | 177 |
for (int rgb = 0; rgb < colorTable.getColorTable().length; rgb++) |
... | ... | |
178 | 182 |
b.append(colorTable.getColorTable()[rgb] + " "); |
179 | 183 |
} |
180 | 184 |
b.append("</" + RGB + ">\n"); |
181 |
|
|
185 |
|
|
182 | 186 |
b.append("\t<" + NAMES + ">"); |
183 | 187 |
for (int rgb = 0; rgb < colorTable.getNameClass().length; rgb++) |
184 | 188 |
b.append(colorTable.getNameClass()[rgb] + " "); |
185 | 189 |
b.append("</" + NAMES + ">\n"); |
186 |
|
|
190 |
|
|
187 | 191 |
b.append("\t<" + RANGE + ">"); |
188 | 192 |
if(colorTable.getType() == IBuffer.TYPE_BYTE || colorTable.getType() == IBuffer.TYPE_SHORT || colorTable.getType() == IBuffer.TYPE_INT) { |
189 | 193 |
for (int rgb = 0; rgb < colorTable.getIntRange().length; rgb++) |
... | ... | |
193 | 197 |
for (int rgb = 0; rgb < colorTable.getDoubleRange().length; rgb++) |
194 | 198 |
b.append(colorTable.getDoubleRange()[rgb] + " "); |
195 | 199 |
} |
200 |
*/ |
|
196 | 201 |
b.append("</" + RANGE + ">\n"); |
197 |
|
|
202 |
|
|
198 | 203 |
b.append("</" + MAIN_TAG + ">"); |
204 |
|
|
199 | 205 |
return b.toString(); |
200 | 206 |
} |
201 |
|
|
207 |
|
|
202 | 208 |
/* |
203 | 209 |
* (non-Javadoc) |
204 | 210 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#getResult() |
trunk/libraries/libRaster/src/org/gvsig/raster/datastruct/ColorItem.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
*/ |
|
19 |
package org.gvsig.raster.datastruct; |
|
20 |
|
|
21 |
import java.awt.Color; |
|
22 |
/** |
|
23 |
* Valor minimo para un item de una tabla de color. Este tendr? que pixel afecta, |
|
24 |
* nombre de esa clase, color y como estar? interpolado con el siguiente. |
|
25 |
* |
|
26 |
* @version 04/07/2007 |
|
27 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
28 |
*/ |
|
29 |
public class ColorItem { |
|
30 |
private double value = 0.0f; |
|
31 |
private String nameClass = null; |
|
32 |
private Color color = Color.black; |
|
33 |
private int interpolated = 50; |
|
34 |
|
|
35 |
/** |
|
36 |
* Devuelve el color |
|
37 |
* @return |
|
38 |
*/ |
|
39 |
public Color getColor() { |
|
40 |
return color; |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* Definir el color |
|
45 |
* @param color |
|
46 |
*/ |
|
47 |
public void setColor(Color color) { |
|
48 |
this.color = color; |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* Devuelve el valor de interpolaci?n con el siguiente color. |
|
53 |
* L?mites: 0..100 |
|
54 |
* @return |
|
55 |
*/ |
|
56 |
public int getInterpolated() { |
|
57 |
return interpolated; |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* Definir el valor de interpolaci?n. Si es mayor a 100 o menor a 0 se pone |
|
62 |
* entre los valores correctos. |
|
63 |
* @param interpolated |
|
64 |
*/ |
|
65 |
public void setInterpolated(int interpolated) { |
|
66 |
this.interpolated = interpolated; |
|
67 |
if (this.interpolated > 100) |
|
68 |
this.interpolated = 100; |
|
69 |
if (this.interpolated < 0) |
|
70 |
this.interpolated = 0; |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
74 |
* Obtener en que valor estar? dicho color |
|
75 |
* @return |
|
76 |
*/ |
|
77 |
public double getValue() { |
|
78 |
return value; |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Definir el valor del ColorItem. |
|
83 |
* @param value |
|
84 |
*/ |
|
85 |
public void setValue(double value) { |
|
86 |
this.value = value; |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Devuelve el nombre de la clase |
|
91 |
* @return |
|
92 |
*/ |
|
93 |
public String getNameClass() { |
|
94 |
return nameClass; |
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* Define el nombre de la clase |
|
99 |
* @param nameClass |
|
100 |
*/ |
|
101 |
public void setNameClass(String nameClass) { |
|
102 |
this.nameClass = nameClass; |
|
103 |
} |
|
104 |
} |
|
0 | 105 |
trunk/libraries/libRaster/src/org/gvsig/raster/datastruct/ColorTable.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package org.gvsig.raster.datastruct; |
20 | 20 |
|
21 |
import java.awt.Color; |
|
21 | 22 |
import java.util.ArrayList; |
22 | 23 |
|
23 |
import org.gvsig.raster.dataset.IBuffer;
|
|
24 |
import org.gvsig.raster.RasterLibrary;
|
|
24 | 25 |
|
25 | 26 |
import es.gva.cit.jgdal.GdalColorEntry; |
26 | 27 |
import es.gva.cit.jgdal.GdalColorTable; |
27 | 28 |
import es.gva.cit.jgdal.GdalException; |
28 | 29 |
/** |
29 | 30 |
* Paleta para raster. Esta consta de los valores RGB de la paleta que son |
30 |
* almacenados en un vector de enteros donde cada elemento entero contiene en su |
|
31 |
* interior el RGB completo y del vector de rangos. Dependiendo de si el tipo de |
|
32 |
* rango es entero o decimal este estar? almacenado en un vector de rangos |
|
33 |
* entero (intRange) o en un vector de rangos double (doubleRange). El tipo de |
|
34 |
* dato del rango quedar? almacenado en la variable type. |
|
31 |
* almacenados en un vector donde cada elemento contiene en su interior el RGB |
|
32 |
* completo y del vector de rangos. |
|
35 | 33 |
* |
34 |
* @version 04/07/2007 |
|
36 | 35 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
36 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
37 | 37 |
*/ |
38 | 38 |
public class ColorTable implements Cloneable { |
39 | 39 |
/** |
40 |
* Tipo de dato de la paleta |
|
41 |
* <UL> |
|
42 |
* <LI>TYPE_INT = Valido para byte, short e int</LI> |
|
43 |
* <LI>TYPE_DOUBLE = Valido para float y double</LI> |
|
44 |
* </UL> |
|
40 |
* Lista de ColorItem donde estaran todos los valores de la paleta segun |
|
41 |
* el interfaz |
|
45 | 42 |
*/ |
46 |
protected int type = IBuffer.TYPE_UNDEFINED; |
|
43 |
private ArrayList colorItems = null; |
|
44 |
|
|
47 | 45 |
/** |
48 |
* Lista de rangos para paletas enteras
|
|
46 |
* Booleano que define si se interpolaran los valores de la paleta.
|
|
49 | 47 |
*/ |
50 |
protected int[] intRange = null; |
|
48 |
protected boolean interpolated = true; |
|
49 |
|
|
51 | 50 |
/** |
52 | 51 |
* Lista de rangos para paletas decimales |
53 | 52 |
*/ |
54 |
protected double[] doubleRange = null; |
|
53 |
|
|
54 |
protected double[] range = null; |
|
55 | 55 |
/** |
56 | 56 |
* Lista de valores RGB |
57 | 57 |
*/ |
58 |
protected int[] palette = null; |
|
59 |
protected byte[][] paletteByBand = null; |
|
58 |
protected byte[][] paletteByBand = null; |
|
60 | 59 |
|
61 | 60 |
/** |
62 | 61 |
* Nombre de la clase asociada a la entrada |
63 | 62 |
*/ |
64 |
protected String[] nameClass = null; |
|
63 |
protected String[] nameClass = null; |
|
64 |
|
|
65 | 65 |
/** |
66 |
* Lista con todas las transparencias de la paleta |
|
67 |
*/ |
|
68 |
protected ArrayList transparencyRange = new ArrayList(); |
|
69 |
|
|
70 |
/** |
|
66 | 71 |
* Nombre de la paleta |
67 | 72 |
*/ |
68 |
protected String name = null; |
|
73 |
protected String name = null; |
|
74 |
|
|
69 | 75 |
/** |
70 |
* Ruta del fichero a la cual se asocia la paleta. Las bandas de un GeoRasterMultiFile
|
|
71 |
* han de saber a que paleta van asociadas. |
|
76 |
* Ruta del fichero a la cual se asocia la paleta. Las bandas de un |
|
77 |
* GeoRasterMultiFile han de saber a que paleta van asociadas.
|
|
72 | 78 |
*/ |
73 |
protected String filePath = null;
|
|
79 |
protected String filePath = null;
|
|
74 | 80 |
|
75 |
private ArrayList range = new ArrayList(); |
|
81 |
/** |
|
82 |
* Constructor vac?o. |
|
83 |
* @param name |
|
84 |
*/ |
|
85 |
public ColorTable() { |
|
86 |
this.name = ""; |
|
87 |
} |
|
76 | 88 |
|
77 |
public ColorTable() {} |
|
78 |
|
|
79 | 89 |
/** |
80 | 90 |
* Constructor. Asigna el nombre de la paleta. |
81 | 91 |
* @param name |
... | ... | |
100 | 110 |
return name; |
101 | 111 |
} |
102 | 112 |
|
103 |
/* |
|
104 |
* TODO: RENDIMIENTO: Incluir una heuristica que dado un valor se compare con el |
|
105 |
* valor de la mitad de la tabla y si es menor se empieza a recorrer desde el principio |
|
106 |
* sino se empieza a recorrer desde la mitad de la tabla hasta abajo. Esto hace |
|
107 |
* que se reduzca la tabla a la mitad de valores haciendo solo una comparaci?n. |
|
108 |
*/ |
|
109 |
/** |
|
110 |
* Obtiene el valor RGB para un clave entera pasada por par?metro |
|
111 |
* @param value clave de la cual se quiere obtener el valor RGB de la paleta |
|
112 |
* @return valor RGB |
|
113 |
*/ |
|
114 |
public int getRGB(int value) { |
|
115 |
int init = 1; |
|
116 |
for(int i = init; i <= intRange.length; i++) { |
|
117 |
if(i < intRange.length) { |
|
118 |
if(value > intRange[i]) |
|
119 |
return palette[i - 1]; |
|
120 |
}else{ |
|
121 |
return palette[i - 1]; |
|
113 |
public void createPaletteFromColorItems(ArrayList colorItems) { |
|
114 |
this.colorItems = colorItems; |
|
115 |
|
|
116 |
// Ordena la paleta |
|
117 |
sortPalette(); |
|
118 |
|
|
119 |
// System.out.println(name); |
|
120 |
// System.out.println("----- Sin comprimir (" + colorItems.size() + ") -----"); |
|
121 |
/* |
|
122 |
if (name.equals("MDT1")) { |
|
123 |
for (int i=0; i<colorItems.size(); i++) { |
|
124 |
ColorItem c1 = ((ColorItem) colorItems.get(i)); |
|
125 |
Color co = c1.getColor(); |
|
126 |
System.out.println(c1.getValue() + ": " + co.getRed() + "," + co.getGreen() + "," + co.getBlue() + "," + co.getAlpha()); |
|
122 | 127 |
} |
123 | 128 |
} |
124 |
return 0; |
|
125 |
} |
|
129 |
*/ |
|
130 |
// Mira que valores se pueden descartar y asi dejamos la paleta reducida |
|
131 |
// para poder hacer interpolaciones |
|
132 |
compressPalette(); |
|
126 | 133 |
|
127 |
/** |
|
128 |
* Obtiene el valor RGB para un clave entera pasada por par?metro |
|
129 |
* @param value clave de la cual se quiere obtener el valor RGB de la paleta |
|
130 |
* @return valor RGB |
|
131 |
*/ |
|
132 |
public byte[] getRGBByBand(int value) { |
|
133 |
int init = 1; |
|
134 |
for(int i = init; i <= intRange.length; i++) { |
|
135 |
if(i < intRange.length) { |
|
136 |
if(value > intRange[i]) |
|
137 |
return paletteByBand[i - 1]; |
|
138 |
}else{ |
|
139 |
return paletteByBand[i - 1]; |
|
134 |
// System.out.println("------ Comprimido (" + colorItems.size() + ") ------"); |
|
135 |
/* |
|
136 |
if (name.equals("MDT1")) { |
|
137 |
for (int i=0; i<colorItems.size(); i++) { |
|
138 |
ColorItem c1 = ((ColorItem) colorItems.get(i)); |
|
139 |
Color co = c1.getColor(); |
|
140 |
System.out.println(c1.getValue() + ": " + co.getRed() + "," + co.getGreen() + "," + co.getBlue() + "," + co.getAlpha()); |
|
140 | 141 |
} |
141 | 142 |
} |
142 |
return new byte[4]; |
|
143 |
*/ |
|
144 |
// Genera la paleta final para poder ser usada |
|
145 |
applyPalette(); |
|
143 | 146 |
} |
144 | 147 |
|
145 |
/** |
|
146 |
* Obtiene el valor RGB para un clave decimal pasada por par?metro |
|
147 |
* @param value clave de la cual se quiere obtener el valor RGB de la paleta |
|
148 |
* @return valor RGB |
|
149 |
*/ |
|
150 |
public int getRGB(double value) { |
|
151 |
int init = 1; |
|
152 |
for(int i = init; i <= doubleRange.length; i++) |
|
153 |
if(i < doubleRange.length) { |
|
154 |
if(value > doubleRange[i]) |
|
155 |
return palette[i - 1]; |
|
156 |
}else{ |
|
157 |
return palette[i - 1]; |
|
158 |
} |
|
159 |
return 0; |
|
148 |
int error = 8; |
|
149 |
private boolean isEqualColor(Color c1, Color c2) { |
|
150 |
if (c2.getRed() < (c1.getRed() - error)) return false; |
|
151 |
if (c2.getGreen() < (c1.getGreen() - error)) return false; |
|
152 |
if (c2.getBlue() < (c1.getBlue() - error)) return false; |
|
153 |
if (c2.getAlpha() < (c1.getAlpha() - error)) return false; |
|
154 |
|
|
155 |
if (c2.getRed() > (c1.getRed() + error)) return false; |
|
156 |
if (c2.getGreen() > (c1.getGreen() + error)) return false; |
|
157 |
if (c2.getBlue() > (c1.getBlue() + error)) return false; |
|
158 |
if (c2.getAlpha() > (c1.getAlpha() + error)) return false; |
|
159 |
|
|
160 |
return true; |
|
160 | 161 |
} |
161 | 162 |
|
162 |
/** |
|
163 |
* Obtiene el valor RGB para un clave entera pasada por par?metro |
|
164 |
* @param value clave de la cual se quiere obtener el valor RGB de la paleta |
|
165 |
* @return valor RGB |
|
166 |
*/ |
|
167 |
public byte[] getRGBByBand(double value) { |
|
168 |
int init = 1; |
|
169 |
for(int i = init; i <= doubleRange.length; i++) { |
|
170 |
if(i < doubleRange.length) { |
|
171 |
if(value > doubleRange[i]) |
|
172 |
return paletteByBand[i - 1]; |
|
173 |
}else{ |
|
174 |
return paletteByBand[i - 1]; |
|
163 |
private boolean isCorrectColor(ColorItem c1, ColorItem c2, ColorItem c3) { |
|
164 |
double max = c2.getValue()-c1.getValue(); |
|
165 |
int r = c1.getColor().getRed() + (int) (((c2.getColor().getRed() - c1.getColor().getRed()) * (c3.getValue() - c1.getValue())) / max); |
|
166 |
int g = c1.getColor().getGreen() + (int) (((c2.getColor().getGreen() - c1.getColor().getGreen()) * (c3.getValue() - c1.getValue())) / max); |
|
167 |
int b = c1.getColor().getBlue() + (int) (((c2.getColor().getBlue() - c1.getColor().getBlue()) * (c3.getValue() - c1.getValue())) / max); |
|
168 |
int a = c1.getColor().getAlpha() + (int) (((c2.getColor().getAlpha() - c1.getColor().getAlpha()) * (c3.getValue() - c1.getValue())) / max); |
|
169 |
Color aux = new Color(r & 0xff, g & 0xff, b & 0xff, a & 0xff); |
|
170 |
|
|
171 |
return isEqualColor(c3.getColor(), aux); |
|
172 |
} |
|
173 |
|
|
174 |
private boolean canDelete(int first, int last) { |
|
175 |
ColorItem c1 = (ColorItem) colorItems.get(first); |
|
176 |
ColorItem c2 = (ColorItem) colorItems.get(last); |
|
177 |
for (int i = (first + 1); i < last; i++) { |
|
178 |
if (!isCorrectColor(c1, c2, (ColorItem) colorItems.get(i))) |
|
179 |
return false; |
|
180 |
} |
|
181 |
return true; |
|
182 |
} |
|
183 |
|
|
184 |
private void compressPalette() { |
|
185 |
int init = 0; |
|
186 |
int posMax = 2; |
|
187 |
while (init < colorItems.size()) { |
|
188 |
if ((posMax < colorItems.size()) && canDelete(init, posMax)) { |
|
189 |
posMax++; |
|
190 |
continue; |
|
175 | 191 |
} |
192 |
if ((init + 2) < posMax) { |
|
193 |
if (canDelete(init, posMax - 1)) |
|
194 |
for (int i = (posMax - 2); i > init; i--) |
|
195 |
if (i < colorItems.size()) |
|
196 |
colorItems.remove(i); |
|
197 |
} |
|
198 |
init++; |
|
199 |
posMax = init + 2; |
|
176 | 200 |
} |
177 |
return new byte[4]; |
|
178 | 201 |
} |
179 | 202 |
|
180 | 203 |
/** |
181 |
* Crea una paleta a partir de un objeto GdalColorTable. Esto es necesario para los ficheros |
|
182 |
* que tienen un paleta asignada, como los gif, y que son tratados por Gdal. Se pasa la tabla |
|
183 |
* de color le?da desde gdal y se crea directamente un objeto Palette. |
|
204 |
* Crea una paleta a partir de un objeto GdalColorTable. Esto es necesario |
|
205 |
* para los ficheros que tienen una paleta asignada, como los gif, y que son |
|
206 |
* tratados por Gdal. Se pasa la tabla de color le?da desde gdal y se crea |
|
207 |
* directamente un objeto Palette. |
|
184 | 208 |
* @param table |
185 | 209 |
*/ |
186 | 210 |
public void createPaletteFromGdalColorTable(GdalColorTable table) { |
187 |
try{ |
|
188 |
type = IBuffer.TYPE_BYTE; |
|
189 |
nameClass = new String[table.getColorEntryCount()]; |
|
190 |
palette = new int[table.getColorEntryCount()]; |
|
191 |
paletteByBand = new byte[table.getColorEntryCount()][4]; |
|
192 |
intRange = new int[table.getColorEntryCount()]; |
|
211 |
try { |
|
212 |
colorItems = new ArrayList(); |
|
213 |
for (int iEntry = 0; iEntry < table.getColorEntryCount(); iEntry++) { |
|
214 |
GdalColorEntry entry = table.getColorEntryAsRGB(iEntry); |
|
193 | 215 |
|
194 |
int cont = table.getColorEntryCount() - 1; |
|
195 |
for(int iEntry = 0; iEntry < table.getColorEntryCount(); iEntry++) { |
|
196 |
GdalColorEntry entry = table.getColorEntryAsRGB(iEntry); |
|
197 |
nameClass[cont] = ""; |
|
198 |
palette[cont] = 0x00000000; |
|
199 |
palette[cont] |= ((entry.c4 & 0x000000ff) << 24); |
|
200 |
palette[cont] |= ((entry.c1 & 0x000000ff) << 16); |
|
201 |
palette[cont] |= ((entry.c2 & 0x000000ff) << 8); |
|
202 |
palette[cont] |= (entry.c3 & 0x000000ff); |
|
203 |
if(entry.c4 != 255) { |
|
204 |
TransparencyRange r = new TransparencyRange(); |
|
205 |
r.setRed(new int[]{entry.c1 & 0xffff, entry.c1 & 0xffff}); |
|
206 |
r.setGreen(new int[]{entry.c2 & 0xffff, entry.c2 & 0xffff}); |
|
207 |
r.setBlue(new int[]{entry.c3 & 0xffff, entry.c3 & 0xffff}); |
|
208 |
r.setAnd(true); |
|
209 |
r.loadStrEntryFromValues(); |
|
210 |
range.add(r); |
|
211 |
} |
|
212 |
paletteByBand[cont][0] = (byte)(entry.c1 & 0xffff); |
|
213 |
paletteByBand[cont][1] = (byte)(entry.c2 & 0xffff); |
|
214 |
paletteByBand[cont][2] = (byte)(entry.c3 & 0xffff); |
|
215 |
intRange[cont] = iEntry; |
|
216 |
cont --; |
|
217 |
} |
|
218 |
}catch(GdalException ex) { |
|
219 |
//No se crea la paleta |
|
216 |
ColorItem colorItem = new ColorItem(); |
|
217 |
colorItem.setNameClass(""); |
|
218 |
colorItem.setValue(iEntry); |
|
219 |
colorItem.setColor(new Color( (int) (entry.c1 & 0xff), |
|
220 |
(int) (entry.c2 & 0xff), |
|
221 |
(int) (entry.c3 & 0xff), |
|
222 |
(int) (entry.c4 & 0xff))); |
|
223 |
|
|
224 |
colorItems.add(colorItem); |
|
225 |
} |
|
226 |
} catch (GdalException ex) { |
|
227 |
// No se crea la paleta |
|
220 | 228 |
} |
229 |
sortPalette(); |
|
230 |
applyPalette(); |
|
221 | 231 |
} |
222 | 232 |
|
223 | 233 |
/** |
... | ... | |
225 | 235 |
* @return Lista de objetos TransparencyRange |
226 | 236 |
*/ |
227 | 237 |
public ArrayList getTransparencyRanges() { |
228 |
return range;
|
|
238 |
return transparencyRange;
|
|
229 | 239 |
} |
230 | 240 |
|
231 | 241 |
/** |
... | ... | |
248 | 258 |
* Obtiene la tabla de color |
249 | 259 |
* @return Paleta |
250 | 260 |
*/ |
261 |
/* |
|
251 | 262 |
public int[] getColorTable() { |
252 | 263 |
return palette; |
253 | 264 |
} |
265 |
*/ |
|
254 | 266 |
|
255 | 267 |
/** |
256 | 268 |
* Obtiene la tabla de color por banda |
... | ... | |
260 | 272 |
return paletteByBand; |
261 | 273 |
} |
262 | 274 |
|
275 |
|
|
263 | 276 |
/** |
264 | 277 |
* Asigna una paleta |
265 | 278 |
* @param palette Paleta |
266 | 279 |
*/ |
267 | 280 |
public void setColorTable(int[] palette) { |
268 |
this.palette = palette; |
|
269 | 281 |
paletteByBand = new byte[palette.length][3]; |
270 | 282 |
for (int i = 0; i < palette.length; i++) { |
271 | 283 |
paletteByBand[i][0] = (byte)((palette[i] & 0x00ff0000) >> 16); |
... | ... | |
275 | 287 |
} |
276 | 288 |
|
277 | 289 |
/** |
278 |
* Obtiene el tipo del rango de la paleta que corresponde con los tipos de rasterBuf |
|
279 |
* @return Tipo de rango, entero o double |
|
280 |
*/ |
|
281 |
public int getType() { |
|
282 |
return type; |
|
283 |
} |
|
284 |
|
|
285 |
/** |
|
286 |
* Asigna el tipo del rango de la paleta que corresponde con los tipos de rasterBuf |
|
287 |
* @param Tipo de rango, entero o double |
|
288 |
*/ |
|
289 |
public void setType(int type) { |
|
290 |
this.type = type; |
|
291 |
} |
|
292 |
|
|
293 |
/** |
|
294 |
* Asigna los rangos si el tipo es decimal |
|
295 |
* @param rangos |
|
296 |
*/ |
|
297 |
public void setDoubleRange(double[] value) { |
|
298 |
doubleRange = value; |
|
299 |
} |
|
300 |
|
|
301 |
/** |
|
302 |
* Asigna los rangos si el tipo es entero |
|
303 |
* @param values |
|
304 |
*/ |
|
305 |
public void setIntRange(int[] values) { |
|
306 |
intRange = values; |
|
307 |
} |
|
308 |
|
|
309 |
/** |
|
310 |
* Obtiene los rangos si el tipo es decimal |
|
311 |
* @return rangos |
|
312 |
*/ |
|
313 |
public double[] getDoubleRange() { |
|
314 |
return doubleRange; |
|
315 |
} |
|
316 |
|
|
317 |
/** |
|
318 |
* Obtiene los rangos si el tipo es entero |
|
319 |
* @return rangos |
|
320 |
*/ |
|
321 |
public int[] getIntRange() { |
|
322 |
return intRange; |
|
323 |
} |
|
324 |
|
|
325 |
|
|
326 |
/** |
|
327 | 290 |
* Obtiene los nombres de las clases de la paleta |
328 | 291 |
* @return Array de cadenas. Cada una corresponde con un nombre de clase |
329 | 292 |
* que corresponde a cada rango de tipos. |
... | ... | |
364 | 327 |
* @return ArrayList |
365 | 328 |
*/ |
366 | 329 |
public ArrayList getTransparencyRange() { |
367 |
return range;
|
|
330 |
return transparencyRange;
|
|
368 | 331 |
} |
369 | 332 |
|
370 | 333 |
/* |
... | ... | |
378 | 341 |
} catch (CloneNotSupportedException e) { |
379 | 342 |
} |
380 | 343 |
|
381 |
if (doubleRange != null) |
|
382 |
clone.doubleRange = (double[]) doubleRange.clone(); |
|
383 |
|
|
384 | 344 |
if (filePath != null) |
385 | 345 |
clone.filePath = new String(filePath); |
386 | 346 |
|
387 |
if (intRange != null) |
|
388 |
clone.intRange = (int[]) intRange.clone(); |
|
389 |
|
|
390 | 347 |
if (name != null) |
391 | 348 |
clone.name = new String(name); |
392 | 349 |
|
... | ... | |
396 | 353 |
clone.nameClass[i] = new String(nameClass[i]); |
397 | 354 |
} |
398 | 355 |
|
399 |
if (palette != null) |
|
400 |
clone.palette = (int[]) palette.clone(); |
|
401 |
|
|
402 | 356 |
if (paletteByBand != null) { |
403 | 357 |
clone.paletteByBand = (byte[][]) paletteByBand.clone(); |
404 | 358 |
for (int i = 0; i < paletteByBand.length; i++) |
405 | 359 |
clone.paletteByBand[i] = (byte[]) paletteByBand[i].clone(); |
406 | 360 |
} |
407 | 361 |
|
408 |
if (range != null) { |
|
409 |
clone.range = new ArrayList(); |
|
410 |
for (int i = 0; i < range.size(); i++) |
|
411 |
clone.range.add(((TransparencyRange) range.get(i)).clone()); |
|
362 |
return clone; |
|
363 |
} |
|
364 |
|
|
365 |
/** |
|
366 |
* Devuelve un color de interpolacion entre dos colores |
|
367 |
* @param value |
|
368 |
* @param pos |
|
369 |
* @return |
|
370 |
*/ |
|
371 |
private Color interpolatedColor(double value, int pos) { |
|
372 |
if ((pos + 1) == colorItems.size()) |
|
373 |
return ((ColorItem) colorItems.get(pos)).getColor(); |
|
374 |
|
|
375 |
ColorItem item1 = (ColorItem) colorItems.get(pos); |
|
376 |
ColorItem item2 = (ColorItem) colorItems.get(pos + 1); |
|
377 |
|
|
378 |
double percValue = ((value - item1.getValue()) * 100) / (item2.getValue() - item1.getValue()); |
|
379 |
|
|
380 |
Color halfColor = new Color( |
|
381 |
(item2.getColor().getRed() + item1.getColor().getRed()) >> 1, |
|
382 |
(item2.getColor().getGreen() + item1.getColor().getGreen()) >> 1, |
|
383 |
(item2.getColor().getBlue() + item1.getColor().getBlue()) >> 1, |
|
384 |
(item2.getColor().getAlpha() + item1.getColor().getAlpha()) >> 1); |
|
385 |
|
|
386 |
Color color1, color2; |
|
387 |
int perc1, perc2; |
|
388 |
|
|
389 |
if (percValue > item1.getInterpolated()) { |
|
390 |
color1 = halfColor; |
|
391 |
color2 = item2.getColor(); |
|
392 |
perc1 = item1.getInterpolated(); |
|
393 |
perc2 = 100; |
|
394 |
} else { |
|
395 |
color1 = item1.getColor(); |
|
396 |
color2 = halfColor; |
|
397 |
perc1 = 0; |
|
398 |
perc2 = item1.getInterpolated(); |
|
412 | 399 |
} |
413 | 400 |
|
414 |
return clone; |
|
401 |
double percNew = (percValue - perc1) / (perc2 - perc1); |
|
402 |
|
|
403 |
Color newColor = new Color( |
|
404 |
(int) (color1.getRed() + ((color2.getRed() - color1.getRed()) * percNew)) & 0xff, |
|
405 |
(int) (color1.getGreen() + ((color2.getGreen() - color1.getGreen()) * percNew)) & 0xff, |
|
406 |
(int) (color1.getBlue() + ((color2.getBlue() - color1.getBlue()) * percNew)) & 0xff, |
|
407 |
(int) (color1.getAlpha() + ((color2.getAlpha() - color1.getAlpha()) * percNew)) & 0xff); |
|
408 |
|
|
409 |
|
|
410 |
return newColor; |
|
415 | 411 |
} |
412 |
|
|
413 |
/* |
|
414 |
* TODO: RENDIMIENTO: Incluir una heuristica que dado un valor se compare con el |
|
415 |
* valor de la mitad de la tabla y si es menor se empieza a recorrer desde el principio |
|
416 |
* sino se empieza a recorrer desde la mitad de la tabla hasta abajo. Esto hace |
|
417 |
* que se reduzca la tabla a la mitad de valores haciendo solo una comparaci?n. |
|
418 |
*/ |
|
419 |
/** |
|
420 |
* Obtiene el valor RGB para un clave entera pasada por par?metro |
|
421 |
* @param value clave de la cual se quiere obtener el valor RGB de la paleta |
|
422 |
* @return valor RGB |
|
423 |
*/ |
|
424 |
public byte[] getRGBByBand(double value) { |
|
425 |
int init = 1; |
|
426 |
for (int i = init; i <= range.length; i++) { |
|
427 |
if (i < range.length) { |
|
428 |
if (value < range[i]) |
|
429 |
return paletteByBand[i - 1]; |
|
430 |
} else { |
|
431 |
return paletteByBand[i - 1]; |
|
432 |
} |
|
433 |
} |
|
434 |
return new byte[4]; |
|
435 |
} |
|
436 |
|
|
437 |
/** |
|
438 |
* Ordena el ColorItems de manera ascendente. De momento se usa el m?todo de |
|
439 |
* ordenaci?n por burbuja. |
|
440 |
*/ |
|
441 |
// TODO: Usar el m?todo Quicksort para ordenar |
|
442 |
private void sortPalette() { |
|
443 |
for (int i = 0; i < colorItems.size(); i++) { |
|
444 |
for (int j = i + 1; j < colorItems.size(); j++) { |
|
445 |
if (((ColorItem) colorItems.get(j)).getValue() < ((ColorItem) colorItems.get(i)).getValue()) { |
|
446 |
Object aux = colorItems.get(i); |
|
447 |
colorItems.set(i, colorItems.get(j)); |
|
448 |
colorItems.set(j, aux); |
|
449 |
} |
|
450 |
} |
|
451 |
} |
|
452 |
} |
|
453 |
|
|
454 |
/** |
|
455 |
* Genera una paleta intermedia para acelerar los calculos. |
|
456 |
*/ |
|
457 |
private void applyPalette() { |
|
458 |
ArrayList arrayColors = new ArrayList(); |
|
459 |
|
|
460 |
paletteByBand = new byte[0][3]; |
|
461 |
range = new double[0]; |
|
462 |
nameClass = new String[0]; |
|
463 |
|
|
464 |
if (colorItems.size()==0) |
|
465 |
return; |
|
466 |
|
|
467 |
// Nos preparamos para hacer las particiones, sabiendo el minimo y maximo |
|
468 |
double min = ((ColorItem) colorItems.get(0)).getValue(); |
|
469 |
double max = ((ColorItem) colorItems.get(colorItems.size() - 1)).getValue(); |
|
470 |
|
|
471 |
if (min > max) { |
|
472 |
double aux = max; |
|
473 |
max = min; |
|
474 |
min = aux; |
|
475 |
} |
|
476 |
|
|
477 |
Color color = Color.white; |
|
478 |
Color colorOld = null; |
|
479 |
|
|
480 |
// Hacemos las particiones, metiendo cada item calculado en un array |
|
481 |
int defaultColors = RasterLibrary.defaultNumberOfColors; |
|
482 |
for (int i = 0; i < defaultColors; i++) { |
|
483 |
double value = min + ((i * (max - min)) / (defaultColors - 1)); |
|
484 |
|
|
485 |
int pos = 0; |
|
486 |
for (int j = 1; j <= colorItems.size(); j++) { |
|
487 |
if (j < colorItems.size()) { |
|
488 |
if (value < ((ColorItem) colorItems.get(j)).getValue()) { |
|
489 |
pos = j - 1; |
|
490 |
break; |
|
491 |
} |
|
492 |
} else { |
|
493 |
pos = j - 1; |
|
494 |
break; |
|
495 |
} |
|
496 |
} |
|
497 |
|
|
498 |
// Calculamos el color que corresponde, tanto interpolado como no |
|
499 |
if (interpolated) |
|
500 |
color = interpolatedColor(value, pos); |
|
501 |
else |
|
502 |
color = ((ColorItem) colorItems.get(pos)).getColor(); |
|
503 |
|
|
504 |
if (!color.equals(colorOld)) { |
|
505 |
ColorItem colorItem = new ColorItem(); |
|
506 |
colorItem.setNameClass(""); |
|
507 |
colorItem.setValue(value); |
|
508 |
colorItem.setColor(color); |
|
509 |
arrayColors.add(colorItem); |
|
510 |
} |
|
511 |
|
|
512 |
colorOld = color; |
|
513 |
} |
|
514 |
|
|
515 |
// Una vez tenemos una paleta de 256 colores o inferior, rellenamos |
|
516 |
// los siguientes valores para hacer busquedas rapidas. |
|
517 |
|
|
518 |
paletteByBand = new byte[arrayColors.size()][3]; |
|
519 |
range = new double[arrayColors.size()]; |
|
520 |
nameClass = new String[arrayColors.size()]; |
|
521 |
|
|
522 |
transparencyRange.clear(); |
|
523 |
for (int i = 0; i < arrayColors.size(); i++) { |
|
524 |
paletteByBand[i][0] = (byte) ((ColorItem) arrayColors.get(i)).getColor().getRed(); |
|
525 |
paletteByBand[i][1] = (byte) ((ColorItem) arrayColors.get(i)).getColor().getGreen(); |
|
526 |
paletteByBand[i][2] = (byte) ((ColorItem) arrayColors.get(i)).getColor().getBlue(); |
|
527 |
range[i] = ((ColorItem) arrayColors.get(i)).getValue(); |
|
528 |
nameClass[i] = ((ColorItem) arrayColors.get(i)).getNameClass(); |
|
529 |
if (((ColorItem) arrayColors.get(i)).getColor().getAlpha() != 255) { |
|
530 |
TransparencyRange r = new TransparencyRange(); |
|
531 |
r.setRed(new int[] { ((ColorItem) arrayColors.get(i)).getColor().getRed(), ((ColorItem) arrayColors.get(i)).getColor().getRed() }); |
|
532 |
r.setGreen(new int[] { ((ColorItem) arrayColors.get(i)).getColor().getGreen(), ((ColorItem) arrayColors.get(i)).getColor().getGreen() }); |
|
533 |
r.setBlue(new int[] { ((ColorItem) arrayColors.get(i)).getColor().getBlue(), ((ColorItem) arrayColors.get(i)).getColor().getBlue() }); |
|
534 |
r.setAlpha(((ColorItem) arrayColors.get(i)).getColor().getAlpha()); |
|
535 |
r.setAnd(true); |
|
536 |
r.loadStrEntryFromValues(); |
|
537 |
transparencyRange.add(r); |
|
538 |
} |
|
539 |
} |
|
540 |
} |
|
541 |
|
|
542 |
public double[] getRange() { |
|
543 |
return range; |
|
544 |
} |
|
545 |
|
|
546 |
public void setRange(double[] range) { |
|
547 |
this.range = range; |
|
548 |
} |
|
549 |
|
|
550 |
public ArrayList getColorItems() { |
|
551 |
return colorItems; |
|
552 |
} |
|
553 |
|
|
554 |
public boolean isInterpolated() { |
|
555 |
return interpolated; |
|
556 |
} |
|
557 |
|
|
558 |
public void setInterpolated(boolean interpolated) { |
|
559 |
this.interpolated = interpolated; |
|
560 |
applyPalette(); |
|
561 |
} |
|
416 | 562 |
} |
trunk/libraries/libRaster/src-test/org/gvsig/raster/dataset/io/rmf/TestRmfRead.java | ||
---|---|---|
43 | 43 |
* Test de lectura para ficheros rmf. |
44 | 44 |
* Obtiene distintos tipos de bloques y comprueba que el objeto que han |
45 | 45 |
* de generar es correcto. |
46 |
*
|
|
46 |
* |
|
47 | 47 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
48 | 48 |
* |
49 | 49 |
*/ |
50 | 50 |
public class TestRmfRead extends TestCase { |
51 |
|
|
51 |
|
|
52 | 52 |
private String baseDir = "./test-images/"; |
53 | 53 |
private RasterDataset testDataset = null; |
54 | 54 |
private RmfBlocksManager manager = null; |
... | ... | |
56 | 56 |
public String file = "readtest.rmf"; |
57 | 57 |
private RasterDataset f1 = null; |
58 | 58 |
private String path1 = baseDir + "03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg"; |
59 |
|
|
59 |
|
|
60 | 60 |
static { |
61 | 61 |
RasterLibrary.wakeUp(); |
62 | 62 |
} |
63 |
|
|
63 |
|
|
64 | 64 |
public void start() { |
65 | 65 |
this.setUp(); |
66 | 66 |
this.testStack(); |
67 | 67 |
} |
68 |
|
|
68 |
|
|
69 | 69 |
public void setUp() { |
70 | 70 |
System.err.println("TestRmfRead running..."); |
71 | 71 |
try { |
... | ... | |
76 | 76 |
e1.printStackTrace(); |
77 | 77 |
} |
78 | 78 |
} |
79 |
|
|
79 |
|
|
80 | 80 |
public void testStack(){ |
81 | 81 |
manager = new RmfBlocksManager(baseDir + file); |
82 | 82 |
if(!manager.checkRmf()) |
... | ... | |
89 | 89 |
manager.addClient(ser1); |
90 | 90 |
manager.addClient(ser2); |
91 | 91 |
manager.addClient(ser3); |
92 |
|
|
92 |
|
|
93 | 93 |
try { |
94 | 94 |
manager.read(null); |
95 | 95 |
for (int i = 0; i < manager.getClientsCount(); i++) { |
96 | 96 |
IRmfBlock client = manager.getClient(i); |
97 | 97 |
if(client instanceof HistogramRmfSerializer) |
98 |
testHistogram((Histogram)manager.getClient(i).getResult());
|
|
98 |
testHistogram((Histogram)manager.getClient(i).getResult()); |
|
99 | 99 |
if(client instanceof ColorTableRmfSerializer) |
100 | 100 |
testColorTable((ColorTable)manager.getClient(i).getResult()); |
101 | 101 |
if(client instanceof StatisticsRmfSerializer) |
... | ... | |
103 | 103 |
if(client instanceof GeoInfoRmfSerializer) |
104 | 104 |
testGeoInfo((RasterDataset)manager.getClient(i).getResult()); |
105 | 105 |
} |
106 |
|
|
106 |
|
|
107 | 107 |
} catch (ParsingException e) { |
108 | 108 |
e.printStackTrace(); |
109 | 109 |
} |
110 |
|
|
110 |
|
|
111 | 111 |
} |
112 |
|
|
112 |
|
|
113 | 113 |
public void testHistogram(Histogram h) { |
114 | 114 |
HistogramClass[][] classes = h.getHistogram(); |
115 | 115 |
for (int iBand = 0; iBand < classes.length; iBand++) { |
... | ... | |
117 | 117 |
assertEquals((int)classes[iBand][iValue].getMin(), iValue); |
118 | 118 |
assertEquals((int)classes[iBand][iValue].getMax(), iValue + 1); |
119 | 119 |
} |
120 |
}
|
|
121 |
|
|
120 |
} |
|
121 |
|
|
122 | 122 |
assertEquals((int)classes[0][0].getValue(), 16); |
123 | 123 |
assertEquals((int)classes[0][1].getValue(), 4); |
124 | 124 |
assertEquals((int)classes[0][23].getValue(), 6); |
125 | 125 |
assertEquals((int)classes[0][48].getValue(), 4); |
126 |
|
|
126 |
|
|
127 | 127 |
assertEquals((int)classes[1][0].getValue(), 2); |
128 | 128 |
assertEquals((int)classes[1][4].getValue(), 1); |
129 | 129 |
assertEquals((int)classes[1][7].getValue(), 8); |
130 | 130 |
assertEquals((int)classes[1][20].getValue(), 4); |
131 |
|
|
131 |
|
|
132 | 132 |
assertEquals((int)classes[2][0].getValue(), 25); |
133 | 133 |
assertEquals((int)classes[2][2].getValue(), 1); |
134 | 134 |
assertEquals((int)classes[2][13].getValue(), 4); |
135 | 135 |
assertEquals((int)classes[2][21].getValue(), 2); |
136 | 136 |
} |
137 |
|
|
137 |
|
|
138 | 138 |
public void testColorTable(ColorTable ct) { |
139 |
/* |
|
139 | 140 |
int[] range = ct.getIntRange(); |
140 | 141 |
byte[][] color = ct.getColorTableByBand(); |
141 |
|
|
142 |
|
|
142 | 143 |
assertEquals(ct.getType(), 0); |
143 | 144 |
assertEquals(ct.getName(), "Prueba Tabla de Color"); |
144 | 145 |
for (int i = 0; i < color.length; i++) { |
145 | 146 |
assertEquals(range[i], (31 - i)); |
146 | 147 |
switch(i) { |
147 |
case 15:
|
|
148 |
case 15: |
|
148 | 149 |
assertEquals(color[i][0], -65); |
149 | 150 |
assertEquals(color[i][1], -65); |
150 | 151 |
assertEquals(color[i][2], -65); |
151 | 152 |
break; |
152 |
case 22:
|
|
153 |
case 22: |
|
153 | 154 |
assertEquals(color[i][0], -65); |
154 | 155 |
assertEquals(color[i][1], -14); |
155 | 156 |
assertEquals(color[i][2], -1); |
156 | 157 |
break; |
157 |
case 24:
|
|
158 |
case 24: |
|
158 | 159 |
assertEquals(color[i][0], 0); |
159 | 160 |
assertEquals(color[i][1], -52); |
160 | 161 |
assertEquals(color[i][2], -1); |
161 | 162 |
break; |
162 |
case 28:
|
|
163 |
case 28: |
|
163 | 164 |
assertEquals(color[i][0], 0); |
164 | 165 |
assertEquals(color[i][1], -103); |
165 | 166 |
assertEquals(color[i][2], -1); |
166 | 167 |
break; |
167 | 168 |
} |
168 | 169 |
} |
169 |
|
|
170 |
*/ |
|
171 |
|
|
170 | 172 |
//System.out.println(ct.getName()); |
171 | 173 |
//System.out.println(ct.getType()); |
172 |
|
|
174 |
|
|
173 | 175 |
/*for (int i = 0; i < color.length; i++) { |
174 | 176 |
System.out.print(range[i] + ": "); |
175 | 177 |
System.out.println(color[i][0] + " " + color[i][1] + " " + color[i][2]); |
... | ... | |
184 | 186 |
double[] secondMin = ds.getSecondMin(); |
185 | 187 |
double[] mean = ds.getMean(); |
186 | 188 |
double[] variance = ds.getVariance(); |
187 |
|
|
189 |
|
|
188 | 190 |
assertEquals(bandCount, 3); |
189 | 191 |
for (int i = 0; i < bandCount; i++) { |
190 | 192 |
switch(i) { |
191 |
case 0:
|
|
193 |
case 0: |
|
192 | 194 |
assertEquals((int)max[i], 250); |
193 | 195 |
assertEquals((int)min[i], 0); |
194 | 196 |
assertEquals((int)secondMax[i], 248); |
... | ... | |
196 | 198 |
assertEquals((int)mean[i], 95); |
197 | 199 |
assertEquals((int)variance[i], 3050); |
198 | 200 |
break; |
199 |
case 1:
|
|
201 |
case 1: |
|
200 | 202 |
assertEquals((int)max[i], 255); |
201 | 203 |
assertEquals((int)min[i], 0); |
202 | 204 |
assertEquals((int)secondMax[i], 254); |
... | ... | |
204 | 206 |
assertEquals((int)mean[i], 105); |
205 | 207 |
assertEquals((int)variance[i], 2689); |
206 | 208 |
break; |
207 |
case 2:
|
|
209 |
case 2: |
|
208 | 210 |
assertEquals((int)max[i], 254); |
209 | 211 |
assertEquals((int)min[i], 0); |
210 | 212 |
assertEquals((int)secondMax[i], 250); |
... | ... | |
214 | 216 |
break; |
215 | 217 |
} |
216 | 218 |
} |
217 |
|
|
219 |
|
|
218 | 220 |
//System.out.println(ct.getName()); |
219 | 221 |
//System.out.println(ct.getType()); |
220 |
|
|
222 |
|
|
221 | 223 |
/*for (int i = 0; i < color.length; i++) { |
222 | 224 |
System.out.print(range[i] + ": "); |
223 | 225 |
System.out.println(color[i][0] + " " + color[i][1] + " " + color[i][2]); |
224 | 226 |
}*/ |
225 | 227 |
} |
226 |
|
|
228 |
|
|
227 | 229 |
public void testGeoInfo(RasterDataset dataset) { |
228 | 230 |
String proj = ""; |
229 | 231 |
//TODO: TEST: Terminar test de acceso a la georreferenciaci?n. |
... | ... | |
231 | 233 |
proj = dataset.getProjection().getAbrev(); |
232 | 234 |
double x = dataset.getExtent().getMin().getX(); |
233 | 235 |
double y = dataset.getExtent().getMax().getY(); |
234 |
|
|
236 |
|
|
235 | 237 |
assertEquals((int)x, 5000); |
236 | 238 |
assertEquals((int)y, 5000); |
237 | 239 |
} |
Also available in: Unified diff