Commit 04aef445 authored by JasonPries's avatar JasonPries
Browse files

Separate mesh/Point class in to own Point.h/Point.cpp files

Separate mesh/utility functions into own util.h/util.cpp files
parent 5f5fc33f
......@@ -11,7 +11,7 @@
<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/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" />
......@@ -24,22 +24,21 @@
<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/Length.h" 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/Constraint.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" />
......@@ -47,16 +46,21 @@
<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/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/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" />
<sourceFolder url="file://$MODULE_DIR$/src/Mesh/src/Mesh.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Mesh/src/Point.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Mesh/src/Mesh.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Mesh/src/Point.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Mesh/src/Edge.cpp" 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" />
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" />
<pair source="c" header="h" />
</extensions>
</Objective-C-extensions>
</value>
</option>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
</component>
</project>
\ No newline at end of file
......@@ -4,7 +4,9 @@ set(SOURCE_FILES
./include/Mesh.hpp
./src/Mesh.h ./src/Mesh.cpp
./src/Edge.h ./src/Edge.cpp)
./src/Edge.h ./src/Edge.cpp
./src/Point.h ./src/Point.cpp
./src/util.h ./src/util.cpp)
add_library(mesh STATIC ${SOURCE_FILES})
......
......@@ -3,5 +3,7 @@
#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
......@@ -3,9 +3,6 @@
#include "Mesh.h"
// Friend Utility
bool are_intersecting(const Edge *e0, const Edge *e1);
class Edge {
public:
friend class Mesh;
......@@ -89,13 +86,4 @@ protected:
bool Mark; // Auxillary variable for mesh refinement
};
// External Utility
void circumradius(std::vector<Edge *> &triangles, std::vector<double> &radii);
void shortest_edge_length(std::vector<Edge *> &triangles, std::vector<double> &length);
void element_quality(std::vector<Edge *> &triangles, std::vector<double> &radii, std::vector<double> &quality);
void sort_permutation(std::vector<double> &value, std::vector<size_t> &index);
#endif //OERSTED_EDGE_H
......@@ -735,7 +735,7 @@ void Mesh::save_as(std::string path, std::string file_name) const {
This is a stub for visualization
*/
if(!boost::filesystem::exists(path)) {
if (!boost::filesystem::exists(path)) {
boost::filesystem::create_directories(path);
}
......@@ -788,8 +788,7 @@ void Mesh::refine_once() {
void Mesh::refine_once(std::vector<size_t> index, std::vector<double> radii, std::vector<double> quality) {
for (size_t i = 0; i < Triangles.size(); ++i) {
size_t j = index[i];
if ((Triangles[j]->Mark) && ((radii[j] > MaximumElementSize) ||
(radii[j] > MinimumElementSize && quality[j] < MinimumElementQuality))) {
if ((Triangles[j]->Mark) && ((radii[j] > MaximumElementSize) || (radii[j] > MinimumElementSize && quality[j] < MinimumElementQuality))) {
//Triangles[j]->insert_circumcenter(Points, Edges);
insert_circumcenter(Triangles[j]);
}
......
......@@ -15,32 +15,7 @@ enum class InsertPointResult {
Success, Midpoint, Duplicate, Failure
};
class Point { // #TODO, Replace Verticies member in Mesh with lighterweight Node class
public:
Point() : X{0.0}, Y{0.0} {};
Point(double x, double y) : X{x}, Y{y} {};
Point(const Vertex &v) : X{v.x()}, Y{v.y()} {};
Point(const Vertex *v) : X{v->x()}, Y{v->y()} {};
//double W; // Nurbs weight?
double X;
double Y;
//double Z; // 3-Dimensions?
//Vertex* V = nullptr; Keep track of constrained nodes?
bool operator==(const Point &p) const { return (X == p.X) && (Y == p.Y); };
bool operator==(const Vertex &v) const { return (X == v.x()) && (Y == v.y()); };
bool operator!=(const Point &p) const { return (X != p.X) || (Y != p.Y); };
bool operator!=(const Vertex &v) const { return (X != v.x()) && (Y != v.y()); };
};
class Point;
class Edge;
......
#include "../include/Mesh.hpp"
#ifndef OERSTED_POINT_H
#define OERSTED_POINT_H
#include "Mesh.h"
class Point { // #TODO, Replace Verticies member in Mesh with lighterweight Node class
public:
Point() : X{0.0}, Y{0.0} {};
Point(double x, double y) : X{x}, Y{y} {};
Point(const Vertex &v) : X{v.x()}, Y{v.y()} {};
Point(const Vertex *v) : X{v->x()}, Y{v->y()} {};
//double W; // Nurbs weight?
double X;
double Y;
//double Z; // 3-Dimensions?
//Vertex* V = nullptr; Keep track of constrained nodes?
bool operator==(const Point &p) const { return (X == p.X) && (Y == p.Y); };
bool operator==(const Vertex &v) const { return (X == v.x()) && (Y == v.y()); };
bool operator!=(const Point &p) const { return (X != p.X) || (Y != p.Y); };
bool operator!=(const Vertex &v) const { return (X != v.x()) && (Y != v.y()); };
};
#endif //OERSTED_POINT_H
#include "../include/Mesh.hpp"
bool are_intersecting(const Edge *e0, const Edge *e1) {
// #TODO, Make more detailed return type enumeration
if (e0->ConstraintCurve != nullptr && e0->ConstraintCurve == e1->ConstraintCurve) {
return false;
}
const Point *v00 = e0->base();
const Point *v01 = e0->tip();
const Point *v10 = e1->base();
const Point *v11 = e1->tip();
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);
}
}
void circumradius(std::vector<Edge *> &triangles, std::vector<double> &radii) {
radii.resize(0);
radii.reserve(triangles.size());
for (size_t i = 0; i < triangles.size(); ++i) {
radii.push_back(triangles[i]->circumradius());
}
}
void shortest_edge_length(std::vector<Edge *> &triangle, std::vector<double> &length) {
length.resize(0);
length.reserve(triangle.size());
for (size_t i = 0; i < triangle.size(); ++i) {
length.push_back(triangle[i]->shortest_edge_length());
}
}
void element_quality(std::vector<Edge *> &triangle, std::vector<double> &radii, std::vector<double> &quality) {
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 = triangle[i]->circumradius();
double l = triangle[i]->shortest_edge_length();
radii.push_back(r);
quality.push_back(l / r);
}
}
void sort_permutation(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_UTIL_H
#define OERSTED_UTIL_H
#include "Mesh.h"
bool are_intersecting(const Edge *e0, const Edge *e1);
void circumradius(std::vector<Edge *> &triangles, std::vector<double> &radii);
void shortest_edge_length(std::vector<Edge *> &triangles, std::vector<double> &length);
void element_quality(std::vector<Edge *> &triangles, std::vector<double> &radii, std::vector<double> &quality);
void sort_permutation(std::vector<double> &value, std::vector<size_t> &index);
#endif //OERSTED_UTIL_H
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