File size: 2,828 Bytes
8be366a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | /**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: noding/IteratedNoder.java r591 (JTS-1.12+)
*
**********************************************************************/
#include <sstream>
#include <vector>
#include <geos/profiler.h>
#include <geos/util/TopologyException.h>
#include <geos/noding/IteratedNoder.h>
#include <geos/noding/SegmentString.h>
#include <geos/noding/MCIndexNoder.h>
#include <geos/noding/IntersectionAdder.h>
#ifndef GEOS_DEBUG
#define GEOS_DEBUG 0
#endif
using namespace std;
using namespace geos::geom;
namespace geos {
namespace noding { // geos.noding
/* private */
void
IteratedNoder::node(vector<SegmentString*> *segStrings,
int *numInteriorIntersections)
{
IntersectionAdder si(li);
MCIndexNoder noder;
noder.setSegmentIntersector(&si);
noder.computeNodes(segStrings);
nodedSegStrings = noder.getNodedSubstrings();
*numInteriorIntersections = si.numInteriorIntersections;
//System.out.println("# intersection tests: " + si.numTests);
}
/* public */
void
IteratedNoder::computeNodes(SegmentString::NonConstVect* segStrings)
// throw(GEOSException);
{
int numInteriorIntersections;
nodedSegStrings = segStrings;
int nodingIterationCount = 0;
int lastNodesCreated = -1;
vector<SegmentString*> *lastStrings = 0;
do {
// NOTE: will change this.nodedSegStrings
node(nodedSegStrings, &numInteriorIntersections);
// Delete noded strings from previous iteration
if ( lastStrings ) {
for ( unsigned int i = 0, n = lastStrings->size(); i < n; ++i )
delete (*lastStrings)[i];
delete lastStrings;
}
lastStrings = nodedSegStrings;
nodingIterationCount++;
int nodesCreated = numInteriorIntersections;
/**
* Fail if the number of nodes created is not declining.
* However, allow a few iterations at least before doing this
*/
//cerr<<"# nodes created: "<<nodesCreated<<endl;
if (lastNodesCreated > 0
&& nodesCreated >= lastNodesCreated
&& nodingIterationCount > maxIter)
{
stringstream s;
s<<"Iterated noding failed to converge after "<<
nodingIterationCount << " iterations";
throw util::TopologyException(s.str());
}
lastNodesCreated = nodesCreated;
} while (lastNodesCreated > 0);
//cerr<<"# nodings = "<<nodingIterationCount<<endl;
}
} // namespace geos.noding
} // namespace geos
|