root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / enhanced / ui / EnhancedHistogramController.java @ 19521
History | View | Annotate | Download (7.77 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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.rastertools.enhanced.ui; |
20 |
|
21 |
import org.gvsig.raster.beans.canvas.layers.GraphicHistogram; |
22 |
import org.gvsig.raster.beans.canvas.layers.functions.StraightLine; |
23 |
import org.gvsig.raster.dataset.Params; |
24 |
import org.gvsig.raster.grid.filter.enhancement.LinearStretchEnhancementFilter; |
25 |
import org.gvsig.rastertools.enhanced.graphics.HistogramGraphicBase; |
26 |
import org.gvsig.rastertools.enhanced.graphics.InputHistogram; |
27 |
import org.gvsig.rastertools.enhanced.graphics.OutputHistogram; |
28 |
import org.gvsig.rastertools.enhanced.graphics.HistogramGraphicBase.HistogramStatus; |
29 |
/**
|
30 |
* Manager para actualizar la vista previa y el histograma de salida del cuadro
|
31 |
* de realce
|
32 |
*
|
33 |
* @version 04/03/2008
|
34 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
35 |
*/
|
36 |
public class EnhancedHistogramController { |
37 |
private InputHistogram inputHistogram = null; |
38 |
private OutputHistogram outputHistogram = null; |
39 |
private EnhancedDialog enhancedDialog = null; |
40 |
|
41 |
public EnhancedHistogramController(InputHistogram inputHistogram, OutputHistogram outputHistogram, EnhancedDialog enhancedDialog) {
|
42 |
this.inputHistogram = inputHistogram;
|
43 |
this.outputHistogram = outputHistogram;
|
44 |
this.enhancedDialog = enhancedDialog;
|
45 |
} |
46 |
|
47 |
public void updatePreview() { |
48 |
Params params = new Params();
|
49 |
|
50 |
// Double min = Double.valueOf(0.0D);
|
51 |
HistogramStatus histogram = inputHistogram.getHistogramStatus(HistogramGraphicBase.GRAY); |
52 |
if (histogram != null) { |
53 |
if (histogram.getBaseFunction() instanceof StraightLine) { |
54 |
StraightLine line = (StraightLine) histogram.getBaseFunction(); |
55 |
double[] valuesIn = line.getInValues(histogram.getMin(), histogram.getMax()); |
56 |
int[] valuesOut = line.getOutValues(); |
57 |
|
58 |
params.setParam("StretchInGray", valuesIn, -1, null); |
59 |
params.setParam("StretchOutGray", valuesOut, -1, null); |
60 |
params.setParam("TailTrimGrayMin", Double.valueOf(0.0D), -1, null); |
61 |
params.setParam("TailTrimGrayMax", Double.valueOf(0.0D), -1, null); |
62 |
} |
63 |
} else {
|
64 |
histogram = inputHistogram.getHistogramStatus(HistogramGraphicBase.RED); |
65 |
if (histogram != null) { |
66 |
if (histogram.getBaseFunction() instanceof StraightLine) { |
67 |
StraightLine line = (StraightLine) histogram.getBaseFunction(); |
68 |
double[] valuesIn = line.getInValues(histogram.getMin(), histogram.getMax()); |
69 |
int[] valuesOut = line.getOutValues(); |
70 |
|
71 |
params.setParam("StretchInRed", valuesIn, -1, null); |
72 |
params.setParam("StretchOutRed", valuesOut, -1, null); |
73 |
params.setParam("TailTrimRedMin", Double.valueOf(0.0D), -1, null); |
74 |
params.setParam("TailTrimRedMax", Double.valueOf(0.0D), -1, null); |
75 |
} |
76 |
} |
77 |
histogram = inputHistogram.getHistogramStatus(HistogramGraphicBase.GREEN); |
78 |
if (histogram != null) { |
79 |
if (histogram.getBaseFunction() instanceof StraightLine) { |
80 |
StraightLine line = (StraightLine) histogram.getBaseFunction(); |
81 |
double[] valuesIn = line.getInValues(histogram.getMin(), histogram.getMax()); |
82 |
int[] valuesOut = line.getOutValues(); |
83 |
|
84 |
params.setParam("StretchInGreen", valuesIn, -1, null); |
85 |
params.setParam("StretchOutGreen", valuesOut, -1, null); |
86 |
params.setParam("TailTrimGreenMin", Double.valueOf(0.0D), -1, null); |
87 |
params.setParam("TailTrimGreenMax", Double.valueOf(0.0D), -1, null); |
88 |
} |
89 |
} |
90 |
histogram = inputHistogram.getHistogramStatus(HistogramGraphicBase.BLUE); |
91 |
if (histogram != null) { |
92 |
if (histogram.getBaseFunction() instanceof StraightLine) { |
93 |
StraightLine line = (StraightLine) histogram.getBaseFunction(); |
94 |
double[] valuesIn = line.getInValues(histogram.getMin(), histogram.getMax()); |
95 |
int[] valuesOut = line.getOutValues(); |
96 |
|
97 |
params.setParam("StretchInBlue", valuesIn, -1, null); |
98 |
params.setParam("StretchOutBlue", valuesOut, -1, null); |
99 |
params.setParam("TailTrimBlueMin", Double.valueOf(0.0D), -1, null); |
100 |
params.setParam("TailTrimBlueMax", Double.valueOf(0.0D), -1, null); |
101 |
} |
102 |
} |
103 |
} |
104 |
|
105 |
// min = Double.valueOf(0.10D);
|
106 |
// params.removeParam("TailTrimRedMin");
|
107 |
// params.removeParam("TailTrimRedMax");
|
108 |
// params.removeParam("TailTrimGreenMin");
|
109 |
// params.removeParam("TailTrimGreenMax");
|
110 |
// params.removeParam("TailTrimBlueMin");
|
111 |
// params.removeParam("TailTrimBlueMax");
|
112 |
// params.setParam("TailTrimRedMin", new Double(0.10D), -1, null);
|
113 |
// params.setParam("TailTrimRedMax", new Double(0.10D), -1, null);
|
114 |
// params.setParam("TailTrimGreenMin", new Double(0.10D), -1, null);
|
115 |
// params.setParam("TailTrimGreenMax", new Double(0.10D), -1, null);
|
116 |
// params.setParam("TailTrimBlueMin", new Double(0.10D), -1, null);
|
117 |
// params.setParam("TailTrimBlueMax", new Double(0.10D), -1, null);
|
118 |
params.setParam("RGB", new Boolean(false), -1, null); |
119 |
|
120 |
enhancedDialog.getFilteredPreview().getParamsList().clear(); |
121 |
enhancedDialog.getFilteredPreview().addNewParam("enhanced_stretch", params, LinearStretchEnhancementFilter.class);
|
122 |
|
123 |
enhancedDialog.getPreviewBasePanel().refreshPreview(); |
124 |
} |
125 |
|
126 |
/**
|
127 |
* Actualiza el histograma de salida del cuadro de realce
|
128 |
*/
|
129 |
public void updateHistogramOut() { |
130 |
HistogramStatus histogram = inputHistogram.getHistogramStatus(HistogramGraphicBase.DRAWED); |
131 |
if (histogram != null) { |
132 |
if (histogram.getBaseFunction() instanceof StraightLine) { |
133 |
StraightLine line = (StraightLine) histogram.getBaseFunction(); |
134 |
double[] valuesIn = line.getPercentInValues(); |
135 |
double[] valuesOut = line.getPercentOutValues(); |
136 |
|
137 |
double origenHistogram[] = inputHistogram.getHistogramStatus(HistogramGraphicBase.DRAWED).getHistogram(); |
138 |
double newHistogram[] = new double[origenHistogram.length]; |
139 |
|
140 |
for (int i = 0; i < newHistogram.length; i++) |
141 |
newHistogram[i] = 0.0D;
|
142 |
|
143 |
int pos;
|
144 |
double p;
|
145 |
for (int i = 0; i < origenHistogram.length; i++) { |
146 |
p = (((double) i) / (origenHistogram.length - 1.0D)); |
147 |
|
148 |
for (int j = 0; j < (valuesIn.length - 1); j++) { |
149 |
if (valuesIn[j] == valuesIn[j + 1]) continue; |
150 |
if (p >= valuesIn[j] && p <= valuesIn[j + 1]) { |
151 |
p = valuesOut[j] + ((valuesOut[j + 1] - valuesOut[j]) * ((p - valuesIn[j]) / (valuesIn[j + 1] - valuesIn[j]))); |
152 |
break;
|
153 |
} |
154 |
} |
155 |
|
156 |
pos = (int) Math.round(p * (origenHistogram.length - 1.0D)); |
157 |
if (pos < 0) |
158 |
pos = 0;
|
159 |
if (pos > (origenHistogram.length - 1)) |
160 |
pos = (origenHistogram.length - 1);
|
161 |
|
162 |
newHistogram[pos] += origenHistogram[i]; |
163 |
} |
164 |
|
165 |
HistogramStatus histogramOut = outputHistogram.getHistogramStatus(HistogramGraphicBase.DRAWED); |
166 |
histogramOut.setHistogram(newHistogram); |
167 |
histogramOut.setLimits(0.0D, 255.0D); |
168 |
histogramOut.getGraphicHistogram().setTypeViewed(GraphicHistogram.VIEW_LINEAL); |
169 |
// histogramOut.getGraphicHistogram().setTypeViewed(GraphicHistogram.VIEW_ACUMMULATED);
|
170 |
// histogramOut.getGraphicHistogram().setTypeViewed(GraphicHistogram.VIEW_LOGARITHMIC);
|
171 |
// histogramOut.getGraphicHistogram().setTypeViewed(GraphicHistogram.VIEW_ACUMMULATEDLOG);
|
172 |
outputHistogram.repaint(); |
173 |
} |
174 |
} |
175 |
} |
176 |
} |