root/MGET/Branches/Jason/Libraries/geos-3.3.2/src/operation/valid/ConsistentAreaTester.cpp @ 891

Revision 891, 4.6 KB (checked in by jjr8, 17 months ago)

* Incremented build number.
* Added Libraries/geos-3.3.2

Line 
1/**********************************************************************
2 * $Id: ConsistentAreaTester.cpp 2547 2009-06-05 13:41:50Z strk $
3 *
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
6 *
7 * Copyright (C) 2005-2006 Refractions Research Inc.
8 * Copyright (C) 2001-2002 Vivid Solutions Inc.
9 *
10 * This is free software; you can redistribute and/or modify it under
11 * the terms of the GNU Lesser General Public Licence as published
12 * by the Free Software Foundation.
13 * See the COPYING file for more information.
14 *
15 **********************************************************************
16 *
17 * Last port: operation/valid/ConsistentAreaTester.java rev. 1.14 (JTS-1.10)
18 *
19 **********************************************************************/
20
21#include <geos/operation/valid/ConsistentAreaTester.h>
22#include <geos/algorithm/LineIntersector.h>
23#include <geos/geomgraph/GeometryGraph.h>
24#include <geos/geomgraph/EdgeEnd.h>
25#include <geos/geomgraph/EdgeEndStar.h>
26#include <geos/geomgraph/Edge.h>
27#include <geos/geomgraph/index/SegmentIntersector.h>
28#include <geos/geom/Coordinate.h>
29#include <geos/operation/relate/RelateNodeGraph.h>
30#include <geos/operation/relate/RelateNode.h>
31#include <geos/operation/relate/EdgeEndBundle.h>
32
33#include <memory> // auto_ptr
34#include <cassert>
35
36using namespace std;
37using namespace geos::algorithm;
38using namespace geos::geomgraph;
39using namespace geos::geom;
40
41namespace geos {
42namespace operation { // geos.operation
43namespace valid { // geos.operation.valid
44
45ConsistentAreaTester::ConsistentAreaTester(GeometryGraph *newGeomGraph)
46        :
47        li(),
48        geomGraph(newGeomGraph),
49        nodeGraph(),
50        invalidPoint()
51{
52}
53
54ConsistentAreaTester::~ConsistentAreaTester()
55{
56}
57
58Coordinate&
59ConsistentAreaTester::getInvalidPoint()
60{
61        return invalidPoint;
62}
63
64bool
65ConsistentAreaTester::isNodeConsistentArea()
66{
67        using geomgraph::index::SegmentIntersector;
68
69        /**
70         * To fully check validity, it is necessary to
71         * compute ALL intersections, including self-intersections within a single edge.
72         */
73        auto_ptr<SegmentIntersector> intersector(geomGraph->computeSelfNodes(&li, true));
74        if (intersector->hasProperIntersection()) {
75                invalidPoint=intersector->getProperIntersectionPoint();
76                return false;
77        }
78        nodeGraph.build(geomGraph);
79        return isNodeEdgeAreaLabelsConsistent();
80}
81
82/*private*/
83bool
84ConsistentAreaTester::isNodeEdgeAreaLabelsConsistent()
85{
86        assert(geomGraph);
87
88        map<Coordinate*,Node*,CoordinateLessThen>& nMap=nodeGraph.getNodeMap();
89        map<Coordinate*,Node*,CoordinateLessThen>::iterator nodeIt;
90        for(nodeIt=nMap.begin();nodeIt!=nMap.end();nodeIt++) {
91                relate::RelateNode *node=static_cast<relate::RelateNode*>(nodeIt->second);
92                if (!node->getEdges()->isAreaLabelsConsistent(*geomGraph)) {
93                        invalidPoint=node->getCoordinate();
94                        return false;
95                }
96        }
97        return true;
98}
99
100/*public*/
101bool
102ConsistentAreaTester::hasDuplicateRings()
103{
104        map<Coordinate*,Node*,CoordinateLessThen>& nMap=nodeGraph.getNodeMap();
105        map<Coordinate*,Node*,CoordinateLessThen>::iterator nodeIt;
106        for(nodeIt=nMap.begin(); nodeIt!=nMap.end(); ++nodeIt)
107        {
108                assert(dynamic_cast<relate::RelateNode*>(nodeIt->second));
109                relate::RelateNode *node=static_cast<relate::RelateNode*>(nodeIt->second);
110                EdgeEndStar *ees=node->getEdges();
111                EdgeEndStar::iterator endIt=ees->end();
112                for(EdgeEndStar::iterator it=ees->begin(); it!=endIt; ++it)
113                {
114                        assert(dynamic_cast<relate::EdgeEndBundle*>(*it));
115                        relate::EdgeEndBundle *eeb=static_cast<relate::EdgeEndBundle*>(*it);
116                        if (eeb->getEdgeEnds()->size()>1) {
117                                invalidPoint=eeb->getEdge()->getCoordinate(0);
118                                return true;
119                        }
120                }
121        }
122        return false;
123}
124
125} // namespace geos.operation.valid
126} // namespace geos.operation
127} // namespace geos
128
129/**********************************************************************
130 * $Log$
131 * Revision 1.17  2006/03/27 10:37:59  strk
132 * Reduced heap allocations and probability of error by making LineIntersector
133 * and RelateNodeGraph part of ConsistentAreaTester class .
134 *
135 * Revision 1.16  2006/03/21 13:11:29  strk
136 * opRelate.h header split
137 *
138 * Revision 1.15  2006/03/20 16:57:44  strk
139 * spatialindex.h and opValid.h headers split
140 *
141 * Revision 1.14  2006/03/17 16:48:55  strk
142 * LineIntersector and PointLocator made complete components of RelateComputer
143 * (were statics const pointers before). Reduced inclusions from opRelate.h
144 * and opValid.h, updated .cpp files to allow build.
145 *
146 * Revision 1.13  2006/03/09 16:46:49  strk
147 * geos::geom namespace definition, first pass at headers split
148 **********************************************************************/
149
Note: See TracBrowser for help on using the browser.