17
17
#include < boost/container/static_vector.hpp>
18
18
#include < boost/range/iterator_range.hpp>
19
19
#include < iostream>
20
+ #include < optional>
20
21
#include < stdexcept>
21
22
#include < tuple>
22
23
#include < unordered_map>
@@ -129,15 +130,7 @@ class Corefine {
129
130
auto first = infos_.begin ();
130
131
while (first != infos_.end ()) {
131
132
auto fi = first->left_fi ;
132
- const auto & f = left_.face (fi);
133
- auto a = left_point_ids_.at (f[0 ].idx ());
134
- auto b = left_point_ids_.at (f[1 ].idx ());
135
- auto c = left_point_ids_.at (f[2 ].idx ());
136
- const auto & pa = points_.at (a);
137
- const auto & pb = points_.at (b);
138
- const auto & pc = points_.at (c);
139
- left_triangulations_.emplace (
140
- fi, Triangulation{Triangle_region::LEFT_FACE, pa, pb, pc, a, b, c});
133
+ left_triangulations_.emplace (fi, std::nullopt);
141
134
142
135
auto last = std::upper_bound (first, infos_.end (), *first, left_fi_less);
143
136
ranges.emplace_back (first, last);
@@ -148,7 +141,17 @@ class Corefine {
148
141
try {
149
142
parallel_do (ranges.begin (), ranges.end (), [&](const auto & range) {
150
143
const auto & any_info = range.front ();
151
- auto & triangulation = left_triangulations_.at (any_info.left_fi );
144
+ auto fi = any_info.left_fi ;
145
+ const auto & f = left_.face (fi);
146
+ auto a = left_point_ids_.at (f[0 ].idx ());
147
+ auto b = left_point_ids_.at (f[1 ].idx ());
148
+ auto c = left_point_ids_.at (f[2 ].idx ());
149
+ const auto & pa = points_.at (a);
150
+ const auto & pb = points_.at (b);
151
+ const auto & pc = points_.at (c);
152
+
153
+ auto & triangulation =
154
+ left_triangulations_.at (fi).emplace (Triangle_region::LEFT_FACE, pa, pb, pc, a, b, c);
152
155
for (const auto & info : range) {
153
156
insert_intersection (triangulation, info);
154
157
}
@@ -167,15 +170,7 @@ class Corefine {
167
170
auto first = infos_.begin ();
168
171
while (first != infos_.end ()) {
169
172
auto fi = first->right_fi ;
170
- const auto & f = right_.face (fi);
171
- auto a = right_point_ids_.at (f[0 ].idx ());
172
- auto b = right_point_ids_.at (f[1 ].idx ());
173
- auto c = right_point_ids_.at (f[2 ].idx ());
174
- const auto & pa = points_.at (a);
175
- const auto & pb = points_.at (b);
176
- const auto & pc = points_.at (c);
177
- right_triangulations_.emplace (
178
- fi, Triangulation{Triangle_region::RIGHT_FACE, pa, pb, pc, a, b, c});
173
+ right_triangulations_.emplace (fi, std::nullopt);
179
174
180
175
auto last = std::upper_bound (first, infos_.end (), *first, right_fi_less);
181
176
ranges.emplace_back (first, last);
@@ -186,7 +181,17 @@ class Corefine {
186
181
try {
187
182
parallel_do (ranges.begin (), ranges.end (), [&](const auto & range) {
188
183
const auto & any_info = range.front ();
189
- auto & triangulation = right_triangulations_.at (any_info.right_fi );
184
+ auto fi = any_info.right_fi ;
185
+ const auto & f = right_.face (fi);
186
+ auto a = right_point_ids_.at (f[0 ].idx ());
187
+ auto b = right_point_ids_.at (f[1 ].idx ());
188
+ auto c = right_point_ids_.at (f[2 ].idx ());
189
+ const auto & pa = points_.at (a);
190
+ const auto & pb = points_.at (b);
191
+ const auto & pc = points_.at (c);
192
+
193
+ auto & triangulation = right_triangulations_.at (any_info.right_fi )
194
+ .emplace (Triangle_region::RIGHT_FACE, pa, pb, pc, a, b, c);
190
195
for (const auto & info : range) {
191
196
insert_intersection (triangulation, info);
192
197
}
@@ -239,9 +244,10 @@ class Corefine {
239
244
};
240
245
241
246
template <class OutputIterator >
242
- void get_triangles (const Triangle_soup& soup, Face_index fi,
243
- const std::unordered_map<Face_index, Triangulation>& triangulations,
244
- const std::vector<std::size_t >& point_ids, OutputIterator tris) const {
247
+ void get_triangles (
248
+ const Triangle_soup& soup, Face_index fi,
249
+ const std::unordered_map<Face_index, std::optional<Triangulation>>& triangulations,
250
+ const std::vector<std::size_t >& point_ids, OutputIterator tris) const {
245
251
auto it = triangulations.find (fi);
246
252
if (it == triangulations.end ()) {
247
253
const auto & f = soup.face (fi);
@@ -250,7 +256,7 @@ class Corefine {
250
256
auto c = point_ids.at (f[2 ].idx ());
251
257
*tris++ = {a, b, c};
252
258
} else {
253
- it->second .get_triangles (tris);
259
+ it->second .value (). get_triangles (tris);
254
260
}
255
261
}
256
262
@@ -276,9 +282,9 @@ class Corefine {
276
282
}
277
283
278
284
const Triangle_soup& left_;
279
- std::unordered_map<Face_index, Triangulation> left_triangulations_;
285
+ std::unordered_map<Face_index, std::optional< Triangulation> > left_triangulations_;
280
286
const Triangle_soup& right_;
281
- std::unordered_map<Face_index, Triangulation> right_triangulations_;
287
+ std::unordered_map<Face_index, std::optional< Triangulation> > right_triangulations_;
282
288
Point_list points_;
283
289
std::vector<std::size_t > left_point_ids_;
284
290
std::vector<std::size_t > right_point_ids_;
0 commit comments