svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / properties / DatasetColorInterpretation.java @ 21623
History | View | Annotate | Download (6.64 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.raster.dataset.properties; |
20 |
|
21 |
import java.io.IOException; |
22 |
import java.util.ArrayList; |
23 |
|
24 |
import org.gvsig.raster.dataset.io.rmf.RmfBlocksManager; |
25 |
import org.gvsig.raster.dataset.serializer.ColorInterpretationRmfSerializer; |
26 |
/**
|
27 |
* Clase que contiene la interpretaci?n de color por banda. Inicialmente
|
28 |
* es inicializada con los valores contenidos en el raster si los tiene. Despu?s
|
29 |
* estos valores pueden ser modificados.
|
30 |
*
|
31 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
32 |
*/
|
33 |
public class DatasetColorInterpretation { |
34 |
// Identificadores de color interpretation
|
35 |
public static final String RED_BAND = "Red"; |
36 |
public static final String GREEN_BAND = "Green"; |
37 |
public static final String BLUE_BAND = "Blue"; |
38 |
public static final String ALPHA_BAND = "Alpha"; |
39 |
public static final String GRAY_BAND = "Gray"; |
40 |
public static final String PAL_BAND = "Palette"; |
41 |
public static final String UNDEF_BAND = "Undefined"; |
42 |
|
43 |
/**
|
44 |
* Interpretaci?n de color para cada banda
|
45 |
*/
|
46 |
private String[] colorInterpretation = null; |
47 |
/**
|
48 |
* true si la imagen tiene una banda con el identificador de interpretaci?n de
|
49 |
* color a Alpha
|
50 |
*/
|
51 |
private boolean isAlphaBand = false; |
52 |
|
53 |
/**
|
54 |
* Constructor vacio.
|
55 |
*/
|
56 |
public DatasetColorInterpretation() {
|
57 |
this.colorInterpretation = new String[0]; |
58 |
} |
59 |
|
60 |
/**
|
61 |
* Constructor que asigna los valores de interpretaci?n de color
|
62 |
*/
|
63 |
public DatasetColorInterpretation(String[] colorInterp) { |
64 |
this.colorInterpretation = colorInterp;
|
65 |
} |
66 |
|
67 |
/**
|
68 |
* Constructor que inicializa el n?mero de valores de la interpretaci?n de
|
69 |
* color. Implica asignar posteriormente los valores a las bandas.
|
70 |
*/
|
71 |
public DatasetColorInterpretation(int values) { |
72 |
colorInterpretation = new String[values]; |
73 |
} |
74 |
|
75 |
/**
|
76 |
* Inicializa el vector de cadenas que contendr?n el nombre de la interpretaci?n
|
77 |
* de color asignada a cada banda. Este valor es el devuelto por la imagen.
|
78 |
* @param values N?mero de valores
|
79 |
*/
|
80 |
public void initColorInterpretation(int values){ |
81 |
colorInterpretation = new String[values]; |
82 |
} |
83 |
|
84 |
/**
|
85 |
* Obtiene los valores de la interpretaci?n de color
|
86 |
* @return String[]
|
87 |
*/
|
88 |
public String[] getValues() { |
89 |
return colorInterpretation;
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* Asigna los valores de la interpretaci?n de color
|
94 |
* @return String[]
|
95 |
*/
|
96 |
public void setValues(String[] colorInterp) { |
97 |
colorInterpretation = colorInterp; |
98 |
} |
99 |
|
100 |
/**
|
101 |
* Asigna un valor para la interpretaci?n de color de una banda
|
102 |
* @param band Banda
|
103 |
* @param value valor
|
104 |
*/
|
105 |
public void setColorInterpValue(int band, String value){ |
106 |
try{
|
107 |
colorInterpretation[band] = value; |
108 |
if(value.equals("Alpha")) |
109 |
isAlphaBand = true;
|
110 |
}catch(ArrayIndexOutOfBoundsException ex){ |
111 |
//No asignamos el elemento
|
112 |
} |
113 |
} |
114 |
|
115 |
/**
|
116 |
* Obtiene la posici?n de la banda que contiene el identificador pasado por par?metro
|
117 |
* o -1 si no tiene dicho identificador.
|
118 |
* @return Posici?n de la banda que contiene el identificador o -1 si no lo tiene.
|
119 |
*/
|
120 |
public int getBand(String id){ |
121 |
if(colorInterpretation != null){ |
122 |
for(int i = 0; i < colorInterpretation.length; i++) |
123 |
if(colorInterpretation[i].equals(id))
|
124 |
return i;
|
125 |
} |
126 |
return -1; |
127 |
} |
128 |
|
129 |
/**
|
130 |
* Obtiene la posici?n de las bandas que contienen el identificador pasado por par?metro
|
131 |
* o null si no tiene dicho identificador.
|
132 |
* @return Lista con las posiciones de las bandas que contienen el identificador o null si no lo tiene.
|
133 |
*/
|
134 |
public int[] getBands(String id){ |
135 |
if(colorInterpretation != null){ |
136 |
ArrayList array = new ArrayList(); |
137 |
for(int i = 0; i < colorInterpretation.length; i++) |
138 |
if(colorInterpretation[i].equals(id))
|
139 |
array.add(new Integer(i)); |
140 |
int[] list = new int[array.size()]; |
141 |
for (int i = 0; i < list.length; i++) |
142 |
list[i] = ((Integer)array.get(i)).intValue();
|
143 |
return list;
|
144 |
} |
145 |
return null; |
146 |
} |
147 |
|
148 |
/**
|
149 |
* Obtiene true si existe una banda de alpha
|
150 |
* @return
|
151 |
*/
|
152 |
public boolean isAlphaBand() { |
153 |
return isAlphaBand;
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* Obtiene el n?mero de entradas de interpretaci?n de color por
|
158 |
* banda en la lista.
|
159 |
* @return
|
160 |
*/
|
161 |
public int length(){ |
162 |
return colorInterpretation.length;
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* Obtiene el valor de interpretaci?n de color de la entrada i.
|
167 |
* @param i N?mero de entrada
|
168 |
* @return interpretaci?n de color para la entrada solicitada
|
169 |
*/
|
170 |
public String get(int i){ |
171 |
if (i >= colorInterpretation.length)
|
172 |
return null; |
173 |
return colorInterpretation[i];
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* A?ade un objeto DatasetColorInterpretation al actual. El resultado es la suma
|
178 |
* de ambos.
|
179 |
* @param ci
|
180 |
*/
|
181 |
public void addColorInterpretation(DatasetColorInterpretation ci) { |
182 |
String[] newCI = new String[colorInterpretation.length + ci.length()]; |
183 |
for (int i = 0; i < colorInterpretation.length; i++) |
184 |
newCI[i] = colorInterpretation[i]; |
185 |
for (int i = 0; i < ci.length(); i++) { |
186 |
newCI[colorInterpretation.length + i] = ci.get(i); |
187 |
if(newCI[colorInterpretation.length + i].equals("Alpha")) |
188 |
isAlphaBand = true;
|
189 |
} |
190 |
this.colorInterpretation = newCI;
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* Consulta si la interpretaci?n de color est? por definir en la imagen.
|
195 |
* @return true si no hay interpretaci?n de color definida y false si la hay
|
196 |
*/
|
197 |
public boolean isUndefined() { |
198 |
for (int i = 0; i < colorInterpretation.length; i++) { |
199 |
if (colorInterpretation[i] != null) { |
200 |
if (!colorInterpretation[i].equals(UNDEF_BAND) &&
|
201 |
!colorInterpretation[i].equals(ALPHA_BAND)) |
202 |
return false; |
203 |
} |
204 |
} |
205 |
return true; |
206 |
} |
207 |
|
208 |
/**
|
209 |
* Salva el objeto a un fichero RMf especificado en el par?metro.
|
210 |
* @param file Nombre de fichero.
|
211 |
* @throws IOException Problemas en la escritura del fichero
|
212 |
*/
|
213 |
public void saveToRMF(String file) throws IOException { |
214 |
RmfBlocksManager manager = new RmfBlocksManager(file);
|
215 |
ColorInterpretationRmfSerializer ser = new ColorInterpretationRmfSerializer(this); |
216 |
manager.addClient(ser); |
217 |
manager.write(); |
218 |
} |
219 |
} |