Skip to content

Commit

Permalink
Remove Find_border_edges
Browse files Browse the repository at this point in the history
  • Loading branch information
unageek committed Sep 10, 2024
1 parent 50c1458 commit 24747ac
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 85 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Here are the timings (in seconds) for computing the Boolean intersection between

| Test case | [coref.][coref] (seq.) | [geogram][geogram] (par.) | kigumi (seq.)¹ | kigumi (par.) | [manif.][manif] (seq.) | manif. (par.)² |
|-------------------|-----------------------:|--------------------------:|---------------:|--------------:|-----------------------:|---------------:|
| **Open** | 4.6 | FAILED | 2.8 | 1.7 | FAILED | FAILED |
| **Open & closed** | FAILED | 70.5 | 2.0 | 1.3 | FAILED | FAILED |
| **Closed** | 57.4 | FAILED | 6.4 | 3.4 | 8.9 | 1.7 |
| **Open** | 4.6 | FAILED | 2.5 | 1.4 | FAILED | FAILED |
| **Open & closed** | FAILED | 70.5 | 1.7 | 1.0 | FAILED | FAILED |
| **Closed** | 57.4 | FAILED | 5.5 | 2.8 | 8.9 | 1.7 |
| **Non-manifold** | FAILED | FAILED | 0.5 | 0.3 | FAILED | FAILED |

¹ Ran with `KIGUMI_NUM_THREADS=1`. ² Configured with `-DMANIFOLD_PAR=TBB`.
Expand Down
50 changes: 35 additions & 15 deletions include/kigumi/Corefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <kigumi/Find_coplanar_faces.h>
#include <kigumi/Find_possibly_intersecting_faces.h>
#include <kigumi/Intersection_point_inserter.h>
#include <kigumi/Mesh_entities.h>
#include <kigumi/Mesh_indices.h>
#include <kigumi/Point_list.h>
#include <kigumi/Triangle_region.h>
Expand Down Expand Up @@ -57,8 +58,6 @@ class Corefine {

std::cout << "Finding symbolic intersections..." << std::endl;

std::vector<Intersection_info> infos;

std::size_t num_intersections{};
parallel_do(
pairs.begin(), pairs.end(), std::pair<std::vector<Intersection_info>, std::size_t>{},
Expand All @@ -84,10 +83,10 @@ class Corefine {
},
[&](auto& local_state) {
auto& [local_infos, local_num_intersections] = local_state;
if (infos.empty()) {
infos = std::move(local_infos);
if (infos_.empty()) {
infos_ = std::move(local_infos);
} else {
infos.insert(infos.end(), local_infos.begin(), local_infos.end());
infos_.insert(infos_.end(), local_infos.begin(), local_infos.end());
}
num_intersections += local_num_intersections;
});
Expand All @@ -98,7 +97,7 @@ class Corefine {

points_.reserve(num_points_before_insertion + num_intersections / 2);
Intersection_point_inserter inserter(points_);
for (auto& info : infos) {
for (auto& info : infos_) {
const auto& left_face = left_.face(info.left_fi);
const auto& right_face = right_.face(info.right_fi);
auto a = left_point_ids_.at(left_face[0].idx());
Expand All @@ -123,12 +122,12 @@ class Corefine {
auto left_fi_less = [](const Intersection_info& a, const Intersection_info& b) -> bool {
return a.left_fi < b.left_fi;
};
std::sort(infos.begin(), infos.end(), left_fi_less);
std::sort(infos_.begin(), infos_.end(), left_fi_less);

std::vector<boost::iterator_range<typename decltype(infos)::const_iterator>> ranges;
std::vector<boost::iterator_range<typename decltype(infos_)::const_iterator>> ranges;
{
auto first = infos.begin();
while (first != infos.end()) {
auto first = infos_.begin();
while (first != infos_.end()) {
auto fi = first->left_fi;
const auto& f = left_.face(fi);
auto a = left_point_ids_.at(f[0].idx());
Expand All @@ -140,7 +139,7 @@ class Corefine {
left_triangulations_.emplace(
fi, Triangulation{Triangle_region::LEFT_FACE, pa, pb, pc, a, b, c});

auto last = std::upper_bound(first, infos.end(), *first, left_fi_less);
auto last = std::upper_bound(first, infos_.end(), *first, left_fi_less);
ranges.emplace_back(first, last);
first = last;
}
Expand All @@ -161,12 +160,12 @@ class Corefine {
auto right_fi_less = [](const Intersection_info& a, const Intersection_info& b) -> bool {
return a.right_fi < b.right_fi;
};
std::sort(infos.begin(), infos.end(), right_fi_less);
std::sort(infos_.begin(), infos_.end(), right_fi_less);

ranges.clear();
{
auto first = infos.begin();
while (first != infos.end()) {
auto first = infos_.begin();
while (first != infos_.end()) {
auto fi = first->right_fi;
const auto& f = right_.face(fi);
auto a = right_point_ids_.at(f[0].idx());
Expand All @@ -178,7 +177,7 @@ class Corefine {
right_triangulations_.emplace(
fi, Triangulation{Triangle_region::RIGHT_FACE, pa, pb, pc, a, b, c});

auto last = std::upper_bound(first, infos.end(), *first, right_fi_less);
auto last = std::upper_bound(first, infos_.end(), *first, right_fi_less);
ranges.emplace_back(first, last);
first = last;
}
Expand All @@ -197,6 +196,26 @@ class Corefine {
}
}

std::vector<Edge> get_intersecting_edges() const {
std::vector<Edge> edges;

for (const auto& info : infos_) {
auto n = info.intersections.size();
if (n < 2) {
continue;
}

for (std::size_t i = 0; i < n; ++i) {
auto j = i < n - 1 ? i + 1 : 0;
auto a = info.intersections.at(i);
auto b = info.intersections.at(j);
edges.push_back(make_edge(Vertex_index{a}, Vertex_index{b}));
}
}

return edges;
}

template <class OutputIterator>
Face_tag get_left_triangles(Face_index fi, OutputIterator tris) const {
get_triangles(left_, fi, left_triangulations_, left_point_ids_, tris);
Expand Down Expand Up @@ -265,6 +284,7 @@ class Corefine {
std::vector<std::size_t> right_point_ids_;
std::vector<Face_tag> left_face_tags_;
std::vector<Face_tag> right_face_tags_;
std::vector<Intersection_info> infos_;
};

} // namespace kigumi
62 changes: 0 additions & 62 deletions include/kigumi/Find_border_edges.h

This file was deleted.

8 changes: 3 additions & 5 deletions include/kigumi/Mix.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <kigumi/Classify_faces_globally.h>
#include <kigumi/Classify_faces_locally.h>
#include <kigumi/Corefine.h>
#include <kigumi/Find_border_edges.h>
#include <kigumi/Mesh_entities.h>
#include <kigumi/Mesh_indices.h>
#include <kigumi/Mixed.h>
Expand All @@ -22,7 +21,6 @@ template <class K, class FaceData>
class Mix {
using Classify_faces_globally = Classify_faces_globally<K, FaceData>;
using Classify_faces_locally = Classify_faces_locally<K, FaceData>;
using Find_border_edges = Find_border_edges<K, FaceData>;
using Mixed_triangle_soup = Mixed_triangle_soup<K, FaceData>;
using Triangle_soup = Triangle_soup<K, FaceData>;

Expand Down Expand Up @@ -64,12 +62,12 @@ class Mix {

std::cout << "Local classification..." << std::endl;

auto border_edges = Find_border_edges{}(m, left, right);
auto intersecting_edges = corefine.get_intersecting_edges();
std::unordered_set<Edge> border_edges(intersecting_edges.begin(), intersecting_edges.end());
Warnings warnings{};

std::vector<Edge> edges(border_edges.begin(), border_edges.end());
parallel_do(
edges.begin(), edges.end(), Warnings{},
intersecting_edges.begin(), intersecting_edges.end(), Warnings{},
[&](const auto& edge, auto& local_warnings) {
thread_local Classify_faces_locally classify_faces_locally;

Expand Down

0 comments on commit 24747ac

Please sign in to comment.