GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 73.1% 95 / 0 / 130
Functions: 60.0% 15 / 0 / 25
Branches: 71.4% 125 / 0 / 175

src/gltf/GltfBoundingBox.cpp
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 #include "GltfBoundingBox.hpp"
7 #include "../model/PlanarSurfaceGroup.hpp"
8
9 #include "../utilities/geometry/BoundingBox.hpp"
10 #include "../utilities/geometry/Point3d.hpp"
11 #include "../utilities/geometry/Transformation.hpp"
12
13 #include <boost/optional.hpp>
14 #include <tiny_gltf.h>
15
16 #include <map>
17 #include <string>
18
19 namespace openstudio {
20 namespace gltf {
21
22 49 GltfBoundingBox::GltfBoundingBox() = default;
23
24 21 GltfBoundingBox::GltfBoundingBox(const std::vector<model::PlanarSurfaceGroup>& planarSurfaceGroups) {
25
26 // Bounding Box
27 21 BoundingBox boundingBox;
28
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 boundingBox.addPoint(Point3d(0, 0, 0));
29
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 boundingBox.addPoint(Point3d(1, 1, 1));
30
2/2
✓ Branch 4 taken 1326 times.
✓ Branch 5 taken 21 times.
1347 for (const auto& group : planarSurfaceGroups) {
31
4/4
✓ Branch 1 taken 1326 times.
✓ Branch 4 taken 1326 times.
✓ Branch 7 taken 1326 times.
✓ Branch 10 taken 1326 times.
1326 boundingBox.add(group.transformation() * group.boundingBox());
32 }
33
34 21 double lookAtX = 0; // (boundingBox.minX().get() + boundingBox.maxX().get()) / 2.0
35 21 double lookAtY = 0; // (boundingBox.minY().get() + boundingBox.maxY().get()) / 2.0
36 21 double lookAtZ = 0; // (boundingBox.minZ().get() + boundingBox.maxZ().get()) / 2.0
37 double lookAtR =
38
6/6
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 8 taken 21 times.
✓ Branch 11 taken 21 times.
✓ Branch 15 taken 21 times.
✓ Branch 18 taken 21 times.
21 sqrt(std::pow(boundingBox.maxX().get() / 2.0, 2) + std::pow(boundingBox.maxY().get() / 2.0, 2) + std::pow(boundingBox.maxZ().get() / 2.0, 2));
39
4/4
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 8 taken 21 times.
✓ Branch 11 taken 21 times.
42 lookAtR = std::max(lookAtR, sqrt(std::pow(boundingBox.minX().get() / 2.0, 2) + std::pow(boundingBox.maxY().get() / 2.0, 2)
40
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 + std::pow(boundingBox.maxZ().get() / 2.0, 2)));
41
4/4
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 8 taken 21 times.
✓ Branch 11 taken 21 times.
42 lookAtR = std::max(lookAtR, sqrt(std::pow(boundingBox.maxX().get() / 2.0, 2) + std::pow(boundingBox.minY().get() / 2.0, 2)
42
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 + std::pow(boundingBox.maxZ().get() / 2.0, 2)));
43
4/4
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 8 taken 21 times.
✓ Branch 11 taken 21 times.
42 lookAtR = std::max(lookAtR, sqrt(std::pow(boundingBox.maxX().get() / 2.0, 2) + std::pow(boundingBox.maxY().get() / 2.0, 2)
44
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 + std::pow(boundingBox.minZ().get() / 2.0, 2)));
45
4/4
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 8 taken 21 times.
✓ Branch 11 taken 21 times.
42 lookAtR = std::max(lookAtR, sqrt(std::pow(boundingBox.minX().get() / 2.0, 2) + std::pow(boundingBox.minY().get() / 2.0, 2)
46
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 + std::pow(boundingBox.maxZ().get() / 2.0, 2)));
47
4/4
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 8 taken 21 times.
✓ Branch 11 taken 21 times.
42 lookAtR = std::max(lookAtR, sqrt(std::pow(boundingBox.minX().get() / 2.0, 2) + std::pow(boundingBox.maxY().get() / 2.0, 2)
48
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 + std::pow(boundingBox.minZ().get() / 2.0, 2)));
49
4/4
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 8 taken 21 times.
✓ Branch 11 taken 21 times.
42 lookAtR = std::max(lookAtR, sqrt(std::pow(boundingBox.maxX().get() / 2.0, 2) + std::pow(boundingBox.minY().get() / 2.0, 2)
50
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 + std::pow(boundingBox.minZ().get() / 2.0, 2)));
51
4/4
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 8 taken 21 times.
✓ Branch 11 taken 21 times.
42 lookAtR = std::max(lookAtR, sqrt(std::pow(boundingBox.minX().get() / 2.0, 2) + std::pow(boundingBox.minY().get() / 2.0, 2)
52
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 + std::pow(boundingBox.minZ().get() / 2.0, 2)));
53
54 21 m_lookAtR = lookAtR;
55 21 m_lookAtX = lookAtX;
56 21 m_lookAtY = lookAtY;
57 21 m_lookAtZ = lookAtZ;
58
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_maxX = boundingBox.maxX().get();
59
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_maxY = boundingBox.maxY().get();
60
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_maxZ = boundingBox.maxZ().get();
61
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_minX = boundingBox.minX().get();
62
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_minY = boundingBox.minY().get();
63
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_minZ = boundingBox.minZ().get();
64 21 }
65
66 1 double GltfBoundingBox::lookAtR() const {
67 1 return m_lookAtR;
68 }
69 ✗ void GltfBoundingBox::setLookAtR(double lookAtR) {
70 ✗ m_lookAtR = lookAtR;
71 ✗ };
72
73 1 double GltfBoundingBox::lookAtX() const {
74 1 return m_lookAtX;
75 }
76 ✗ void GltfBoundingBox::setLookAtX(double lookAtX) {
77 ✗ m_lookAtX = lookAtX;
78 ✗ };
79
80 1 double GltfBoundingBox::lookAtY() const {
81 1 return m_lookAtY;
82 }
83 ✗ void GltfBoundingBox::setLookAtY(double lookAtY) {
84 ✗ m_lookAtY = lookAtY;
85 ✗ };
86
87 1 double GltfBoundingBox::lookAtZ() const {
88 1 return m_lookAtZ;
89 }
90 ✗ void GltfBoundingBox::setLookAtZ(double lookAtZ) {
91 ✗ m_lookAtZ = lookAtZ;
92 ✗ };
93
94 1 double GltfBoundingBox::maxX() const {
95 1 return m_maxX;
96 }
97 ✗ void GltfBoundingBox::setMaxX(double maxX) {
98 ✗ m_maxX = maxX;
99 ✗ };
100
101 1 double GltfBoundingBox::maxY() const {
102 1 return m_maxY;
103 }
104 ✗ void GltfBoundingBox::setMaxY(double maxY) {
105 ✗ m_maxY = maxY;
106 ✗ };
107
108 1 double GltfBoundingBox::maxZ() const {
109 1 return m_maxZ;
110 }
111 ✗ void GltfBoundingBox::setMaxZ(double maxZ) {
112 ✗ m_maxZ = maxZ;
113 ✗ };
114
115 1 double GltfBoundingBox::minX() const {
116 1 return m_minX;
117 }
118 ✗ void GltfBoundingBox::setMinX(double minX) {
119 ✗ m_minX = minX;
120 ✗ };
121
122 1 double GltfBoundingBox::minY() const {
123 1 return m_minY;
124 }
125 ✗ void GltfBoundingBox::setMinY(double minY) {
126 ✗ m_minY = minY;
127 ✗ };
128
129 1 double GltfBoundingBox::minZ() const {
130 1 return m_minZ;
131 }
132 ✗ void GltfBoundingBox::setMinZ(double minZ) {
133 ✗ m_minZ = minZ;
134 ✗ };
135
136 21 std::map<std::string, tinygltf::Value> GltfBoundingBox::toExtras() const {
137 return {
138 21 {"lookAtR", tinygltf::Value(m_lookAtR)}, {"lookAtX", tinygltf::Value(m_lookAtX)}, {"lookAtY", tinygltf::Value(m_lookAtY)},
139 21 {"lookAtZ", tinygltf::Value(m_lookAtZ)}, {"maxX", tinygltf::Value(m_maxX)}, {"maxY", tinygltf::Value(m_maxY)},
140 21 {"maxZ", tinygltf::Value(m_maxZ)}, {"minX", tinygltf::Value(m_minX)}, {"minY", tinygltf::Value(m_minY)},
141 21 {"minZ", tinygltf::Value(m_minZ)},
142
3/5
✓ Branch 1 taken 21 times.
✓ Branch 3 taken 210 times.
✓ Branch 4 taken 21 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
273 };
143 21 }
144
145 1 GltfBoundingBox::GltfBoundingBox(const tinygltf::Value& boundingBoxObj) {
146
147
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1 if (!boundingBoxObj.IsObject()) {
148 ✗ LOG_AND_THROW("boundingBoxObj is not a tinygltf Object.");
149 }
150
151
2/2
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 1 time.
11 for (const auto& key : {"lookAtR", "lookAtX", "lookAtY", "lookAtZ", "maxX", "maxY", "maxZ", "minX", "minY", "minZ"}) {
152
3/4
✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10 times.
20 if (!boundingBoxObj.Has(key)) {
153 ✗ LOG(Debug, "boundingBoxObj is missing the key " << key);
154 }
155 }
156
157 10 auto tryGetDoubleFromkey = [&boundingBoxObj](const std::string& key) -> boost::optional<double> {
158
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 if (boundingBoxObj.Has(key)) {
159
2/2
✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
10 auto val = boundingBoxObj.Get(key);
160
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 if (val.IsReal()) {
161
1/1
✓ Branch 2 taken 10 times.
10 return val.Get<double>();
162 } else {
163 ✗ LOG(Warn, "boundingBoxObj has the key '" << key << "' but it is not a double");
164 }
165
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 } else {
166 ✗ LOG(Debug, "boundingBoxObj is missing the key '" << key << "'");
167 }
168 ✗ return boost::none;
169 1 };
170
171
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
3 if (auto d_ = tryGetDoubleFromkey("lookAtR")) {
172
1/1
✓ Branch 1 taken 1 time.
1 m_lookAtR = d_.get();
173 }
174
175
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
3 if (auto d_ = tryGetDoubleFromkey("lookAtX")) {
176
1/1
✓ Branch 1 taken 1 time.
1 m_lookAtX = d_.get();
177 }
178
179
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
3 if (auto d_ = tryGetDoubleFromkey("lookAtY")) {
180
1/1
✓ Branch 1 taken 1 time.
1 m_lookAtY = d_.get();
181 }
182
183
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
3 if (auto d_ = tryGetDoubleFromkey("lookAtZ")) {
184
1/1
✓ Branch 1 taken 1 time.
1 m_lookAtZ = d_.get();
185 }
186
187
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
3 if (auto d_ = tryGetDoubleFromkey("maxX")) {
188
1/1
✓ Branch 1 taken 1 time.
1 m_maxX = d_.get();
189 }
190
191
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
3 if (auto d_ = tryGetDoubleFromkey("maxY")) {
192
1/1
✓ Branch 1 taken 1 time.
1 m_maxY = d_.get();
193 }
194
195
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
3 if (auto d_ = tryGetDoubleFromkey("maxZ")) {
196
1/1
✓ Branch 1 taken 1 time.
1 m_maxZ = d_.get();
197 }
198
199
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
3 if (auto d_ = tryGetDoubleFromkey("minX")) {
200
1/1
✓ Branch 1 taken 1 time.
1 m_minX = d_.get();
201 }
202
203
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
3 if (auto d_ = tryGetDoubleFromkey("minY")) {
204
1/1
✓ Branch 1 taken 1 time.
1 m_minY = d_.get();
205 }
206
207
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
3 if (auto d_ = tryGetDoubleFromkey("minZ")) {
208
1/1
✓ Branch 1 taken 1 time.
1 m_minZ = d_.get();
209 }
210 1 }
211
212 } // namespace gltf
213 } // namespace openstudio
214