Skip to content

Commit 09939b5

Browse files
committed
Construct triangulations inside parallel_do
1 parent d0f4cf2 commit 09939b5

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ Here are the timings (in seconds) for computing the Boolean intersection between
2323

2424
| Test case | [coref.][coref] (seq.) | [geogram][geogram] (par.) | kigumi (seq.)¹ | kigumi (par.) | [libigl][libigl] (par.)² | [manif.][manif] (seq.)³ | manif. (par.) | [MCUT][mcut] (par.) |
2525
|-------------------|-----------------------:|--------------------------:|---------------:|--------------:|-------------------------:|------------------------:|--------------:|--------------------:|
26-
| **Open** | 4.6 | FAILED | 2.4 | 1.3 | FAILED | FAILED | FAILED | FAILED |
26+
| **Open** | 4.6 | FAILED | 2.3 | 1.2 | FAILED | FAILED | FAILED | FAILED |
2727
| **Open & closed** | FAILED | 70.5 | 1.6 | 0.9 | FAILED | FAILED | FAILED | FAILED |
28-
| **Closed** | 57.4 | FAILED | 5.3 | 2.7 | 61.0 | 8.9 | 1.7 | 24.5 |
29-
| **Non-manifold** | FAILED | FAILED | 0.5 | 0.3 | FAILED | FAILED | FAILED | FAILED |
28+
| **Closed** | 57.4 | FAILED | 5.1 | 2.5 | 61.0 | 8.9 | 1.7 | 24.5 |
29+
| **Non-manifold** | FAILED | FAILED | 0.5 | 0.2 | FAILED | FAILED | FAILED | FAILED |
3030

3131
¹ Ran with `KIGUMI_NUM_THREADS=1`. ² `igl::copyleft::cgal::mesh_boolean` with `CGAL::Lazy_exact_nt<mpq_class>` as the
3232
number type was used. ³ Configured with `-DMANIFOLD_PAR=NONE`.

include/kigumi/Corefine.h

+32-26
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <boost/container/static_vector.hpp>
1818
#include <boost/range/iterator_range.hpp>
1919
#include <iostream>
20+
#include <optional>
2021
#include <stdexcept>
2122
#include <tuple>
2223
#include <unordered_map>
@@ -129,15 +130,7 @@ class Corefine {
129130
auto first = infos_.begin();
130131
while (first != infos_.end()) {
131132
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);
141134

142135
auto last = std::upper_bound(first, infos_.end(), *first, left_fi_less);
143136
ranges.emplace_back(first, last);
@@ -148,7 +141,17 @@ class Corefine {
148141
try {
149142
parallel_do(ranges.begin(), ranges.end(), [&](const auto& range) {
150143
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);
152155
for (const auto& info : range) {
153156
insert_intersection(triangulation, info);
154157
}
@@ -167,15 +170,7 @@ class Corefine {
167170
auto first = infos_.begin();
168171
while (first != infos_.end()) {
169172
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);
179174

180175
auto last = std::upper_bound(first, infos_.end(), *first, right_fi_less);
181176
ranges.emplace_back(first, last);
@@ -186,7 +181,17 @@ class Corefine {
186181
try {
187182
parallel_do(ranges.begin(), ranges.end(), [&](const auto& range) {
188183
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);
190195
for (const auto& info : range) {
191196
insert_intersection(triangulation, info);
192197
}
@@ -239,9 +244,10 @@ class Corefine {
239244
};
240245

241246
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 {
245251
auto it = triangulations.find(fi);
246252
if (it == triangulations.end()) {
247253
const auto& f = soup.face(fi);
@@ -250,7 +256,7 @@ class Corefine {
250256
auto c = point_ids.at(f[2].idx());
251257
*tris++ = {a, b, c};
252258
} else {
253-
it->second.get_triangles(tris);
259+
it->second.value().get_triangles(tris);
254260
}
255261
}
256262

@@ -276,9 +282,9 @@ class Corefine {
276282
}
277283

278284
const Triangle_soup& left_;
279-
std::unordered_map<Face_index, Triangulation> left_triangulations_;
285+
std::unordered_map<Face_index, std::optional<Triangulation>> left_triangulations_;
280286
const Triangle_soup& right_;
281-
std::unordered_map<Face_index, Triangulation> right_triangulations_;
287+
std::unordered_map<Face_index, std::optional<Triangulation>> right_triangulations_;
282288
Point_list points_;
283289
std::vector<std::size_t> left_point_ids_;
284290
std::vector<std::size_t> right_point_ids_;

0 commit comments

Comments
 (0)