svn-gvsig-desktop / trunk / libraries / libFMap / src / com / vividsolutions / jts / geomgraph / index / SnapMonotoneChainEdge.java @ 9178
History | View | Annotate | Download (5.31 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: SnapMonotoneChainEdge.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.1 2006/10/17 18:25:53 azabala
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
* Revision 1.1 2006/10/05 19:20:57 azabala
|
55 |
* first version in cvs
|
56 |
*
|
57 |
* Revision 1.1 2006/10/02 19:06:26 azabala
|
58 |
* First version in CVS
|
59 |
*
|
60 |
*
|
61 |
*/
|
62 |
package com.vividsolutions.jts.geomgraph.index; |
63 |
|
64 |
import com.vividsolutions.jts.geom.Coordinate; |
65 |
import com.vividsolutions.jts.geom.Envelope; |
66 |
import com.vividsolutions.jts.geomgraph.SnappingEdge; |
67 |
import com.vividsolutions.jts.geomgraph.index.MonotoneChainEdge; |
68 |
import com.vividsolutions.jts.geomgraph.index.SegmentIntersector; |
69 |
|
70 |
public class SnapMonotoneChainEdge extends MonotoneChainEdge { |
71 |
|
72 |
SnappingEdge e; |
73 |
int[] startIndex; |
74 |
double snapTolerance;
|
75 |
|
76 |
|
77 |
public SnapMonotoneChainEdge(SnappingEdge e, double snapTolerance) { |
78 |
super(e);
|
79 |
this.e = e;
|
80 |
startIndex = super.getStartIndexes();
|
81 |
this.snapTolerance = snapTolerance;
|
82 |
} |
83 |
|
84 |
public SnappingEdge getEdge(){
|
85 |
return e;
|
86 |
} |
87 |
|
88 |
public void computeIntersects(MonotoneChainEdge mce, |
89 |
SegmentIntersector si) |
90 |
{ |
91 |
if (! (mce instanceof SnapMonotoneChainEdge)) |
92 |
throw new IllegalArgumentException("Requiere MCE de snap"); |
93 |
for (int i = 0; i < startIndex.length - 1; i++) { |
94 |
for (int j = 0; j < mce.getStartIndexes().length - 1; j++) { |
95 |
computeIntersectsForChain(i, mce, j, si ); |
96 |
}//for
|
97 |
}//for
|
98 |
} |
99 |
|
100 |
|
101 |
public void computeIntersectsForChain(int chainIndex0, |
102 |
MonotoneChainEdge mce, |
103 |
int chainIndex1,
|
104 |
SegmentIntersector si){ |
105 |
if (! (mce instanceof SnapMonotoneChainEdge)) |
106 |
throw new IllegalArgumentException("Requiere MCE de snap"); |
107 |
computeIntersectsForChain(startIndex[chainIndex0], |
108 |
startIndex[chainIndex0 + 1],
|
109 |
mce, |
110 |
mce.getStartIndexes()[chainIndex1], |
111 |
mce.getStartIndexes()[chainIndex1 + 1],
|
112 |
si ); |
113 |
} |
114 |
|
115 |
|
116 |
|
117 |
private void computeIntersectsForChain(int start0, int end0, |
118 |
MonotoneChainEdge mce, int start1,
|
119 |
int end1, SegmentIntersector ei){
|
120 |
|
121 |
if (! (mce instanceof SnapMonotoneChainEdge)) |
122 |
throw new IllegalArgumentException("Requiere MCE de snap"); |
123 |
|
124 |
SnapMonotoneChainEdge snapMce = (SnapMonotoneChainEdge) mce; |
125 |
Coordinate p00 = super.getCoordinates()[start0];
|
126 |
Coordinate p01 = super.getCoordinates()[end0];
|
127 |
|
128 |
Coordinate p10 = mce.getCoordinates()[start1]; |
129 |
Coordinate p11 = mce.getCoordinates()[end1]; |
130 |
|
131 |
|
132 |
// terminating condition for the recursion
|
133 |
if (end0 - start0 == 1 && end1 - start1 == 1) { |
134 |
ei.addIntersections(e, start0, snapMce.getEdge(), start1); |
135 |
return;
|
136 |
} |
137 |
|
138 |
// nothing to do if the envelopes of these chains don't overlap
|
139 |
Envelope env1 = new Envelope(p00, p01);
|
140 |
double newMinX = env1.getMinX() - snapTolerance;
|
141 |
double newMaxX = env1.getMaxX() + snapTolerance;
|
142 |
double newMinY = env1.getMinY() - snapTolerance;
|
143 |
double newMaxY = env1.getMaxY() + snapTolerance;
|
144 |
env1 = new Envelope(newMinX, newMaxX, newMinY, newMaxY);
|
145 |
|
146 |
Envelope env2 = new Envelope(p10, p11);
|
147 |
newMinX = env1.getMinX() - snapTolerance; |
148 |
newMaxX = env1.getMaxX() + snapTolerance; |
149 |
newMinY = env1.getMinY() - snapTolerance; |
150 |
newMaxY = env1.getMaxY() + snapTolerance; |
151 |
env2 = new Envelope(newMinX, newMaxX, newMinY, newMaxY);
|
152 |
|
153 |
if (! env1.intersects(env2))
|
154 |
return;
|
155 |
|
156 |
|
157 |
// the chains overlap,
|
158 |
//so split each in half and iterate (binary search)
|
159 |
int mid0 = (start0 + end0) / 2; |
160 |
int mid1 = (start1 + end1) / 2; |
161 |
|
162 |
if (start0 < mid0) {
|
163 |
if (start1 < mid1)
|
164 |
computeIntersectsForChain(start0, mid0, mce, start1, mid1, ei); |
165 |
if (mid1 < end1)
|
166 |
computeIntersectsForChain(start0, mid0, mce, mid1, end1, ei); |
167 |
} |
168 |
|
169 |
if (mid0 < end0) {
|
170 |
if (start1 < mid1)
|
171 |
computeIntersectsForChain(mid0, end0, mce, start1, mid1, ei); |
172 |
if (mid1 < end1)
|
173 |
computeIntersectsForChain(mid0, end0, mce, mid1, end1, ei); |
174 |
} |
175 |
} |
176 |
} |
177 |
|