svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src-dvp / org / cresques / io / Rasterizer.java @ 1844
History | View | Annotate | Download (4.47 KB)
1 |
/*
|
---|---|
2 |
* Created on 04-mar-2005
|
3 |
*
|
4 |
* TODO To change the template for this generated file go to
|
5 |
* Window - Preferences - Java - Code Style - Code Templates
|
6 |
*/
|
7 |
package org.cresques.io; |
8 |
|
9 |
import java.awt.Color; |
10 |
import java.awt.Dimension; |
11 |
import java.awt.Graphics; |
12 |
import java.awt.Graphics2D; |
13 |
import java.awt.image.BufferedImage; |
14 |
import java.awt.image.Raster; |
15 |
import java.awt.image.WritableRaster; |
16 |
|
17 |
import org.cresques.geo.ViewPortData; |
18 |
import org.cresques.px.Extent; |
19 |
import org.cresques.px.PxLayerList; |
20 |
|
21 |
|
22 |
/**
|
23 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
24 |
*
|
25 |
* Sirve datos solicitados por los drivers que salvan a raster. Implementa
|
26 |
* IDataWriter que obliga al m?todo readData que es el que ser? llamado
|
27 |
* desde el driver cada vez que vacie el buffer y necesite m?s datos.
|
28 |
*/
|
29 |
public class Rasterizer implements IDataWriter { |
30 |
|
31 |
private ViewPortData viewPort = null; |
32 |
private ViewPortData viewPortBlock = null; |
33 |
protected BufferedImage image; |
34 |
private PxLayerList layerList;
|
35 |
protected int sizeBlock = 0; |
36 |
protected int lastBlock = 0; |
37 |
protected WritableRaster raster = null; |
38 |
protected int contBlocks = 1; |
39 |
protected double wcIntervalo = 0; |
40 |
protected int[] rasterData = null; |
41 |
protected Dimension dimension = null; |
42 |
protected int[] buffer; |
43 |
protected double wcAlto = 0; |
44 |
protected Graphics2D g; |
45 |
|
46 |
/**
|
47 |
* Calculo del viewPort de cada bloque que vamos salvando a raster
|
48 |
* @param vp viewPort
|
49 |
*/
|
50 |
private void calcViewPort(ViewPortData vp){ |
51 |
Extent ext = null;
|
52 |
|
53 |
if(viewPortBlock == null)//Primer bloque |
54 |
ext = new Extent( vp.getExtent().minX(),
|
55 |
vp.getExtent().maxY(), |
56 |
vp.getExtent().maxX(), |
57 |
vp.getExtent().maxY()-wcIntervalo); |
58 |
else //Bloques siguientes |
59 |
ext = new Extent( vp.getExtent().minX(),
|
60 |
vp.getExtent().minY(), |
61 |
vp.getExtent().maxX(), |
62 |
vp.getExtent().minY()-wcIntervalo); |
63 |
|
64 |
viewPortBlock = new ViewPortData( vp.getProjection(),
|
65 |
ext, |
66 |
dimension); |
67 |
viewPortBlock.zoom(ext); |
68 |
|
69 |
} |
70 |
|
71 |
/**
|
72 |
* Constructor para las clases que hereden de esta
|
73 |
* y redefinan la funcionalidad que sirve los datos. Estas
|
74 |
* tampoco usaran el viewPort ya que se supone que disponen
|
75 |
* de su propia estructura para la seleccion de la vista
|
76 |
*/
|
77 |
public Rasterizer(int sizeBlock){ |
78 |
this.sizeBlock = sizeBlock;
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* Constructor
|
83 |
* @param layerList
|
84 |
* @param vp
|
85 |
* @param sizeBlock
|
86 |
*/
|
87 |
|
88 |
public Rasterizer(PxLayerList layerList, ViewPortData vp, int sizeBlock){ |
89 |
|
90 |
viewPort = (ViewPortData) vp.clone(); |
91 |
|
92 |
//Calculo del viewPort del primer bloque
|
93 |
|
94 |
wcAlto = viewPort.getExtent().maxY() - viewPort.getExtent().minY(); |
95 |
wcIntervalo = (sizeBlock*wcAlto)/viewPort.getHeight(); |
96 |
dimension = new Dimension((int)viewPort.getWidth(), sizeBlock); |
97 |
|
98 |
calcViewPort(viewPort); |
99 |
|
100 |
//Tama?o de ?ltimo bloque
|
101 |
int nBlocks = (int)(vp.getHeight()/sizeBlock); |
102 |
lastBlock = (int)(vp.getHeight()-(nBlocks*sizeBlock));
|
103 |
|
104 |
this.layerList = layerList;
|
105 |
this.sizeBlock = sizeBlock;
|
106 |
//System.out.println("==>Iniciando servidor datos raster "+viewPort.getHeight()+" "+viewPort.getWidth()+" "+wcIntervalo +"..."+viewPortBlock.getExtent().maxX()+" - "+viewPortBlock.getExtent().maxY()+" - "+viewPortBlock.getExtent().minX()+" - "+viewPortBlock.getExtent().minY());
|
107 |
|
108 |
} |
109 |
|
110 |
public int[] readData(int sX, int sY, int nBand){ |
111 |
|
112 |
if(nBand == 0){ //Con nBand==0 se devuelven las 3 bandas |
113 |
//image = new BufferedImage((int)this.viewPortBlock.getWidth(), (int)this.viewPortBlock.getHeight(), BufferedImage.TYPE_INT_RGB);
|
114 |
image = new BufferedImage(sX, sY, BufferedImage.TYPE_INT_RGB); |
115 |
g = (Graphics2D) image.getGraphics();
|
116 |
layerList.draw(g, viewPortBlock); |
117 |
|
118 |
rasterData = image.getRGB(0, 0, sX, sY, rasterData, 0, sX); |
119 |
|
120 |
//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());
|
121 |
//System.out.println("==>Escribiendo linea ...0 - 0 - "+sX+" - "+sY+" - "+contBlocks);
|
122 |
|
123 |
//Calculamos el viewPort del sgte bloque
|
124 |
|
125 |
if(((contBlocks+1)*sizeBlock)<=viewPort.getHeight()){ |
126 |
dimension = new Dimension(sX, sY); |
127 |
} |
128 |
else{ //Calculo de la altura del ?ltimo bloque |
129 |
dimension = new Dimension(sX, (int)(viewPort.getHeight()-(contBlocks*sizeBlock))); |
130 |
wcIntervalo = (lastBlock*wcAlto)/viewPort.getHeight(); |
131 |
} |
132 |
|
133 |
calcViewPort(viewPortBlock); |
134 |
|
135 |
contBlocks++; |
136 |
return rasterData;
|
137 |
} |
138 |
|
139 |
return null; |
140 |
} |
141 |
} |