forked from tudelft3d/val3dity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeometryTemplate.cpp
141 lines (114 loc) · 3.18 KB
/
GeometryTemplate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
val3dity
Copyright (c) 2011-2020, 3D geoinformation research group, TU Delft
This file is part of val3dity.
val3dity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
val3dity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with val3dity. If not, see <http://www.gnu.org/licenses/>.
For any information or further details about the use of val3dity, contact
Hugo Ledoux
Faculty of Architecture & the Built Environment
Delft University of Technology
Julianalaan 134, Delft 2628BL, the Netherlands
*/
#include "GeometryTemplate.h"
#include "input.h"
namespace val3dity
{
GeometryTemplate::GeometryTemplate(std::string id) {
_id = id;
_is_valid = -1;
}
GeometryTemplate::~GeometryTemplate() {
}
Primitive3D GeometryTemplate::get_type()
{
return GEOMETRYTEMPLATE;
}
bool GeometryTemplate::validate(double tol_planarity_d2p, double tol_planarity_normals, double tol_overlap)
{
bool isValid = true;
for (auto& p : _lsPrimitives)
{
if (p->validate(tol_planarity_d2p, tol_planarity_normals) == false)
isValid = false;
}
_is_valid = isValid;
return isValid;
}
int GeometryTemplate::is_valid()
{
if ( (_is_valid == 1) && (this->is_empty() == false) && (_errors.empty() == true) )
return 1;
else
return _is_valid;
}
void GeometryTemplate::get_min_bbox(double& x, double& y)
{
x = 0.0;
y = 0.0;
}
void GeometryTemplate::translate_vertices()
{}
bool GeometryTemplate::is_empty()
{
return _lsPrimitives.empty();
}
json GeometryTemplate::get_report_json()
{
json j;
bool isValid = true;
j["type"] = "GeometryTemplate";
if (this->get_id() != "")
j["id"] = this->_id;
else
j["id"] = "none";
// j["numbersolids"] = this->number_of_solids();
j["errors"] = json::array();
for (auto& err : _errors)
{
for (auto& e : _errors[std::get<0>(err)])
{
json jj;
jj["type"] = "Error";
jj["code"] = std::get<0>(err);
jj["description"] = ALL_ERRORS[std::get<0>(err)];
jj["id"] = std::get<0>(e);
jj["info"] = std::get<1>(e);
j["errors"].push_back(jj);
isValid = false;
}
}
for (auto& p : _lsPrimitives)
{
j["primitives"].push_back(p->get_report_json());
if (p->is_valid() == false)
isValid = false;
}
j["validity"] = isValid;
return j;
}
bool GeometryTemplate::add_primitive(Primitive* s) {
_lsPrimitives.push_back(s);
return true;
}
std::set<int> GeometryTemplate::get_unique_error_codes() {
std::set<int> errs = Primitive::get_unique_error_codes();
for (auto& p : _lsPrimitives) {
std::set<int> tmp = p->get_unique_error_codes();
errs.insert(tmp.begin(), tmp.end());
}
return errs;
}
// int GeometryTemplate::number_of_solids() {
// return _lsSolids.size();
// }
} // namespace val3dity