svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / georeferencing / Georeferencing.java @ 18264
History | View | Annotate | Download (10.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.rastertools.georeferencing; |
20 |
|
21 |
import java.awt.geom.Point2D; |
22 |
import java.awt.geom.Rectangle2D; |
23 |
import java.awt.image.BufferedImage; |
24 |
import java.util.ArrayList; |
25 |
|
26 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
27 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
28 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
29 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
30 |
import org.gvsig.raster.util.RasterToolsUtil; |
31 |
import org.gvsig.rastertools.georeferencing.ui.launcher.GeorefLauncherDialog; |
32 |
import org.gvsig.rastertools.georeferencing.ui.table.GCPTablePanel; |
33 |
import org.gvsig.rastertools.georeferencing.ui.zoom.InvalidRequestException; |
34 |
import org.gvsig.rastertools.georeferencing.ui.zoom.ViewRasterRequestManager; |
35 |
import org.gvsig.rastertools.georeferencing.ui.zoom.layers.ZoomCursorGraphicLayer; |
36 |
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.ToolEvent; |
37 |
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.ToolListener; |
38 |
import org.gvsig.rastertools.georeferencing.view.ViewDialog; |
39 |
import org.gvsig.rastertools.georeferencing.view.ZoomMapDialog; |
40 |
import org.gvsig.rastertools.georeferencing.view.ZoomRasterDialog; |
41 |
|
42 |
import com.iver.andami.PluginServices; |
43 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
44 |
import com.iver.andami.ui.mdiManager.IWindow; |
45 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
46 |
import com.iver.cit.gvsig.ProjectExtension; |
47 |
import com.iver.cit.gvsig.fmap.ViewPort; |
48 |
import com.iver.cit.gvsig.project.Project; |
49 |
import com.iver.cit.gvsig.project.documents.view.ProjectView; |
50 |
import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory; |
51 |
import com.iver.cit.gvsig.project.documents.view.gui.IView; |
52 |
|
53 |
/**
|
54 |
* Clase principal para la georreferenciaci?n. Se encarga de la inicializaci?n
|
55 |
* de la funcionalidad. Las acciones a realizar son:
|
56 |
* <UL>
|
57 |
* <LI>Lanzamiento del dialogo de inicializaci?n.</LI>
|
58 |
* <LI>Carga de la capa raster a georreferenciar.</LI>
|
59 |
* <LI>Creaci?n de las ventanas si no han sido creadas previamente.</LI>
|
60 |
* <LI>Asignaci?n de tama?os y posiciones a las ventanas.</LI>
|
61 |
* </UL>
|
62 |
* 26/12/2007
|
63 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
64 |
*/
|
65 |
public class Georeferencing implements ButtonsPanelListener, ToolListener { |
66 |
public static final int UNDEFINED = -1; |
67 |
//Algoritmo
|
68 |
public static final int POLYNOMIAL = 0; |
69 |
public static final int AFFINE = 1; |
70 |
|
71 |
//Tipo de georreferenciacion
|
72 |
public static final int WITH_MAP = 0; |
73 |
public static final int WITHOUT_MAP = 1; |
74 |
|
75 |
private static int DEFAULT_DEGREE = 3; |
76 |
|
77 |
private GeorefLauncherDialog initDialog = null; |
78 |
private FLyrRasterSE lyrToGeoref = null; |
79 |
private static GCPTablePanel table = null; |
80 |
private static ZoomMapDialog zoomMap = null; |
81 |
private static ZoomRasterDialog zoomPixel = null; |
82 |
private static ViewDialog view = null; |
83 |
private static final int smallWindowsHeight = 100; |
84 |
private static final double smallWindowsWidthPercent = 0.5; |
85 |
private ViewRasterRequestManager viewRequestManager = null; |
86 |
private ViewRasterRequestManager viewRequestManagerZoomPixel = null; |
87 |
|
88 |
public Georeferencing() {
|
89 |
|
90 |
} |
91 |
|
92 |
public void initialize() { |
93 |
launcher(); |
94 |
} |
95 |
|
96 |
/**
|
97 |
* Colocaci?n inicial de las ventanas del espacio de trabajo
|
98 |
*/
|
99 |
private void initWindows() { |
100 |
MDIFrame p = (MDIFrame)PluginServices.getMainFrame(); |
101 |
int wViews = p.getWidth() >> 1; |
102 |
int hViews = p.getHeight() - 178 - smallWindowsHeight; |
103 |
int posYViews = p.getHeight() - 138 - smallWindowsHeight; |
104 |
int smallWindowsWidth = (int)(p.getWidth() * (smallWindowsWidthPercent * 0.5)); |
105 |
int tableWidth = (int)(p.getWidth() * (1 - smallWindowsWidthPercent)); |
106 |
|
107 |
IWindow[] windowList = PluginServices.getMDIManager().getAllWindows();
|
108 |
BufferedImage imgView = null; |
109 |
ViewPort vp = null;
|
110 |
for (int i = 0; i < windowList.length; i++) { |
111 |
if(windowList[i] instanceof IView) { |
112 |
WindowInfo info = windowList[i].getWindowInfo(); |
113 |
info.setX(0);
|
114 |
info.setY(0);
|
115 |
info.setWidth(wViews); |
116 |
info.setHeight(posYViews); |
117 |
|
118 |
imgView = ((IView)windowList[i]).getMapControl().getImage(); |
119 |
vp = ((IView)windowList[i]).getMapControl().getViewPort(); |
120 |
} |
121 |
} |
122 |
if(zoomMap != null) |
123 |
PluginServices.getMDIManager().closeWindow(zoomMap); |
124 |
if(zoomPixel != null) |
125 |
PluginServices.getMDIManager().closeWindow(zoomPixel); |
126 |
if(view != null) |
127 |
PluginServices.getMDIManager().closeWindow(view); |
128 |
if(table != null) |
129 |
PluginServices.getMDIManager().closeWindow(table); |
130 |
|
131 |
table = new GCPTablePanel(smallWindowsWidth, posYViews, tableWidth, smallWindowsHeight);
|
132 |
|
133 |
//Inicializaci?n de la vista raster
|
134 |
view = new ViewDialog(wViews, 0, wViews, hViews, this); |
135 |
view.setShowInfo(true);
|
136 |
viewRequestManager = new ViewRasterRequestManager(view, lyrToGeoref);
|
137 |
view.setExtensionRequest(viewRequestManager); |
138 |
|
139 |
//Inicializaci?n del zoom de la vista raster
|
140 |
zoomPixel = new ZoomRasterDialog(smallWindowsWidth + tableWidth, posYViews, smallWindowsWidth, smallWindowsHeight);
|
141 |
viewRequestManagerZoomPixel = new ViewRasterRequestManager(zoomPixel, lyrToGeoref);
|
142 |
zoomPixel.setExtensionRequest(viewRequestManagerZoomPixel); |
143 |
|
144 |
//Inicializaci?n del zoom de la vista de referencia
|
145 |
zoomMap = new ZoomMapDialog(0, posYViews, smallWindowsWidth, smallWindowsHeight); |
146 |
|
147 |
/*GeoPoint gp = new GeoPoint(new Point2D.Double(100, 100), null);
|
148 |
GPGraphic gpg = new GPGraphic(GPGraphic.PIXEL, gp);
|
149 |
view.getPixelGraphicLayer().addGeoPoint(gpg);*/
|
150 |
|
151 |
/*BufferedImage imgRasterToGeoref = viewRequestManager.drawRasterLayer(new Dimension(wViews, hViews));
|
152 |
if(imgView != null)
|
153 |
setMapParams(imgView, vp);
|
154 |
if(imgRasterToGeoref != null)
|
155 |
setPixelParams(imgRasterToGeoref, lyrToGeoref);
|
156 |
*/
|
157 |
//A?adimos las ventanas a gvSIG
|
158 |
PluginServices.getMDIManager().addWindow(view); |
159 |
PluginServices.getMDIManager().addWindow(table); |
160 |
PluginServices.getMDIManager().addWindow(zoomMap); |
161 |
PluginServices.getMDIManager().addWindow(zoomPixel); |
162 |
|
163 |
//Inicializamos la extensi?n del componente y dibujamos
|
164 |
try {
|
165 |
viewRequestManager.initRequest(lyrToGeoref.getFullExtent());/*new Rectangle2D.Double( lyrToGeoref.getFullRasterExtent().getULX(),
|
166 |
lyrToGeoref.getFullRasterExtent().getULY(),
|
167 |
lyrToGeoref.getFullRasterExtent().width(),
|
168 |
lyrToGeoref.getFullRasterExtent().height()));*/
|
169 |
view.setZoomCursorSize(zoomPixel.getCanvasWidth() / 3, zoomPixel.getCanvasHeight() / 3); |
170 |
|
171 |
Rectangle2D ext = view.getCursorAdjustedWorldCoordinates(zoomPixel.getCanvasWidth(), zoomPixel.getCanvasHeight());
|
172 |
viewRequestManagerZoomPixel.initRequest(lyrToGeoref.getFullExtent()); |
173 |
//viewRequestManagerZoomPixel.setDrawParams(null, new Rectangle2D.Double(ext.getX(), ext.getY() - ext.getHeight(), ext.getWidth(), ext.getHeight()));
|
174 |
viewRequestManagerZoomPixel.request(ext); |
175 |
} catch (InvalidRequestException e1) {
|
176 |
RasterToolsUtil.messageBoxError("error_setview_preview", this); |
177 |
} |
178 |
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* Obtiene y asigna los par?metros para el control de zoom del mapa
|
183 |
* @param img BufferedImage
|
184 |
* @param vp ViewPort
|
185 |
*/
|
186 |
public void setMapParams(BufferedImage img, ViewPort vp) { |
187 |
if(zoomMap != null && img != null) { |
188 |
Rectangle2D r = vp.getAdjustedExtent();
|
189 |
int w = vp.getImageWidth();
|
190 |
zoomMap.setDrawParams(img, r, r.getWidth() / w, new Point2D.Double(r.getCenterX(), r.getCenterY())); |
191 |
zoomMap.getMapGraphicLayer(); |
192 |
} |
193 |
} |
194 |
|
195 |
/**
|
196 |
* Obtiene y asigna los par?metros para el control de zoom del mapa
|
197 |
* @param img BufferedImage
|
198 |
* @param vp ViewPort
|
199 |
*/
|
200 |
public void setPixelParams(BufferedImage img, FLyrRasterSE lyr) { |
201 |
if(view != null && zoomPixel != null && img != null && lyr != null) { |
202 |
Rectangle2D extBuf;
|
203 |
try {
|
204 |
extBuf = viewRequestManager.request(null);
|
205 |
viewRequestManager.setDrawParams(img, extBuf); |
206 |
zoomPixel.setDrawParams(img, extBuf, extBuf.getHeight()/img.getHeight(), new Point2D.Double(extBuf.getCenterX(), extBuf.getCenterY())); |
207 |
zoomPixel.getPixelGraphicLayer(); |
208 |
} catch (InvalidRequestException e1) {
|
209 |
RasterToolsUtil.messageBoxError("error_setview_preview", this); |
210 |
} |
211 |
} |
212 |
} |
213 |
|
214 |
/**
|
215 |
* Lanzador del cuadro de inicializaci?n de propiedades de georreferenciaci?n.
|
216 |
*/
|
217 |
private void launcher() { |
218 |
Project p = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject(); |
219 |
ArrayList docs = p.getDocumentsByType(ProjectViewFactory.registerName);
|
220 |
String[] viewList = new String[docs.size()]; |
221 |
for (int i = 0; i < docs.size(); i++) |
222 |
viewList[i] = (((ProjectView)docs.get(i)).getName()); |
223 |
initDialog = new GeorefLauncherDialog(viewList, DEFAULT_DEGREE, this); |
224 |
PluginServices.getMDIManager().addWindow(initDialog); |
225 |
} |
226 |
|
227 |
/**
|
228 |
* Captura de eventos de los botones Aceptar y Cancelar del cuadro
|
229 |
* inicial con las propiedades de georreferenciaci?n.
|
230 |
*/
|
231 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
232 |
// Bot?n de Aceptar
|
233 |
if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
|
234 |
if(initDialog != null) { |
235 |
lyrToGeoref = initDialog.getLayer(); |
236 |
if(lyrToGeoref == null) |
237 |
RasterToolsUtil.messageBoxError("layer_not_loaded", this); |
238 |
else {
|
239 |
PluginServices.getMDIManager().closeWindow(initDialog); |
240 |
initWindows(); |
241 |
} |
242 |
} |
243 |
} |
244 |
// Bot?n de Cerrar
|
245 |
if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
|
246 |
if(initDialog != null) |
247 |
PluginServices.getMDIManager().closeWindow(initDialog); |
248 |
} |
249 |
} |
250 |
|
251 |
/**
|
252 |
* Evento de finalizaci?n de la capa con el
|
253 |
* cursor gr?fico que controla el ?rea de la miniimagen asociada
|
254 |
*/
|
255 |
public void endAction(ToolEvent ev) { |
256 |
if(ev.getSource() instanceof ZoomCursorGraphicLayer) { |
257 |
try {
|
258 |
Rectangle2D ext = view.getCursorAdjustedWorldCoordinates(zoomPixel.getCanvasWidth(), zoomPixel.getCanvasHeight());
|
259 |
viewRequestManagerZoomPixel.request(ext); |
260 |
} catch (InvalidRequestException e1) {
|
261 |
RasterToolsUtil.messageBoxError("error_setview_preview", this); |
262 |
} |
263 |
} |
264 |
} |
265 |
} |