00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #ifndef GEOS_GEOMGRAPH_INDEX_H
00046 #define GEOS_GEOMGRAPH_INDEX_H
00047
00048 #include <memory>
00049 #include <geos/geomgraph.h>
00050 #include <geos/geom.h>
00051 #include <vector>
00052 #include <geos/geosAlgorithm.h>
00053 #include <geos/platform.h>
00054
00055 namespace geos {
00056
00057 class Edge;
00058 class Node;
00059 class CoordinateSequence;
00060
00061 class SegmentIntersector{
00062 public:
00063 static bool isAdjacentSegments(int i1,int i2);
00064
00065 int numTests;
00066 SegmentIntersector();
00067 virtual ~SegmentIntersector();
00068 SegmentIntersector(LineIntersector *newLi,bool newIncludeProper,bool newRecordIsolated);
00069 void setBoundaryNodes(vector<Node*> *bdyNodes0,vector<Node*> *bdyNodes1);
00070 Coordinate& getProperIntersectionPoint();
00071 bool hasIntersection();
00072 bool hasProperIntersection();
00073 bool hasProperInteriorIntersection();
00074 void addIntersections(Edge *e0,int segIndex0,Edge *e1,int segIndex1);
00075 private:
00080 bool hasIntersectionVar;
00081 bool hasProper;
00082 bool hasProperInterior;
00083
00084 Coordinate properIntersectionPoint;
00085 LineIntersector *li;
00086 bool includeProper;
00087 bool recordIsolated;
00088 bool isSelfIntersection;
00089
00090 int numIntersections;
00091 vector<vector<Node*>*> *bdyNodes;
00092 bool isTrivialIntersection(Edge *e0,int segIndex0,Edge *e1, int segIndex1);
00093 bool isBoundaryPoint(LineIntersector *li,vector<vector<Node*>*> *tstBdyNodes);
00094 bool isBoundaryPoint(LineIntersector *li,vector<Node*> *tstBdyNodes);
00095 };
00096
00097 class EdgeSetIntersector{
00098 public:
00107 virtual void computeIntersections(vector<Edge*> *edges,SegmentIntersector *si,bool testAllSegments)=0;
00111 virtual void computeIntersections(vector<Edge*> *edges0,vector<Edge*> *edges1,SegmentIntersector *si)=0;
00112 virtual ~EdgeSetIntersector(){};
00113 protected:
00114
00115
00116 };
00117
00118
00119
00120
00121
00122 class SweepLineEventOBJ {
00123 public:
00124 virtual ~SweepLineEventOBJ(){};
00125 };
00126
00127
00128 class SweepLineSegment: public SweepLineEventOBJ {
00129 public:
00130 SweepLineSegment(Edge *newEdge,int newPtIndex);
00131 ~SweepLineSegment();
00132 double getMinX();
00133 double getMaxX();
00134 void computeIntersections(SweepLineSegment *ss,SegmentIntersector *si);
00135 protected:
00136 Edge *edge;
00137 const CoordinateSequence* pts;
00138 int ptIndex;
00139 };
00140
00141 class SweepLineEvent{
00142 public:
00143 enum {
00144 INSERT_EVENT=1,
00145 DELETE_EVENT
00146 };
00147 SweepLineEvent(void* newEdgeSet,double x,SweepLineEvent *newInsertEvent,SweepLineEventOBJ *newObj);
00148 virtual ~SweepLineEvent();
00149 bool isInsert();
00150 bool isDelete();
00151 SweepLineEvent* getInsertEvent();
00152 int getDeleteEventIndex();
00153 void setDeleteEventIndex(int newDeleteEventIndex);
00154 SweepLineEventOBJ* getObject() const;
00155 int compareTo(SweepLineEvent *sle);
00156 string print();
00157 void* edgeSet;
00158 protected:
00159 SweepLineEventOBJ* obj;
00160 private:
00161 double xValue;
00162 int eventType;
00163 SweepLineEvent *insertEvent;
00164 int deleteEventIndex;
00165 };
00166
00167 class MonotoneChainIndexer{
00168 public:
00169
00170 MonotoneChainIndexer(){};
00171 vector<int>* getChainStartIndices(const CoordinateSequence* pts);
00172 private:
00173 int findChainEnd(const CoordinateSequence* pts,int start);
00174 };
00175
00176 class MonotoneChainEdge{
00177 public:
00178 MonotoneChainEdge();
00179 ~MonotoneChainEdge();
00180 MonotoneChainEdge(Edge *newE);
00181 const CoordinateSequence* getCoordinates();
00182 vector<int>* getStartIndexes();
00183 double getMinX(int chainIndex);
00184 double getMaxX(int chainIndex);
00185 void computeIntersects(MonotoneChainEdge *mce,SegmentIntersector *si);
00186 void computeIntersectsForChain(int chainIndex0,MonotoneChainEdge *mce,int chainIndex1,SegmentIntersector *si);
00187 protected:
00188 Edge *e;
00189 const CoordinateSequence* pts;
00190
00191
00192 vector<int>* startIndex;
00193
00194 Envelope *env1;
00195 Envelope *env2;
00196 private:
00197 void computeIntersectsForChain(int start0,int end0,MonotoneChainEdge *mce,
00198 int start1,int end1,SegmentIntersector *ei);
00199 };
00200
00201 class MonotoneChain: public SweepLineEventOBJ {
00202 public:
00203 MonotoneChain(MonotoneChainEdge *newMce,int newChainIndex);
00204 ~MonotoneChain();
00205 void computeIntersections(MonotoneChain *mc,SegmentIntersector *si);
00206 protected:
00207 MonotoneChainEdge *mce;
00208 int chainIndex;
00209 };
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 class SimpleMCSweepLineIntersector: public EdgeSetIntersector {
00220 public:
00221 SimpleMCSweepLineIntersector();
00222 virtual ~SimpleMCSweepLineIntersector();
00223 void computeIntersections(vector<Edge*> *edges,SegmentIntersector *si,bool testAllSegments);
00224 void computeIntersections(vector<Edge*> *edges0,vector<Edge*> *edges1,SegmentIntersector *si);
00225 protected:
00226 vector<SweepLineEvent*>* events;
00227
00228 int nOverlaps;
00229 private:
00230 void add(vector<Edge*> *edges);
00231 void add(vector<Edge*> *edges,void* edgeSet);
00232 void add(Edge *edge,void* edgeSet);
00233 void prepareEvents();
00234 void computeIntersections(SegmentIntersector *si);
00235 void processOverlaps(int start,int end,SweepLineEvent *ev0,SegmentIntersector *si);
00236 };
00237
00238 class SimpleEdgeSetIntersector: public EdgeSetIntersector {
00239 public:
00240 SimpleEdgeSetIntersector();
00241 void computeIntersections(vector<Edge*> *edges,SegmentIntersector *si,bool testAllSegments);
00242 void computeIntersections(vector<Edge*> *edges0,vector<Edge*> *edges1,SegmentIntersector *si);
00243 private:
00244 int nOverlaps;
00245 void computeIntersects(Edge *e0,Edge *e1,SegmentIntersector *si);
00246 };
00247
00248
00249
00250
00251
00252
00253
00254 class SimpleSweepLineIntersector: public EdgeSetIntersector {
00255 public:
00256 SimpleSweepLineIntersector();
00257 virtual ~SimpleSweepLineIntersector();
00258 void computeIntersections(vector<Edge*> *edges,SegmentIntersector *si,bool testAllSegments);
00259 void computeIntersections(vector<Edge*> *edges0,vector<Edge*> *edges1,SegmentIntersector *si);
00260 private:
00261 void add(vector<Edge*> *edges);
00262 vector<SweepLineEvent*>* events;
00263
00264 int nOverlaps;
00265 void add(vector<Edge*> *edges,void* edgeSet);
00266 void add(Edge *edge,void* edgeSet);
00267 void prepareEvents();
00268 void computeIntersections(SegmentIntersector *si);
00269 void processOverlaps(int start,int end,SweepLineEvent *ev0,SegmentIntersector *si);
00270 };
00271
00272 bool sleLessThen(SweepLineEvent *first,SweepLineEvent *second);
00273 }
00274 #endif