gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / datastruct / DefaultStretch.java @ 2311
History | View | Annotate | Download (5.92 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.impl.datastruct; |
23 |
|
24 |
import org.gvsig.fmap.dal.coverage.datastruct.Stretch; |
25 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
26 |
|
27 |
public class DefaultStretch implements Stretch { |
28 |
/**
|
29 |
* Valores de los datos de entrada correspondientes al m?nimo y al m?ximo de
|
30 |
* cada tramo. Estos tendr?n un rango entre el m?nimo y el m?ximo en cada banda
|
31 |
* de la imagen.
|
32 |
*/
|
33 |
public double[] stretchIn = null; |
34 |
/**
|
35 |
* Valores de los datos de salida correspondientes al m?nimo y al m?ximo de
|
36 |
* cada tramo. Estos tendr?n un rango entre 0 y 255.
|
37 |
*/
|
38 |
public int[] stretchOut = null; |
39 |
/**
|
40 |
* Porcentajes de recorte de colas (Valores de entrada)
|
41 |
*/
|
42 |
public double tailTrimMin = 0; |
43 |
public double tailTrimMax = 0; |
44 |
/**
|
45 |
* Valores de recorte de colas (Valores de salida calculados por el filtro TailTrim)
|
46 |
*/
|
47 |
public double tailTrimValueMin = 0; |
48 |
public double tailTrimValueMax = 0; |
49 |
/**
|
50 |
* Valores de escala a calcular por el filtro lineal por tramos.
|
51 |
* Cada elemento del array es un tramo.
|
52 |
*/
|
53 |
public double[] scale = null; |
54 |
/**
|
55 |
* Valores de desplazamiento a calcular por el filtro lineal por tramos.
|
56 |
* Cada elemento del array es un tramo.
|
57 |
*/
|
58 |
public double[] offset = null; |
59 |
/**
|
60 |
* Valores m?ximos y m?nimos
|
61 |
*/
|
62 |
public double maxValue = 0; |
63 |
public double minValue = 0; |
64 |
|
65 |
/**
|
66 |
* Funcion grafica que se ha usado para generar el LinearStretchParams
|
67 |
* 0 - Lineal
|
68 |
* 1 - Exponencial / Logaritmica
|
69 |
* 2 - Raiz cuadrada / Cuadrada
|
70 |
* 3 - Level slice
|
71 |
*/
|
72 |
public int functionType = 0; |
73 |
|
74 |
/**
|
75 |
* Valor de la gr?fica para la funci?n. No se usa en una gr?fica lineal.
|
76 |
*/
|
77 |
public double valueFunction = 0.0; |
78 |
|
79 |
/**
|
80 |
* Aplica el recorte de colas sobre los extremos de los m?ximos y m?nimos de entrada.
|
81 |
* La aplicaci?n de esta funci?n considera que ya se han calculado los valores con
|
82 |
* loadTailTrimValues.
|
83 |
*/
|
84 |
public void applyTrimToStretchs() { |
85 |
if(stretchIn != null && stretchIn.length >= 2) { |
86 |
minValue = stretchIn[0] = tailTrimValueMin;
|
87 |
maxValue = stretchIn[stretchIn.length - 1] = tailTrimValueMax;
|
88 |
} |
89 |
} |
90 |
|
91 |
/**
|
92 |
* Consulta si tiene alg?n valor el recorte de colas
|
93 |
* @return true si tiene valor el recorte de colas y false si no lo tiene
|
94 |
*/
|
95 |
public boolean hasTailTrim() { |
96 |
return (tailTrimMin != 0 || tailTrimMax != 0); |
97 |
} |
98 |
|
99 |
/**
|
100 |
* Calcula la escala y el desplazamiento teniendo en cuenta que
|
101 |
* ya tenga todos los valores de entrada asignados.
|
102 |
*
|
103 |
*/
|
104 |
public void calcLinearScaleAndOffset() { |
105 |
if(stretchIn != null && stretchOut != null) { |
106 |
//simplifyStretch();
|
107 |
scale = new double[stretchIn.length - 1]; |
108 |
offset = new double[stretchIn.length - 1]; |
109 |
for (int i = 0; i < scale.length; i++) { |
110 |
double rgbRange = (stretchOut[i + 1] - stretchOut[i]); |
111 |
if((stretchIn[i + 1] - stretchIn[i]) == 0) |
112 |
scale[i] = 0;
|
113 |
else
|
114 |
scale[i] = rgbRange / (stretchIn[i + 1] - stretchIn[i]);
|
115 |
offset[i] = stretchOut[i]; |
116 |
} |
117 |
} |
118 |
} |
119 |
|
120 |
/**
|
121 |
* Asigna el m?ximo y el m?nimo
|
122 |
* @param stats
|
123 |
* @param type
|
124 |
* @param band
|
125 |
*/
|
126 |
public void setMaxMin(Statistics stats, int band, boolean rgb) { |
127 |
try {
|
128 |
if (rgb) {
|
129 |
if (stats.getMinByteUnsigned() != null) |
130 |
minValue = stats.getMinByteUnsigned()[band]; |
131 |
if (stats.getMaxByteUnsigned() != null) |
132 |
maxValue = stats.getMaxByteUnsigned()[band]; |
133 |
} else {
|
134 |
if (stats.getMin() != null) { |
135 |
minValue = stats.getMin()[band]; |
136 |
} |
137 |
if (stats.getMax() != null) { |
138 |
maxValue = stats.getMax()[band]; |
139 |
} |
140 |
} |
141 |
if (stretchIn == null) { |
142 |
stretchIn = new double[] { minValue, maxValue }; |
143 |
} else {
|
144 |
stretchIn[0] = minValue;
|
145 |
stretchIn[stretchIn.length - 1] = maxValue;
|
146 |
} |
147 |
} catch (ArrayIndexOutOfBoundsException ex) { |
148 |
// No se asigna el m?ximo o m?nimo
|
149 |
} |
150 |
} |
151 |
|
152 |
/**
|
153 |
* Aplica el eliminado de extremos. Para ello utiliza el segundo m?ximo y m?nimo de entrada.
|
154 |
*/
|
155 |
public void applyRemoveEndsToStretchs(Statistics stats, boolean rgb, int band) { |
156 |
if(stretchIn == null) |
157 |
return;
|
158 |
try {
|
159 |
if(rgb) {
|
160 |
if(stats.getSecondMinByteUnsigned() != null) |
161 |
stretchIn[0] = minValue = stats.getSecondMinByteUnsigned()[band];
|
162 |
if(stats.getSecondMaxByteUnsigned() != null) |
163 |
stretchIn[stretchIn.length - 1] = maxValue = stats.getSecondMaxByteUnsigned()[band];
|
164 |
} else {
|
165 |
if(stats.getSecondMin() != null) |
166 |
stretchIn[0] = minValue = stats.getSecondMin()[band];
|
167 |
if(stats.getMax() != null) |
168 |
stretchIn[stretchIn.length - 1] = maxValue = stats.getSecondMax()[band];
|
169 |
} |
170 |
} catch (ArrayIndexOutOfBoundsException ex) { |
171 |
//No se asigna el m?ximo o m?nimo
|
172 |
} |
173 |
} |
174 |
|
175 |
public double[] getOffset() { |
176 |
return offset;
|
177 |
} |
178 |
|
179 |
public double getMaxValue() { |
180 |
return maxValue;
|
181 |
} |
182 |
|
183 |
public double getMinValue() { |
184 |
return minValue;
|
185 |
} |
186 |
|
187 |
public int getFunctionType() { |
188 |
return functionType;
|
189 |
} |
190 |
|
191 |
public double[] getStretchIn() { |
192 |
return stretchIn;
|
193 |
} |
194 |
|
195 |
public int[] getStretchOut() { |
196 |
return stretchOut;
|
197 |
} |
198 |
|
199 |
public double getValueFunction() { |
200 |
return valueFunction;
|
201 |
} |
202 |
} |