GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 0 / 1 / 1
Functions: -% 0 / 1 / 1
Branches: -% 0 / 1 / 1

src/utilities/geometry/Polyhedron.hpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #ifndef UTILITIES_GEOMETRY_POLYHEDRON_HPP
7 #define UTILITIES_GEOMETRY_POLYHEDRON_HPP
8
9 #include "../UtilitiesAPI.hpp"
10 #include "Point3d.hpp"
11
12 #include <vector>
13 #include <boost/optional.hpp>
14
15 namespace openstudio {
16
17 namespace model {
18 class Space;
19 class ThermalZone;
20 } // namespace model
21
22 class Surface3d;
23
24 class UTILITIES_API Surface3dEdge
25 {
26 public:
27 Surface3dEdge(Point3d start, Point3d end, const Surface3d& firstSurface);
28 Surface3dEdge(Point3d start, Point3d end, std::string t_name, size_t t_surfNum);
29
30 const Point3d& start() const;
31 const Point3d& end() const;
32
33 /// check equality: this uses a tolerance
34 bool operator==(const Surface3dEdge& other) const;
35
36 // Asserts that isAlmostEqual3dPt(start, other.end) && isAlmostEqual3dPt(end, other.start)
37 bool reverseEqual(const Surface3dEdge& other) const;
38
39 /// check inequality
40 bool operator!=(const Surface3dEdge& other) const;
41
42 size_t count() const;
43
44 size_t firstSurfNum() const;
45 std::string firstSurfaceName() const;
46 const std::vector<size_t>& allSurfNums() const;
47 void appendSurface(const Surface3d& surface);
48
49 // Checks whether a Point: is not almost equal to the start and end points, and that isPointOnLineBetweenPoints(start, end, testVertex) is true
50 bool containsPoint(const Point3d& testVertex) const;
51
52 void markConflictedOrientation();
53 bool hasConflictedOrientation() const;
54
55 // Indicates this edge has been created and wasn't part of the original surface (cf updateZonePolygonsForMissingColinearPoints)
56 void markCreated();
57 bool hasBeenCreated() const;
58
59 void resetEdgeMatching();
60
61 Vector3d asVector() const;
62
63 // If it containsPoint the testVertex, Split in place the current edge from [start, vertex] vertex and returns the new next [vertex, end]
64 boost::optional<Surface3dEdge> splitEdge(Point3d testVertex);
65
66 private:
67 Point3d m_start;
68 Point3d m_end;
69 bool m_conflictedOrientation = false;
70 bool m_hasBeenCreated = false;
71 std::string m_firstSurfaceName;
72 std::vector<size_t> m_allSurfNums;
73 };
74
75 // A thin wrapper to improve reporting, by attaching a name to the vertices
76 class UTILITIES_API Surface3d
77 {
78 public:
79 Surface3d(std::vector<Point3d> t_vertices, std::string t_name, size_t t_surfNum);
80 std::vector<Point3d> vertices;
81 std::string name;
82 size_t surfNum;
83 std::vector<Surface3dEdge> edges;
84
85 size_t numConflictedEdges() const;
86 double ratioOfConflictedEdges() const;
87
88 // There is no check done whatsoevever to ensure the surface is planar.
89 bool isConvex() const;
90
91 void resetEdgeMatching();
92
93 bool operator<(const Surface3d& rhs) const;
94 };
95
96 class UTILITIES_API Polyhedron
97 {
98 public:
99 /** This will call updateZonePolygonsForMissingColinearPoints if needed (if original Polyhedron isn't enclosed) to add any missing colinear point
100 * (=splitting up edges in case surface intersection hasn't been performed already) */
101 Polyhedron(std::vector<Surface3d> surfaces);
102
103 /** Test if the volume described by the polyhedron if full enclosed (would not leak).
104 * This is done by checking that every edge is used exactly TWICE. */
105 bool isEnclosedVolume() const;
106
107 /** All unique edges that aren't used exactly twice */
108 std::vector<Surface3dEdge> edgesNotTwo(bool includeCreatedEdges = false) const;
109
110 std::vector<Point3d> uniqueVertices() const;
111
112 /** Ignores orientation of edges to return the unique edges */
113 std::vector<Surface3dEdge> uniqueEdges() const;
114
115 size_t numVertices() const;
116
117 // Call calculatedVolume as it will handle the logic to dispatch to inidivual methods based on checks
118 // Note JM 2022-05-23: Actually a lot of the needed logic is in PlanarSurface,
119 // so I don't think it's worth trying to fallback to the other calculation modes E+ does (like checking if floor and roof are same and use that etc)
120 // double calculatedVolume() const;
121
122 // Polyhedron MUST be enclosed
123 double polyhedronVolume() const;
124 // Polyhedron MUST be enclosed
125 double calcDivergenceTheoremVolume() const;
126
127 // Whether updateZonePolygonsForMissingColinearPoints was called and ended up actually splitting up edges
128 bool hasAddedColinearPoints() const;
129
130 /** In an ENCLOSED Polyhedron, all edges should be used twice. And if all surfaces are correctly oriented, each edge should match an edge that is in
131 * reversed order */
132 bool hasAnySurfaceWithIncorrectOrientation() const;
133
134 bool isCompletelyInsideOut() const;
135
136 /** Finds all edges that two surface define in the **same** order (if all surfaces are correctly oriented, they should match in reverse order)
137 * For each matching edge, we pick a single surface between the two surfaces that define it but retainign the surface that has the largest
138 * proportion of conflicted edges / total number of edges */
139 std::vector<Surface3d> findSurfacesWithIncorrectOrientation() const;
140
141 std::vector<Surface3d> surface3ds() const;
142
143 protected:
144 void performEdgeMatching();
145 void resetEdgeMatching();
146 void updateZonePolygonsForMissingColinearPoints();
147 bool hasEdgesNot2() const;
148 // Internal method, result is cached. We have to call it initially to detect if polyhedron is completely inside-out
149 double calcPolyhedronVolume() const;
150
151 private:
152 − REGISTER_LOGGER("utilities.Polyhedron");
153
154 std::vector<Surface3d> m_surfaces;
155 bool m_isEnclosedVolume = false;
156 bool m_hasAddedColinearPoints = false;
157 bool m_hasAnySurfaceWithIncorrectOrientation = false;
158 bool m_isCompletelyInsideOut = false;
159 double m_polyhedronVolume = 0.0;
160 };
161
162 using OptionalSurface3dEdge = boost::optional<Surface3dEdge>;
163 using Surface3dEdgeVector = std::vector<Surface3dEdge>;
164 using Surface3dVector = std::vector<Surface3d>;
165 using PolyhedronVector = std::vector<Polyhedron>;
166
167 /// ostream operator
168 UTILITIES_API std::ostream& operator<<(std::ostream& os, const Surface3dEdge& edge);
169 UTILITIES_API std::ostream& operator<<(std::ostream& os, const Surface3d& surface3d);
170
171 } // namespace openstudio
172
173 #endif // UTILITIES_GEOMETRY_POLYHEDRON_HPP
174