Commit 0dce6596 by JasonPries

### Update of Mesh functions

`Work required before changing Mesh::Edges from type std::vector<Edge*> to std::Vector<Edge>`
parent 548b3918
 ... ... @@ -11,6 +11,8 @@ public: Edge() : Node(SIZE_MAX), Self(SIZE_MAX), Next(SIZE_MAX), Twin(SIZE_MAX), Prev(SIZE_MAX), ConstraintCurve(nullptr), Orientation(true), Mark(false) {}; Edge(size_t s) : Node(SIZE_MAX), Self(s), Next(SIZE_MAX), Twin(SIZE_MAX), Prev(SIZE_MAX), ConstraintCurve(nullptr), Orientation(true), Mark(false) {}; Edge(size_t n, size_t s, Edge &nx, Edge &pr, Edge &tw) : Node(n), Self(s), Next(nx.Self), Twin(tw.Self), Prev(pr.Self), ConstraintCurve(nullptr), Orientation(true), Mark(false) {}; Edge(size_t n, size_t s, Curve *c, bool d) : Node(n), Self(s), Next(SIZE_MAX), Twin(SIZE_MAX), Prev(SIZE_MAX), ConstraintCurve(c), Orientation(d), Mark(false) {}; ... ... @@ -43,6 +45,8 @@ public: bool is_constrained() const { return (ConstraintCurve != nullptr); }; bool is_not_constrained() const { return (ConstraintCurve == nullptr); }; protected: size_t Node; //Point at start of this edge size_t Self; //This edge in this triangle ... ...
This diff is collapsed.
 ... ... @@ -25,35 +25,37 @@ public: Mesh(Sketch &s); bool are_intersecting(Edge const *e0, Edge const *e1) const; bool are_intersecting(size_t ei, size_t ej) const; bool edges_are_valid() const; bool in_triangle(Point const p, Edge const *e) const; bool in_triangle(Point const p, size_t ei) const; bool is_encroached(Edge const *e, Point const p) const; bool is_constrained(size_t ei) const { return Edges[ei]->is_constrained(); }; bool is_locally_optimal(Edge const *e) const; bool is_encroached(Point const p, size_t ei) const; bool is_protruding(Edge const *e) const; bool is_locally_optimal(size_t ei) const; bool is_valid(Edge const *e) const; bool is_protruding(size_t ei) const; bool is_valid(size_t ei) const; bool orientation(size_t ei) const { return Edges[ei]->Orientation; }; bool refine(); bool refine_once(); double circumradius(Edge const *e) const; double circumradius(size_t ei) const; double length(Edge const *e) const; double length(size_t ei) const; double shortest_edge_length(Edge const *e) const; double shortest_edge_length(size_t ei) const; size_t size_points() const { return Points.size(); }; size_t size_edges() const { return Edges.size(); }; size_t next(size_t ei) const { return Edges[ei]->Next; }; size_t size_triangles() const { return Triangles.size(); }; size_t node(size_t ei) const { return Edges[ei]->Node; }; size_t node(Edge const *e) const { return e->Node; }; ... ... @@ -63,22 +65,38 @@ public: size_t num_triangles() const { return Triangles.size(); }; size_t prev(size_t ei) const { return Edges[ei]->Prev; }; size_t size_points() const { return Points.size(); }; size_t size_edges() const { return Edges.size(); }; size_t size_triangles() const { return Triangles.size(); }; size_t twin(size_t ei) const { return Edges[ei]->Twin; }; void create(); void delete_me(); // TODO: refactor to non-pointer version void save_as(std::string path, std::string file_name) const; Point circumcenter(Edge const *e) const; Curve const *constraint_curve(size_t ei) const { return Edges[ei]->ConstraintCurve; }; Point circumcenter(size_t ei) const; Point const base(Edge const *e) const { return Points[e->Node]; }; Point const base(size_t ei) const { return Points[node(ei)]; }; Point const point(size_t i) const { return Points[i]; }; Point const point(Edge const *e) const { return Points[e->Node]; }; Point const tip(Edge const *e) const { return Points[next(e)->Node]; }; Point const tip(size_t ei) const { return Points[node(next(ei))]; }; Edge const *edge(size_t i) const { return Edges[i]; }; Edge const *next(Edge const *e) const { return Edges[e->Next]; }; ... ... @@ -93,16 +111,17 @@ public: Edge *&twin(Edge *e) { return Edges[e->Twin]; }; Edge const *triangle(size_t i) const { return Triangles[i]; }; Edge const *triangle(size_t i) const { return Edges[Triangles[i]]; }; LocateTriangleResult locate_triangle(Point const p, Edge const *&e) const; LocateTriangleResult locate_triangle(Point const p, size_t &ei) const; LocateTriangleResult locate_triangle(Point const p) const { Edge const *e = Edges.back(); return locate_triangle(p, e); //Edge const *e = Edges.back(); size_t ei = Edges.size() - 1; return locate_triangle(p, ei); }; InsertPointResult insert_point(Point const p) { return insert_point(p, Edges.back()); }; InsertPointResult insert_point(Point const p) { return insert_point(p, Edges.size() - 1); }; protected: Contour const *Boundary; ... ... @@ -110,23 +129,28 @@ protected: std::vector Contours; std::vector Points; std::vector Edges; std::vector Triangles; std::vector Triangles; private: bool find_attached(Edge *&e_out, Point const p); bool find_attached(Point const p, size_t &ei); bool recursive_swap(Edge *e); bool recursive_swap(size_t ei); bool swap(Edge *&e0); bool swap(size_t ei); void add_edge(Edge *&e) { e->Self = Edges.size(); Edges.push_back(e); }; Edge *&new_edge() { Edges.push_back(new Edge(Edges.size())); return Edges.back(); } Edge *&new_edge(size_t p, Curve *c, bool dir) { Edges.push_back(new Edge(p, Edges.size(), c, dir)); return Edges.back(); } void create_boundary_polygon(); void element_quality(std::vector &triangle, std::vector &radii, std::vector &quality); void element_quality(std::vector &radii, std::vector &quality); void get_triangles(); ... ... @@ -140,19 +164,17 @@ private: void sort_permutation_descending(std::vector &values, std::vector &index) const; void split_edge(Edge *e); void split_edge(size_t ei); void split_encroached_edges(); void triangulate_boundary_polygon(); LocateTriangleResult locate_triangle(Point const p, Edge *&e) const; InsertPointResult insert_circumcenter(Edge *e); InsertPointResult insert_circumcenter(size_t ei); InsertPointResult insert_point(Point const p, Edge *e); InsertPointResult insert_point(Point const p, size_t ei); InsertPointResult insert_midpoint(Edge *e); InsertPointResult insert_midpoint(size_t ei); }; #endif //OERSTED_MESH_H
 ... ... @@ -69,11 +69,11 @@ TEST(Mesh, create__triangle_domain) { { // Test triangles const Edge *e = m.triangle(0); Point cc = m.circumcenter(e); Point cc = m.circumcenter(e->self()); EXPECT_NEAR(0.0, cc.X, TOL); EXPECT_NEAR(sqrt(3.0) / 3.0, cc.Y, TOL); double cr = m.circumradius(e); double cr = m.circumradius(e->self()); EXPECT_NEAR(2.0 * sqrt(3.0) / 3.0, cr, TOL); } ... ... @@ -155,7 +155,7 @@ TEST(Mesh, create__square_domain) { // Test triangles { for (size_t i = 0; i < m.size_triangles(); ++i) { Point cc = m.circumcenter(m.triangle(0)); Point cc = m.circumcenter(m.triangle(0)->self()); EXPECT_NEAR(0.5, cc.X, TOL); EXPECT_NEAR(0.5, cc.Y, TOL); } ... ... @@ -226,8 +226,8 @@ TEST(Mesh, create__narrow_diamond_domain) { // Test triangle circumcenters { Point cc0 = m.circumcenter(m.triangle(0)); // TODO: Write m.circumcenter(size_t) Point cc1 = m.circumcenter(m.triangle(1)); Point cc0 = m.circumcenter(m.triangle(0)->self()); // TODO: Write m.circumcenter(size_t) Point cc1 = m.circumcenter(m.triangle(1)->self()); EXPECT_NEAR(0.0, cc0.X, TOL); EXPECT_NEAR(0.75, std::abs(cc0.Y), TOL); ... ... @@ -744,21 +744,26 @@ TEST(Mesh, locate_triangle__triangular_domain) { std::vector vmap = map_verticies_to_points({v0, v1, v2}, mesh); for (size_t i = 0; i < mesh.size_edges(); ++i) { Edge const *e = mesh.edge(i); Point vp = vi; Edge const *e; Point vp; size_t loc = i; EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Interior); vp = vi; EXPECT_TRUE(mesh.locate_triangle(vp, loc) == LocateTriangleResult::Interior); vp = ve0; EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Exterior); EXPECT_TRUE(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, e) == LocateTriangleResult::Exterior); EXPECT_TRUE(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, e) == LocateTriangleResult::Exterior); EXPECT_TRUE(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[0]))); } ... ... @@ -767,20 +772,24 @@ TEST(Mesh, locate_triangle__triangular_domain) { ve1 = {1.5 + DBL_EPSILON, sqrt(3.0) / 2.0 + DBL_EPSILON}; ve2 = {0.5 - DBL_EPSILON, sqrt(3.0) / 2.0 + DBL_EPSILON}; for (size_t i = 0; i < mesh.size_edges(); ++i) { Edge const *e = mesh.edge(i); for (size_t i = 0; i != mesh.size_edges(); ++i) { Edge const *e; Point vp; size_t loc = i; vp = ve0; EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Interior); EXPECT_TRUE(mesh.locate_triangle(vp, loc) == 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; EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Interior); EXPECT_TRUE(mesh.locate_triangle(vp, loc) == 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; EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Interior); EXPECT_TRUE(mesh.locate_triangle(vp, loc) == 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[0]))); } } ... ... @@ -816,14 +825,15 @@ TEST(Mesh, locate_triange__square_domain) { Point vi0{0.25, 0.25}; Point vi1{0.75, 0.75}; for (size_t i = 0; i < mesh.size_edges(); ++i) { Edge const *e = mesh.edge(i); //Edge const *e; Point vp; size_t loc = i; vp = vi0; EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Interior); EXPECT_TRUE(mesh.locate_triangle(vp, loc) == LocateTriangleResult::Interior); vp = vi1; EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Interior); EXPECT_TRUE(mesh.locate_triangle(vp, loc) == LocateTriangleResult::Interior); } // Exterior Points ... ... @@ -834,23 +844,28 @@ TEST(Mesh, locate_triange__square_domain) { Point ve2{0.5, 2.0}; Point ve3{-1.0, 0.5}; for (size_t i = 0; i < mesh.size_edges(); ++i) { Edge const *e = mesh.edge(i); Edge const *e; Point vp; size_t loc = i; vp = ve0; EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Exterior); EXPECT_TRUE(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, e) == LocateTriangleResult::Exterior); EXPECT_TRUE(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, e) == LocateTriangleResult::Exterior); EXPECT_TRUE(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, e) == LocateTriangleResult::Exterior); EXPECT_TRUE(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]))); } ... ... @@ -861,34 +876,39 @@ TEST(Mesh, locate_triange__square_domain) { ve3 = {0.0 - DBL_EPSILON, 0.5}; LocateTriangleResult result; for (size_t i = 0; i < mesh.size_edges(); ++i) { Edge const *e = mesh.edge(i); Edge const *e; Point vp; size_t loc = i; vp = ve0; result = mesh.locate_triangle(vp, e); result = mesh.locate_triangle(vp,loc); EXPECT_TRUE(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, e); result = mesh.locate_triangle(vp,loc); EXPECT_TRUE(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, e); result = mesh.locate_triangle(vp,loc); EXPECT_TRUE(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, e); result = mesh.locate_triangle(vp,loc); EXPECT_TRUE(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) { const Edge *e = mesh.edge(i); //const Edge *e = mesh.edge(i); EXPECT_TRUE(mesh.locate_triangle(vie, e) == LocateTriangleResult::Interior); EXPECT_TRUE(mesh.locate_triangle(vie, i) == LocateTriangleResult::Interior); } } \ No newline at end of file
 #include "test_Mesh.hpp" bool edges_are_optimal(Mesh &m) { for (size_t i = 0;i < m.size_edges();++i) { EXPECT_TRUE(m.is_locally_optimal(m.edge(i))); for (size_t i = 0;i != m.size_edges();++i) { EXPECT_TRUE(m.is_locally_optimal(i)); } return true; ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!