Commit 40b24c84 authored by JasonPries's avatar JasonPries
Browse files

Moved more functions from Edge and util to Mesh

parent 821dfba3
......@@ -5,14 +5,13 @@
<sourceFolder url="file://$MODULE_DIR$/src/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Angle.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Vertical.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Sketch.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Curve.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Coincident.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Vertical.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Angle.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Vertex.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Curve.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Pattern.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Length.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Radius.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Coincident.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constellation.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Radius.cpp" isTestSource="false" />
......@@ -20,36 +19,37 @@
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Vertex.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/LineSegment.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Curve.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Branch.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Rotation.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Tangency.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Rotation.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Branch.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Branch.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Tangency.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constraint.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constraint.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/RotateCopy.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Star.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Symmetry.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constraint.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Length.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Length.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constellation.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Contour.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Fixation.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Radius.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Horizontal.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/CircularArc.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Distance.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Symmetry.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Distance.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Symmetry.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/MirrorCopy.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Pattern.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Star.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/LineSegment.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/MirrorCopy.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Fixation.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Sketch.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/RotateCopy.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/RotateCopy.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Tangency.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constraint.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Contour.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Pattern.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Rotation.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Distance.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Sketch.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/CircularArc.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/include/Sketch.hpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/CMakeLists.txt" isTestSource="false" />
......@@ -58,9 +58,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/Mesh/src/Point.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Mesh/src/Mesh.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Mesh/src/Mesh.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Mesh/src/util.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Mesh/src/Edge.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Mesh/src/util.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Mesh/include/Mesh.hpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Mesh/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lib/CMakeLists.txt" isTestSource="false" />
......@@ -70,25 +68,25 @@
<sourceFolder url="file://$MODULE_DIR$/lib/GoogleTest/googletest/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lib/GoogleTest/googletest/cmake/internal_utils.cmake" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/main.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Mesh/util.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Mesh/test_Mesh.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Mesh/test_Mesh.hpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Mesh/util.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Curve.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_LineSegment.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Pattern.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Sketch.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Constraint.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Contour.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_CircularArc.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Vertex.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Star.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Sketch.hpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Contour.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Constraint.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/main.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/UseCases/test_Rotor.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/UseCases/test_Stator.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/UseCases/test_UseCases.hpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Mesh/util.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Mesh/test_Mesh.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Mesh/test_Mesh.hpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Mesh/util.h" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
......
......@@ -5,8 +5,7 @@ set(SOURCE_FILES
./src/Mesh.h ./src/Mesh.cpp
./src/Edge.h ./src/Edge.cpp
./src/Point.h ./src/Point.cpp
./src/util.h ./src/util.cpp)
./src/Point.h ./src/Point.cpp)
add_library(mesh STATIC ${SOURCE_FILES})
......
......@@ -4,6 +4,5 @@
#include "../src/Mesh.h"
#include "../src/Edge.h"
#include "../src/Point.h"
#include "../src/util.h"
#endif //OERSTED_MESH_HPP
\ No newline at end of file
This diff is collapsed.
......@@ -27,17 +27,29 @@ public:
Mesh(Sketch &s);
void delete_me(); // TODO: refactor to non-pointer version
bool are_intersecting(Edge const *e0, Edge const *e1) const;
void create();
bool edges_are_valid() const;
Point circumcenter(Edge const *e) const;
bool in_triangle(Point const p, Edge const *e) const;
Point const point(size_t i) const { return Points[i]; };
bool is_encroached(Edge const *e, Point const p) const;
Edge const *edge(size_t i) const { return Edges[i]; };
bool is_locally_optimal(Edge const *e) const;
Edge const *triangle(size_t i) const { return Triangles[i]; };
bool is_protruding(Edge const *e) const;
bool is_valid(Edge const *e) const;
bool refine();
bool refine_once();
double circumradius(Edge const *e) const;
double length(Edge const *e) const;
double shortest_edge_length(Edge const *e) const;
size_t size_points() const { return Points.size(); };
......@@ -51,83 +63,80 @@ public:
size_t num_triangles() const { return Triangles.size(); };
void create();
void delete_me(); // TODO: refactor to non-pointer version
void save_as(std::string path, std::string file_name) const;
LocateTriangleResult locate_triangle(Point const &p, Edge *&e) const;
Point circumcenter(Edge const *e) const;
Point const point(size_t i) const { return Points[i]; };
LocateTriangleResult locate_triangle(Point const &p, Edge const *&e) const;
Edge const *edge(size_t i) const { return Edges[i]; };
Edge const *triangle(size_t i) const { return Triangles[i]; };
LocateTriangleResult locate_triangle(Point const p, Edge const *&e) const;
LocateTriangleResult locate_triangle(Point const p) const {
Edge const *e = Edges.back();
return locate_triangle(p, e);
};
InsertPointResult insert_point(Point const &p, Edge *e);
InsertPointResult insert_point(Point const p) { return insert_point(p, Edges.back()); };
InsertPointResult insert_circumcenter(Edge *e);
InsertPointResult insert_midpoint(Edge *e);
bool refine();
bool refine_once();
void refine_once(std::vector<size_t> index, std::vector<double> circumradius, std::vector<double> quality);
bool edges_are_valid() const;
protected:
Contour const *Boundary;
std::vector<Curve const *> Curves;
std::vector<Contour const *> Contours;
std::vector<Point> Points;
std::vector<Edge *> Edges;
std::vector<Edge *> Triangles;
double circumradius(Edge const *e) const;
private:
bool find_attached(Edge *&e_out, Point const p) const;
double length(Edge const *e) const;
bool recursive_swap(Edge *e) const;
double shortest_edge_length(Edge const *e) const;
bool swap(Edge *&e0) const;
bool is_protruding(Edge const *e) const;
void add_edge(Edge *&e) {
e->Self = Edges.size();
Edges.push_back(e);
};
bool recursive_swap(Edge *edge) const;
void create_boundary_polygon();
bool is_locally_optimal(Edge const *edge) const;
void element_quality(std::vector<Edge *> &triangle, std::vector<double> &radii, std::vector<double> &quality);
void split_edge(Edge *edge);
void get_triangles();
bool is_encroached(Edge const *e, Point const p2) const;
void insert_internal_boundaries();
bool is_attached(Edge *&edge_out, Point const &p) const;
void mark_triangles();
bool is_valid(Edge const *&e) const;
void recursive_mark(Edge *e) const;
bool swap(Edge *&e0) const;
void refine_once(std::vector<size_t> index, std::vector<double> circumradius, std::vector<double> quality);
void add_edge(Edge *&e) {
e->Self = Edges.size();
Edges.push_back(e);
};
void sort_permutation_ascending(std::vector<double> &value, std::vector<size_t> &index) const;
void recursive_mark(Edge *&e) const;
void sort_permutation_descending(std::vector<double> &values, std::vector<size_t> &index) const;
protected:
Contour const *Boundary;
std::vector<Curve const *> Curves;
std::vector<Contour const *> Contours;
std::vector<Point> Points;
std::vector<Edge *> Edges;
std::vector<Edge *> Triangles;
void split_edge(Edge *e);
private:
void create_boundary_polygon();
void split_encroached_edges();
void triangulate_boundary_polygon();
void insert_internal_boundaries();
LocateTriangleResult locate_triangle(Point const p, Edge *&e) const;
void split_encroached_edges();
InsertPointResult insert_circumcenter(Edge *e);
// Misc
void mark_triangles();
InsertPointResult insert_point(Point const p, Edge *e);
void get_triangles();
InsertPointResult insert_midpoint(Edge *e);
};
#endif //OERSTED_MESH_H
#include "Mesh.hpp"
// TODO: Make these mesh routines
bool are_intersecting(Edge const *e0, Edge const *e1, Mesh const &m) {
// TODO, Make more detailed return type enumeration
if (e0->ConstraintCurve != nullptr && e0->ConstraintCurve == e1->ConstraintCurve) {
return false;
}
Point const v00 = m.point(e0->base());
Point const v01 = m.point(e0->tip(m));
Point const v10 = m.point(e1->base());
Point const v11 = m.point(e1->tip(m));
double xs0 = (v00.X + v01.X) / 2.0;
double ys0 = (v00.Y + v01.Y) / 2.0;
double xs1 = (v10.X + v11.X) / 2.0;
double ys1 = (v10.Y + v11.Y) / 2.0;
double xd0 = (v00.X - v01.X) / 2.0;
double yd0 = (v00.Y - v01.Y) / 2.0;
double xd1 = (v10.X - v11.X) / 2.0;
double yd1 = (v10.Y - v11.Y) / 2.0;
double d0 = xd0 * xd0 + yd0 * yd0;
double d1 = xd1 * xd1 + yd1 * yd1;
double cross = abs(xd0 * yd1 - xd1 * yd0);
double tol = (d0 * d1) * FLT_EPSILON;
if (cross < tol) {
// Lines are nearly parallel
// There are four possible minimum distance points between the lines
double s, dx, dy, dmin = DBL_MAX;
s = ((xd0 - xd1) * (xs0 - xs1) + (yd0 - yd1) * (ys0 - ys1)) /
((xd0 - xd1) * (xd0 - xd1) + (yd0 - yd1) * (yd0 - yd1));
if (abs(s) < 1.0 - FLT_EPSILON) {
dx = xs0 + xd0 * s - xs1 - xd1 * s;
dy = ys0 + yd0 * s - ys1 - yd1 * s;
dmin = fmin(dmin, dx * dx + dy * dy);
dx = xs0 - xd0 * s - xs1 + xd1 * s;
dy = ys0 - yd0 * s - ys1 + yd1 * s;
dmin = fmin(dmin, dx * dx + dy * dy);
}
s = ((xd0 + xd1) * (xs0 - xs1) + (yd0 + yd1) * (ys0 - ys1)) /
((xd0 + xd1) * (xd0 + xd1) + (yd0 + yd1) * (yd0 + yd1));
if (abs(s) < 1.0 - FLT_EPSILON) {
dx = xs0 + xd0 * s - xs1 + xd1 * s;
dy = ys0 + yd0 * s - ys1 + yd1 * s;
dmin = fmin(dmin, dx * dx + dy * dy);
dx = xs0 - xd0 * s - xs1 - xd1 * s;
dy = ys0 - yd0 * s - ys1 - yd1 * s;
dmin = fmin(dmin, dx * dx + dy * dy);
}
tol = (d0 + d1) * FLT_EPSILON;
return (dmin < tol);
} else { // Lines are not parallel
double s0 = abs(xd1 * (ys0 - ys1) - yd1 * (xs0 - xs1));
double s1 = abs(xd0 * (ys0 - ys1) - yd0 * (xs0 - xs1));
tol = cross * (1.0 - FLT_EPSILON);
return (s0 < tol && s1 < tol);
}
}
bool in_triangle(Point const &p, Edge const *&e, Mesh const &m) {
double xp = p.X;
double yp = p.Y;
Point const p0 = m.point(e->node());
Point const p1 = m.point(m.edge(e->next())->node());
Point const p2 = m.point(m.edge(e->prev())->node());
double dx0p = p0.X - xp;
double dy0p = p0.Y - yp;
double dx1p = p1.X - xp;
double dy1p = p1.Y - yp;
double dx2p = p2.X - xp;
double dy2p = p2.Y - yp;
double dx01 = p0.X - p1.X;
double dy01 = p0.Y - p1.Y;
double dx12 = p1.X - p2.X;
double dy12 = p1.Y - p2.Y;
double dx20 = p2.X - p0.X;
double dy20 = p2.Y - p0.Y;
double area012 = dx01 * dy12 - dy01 * dx12;
double tol = FLT_EPSILON * area012;
double area01p = dx0p * dy1p - dx1p * dy0p;
double area12p = dx1p * dy2p - dx2p * dy1p;
double area20p = dx2p * dy0p - dx0p * dy2p;
return (area01p > -tol && area12p > -tol && area20p > -tol);
}
void element_quality(std::vector<Edge *> &triangle, std::vector<double> &radii, std::vector<double> &quality, Mesh const &m) {
radii.resize(0);
quality.resize(0);
radii.reserve(triangle.size());
quality.reserve(triangle.size());
for (size_t i = 0; i < triangle.size(); ++i) {
double r = m.circumradius(triangle[i]);
double l = m.shortest_edge_length(triangle[i]);
radii.push_back(r);
quality.push_back(l / r);
}
}
void sort_permutation_ascending(std::vector<double> &values, std::vector<size_t> &index) {
index.resize(values.size());
std::iota(index.begin(), index.end(), 0);
std::sort(index.begin(), index.end(), [&](size_t i, size_t j) { return (values[i] < values[j]); });
}
void sort_permutation_descending(std::vector<double> &values, std::vector<size_t> &index) {
index.resize(values.size());
std::iota(index.begin(), index.end(), 0);
std::sort(index.begin(), index.end(), [&](size_t i, size_t j) { return (values[i] > values[j]); });
}
\ No newline at end of file
#ifndef OERSTED_MESH_UTIL_H
#define OERSTED_MESH_UTIL_H
#include "Mesh.h"
// TODO: Make these mesh routines
bool are_intersecting(Edge const *e0, Edge const *e1, Mesh const &m);
bool in_triangle(Point const *p, Edge const *&e, Mesh const &m);
void element_quality(std::vector<Edge *> &triangles, std::vector<double> &radii, std::vector<double> &quality, Mesh const &m);
void sort_permutation_ascending(std::vector<double> &value, std::vector<size_t> &index);
void sort_permutation_descending(std::vector<double> &values, std::vector<size_t> &index);
#endif //OERSTED_MESH_UTIL_H
......@@ -282,7 +282,7 @@ TEST(CircularArc, on_manifold) {
}
}
TEST(CircularARc, on_segment) {
TEST(CircularArc, on_segment) {
{ //ARGS::(Vertex)
Sketch s;
......
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