gvsig-raster / org.gvsig.raster.georeferencing / trunk / org.gvsig.raster.georeferencing / org.gvsig.raster.georeferencing.app / org.gvsig.raster.georeferencing.app.georeferencingclient / src / main / java / org / gvsig / raster / georeferencing / app / georeferencingclient / TableWrapper.java @ 1717
History | View | Annotate | Download (7.48 KB)
1 |
package org.gvsig.raster.georeferencing.app.georeferencingclient; |
---|---|
2 |
|
3 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPoint; |
4 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPointList; |
5 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
6 |
import org.gvsig.i18n.Messages; |
7 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.gui.CheckBoxColumnEditor; |
8 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.gui.CheckBoxColumnRenderer; |
9 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.gui.ColorColumnRenderer; |
10 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.gui.GCPModel; |
11 |
import org.gvsig.raster.georeferencing.lib.impl.GeoTransformDataResult; |
12 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingOptionsDataModel; |
13 |
import org.gvsig.raster.georeferencing.swing.control.GeorefControlPanel; |
14 |
import org.gvsig.raster.georeferencing.swing.impl.GeoreferencingSwingImplLibrary; |
15 |
import org.gvsig.raster.swing.RasterSwingLocator; |
16 |
import org.gvsig.raster.swing.RasterSwingManager; |
17 |
import org.gvsig.raster.swing.impl.pagedtable.NotInitializeException; |
18 |
import org.gvsig.raster.swing.pagedtable.ModelLoader; |
19 |
import org.gvsig.raster.swing.pagedtable.PagedTable; |
20 |
import org.gvsig.raster.tools.algorithm.base.RasterBaseAlgorithmLibrary; |
21 |
import org.gvsig.raster.tools.algorithm.base.process.ProcessException; |
22 |
import org.gvsig.raster.tools.algorithm.base.process.RasterProcess; |
23 |
import org.gvsig.raster.tools.app.basic.RasterToolsUtil; |
24 |
|
25 |
/**
|
26 |
* API for the table to manage ground control points. This table
|
27 |
* has a specific structure.
|
28 |
*
|
29 |
* @author Nacho Brodin nachobrodin@gmail.com
|
30 |
*/
|
31 |
public class TableWrapper { |
32 |
private PagedTable table = null; |
33 |
private RasterProcess process = null; |
34 |
private GeoPointList gpList = null; |
35 |
private GeoreferencingOptionsDataModel dataModel = null; |
36 |
private GeorefControlPanel controlPanel = null; |
37 |
|
38 |
public TableWrapper(
|
39 |
GeoPointList gpList, |
40 |
GeoreferencingOptionsDataModel dataModel, |
41 |
GeorefControlPanel controlPanel) { |
42 |
this.gpList = gpList;
|
43 |
this.dataModel = dataModel;
|
44 |
this.controlPanel = controlPanel;
|
45 |
try {
|
46 |
process = RasterBaseAlgorithmLibrary.getManager().createRasterTask("GeoreferencingProcess");
|
47 |
} catch (ProcessException e) {
|
48 |
GeoreferencingSwingImplLibrary.messageBoxError("process_not_registered", null, e); |
49 |
} |
50 |
} |
51 |
|
52 |
public PagedTable getTable() {
|
53 |
if(table == null) { |
54 |
RasterSwingManager manager = RasterSwingLocator.getSwingManager(); |
55 |
String[] columnNames = { |
56 |
"-",
|
57 |
Messages.getText("num"),
|
58 |
Messages.getText("worldx"),
|
59 |
Messages.getText("worldy"),
|
60 |
Messages.getText("imagex"),
|
61 |
Messages.getText("imagey"),
|
62 |
"Error X", "Error Y", "RMS", ""}; |
63 |
int[] columnSizes = {40, 37, -1, -1, -1, -1, -1, -1, -1, 0}; |
64 |
|
65 |
GCPModel model = new GCPModel(columnNames);
|
66 |
ModelLoader loader = manager.createModelLoader(model); |
67 |
CheckBoxColumnRenderer render = new CheckBoxColumnRenderer(null); |
68 |
CheckBoxColumnEditor editor = new CheckBoxColumnEditor();
|
69 |
loader.setRenderForColumn(0, render);
|
70 |
loader.setCellEditorForColumn(0, editor);
|
71 |
loader.setColumnNames(columnNames); |
72 |
loader.setColumnWidths(columnSizes); |
73 |
|
74 |
table = manager.createPagedTable(loader); |
75 |
} |
76 |
return table;
|
77 |
} |
78 |
|
79 |
/**
|
80 |
* Inicializa una fila de la tabla con los valores a 0, el n?mero de punto
|
81 |
* y el identificador. Esto es util para la inserci?n de un nuevo punto antes
|
82 |
* de introducir sus coordenadas.
|
83 |
* @param row Fila a inicializar
|
84 |
* @param id Identificador
|
85 |
*/
|
86 |
public void initializeRow(int row, long id) { |
87 |
getTable().setValueAt(new Integer(row), row, 1); |
88 |
for (int i = 2; i <= 9; i++) |
89 |
getTable().setValueAt(new Double(0), row, i); |
90 |
getTable().setValueAt(new Long(id), row, getTable().getColumnCount() - 1); |
91 |
} |
92 |
|
93 |
/**
|
94 |
* Actualiza los errores de toda la tabla. Esta funci?n debe ser llamada cuando ha
|
95 |
* habido alg?n cambio en los valores de los puntos.
|
96 |
* @throws NotInitializeException
|
97 |
*/
|
98 |
public void updateErrors() { |
99 |
process.addParam("gpcs", gpList);
|
100 |
int degree = 1; |
101 |
if(dataModel.getAlgorithm() == Georeferencing.POLYNOMIAL)
|
102 |
degree = dataModel.getDegree(); |
103 |
process.addParam("orden", new Integer(degree)); |
104 |
try {
|
105 |
process.execute(); |
106 |
} catch (ProcessException e) {
|
107 |
return;
|
108 |
} catch(RuntimeException e) { |
109 |
//Matriz singular
|
110 |
return;
|
111 |
} catch (ProcessInterruptedException e) {
|
112 |
} |
113 |
GeoTransformDataResult result = (GeoTransformDataResult)process.getResult(); |
114 |
if(result == null) |
115 |
return;
|
116 |
|
117 |
//Actualizamos los errores de toda la tabla
|
118 |
ColorColumnRenderer cr = new ColorColumnRenderer();
|
119 |
for (int i = 0; i < gpList.size(); i++) { |
120 |
GeoPoint point = gpList.get(i); |
121 |
getTable().setValueAt(new Double(point.getErrorX()), point.getNumber(), 6); |
122 |
getTable().setValueAt(new Double(point.getErrorY()), point.getNumber(), 7); |
123 |
getTable().setValueAt(new Double(point.getRms()), point.getNumber(), 8); |
124 |
if (point.getRms() > dataModel.getThreshold())
|
125 |
cr.addRowToColor1(point.getNumber()); |
126 |
else
|
127 |
cr.addRowToColor2(point.getNumber()); |
128 |
} |
129 |
getTable().getJTable().getColumnModel().getColumn(8).setCellRenderer(cr);
|
130 |
controlPanel.getError().setValue(result.getRmsTotal() + "");
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* Obtiene las coordenadas de una fila
|
135 |
* @param row Fila de la que se quieren obtener las coordenadas
|
136 |
* @return Array con 4 valores coordenadas real X, coordenada real Y, coordenadas raster X y coordenada raste Y
|
137 |
*/
|
138 |
public double[] getCoordinates(int row) { |
139 |
double xMap = 0, yMap = 0, xRaster = 0, yRaster = 0; |
140 |
boolean numberFormatException = false; |
141 |
|
142 |
Object value = getTable().getValueAt(row, 2); |
143 |
try {
|
144 |
if(value instanceof Double) |
145 |
xMap = ((Double)value).doubleValue();
|
146 |
else if(value instanceof String) |
147 |
xMap = Double.valueOf(((String)value)).doubleValue(); |
148 |
} catch (NumberFormatException ex1) { |
149 |
numberFormatException = true;
|
150 |
} |
151 |
|
152 |
value = getTable().getValueAt(row, 3);
|
153 |
try {
|
154 |
if(value instanceof Double) |
155 |
yMap = ((Double)value).doubleValue();
|
156 |
else if(value instanceof String) |
157 |
yMap = Double.valueOf(((String)value)).doubleValue(); |
158 |
} catch (NumberFormatException ex1) { |
159 |
numberFormatException = true;
|
160 |
} |
161 |
|
162 |
try {
|
163 |
value = getTable().getValueAt(row, 4);
|
164 |
if(value instanceof Double) |
165 |
xRaster = ((Double)value).doubleValue();
|
166 |
else if(value instanceof String) |
167 |
xRaster = Double.valueOf(((String)value)).doubleValue(); |
168 |
} catch (NumberFormatException ex1) { |
169 |
numberFormatException = true;
|
170 |
} |
171 |
|
172 |
try {
|
173 |
value = getTable().getValueAt(row, 5);
|
174 |
if(value instanceof Double) |
175 |
yRaster = ((Double)value).doubleValue();
|
176 |
else if(value instanceof String) |
177 |
yRaster = Double.valueOf(((String)value)).doubleValue(); |
178 |
} catch (NumberFormatException ex1) { |
179 |
numberFormatException = true;
|
180 |
} |
181 |
|
182 |
//Esto es necesario porque aunque se produzca una excepci?n en la lectura
|
183 |
//de un valor deben leerse los dem?s campos antes de terminar.
|
184 |
if(numberFormatException) {
|
185 |
RasterToolsUtil.messageBoxError("value_not_valid", table);
|
186 |
getTable().setValueAt(new String(xMap + ""), row, 2); |
187 |
getTable().setValueAt(new String(yMap + ""), row, 3); |
188 |
getTable().setValueAt(new String(xRaster + ""), row, 4); |
189 |
getTable().setValueAt(new String(yRaster + ""), row, 5); |
190 |
|
191 |
} |
192 |
|
193 |
return new double[]{xMap, yMap, xRaster, yRaster}; |
194 |
} |
195 |
|
196 |
/**
|
197 |
* Obtiene el resultado de aplicar el algoritmo de transformaci?n
|
198 |
* @return
|
199 |
*/
|
200 |
public GeoTransformDataResult getGeoTransformDataResult() {
|
201 |
if(process != null) |
202 |
return (GeoTransformDataResult)process.getResult();
|
203 |
return null; |
204 |
} |
205 |
} |