root / branches / v2_0_0_prep / extensions / extRemoteSensing / src / org / gvsig / remotesensing / PrincipalComponentsExtension.java @ 31496
History | View | Annotate | Download (7.89 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 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 Ibez, 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 |
package org.gvsig.remotesensing; |
41 |
|
42 |
import javax.swing.Icon; |
43 |
|
44 |
import org.gvsig.andami.PluginServices; |
45 |
import org.gvsig.andami.plugins.Extension; |
46 |
import org.gvsig.app.project.documents.view.ViewDocument; |
47 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
48 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
49 |
import org.gvsig.fmap.mapcontext.MapContext; |
50 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
51 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
52 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
53 |
import org.gvsig.fmap.raster.layers.ILayerState; |
54 |
import org.gvsig.raster.gui.IGenericToolBarMenuItem; |
55 |
import org.gvsig.remotesensing.principalcomponents.gui.PrincipalComponentPanel; |
56 |
import org.gvsig.tools.ToolsLocator; |
57 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
58 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
59 |
|
60 |
/**
|
61 |
* Extensi?n para el c?lculo de Componentes Principales.
|
62 |
*
|
63 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
64 |
*/
|
65 |
public class PrincipalComponentsExtension extends Extension implements IGenericToolBarMenuItem { |
66 |
private static final double NODATA = -99999999999999.; |
67 |
|
68 |
/*
|
69 |
* (non-Javadoc)
|
70 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
71 |
*/
|
72 |
public void initialize() { |
73 |
ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager(); |
74 |
ExtensionPoint point=extensionPoints.add("GenericToolBarMenu");
|
75 |
point.append("PrincipalComponents", "", this.getClass()); |
76 |
} |
77 |
|
78 |
/*
|
79 |
* (non-Javadoc)
|
80 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
81 |
*/
|
82 |
public void execute(String actionCommand) { |
83 |
if (actionCommand.equals("principal_components")){ |
84 |
org.gvsig.andami.ui.mdiManager.IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
85 |
|
86 |
//si la ventana activa es de tipo Vista
|
87 |
if (activeWindow instanceof DefaultViewPanel) { |
88 |
PrincipalComponentPanel pcPanel = new PrincipalComponentPanel ((DefaultViewPanel)activeWindow);
|
89 |
PluginServices.getMDIManager().addWindow(pcPanel); |
90 |
|
91 |
} |
92 |
} |
93 |
} |
94 |
|
95 |
/*
|
96 |
* (non-Javadoc)
|
97 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
98 |
*/
|
99 |
public boolean isEnabled() { |
100 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
101 |
if (f == null) { |
102 |
return false; |
103 |
} |
104 |
if (f.getClass() == DefaultViewPanel.class) {
|
105 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
106 |
ViewDocument model = vista.getModel(); |
107 |
MapContext mapa = model.getMapContext(); |
108 |
FLayers layers = mapa.getLayers(); |
109 |
for (int i = 0; i < layers.getLayersCount(); i++) |
110 |
if (layers.getLayer(i) instanceof FLyrRasterSE) |
111 |
return true; |
112 |
} |
113 |
return false; |
114 |
} |
115 |
|
116 |
/*
|
117 |
* (non-Javadoc)
|
118 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
119 |
*/
|
120 |
public boolean isVisible() { |
121 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
122 |
if (f == null) { |
123 |
return false; |
124 |
} |
125 |
if (f instanceof DefaultViewPanel) { |
126 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
127 |
ViewDocument model = vista.getModel(); |
128 |
MapContext mapa = model.getMapContext(); |
129 |
return mapa.getLayers().getLayersCount() > 0; |
130 |
} else {
|
131 |
return false; |
132 |
} |
133 |
} |
134 |
|
135 |
private static double covariance(double[] xx, double x, double[] yy, double y) { |
136 |
double dSum = 0; |
137 |
int iValues = 0; |
138 |
|
139 |
for (int i = 0; i < yy.length; i++) { |
140 |
if (xx[i] != NODATA && yy[i] != NODATA) {
|
141 |
dSum += (xx[i] - x) * (yy[i] - y); |
142 |
iValues++; |
143 |
} |
144 |
} |
145 |
if (iValues > 1) { |
146 |
return dSum / (double) (iValues - 1); |
147 |
} else {
|
148 |
return NODATA;
|
149 |
} |
150 |
} |
151 |
|
152 |
private static double covariance(byte[][] xx, double x, byte[][] yy, double y) { |
153 |
double dSum = 0; |
154 |
int iValues = 0; |
155 |
|
156 |
for (int i = 0; i < yy.length; i++) { |
157 |
for (int j = 0; j < yy[0].length; j++) { |
158 |
if (xx[i][j] != NODATA && yy[i][j] != NODATA) {
|
159 |
dSum += (xx[i][j] - x) * (yy[i][j] - y); |
160 |
iValues++; |
161 |
} |
162 |
} |
163 |
} |
164 |
if (iValues > 1) { |
165 |
return dSum / (double) (iValues - 1); |
166 |
} else {
|
167 |
return NODATA;
|
168 |
} |
169 |
} |
170 |
|
171 |
/**
|
172 |
* Covariance of two 1D arrays of doubles, xx and yy
|
173 |
* @param xx
|
174 |
* @param yy
|
175 |
* @return
|
176 |
*/
|
177 |
public static double covariance(byte[][] xx, byte[][] yy){ |
178 |
int nx = xx.length;
|
179 |
int ny = xx[0].length; |
180 |
if (nx != yy.length)
|
181 |
throw new IllegalArgumentException("length of x variable array, " + nx + " and length of y array, " + yy.length + " are different"); |
182 |
|
183 |
double sumx = 0.0D, meanx = 0.0D; |
184 |
double sumy = 0.0D, meany = 0.0D; |
185 |
for (int i = 0; i < nx; i++) { |
186 |
for (int j = 0; j < ny; j++) { |
187 |
sumx += xx[i][j]; |
188 |
sumy += yy[i][j]; |
189 |
} |
190 |
} |
191 |
meanx = sumx / ((double) nx * (double) ny); |
192 |
meany = sumy / ((double) nx * (double) ny); |
193 |
double sum = 0.0D; |
194 |
for (int i = 0; i < nx; i++) { |
195 |
for (int j = 0; j < ny; j++) |
196 |
sum += (xx[i][j] - meanx) * (yy[i][j] - meany); |
197 |
} |
198 |
return sum / ((double) (nx * ny - 1)); |
199 |
} |
200 |
|
201 |
/*
|
202 |
* (non-Javadoc)
|
203 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#execute(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
|
204 |
*/
|
205 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
206 |
this.execute("principal_components"); |
207 |
} |
208 |
|
209 |
/*
|
210 |
* (non-Javadoc)
|
211 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getGroup()
|
212 |
*/
|
213 |
public String getGroup() { |
214 |
return "RasterProcess"; |
215 |
} |
216 |
|
217 |
/*
|
218 |
* (non-Javadoc)
|
219 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getIcon()
|
220 |
*/
|
221 |
public Icon getIcon() { |
222 |
return PluginServices.getIconTheme().get("blank-icon"); |
223 |
} |
224 |
|
225 |
/*
|
226 |
* (non-Javadoc)
|
227 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getOrder()
|
228 |
*/
|
229 |
public int getOrder() { |
230 |
return 0; |
231 |
} |
232 |
|
233 |
/*
|
234 |
* (non-Javadoc)
|
235 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getText()
|
236 |
*/
|
237 |
public String getText() { |
238 |
return PluginServices.getText(this, "principal_components"); |
239 |
} |
240 |
|
241 |
/*
|
242 |
* (non-Javadoc)
|
243 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#isEnabled(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
|
244 |
*/
|
245 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
246 |
if ((selectedItems == null) || (selectedItems.length != 1)) |
247 |
return false; |
248 |
|
249 |
if (!(selectedItems[0] instanceof ILayerState)) |
250 |
return false; |
251 |
|
252 |
if (!((ILayerState) selectedItems[0]).isOpen()) |
253 |
return false; |
254 |
|
255 |
return true; |
256 |
} |
257 |
|
258 |
/*
|
259 |
* (non-Javadoc)
|
260 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#isVisible(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
|
261 |
*/
|
262 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
263 |
if ((selectedItems == null) || (selectedItems.length != 1)) |
264 |
return false; |
265 |
|
266 |
if (!(selectedItems[0] instanceof FLyrRasterSE)) |
267 |
return false; |
268 |
|
269 |
return true; |
270 |
} |
271 |
|
272 |
/*
|
273 |
* (non-Javadoc)
|
274 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getGroupOrder()
|
275 |
*/
|
276 |
public int getGroupOrder() { |
277 |
return 0; |
278 |
} |
279 |
} |