root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / enhanced / graphics / InputHistogram.java @ 19969
History | View | Annotate | Download (5.09 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.rastertools.enhanced.graphics; |
20 |
|
21 |
import java.awt.Color; |
22 |
|
23 |
import org.gvsig.raster.beans.canvas.GCanvas; |
24 |
import org.gvsig.raster.beans.canvas.layers.Border; |
25 |
import org.gvsig.raster.beans.canvas.layers.GraphicHistogram; |
26 |
import org.gvsig.raster.beans.canvas.layers.InfoLayer; |
27 |
import org.gvsig.raster.beans.canvas.layers.MinMaxLines; |
28 |
import org.gvsig.raster.beans.canvas.layers.functions.BaseFunction; |
29 |
import org.gvsig.raster.beans.canvas.layers.functions.DensitySlicingLine; |
30 |
import org.gvsig.raster.beans.canvas.layers.functions.LogaritmicExponentialLine; |
31 |
import org.gvsig.raster.beans.canvas.layers.functions.SquareRootPowLine; |
32 |
import org.gvsig.raster.beans.canvas.layers.functions.StraightLine; |
33 |
import org.gvsig.raster.datastruct.Histogram; |
34 |
import org.gvsig.rastertools.enhanced.ui.EnhancedListener; |
35 |
/**
|
36 |
* Componente con el histograma de entrada.
|
37 |
*
|
38 |
* 20/02/2008
|
39 |
* @author Nacho Brodin nachobrodin@gmail.com
|
40 |
*/
|
41 |
public class InputHistogram extends HistogramGraphicBase { |
42 |
private static final long serialVersionUID = 681848373747974757L; |
43 |
|
44 |
/**
|
45 |
* Crea una nueva instancia de InputHistogram.
|
46 |
*/
|
47 |
public InputHistogram(Histogram hist, int[] renderBands, double[] minList, double[] maxList) { |
48 |
super(hist, renderBands, minList, maxList);
|
49 |
} |
50 |
|
51 |
/*
|
52 |
* (non-Javadoc)
|
53 |
* @see org.gvsig.rastertools.enhanced.graphics.HistogramGraphicBase#getCanvas()
|
54 |
*/
|
55 |
public GCanvas getCanvas() {
|
56 |
if(canvas == null) { |
57 |
canvas = new GCanvas(Color.BLACK); |
58 |
canvas.addDrawableElement(new GraphicHistogram(Color.white)); |
59 |
canvas.addDrawableElement(new MinMaxLines(minMaxLineColor));
|
60 |
canvas.addDrawableElement(new StraightLine(functionColor));
|
61 |
canvas.addDrawableElement(new Border(borderColor)); |
62 |
canvas.addDrawableElement(new InfoLayer(Color.WHITE)); |
63 |
} |
64 |
return canvas;
|
65 |
} |
66 |
|
67 |
/**
|
68 |
* Asigna el listener para gestionar el evento de movimiento de gr?ficos
|
69 |
* @param listener
|
70 |
*/
|
71 |
public void setListener(EnhancedListener listener) { |
72 |
getCanvas().addValueChangedListener(listener); |
73 |
} |
74 |
|
75 |
/**
|
76 |
* Asigna el nivel de la funci?n si esta es density slicing.
|
77 |
* @param level
|
78 |
*/
|
79 |
public void setLevel(int level) { |
80 |
if (histogramDrawed != null) |
81 |
histogramDrawed.setLevel(level); |
82 |
getCanvas().repaint(); |
83 |
} |
84 |
|
85 |
/**
|
86 |
* Asigna el tipo de funci?n Lineal, Exponencial, logaritmica, density slicing, campana de gauss,
|
87 |
* raiz cuadrada o ecualizaci?n.
|
88 |
*
|
89 |
* @param type Tipo de histograma. El valor est? definido en las constantes de GraphicHistogram
|
90 |
*/
|
91 |
public void setFunction(int function) { |
92 |
if (histogramDrawed == null) |
93 |
return;
|
94 |
|
95 |
BaseFunction baseFunction = histogramDrawed.getBaseFunction(); |
96 |
boolean regen = false; |
97 |
switch (function) {
|
98 |
case GraphicHistogram.FUNCTION_DENSITY:
|
99 |
if (!baseFunction.getClass().equals(DensitySlicingLine.class))
|
100 |
baseFunction = new DensitySlicingLine(histogramDrawed.getBaseFunction().getColor());
|
101 |
break;
|
102 |
case GraphicHistogram.FUNCTION_LINEAL:
|
103 |
if (!baseFunction.getClass().equals(StraightLine.class))
|
104 |
baseFunction = new StraightLine(histogramDrawed.getBaseFunction().getColor());
|
105 |
break;
|
106 |
case GraphicHistogram.FUNCTION_LOGARIT:
|
107 |
regen = false;
|
108 |
if (!baseFunction.getClass().equals(LogaritmicExponentialLine.class)) {
|
109 |
regen = true;
|
110 |
} else {
|
111 |
if (!((LogaritmicExponentialLine) baseFunction).isLogaritmical())
|
112 |
regen = true;
|
113 |
} |
114 |
if (regen)
|
115 |
baseFunction = new LogaritmicExponentialLine(histogramDrawed.getBaseFunction().getColor(), 1.0); |
116 |
break;
|
117 |
case GraphicHistogram.FUNCTION_EXPONENT:
|
118 |
regen = false;
|
119 |
if (!baseFunction.getClass().equals(LogaritmicExponentialLine.class)) {
|
120 |
regen = true;
|
121 |
} else {
|
122 |
if (!((LogaritmicExponentialLine) baseFunction).isExponencial())
|
123 |
regen = true;
|
124 |
} |
125 |
if (regen)
|
126 |
baseFunction = new LogaritmicExponentialLine(histogramDrawed.getBaseFunction().getColor(), -1.0); |
127 |
break;
|
128 |
case GraphicHistogram.FUNCTION_SQUARE_ROOT:
|
129 |
if (!baseFunction.getClass().equals(SquareRootPowLine.class))
|
130 |
baseFunction = new SquareRootPowLine(histogramDrawed.getBaseFunction().getColor(), 1.0); |
131 |
break;
|
132 |
} |
133 |
|
134 |
histogramDrawed.setBaseFunction(baseFunction); |
135 |
getCanvas().replaceDrawableElement(histogramDrawed.getBaseFunction(), BaseFunction.class); |
136 |
|
137 |
// Fuerza un repintado inmediato para actualizar los valores
|
138 |
getCanvas().paint(getCanvas().getGraphics()); |
139 |
} |
140 |
} |