svn-gvsig-desktop / trunk / libraries / libFMap / src / com / vividsolutions / jts / geomgraph / SnappingEdge.java @ 9178
History | View | Annotate | Download (7.36 KB)
1 |
/*
|
---|---|
2 |
* Created on 02-oct-2006
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: SnappingEdge.java 9178 2006-12-04 19:30:23Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.1 2006-12-04 19:30:23 azabala
|
49 |
* *** empty log message ***
|
50 |
*
|
51 |
* Revision 1.2 2006/10/19 16:06:48 azabala
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
* Revision 1.1 2006/10/17 18:25:53 azabala
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.1 2006/10/05 19:20:57 azabala
|
58 |
* first version in cvs
|
59 |
*
|
60 |
* Revision 1.1 2006/10/02 19:06:39 azabala
|
61 |
* *** empty log message ***
|
62 |
*
|
63 |
*
|
64 |
*/
|
65 |
package com.vividsolutions.jts.geomgraph; |
66 |
|
67 |
import com.vividsolutions.jts.algorithm.LineIntersector; |
68 |
import com.vividsolutions.jts.geom.Coordinate; |
69 |
import com.vividsolutions.jts.geomgraph.Edge; |
70 |
import com.vividsolutions.jts.geomgraph.EdgeIntersectionList; |
71 |
import com.vividsolutions.jts.geomgraph.Label; |
72 |
import com.vividsolutions.jts.geomgraph.index.MonotoneChainEdge; |
73 |
import com.vividsolutions.jts.geomgraph.index.SnapMonotoneChainEdge; |
74 |
|
75 |
public class SnappingEdge extends Edge { |
76 |
|
77 |
SnapEdgeIntersectionList eiList; |
78 |
private double snapTolerance; |
79 |
private SnapMonotoneChainEdge mce;
|
80 |
|
81 |
/**
|
82 |
* TODO->Esto es una cagada????
|
83 |
* El problema es que no estoy aplicando SNAP
|
84 |
* en el compute de intersecciones colineales
|
85 |
*
|
86 |
*
|
87 |
*
|
88 |
* Nos permite snapear las coordenadas del Edge, para
|
89 |
* que antes de a?adir un SnapEdgeIntersection se verifique
|
90 |
* si coincide con un vertice (y snapearlo al vertice
|
91 |
* para evitar que salgan cosas raras)
|
92 |
* */
|
93 |
private SnappingNodeMap nodes;
|
94 |
|
95 |
public SnappingEdge(Coordinate[] pts, Label label, double tolerance) |
96 |
{ |
97 |
super(pts, label);
|
98 |
this.snapTolerance = tolerance;
|
99 |
eiList = new SnapEdgeIntersectionList(this); |
100 |
|
101 |
} |
102 |
|
103 |
public double getSnapTolerance(){ |
104 |
return snapTolerance;
|
105 |
} |
106 |
|
107 |
public SnappingEdge(Coordinate[] pts, double snapTolerance) |
108 |
{ |
109 |
this(pts, null, snapTolerance); |
110 |
} |
111 |
|
112 |
|
113 |
public EdgeIntersectionList getEdgeIntersectionList() {
|
114 |
return eiList;
|
115 |
} |
116 |
|
117 |
|
118 |
public MonotoneChainEdge getMonotoneChainEdge()
|
119 |
{ |
120 |
if (mce == null) |
121 |
mce = new SnapMonotoneChainEdge(this, snapTolerance); |
122 |
return mce;
|
123 |
} |
124 |
|
125 |
public boolean isPointwiseEqual(Edge e) |
126 |
{ |
127 |
Coordinate[] thisCoordinates = this.getCoordinates(); |
128 |
Coordinate[] otherCoordinates = e.getCoordinates();
|
129 |
if (thisCoordinates.length != otherCoordinates.length)
|
130 |
return false; |
131 |
|
132 |
for (int i = 0; i < thisCoordinates.length; i++) { |
133 |
if (! (thisCoordinates[i].distance(otherCoordinates[i]) <= snapTolerance)) {
|
134 |
return false; |
135 |
} |
136 |
} |
137 |
return true; |
138 |
} |
139 |
|
140 |
public boolean equals(Object o) |
141 |
{ |
142 |
if (! (o instanceof Edge)) return false; |
143 |
Edge e = (Edge) o; |
144 |
Coordinate[] thisCoordinates = this.getCoordinates(); |
145 |
Coordinate[] otherCoordinates = e.getCoordinates();
|
146 |
if (thisCoordinates.length != otherCoordinates.length)
|
147 |
return false; |
148 |
|
149 |
boolean isEqualForward = true; |
150 |
boolean isEqualReverse = true; |
151 |
int iRev = thisCoordinates.length;
|
152 |
for (int i = 0; i < thisCoordinates.length; i++) { |
153 |
if (! (thisCoordinates[i].distance(otherCoordinates[i])
|
154 |
<= snapTolerance)) { |
155 |
isEqualForward = false;
|
156 |
} |
157 |
if (!(thisCoordinates[i].distance(otherCoordinates[--iRev]) <= snapTolerance)) {
|
158 |
isEqualReverse = false;
|
159 |
} |
160 |
if (! isEqualForward && ! isEqualReverse) return false; |
161 |
} |
162 |
return true; |
163 |
} |
164 |
|
165 |
|
166 |
/**
|
167 |
* Adds EdgeIntersections for one or both
|
168 |
* intersections found for a segment of an edge to the edge intersection list.
|
169 |
*/
|
170 |
public void addIntersections(LineIntersector li, |
171 |
int segmentIndex,
|
172 |
int geomIndex){
|
173 |
|
174 |
//se supone que si es colineal, aqu? se a?aden los
|
175 |
// dos puntos
|
176 |
|
177 |
for (int i = 0; i < li.getIntersectionNum(); i++) { |
178 |
addIntersection(li, segmentIndex, geomIndex, i); |
179 |
} |
180 |
} |
181 |
|
182 |
/**
|
183 |
* Add an EdgeIntersection for intersection intIndex.
|
184 |
* An intersection that falls exactly on a vertex of the edge is normalized
|
185 |
* to use the higher of the two possible segmentIndexes
|
186 |
*/
|
187 |
public void addIntersection(LineIntersector li, |
188 |
int segmentIndex,
|
189 |
int geomIndex,
|
190 |
int intIndex)
|
191 |
{ |
192 |
Coordinate intPt = new Coordinate(li.getIntersection(intIndex));
|
193 |
|
194 |
|
195 |
// AQUI ESTA OTRA DE LAS CLAVES
|
196 |
// intPt es una coordenada, que puede estar muy cerca de alguna coordenada
|
197 |
// del EDGE. ?Como gestionar esto?
|
198 |
// CREO QUE LO MEJOR ES SNAPEAR
|
199 |
|
200 |
int normalizedSegmentIndex = segmentIndex;
|
201 |
double dist = li.getEdgeDistance(geomIndex, intIndex);
|
202 |
// normalize the intersection point location
|
203 |
int nextSegIndex = normalizedSegmentIndex + 1; |
204 |
if (nextSegIndex < super.getNumPoints()) { |
205 |
Coordinate nextPt = super.getCoordinate(nextSegIndex);
|
206 |
|
207 |
//TODO VER ESTO DEL 0.0
|
208 |
// AQUI PASA ALGO RARO TAMBIEN
|
209 |
// PARA EL TEST N? 1, TUVE QUE A?ADIR EL ELSE
|
210 |
// PERO PARA EL SIGUIENTE TESTE CREO QUE ME EST? PERDIENDO
|
211 |
// LOS PUNTOS INTERMEDIOS
|
212 |
|
213 |
|
214 |
//if (intPt.distance(nextPt) == 0.0) {
|
215 |
if (intPt.distance(nextPt) <= snapTolerance) {
|
216 |
normalizedSegmentIndex = nextSegIndex; |
217 |
dist = 0.0;
|
218 |
intPt = nextPt; |
219 |
|
220 |
}else{
|
221 |
Coordinate previousPoint = this.getCoordinate(normalizedSegmentIndex);
|
222 |
if(intPt.distance(previousPoint) <= snapTolerance){
|
223 |
dist = 0.0;
|
224 |
intPt = previousPoint; |
225 |
} |
226 |
} |
227 |
|
228 |
/*
|
229 |
TODO
|
230 |
Esto lo a?ado porque cuando la interseccion es un snapping, me conserva
|
231 |
todos los puntos y me salen dos puntos seguidos iguales (probar)
|
232 |
y luego la clase Quadrant me tira excepciones
|
233 |
*/
|
234 |
// else if (intPt.distance(nextPt) <= snapTolerance) {
|
235 |
// normalizedSegmentIndex = segmentIndex;
|
236 |
// dist = 0.0;
|
237 |
// //TODO PRUEBA
|
238 |
// intPt = nextPt;
|
239 |
// }
|
240 |
} |
241 |
|
242 |
eiList.add(intPt, normalizedSegmentIndex, dist); |
243 |
} |
244 |
|
245 |
/**
|
246 |
* Util para volver a calcular intersecciones de este Edge
|
247 |
* con los Edges de un geometrygraph distinto al original
|
248 |
*
|
249 |
* */
|
250 |
public void clearIntersections(){ |
251 |
eiList = new SnapEdgeIntersectionList(this); |
252 |
} |
253 |
} |
254 |
|