Commit 03ccc891 authored by JasonPries's avatar JasonPries
Browse files

Fixed a bug and added testing for Edge <-> DartConstraint mapping

Some infrastructure changes for implementing boundaries with uniform discretizations
parent 58c9322e
#include "BoundaryConstraint.h"
#include "DartConstraint.h"
void BoundaryConstraint::add_to_queue(std::vector<std::unique_ptr<InsertionQueuer>> &queue, std::vector<DartConstraint> &constraints, size_t dart_constraint) {
if (UniformDiscretization) {
for (size_t dc : DartConstraints) {
size_t dart = constraints[dc].dart();
queue.push_back(std::make_unique<MidpointQueuer>(dart));
}
} else {
size_t dart = constraints[dart_constraint].dart();
queue.push_back(std::make_unique<MidpointQueuer>(dart));
}
}
\ No newline at end of file
......@@ -6,17 +6,33 @@
#include "Sketch.hpp"
#include "InsertionQueuer.h"
class DartConstraint;
class BoundaryConstraint {
public:
BoundaryConstraint(std::shared_ptr<Curve const> cc) : ConstraintCurve(cc) {};
void add_dart(size_t d) { Darts.push_back(d); }; // TODO: Enforce uniqueness (std::set?)
void add_dart_constraint(size_t d) { DartConstraints.push_back(d); }; // TODO: Enforce uniqueness (std::set?)
std::shared_ptr<Curve const> curve() const { return ConstraintCurve; };
bool uniform_discretizaiton() const { return UniformDiscretization; };
void uniform_discretization(bool flag) { UniformDiscretization = flag; };
void add_to_queue(std::vector<std::unique_ptr<InsertionQueuer>> &queue, std::vector<DartConstraint> &constraints, size_t dart);
size_t size_dart_constraints() const {return DartConstraints.size(); };
size_t dart(size_t i) const {return DartConstraints[i]; };
protected:
std::vector<size_t> Darts;
std::vector<size_t> DartConstraints;
std::shared_ptr<Curve const> ConstraintCurve;
bool UniformDiscretization{false};
};
......
......@@ -11,16 +11,23 @@
class DartConstraint {
public:
DartConstraint(double s0, double s1, std::shared_ptr<BoundaryConstraint> bc, size_t self) : S0{s0}, S1{s1}, Constraint{bc}, Self{self}, ForwardDart{SIZE_MAX}, ReverseDart{SIZE_MAX} {};
std::shared_ptr<BoundaryConstraint> boundary_constraint() const { return Constraint; };
std::shared_ptr<Curve const> constraint_curve() const { return Constraint->curve(); };
size_t self() const { return Self; };
size_t dart() const { return std::min(ForwardDart, ReverseDart); };
size_t forward_dart() const { return ForwardDart; };
size_t reverse_dart() const { return ReverseDart; };
void add_to_queue(std::vector<std::unique_ptr<InsertionQueuer>> &queue, std::vector<DartConstraint> &constraints) {
Constraint->add_to_queue(queue, constraints, Self);
}
void forward_dart(size_t d) { ForwardDart = d; };
void reverse_dart(size_t d) { ReverseDart = d; };
......@@ -30,8 +37,8 @@ public:
size_t Self;
size_t ForwardDart;
size_t ReverseDart;
size_t ForwardDart{SIZE_MAX};
size_t ReverseDart{SIZE_MAX};
protected:
std::shared_ptr<BoundaryConstraint> Constraint;
......
......@@ -20,7 +20,7 @@ public:
Edge(size_t n, size_t s, size_t c, bool d) : Node(n), Self(s), Next(SIZE_MAX), Twin(SIZE_MAX), Prev(SIZE_MAX), Constraint(c), Orientation(d), Mark(false) {};
void add_to_queue(std::vector<std::unique_ptr<InsertionQueuer>> &queue, std::vector<DartConstraint> &constraints) {
queue.push_back(std::make_unique<MidpointQueuer>(Self));
constraints[Constraint].add_to_queue(queue, constraints);
}
size_t node() const { return Node; };
......
......@@ -705,10 +705,13 @@ void Mesh::insert_internal_boundaries() {
Edge &e = Edges[ei];
e.Constraint = dc.Self;
e.Orientation = true;
dc.forward_dart(e.self());
Edge &et = Edges[e.Twin];
et.Constraint = dc.Self;
et.Orientation = false;
dc.reverse_dart(et.self());
queue.pop_back();
} else {
......@@ -732,10 +735,21 @@ void Mesh::insert_internal_boundaries() {
}
}
// TODO: One final pass to insert any midpoints that have not been inserted OR length based refinement
// TODO: Do length based refinement instead
// There are some errors that occur with half-circles becoming degenerate when the LineSegment is not encroached because this isn't done
for (auto bc : BoundaryConstraints) {
/*
auto &temp = *(bc.get());
if(bc->size_dart_constraints() == 1) {
bc->add_to_queue(Queue, DartConstraints, bc->dart(0));
insert_from_queue();
}
*/
}
split_encroached_edges();
// TODO: Enforce BoundaryConstraint conditions (e.g. uniform discretization, boundary maps)
}
void Mesh::mark_triangles() {
......
......@@ -228,7 +228,7 @@ private:
}
DartConstraint &new_dart_constraint(double s0, double s1, std::shared_ptr<BoundaryConstraint> bc) {
bc->add_dart(DartConstraints.size());
bc->add_dart_constraint(DartConstraints.size());
DartConstraints.emplace_back(s0, s1, bc, DartConstraints.size());
return DartConstraints.back();
}
......
......@@ -117,13 +117,13 @@ TEST(Mesh, create_square_domain) {
// Test number of verticies, edges, triangles
std::vector<size_t> vmap = map_verticies_to_points({v0, v1, v2, v3}, m);
EXPECT_TRUE(m.size_points() == 4);
EXPECT_TRUE(m.size_edges() == 6);
EXPECT_TRUE(m.size_triangles() == 2);
EXPECT_EQ(m.size_points(), 4);
EXPECT_EQ(m.size_edges(), 6);
EXPECT_EQ(m.size_triangles(), 2);
EXPECT_TRUE(m.num_points() == 4);
EXPECT_TRUE(m.num_edges() == 5);
EXPECT_TRUE(m.num_triangles() == 2);
EXPECT_EQ(m.num_points(), 4);
EXPECT_EQ(m.num_edges(), 5);
EXPECT_EQ(m.num_triangles(), 2);
EXPECT_TRUE(v0->x() == m.point(vmap[0]).X);
EXPECT_TRUE(v0->y() == m.point(vmap[0]).Y);
......@@ -922,8 +922,8 @@ TEST(Mesh, locate_triange__square_domain) {
Mesh mesh{s};
mesh.create();
EXPECT_TRUE(mesh.size_edges() == 6);
EXPECT_TRUE(mesh.size_points() == 4);
EXPECT_EQ(mesh.size_edges(), 6);
EXPECT_EQ(mesh.size_points(), 4);
// Interior Points
Point vi0{0.25, 0.25};
......@@ -933,10 +933,10 @@ TEST(Mesh, locate_triange__square_domain) {
size_t loc = i;
vp = vi0;
EXPECT_TRUE(mesh.locate_triangle(vp, loc) == LocateTriangleResult::Interior);
EXPECT_EQ(mesh.locate_triangle(vp, loc), LocateTriangleResult::Interior);
vp = vi1;
EXPECT_TRUE(mesh.locate_triangle(vp, loc) == LocateTriangleResult::Interior);
EXPECT_EQ(mesh.locate_triangle(vp, loc), LocateTriangleResult::Interior);
}
// Exterior Points
......@@ -946,28 +946,28 @@ TEST(Mesh, locate_triange__square_domain) {
Point ve1{2.0, 0.5};
Point ve2{0.5, 2.0};
Point ve3{-1.0, 0.5};
for (size_t i = 0; i < mesh.size_edges(); ++i) {
for (size_t i = 0; i != mesh.size_edges(); ++i) {
Edge e;
Point vp;
size_t loc = i;
vp = ve0;
EXPECT_TRUE(mesh.locate_triangle(vp, loc) == LocateTriangleResult::Exterior);
EXPECT_EQ(mesh.locate_triangle(vp, loc), LocateTriangleResult::Exterior);
e = mesh.edge(loc);
EXPECT_TRUE((mesh.point(e.node()) == mesh.point(vmap[0])) && (mesh.point(mesh.edge(e.next()).node()) == mesh.point(vmap[1])));
vp = ve1;
EXPECT_TRUE(mesh.locate_triangle(vp, loc) == LocateTriangleResult::Exterior);
EXPECT_EQ(mesh.locate_triangle(vp, loc), LocateTriangleResult::Exterior);
e = mesh.edge(loc);
EXPECT_TRUE((mesh.point(e.node()) == mesh.point(vmap[1])) && (mesh.point(mesh.edge(e.next()).node()) == mesh.point(vmap[2])));
vp = ve2;
EXPECT_TRUE(mesh.locate_triangle(vp, loc) == LocateTriangleResult::Exterior);
EXPECT_EQ(mesh.locate_triangle(vp, loc), LocateTriangleResult::Exterior);
e = mesh.edge(loc);
EXPECT_TRUE((mesh.point(e.node()) == mesh.point(vmap[2])) && (mesh.point(mesh.edge(e.next()).node()) == mesh.point(vmap[3])));
vp = ve3;
EXPECT_TRUE(mesh.locate_triangle(vp, loc) == LocateTriangleResult::Exterior);
EXPECT_EQ(mesh.locate_triangle(vp, loc), LocateTriangleResult::Exterior);
e = mesh.edge(loc);
EXPECT_TRUE((mesh.point(e.node()) == mesh.point(vmap[3])) && (mesh.point(mesh.edge(e.next()).node()) == mesh.point(vmap[0])));
}
......@@ -978,38 +978,39 @@ TEST(Mesh, locate_triange__square_domain) {
ve2 = {0.5, 1.0 + DBL_EPSILON};
ve3 = {0.0 - DBL_EPSILON, 0.5};
LocateTriangleResult result;
for (size_t i = 0; i < mesh.size_edges(); ++i) {
for (size_t i = 0; i != mesh.size_edges(); ++i) {
Edge e;
Point vp;
size_t loc = i;
vp = ve0;
result = mesh.locate_triangle(vp, loc);
EXPECT_TRUE(result == LocateTriangleResult::Interior);
EXPECT_EQ(result, LocateTriangleResult::Interior);
e = mesh.edge(loc);
EXPECT_TRUE((mesh.point(e.node()) == mesh.point(vmap[0])) && (mesh.point(mesh.edge(e.next()).node()) == mesh.point(vmap[1])));
vp = ve1;
result = mesh.locate_triangle(vp, loc);
EXPECT_TRUE(result == LocateTriangleResult::Interior);
EXPECT_EQ(result, LocateTriangleResult::Interior);
e = mesh.edge(loc);
EXPECT_TRUE((mesh.point(e.node()) == mesh.point(vmap[1])) && (mesh.point(mesh.edge(e.next()).node()) == mesh.point(vmap[2])));
vp = ve2;
result = mesh.locate_triangle(vp, loc);
EXPECT_TRUE(result == LocateTriangleResult::Interior);
EXPECT_EQ(result, LocateTriangleResult::Interior);
e = mesh.edge(loc);
EXPECT_TRUE((mesh.point(e.node()) == mesh.point(vmap[2])) && (mesh.point(mesh.edge(e.next()).node()) == mesh.point(vmap[3])));
vp = ve3;
result = mesh.locate_triangle(vp, loc);
EXPECT_TRUE(result == LocateTriangleResult::Interior);
EXPECT_EQ(result, LocateTriangleResult::Interior);
e = mesh.edge(loc);
EXPECT_TRUE((mesh.point(e.node()) == mesh.point(vmap[3])) && (mesh.point(mesh.edge(e.next()).node()) == mesh.point(vmap[0])));
}
Point vie{0.5, 0.5};
for (size_t i = 0; i < mesh.size_edges(); ++i) {
EXPECT_TRUE(mesh.locate_triangle(vie, i) == LocateTriangleResult::Interior);
for (size_t i = 0; i != mesh.size_edges(); ++i) {
size_t e = i;
EXPECT_EQ(mesh.locate_triangle(vie, e), LocateTriangleResult::Interior);
}
}
\ No newline at end of file
......@@ -54,6 +54,8 @@ bool edges_are_valid(Mesh &m) {
DartConstraint const &d = m.dart_constraint(i);
EXPECT_EQ(i, d.self());
EXPECT_TRUE(d.forward_dart() != SIZE_MAX || d.reverse_dart() != SIZE_MAX || d.self() == 0);
if (d.forward_dart() != SIZE_MAX) {
Edge const &e = m.edge(d.forward_dart());
EXPECT_TRUE(e.orientation());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment