GEOS  3.8.0dev
geomgraph/Node.h
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 #ifndef GEOS_GEOMGRAPH_NODE_H
23 #define GEOS_GEOMGRAPH_NODE_H
24 
25 #include <geos/export.h>
26 #include <geos/geomgraph/GraphComponent.h> // for inheritance
27 #include <geos/geom/Coordinate.h> // for member
28 
29 #ifndef NDEBUG
30 #include <geos/geomgraph/EdgeEndStar.h> // for testInvariant
31 #include <geos/geomgraph/EdgeEnd.h> // for testInvariant
32 #endif // ndef NDEBUG
33 
34 #include <geos/inline.h>
35 
36 #include <cassert>
37 #include <string>
38 
39 #ifdef _MSC_VER
40 #pragma warning(push)
41 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
42 #endif
43 
44 // Forward declarations
45 namespace geos {
46 namespace geom {
47 class IntersectionMatrix;
48 }
49 namespace geomgraph {
50 class Node;
51 class EdgeEndStar;
52 class EdgeEnd;
53 class Label;
54 class NodeFactory;
55 }
56 }
57 
58 namespace geos {
59 namespace geomgraph { // geos.geomgraph
60 
62 class GEOS_DLL Node: public GraphComponent {
63  using GraphComponent::setLabel;
64 
65 public:
66 
67  friend std::ostream& operator<< (std::ostream& os, const Node& node);
68 
69  Node(const geom::Coordinate& newCoord, EdgeEndStar* newEdges);
70 
71  ~Node() override;
72 
73  virtual const geom::Coordinate& getCoordinate() const;
74 
75  virtual EdgeEndStar* getEdges();
76 
77  bool isIsolated() const override;
78 
82  virtual void add(EdgeEnd* e);
83 
84  virtual void mergeLabel(const Node& n);
85 
93  virtual void mergeLabel(const Label& label2);
94 
95  virtual void setLabel(int argIndex, geom::Location onLocation);
96 
101  virtual void setLabelBoundary(int argIndex);
102 
111  virtual geom::Location computeMergedLocation(const Label& label2, int eltIndex);
112 
113  virtual std::string print();
114 
115  virtual const std::vector<double>& getZ() const;
116 
117  virtual void addZ(double);
118 
130  virtual bool isIncidentEdgeInResult() const;
131 
132 protected:
133 
134  void testInvariant() const;
135 
136  geom::Coordinate coord;
137 
138  EdgeEndStar* edges;
139 
143  void
144  computeIM(geom::IntersectionMatrix& /*im*/) override {}
145 
146 private:
147 
148  std::vector<double> zvals;
149 
150  double ztot;
151 
152 };
153 
154 std::ostream& operator<< (std::ostream& os, const Node& node);
155 
156 inline void
157 Node::testInvariant() const
158 {
159 #ifndef NDEBUG
160  if(edges) {
161  // Each EdgeEnd in the star has this Node's
162  // coordinate as first coordinate
163  for(EdgeEndStar::iterator
164  it = edges->begin(), itEnd = edges->end();
165  it != itEnd; it++) {
166  EdgeEnd* e = *it;
167  assert(e);
168  assert(e->getCoordinate().equals2D(coord));
169  }
170  }
171 
172 #if 0 // We can't rely on numerical stability with FP computations
173  // ztot is the sum of doubnle sin zvals vector
174  double ztot_check = 0.0;
175  for(std::vector<double>::const_iterator
176  i = zvals.begin(), e = zvals.end();
177  i != e;
178  i++) {
179  ztot_check += *i;
180  }
181  assert(ztot_check == ztot);
182 #endif // 0
183 
184 #endif
185 }
186 
187 
188 } // namespace geos.geomgraph
189 } // namespace geos
190 
191 //#ifdef GEOS_INLINE
192 //# include "geos/geomgraph/Node.inl"
193 //#endif
194 
195 #ifdef _MSC_VER
196 #pragma warning(pop)
197 #endif
198 
199 #endif // ifndef GEOS_GEOMGRAPH_NODE_H
A EdgeEndStar is an ordered list of EdgeEnds around a node.
Definition: EdgeEndStar.h:65
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
void computeIM(geom::IntersectionMatrix &) override
Basic nodes do not compute IMs.
Definition: geomgraph/Node.h:144
Implementation of Dimensionally Extended Nine-Intersection Model (DE-9IM) matrix. ...
Definition: IntersectionMatrix.h:54
Models the end of an edge incident on a node.
Definition: EdgeEnd.h:56
Location
Constants representing the location of a point relative to a geometry.
Definition: Location.h:33
A Label indicates the topological relationship of a component of a topology graph to a given Geometry...
Definition: Label.h:58
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
Definition: geomgraph/Node.h:62
A GraphComponent is the parent class for the objects' that form a graph.
Definition: geomgraph/GraphComponent.h:47