svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / georeferencing / geotransform / GeoTransformProcess.java @ 18306
History | View | Annotate | Download (7.65 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 |
// obligar a que las listas de puntos tengan la misma longitud
|
106 |
return (geo_points.length>=minGPC && image_points.length==geo_points.length);
|
107 |
} |
108 |
|
109 |
/**
|
110 |
* Proceso de calculo de los coeficientes del polinomio.
|
111 |
**/
|
112 |
public void process() throws InterruptedException { |
113 |
// Obtencion polinomio de transformacion en x
|
114 |
getPolinomyalCoefX(); |
115 |
|
116 |
// Obtencion del polinomio de transformaci?n en y
|
117 |
getPolinomialCoefY(); |
118 |
|
119 |
} |
120 |
|
121 |
|
122 |
/**
|
123 |
* @return coeficientes para el polinomio de transformaci?n en x.
|
124 |
* */
|
125 |
public double[] getPolinomyalCoefX(){ |
126 |
if(coefX==null) |
127 |
setDxGeneral(); |
128 |
return coefX;
|
129 |
} |
130 |
|
131 |
|
132 |
/**
|
133 |
* @return coeficientes para el polinomio de transformaci?n en y.
|
134 |
* */
|
135 |
public double[] getPolinomialCoefY(){ |
136 |
if(coefY==null) |
137 |
setDyGeneral(); |
138 |
return coefY;
|
139 |
} |
140 |
|
141 |
|
142 |
/////////!!!!!!! Obtiene matriz general a partir de los puntos de control y el orden del polinomio aproximador
|
143 |
public void setDxGeneral(){ |
144 |
double matrixDx[][]= new double [minGPC][minGPC]; |
145 |
double result[]= new double[minGPC]; |
146 |
int exp[][]=new int[minGPC][2]; |
147 |
int k=-1; |
148 |
// Obtencion de la primera fila de la matriz
|
149 |
|
150 |
for (int filas=0; filas<minGPC;filas++) |
151 |
{ k=-1;
|
152 |
for (int i=0; i<=orden; i++) |
153 |
for(int j=0; j<=i; j++){ |
154 |
k++; |
155 |
for(int v=0; v<geo_points.length;v++) |
156 |
matrixDx[filas][k]+=(Math.pow(geo_points[v][0],i-j)* Math.pow(geo_points[v][0],exp[filas][0])) |
157 |
* (Math.pow(geo_points[v][1],j)* Math.pow(geo_points[v][1],exp[filas][1])); |
158 |
// Para la fila 0 se guardan los exponentes
|
159 |
if(filas==0){ |
160 |
exp[k][0]=i-j;
|
161 |
exp[k][1]=j;
|
162 |
|
163 |
// Se calcula el resultado de !!!!!
|
164 |
for(int v=0; v<geo_points.length;v++) |
165 |
result[k]+=(Math.pow(geo_points[v][0],i-j)* Math.pow(geo_points[v][0],exp[filas][0])) |
166 |
* (Math.pow(geo_points[v][1],j)* Math.pow(geo_points[v][1],exp[filas][1]))*image_points[v][0]; |
167 |
} |
168 |
|
169 |
} |
170 |
} |
171 |
Matrix matrixResult= new Matrix(matrixDx);
|
172 |
try {
|
173 |
coefX=solveSistemforCramer(matrixResult,result); |
174 |
} catch (BadDeteminantException e) {
|
175 |
// Resolver sistema de ecuaciones o por otro metodo
|
176 |
} |
177 |
} |
178 |
|
179 |
|
180 |
// TO DO: Ver la manera de unificar con setDxGeneral(Parametrizar un metodo general)..... Estudiar optimizaciones!!!
|
181 |
// Cambios necesarios para el caolculo de coeficientes para coordenadas y
|
182 |
public void setDyGeneral(){ |
183 |
double matrixDy[][]= new double [minGPC][minGPC]; |
184 |
double result[]= new double[minGPC]; |
185 |
int exp[][]=new int[minGPC][2]; |
186 |
int k=-1; |
187 |
// Obtencion de la primera fila de la matriz
|
188 |
|
189 |
for (int filas=0; filas<minGPC;filas++) |
190 |
{ k=-1;
|
191 |
for (int i=0; i<=orden; i++) |
192 |
for(int j=0; j<=i; j++){ |
193 |
k++; |
194 |
for(int v=0; v<geo_points.length;v++) |
195 |
matrixDy[filas][k]+=(Math.pow(geo_points[v][0],i-j)* Math.pow(geo_points[v][0],exp[filas][0])) |
196 |
* (Math.pow(geo_points[v][1],j)* Math.pow(geo_points[v][1],exp[filas][1])); |
197 |
// Para la fila 0 se guardan los exponentes
|
198 |
if(filas==0){ |
199 |
exp[k][0]=i-j;
|
200 |
exp[k][1]=j;
|
201 |
|
202 |
// Se calcula el resultado de !!!!!
|
203 |
for(int v=0; v<geo_points.length;v++) |
204 |
result[k]+=(Math.pow(geo_points[v][0],i-j)* Math.pow(geo_points[v][0],exp[filas][0])) |
205 |
* (Math.pow(geo_points[v][1],j)* Math.pow(geo_points[v][1],exp[filas][1]))*image_points[v][0]; |
206 |
} |
207 |
|
208 |
} |
209 |
} |
210 |
Matrix matrixResult= new Matrix(matrixDy);
|
211 |
try {
|
212 |
coefY=solveSistemforCramer(matrixResult,result); |
213 |
} catch (BadDeteminantException e) {
|
214 |
// Resolver sistema de ecuaciones opor otro metodo
|
215 |
} |
216 |
} |
217 |
|
218 |
/**
|
219 |
* Resoluci?n del sistema por la regla de Cramer.
|
220 |
* @return array con la solucion al sistema de ecuadiones.
|
221 |
* */
|
222 |
public double[] solveSistemforCramer(Matrix matrix, double columResult[]) throws BadDeteminantException{ |
223 |
double xCoef []= new double[minGPC]; |
224 |
double det= matrix.det();
|
225 |
if(det==0) |
226 |
throw new BadDeteminantException(); |
227 |
double aux[][]= matrix.getArrayCopy(); |
228 |
Matrix m=null;
|
229 |
|
230 |
// Resolucion del sistema por cramer
|
231 |
for(int k=0; k<columResult.length; k++) |
232 |
{ |
233 |
for(int i=0;i<columResult.length;i++) |
234 |
aux[i][k]= columResult[i]; |
235 |
m= new Matrix (aux);
|
236 |
xCoef[k]= m.det()/det; |
237 |
aux=matrix.getArrayCopy();; |
238 |
} |
239 |
return xCoef;
|
240 |
} |
241 |
|
242 |
|
243 |
public String getTitle() { |
244 |
return PluginServices.getText(this,"transformacion"); |
245 |
} |
246 |
|
247 |
|
248 |
public String getLog() { |
249 |
return PluginServices.getText(this,"calculando_transformacion"); |
250 |
} |
251 |
|
252 |
|
253 |
public int getPercent() { |
254 |
// TODO Auto-generated method stub
|
255 |
return percent;
|
256 |
} |
257 |
|
258 |
|
259 |
} |
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|