~sharpie/geos/3.3.2

« back to all changes in this revision

Viewing changes to source/operation/overlay/PointBuilder.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabio Tranchitella
  • Date: 2006-11-06 21:35:52 UTC
  • mfrom: (3.1.3 feisty)
  • Revision ID: james.westby@ubuntu.com-20061106213552-m03o92ggj1na737b
Tags: 2.2.3-3
debian/control: move doxygen from build-depends-indep to build-depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**********************************************************************
2
 
 * $Id: PointBuilder.cpp,v 1.13 2004/11/17 15:09:08 strk Exp $
 
2
 * $Id: PointBuilder.cpp,v 1.13.2.2 2005/06/28 01:07:11 strk Exp $
3
3
 *
4
4
 * GEOS - Geometry Engine Open Source
5
5
 * http://geos.refractions.net
26
26
 
27
27
namespace geos {
28
28
 
29
 
PointBuilder::PointBuilder(OverlayOp *newOp, const GeometryFactory *newGeometryFactory,PointLocator *newPtLocator)
 
29
PointBuilder::PointBuilder(OverlayOp *newOp,
 
30
        const GeometryFactory *newGeometryFactory,
 
31
        PointLocator *newPtLocator):
 
32
                op(newOp),
 
33
                geometryFactory(newGeometryFactory),
 
34
                resultPointList(new vector<Point *>())
30
35
{
31
 
        op=newOp;
32
 
        geometryFactory=newGeometryFactory;
33
 
        ptLocator=newPtLocator;
34
36
}
35
37
 
36
38
/*
40
42
vector<Point*>*
41
43
PointBuilder::build(int opCode)
42
44
{
43
 
        vector<Node*>* nodeList=collectNodes(opCode);
44
 
        vector<Point*>* resultPointList=simplifyPoints(nodeList);
45
 
        delete nodeList;
 
45
        extractNonCoveredResultNodes(opCode);
46
46
        return resultPointList;
47
47
}
48
48
 
49
 
vector<Node*>*
50
 
PointBuilder::collectNodes(int opCode)
51
 
{
52
 
        vector<Node*>* resultNodeList=new vector<Node*>();
53
 
        // add nodes from edge intersections which have not already been
54
 
        // included in the result
55
 
        map<Coordinate,Node*,CoordLT> *nodeMap=op->getGraph()->getNodeMap()->nodeMap;
56
 
        map<Coordinate,Node*,CoordLT>::iterator it=nodeMap->begin();
57
 
        for (;it!=nodeMap->end();it++) {
58
 
                Node *node=it->second;
59
 
                if (!node->isInResult()) {
60
 
                        Label *label=node->getLabel();
61
 
                        if (OverlayOp::isResultOfOp(label,opCode)) {
62
 
                                resultNodeList->push_back(node);
63
 
                        }
64
 
                }
65
 
        }
66
 
        return resultNodeList;
67
 
}
68
 
 
69
49
/*
70
 
 * This method simplifies the resultant Geometry by finding and eliminating
71
 
 * "covered" points.
72
 
 * A point is covered if it is contained in another element Geometry
73
 
 * with higher dimension (e.g. a point might be contained in a polygon,
74
 
 * in which case the point can be eliminated from the resultant).
 
50
 * Determines nodes which are in the result, and creates Point for them.
 
51
 *
 
52
 * This method determines nodes which are candidates for the result via their
 
53
 * labelling and their graph topology.
 
54
 *
 
55
 * @param opCode the overlay operation
75
56
 */
76
 
vector<Point*>*
77
 
PointBuilder::simplifyPoints(vector<Node*> *resultNodeList)
 
57
void
 
58
PointBuilder::extractNonCoveredResultNodes(int opCode)
78
59
{
79
 
        vector<Point*>* nonCoveredPointList=new vector<Point*>();
80
 
        for(int i=0;i<(int)resultNodeList->size();i++)
 
60
        map<Coordinate,Node*,CoordLT> *nodeMap =
 
61
                op->getGraph()->getNodeMap()->nodeMap;
 
62
        map<Coordinate,Node*,CoordLT>::iterator it=nodeMap->begin();
 
63
        for (; it!=nodeMap->end(); ++it)
81
64
        {
82
 
                Node *n=(*resultNodeList)[i];
83
 
                const Coordinate& coord=n->getCoordinate();
84
 
                if(!op->isCoveredByLA(coord)) {
85
 
                        Point *pt=geometryFactory->createPoint(coord);
86
 
                        nonCoveredPointList->push_back(pt);
 
65
                Node *n=it->second;
 
66
 
 
67
                // filter out nodes which are known to be in the result
 
68
                if (n->isInResult()) continue;
 
69
 
 
70
                // if an incident edge is in the result, then
 
71
                // the node coordinate is included already
 
72
                if (n->isIncidentEdgeInResult()) continue;
 
73
 
 
74
                if ( n->getEdges()->getDegree() == 0 ||
 
75
                        opCode == OverlayOp::INTERSECTION )
 
76
                {
 
77
 
 
78
                        /**
 
79
                         * For nodes on edges, only INTERSECTION can result 
 
80
                         * in edge nodes being included even
 
81
                         * if none of their incident edges are included
 
82
                         */
 
83
                        Label *label=n->getLabel();
 
84
                        if (OverlayOp::isResultOfOp(label,opCode)) 
 
85
                                filterCoveredNodeToPoint(n);
87
86
                }
88
87
        }
89
 
        return nonCoveredPointList;
 
88
}
 
89
 
 
90
void
 
91
PointBuilder::filterCoveredNodeToPoint(const Node *n)
 
92
{
 
93
        const Coordinate& coord=n->getCoordinate();
 
94
        if(!op->isCoveredByLA(coord)) {
 
95
                Point *pt=geometryFactory->createPoint(coord);
 
96
                resultPointList->push_back(pt);
 
97
        }
90
98
}
91
99
 
92
100
} // namespace geos
93
101
 
94
102
/**********************************************************************
95
103
 * $Log: PointBuilder.cpp,v $
 
104
 * Revision 1.13.2.2  2005/06/28 01:07:11  strk
 
105
 * improved extraction of result points in overlay op
 
106
 *
 
107
 * Revision 1.13.2.1  2005/06/26 09:40:19  strk
 
108
 * Backport of OverlayOp performance improvements
 
109
 *
96
110
 * Revision 1.13  2004/11/17 15:09:08  strk
97
111
 * Changed COMPUTE_Z defaults to be more conservative
98
112
 *