svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / georeferencing / ui / zoom / ViewRasterRequestManager.java @ 18264
History | View | Annotate | Download (5.48 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.ui.zoom; |
20 |
|
21 |
import java.awt.Dimension; |
22 |
import java.awt.Graphics2D; |
23 |
import java.awt.geom.Point2D; |
24 |
import java.awt.geom.Rectangle2D; |
25 |
import java.awt.image.BufferedImage; |
26 |
|
27 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
28 |
import org.gvsig.raster.dataset.InvalidSetViewException; |
29 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
30 |
import org.gvsig.raster.datastruct.Extent; |
31 |
import org.gvsig.raster.datastruct.ViewPortData; |
32 |
import org.gvsig.raster.util.RasterUtilities; |
33 |
import org.gvsig.rastertools.georeferencing.view.BaseZoomView; |
34 |
|
35 |
/**
|
36 |
* Gestor de peticiones de zoom sobre el panel con el raster a georreferenciar.
|
37 |
* Implementa el interfaz IExtensionRequest para que este comunique la peticiones
|
38 |
* de zoom y ViewRasterRequestManager pueda hacer las peticiones de datos a la capa.
|
39 |
*
|
40 |
* 30/12/2007
|
41 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
42 |
*/
|
43 |
public class ViewRasterRequestManager implements IExtensionRequest { |
44 |
private FLyrRasterSE lyr = null; |
45 |
private BaseZoomView view = null; |
46 |
|
47 |
/**
|
48 |
* Asigna la capa a georreferenciar de donde se obtienen los datos.
|
49 |
* @param lyr
|
50 |
*/
|
51 |
public ViewRasterRequestManager(BaseZoomView view, FLyrRasterSE lyr) {
|
52 |
this.lyr = lyr;
|
53 |
this.view = view;
|
54 |
} |
55 |
|
56 |
/**
|
57 |
* Calcula la extensi?n que contendr? la vista a partir del extent
|
58 |
* m?ximo de la capa/s que contienen . Tienen en cuenta las distintan proporciones
|
59 |
* entre vista y petici?n
|
60 |
* @param Rectangle2D
|
61 |
*/
|
62 |
public Rectangle2D initRequest(Rectangle2D extent) throws InvalidRequestException { |
63 |
double x, y, w, h;
|
64 |
//Calculamos la extensi?n de la vista para el extent m?ximo que va a contener
|
65 |
//teniendo en cuenta las proporciones de ambos.
|
66 |
if(extent.getHeight() > extent.getWidth()) {
|
67 |
y = extent.getY(); |
68 |
h = extent.getHeight(); |
69 |
w = (view.getCanvasWidth() * h) / view.getCanvasHeight(); |
70 |
x = extent.getCenterX() - (w / 2);
|
71 |
} else {
|
72 |
x = extent.getX(); |
73 |
w = extent.getWidth(); |
74 |
h = (view.getCanvasHeight() * w) / view.getCanvasWidth(); |
75 |
y = extent.getCenterY() - (h / 2);
|
76 |
} |
77 |
Rectangle2D r = new Rectangle2D.Double(x, y, w, h); |
78 |
view.getCanvas().setCanvasExtent(new Rectangle2D.Double(x, y + h , w, h)); |
79 |
request(r); |
80 |
return r;
|
81 |
} |
82 |
|
83 |
/*
|
84 |
* (non-Javadoc)
|
85 |
* @see org.gvsig.rastertools.georeferencing.ui.zoom.IExtensionRequest#request(java.awt.geom.Rectangle2D)
|
86 |
*/
|
87 |
public Rectangle2D request(Rectangle2D extent) throws InvalidRequestException { |
88 |
if(extent == null) |
89 |
return lyr.getFullExtent();
|
90 |
|
91 |
//Ajustamos el extent al del raster
|
92 |
Extent ext = new Extent(extent);//.getX(), extent.getY(), extent.getX() + extent.getWidth(), extent.getY() - extent.getHeight()); |
93 |
Extent extSelection = RasterUtilities.calculateAdjustedView(ext, lyr.getFullRasterExtent()); |
94 |
|
95 |
//Obtenemos el viewport y calculamos la matriz de transformaci?n
|
96 |
ViewPortData vp = new ViewPortData( null, ext, new Dimension(view.getCanvasWidth(), view.getCanvasHeight())); |
97 |
vp.calculateAffineTransform(); |
98 |
|
99 |
//Calculamos el punto del canvas de la vista donde se empieza a dibujar el buffer de la imagen
|
100 |
Point2D pt = new Point2D.Double(extSelection.getULX(), extSelection.getLRY()); |
101 |
vp.mat.transform(pt, pt); |
102 |
|
103 |
try {
|
104 |
//Dibujamos a trav?s del render de la capa en un graphics como el de la vista
|
105 |
BufferedImage initImg = new BufferedImage(view.getCanvasWidth(), view.getCanvasHeight(), BufferedImage.TYPE_INT_RGB); |
106 |
BufferedImage drawedImg = (BufferedImage)lyr.getRender().draw((Graphics2D)initImg.getGraphics(), vp); |
107 |
((Graphics2D)initImg.getGraphics()).drawImage(drawedImg, (int) Math.round(pt.getX()), (int) Math.round(pt.getY()), null); |
108 |
|
109 |
//Asignamos el buffer a dibujar al canvas
|
110 |
if(initImg != null) |
111 |
setDrawParams(initImg, extent); |
112 |
else
|
113 |
throw new InvalidSetViewException("Buffer de dibujado vacio"); |
114 |
} catch (RasterDriverException e) {
|
115 |
throw new InvalidRequestException("Error en al acceso al fichero"); |
116 |
} catch (InvalidSetViewException e) {
|
117 |
throw new InvalidRequestException("Error asignando el ?rea de la petici?n"); |
118 |
} catch (InterruptedException e) { |
119 |
} |
120 |
return extent;
|
121 |
} |
122 |
|
123 |
/*
|
124 |
* (non-Javadoc)
|
125 |
* @see org.gvsig.rastertools.georeferencing.ui.zoom.IExtensionRequest#fullExtent(java.awt.Dimension)
|
126 |
*/
|
127 |
public void fullExtent() throws InvalidRequestException { |
128 |
this.initRequest(lyr.getFullRasterExtent().toRectangle2D());
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* Asigna los par?metros para el control de zoom del mapa
|
133 |
* @param img BufferedImage
|
134 |
* @param vp ViewPort
|
135 |
*/
|
136 |
public void setDrawParams(BufferedImage img, Rectangle2D extBuf) { |
137 |
if(view != null && lyr != null) { |
138 |
if(img != null) |
139 |
view.setDrawParams(img, extBuf, extBuf.getWidth()/img.getWidth(), new Point2D.Double(extBuf.getCenterX(), extBuf.getCenterY())); |
140 |
} |
141 |
} |
142 |
|
143 |
} |