root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / Rasterizer.java @ 2249
History | View | Annotate | Download (5.77 KB)
1 |
/*
|
---|---|
2 |
* Created on 21-jun-2005
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package org.cresques.io; |
48 |
|
49 |
import java.awt.Dimension; |
50 |
import java.awt.Graphics2D; |
51 |
import java.awt.image.BufferedImage; |
52 |
import java.awt.image.WritableRaster; |
53 |
|
54 |
import org.cresques.geo.ViewPortData; |
55 |
import org.cresques.px.Extent; |
56 |
import org.cresques.px.PxLayerList; |
57 |
|
58 |
|
59 |
/**
|
60 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
61 |
*
|
62 |
* Sirve datos solicitados por los drivers que salvan a raster. Implementa
|
63 |
* IDataWriter que obliga al m?todo readData que es el que ser? llamado
|
64 |
* desde el driver cada vez que vacie el buffer y necesite m?s datos.
|
65 |
*/
|
66 |
public class Rasterizer implements IDataWriter { |
67 |
|
68 |
private ViewPortData viewPort = null; |
69 |
private ViewPortData viewPortBlock = null; |
70 |
protected BufferedImage image; |
71 |
private PxLayerList layerList;
|
72 |
protected int sizeBlock = 0; |
73 |
protected int lastBlock = 0; |
74 |
protected WritableRaster raster = null; |
75 |
protected int contBlocks = 1; |
76 |
protected double wcIntervalo = 0; |
77 |
protected int[] rasterData = null; |
78 |
protected Dimension dimension = null; |
79 |
protected int[] buffer; |
80 |
protected double wcAlto = 0; |
81 |
protected Graphics2D g; |
82 |
|
83 |
/**
|
84 |
* Calculo del viewPort de cada bloque que vamos salvando a raster
|
85 |
* @param vp viewPort
|
86 |
*/
|
87 |
private void calcViewPort(ViewPortData vp){ |
88 |
Extent ext = null;
|
89 |
|
90 |
if(viewPortBlock == null)//Primer bloque |
91 |
ext = new Extent( Math.round(vp.getExtent().minX()), |
92 |
Math.round(vp.getExtent().maxY()),
|
93 |
Math.round(vp.getExtent().maxX()),
|
94 |
Math.round(vp.getExtent().maxY()-wcIntervalo));
|
95 |
else //Bloques siguientes |
96 |
ext = new Extent( Math.round(vp.getExtent().minX()), |
97 |
Math.round(vp.getExtent().minY()),
|
98 |
Math.round(vp.getExtent().maxX()),
|
99 |
Math.round(vp.getExtent().minY()-wcIntervalo));
|
100 |
|
101 |
viewPortBlock = new ViewPortData( vp.getProjection(),
|
102 |
ext, |
103 |
dimension); |
104 |
viewPortBlock.zoom(ext); |
105 |
|
106 |
} |
107 |
|
108 |
/**
|
109 |
* Constructor para las clases que hereden de esta
|
110 |
* y redefinan la funcionalidad que sirve los datos. Estas
|
111 |
* tampoco usaran el viewPort ya que se supone que disponen
|
112 |
* de su propia estructura para la seleccion de la vista
|
113 |
*/
|
114 |
public Rasterizer(int sizeBlock){ |
115 |
this.sizeBlock = sizeBlock;
|
116 |
} |
117 |
|
118 |
/**
|
119 |
* Constructor
|
120 |
* @param layerList
|
121 |
* @param vp
|
122 |
* @param sizeBlock
|
123 |
*/
|
124 |
|
125 |
public Rasterizer(PxLayerList layerList, ViewPortData vp, int sizeBlock){ |
126 |
|
127 |
viewPort = (ViewPortData) vp.clone(); |
128 |
|
129 |
//Calculo del viewPort del primer bloque
|
130 |
|
131 |
wcAlto = viewPort.getExtent().maxY() - viewPort.getExtent().minY(); |
132 |
wcIntervalo = (sizeBlock*wcAlto)/viewPort.getHeight(); |
133 |
dimension = new Dimension((int)viewPort.getWidth(), sizeBlock); |
134 |
|
135 |
calcViewPort(viewPort); |
136 |
|
137 |
//Tama?o de ?ltimo bloque
|
138 |
int nBlocks = (int)(vp.getHeight()/sizeBlock); |
139 |
lastBlock = (int)(vp.getHeight()-(nBlocks*sizeBlock));
|
140 |
|
141 |
this.layerList = layerList;
|
142 |
this.sizeBlock = sizeBlock;
|
143 |
//System.out.println("==>Iniciando servidor datos raster "+viewPort.getHeight()+" "+viewPort.getWidth()+" "+wcIntervalo +"..."+viewPortBlock.getExtent().maxX()+" - "+viewPortBlock.getExtent().maxY()+" - "+viewPortBlock.getExtent().minX()+" - "+viewPortBlock.getExtent().minY());
|
144 |
|
145 |
} |
146 |
|
147 |
/* (non-Javadoc)
|
148 |
* @see org.cresques.io.IDataWriter#readData(int, int, int)
|
149 |
*/
|
150 |
public int[] readData(int sX, int sY, int nBand){ |
151 |
|
152 |
if(nBand == 0){ //Con nBand==0 se devuelven las 3 bandas |
153 |
//image = new BufferedImage((int)this.viewPortBlock.getWidth(), (int)this.viewPortBlock.getHeight(), BufferedImage.TYPE_INT_RGB);
|
154 |
image = new BufferedImage(sX, sY, BufferedImage.TYPE_INT_RGB); |
155 |
g = (Graphics2D) image.getGraphics();
|
156 |
layerList.draw(g, viewPortBlock); |
157 |
|
158 |
rasterData = image.getRGB(0, 0, sX, sY, rasterData, 0, sX); |
159 |
|
160 |
//System.out.println("==>Cargando bloque ..."+(int)this.viewPortBlock.getWidth()+" * "+(int)this.viewPortBlock.getHeight()+" * "+viewPortBlock.getExtent().maxX()+" - "+viewPortBlock.getExtent().maxY()+" - "+viewPortBlock.getExtent().minX()+" - "+viewPortBlock.getExtent().minY());
|
161 |
//System.out.println("==>Escribiendo linea ...0 - 0 - "+sX+" - "+sY+" - "+contBlocks);
|
162 |
|
163 |
//Calculamos el viewPort del sgte bloque
|
164 |
|
165 |
if(((contBlocks+1)*sizeBlock)<=viewPort.getHeight()){ |
166 |
dimension = new Dimension(sX, sY); |
167 |
} |
168 |
else{ //Calculo de la altura del ?ltimo bloque |
169 |
dimension = new Dimension(sX, (int)(viewPort.getHeight()-(contBlocks*sizeBlock))); |
170 |
wcIntervalo = (lastBlock*wcAlto)/viewPort.getHeight(); |
171 |
} |
172 |
|
173 |
calcViewPort(viewPortBlock); |
174 |
|
175 |
contBlocks++; |
176 |
return rasterData;
|
177 |
} |
178 |
|
179 |
return null; |
180 |
} |
181 |
} |