Skip to content

Commit

Permalink
Fix local classification bug
Browse files Browse the repository at this point in the history
  • Loading branch information
unageek committed Nov 26, 2024
1 parent c5da22b commit 3e88764
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 56 deletions.
89 changes: 43 additions & 46 deletions include/kigumi/Classify_faces_locally.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,63 +118,60 @@ class Classify_faces_locally {
}
}

if (is_undefined_configuration) {
return {};
}

// Check consistency and tag rest of the faces.

// An example case of an inconsistent configuration:
//
// Right, Int.
// //|
// //|
// //|
// /////////|/////////
// Left, ??? ---------+--------- Left, Ext.
// :
// Should be tagged as interior according to global classification.

auto consistent = true;
for (auto dry_run : {true, false}) {
auto tag = m.data(faces_.at(k).fi).tag;
auto orientation = faces_.at(k).orientation;
// Go around and return to the starting point to check consistency.
for (std::size_t i = k + 1; i <= k + faces_.size(); ++i) {
const auto& f = faces_.at(i % faces_.size());
auto& f_data = m.data(f.fi);

if (f.orientation == orientation) {
tag = tag == Face_tag::EXTERIOR ? Face_tag::INTERIOR : Face_tag::EXTERIOR;
if (!is_undefined_configuration) {
// Check consistency and tag rest of the faces.

// An example case of an inconsistent configuration:
//
// Right, Int.
// //|
// //|
// //|
// /////////|/////////
// Left, ??? ---------+--------- Left, Ext.
// :
// Should be tagged as interior according to global classification.

auto consistent = true;
for (auto dry_run : {true, false}) {
auto tag = m.data(faces_.at(k).fi).tag;
auto orientation = faces_.at(k).orientation;
// Go around and return to the starting point to check consistency.
for (std::size_t i = k + 1; i <= k + faces_.size(); ++i) {
const auto& f = faces_.at(i % faces_.size());
auto& f_data = m.data(f.fi);

if (f.orientation == orientation) {
tag = tag == Face_tag::EXTERIOR ? Face_tag::INTERIOR : Face_tag::EXTERIOR;
}
orientation = f.orientation;

if (f_data.tag == Face_tag::UNKNOWN) {
if (!dry_run) {
f_data.tag = tag;
}
} else if ((f_data.tag == Face_tag::EXTERIOR || f_data.tag == Face_tag::INTERIOR) &&
f_data.tag != tag) {
consistent = false;
break;
}
}
orientation = f.orientation;

if (f_data.tag == Face_tag::UNKNOWN) {
if (!dry_run) {
f_data.tag = tag;
}
} else if ((f_data.tag == Face_tag::EXTERIOR || f_data.tag == Face_tag::INTERIOR) &&
f_data.tag != tag) {
consistent = false;
if (!consistent) {
// Leave unknown faces to the global classifier.
break;
}
}

if (!consistent) {
// Leave unknown faces to the global classifier.
break;
}
}

// Propagate face tags.
// Propagate the tags.

Warnings warnings{};

for (const auto& f : faces_) {
auto fi = f.fi;
auto f_tag = m.data(fi).tag;
if (f_tag == Face_tag::EXTERIOR || f_tag == Face_tag::INTERIOR) {
warnings |= propagate_face_tags_(m, border_edges, fi);
const auto& f_data = m.data(f.fi);
if (f_data.tag != Face_tag::UNKNOWN) {
warnings |= propagate_face_tags_(m, border_edges, f.fi);
}
}

Expand Down
6 changes: 3 additions & 3 deletions include/kigumi/Corefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ class Corefine {
}
}

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

for (const auto& info : infos_) {
auto n = info.intersections.size();
Expand All @@ -217,7 +217,7 @@ class Corefine {
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}));
edges.insert(make_edge(Vertex_index{a}, Vertex_index{b}));
}
}

Expand Down
4 changes: 2 additions & 2 deletions include/kigumi/Mix.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class Mix {

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

auto intersecting_edges = corefine.get_intersecting_edges();
Edge_set border_edges(intersecting_edges.begin(), intersecting_edges.end());
auto border_edges = corefine.get_intersecting_edges();
std::vector<Edge> intersecting_edges(border_edges.begin(), border_edges.end());
Warnings warnings{};

parallel_do(
Expand Down
5 changes: 0 additions & 5 deletions include/kigumi/Propagate_face_tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <kigumi/Warnings.h>

#include <queue>
#include <stdexcept>

namespace kigumi {

Expand All @@ -21,10 +20,6 @@ class Propagate_face_tags {
auto from_left = data.from_left;
auto tag = data.tag;

if (tag != Face_tag::INTERIOR && tag != Face_tag::EXTERIOR) {
throw std::runtime_error("the seed face must be tagged as either interior or exterior");
}

Warnings warnings{};

queue_.push(seed);
Expand Down

0 comments on commit 3e88764

Please sign in to comment.