gvsig-raster / org.gvsig.raster.georeferencing / trunk / org.gvsig.raster.georeferencing / org.gvsig.raster.georeferencing.swing / org.gvsig.raster.georeferencing.swing.impl / src / main / java / org / gvsig / raster / georeferencing / swing / impl / view / synchronize / GCPSynchronizationImpl.java @ 1712
History | View | Annotate | Download (15.8 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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.georeferencing.swing.impl.view.synchronize; |
20 |
|
21 |
import java.awt.geom.Point2D; |
22 |
import java.util.List; |
23 |
|
24 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
25 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPoint; |
26 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPointList; |
27 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
28 |
import org.gvsig.raster.georeferencing.swing.impl.layer.GCPsGraphicLayer; |
29 |
import org.gvsig.raster.georeferencing.swing.impl.layer.GPGraphic; |
30 |
import org.gvsig.raster.georeferencing.swing.impl.tool.PanTool; |
31 |
import org.gvsig.raster.georeferencing.swing.impl.tool.SelectPointTool; |
32 |
import org.gvsig.raster.georeferencing.swing.impl.tool.ZoomRectangleTool; |
33 |
import org.gvsig.raster.georeferencing.swing.impl.view.ViewPanelImpl; |
34 |
import org.gvsig.raster.georeferencing.swing.impl.view.ZoomPanelImpl; |
35 |
import org.gvsig.raster.georeferencing.swing.view.GeoreferencingView; |
36 |
import org.gvsig.raster.georeferencing.swing.view.IGraphicLayer; |
37 |
import org.gvsig.raster.georeferencing.swing.view.ToolListener; |
38 |
import org.gvsig.raster.swing.pagedtable.PagedTable; |
39 |
|
40 |
/**
|
41 |
* Clase para realizar operaciones y mantener la sincronizaci?n entre las
|
42 |
* capas de puntos de las dos vistas y las dos ventanas de zoom.
|
43 |
*
|
44 |
* 04/02/2008
|
45 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
46 |
*/
|
47 |
public class GCPSynchronizationImpl { |
48 |
private ToolListener toolListener = null; |
49 |
//Vistas
|
50 |
private ViewPanelImpl viewRaster = null; |
51 |
private ViewPanelImpl viewMap = null; |
52 |
private ZoomPanelImpl zoomMap = null; |
53 |
private ZoomPanelImpl zoomRaster = null; |
54 |
|
55 |
//Capas de puntos
|
56 |
private GCPsGraphicLayer viewRasterGCPs = null; |
57 |
private GCPsGraphicLayer viewMapGCPs = null; |
58 |
private GCPsGraphicLayer viewRasterGCPsZoom = null; |
59 |
private GCPsGraphicLayer viewMapGCPsZoom = null; |
60 |
|
61 |
//Herramientas de selecci?n
|
62 |
private SelectPointTool viewRasterSelectPointTool = null; |
63 |
private SelectPointTool viewMapSelectPointTool = null; |
64 |
private SelectPointTool zoomRasterSelectPointTool = null; |
65 |
private SelectPointTool zoomMapSelectPointTool = null; |
66 |
private PagedTable table = null; |
67 |
private GeoPointList geoPointList = null; |
68 |
|
69 |
public GCPSynchronizationImpl(GeoPointList gpList, ToolListener listener) {
|
70 |
this.toolListener = listener;
|
71 |
this.geoPointList = gpList;
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* Asigna las vistas
|
76 |
* @param vRaster
|
77 |
* @param vMap
|
78 |
* @param zRaster
|
79 |
* @param zMap
|
80 |
*/
|
81 |
public void setViews( |
82 |
GeoreferencingView vRaster, |
83 |
GeoreferencingView vMap, |
84 |
GeoreferencingView zRaster, |
85 |
GeoreferencingView zMap, |
86 |
PagedTable table) { |
87 |
this.table = table;
|
88 |
viewRaster = (ViewPanelImpl)vRaster; |
89 |
viewMap = (ViewPanelImpl)vMap; |
90 |
zoomMap = (ZoomPanelImpl)zMap; |
91 |
zoomRaster = (ZoomPanelImpl)zRaster; |
92 |
if(zoomRaster != null) |
93 |
zoomRasterSelectPointTool = new SelectPointTool(zoomRaster.getCanvas(), toolListener);
|
94 |
if(zoomMap != null) |
95 |
zoomMapSelectPointTool = new SelectPointTool(zoomMap.getCanvas(), toolListener);
|
96 |
if(viewRaster != null) |
97 |
viewRasterSelectPointTool = new SelectPointTool(viewRaster.getCanvas(), toolListener);
|
98 |
if(viewMap != null) |
99 |
viewMapSelectPointTool = new SelectPointTool(viewMap.getCanvas(), toolListener);
|
100 |
createGCPLayers(); |
101 |
registerPointToolListener(); |
102 |
} |
103 |
|
104 |
/**
|
105 |
* Asigna las capas de puntos
|
106 |
* @param vRaster
|
107 |
* @param vMap
|
108 |
* @param zRaster
|
109 |
* @param zMap
|
110 |
*/
|
111 |
public void setLayerPoints( |
112 |
IGraphicLayer vRaster, |
113 |
IGraphicLayer vMap, |
114 |
IGraphicLayer zRaster, |
115 |
IGraphicLayer zMap) { |
116 |
viewRasterGCPs = (GCPsGraphicLayer)vRaster; |
117 |
viewMapGCPs = (GCPsGraphicLayer)vMap; |
118 |
viewRasterGCPsZoom = (GCPsGraphicLayer)zRaster; |
119 |
viewMapGCPsZoom = (GCPsGraphicLayer)zMap; |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Activa o desactiva la capa de puntos
|
124 |
* @param active
|
125 |
*/
|
126 |
public void setActiveLayerZoomCursor(boolean active) { |
127 |
if(viewRaster != null && viewRaster.getZoomCursorGraphicLayer() != null) |
128 |
viewRaster.getZoomCursorGraphicLayer().setActive(active); |
129 |
if(viewMap != null && viewMap.getZoomCursorGraphicLayer() != null) |
130 |
viewMap.getZoomCursorGraphicLayer().setActive(active); |
131 |
} |
132 |
|
133 |
/**
|
134 |
* Recalcula las coordenadas de dibujado de los puntos de control
|
135 |
* y redibuja estos en todas las vistas
|
136 |
*/
|
137 |
public void redrawPoints() { |
138 |
if(viewMapGCPs != null) |
139 |
viewMapGCPs.recalcMapDrawCoordinates(); |
140 |
if(viewRasterGCPs != null) |
141 |
viewRasterGCPs.recalcPixelDrawCoordinates(); |
142 |
if(viewMapGCPsZoom != null) |
143 |
viewMapGCPsZoom.recalcMapDrawCoordinates(); |
144 |
if(viewRasterGCPsZoom != null) |
145 |
viewRasterGCPsZoom.recalcPixelDrawCoordinates(); |
146 |
repaint(); |
147 |
} |
148 |
|
149 |
/**
|
150 |
* Redibuja el canvas de todas las vistas
|
151 |
*/
|
152 |
private void repaint() { |
153 |
if(viewRaster != null) |
154 |
viewRaster.getCanvas().repaint(); |
155 |
if(viewMap != null) |
156 |
viewMap.getCanvas().repaint(); |
157 |
if(zoomMap != null) |
158 |
zoomMap.getCanvas().repaint(); |
159 |
if(zoomRaster != null) |
160 |
zoomRaster.getCanvas().repaint(); |
161 |
} |
162 |
|
163 |
/**
|
164 |
* Registra el listener para la herramienta de selecci?n de puntos de control
|
165 |
*/
|
166 |
public void registerPointToolListener() { |
167 |
if(zoomMap != null) { |
168 |
zoomMapSelectPointTool.setActive(false);
|
169 |
zoomMap.getControl().addTool(zoomMapSelectPointTool); |
170 |
zoomMap.getControl().registerToolListener(ZoomRectangleTool.class, toolListener); |
171 |
zoomMap.getControl().registerToolListener(PanTool.class, toolListener); |
172 |
} |
173 |
if(zoomRaster != null) { |
174 |
zoomRasterSelectPointTool.setActive(false);
|
175 |
zoomRaster.getControl().addTool(zoomRasterSelectPointTool); |
176 |
zoomRaster.getControl().registerToolListener(ZoomRectangleTool.class, toolListener); |
177 |
zoomRaster.getControl().registerToolListener(PanTool.class, toolListener); |
178 |
} |
179 |
if(viewRaster != null) { |
180 |
viewRasterSelectPointTool.setActive(false);
|
181 |
viewRaster.getControl().addTool(viewRasterSelectPointTool); |
182 |
viewRaster.getControl().registerToolListener(ZoomRectangleTool.class, toolListener); |
183 |
viewRaster.getControl().registerToolListener(PanTool.class, toolListener); |
184 |
} |
185 |
if(viewMap != null) { |
186 |
viewMapSelectPointTool.setActive(false);
|
187 |
viewMap.getControl().addTool(viewMapSelectPointTool); |
188 |
viewMap.getControl().registerToolListener(ZoomRectangleTool.class, toolListener); |
189 |
viewMap.getControl().registerToolListener(PanTool.class, toolListener); |
190 |
} |
191 |
} |
192 |
|
193 |
/**
|
194 |
* A?ade un punto a las capas gr?ficas
|
195 |
* @param map Coordenadas del mapa del punto
|
196 |
* @param raster Coordenadas pixel del punto
|
197 |
* @return identificador del punto a?adido
|
198 |
*/
|
199 |
public long addPoint(Point2D map, Point2D raster) { |
200 |
GeoPoint gp = RasterLocator.getManager().getDataStructFactory().createGeoPoint(raster, map); |
201 |
long id = System.currentTimeMillis(); |
202 |
System.out.println(id);
|
203 |
//Esperamos al menos 5 ms para que la carga de los puntos no sea
|
204 |
//tan r?pida que coincida el id de dos puntos
|
205 |
try {
|
206 |
Thread.sleep(80); |
207 |
} catch (InterruptedException e) { |
208 |
} |
209 |
if(viewRasterGCPs != null) |
210 |
viewRasterGCPs.addPixelGeoPoint(gp, id); |
211 |
if(viewMapGCPs != null) |
212 |
viewMapGCPs.addMapGeoPoint(gp, id); |
213 |
if(viewRasterGCPsZoom != null) |
214 |
viewRasterGCPsZoom.addPixelGeoPoint(gp, id); |
215 |
if(viewMapGCPsZoom != null) |
216 |
viewMapGCPsZoom.addMapGeoPoint(gp, id); |
217 |
return id;
|
218 |
} |
219 |
|
220 |
/**
|
221 |
* Elimina todos los puntos gr?ficos de las capas
|
222 |
*
|
223 |
*/
|
224 |
public void removeAllPoints() { |
225 |
if(viewRasterGCPs != null) |
226 |
viewRasterGCPs.removeAllPoints(); |
227 |
if(viewMapGCPs != null) |
228 |
viewMapGCPs.removeAllPoints(); |
229 |
if(viewRasterGCPsZoom != null) |
230 |
viewRasterGCPsZoom.removeAllPoints(); |
231 |
if(viewMapGCPsZoom != null) |
232 |
viewMapGCPsZoom.removeAllPoints(); |
233 |
} |
234 |
|
235 |
/**
|
236 |
* Asigna las coordenadas del mundo real y raster al punto indicado en el par?metro.
|
237 |
* @param point Punto a asignar las nuevas coordenadas
|
238 |
* @param xMap Coordenada real en X
|
239 |
* @param yMap Coordenada real en Y
|
240 |
* @param xRaster Coordenada pixel en X
|
241 |
* @param yRaster Coordenada pixel en Y
|
242 |
*/
|
243 |
public void setCoordinates(int point, double xMap, double yMap, double xRaster, double yRaster) { |
244 |
setXMapCoordinate(point, xMap); |
245 |
setYMapCoordinate(point, yMap); |
246 |
setXRasterCoordinate(point, xRaster); |
247 |
setYRasterCoordinate(point, yRaster); |
248 |
redrawPoints(); |
249 |
} |
250 |
|
251 |
/**
|
252 |
* Asigna la coordenada del mundo real X
|
253 |
* @param point
|
254 |
* @param xMap
|
255 |
*/
|
256 |
public void setXMapCoordinate(int point, double xMap) { |
257 |
double oldMapY = viewRasterGCPs.getPoint(point).getGeoPoint().getMapPoint().getY();
|
258 |
viewRasterGCPs.getPoint(point).getGeoPoint().getMapPoint().setLocation(xMap, oldMapY); |
259 |
} |
260 |
|
261 |
/**
|
262 |
* Asigna la coordenada del mundo real Y
|
263 |
* @param point
|
264 |
* @param yMap
|
265 |
*/
|
266 |
public void setYMapCoordinate(int point, double yMap) { |
267 |
double oldMapX = viewRasterGCPs.getPoint(point).getGeoPoint().getMapPoint().getX();
|
268 |
viewRasterGCPs.getPoint(point).getGeoPoint().getMapPoint().setLocation(oldMapX, yMap); |
269 |
} |
270 |
|
271 |
/**
|
272 |
* Asigna la coordenada raster X
|
273 |
* @param point
|
274 |
* @param xRaster
|
275 |
*/
|
276 |
public void setXRasterCoordinate(int point, double xRaster) { |
277 |
double oldRasterY = viewRasterGCPs.getPoint(point).getGeoPoint().getPixelPoint().getY();
|
278 |
viewRasterGCPs.getPoint(point).getGeoPoint().getPixelPoint().setLocation(xRaster, oldRasterY); |
279 |
} |
280 |
|
281 |
/**
|
282 |
* Asigna la coordenada raster Y
|
283 |
* @param point
|
284 |
* @param xRaster
|
285 |
*/
|
286 |
public void setYRasterCoordinate(int point, double yRaster) { |
287 |
double oldRasterX = viewRasterGCPs.getPoint(point).getGeoPoint().getPixelPoint().getX();
|
288 |
viewRasterGCPs.getPoint(point).getGeoPoint().getPixelPoint().setLocation(oldRasterX, yRaster); |
289 |
} |
290 |
|
291 |
/**
|
292 |
* Elimina un punto de la lista a partir de su posici?n
|
293 |
* @param position
|
294 |
*/
|
295 |
public void removePoint(int position) { |
296 |
if(viewRasterGCPs != null) |
297 |
viewRasterGCPs.removePixelGeoPoint(position); |
298 |
if(viewMapGCPs != null) |
299 |
viewMapGCPs.removePixelGeoPoint(position); |
300 |
if(viewRasterGCPsZoom != null) |
301 |
viewRasterGCPsZoom.removePixelGeoPoint(position); |
302 |
if(viewMapGCPsZoom != null) |
303 |
viewMapGCPsZoom.removePixelGeoPoint(position); |
304 |
} |
305 |
|
306 |
/**
|
307 |
* Informa de si la tool de selecci?n de puntos est? activa o no
|
308 |
* @return true si est? activa y false si no lo est?
|
309 |
*/
|
310 |
public boolean isSelectPointToolSelected() { |
311 |
if(viewRaster != null) |
312 |
if(viewRaster.getControl().getToolSelected() instanceof SelectPointTool) |
313 |
return true; |
314 |
return false; |
315 |
} |
316 |
|
317 |
/**
|
318 |
* Obtiene la lista de puntos
|
319 |
* @return ArrayList
|
320 |
*/
|
321 |
public List<GPGraphic> getPointList() { |
322 |
if(viewRasterGCPs != null) |
323 |
return viewRasterGCPs.getPointList();
|
324 |
return null; |
325 |
} |
326 |
|
327 |
/**
|
328 |
* Obtiene un array con la lista de puntos
|
329 |
* @return
|
330 |
*/
|
331 |
public List<GeoPoint> getGeoPoints() { |
332 |
List<GPGraphic> pointList = getPointList();
|
333 |
for (int i = 0; i < pointList.size(); i++) |
334 |
geoPointList.add(((GPGraphic) pointList.get(i)).getGeoPoint()); |
335 |
return geoPointList;
|
336 |
} |
337 |
|
338 |
/**
|
339 |
* Activa o desactiva la visualizaci?n de un punto.
|
340 |
* @param active true para activarlo y false para desactivarlo
|
341 |
* @param position Posici?n del punto
|
342 |
*/
|
343 |
public void setVisiblePoint(boolean visible, int position) { |
344 |
if(viewRasterGCPs != null) |
345 |
((GPGraphic)viewRasterGCPs.getPointList().get(position)).setDraw(visible); |
346 |
if(viewMapGCPs != null) |
347 |
((GPGraphic)viewMapGCPs.getPointList().get(position)).setDraw(visible); |
348 |
if(viewRasterGCPsZoom != null) |
349 |
((GPGraphic)viewRasterGCPsZoom.getPointList().get(position)).setDraw(visible); |
350 |
if(viewMapGCPsZoom != null) |
351 |
((GPGraphic)viewMapGCPsZoom.getPointList().get(position)).setDraw(visible); |
352 |
} |
353 |
|
354 |
/**
|
355 |
* Asigna la numeraci?n a los puntos de control. Tanto a la tabla como
|
356 |
* a los GeoPuntos
|
357 |
* @throws NotInitializeException
|
358 |
*/
|
359 |
public void calcPointsNumeration() throws NotInitializeException { |
360 |
List<GPGraphic> pointList = getPointList();
|
361 |
|
362 |
for (int i = 0; i < table.getRowCount(); i++) { |
363 |
table.setValueAt(new Integer(i), i, 1); |
364 |
long id = (long)((Long)table.getValueAt(i, table.getColumnCount() - 1)).longValue(); |
365 |
|
366 |
if(i < pointList.size()) {
|
367 |
for (int j = 0; j < pointList.size(); j++) { |
368 |
GPGraphic gpg = ((GPGraphic)pointList.get(j)); |
369 |
if(id == gpg.getId()) {
|
370 |
((GPGraphic)pointList.get(j)).getGeoPoint().setNumber(i); |
371 |
break;
|
372 |
} |
373 |
} |
374 |
} |
375 |
} |
376 |
redrawPoints(); |
377 |
} |
378 |
|
379 |
public void createGCPLayers() { |
380 |
if(viewRaster != null) { |
381 |
viewRasterGCPs = new GCPsGraphicLayer(GPGraphic.PIXEL, toolListener);
|
382 |
viewRasterGCPs.setCanvas(viewRaster.getCanvas()); |
383 |
viewRaster.addGraphicLayer(viewRasterGCPs); |
384 |
//viewRasterRequestManager.setGCPsGraphicLayer(viewRasterGCPs);
|
385 |
} |
386 |
|
387 |
if(zoomRaster != null) { |
388 |
viewRasterGCPsZoom = new GCPsGraphicLayer(GPGraphic.PIXEL, toolListener);
|
389 |
viewRasterGCPsZoom.setCanvas(zoomRaster.getCanvas()); |
390 |
zoomRaster.addGraphicLayer(viewRasterGCPsZoom); |
391 |
//zoomRasterRequestManager.setGCPsGraphicLayer(viewRasterGCPsZoom);
|
392 |
} |
393 |
|
394 |
if(viewMap != null) { |
395 |
viewMapGCPs = new GCPsGraphicLayer(GPGraphic.MAP, toolListener);
|
396 |
viewMapGCPs.setCanvas(viewMap.getCanvas()); |
397 |
viewMap.addGraphicLayer(viewMapGCPs); |
398 |
//viewMapRequestManager.setGCPsGraphicLayer(viewMapGCPs);
|
399 |
} |
400 |
|
401 |
if(zoomMap != null) { |
402 |
viewMapGCPsZoom = new GCPsGraphicLayer(GPGraphic.MAP, toolListener);
|
403 |
viewMapGCPsZoom.setCanvas(zoomMap.getCanvas()); |
404 |
zoomMap.addGraphicLayer(viewMapGCPsZoom); |
405 |
//zoomMapRequestManager.setGCPsGraphicLayer(viewMapGCPsZoom);
|
406 |
} |
407 |
} |
408 |
|
409 |
/**
|
410 |
* Activa y desactiva los n?meros de punto de las capas gr?ficas
|
411 |
* @param active
|
412 |
*/
|
413 |
public void setActiveNumberPoint(boolean active) { |
414 |
if(viewMapGCPs != null) |
415 |
viewMapGCPs.setShowNumber(active); |
416 |
if(viewRasterGCPs != null) |
417 |
viewRasterGCPs.setShowNumber(active); |
418 |
if(viewMapGCPsZoom != null) |
419 |
viewMapGCPsZoom.setShowNumber(active); |
420 |
if(viewRasterGCPsZoom != null) |
421 |
viewRasterGCPsZoom.setShowNumber(active); |
422 |
} |
423 |
|
424 |
/**
|
425 |
* Activa o desactiva la capa de puntos
|
426 |
* @param active
|
427 |
*/
|
428 |
public void setActiveLayerPoints(boolean active) { |
429 |
if(viewRasterGCPs != null) |
430 |
viewRasterGCPs.setActive(active); |
431 |
if(viewMapGCPs != null) |
432 |
viewMapGCPs.setActive(active); |
433 |
if(viewRasterGCPsZoom != null) |
434 |
viewRasterGCPsZoom.setActive(active); |
435 |
if(viewMapGCPsZoom != null) |
436 |
viewMapGCPsZoom.setActive(active); |
437 |
} |
438 |
|
439 |
/**
|
440 |
* Obtiene un punto (GeoPoint) a partir de su n?mero. Hay que tener en cuenta que el n?mero de
|
441 |
* punto puede no coincidir con su posici?n en el array.
|
442 |
* @return GeoPoint
|
443 |
*/
|
444 |
public GeoPoint getPointByNumber(int number) { |
445 |
List<GPGraphic> pointList = getPointList();
|
446 |
for (int i = 0; i < pointList.size(); i++) { |
447 |
GeoPoint p = ((GPGraphic)pointList.get(i)).getGeoPoint(); |
448 |
if(p.getNumber() == number)
|
449 |
return p;
|
450 |
} |
451 |
return null; |
452 |
} |
453 |
|
454 |
/**
|
455 |
* Obtiene la posici?n de un punto a partir de su n?mero. Hay que tener en cuenta que el n?mero de
|
456 |
* punto puede no coincidir con su posici?n en el array.
|
457 |
* @return entero con la posici?n o -1 si no existe
|
458 |
*/
|
459 |
public int getPointPositionByNumber(int number) { |
460 |
List<GPGraphic> pointList = getPointList();
|
461 |
for (int i = 0; i < pointList.size(); i++) { |
462 |
GeoPoint p = ((GPGraphic)pointList.get(i)).getGeoPoint(); |
463 |
if(p.getNumber() == number)
|
464 |
return i;
|
465 |
} |
466 |
return -1; |
467 |
} |
468 |
} |