Revision 18040 trunk/libraries/libRaster/src/org/gvsig/raster/dataset/properties/DatasetColorInterpretation.java
DatasetColorInterpretation.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package org.gvsig.raster.dataset.properties; |
20 | 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 |
|
|
21 | 27 |
/** |
22 | 28 |
* Clase que contiene la interpretaci?n de color por banda. Inicialmente |
23 | 29 |
* es inicializada con los valores contenidos en el raster si los tiene. Despu?s |
... | ... | |
44 | 50 |
*/ |
45 | 51 |
private boolean isAlphaBand = false; |
46 | 52 |
|
53 |
/** |
|
54 |
* Constructor vacio. |
|
55 |
*/ |
|
56 |
public DatasetColorInterpretation(){} |
|
47 | 57 |
|
48 |
public DatasetColorInterpretation(){ |
|
49 |
|
|
58 |
/** |
|
59 |
* Constructor que asigna los valores de interpretaci?n de color |
|
60 |
*/ |
|
61 |
public DatasetColorInterpretation(String[] colorInterp) { |
|
62 |
this.colorInterpretation = colorInterp; |
|
50 | 63 |
} |
51 | 64 |
|
52 | 65 |
/** |
66 |
* Constructor que inicializa el n?mero de valores de la interpretaci?n de |
|
67 |
* color. Implica asignar posteriormente los valores a las bandas. |
|
68 |
*/ |
|
69 |
public DatasetColorInterpretation(int values) { |
|
70 |
colorInterpretation = new String[values]; |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
53 | 74 |
* Inicializa el vector de cadenas que contendr?n el nombre de la interpretaci?n |
54 | 75 |
* de color asignada a cada banda. Este valor es el devuelto por la imagen. |
55 | 76 |
* @param values N?mero de valores |
... | ... | |
59 | 80 |
} |
60 | 81 |
|
61 | 82 |
/** |
83 |
* Obtiene los valores de la interpretaci?n de color |
|
84 |
* @return String[] |
|
85 |
*/ |
|
86 |
public String[] getValues() { |
|
87 |
return colorInterpretation; |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* Asigna los valores de la interpretaci?n de color |
|
92 |
* @return String[] |
|
93 |
*/ |
|
94 |
public void setValues(String[] colorInterp) { |
|
95 |
colorInterpretation = colorInterp; |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
62 | 99 |
* Asigna un valor para la interpretaci?n de color de una banda |
63 | 100 |
* @param band Banda |
64 | 101 |
* @param value valor |
... | ... | |
86 | 123 |
} |
87 | 124 |
return -1; |
88 | 125 |
} |
126 |
|
|
127 |
/** |
|
128 |
* Obtiene la posici?n de las bandas que contienen el identificador pasado por par?metro |
|
129 |
* o null si no tiene dicho identificador. |
|
130 |
* @return Lista con las posiciones de las bandas que contienen el identificador o null si no lo tiene. |
|
131 |
*/ |
|
132 |
public int[] getBands(String id){ |
|
133 |
if(colorInterpretation != null){ |
|
134 |
ArrayList array = new ArrayList(); |
|
135 |
for(int i = 0; i < colorInterpretation.length; i++) |
|
136 |
if(colorInterpretation[i].equals(id)) |
|
137 |
array.add(new Integer(i)); |
|
138 |
int[] list = new int[array.size()]; |
|
139 |
for (int i = 0; i < list.length; i++) |
|
140 |
list[i] = ((Integer)array.get(i)).intValue(); |
|
141 |
return list; |
|
142 |
} |
|
143 |
return null; |
|
144 |
} |
|
89 | 145 |
|
90 | 146 |
/** |
91 | 147 |
* Obtiene true si existe una banda de alpha |
... | ... | |
112 | 168 |
public String get(int i){ |
113 | 169 |
return colorInterpretation[i]; |
114 | 170 |
} |
171 |
|
|
172 |
/** |
|
173 |
* A?ade un objeto DatasetColorInterpretation al actual. El resultado es la suma |
|
174 |
* de ambos. |
|
175 |
* @param ci |
|
176 |
*/ |
|
177 |
public void addColorInterpretation(DatasetColorInterpretation ci) { |
|
178 |
int lenght = colorInterpretation.length + ci.length(); |
|
179 |
String[] newCI = new String[lenght]; |
|
180 |
for (int i = 0; i < colorInterpretation.length; i++) |
|
181 |
newCI[i] = colorInterpretation[i]; |
|
182 |
int pos = colorInterpretation.length; |
|
183 |
for (int i = 0; i < ci.length(); i++) { |
|
184 |
newCI[pos] = ci.get(i); |
|
185 |
pos ++; |
|
186 |
} |
|
187 |
this.colorInterpretation = newCI; |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* Salva el objeto a un fichero RMf especificado en el par?metro. |
|
192 |
* @param file Nombre de fichero. |
|
193 |
* @throws IOException Problemas en la escritura del fichero |
|
194 |
*/ |
|
195 |
public void saveToRMF(String file) throws IOException { |
|
196 |
RmfBlocksManager manager = new RmfBlocksManager(file); |
|
197 |
ColorInterpretationRmfSerializer ser = new ColorInterpretationRmfSerializer(this); |
|
198 |
manager.addClient(ser); |
|
199 |
manager.write(); |
|
200 |
} |
|
115 | 201 |
} |
Also available in: Unified diff