Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / georeferencing / geotransform / GeoTransformProcess.java @ 18305

History | View | Annotate | Download (7.58 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 Iba?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.georeferencing.geotransform;
42

    
43
import org.gvsig.rastertools.RasterProcess;
44

    
45
import Jama.Matrix;
46

    
47
import com.iver.andami.PluginServices;
48

    
49
/**
50
 *  Clase que representa una transformacion polinomial  para la convertir las
51
 *  coordenadas de una imagen en la imagen rectificada.
52
 *  
53
 *  @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
54
 *         @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)  
55
 *         @version 20/1/2008
56
 **/
57
public class GeoTransformProcess extends RasterProcess {
58

    
59
        // Esto va a cambiar dependiendo del formato de los punto de la interfaz
60
        // de momento geo_points puntos sobre imagen georeferenciada, image_points
61
        // puntos sobre imagen a georeferenciar.
62
        
63
        protected double geo_points[][]=new double[2][];
64
        protected double image_points[][]=new double[2][];
65
        
66
        // porcentage del proceso global de la tarea
67
        private int percent=0;
68
        
69
        // orden del polinomio aproximador
70
        protected int orden = 0;
71
        
72
        // numero minimo de puntos 
73
        protected int minGPC=0;
74
        
75
        // coeficientes del polinomio de transformacion para las coordenadas en X
76
        private double []coefX=null;
77
        
78
//         coeficientes del polinomio de transformacion para las coordenadas en Y
79
        private double []coefY=null;
80
        
81
        
82
        /** Metodo que recoge los parametros del proceso de clasificacion de 
83
        * m?xima probabilidad 
84
        * <LI>geo_points: lista de puntos con coordenadas reales</LI>
85
        * <LI> image_points: lista de puntos coordenadas pixel</LI> 
86
        * <LI> orden: orden del polinomio de transformacion </LI> 
87
        */
88
        public void init() {                
89
                geo_points =(double[][]) getParam("geoPoints");
90
                image_points=(double[][]) getParam("imagePoints");
91
                orden= (int)getIntParam("orden");
92
                minGPC = (orden+1)*(orden+2)/2;
93
                // Chequear si el numero de puntos es suficiente para determinar la transformacion de orden n. 
94
                if(!enoughPoints()){
95
                        // NOTIFICAR, NO SUFICIENTES PUNTOS PARA ORDEN SELECCIONADO
96
                        return;
97
                }
98
        }
99
        
100
        /**
101
         * @return true si se proporciona el numero minimo de puntos de entrada 
102
         * para la transformaci?n. false en caso contrario.
103
         * */                
104
        public boolean enoughPoints() {
105
                return (geo_points[0].length>minGPC && image_points[0].length>minGPC);
106
        }
107

    
108
        /**
109
         *  Proceso de calculo de los coeficientes del polinomio. 
110
         **/
111
        public void process() throws InterruptedException {
112
                // Obtencion  polinomio de transformacion en x
113
                getPolinomyalCoefX();
114
                
115
                // Obtencion del polinomio de transformaci?n en y
116
                getPolinomialCoefY();
117
        
118
        }
119

    
120

    
121
        /**
122
         * @return coeficientes para el polinomio de transformaci?n en x.
123
         * */
124
        public double[] getPolinomyalCoefX(){
125
                if(coefX==null)
126
                        setDxGeneral();
127
                return coefX;
128
        }
129
        
130
        
131
        /**
132
         * @return coeficientes para el polinomio de transformaci?n en y.
133
         * */
134
        public double[] getPolinomialCoefY(){
135
                if(coefY==null)
136
                        setDyGeneral();
137
                return coefY;
138
        }
139
        
140

    
141
/////////!!!!!!! Obtiene matriz general a partir de los puntos de control y el orden del polinomio aproximador
142
        public void setDxGeneral(){
143
                double matrixDx[][]= new double [minGPC][minGPC]; 
144
                double result[]= new double[minGPC];
145
                int exp[][]=new int[minGPC][2];
146
                int k=-1;
147
                // Obtencion de la primera fila de la matriz
148
                
149
                for (int filas=0; filas<minGPC;filas++)
150
                {        k=-1;
151
                for (int i=0; i<=orden; i++)
152
                        for(int j=0; j<=i; j++){
153
                                k++;
154
                                for(int v=0; v<geo_points.length;v++)
155
                                        matrixDx[filas][k]+=(Math.pow(geo_points[v][0],i-j)* Math.pow(geo_points[v][0],exp[filas][0]))
156
                                                        * (Math.pow(geo_points[v][1],j)* Math.pow(geo_points[v][1],exp[filas][1]));                        
157
                                // Para la fila 0 se guardan los exponentes
158
                                if(filas==0){
159
                                        exp[k][0]=i-j;
160
                                        exp[k][1]=j;
161

    
162
                                        // Se calcula el resultado de !!!!!
163
                                        for(int v=0; v<geo_points.length;v++)
164
                                                result[k]+=(Math.pow(geo_points[v][0],i-j)* Math.pow(geo_points[v][0],exp[filas][0]))
165
                                                * (Math.pow(geo_points[v][1],j)* Math.pow(geo_points[v][1],exp[filas][1]))*image_points[v][0];                                
166
                                }
167
        
168
                        }
169
                }
170
                Matrix matrixResult= new Matrix(matrixDx);
171
                try {
172
                        coefX=solveSistemforCramer(matrixResult,result);
173
                } catch (BadDeteminantException e) {
174
                        // Resolver sistema de ecuaciones o por otro metodo
175
                }
176
        }
177
        
178
        
179
        // TO DO: Ver la manera de unificar con setDxGeneral(Parametrizar un metodo general)..... Estudiar optimizaciones!!! 
180
        // Cambios necesarios para el caolculo de coeficientes para coordenadas y
181
        public void setDyGeneral(){
182
                double matrixDy[][]= new double [minGPC][minGPC]; 
183
                double result[]= new double[minGPC];
184
                int exp[][]=new int[minGPC][2];
185
                int k=-1;
186
                // Obtencion de la primera fila de la matriz
187
                
188
                for (int filas=0; filas<minGPC;filas++)
189
                {        k=-1;
190
                for (int i=0; i<=orden; i++)
191
                        for(int j=0; j<=i; j++){
192
                                k++;
193
                                for(int v=0; v<geo_points.length;v++)
194
                                        matrixDy[filas][k]+=(Math.pow(geo_points[v][0],i-j)* Math.pow(geo_points[v][0],exp[filas][0]))
195
                                                        * (Math.pow(geo_points[v][1],j)* Math.pow(geo_points[v][1],exp[filas][1]));                        
196
                                // Para la fila 0 se guardan los exponentes
197
                                if(filas==0){
198
                                        exp[k][0]=i-j;
199
                                        exp[k][1]=j;
200

    
201
                                        // Se calcula el resultado de !!!!!
202
                                        for(int v=0; v<geo_points.length;v++)
203
                                                result[k]+=(Math.pow(geo_points[v][0],i-j)* Math.pow(geo_points[v][0],exp[filas][0]))
204
                                                * (Math.pow(geo_points[v][1],j)* Math.pow(geo_points[v][1],exp[filas][1]))*image_points[v][0];                                
205
                                }
206
        
207
                        }
208
                }
209
                Matrix matrixResult= new Matrix(matrixDy);
210
                try {
211
                        coefY=solveSistemforCramer(matrixResult,result);
212
                } catch (BadDeteminantException e) {
213
                        // Resolver sistema de ecuaciones opor otro metodo
214
                }
215
        }
216
                
217
        /**
218
         *         Resoluci?n del sistema por la regla de Cramer.
219
         *  @return array con la solucion al sistema de ecuadiones.
220
         * */
221
        public double[] solveSistemforCramer(Matrix matrix, double columResult[]) throws BadDeteminantException{
222
                double xCoef []= new double[minGPC];
223
                double det= matrix.det();
224
                if(det==0)
225
                        throw new BadDeteminantException();
226
                double aux[][]= matrix.getArrayCopy();
227
                Matrix m=null;
228
                
229
                // Resolucion del sistema por cramer
230
                for(int k=0; k<columResult.length; k++)
231
                {
232
                        for(int i=0;i<columResult.length;i++)
233
                                aux[i][k]= columResult[i];
234
                        m= new Matrix (aux);
235
                        xCoef[k]= m.det()/det;
236
                        aux=matrix.getArrayCopy();;
237
                }
238
                return xCoef;
239
        }
240
        
241
        
242
        public String getTitle() {
243
                return PluginServices.getText(this,"transformacion");
244
        }
245

    
246

    
247
        public String getLog() {
248
                return PluginServices.getText(this,"calculando_transformacion");
249
        }
250

    
251
        
252
        public int getPercent() {
253
                // TODO Auto-generated method stub
254
                return percent;
255
        }
256
        
257
        
258
}
259
        
260
        
261
        
262
        
263