Statistics
| Revision:

root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / scatterplot / listener / RoiFromChartProcess.java @ 17634

History | View | Annotate | Download (6.32 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.listener;
42

    
43
import java.util.ArrayList;
44
import java.util.Iterator;
45

    
46
import org.gvsig.fmap.raster.grid.roi.VectorialROI;
47
import org.gvsig.raster.buffer.RasterBuffer;
48
import org.gvsig.raster.dataset.IBuffer;
49
import org.gvsig.raster.grid.Grid;
50
import org.gvsig.raster.grid.roi.ROI;
51
import org.gvsig.remotesensing.scatterplot.chart.ROIChart;
52
import org.jfree.data.Range;
53

    
54
import com.iver.andami.PluginServices;
55
import com.iver.cit.gvsig.fmap.MapControl;
56
import com.iver.cit.gvsig.fmap.core.FShape;
57
import com.iver.cit.gvsig.fmap.core.IGeometry;
58
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
59
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
60
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol;
61
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
62
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
63
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
64
import com.iver.cit.gvsig.project.documents.view.gui.View;
65

    
66
/**
67
 * Clase que implementa el proceso de construcci?n de una roi a partir de una 
68
 * ROIChart definida en el gr?fico de dispersion.
69
 * 
70
 * @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)  
71
 * @version 11/12/2007
72
 */
73
public class RoiFromChartProcess {
74

    
75
        private Grid grid=null;
76
        private ROIChart roiToExport= null;
77
        
78
        
79
        /**
80
         *  Constructor
81
         *  @param roiToExport roiChart  que va a ser a exportar
82
         *  @grid        grid asociado (unicamente dispone de las dos bandas seleccionadas en el grafico)
83
         *  
84
         **/
85
        
86
        public RoiFromChartProcess(ROIChart roiToExport, Grid grid){
87
                this.roiToExport= roiToExport;
88
                this.grid= grid;
89
        }
90
        
91
        /**
92
         *  Metodo que construye la ROI Vectorial a?adiendo un punto por
93
         *  cada pixel que se encuentra en el conjunto de rangos especificados.
94
         *  
95
         *  @return roi vectorial creada
96
         * */
97
        public ROI createVectorialRoi(){
98
                
99
                VectorialROI newRoi = new VectorialROI(grid);
100
                newRoi.setColor(roiToExport.getColor());
101
                newRoi.setName(roiToExport.getName());
102
                
103
                double valorBandX= 0;
104
                double valorBandY=0;
105
                Range rango[] = null;
106
                int nX = grid.getNX();
107
                int nY = grid.getNY();
108
                IBuffer buffer = grid.getRasterBuf();
109
                ArrayList rangos= roiToExport.getRanges();
110
                double mapX=0;
111
                double mapY=0;
112
                
113
//                 Caso de buffer tipo BYTE
114
                if(buffer.getDataType() == RasterBuffer.TYPE_BYTE)
115
                {
116
                                for (int j=0; j<nY; j++){
117
                                        for(int i=0; i<nX; i++)
118
                                        {
119
                                                valorBandX= buffer.getElemByte(j,i,0)&0xff;
120
                                                valorBandY=        buffer.getElemByte(j,i,1)&0xff;
121
                                                 
122
                                                Iterator iterator =rangos.iterator();
123
                                                while(iterator.hasNext()){
124
                                                        rango=(Range[]) iterator.next();
125
                                                        if(isInside(valorBandX,rango[0]) && isInside(valorBandY,rango[1])){                                         
126
                                                                 mapX = grid.getGridExtent().getMin().getX()+i*grid.getCellSize();
127
                                                                 mapY = grid.getGridExtent().getMax().getY()-j*grid.getCellSize();
128
                                                                IGeometry geometry = ShapeFactory.createPoint2D(mapX,mapY);
129
                                                                newRoi.addGeometry(geometry); // Geometria                                                
130
                                                        }
131
                                                }
132
                                        }
133
                                }
134
                }
135
                
136
                // Caso de buffer tipo SHORT
137
                if(buffer.getDataType() == RasterBuffer.TYPE_SHORT)
138
                {
139
                                for (int j=0; j<nY; j++){
140
                                        for(int i=0; i<nX; i++)                        
141
                                        {
142
                                                valorBandX= buffer.getElemShort(j,i,0);
143
                                                valorBandY=        buffer.getElemShort(j,i,1);
144
                                                 
145
                                                Iterator iterator =rangos.iterator();
146
                                                while(iterator.hasNext()){
147
                                                        rango=(Range[]) iterator.next();
148
                                                        if(isInside(valorBandX,rango[0]) && isInside(valorBandY,rango[1])){                                         
149
                                                                 mapX = grid.getGridExtent().getMin().getX()+i*grid.getCellSize();
150
                                                                 mapY = grid.getGridExtent().getMax().getY()-j*grid.getCellSize();
151
                                                                IGeometry geometry = ShapeFactory.createPoint2D(mapX,mapY);
152
                                                                newRoi.addGeometry(geometry);
153
                                                        }
154
                                                }
155
                                        }
156
                                }
157
                }
158
                
159
                drawRoi(newRoi);
160
                return newRoi;
161
        }
162
        
163
        
164
        
165
        public ROI createRasterRoi(){
166
                // creaccion de la roiRaster
167
                return null;
168
        }
169
        
170
        
171
        
172
        /***
173
         *  Metodo que determina si el valor pasado esta dentro del intervalo
174
         *  definido en rango.
175
         * @param valor valor a comprobar
176
         * @rango rango intervalo de tipo double
177
         * 
178
         */
179
        public boolean isInside(double valor, Range rango){
180
                
181
                double minValue= rango.getLowerBound();
182
                double maxValue= rango.getUpperBound();
183
                if( ( minValue< valor) && (maxValue>valor)) 
184
                        return true;
185
                else
186
                        return false;
187
                
188
        }
189
        
190
        
191
        /**
192
         * Dibujado de la roi
193
         * */        
194
        void drawRoi(VectorialROI roi){
195
                
196
                VectorialROI vectorialROI = (VectorialROI) roi;
197
                ISymbol symbol = null;
198
                FGraphic fGraphic = null;
199
                View view = (View) PluginServices.getMDIManager().getActiveWindow();
200
                MapControl mapControl = view.getMapControl();
201
                GraphicLayer graphicLayer =mapControl.getMapContext().getGraphicsLayer();
202
        
203
                for (Iterator iterator = vectorialROI.getGeometries()
204
                                .iterator(); iterator.hasNext();) {
205
                        IGeometry geometry = (IGeometry) iterator.next();
206
                        switch (geometry.getGeometryType()) {
207
                        case FShape.POINT:
208
                                symbol = SymbologyFactory.createDefaultMarkerSymbol();
209
                                ((IMarkerSymbol) symbol).setColor(roi.getColor());
210
                                break;
211
                        }
212
                        fGraphic = new FGraphic(geometry, graphicLayer.addSymbol(symbol));
213
                        graphicLayer.addGraphic(fGraphic);
214
                        //tablePanel.getRoiGraphics(roi.getName()).add(fGraphic);
215
                        mapControl.drawGraphics();
216
                
217
                }
218
                
219
        }
220
                
221
}