root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / scatterplot / gui / ChartScaterPlotPanel.java @ 17616
History | View | Annotate | Download (8.63 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 Instituto de Desarrollo Regional 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.remotesensing.scatterplot.gui; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Color; |
45 |
|
46 |
import javax.swing.JPanel; |
47 |
|
48 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
49 |
import org.gvsig.raster.buffer.BufferFactory; |
50 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
51 |
import org.gvsig.raster.dataset.IBuffer; |
52 |
import org.gvsig.raster.grid.Grid; |
53 |
import org.gvsig.remotesensing.scatterplot.chart.ScatterPlotChart; |
54 |
import org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram; |
55 |
import org.jfree.chart.JFreeChart; |
56 |
import org.jfree.chart.axis.NumberAxis; |
57 |
|
58 |
import com.iver.andami.PluginServices; |
59 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
60 |
|
61 |
/**
|
62 |
* Clase que define el panel donde aparece el grafico de dispersion para dos bandas, determinadas por
|
63 |
* las variables bandaX y bandaY. El grafico es un FastScatterPlot de la libreria jfreeChart (personalizada para este
|
64 |
* apartado).
|
65 |
*
|
66 |
* @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
|
67 |
* @version 11/12/2007
|
68 |
*/
|
69 |
|
70 |
public class ChartScaterPlotPanel extends JPanel { |
71 |
|
72 |
private static final long serialVersionUID = 1L; |
73 |
private JFreeChart chart;
|
74 |
private ScatterPlotDiagram jPanelChart = null; |
75 |
private ScatterPlotChart plot = null; |
76 |
private int bandaX = 0; |
77 |
private int bandaY = 1; |
78 |
private Grid grid = null; |
79 |
private float data[][] = null; |
80 |
FLayer fLayer = null;
|
81 |
|
82 |
|
83 |
/**
|
84 |
* Constructor
|
85 |
* @param flayer capa
|
86 |
* @param band1 banda que se representa en el eje x.
|
87 |
* @param band2 banda que se representa en el eje y.
|
88 |
* */
|
89 |
public ChartScaterPlotPanel(FLayer fLayer, int band1, int band2){ |
90 |
this.fLayer= fLayer;
|
91 |
bandaX= band1; |
92 |
bandaY= band2; |
93 |
createChart(); |
94 |
initialize(); |
95 |
} |
96 |
|
97 |
|
98 |
/**
|
99 |
* Inicializacion del panel que contiene el grafico
|
100 |
* */
|
101 |
private void initialize() { |
102 |
this.setLayout(new BorderLayout()); |
103 |
this.add(getChart(), BorderLayout.CENTER); |
104 |
} |
105 |
|
106 |
|
107 |
/**
|
108 |
* @return grafico actual
|
109 |
* */
|
110 |
public ScatterPlotDiagram getChart(){
|
111 |
if(jPanelChart == null){ |
112 |
jPanelChart = new ScatterPlotDiagram(chart,getGrid());
|
113 |
chart=null;
|
114 |
jPanelChart.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
|
115 |
} |
116 |
return jPanelChart;
|
117 |
} |
118 |
|
119 |
|
120 |
|
121 |
/**
|
122 |
* Metodo que construye el grafico inicialmente. Antes de construirlo, llama a
|
123 |
* setDataChart() para cargar los datos a representar
|
124 |
*
|
125 |
* */
|
126 |
private void createChart() { |
127 |
|
128 |
NumberAxis domainAxis = new NumberAxis(PluginServices.getText(this,"banda")+" "+bandaX); |
129 |
domainAxis.setAutoRangeIncludesZero(false);
|
130 |
NumberAxis rangeAxis = new NumberAxis(PluginServices.getText(this,"banda")+" "+bandaY); |
131 |
rangeAxis.setAutoRangeIncludesZero(false);
|
132 |
|
133 |
// Se cargan los datos antes de construir el grafico
|
134 |
setDataChart(fLayer); |
135 |
plot = new ScatterPlotChart(this.data, domainAxis, rangeAxis); |
136 |
|
137 |
|
138 |
chart = new JFreeChart(PluginServices.getText(this,"diagrama_dispersion"), plot); |
139 |
data= null;
|
140 |
chart.getRenderingHints().clear(); |
141 |
|
142 |
// Image img = new ImageIcon(ScatterPlotPanel.class.getClassLoader().getResource("images/splash.png")).getImage();
|
143 |
plot.setBackgroundPaint(null);
|
144 |
plot.setBackgroundImageAlpha(0.18f);
|
145 |
// plot.setBackgroundImage(img);
|
146 |
chart.setBackgroundPaint(Color.white);
|
147 |
|
148 |
plot.setBackgroundPaint(new Color(245, 245, 245)); |
149 |
plot=null;
|
150 |
} |
151 |
|
152 |
|
153 |
/**
|
154 |
* Actualizacion del panel que contiene el grafico
|
155 |
* */
|
156 |
public void updateChartPanel(){ |
157 |
jPanelChart.setChart(chart); |
158 |
// hace un clear cuando se cambian las bandas
|
159 |
jPanelChart.getROIChartList().getListRois().clear(); |
160 |
jPanelChart.repaint(); |
161 |
updateUI(); |
162 |
|
163 |
} |
164 |
|
165 |
|
166 |
/**
|
167 |
* Actualizacion del grafico. Esta actualizacion se producira cuando haya variacion en la
|
168 |
* seleccion de las bandas por parte del usuario.
|
169 |
*
|
170 |
* */
|
171 |
public void updateChart() { |
172 |
|
173 |
NumberAxis domainAxis = new NumberAxis(PluginServices.getText(this,"banda")+bandaX); |
174 |
domainAxis.setAutoRangeIncludesZero(false);
|
175 |
NumberAxis rangeAxis = new NumberAxis(PluginServices.getText(this,"banda")+bandaY); |
176 |
rangeAxis.setAutoRangeIncludesZero(false);
|
177 |
chart=null;
|
178 |
plot=null;
|
179 |
|
180 |
// Se cargan los datos correspondiesntes a las bandas seleccionadas
|
181 |
setDataChart(fLayer); |
182 |
plot = new ScatterPlotChart(this.data, domainAxis, rangeAxis); |
183 |
|
184 |
chart = new JFreeChart(PluginServices.getText(this,"diagrama_dispersion"), plot); |
185 |
chart.getRenderingHints().clear(); |
186 |
data=null;
|
187 |
|
188 |
/* Image img = new ImageIcon(ScatterPlotPanel.class.getClassLoader().getResource("images/splash.png")).getImage();
|
189 |
//plot.setBackgroundPaint(null);
|
190 |
*/ plot.setBackgroundImageAlpha(0.18f); |
191 |
//plot.setBackgroundImage(img);
|
192 |
chart.setBackgroundPaint(Color.white);
|
193 |
|
194 |
plot.setBackgroundPaint(new Color(245, 245, 245)); |
195 |
//chart.fireChartChanged();
|
196 |
plot=null;
|
197 |
updateChartPanel(); |
198 |
|
199 |
} |
200 |
|
201 |
|
202 |
|
203 |
/**
|
204 |
* Metodo que establece los datos a representar.
|
205 |
* El vector data[][] se rellena con los valores de cada punto para las bandas
|
206 |
* bandX y bandY.
|
207 |
* */
|
208 |
public void setDataChart(FLayer fLayer){ |
209 |
|
210 |
this.fLayer = fLayer;
|
211 |
FLyrRasterSE rasterLayer = (FLyrRasterSE) fLayer; |
212 |
|
213 |
BufferFactory dataSource = rasterLayer.getBufferFactory(); |
214 |
|
215 |
int bands[] = null; |
216 |
bands = new int[rasterLayer.getBandCount()]; |
217 |
for (int i = 0; i < rasterLayer.getBandCount(); i++) |
218 |
bands[i] = i; |
219 |
try {
|
220 |
grid = new Grid(dataSource, new int[]{bandaX, bandaY}); |
221 |
} catch (RasterBufferInvalidException e) {
|
222 |
e.printStackTrace(); |
223 |
} |
224 |
|
225 |
|
226 |
int width= grid.getRasterBuf().getWidth();
|
227 |
int height= grid.getRasterBuf().getHeight();
|
228 |
int indice=0; |
229 |
|
230 |
data= new float[2][width*height]; |
231 |
|
232 |
if (grid.getDataType()== IBuffer.TYPE_BYTE){
|
233 |
for(int i=0; i<width;i++){ |
234 |
for(int j=0; j<height; j++){ |
235 |
data[0][indice]= grid.getRasterBuf().getElemByte(j,i,0)&0x0ff; |
236 |
data[1][indice]= grid.getRasterBuf().getElemByte(j,i,1)&0x0ff; |
237 |
indice++; |
238 |
} |
239 |
} |
240 |
} |
241 |
|
242 |
if (grid.getDataType()== IBuffer.TYPE_SHORT){
|
243 |
|
244 |
for(int i=0; i<width;i++){ |
245 |
for(int j=0; j<height; j++){ |
246 |
data[0][indice]= grid.getRasterBuf().getElemShort(j,i,0); |
247 |
data[1][indice]= grid.getRasterBuf().getElemShort(j,i,1); |
248 |
indice++; |
249 |
} |
250 |
} |
251 |
} |
252 |
|
253 |
if (grid.getDataType()== IBuffer.TYPE_INT){
|
254 |
|
255 |
for(int i=0; i<width;i++){ |
256 |
for(int j=0; j<height; j++){ |
257 |
data[0][indice]= grid.getRasterBuf().getElemInt(j,i,0); |
258 |
data[1][indice]= grid.getRasterBuf().getElemInt(j,i,1); |
259 |
indice++; |
260 |
} |
261 |
} |
262 |
} |
263 |
|
264 |
if (grid.getDataType()== IBuffer.TYPE_FLOAT){
|
265 |
for(int i=0; i<width;i++){ |
266 |
for(int j=0; j<height; j++){ |
267 |
data[0][indice]= grid.getRasterBuf().getElemFloat(j,i,0); |
268 |
data[1][indice]= grid.getRasterBuf().getElemFloat(j,i,1); |
269 |
indice++; |
270 |
} |
271 |
} |
272 |
} |
273 |
// OJO AL CASTINTG DE DOUBLE A FLOAT
|
274 |
if (grid.getDataType()== IBuffer.TYPE_DOUBLE){
|
275 |
for(int i=0; i<width;i++){ |
276 |
for(int j=0; j<height; j++){ |
277 |
data[0][indice]= (float)grid.getRasterBuf().getElemDouble(j,i,bandaX); |
278 |
data[1][indice]= (float)grid.getRasterBuf().getElemDouble(j,i,bandaY); |
279 |
indice++; |
280 |
} |
281 |
} |
282 |
} |
283 |
|
284 |
} |
285 |
|
286 |
|
287 |
/**
|
288 |
* Asignacion de la banda X
|
289 |
* */
|
290 |
public void setBandX(int band){ |
291 |
bandaX= band; |
292 |
} |
293 |
|
294 |
|
295 |
/**
|
296 |
* Asignacion de la banda Y
|
297 |
* */
|
298 |
public void setBandY(int band){ |
299 |
bandaY= band; |
300 |
} |
301 |
|
302 |
|
303 |
/**
|
304 |
* @return banda X
|
305 |
* */
|
306 |
public int getBandX(){ |
307 |
return bandaX;
|
308 |
} |
309 |
|
310 |
|
311 |
/**
|
312 |
* @return banda Y
|
313 |
* */
|
314 |
public int getBandY(){ |
315 |
return bandaY;
|
316 |
} |
317 |
|
318 |
|
319 |
/**
|
320 |
* @return grid asociado
|
321 |
*
|
322 |
* */
|
323 |
public Grid getGrid(){
|
324 |
return grid;
|
325 |
} |
326 |
} |
327 |
|
328 |
|