/src/geos/include/geos/geomgraph/Node.h
Line | Count | Source |
1 | | /********************************************************************** |
2 | | * |
3 | | * GEOS - Geometry Engine Open Source |
4 | | * http://geos.osgeo.org |
5 | | * |
6 | | * Copyright (C) 2011 Sandro Santilli <strk@kbt.io> |
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: geomgraph/Node.java r411 (JTS-1.12+) |
18 | | * |
19 | | **********************************************************************/ |
20 | | |
21 | | |
22 | | #pragma once |
23 | | |
24 | | #include <geos/export.h> |
25 | | #include <geos/geomgraph/GraphComponent.h> // for inheritance |
26 | | #include <geos/geom/Coordinate.h> // for member |
27 | | |
28 | | #ifndef NDEBUG |
29 | | #include <geos/geomgraph/EdgeEndStar.h> // for testInvariant |
30 | | #include <geos/geomgraph/EdgeEnd.h> // for testInvariant |
31 | | #endif // ndef NDEBUG |
32 | | |
33 | | #include <cassert> |
34 | | #include <string> |
35 | | |
36 | | #ifdef _MSC_VER |
37 | | #pragma warning(push) |
38 | | #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class |
39 | | #endif |
40 | | |
41 | | // Forward declarations |
42 | | namespace geos { |
43 | | namespace geom { |
44 | | class IntersectionMatrix; |
45 | | } |
46 | | namespace geomgraph { |
47 | | class Node; |
48 | | class EdgeEndStar; |
49 | | class EdgeEnd; |
50 | | class Label; |
51 | | class NodeFactory; |
52 | | } |
53 | | } |
54 | | |
55 | | namespace geos { |
56 | | namespace geomgraph { // geos.geomgraph |
57 | | |
58 | | /** \brief The node component of a geometry graph. */ |
59 | | class GEOS_DLL Node /* non-final */: public GraphComponent { |
60 | | using GraphComponent::setLabel; |
61 | | |
62 | | public: |
63 | | |
64 | | friend std::ostream& operator<< (std::ostream& os, const Node& node); |
65 | | |
66 | | Node(const geom::Coordinate& newCoord, EdgeEndStar* newEdges); |
67 | | |
68 | | ~Node() override; |
69 | | |
70 | | const geom::Coordinate& getCoordinate() const; |
71 | | |
72 | | EdgeEndStar* getEdges(); |
73 | | |
74 | | bool isIsolated() const override; |
75 | | |
76 | | /** \brief |
77 | | * Add the edge to the list of edges at this node |
78 | | */ |
79 | | void add(EdgeEnd* e); |
80 | | |
81 | | void mergeLabel(const Node& n); |
82 | | |
83 | | /** \brief |
84 | | * To merge labels for two nodes, |
85 | | * the merged location for each LabelElement is computed. |
86 | | * |
87 | | * The location for the corresponding node LabelElement is set |
88 | | * to the result, as long as the location is non-null. |
89 | | */ |
90 | | void mergeLabel(const Label& label2); |
91 | | |
92 | | void setLabel(uint8_t argIndex, geom::Location onLocation); |
93 | | |
94 | | /** \brief |
95 | | * Updates the label of a node to BOUNDARY, |
96 | | * obeying the mod-2 boundaryDetermination rule. |
97 | | */ |
98 | | void setLabelBoundary(uint8_t argIndex); |
99 | | |
100 | | /** |
101 | | * The location for a given eltIndex for a node will be one |
102 | | * of { null, INTERIOR, BOUNDARY }. |
103 | | * A node may be on both the boundary and the interior of a geometry; |
104 | | * in this case, the rule is that the node is considered to be |
105 | | * in the boundary. |
106 | | * The merged location is the maximum of the two input values. |
107 | | */ |
108 | | geom::Location computeMergedLocation(const Label& label2, uint8_t eltIndex); |
109 | | |
110 | | std::string print() const; |
111 | | |
112 | | const std::vector<double>& getZ() const; |
113 | | |
114 | | void addZ(double); |
115 | | |
116 | | /** \brief |
117 | | * Tests whether any incident edge is flagged as |
118 | | * being in the result. |
119 | | * |
120 | | * This test can be used to determine if the node is in the result, |
121 | | * since if any incident edge is in the result, the node must be in |
122 | | * the result as well. |
123 | | * |
124 | | * @return <code>true</code> if any indicident edge in the in |
125 | | * the result |
126 | | */ |
127 | | bool isIncidentEdgeInResult() const; |
128 | | |
129 | | protected: |
130 | | |
131 | | void testInvariant() const; |
132 | | |
133 | | geom::Coordinate coord; |
134 | | |
135 | | EdgeEndStar* edges; |
136 | | |
137 | | /** \brief |
138 | | * Basic nodes do not compute IMs |
139 | | */ |
140 | | void |
141 | 0 | computeIM(geom::IntersectionMatrix& /*im*/) override {} |
142 | | |
143 | | private: |
144 | | |
145 | | std::vector<double> zvals; |
146 | | |
147 | | double ztot; |
148 | | |
149 | | }; |
150 | | |
151 | | std::ostream& operator<< (std::ostream& os, const Node& node); |
152 | | |
153 | | inline void |
154 | | Node::testInvariant() const |
155 | 112M | { |
156 | | #ifndef NDEBUG |
157 | | if(edges) { |
158 | | // Each EdgeEnd in the star has this Node's |
159 | | // coordinate as first coordinate |
160 | | for(EdgeEndStar::iterator |
161 | | it = edges->begin(), itEnd = edges->end(); |
162 | | it != itEnd; it++) { |
163 | | EdgeEnd* e = *it; |
164 | | assert(e); |
165 | | assert(e->getCoordinate().equals2D(coord)); |
166 | | } |
167 | | } |
168 | | |
169 | | #if 0 |
170 | | // We can't rely on numerical stability with FP computations |
171 | | // ztot is the sum of doubnle sin zvals vector |
172 | | double ztot_check = 0.0; |
173 | | for(std::vector<double>::const_iterator |
174 | | i = zvals.begin(), e = zvals.end(); |
175 | | i != e; |
176 | | i++) { |
177 | | ztot_check += *i; |
178 | | } |
179 | | assert(ztot_check == ztot); |
180 | | #endif // 0 |
181 | | |
182 | | #endif |
183 | 112M | } |
184 | | |
185 | | |
186 | | } // namespace geos.geomgraph |
187 | | } // namespace geos |
188 | | |
189 | | #ifdef _MSC_VER |
190 | | #pragma warning(pop) |
191 | | #endif |
192 | | |