Revision 17622 trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/scatterplot/listener/RoiFromChartProcess.java

View differences:

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