svn-gvsig-desktop / branches / gvSIG_GisPlanet / applications / appgvSIG / src / com / iver / cit / gvsig / RasterizerLayer.java @ 2147
History | View | Annotate | Download (6.81 KB)
1 | 1970 | igbrotru | /*
|
---|---|---|---|
2 | * Created on 17-feb-2004
|
||
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 com.iver.cit.gvsig; |
||
48 | |||
49 | import java.awt.Color; |
||
50 | import java.awt.Dimension; |
||
51 | import java.awt.Graphics2D; |
||
52 | import java.awt.geom.Rectangle2D; |
||
53 | import java.awt.image.BufferedImage; |
||
54 | |||
55 | 2123 | igbrotru | import javax.swing.JProgressBar; |
56 | |||
57 | 1970 | igbrotru | import org.cresques.io.Rasterizer; |
58 | |||
59 | import com.iver.cit.gvsig.fmap.DriverException; |
||
60 | import com.iver.cit.gvsig.fmap.MapControl; |
||
61 | import com.iver.cit.gvsig.fmap.ViewPort; |
||
62 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
63 | import com.iver.cit.gvsig.fmap.operations.Cancellable; |
||
64 | |||
65 | /**
|
||
66 | * @author Nacho Brodin <brodin_ign@gva.es>
|
||
67 | *
|
||
68 | * Sirve datos solicitados por los drivers que salvan a raster.
|
||
69 | * Hereda de Rasterizer y reescribe el m?todo readData que es el que
|
||
70 | * ser? llamado desde el driver cada vez que vacie el buffer y
|
||
71 | * necesite m?s datos.
|
||
72 | */
|
||
73 | public class RasterizerLayer extends Rasterizer{ |
||
74 | |||
75 | 2123 | igbrotru | private ViewPort viewPort = null; |
76 | private ViewPort viewPortBlock = null; |
||
77 | private FLayers flayers = null; |
||
78 | private Color backgroundColor = null; |
||
79 | private JProgressBar progressBar = null; |
||
80 | private double incrProgressBar = 0; |
||
81 | 1970 | igbrotru | |
82 | /**
|
||
83 | * Calculo del viewPort
|
||
84 | * @param vp
|
||
85 | */
|
||
86 | private void calcViewPort(ViewPort vp){ |
||
87 | Rectangle2D ext = null; |
||
88 | |||
89 | if(viewPortBlock == null){ |
||
90 | 2107 | igbrotru | ext = new Rectangle2D.Double( Math.round(vp.getExtent().getMinX()), |
91 | Math.round(vp.getExtent().getMaxY()-wcIntervalo),
|
||
92 | Math.round(vp.getExtent().getWidth()),
|
||
93 | Math.round(wcIntervalo)
|
||
94 | 1970 | igbrotru | ); |
95 | }else{
|
||
96 | 2107 | igbrotru | ext = new Rectangle2D.Double( Math.round(vp.getExtent().getMinX()), |
97 | Math.round(vp.getExtent().getMinY()-wcIntervalo),
|
||
98 | Math.round(vp.getExtent().getWidth()),
|
||
99 | Math.round(wcIntervalo)
|
||
100 | 1970 | igbrotru | ); |
101 | } |
||
102 | |||
103 | viewPortBlock = new ViewPort(vp.getProjection());
|
||
104 | viewPortBlock.setExtent(ext); |
||
105 | viewPortBlock.setImageSize(dimension); |
||
106 | viewPortBlock.setScale(); |
||
107 | //System.out.println("--->bloque="+contBlocks+" ImageHeight="+viewPortBlock.getImageHeight()+" ImageWidth="+viewPortBlock.getImageWidth());
|
||
108 | //System.out.println("--->minX="+viewPortBlock.getExtent().getMinX()+" minY="+viewPortBlock.getExtent().getMinY()+" maxX="+viewPortBlock.getExtent().getMaxX()+" maxY="+viewPortBlock.getExtent().getMaxY()+" width="+viewPortBlock.getExtent().getWidth()+" height="+viewPortBlock.getExtent().getHeight());
|
||
109 | } |
||
110 | |||
111 | /**
|
||
112 | * Constructor
|
||
113 | * @param flyrs capas
|
||
114 | * @param vp viewport
|
||
115 | * @param sizeBlock altura del bloque que se lee de una vez en la imagen de entrada
|
||
116 | * @param mapCtrl Mapcontrol
|
||
117 | */
|
||
118 | public RasterizerLayer(FLayers flyrs, ViewPort vp, int sizeBlock, MapControl mapCtrl){ |
||
119 | |||
120 | super(sizeBlock);
|
||
121 | backgroundColor = vp.getBackColor(); |
||
122 | viewPort = new ViewPort(vp.getProjection());
|
||
123 | viewPort.setImageSize(vp.getImageSize()); |
||
124 | viewPort.setExtent(vp.getExtent()); |
||
125 | |||
126 | //Calculo del viewPort del primer bloque
|
||
127 | |||
128 | wcAlto = viewPort.getExtent().getMaxY() - viewPort.getExtent().getMinY(); |
||
129 | wcIntervalo = (sizeBlock*wcAlto)/viewPort.getImageHeight(); |
||
130 | dimension = new Dimension(viewPort.getImageWidth(), sizeBlock); |
||
131 | |||
132 | calcViewPort(viewPort); |
||
133 | |||
134 | int nBlocks = (int)(vp.getImageHeight()/sizeBlock); |
||
135 | 2123 | igbrotru | incrProgressBar = 100.0/((double)nBlocks); |
136 | System.out.println("===>NBLOCKS="+nBlocks+" INCR="+incrProgressBar); |
||
137 | 1970 | igbrotru | |
138 | //Tama?o de ?ltimo bloque en pixeles
|
||
139 | lastBlock = Math.round(vp.getImageHeight()-(nBlocks*sizeBlock));
|
||
140 | |||
141 | /*System.out.println("1--->SizeBlock="+sizeBlock+" ImageHeight="+viewPort.getImageHeight()+" ImageWidth="+viewPort.getImageWidth());
|
||
142 | System.out.println("2--->wcAlto="+wcAlto+" wcIntervalo="+wcIntervalo);
|
||
143 | System.out.println("3--->nBlocks="+nBlocks+" lastBlock="+lastBlock);
|
||
144 | System.out.println("4--->minX="+viewPort.getExtent().getMinX()+" minY="+viewPort.getExtent().getMinY()+" maxX="+viewPort.getExtent().getMaxX()+" maxY="+viewPort.getExtent().getMaxY()+" width="+viewPort.getExtent().getWidth()+" height="+viewPort.getExtent().getHeight());
|
||
145 | */
|
||
146 | this.flayers = flyrs;
|
||
147 | this.sizeBlock = sizeBlock;
|
||
148 | } |
||
149 | |||
150 | |||
151 | /* (non-Javadoc)
|
||
152 | * @see org.cresques.io.IDataWriter#readData(int, int, int)
|
||
153 | */
|
||
154 | public int[] readData(int sX, int sY, int nBand){ |
||
155 | if(nBand == 0){ //Con nBand==0 se devuelven las 3 bandas |
||
156 | image = new BufferedImage(sX, sY, BufferedImage.TYPE_INT_RGB); |
||
157 | g = (Graphics2D) image.getGraphics();
|
||
158 | BufferedImage img = new BufferedImage( viewPortBlock.getImageWidth(), |
||
159 | viewPortBlock.getImageHeight(), |
||
160 | BufferedImage.TYPE_INT_ARGB
|
||
161 | ); |
||
162 | g.setColor(backgroundColor); |
||
163 | g.fillRect(0, 0, viewPortBlock.getImageWidth(), viewPortBlock.getImageHeight()); |
||
164 | try{
|
||
165 | flayers.draw(img, g, viewPortBlock,new Cancellable() {
|
||
166 | public boolean isCanceled() { |
||
167 | return false; |
||
168 | } |
||
169 | }); |
||
170 | }catch (DriverException e) {
|
||
171 | e.printStackTrace(); |
||
172 | } |
||
173 | rasterData = image.getRGB(0, 0, sX, sY, rasterData, 0, sX); |
||
174 | |||
175 | //Calculamos el viewPort del sgte bloque
|
||
176 | |||
177 | if(((contBlocks+1)*sizeBlock)<=viewPort.getImageHeight()){ |
||
178 | dimension = new Dimension(sX, sY); |
||
179 | } |
||
180 | else{ //Calculo de la altura del ?ltimo bloque |
||
181 | dimension = new Dimension(sX, (int)(viewPort.getImageHeight()-(contBlocks*sizeBlock))); |
||
182 | wcIntervalo = (lastBlock*wcAlto)/viewPort.getImageHeight(); |
||
183 | } |
||
184 | |||
185 | calcViewPort(viewPortBlock); |
||
186 | 2123 | igbrotru | |
187 | if(progressBar != null) |
||
188 | progressBar.setValue((int)Math.round(progressBar.getValue()+incrProgressBar)); |
||
189 | |||
190 | 1970 | igbrotru | contBlocks++; |
191 | return rasterData;
|
||
192 | } |
||
193 | |||
194 | return null; |
||
195 | } |
||
196 | |||
197 | 2123 | igbrotru | /**
|
198 | * Asigna la barra de progreso
|
||
199 | * @param bar Barra de progreso
|
||
200 | */
|
||
201 | public void setProgressBar(JProgressBar bar){ |
||
202 | this.progressBar = bar;
|
||
203 | //progressBar.setValue((int)Math.round(incrProgressBar));
|
||
204 | } |
||
205 | 1970 | igbrotru | } |