svn-gvsig-desktop / tags / v1_1_Build_1013 / libraries / libCq_CMS_praster / src / org / cresques / io / data / BandList.java @ 13521
History | View | Annotate | Download (7.78 KB)
1 | 8026 | nacho | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2006 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.cresques.io.data; |
||
20 | |||
21 | import java.util.ArrayList; |
||
22 | |||
23 | import org.cresques.io.exceptions.BandFoundInListException; |
||
24 | |||
25 | /**
|
||
26 | * Esta clase gestiona una lista de bandas que puede pertenecer
|
||
27 | * a un fichero (la tiene un geoRasterFile) o puede ser una lista
|
||
28 | * de bandas de multiples ficheros (la tiene un multifiledataset)
|
||
29 | * @author Nacho Brodin (brodin_ign@gva.es)
|
||
30 | *
|
||
31 | */
|
||
32 | public class BandList { |
||
33 | 10645 | nacho | //Band array
|
34 | 8026 | nacho | private ArrayList bands = new ArrayList(); |
35 | |||
36 | /**
|
||
37 | * Encuentra una banda en la lista.
|
||
38 | * @param file Fichero al que pertenece la banda buscada.
|
||
39 | * @param pos Posici?n que ocupa en el fichero.
|
||
40 | * @return true si se ha hallado la banda y false si no se
|
||
41 | * ha encontrado
|
||
42 | */
|
||
43 | public boolean findBand(Band band){ |
||
44 | for(int i = 0; i < bands.size(); i++){ |
||
45 | Band b = (Band)bands.get(i); |
||
46 | if( b.getFileName().equals(band.getFileName()) &&
|
||
47 | b.getPosition() == band.getPosition()) |
||
48 | return true; |
||
49 | } |
||
50 | return false; |
||
51 | } |
||
52 | |||
53 | /**
|
||
54 | * Obtiene la lista de bandas a pintar sobre el buffer de
|
||
55 | * salida en forma de array. Cada elemento del array es una banda
|
||
56 | * del RasterBuf de salida que ha de dibujarse y el valor que contiene
|
||
57 | * ese elemento es la banda de la imagen que va pintada en esa banda
|
||
58 | * del RasterBuf.
|
||
59 | * <table border=1>
|
||
60 | * <tr><td>Elem</td><td>Valor</td></tr>
|
||
61 | * <tr><td>0</td><td>1</td></tr>
|
||
62 | * <tr><td>1</td><td>0</td></tr>
|
||
63 | * <tr><td>2</td><td>-1</td></tr>
|
||
64 | * <tr><td>3</td><td>0</td></tr>
|
||
65 | * <tr><td>4</td><td>2</td></tr>
|
||
66 | * </table>
|
||
67 | * El RasterBuf tendra en la banda 0 dibujada la banda 1 de este GeoRasterFile,
|
||
68 | * en la banda 1 la 0 del dataset, en la banda 2 no habr? ninguna de este dataset,
|
||
69 | * en la 3 la 0 y en la 4 la 2 de este GeoRasterFile.
|
||
70 | * @return lista de bandas a dibujar o un array de un elemento con valor -1.
|
||
71 | */
|
||
72 | public int[] bandsToDrawList(int nBandsDataImage){ |
||
73 | |||
74 | int[] bandsToRead = new int[nBandsDataImage]; |
||
75 | for(int dataImageBand = 0;dataImageBand < nBandsDataImage;dataImageBand++){ |
||
76 | bandsToRead[dataImageBand] = -1;
|
||
77 | for(int band = 0;band < bands.size();band++){ |
||
78 | if( ((Band)bands.get(band)) != null && |
||
79 | ((Band)bands.get(band)).getDataImageBandToDraw() != null){
|
||
80 | for(int dest=0;dest<((Band)bands.get(band)).getDataImageBandToDraw().length;dest++){ |
||
81 | if(dataImageBand == ((Band)bands.get(band)).getDataImageBandToDraw()[dest])
|
||
82 | bandsToRead[dataImageBand] = band; |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | return bandsToRead;
|
||
89 | } |
||
90 | |||
91 | /**
|
||
92 | * Checkea si alguna banda de la lista se est?a dibujando en el buffer de salida.
|
||
93 | * @return true si alguna banda se est? dibujando y false si no
|
||
94 | */
|
||
95 | public boolean isDrawingAnyBand(){ |
||
96 | for(int band = 0;band < bands.size();band++){ |
||
97 | if(((Band)bands.get(band)).isDrawing())
|
||
98 | return true; |
||
99 | } |
||
100 | return false; |
||
101 | } |
||
102 | |||
103 | //******************************
|
||
104 | //Setters and Getters
|
||
105 | //******************************
|
||
106 | |||
107 | /**
|
||
108 | * A?ade una banda a la lista.
|
||
109 | * @param b banda a a?adir.
|
||
110 | */
|
||
111 | public void addBand(Band b, int pos)throws BandFoundInListException{ |
||
112 | bands.add(b); |
||
113 | } |
||
114 | |||
115 | /**
|
||
116 | * A?ade la lista de bandas pasada por par?metro a la lista
|
||
117 | * actual. Si alguna banda ya existe no la a?ade y continua.
|
||
118 | * @param bl Lista de bandas
|
||
119 | */
|
||
120 | public void addBandList(BandList bl){ |
||
121 | for(int i = 0; i < bl.getBandCount(); i++){ |
||
122 | if(!findBand(bl.getBand(i)))
|
||
123 | bands.add(bl.getBand(i)); |
||
124 | } |
||
125 | } |
||
126 | |||
127 | /**
|
||
128 | * ELimina todas las bandas que tienen un nombre determinado.
|
||
129 | * @param name Nombre de las bandas a eliminar
|
||
130 | */
|
||
131 | public void removeBands(String name){ |
||
132 | for(int i = 0; i < getBandCount(); i++){ |
||
133 | Band band = getBand(i); |
||
134 | if(band.getFileName().equals(name))
|
||
135 | bands.remove(i); |
||
136 | } |
||
137 | } |
||
138 | |||
139 | /**
|
||
140 | * Resetea la asignaci?n de dibujado de las bandas de la imagen
|
||
141 | * sobre el DataImage cuando se hace un update para esta banda.
|
||
142 | */
|
||
143 | public void clearDrawableBand(){ |
||
144 | for(int i = 0; i < getBandCount(); i++) |
||
145 | ((Band)bands.get(i)).clearDrawableBands(); |
||
146 | } |
||
147 | |||
148 | /**
|
||
149 | * Para este GeoRasterFile asigna que bandas se pintaran
|
||
150 | * sobre el RasterBuf cuando se haga un update. Especificamos a
|
||
151 | * trav?s de los par?metros para que posici?n del RasterBuf ir?
|
||
152 | * dibujada con que banda del fichero de imagen.
|
||
153 | * @param posDataImage Posici?n del RasterBuf que queremos pintar.
|
||
154 | * @param imageBand Banda de la imagen que se pintar?
|
||
155 | */
|
||
156 | public void addDrawableBand(int posRasterBuf, int imageBand){ |
||
157 | try{
|
||
158 | ((Band)bands.get(imageBand)).setPositionToDrawInBuffer(posRasterBuf); |
||
159 | }catch(IndexOutOfBoundsException exc){ |
||
160 | //No hacemos nada simplemente no inserta la banda.
|
||
161 | } |
||
162 | } |
||
163 | |||
164 | /**
|
||
165 | * Obtiene el n?mero de bandas de un RasterBuf sobre las que se pintara
|
||
166 | * alguna banda de este fichero cuando se llama a un updateBuffer.
|
||
167 | * @return N?mero de bandas. Cero en caso de no tener ninguna asignada.
|
||
168 | */
|
||
169 | public int getDrawableBandsCount(){ |
||
170 | int nbands = 0; |
||
171 | for(int i = 0;i<bands.size();i++){ |
||
172 | Band b = (Band)bands.get(i); |
||
173 | if(b.getDataImageBandToDraw() != null) |
||
174 | nbands += b.getDataImageBandToDraw().length; |
||
175 | } |
||
176 | return nbands;
|
||
177 | } |
||
178 | |||
179 | /**
|
||
180 | * Obtiene la banda de la posici?n i.
|
||
181 | * @param i Posici?n de la banda a obtener.
|
||
182 | * @return Banda.
|
||
183 | */
|
||
184 | public Band getBand(int i){ |
||
185 | return (Band)bands.get(i);
|
||
186 | } |
||
187 | |||
188 | /**
|
||
189 | * Obtiene el n?mero de bandas.
|
||
190 | * @return entero con el n?mero de bandas.
|
||
191 | */
|
||
192 | public int getBandCount(){ |
||
193 | return bands.size();
|
||
194 | } |
||
195 | |||
196 | /**
|
||
197 | * A partir de un nombre de fichero y un n?mero de banda obtiene la banda o bandas del buffer de salida
|
||
198 | * donde se pinta.
|
||
199 | * @param fileName Nombre de fichero
|
||
200 | * @param band N?mero de banda de la imagen
|
||
201 | * @return banda o bandas del buffer de salida donde se dibuja.
|
||
202 | */
|
||
203 | public int[] getBufferBandToDraw(String fileName, int band){ |
||
204 | 10645 | nacho | if(fileName != null){ |
205 | for(int i = 0; i < bands.size(); i++){ |
||
206 | if(((Band)bands.get(i)).getFileName().equals(fileName))
|
||
207 | if(((Band)bands.get(i)).getPosition() == band)
|
||
208 | return ((Band)bands.get(i)).getDataImageBandToDraw();
|
||
209 | } |
||
210 | }else{
|
||
211 | for(int i = 0; i < bands.size(); i++){ |
||
212 | 8026 | nacho | if(((Band)bands.get(i)).getPosition() == band)
|
213 | return ((Band)bands.get(i)).getDataImageBandToDraw();
|
||
214 | 10645 | nacho | } |
215 | 8026 | nacho | } |
216 | int[] r = {-1}; |
||
217 | return r;
|
||
218 | } |
||
219 | /**
|
||
220 | * Obtiene en un array de String la lista de nombres de ficheros
|
||
221 | * @return lista de nombres de los ficheros del GeoRasterMultiFile
|
||
222 | */
|
||
223 | public String[] getBandStringList(){ |
||
224 | String[] list = new String[bands.size()]; |
||
225 | for(int i = 0; i < bands.size(); i++) |
||
226 | list[i] = ((Band)bands.get(i)).getFileName(); |
||
227 | return list;
|
||
228 | } |
||
229 | |||
230 | /**
|
||
231 | * Obtiene en un array de enteros con la lista de la posici?n de bandas
|
||
232 | * @return lista de la posici?n de bandas
|
||
233 | */
|
||
234 | public int[] getBandPositionList(){ |
||
235 | int[] list = new int[bands.size()]; |
||
236 | for(int i = 0; i < bands.size(); i++) |
||
237 | list[i] = ((Band)bands.get(i)).getPosition(); |
||
238 | return list;
|
||
239 | } |
||
240 | |||
241 | /**
|
||
242 | * Obtiene el tipo de dato de las bandas. Esta llamada supone que todos los tipos de dato
|
||
243 | * de las bandas son igual por lo que devolver? el primero.
|
||
244 | * @return Entero que representa el tipo de datos de las bandas
|
||
245 | */
|
||
246 | public int getBandsDataType(){ |
||
247 | if(bands.size() <= 0) |
||
248 | return RasterBuf.TYPE_UNDEFINED;
|
||
249 | return ((Band)bands.get(0)).getDataType(); |
||
250 | } |
||
251 | |||
252 | } |