svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / PrincipalComponentsExtension.java @ 18306
History | View | Annotate | Download (4.98 KB)
1 | 13790 | dguerrero | /* 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 | |||
41 | |||
42 | package org.gvsig.remotesensing; |
||
43 | |||
44 | 15665 | nbrodin | import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
45 | 13790 | dguerrero | import org.gvsig.remotesensing.principalcomponents.gui.PrincipalComponentPanel; |
46 | |||
47 | import com.iver.andami.PluginServices; |
||
48 | import com.iver.andami.plugins.Extension; |
||
49 | import com.iver.cit.gvsig.fmap.MapContext; |
||
50 | 15665 | nbrodin | import com.iver.cit.gvsig.fmap.layers.FLayers; |
51 | 13790 | dguerrero | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
52 | import com.iver.cit.gvsig.project.documents.view.gui.View; |
||
53 | |||
54 | |||
55 | |||
56 | /**
|
||
57 | * Extensi?n para el c?lculo de Componentes Principales.
|
||
58 | *
|
||
59 | * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
||
60 | *
|
||
61 | */
|
||
62 | public class PrincipalComponentsExtension extends Extension { |
||
63 | |||
64 | private static final double NODATA = -99999999999999.; |
||
65 | |||
66 | public void initialize() { |
||
67 | 16682 | gsdiego | //PrincipalComponentListManager.register();
|
68 | 13790 | dguerrero | } |
69 | |||
70 | public void execute(String actionCommand) { |
||
71 | if (actionCommand.equals("principal_components")){ |
||
72 | com.iver.andami.ui.mdiManager.IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
||
73 | 16635 | amunoz | |
74 | 13790 | dguerrero | //si la ventana activa es de tipo Vista
|
75 | if (activeWindow instanceof View) { |
||
76 | PrincipalComponentPanel pcPanel = new PrincipalComponentPanel ((View)activeWindow); |
||
77 | PluginServices.getMDIManager().addWindow(pcPanel); |
||
78 | |||
79 | } |
||
80 | } |
||
81 | } |
||
82 | |||
83 | public boolean isEnabled() { |
||
84 | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
||
85 | if (f == null) { |
||
86 | return false; |
||
87 | } |
||
88 | if (f.getClass() == View.class) { |
||
89 | View vista = (View) f; |
||
90 | IProjectView model = vista.getModel(); |
||
91 | MapContext mapa = model.getMapContext(); |
||
92 | 15665 | nbrodin | FLayers layers = mapa.getLayers(); |
93 | for (int i = 0; i < layers.getLayersCount(); i++) |
||
94 | if (layers.getLayer(i) instanceof FLyrRasterSE) |
||
95 | return true; |
||
96 | 13790 | dguerrero | } |
97 | 15665 | nbrodin | return false; |
98 | 13790 | dguerrero | } |
99 | |||
100 | public boolean isVisible() { |
||
101 | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
||
102 | if (f == null) { |
||
103 | return false; |
||
104 | } |
||
105 | if (f instanceof View) { |
||
106 | View vista = (View) f; |
||
107 | IProjectView model = vista.getModel(); |
||
108 | MapContext mapa = model.getMapContext(); |
||
109 | return mapa.getLayers().getLayersCount() > 0; |
||
110 | } else {
|
||
111 | return false; |
||
112 | } |
||
113 | } |
||
114 | |||
115 | private static double covariance(double[] xx, double x, double[] yy, double y) { |
||
116 | |||
117 | double dSum = 0; |
||
118 | int iValues = 0; |
||
119 | |||
120 | for (int i = 0; i < yy.length; i++) { |
||
121 | if (xx[i] != NODATA && yy[i] != NODATA){
|
||
122 | dSum += (xx[i] - x) * (yy[i] - y); |
||
123 | iValues++; |
||
124 | } |
||
125 | } |
||
126 | if (iValues > 1){ |
||
127 | return dSum / (double) (iValues - 1); |
||
128 | } |
||
129 | else{
|
||
130 | return NODATA;
|
||
131 | } |
||
132 | } |
||
133 | |||
134 | private static double covariance(byte[][] xx, double x, byte[][] yy, double y) { |
||
135 | |||
136 | double dSum = 0; |
||
137 | int iValues = 0; |
||
138 | |||
139 | for (int i = 0; i < yy.length; i++) { |
||
140 | for (int j = 0; j < yy[0].length; j++) { |
||
141 | if (xx[i][j] != NODATA && yy[i][j] != NODATA){
|
||
142 | dSum += (xx[i][j] - x) * (yy[i][j] - y); |
||
143 | iValues++; |
||
144 | } |
||
145 | } |
||
146 | } |
||
147 | if (iValues > 1){ |
||
148 | return dSum / (double) (iValues - 1); |
||
149 | } |
||
150 | else{
|
||
151 | return NODATA;
|
||
152 | } |
||
153 | } |
||
154 | |||
155 | //Covariance of two 1D arrays of doubles, xx and yy
|
||
156 | public static double covariance(byte[][] xx, byte[][] yy){ |
||
157 | int nx = xx.length;
|
||
158 | int ny = xx[0].length; |
||
159 | if(nx!=yy.length)throw new IllegalArgumentException("length of x variable array, " + nx + " and length of y array, " + yy.length + " are different"); |
||
160 | |||
161 | double sumx=0.0D, meanx=0.0D; |
||
162 | double sumy=0.0D, meany=0.0D; |
||
163 | for(int i=0; i<nx; i++){ |
||
164 | for(int j=0; j<ny; j++){ |
||
165 | sumx+=xx[i][j]; |
||
166 | sumy+=yy[i][j]; |
||
167 | } |
||
168 | } |
||
169 | meanx=sumx/((double)nx*(double)ny); |
||
170 | meany=sumy/((double)nx*(double)ny); |
||
171 | double sum=0.0D; |
||
172 | for(int i=0; i<nx; i++){ |
||
173 | for(int j=0; j<ny; j++) |
||
174 | sum+=(xx[i][j]-meanx)*(yy[i][j]-meany); |
||
175 | } |
||
176 | return sum/((double)(nx*ny-1)); |
||
177 | } |
||
178 | } |