root / branches / v2_0_0_prep / extensions / extRemoteSensing / src / org / gvsig / remotesensing / scatterplot / chart / ScatterPlotProcess.java @ 29641
History | View | Annotate | Download (5.15 KB)
1 |
package org.gvsig.remotesensing.scatterplot.chart; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
|
5 |
import org.gvsig.andami.PluginServices; |
6 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
7 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
8 |
import org.gvsig.raster.RasterProcess; |
9 |
import org.gvsig.raster.buffer.BufferFactory; |
10 |
import org.gvsig.raster.buffer.RasterBuffer; |
11 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
12 |
import org.gvsig.raster.dataset.IBuffer; |
13 |
import org.gvsig.raster.dataset.IRasterDataSource; |
14 |
import org.gvsig.raster.grid.Grid; |
15 |
import org.jfree.chart.JFreeChart; |
16 |
import org.jfree.chart.axis.NumberAxis; |
17 |
|
18 |
|
19 |
public class ScatterPlotProcess extends RasterProcess { |
20 |
|
21 |
private static final long serialVersionUID = 1L; |
22 |
private JFreeChart chart = null; |
23 |
private ScatterPlotChart plot = null; |
24 |
private int bandaX = 0; |
25 |
private int bandaY = 1; |
26 |
private Grid grid = null; |
27 |
private float data[][] = null; |
28 |
private FLayer fLayer = null; |
29 |
private int percent = 0; |
30 |
private Color colorExternal = null; |
31 |
private Color colorBackground = null; |
32 |
private Color colorChart = null; |
33 |
|
34 |
public void init() { |
35 |
fLayer = (FLayer)getParam("layer");
|
36 |
colorBackground = (Color) getParam("backgroundColor"); |
37 |
colorExternal = (Color) getParam("externalColor"); |
38 |
colorChart = (Color) getParam("chartColor"); |
39 |
bandaX = getIntParam("bandX");
|
40 |
bandaY = getIntParam("bandY");
|
41 |
percent = 0;
|
42 |
} |
43 |
|
44 |
public void process() throws InterruptedException { |
45 |
createChart(colorChart, colorBackground, colorExternal); |
46 |
if (externalActions != null) |
47 |
externalActions.end(chart); |
48 |
} |
49 |
|
50 |
public int getPercent() { |
51 |
return percent;
|
52 |
} |
53 |
|
54 |
public String getTitle() { |
55 |
return PluginServices.getText(this, "generando_scatterplot"); |
56 |
} |
57 |
|
58 |
public Object getResult() { |
59 |
return chart;
|
60 |
} |
61 |
|
62 |
/**
|
63 |
* Metodo que construye el grafico inicialmente. Antes de construirlo, llama a
|
64 |
* setDataChart() para cargar los datos a representar
|
65 |
*
|
66 |
* */
|
67 |
private void createChart(Color colorChart, Color colorBackground, Color colorExternal) { |
68 |
|
69 |
NumberAxis domainAxis = new NumberAxis(PluginServices.getText(this,"banda")+" "+(bandaX+1)); |
70 |
domainAxis.setAutoRangeIncludesZero(false);
|
71 |
NumberAxis rangeAxis = new NumberAxis(PluginServices.getText(this,"banda")+" "+(bandaY+1)); |
72 |
rangeAxis.setAutoRangeIncludesZero(false);
|
73 |
|
74 |
// Se cargan los datos antes de construir el grafico
|
75 |
setDataChart(); |
76 |
plot = new ScatterPlotChart(this.data, domainAxis, rangeAxis); |
77 |
chart = new JFreeChart(PluginServices.getText(this,"diagrama_dispersion"), plot); |
78 |
data= null;
|
79 |
chart.getRenderingHints().clear(); |
80 |
chart.setBackgroundPaint(colorExternal); |
81 |
plot.setPaint(colorChart); |
82 |
plot.setBackgroundPaint(colorBackground); |
83 |
} |
84 |
|
85 |
|
86 |
/**
|
87 |
* Metodo que establece los datos a representar.
|
88 |
* El vector data[][] se rellena con los valores de cada punto para las bandas
|
89 |
* bandX y bandY.
|
90 |
* */
|
91 |
public void setDataChart(){ |
92 |
|
93 |
FLyrRasterSE rasterLayer = (FLyrRasterSE) fLayer; |
94 |
|
95 |
IRasterDataSource dsetCopy = null;
|
96 |
dsetCopy = rasterLayer.getDataSource().newDataset(); |
97 |
BufferFactory bufferFactory = new BufferFactory(dsetCopy);
|
98 |
if (!RasterBuffer.loadInMemory(dsetCopy))
|
99 |
bufferFactory.setReadOnly(true);
|
100 |
|
101 |
// grid renderizado
|
102 |
grid=rasterLayer.getRender().getGrid(); |
103 |
Grid dataGrid= null;
|
104 |
try {
|
105 |
dataGrid= new Grid(bufferFactory,new int[]{bandaX,bandaY}); |
106 |
} catch (RasterBufferInvalidException e) {
|
107 |
e.printStackTrace(); |
108 |
} |
109 |
int width= grid.getRasterBuf().getWidth();
|
110 |
int height= grid.getRasterBuf().getHeight();
|
111 |
int indice=0; |
112 |
|
113 |
data= new float[2][width*height]; |
114 |
|
115 |
if (dataGrid.getDataType()== IBuffer.TYPE_BYTE){
|
116 |
for(int j=0; j<height; j++){ |
117 |
for(int i=0; i<width;i++){ |
118 |
data[0][indice]= dataGrid.getRasterBuf().getElemByte(j, i, 0) & 0xff; |
119 |
data[1][indice]= dataGrid.getRasterBuf().getElemByte(j, i, 1) & 0xff; |
120 |
indice++; |
121 |
} |
122 |
percent = j * 100 /height;
|
123 |
} |
124 |
} |
125 |
|
126 |
if (dataGrid.getDataType()== IBuffer.TYPE_SHORT){
|
127 |
for(int j=0; j<height; j++){ |
128 |
for(int i=0; i<width;i++){ |
129 |
data[0][indice]= dataGrid.getRasterBuf().getElemShort(j, i, 0); |
130 |
data[1][indice]= dataGrid.getRasterBuf().getElemShort(j, i, 1); |
131 |
indice++; |
132 |
} |
133 |
percent = j * 100 /height;
|
134 |
} |
135 |
} |
136 |
|
137 |
if (dataGrid.getDataType()== IBuffer.TYPE_INT){
|
138 |
for(int j=0; j<height; j++){ |
139 |
for(int i=0; i<width;i++){ |
140 |
data[0][indice]= dataGrid.getRasterBuf().getElemInt(j, i, 0); |
141 |
data[1][indice]= dataGrid.getRasterBuf().getElemInt(j, i, 1); |
142 |
indice++; |
143 |
} |
144 |
percent = j * 100 /height;
|
145 |
} |
146 |
} |
147 |
|
148 |
if (dataGrid.getDataType()== IBuffer.TYPE_FLOAT){
|
149 |
for(int j=0; j<height; j++){ |
150 |
for(int i=0; i<width;i++){ |
151 |
data[0][indice]= dataGrid.getRasterBuf().getElemFloat(j, i, 0); |
152 |
data[1][indice]= dataGrid.getRasterBuf().getElemFloat(j, i, 1); |
153 |
indice++; |
154 |
} |
155 |
percent = j * 100 /height;
|
156 |
} |
157 |
} |
158 |
// OJO AL CASTINTG DE DOUBLE A FLOAT
|
159 |
if (dataGrid.getDataType()== IBuffer.TYPE_DOUBLE){
|
160 |
for(int j=0; j<height; j++){ |
161 |
for(int i=0; i<width;i++){ |
162 |
data[0][indice]= (float)dataGrid.getRasterBuf().getElemDouble(j, i, 0); |
163 |
data[1][indice]= (float)dataGrid.getRasterBuf().getElemDouble(j, i, 1); |
164 |
indice++; |
165 |
} |
166 |
percent = j * 100 /height;
|
167 |
} |
168 |
} |
169 |
|
170 |
} |
171 |
} |