Revision 17622

View differences:

trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/scatterplot/listener/ManagerROIChartPanelListener.java
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

  
1 41
package org.gvsig.remotesensing.scatterplot.listener;
2 42

  
3 43
import java.awt.Color;
4 44
import java.awt.event.ActionEvent;
5 45
import java.awt.event.ActionListener;
6 46
import java.util.ArrayList;
7
import java.util.Iterator;
8 47

  
9 48
import javax.swing.event.ListSelectionEvent;
10 49
import javax.swing.event.ListSelectionListener;
......
12 51
import javax.swing.event.TableModelListener;
13 52
import javax.swing.table.DefaultTableModel;
14 53

  
15
import org.gvsig.fmap.raster.grid.roi.VectorialROI;
54
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
16 55
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
17 56
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
18 57
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
19
import org.gvsig.raster.buffer.RasterBuffer;
20
import org.gvsig.raster.dataset.IBuffer;
21
import org.gvsig.raster.grid.Grid;
58
import org.gvsig.raster.grid.roi.ROI;
22 59
import org.gvsig.remotesensing.scatterplot.chart.ROIChart;
23 60
import org.gvsig.remotesensing.scatterplot.gui.ManagerROIChartPanel;
24
import org.jfree.data.Range;
25 61

  
26
import com.iver.andami.PluginServices;
27
import com.iver.cit.gvsig.fmap.MapControl;
28
import com.iver.cit.gvsig.fmap.core.FShape;
29
import com.iver.cit.gvsig.fmap.core.IGeometry;
30
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
31 62
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
32
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol;
33 63
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
34
import com.iver.cit.gvsig.fmap.layers.FLayer;
35 64
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
36 65
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
37
import com.iver.cit.gvsig.project.documents.view.gui.View;
38 66

  
39 67

  
40 68
/**
......
48 76
		
49 77
		private ManagerROIChartPanel tablePanel = null;
50 78
		private String 		   roiSelectedName = "";
51
		private ROIChart activeRoi = null;
52
		private FLayer layer= null;
53 79
	
80
	
81
		/**
82
		 * Constructor
83
		 * */
54 84
		public ManagerROIChartPanelListener(ManagerROIChartPanel tablePanel) {
55 85
			this.tablePanel = tablePanel;
56
			activeRoi = tablePanel.getDiagram().getActiveRoiChart();
57
			layer= tablePanel.getFLayer();
58 86
		}
59 87
		
60 88

  
61 89
		public void actionPerformed(ActionEvent e) {
62 90
			
63 91
			if (e.getSource() == tablePanel.getExportButton()){
64
				
65
				
66
				// EXTRAER DE AQUI. PROVISIONAL
67
				
68
				// ACCIONES PARA EXPORTAR LA ROI ACTIVA DEL GRAFICO A LA VISTA
69 92
				ROIChart roiToExport=  tablePanel.getDiagram().getActiveRoiChart();
70
				//ArrayList rangos=roiToExport.getRanges();
71
				
72 93
				RoiFromChartProcess toRoi= new RoiFromChartProcess(roiToExport,tablePanel.getScatterPlotPanel().getGrid());
73
				toRoi.createVectorialRoi();
74
			
75
		
76
				
77
				
94
				ROI roi=toRoi.createVectorialRoi();
95
				ArrayList rois= ((FLyrRasterSE)tablePanel.getFLayer()).getRois();
96
				if(rois!= null){
97
					rois.add(roi);
98
					((FLyrRasterSE)tablePanel.getFLayer()).setRois(rois);
99
				}
100
				else{
101
					rois= new ArrayList();
102
					rois.add(roi);
103
					((FLyrRasterSE)tablePanel.getFLayer()).setRois(rois);
104
				}
78 105

  
79 106
					
80 107
					
......
88 115
						String roiName= tablePanel.getDiagram().getActiveRoiChart().getName();
89 116
						// Borrado de la roi de la lista de rois 
90 117
						tablePanel.getDiagram().getROIChartList().deleteROI(roiName);
91

  
92 118
						
93
						// Se establece la roi activa.
94
						tablePanel.getDiagram().setActiveRoi(null);
119
						if(tablePanel.getTable().getRowCount()>0){
120
							int selectedRow = 0;
121
							roiSelectedName = (String)tablePanel.getTable().getTable().getJTable().getValueAt(selectedRow,0);
122
							// Se establece la roi activa.
123
							tablePanel.getDiagram().setActiveRoi((ROIChart)tablePanel.getDiagram().getROIChartList().getListRois().get(roiSelectedName));
124
							tablePanel.getDiagram().updateUI();
125
						}
95 126
						
96
						tablePanel.loadROIs();
97
						tablePanel.updateTable();
98
						
127
						else{
128
							// Se crea una nueva ROiChar que sera la activa
129
							tablePanel.getDiagram().newRoiChart();	
130
						}
99 131
					}
132
				
100 133
				} catch (NotInitializeException e1) {
101 134
							e1.printStackTrace();
102 135
				}
......
117 150
					// Cambio en la seleccion de la tabla
118 151
					tablePanel.selectDrawRoiTool();
119 152
					int selectedRow = tablePanel.getTable().getSelectedRow();
120
					ROIChart  activeClone= tablePanel.getDiagram().getActiveRoiChart();
121 153
					roiSelectedName = (String)tablePanel.getTable().getTable().getJTable().getValueAt(selectedRow,0);
122 154
					tablePanel.getDiagram().setActiveRoi((ROIChart)tablePanel.getDiagram().getROIChartList().getListRois().get(roiSelectedName));
123 155
					tablePanel.getDiagram().updateUI();
......
146 178
					}
147 179
					tablePanel.getROI(roiName).setColor(color);
148 180
					tablePanel.getMapControl().drawGraphics();
181
					tablePanel.updateUI();
149 182
				}
150 183
			}else if(e.getColumn()==0){
151 184
				String newName = (String)tablePanel.getTable().getTable().getJTable().getValueAt(e.getFirstRow(),0);
......
155 188
	
156 189
		}
157 190
		
158
		
159
		// Metodo que pinta la roi en la vista
160
		
161
	/**
162
	 * Dibujado de la ro
163
	 * */	
164
	void drawRoi(VectorialROI roi){
165
		
166
		VectorialROI vectorialROI = (VectorialROI) roi;
167
		ISymbol symbol = null;
168
		FGraphic fGraphic = null;
169
		View view = (View) PluginServices.getMDIManager().getActiveWindow();
170
		MapControl mapControl = view.getMapControl();
171
		GraphicLayer graphicLayer =mapControl.getMapContext().getGraphicsLayer();
172 191
	
173
		for (Iterator iterator = vectorialROI.getGeometries()
174
				.iterator(); iterator.hasNext();) {
175
			IGeometry geometry = (IGeometry) iterator.next();
176
			switch (geometry.getGeometryType()) {
177
			case FShape.POINT:
178
				symbol = SymbologyFactory.createDefaultMarkerSymbol();
179
				((IMarkerSymbol) symbol).setColor(roi.getColor());
180
				break;
181
			}
182
			fGraphic = new FGraphic(geometry, graphicLayer.addSymbol(symbol));
183
			graphicLayer.addGraphic(fGraphic);
184
			//tablePanel.getRoiGraphics(roi.getName()).add(fGraphic);
185
			mapControl.drawGraphics();
186
		
187
		}
188
	
189
	}
190
	
191
	
192
	public boolean isInside(double valor, Range rango){
193
	
194
		double minValue= rango.getLowerBound();
195
		double maxValue= rango.getUpperBound();
196
		if( ( minValue< valor) && (maxValue>valor)) 
197
			return true;
198
		else
199
			return false;
200
		
201
	}
202

  
203

  
204 192
	public void actionButtonPressed(ButtonsPanelEvent e) {
205 193
		// TODO Auto-generated method stub
206 194
		
trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/scatterplot/listener/RoiFromChartProcess.java
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

  
1 41
package org.gvsig.remotesensing.scatterplot.listener;
2 42

  
3 43
import java.util.ArrayList;
......
7 47
import org.gvsig.raster.buffer.RasterBuffer;
8 48
import org.gvsig.raster.dataset.IBuffer;
9 49
import org.gvsig.raster.grid.Grid;
50
import org.gvsig.raster.grid.roi.ROI;
10 51
import org.gvsig.remotesensing.scatterplot.chart.ROIChart;
11 52
import org.jfree.data.Range;
12 53

  
......
23 64
import com.iver.cit.gvsig.project.documents.view.gui.View;
24 65

  
25 66

  
26

  
27 67
/**
28 68
 * Clase que implementa el proceso de construcci?n de una roi a partir de una 
29
 * ROi definida en el gr?fico de dispersion.
69
 * ROIChart definida en el gr?fico de dispersion.
30 70
 * 
31 71
 * @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)  
32 72
 * @version 11/12/2007
33 73
 */
34

  
35

  
36 74
public class RoiFromChartProcess {
37 75

  
38 76
	private Grid grid=null;
39 77
	private ROIChart roiToExport= null;
40 78
	
79
	
80
	/**
81
	 *  Constructor
82
	 *  @param roiToExport roiChart  que va a ser a exportar
83
	 *  @grid	grid asociado (unica mente dispone de las dos bandas seleccionadas en el grafico)
84
	 *  
85
	 **/
86
	
41 87
	public RoiFromChartProcess(ROIChart roiToExport, Grid grid){
42 88
		this.roiToExport= roiToExport;
43 89
		this.grid= grid;
44 90
	}
45 91
	
46
	
47
	public void createVectorialRoi(){
92
	/**
93
	 *  Metodo que construye la ROI Vectorial a?adiendo un punto por
94
	 *  cada pixel que se encuentra en el conjunto de rangos especificados.
95
	 *  
96
	 *  @return roi vectorial creada
97
	 * */
98
	public ROI createVectorialRoi(){
48 99
		
49
		
50 100
		VectorialROI newRoi = new VectorialROI(grid);
51 101
		newRoi.setColor(roiToExport.getColor());
102
		newRoi.setName(roiToExport.getName());
103
		
52 104
		double valorBandX= 0;
53 105
		double valorBandY=0;
54 106
		Range rango[] = null;
......
56 108
		int nY = grid.getNY();
57 109
		IBuffer buffer = grid.getRasterBuf();
58 110
		ArrayList rangos= roiToExport.getRanges();
111
		double mapX=0;
112
		double mapY=0;
59 113
		
114
//		 Caso de buffer tipo BYTE
60 115
		if(buffer.getDataType() == RasterBuffer.TYPE_BYTE)
61 116
		{
62 117
				for (int j=0; j<nY; j++){
63 118
					for(int i=0; i<nX; i++)
64
					
65 119
					{
66
						valorBandX= buffer.getElemByte(j,i,0);
67
						valorBandY=	buffer.getElemByte(j,i,1);
120
						valorBandX= buffer.getElemByte(j,i,0)&0xff;
121
						valorBandY=	buffer.getElemByte(j,i,1)&0xff;
68 122
					 	
69 123
						Iterator iterator =rangos.iterator();
70 124
						while(iterator.hasNext()){
71 125
							rango=(Range[]) iterator.next();
72 126
							if(isInside(valorBandX,rango[0]) && isInside(valorBandY,rango[1])){					 
73
								double mapX = grid.getGridExtent().getMin().getX()+i*grid.getCellSize();
74
								double mapY = grid.getGridExtent().getMax().getY()-j*grid.getCellSize();
127
								 mapX = grid.getGridExtent().getMin().getX()+i*grid.getCellSize();
128
								 mapY = grid.getGridExtent().getMax().getY()-j*grid.getCellSize();
75 129
								IGeometry geometry = ShapeFactory.createPoint2D(mapX,mapY);
76 130
								newRoi.addGeometry(geometry); // Geometria						
77 131
							}
......
80 134
				}
81 135
		}
82 136
		
137
		// Caso de buffer tipo SHORT
83 138
		if(buffer.getDataType() == RasterBuffer.TYPE_SHORT)
84 139
		{
85 140
				for (int j=0; j<nY; j++){
86
					for(int i=0; i<nX; i++)
87
					
141
					for(int i=0; i<nX; i++)			
88 142
					{
89 143
						valorBandX= buffer.getElemShort(j,i,0);
90 144
						valorBandY=	buffer.getElemShort(j,i,1);
......
93 147
						while(iterator.hasNext()){
94 148
							rango=(Range[]) iterator.next();
95 149
							if(isInside(valorBandX,rango[0]) && isInside(valorBandY,rango[1])){					 
96
								double mapX = grid.getGridExtent().getMin().getX()+i*grid.getCellSize();
97
								double mapY = grid.getGridExtent().getMax().getY()-j*grid.getCellSize();
150
								 mapX = grid.getGridExtent().getMin().getX()+i*grid.getCellSize();
151
								 mapY = grid.getGridExtent().getMax().getY()-j*grid.getCellSize();
98 152
								IGeometry geometry = ShapeFactory.createPoint2D(mapX,mapY);
99 153
								newRoi.addGeometry(geometry);
100 154
							}
......
103 157
				}
104 158
		}
105 159
		
106
		
107 160
		drawRoi(newRoi);
161
		return newRoi;
162
	}
163
	
164
	
165
	
166
	public ROI createRasterRoi(){
108 167
		
168
		// creaccion de la roiRaster
169
		return null;
109 170
	}
110 171
	
111 172
	
......
130 191
	
131 192
	
132 193
	/**
133
	 * Dibujado de la ro
194
	 * Dibujado de la roi
134 195
	 * */	
135 196
	void drawRoi(VectorialROI roi){
136 197
		
......
156 217
			mapControl.drawGraphics();
157 218
		
158 219
		}
159
	
220
		
160 221
	}
161
	
162
	
163
	
222
		
164 223
}

Also available in: Unified diff