Commit 8e5011bb authored by JasonPries's avatar JasonPries
Browse files

Change Sketch Constraint and Curve vectors from raw pointers to shared pointers

parent 1c94c79a
...@@ -542,7 +542,7 @@ void Mesh::create_boundary_polygon() { ...@@ -542,7 +542,7 @@ void Mesh::create_boundary_polygon() {
Edges.reserve(Boundary->size()); Edges.reserve(Boundary->size());
Points.reserve(Boundary->size()); Points.reserve(Boundary->size());
for (size_t i = 0; i != Boundary->size(); ++i) { for (size_t i = 0; i != Boundary->size(); ++i) {
Curve const *cc = Boundary->curve(i); //clone() to prevent alteration of input Contour when Edge is split std::shared_ptr<Curve> cc = Boundary->curve(i);
bool dir = Boundary->orientation(i); bool dir = Boundary->orientation(i);
Edge &e = new_edge(Points.size(), Constraints.size(), dir); // TODO: change to new_edge(Edge) Edge &e = new_edge(Points.size(), Constraints.size(), dir); // TODO: change to new_edge(Edge)
e.Twin = e.Self; e.Twin = e.Self;
...@@ -629,7 +629,7 @@ void Mesh::insert_internal_boundaries() { ...@@ -629,7 +629,7 @@ void Mesh::insert_internal_boundaries() {
*/ */
// Find interior curves // Find interior curves
std::vector<Curve const *> interior; std::vector<std::shared_ptr<Curve>> interior;
for (auto c : Curves) { for (auto c : Curves) {
bool on_exterior = false; bool on_exterior = false;
for (size_t i = 0; i != Boundary->size(); ++i) { for (size_t i = 0; i != Boundary->size(); ++i) {
...@@ -691,7 +691,7 @@ void Mesh::insert_internal_boundaries() { ...@@ -691,7 +691,7 @@ void Mesh::insert_internal_boundaries() {
} else { } else {
double s0 = dc.S0; double s0 = dc.S0;
double s1 = dc.S1; double s1 = dc.S1;
Curve const *cc = dc.ConstraintCurve; std::shared_ptr<Curve> cc = dc.ConstraintCurve;
double sn = (s0 + s1) / 2.0; double sn = (s0 + s1) / 2.0;
Point const p = cc->point(sn); Point const p = cc->point(sn);
...@@ -778,7 +778,7 @@ void Mesh::split_edge(size_t ei) { ...@@ -778,7 +778,7 @@ void Mesh::split_edge(size_t ei) {
DartConstraint &dc = Constraints[Edges[ei].Constraint]; DartConstraint &dc = Constraints[Edges[ei].Constraint];
double s0 = dc.S0; double s0 = dc.S0;
double s1 = dc.S1; double s1 = dc.S1;
Curve const *cc = dc.ConstraintCurve; std::shared_ptr<Curve> cc = dc.ConstraintCurve;
double sn = (s0 + s1) / 2.0; double sn = (s0 + s1) / 2.0;
dc.S1 = sn; dc.S1 = sn;
...@@ -1069,7 +1069,7 @@ InsertPointResult Mesh::insert_midpoint(size_t ei) { ...@@ -1069,7 +1069,7 @@ InsertPointResult Mesh::insert_midpoint(size_t ei) {
DartConstraint &dc = Constraints[Edges[ei].Constraint]; DartConstraint &dc = Constraints[Edges[ei].Constraint];
double s0 = dc.S0; double s0 = dc.S0;
double s1 = dc.S1; double s1 = dc.S1;
Curve const *cc = dc.ConstraintCurve; std::shared_ptr<Curve> cc = dc.ConstraintCurve;
double sn = (s0 + s1) / 2.0; double sn = (s0 + s1) / 2.0;
dc.S1 = sn; dc.S1 = sn;
......
...@@ -21,11 +21,11 @@ class DartConstraint { ...@@ -21,11 +21,11 @@ class DartConstraint {
public: public:
DartConstraint() : S0(DBL_MAX), S1(DBL_MAX), ConstraintCurve(nullptr) {}; DartConstraint() : S0(DBL_MAX), S1(DBL_MAX), ConstraintCurve(nullptr) {};
DartConstraint(double s0, double s1, Curve const *cc) : S0(s0), S1(s1), ConstraintCurve(cc) {}; DartConstraint(double s0, double s1, std::shared_ptr<Curve> cc) : S0(s0), S1(s1), ConstraintCurve(cc) {};
double S0; double S0;
double S1; double S1;
Curve const *ConstraintCurve; std::shared_ptr<Curve> ConstraintCurve;
}; };
class Mesh { class Mesh {
...@@ -92,7 +92,7 @@ public: ...@@ -92,7 +92,7 @@ public:
DartConstraint const constraint(size_t ei) const { return Constraints[Edges[ei].Constraint]; }; DartConstraint const constraint(size_t ei) const { return Constraints[Edges[ei].Constraint]; };
Curve const *constraint_curve(size_t ei) const { return Constraints[Edges[ei].Constraint].ConstraintCurve; }; std::shared_ptr<Curve> constraint_curve(size_t ei) const { return Constraints[Edges[ei].Constraint].ConstraintCurve; };
Point circumcenter(size_t ei) const; Point circumcenter(size_t ei) const;
...@@ -129,7 +129,7 @@ public: ...@@ -129,7 +129,7 @@ public:
protected: protected:
std::shared_ptr<Contour> Boundary; std::shared_ptr<Contour> Boundary;
std::vector<Curve const *> Curves; std::vector<std::shared_ptr<Curve>> Curves;
std::vector<std::shared_ptr<Contour>> Contours; std::vector<std::shared_ptr<Contour>> Contours;
std::vector<Point> Points; std::vector<Point> Points;
......
...@@ -3,14 +3,13 @@ ...@@ -3,14 +3,13 @@
class Angle : public Constraint { class Angle : public Constraint {
public: public:
LineSegment *Line0, *Line1; std::shared_ptr<LineSegment> Line0;
std::shared_ptr<LineSegment> Line1;
double Dim; double Dim;
// Constructors Angle(std::shared_ptr<LineSegment> l0, std::shared_ptr<LineSegment> l1, double angle) : Line0(l0), Line1(l1), Dim(angle) {};
Angle(LineSegment &l0, LineSegment &l1, double angle) : Line0(&l0), Line1(&l1), Dim(angle) {};
// Public Member Functions
size_t set_equation_index(size_t i) override { size_t set_equation_index(size_t i) override {
EquationIndex = i; EquationIndex = i;
return 1; return 1;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define OERSTED_BRANCH_H #define OERSTED_BRANCH_H
struct Branch { struct Branch {
const Curve *Path; std::shared_ptr<Curve> Path;
bool Orientation; bool Orientation;
double Angle; double Angle;
}; };
......
...@@ -199,10 +199,12 @@ bool CircularArc::on_manifold(const double x, const double y) const { ...@@ -199,10 +199,12 @@ bool CircularArc::on_manifold(const double x, const double y) const {
} }
} }
bool CircularArc::is_identical(const Curve *c) const { bool CircularArc::is_identical(std::shared_ptr<Curve> c) const {
const CircularArc *cc = dynamic_cast<const CircularArc *>(c); //const CircularArc *cc = dynamic_cast<const CircularArc *>(c);
if (cc == nullptr) { auto cc = std::dynamic_pointer_cast<CircularArc>(c);
if (cc.get() == nullptr) {
return false; return false;
} else { } else {
return is_identical( return is_identical(
...@@ -216,10 +218,12 @@ bool CircularArc::is_identical(const Curve *c) const { ...@@ -216,10 +218,12 @@ bool CircularArc::is_identical(const Curve *c) const {
} }
} }
bool CircularArc::is_identical(const Curve *c, std::shared_ptr<Vertex> origin, const double angle) const { bool CircularArc::is_identical(std::shared_ptr<Curve> c, std::shared_ptr<Vertex> origin, const double angle) const {
const CircularArc *cc = dynamic_cast<const CircularArc *>(c); //const CircularArc *cc = dynamic_cast<const CircularArc *>(c);
auto cc = std::dynamic_pointer_cast<CircularArc>(c);
if (cc == nullptr) { if (cc.get() == nullptr) {
return false; return false;
} else { } else {
double xc, yc, xs, ys, xe, ye; double xc, yc, xs, ys, xe, ye;
...@@ -245,10 +249,12 @@ bool CircularArc::is_identical(const double r, const double xc, const double yc, ...@@ -245,10 +249,12 @@ bool CircularArc::is_identical(const double r, const double xc, const double yc,
&& abs(end()->y() - ye) < tol; && abs(end()->y() - ye) < tol;
} }
bool CircularArc::is_coincident(const Curve *c) const { bool CircularArc::is_coincident(std::shared_ptr<Curve> c) const {
const CircularArc *cc = dynamic_cast<const CircularArc *>(c); //const CircularArc *cc = dynamic_cast<const CircularArc *>(c);
auto cc = std::dynamic_pointer_cast<CircularArc>(c);
if (cc == nullptr) { if (cc.get() == nullptr) {
return false; return false;
} else { } else {
// #TODO: Extract input curve center, put the rest of the method in subroutine // #TODO: Extract input curve center, put the rest of the method in subroutine
......
...@@ -13,10 +13,9 @@ public: ...@@ -13,10 +13,9 @@ public:
friend class Tangency; friend class Tangency;
// Constructors
CircularArc() : Curve(), Radius(std::make_shared<Variable>(0.0)) {}; CircularArc() : Curve(), Radius(std::make_shared<Variable>(0.0)) {};
CircularArc(const CircularArc *c) : Curve(c->Start, c->End, c->ForConstruction), Center(c->Center), Radius(c->Radius) {}; CircularArc(CircularArc const *c) : Curve(c->Start, c->End, c->ForConstruction), Center(c->Center), Radius(c->Radius) {};
CircularArc(std::shared_ptr<Vertex> v0, std::shared_ptr<Vertex> v1, std::shared_ptr<Vertex> c, bool fc = false) : Curve(v0, v1, fc), Center(c) {}; CircularArc(std::shared_ptr<Vertex> v0, std::shared_ptr<Vertex> v1, std::shared_ptr<Vertex> c, bool fc = false) : Curve(v0, v1, fc), Center(c) {};
...@@ -24,12 +23,10 @@ public: ...@@ -24,12 +23,10 @@ public:
CircularArc(std::shared_ptr<Vertex> v0, std::shared_ptr<Vertex> v1, std::shared_ptr<Vertex> c, std::shared_ptr<Variable> r, Sketch &s, bool fc = false) : Curve(v0, v1, fc), Center(c), Radius(r) {}; CircularArc(std::shared_ptr<Vertex> v0, std::shared_ptr<Vertex> v1, std::shared_ptr<Vertex> c, std::shared_ptr<Variable> r, Sketch &s, bool fc = false) : Curve(v0, v1, fc), Center(c), Radius(r) {};
// Accessors
std::shared_ptr<Vertex> center() const { return Center; }; std::shared_ptr<Vertex> center() const { return Center; };
double radius() const { return Radius->value(); }; double radius() const { return Radius->value(); };
// Virtual Function Implementation
void get_verticies(std::list<std::shared_ptr<Vertex>> &v) const override { void get_verticies(std::list<std::shared_ptr<Vertex>> &v) const override {
v.push_back(Start); v.push_back(Start);
v.push_back(End); v.push_back(End);
...@@ -45,7 +42,6 @@ public: ...@@ -45,7 +42,6 @@ public:
void update(Eigen::MatrixXd &J, Eigen::VectorXd &r) override; void update(Eigen::MatrixXd &J, Eigen::VectorXd &r) override;
// Calculation
sPoint point(double s) const override; sPoint point(double s) const override;
Vertex tangent(double s, bool orientation) const override; Vertex tangent(double s, bool orientation) const override;
...@@ -60,20 +56,17 @@ public: ...@@ -60,20 +56,17 @@ public:
std::pair<double, double> supremum() const override; std::pair<double, double> supremum() const override;
// Curve-Vertex Comparison
using Curve::on_manifold; using Curve::on_manifold;
using Curve::on_segment; using Curve::on_segment;
// Curve-Curve Comparison bool is_identical(std::shared_ptr<Curve> c) const override;
bool is_identical(const Curve *c) const override;
bool is_identical(const Curve *c, std::shared_ptr<Vertex> origin, const double angle) const override; bool is_identical(std::shared_ptr<Curve> c, std::shared_ptr<Vertex> origin, const double angle) const override;
bool is_coincident(const Curve *c) const override; bool is_coincident(std::shared_ptr<Curve> c) const override;
// Modification std::shared_ptr<Curve> clone() const override { return std::make_shared<CircularArc>(this); };
Curve *clone() const override { return new CircularArc(this); };
void replace_verticies(std::vector<std::shared_ptr<Vertex>> oldv, std::vector<std::shared_ptr<Vertex>> newv) override; void replace_verticies(std::vector<std::shared_ptr<Vertex>> oldv, std::vector<std::shared_ptr<Vertex>> newv) override;
......
...@@ -5,10 +5,10 @@ template<class T> ...@@ -5,10 +5,10 @@ template<class T>
class Coincident : public Constraint { class Coincident : public Constraint {
public: public:
std::shared_ptr<Vertex> Point; std::shared_ptr<Vertex> Point;
T *Element; std::shared_ptr<T> Element;
// Constructors // Constructors
Coincident(std::shared_ptr<Vertex> p, T &e) : Point(p), Element(&e) {}; Coincident(std::shared_ptr<Vertex> p, std::shared_ptr<T> e) : Point(p), Element(e) {};
// Public Member Functions // Public Member Functions
size_t set_equation_index(size_t i) override { size_t set_equation_index(size_t i) override {
......
...@@ -8,7 +8,7 @@ Constellation::Constellation(const Sketch *s) { ...@@ -8,7 +8,7 @@ Constellation::Constellation(const Sketch *s) {
} }
bool Constellation::twin(std::list<Star>::iterator &s_out, std::list<Branch>::iterator &b_out) { bool Constellation::twin(std::list<Star>::iterator &s_out, std::list<Branch>::iterator &b_out) {
const Curve *c = b_out->Path; // #TODO: Local variable 'c' is only assigned but never accessed std::shared_ptr<Curve> c = b_out->Path; // #TODO: Local variable 'c' is only assigned but never accessed
for (auto s = Stars.begin(); s != Stars.end(); ++s) { for (auto s = Stars.begin(); s != Stars.end(); ++s) {
if (s != s_out) { if (s != s_out) {
...@@ -44,7 +44,7 @@ void Constellation::supremum(std::list<Star>::iterator &s_out, std::list<Branch> ...@@ -44,7 +44,7 @@ void Constellation::supremum(std::list<Star>::iterator &s_out, std::list<Branch>
} }
} }
void Constellation::pop(const Curve *c) { void Constellation::pop(std::shared_ptr<Curve> c) {
bool iterate = true; bool iterate = true;
while (iterate) { while (iterate) {
...@@ -76,7 +76,7 @@ void Constellation::pop(const Curve *c) { ...@@ -76,7 +76,7 @@ void Constellation::pop(const Curve *c) {
} }
bool Constellation::boundary(std::shared_ptr<Contour> c) { bool Constellation::boundary(std::shared_ptr<Contour> c) {
std::vector<const Curve *> curves; std::vector<std::shared_ptr<Curve>> curves;
std::vector<bool> orientation; std::vector<bool> orientation;
// Base of induction // Base of induction
...@@ -122,7 +122,7 @@ bool Constellation::boundary(std::shared_ptr<Contour> c) { ...@@ -122,7 +122,7 @@ bool Constellation::boundary(std::shared_ptr<Contour> c) {
} }
bool Constellation::contours(std::vector<std::shared_ptr<Contour>> &contours) { bool Constellation::contours(std::vector<std::shared_ptr<Contour>> &contours) {
std::vector<const Curve *> contour_curves; std::vector<std::shared_ptr<Curve>> contour_curves;
std::vector<bool> orientation; std::vector<bool> orientation;
while (size() > 0) { while (size() > 0) {
...@@ -137,7 +137,7 @@ bool Constellation::contours(std::vector<std::shared_ptr<Contour>> &contours) { ...@@ -137,7 +137,7 @@ bool Constellation::contours(std::vector<std::shared_ptr<Contour>> &contours) {
return true; return true;
} }
bool Constellation::find_closed_contour(std::vector<const Curve *> &curves, std::vector<bool> &orientation) { bool Constellation::find_closed_contour(std::vector<std::shared_ptr<Curve>> &curves, std::vector<bool> &orientation) {
curves.resize(0); curves.resize(0);
orientation.resize(0); orientation.resize(0);
......
...@@ -19,13 +19,13 @@ public: ...@@ -19,13 +19,13 @@ public:
private: private:
std::list<Star> Stars; std::list<Star> Stars;
void pop(const Curve *c = nullptr); void pop(std::shared_ptr<Curve> c = nullptr);
bool twin(std::list<Star>::iterator &s_out, std::list<Branch>::iterator &b_out); bool twin(std::list<Star>::iterator &s_out, std::list<Branch>::iterator &b_out);
void supremum(std::list<Star>::iterator &s_out, std::list<Branch>::iterator &b_out); void supremum(std::list<Star>::iterator &s_out, std::list<Branch>::iterator &b_out);
bool find_closed_contour(std::vector<const Curve *> &curves, std::vector<bool> &orientation); bool find_closed_contour(std::vector<std::shared_ptr<Curve>> &curves, std::vector<bool> &orientation);
}; };
#endif //OERSTED_CONSTELLATION_H #endif //OERSTED_CONSTELLATION_H
\ No newline at end of file
#include "Sketch.hpp" #include "Sketch.hpp"
Contour::Contour(const std::vector<const Curve *> &c) { Contour::Contour(std::vector<std::shared_ptr<Curve>> const &c) {
// #TODO: Check for intersecting curves // #TODO: Check for intersecting curves
// #TODO: Check for ccw orientation of entire contour // #TODO: Check for ccw orientation of entire contour
Curves = std::vector<const Curve *>(); Curves = std::vector<std::shared_ptr<Curve>>();
Curves.reserve(c.size()); Curves.reserve(c.size());
std::vector<std::shared_ptr<Vertex>> start; std::vector<std::shared_ptr<Vertex>> start;
...@@ -56,7 +56,7 @@ Contour::Contour(const std::vector<const Curve *> &c) { ...@@ -56,7 +56,7 @@ Contour::Contour(const std::vector<const Curve *> &c) {
} }
} }
Contour::Contour(const std::vector<const Curve *> &c, const std::vector<bool> &dir) { Contour::Contour(std::vector<std::shared_ptr<Curve>> const &c, std::vector<bool> const &dir) {
bool success = initialize(c, dir); bool success = initialize(c, dir);
if (!success) { if (!success) {
...@@ -64,7 +64,7 @@ Contour::Contour(const std::vector<const Curve *> &c, const std::vector<bool> &d ...@@ -64,7 +64,7 @@ Contour::Contour(const std::vector<const Curve *> &c, const std::vector<bool> &d
} }
} }
bool Contour::initialize(const std::vector<const Curve *> &c, const std::vector<bool> &dir) { bool Contour::initialize(std::vector<std::shared_ptr<Curve>> const &c, std::vector<bool> const &dir) {
Curves.resize(0); Curves.resize(0);
Orientation.resize(0); Orientation.resize(0);
......
...@@ -6,22 +6,22 @@ ...@@ -6,22 +6,22 @@
class Contour { class Contour {
public: public:
// Constructors // Constructors
Contour() : Curves(std::vector<const Curve *>()), Orientation(std::vector<bool>()) {}; Contour() : Curves(std::vector<std::shared_ptr<Curve>>()), Orientation(std::vector<bool>()) {};
Contour(const std::vector<const Curve *> &c); Contour(std::vector<std::shared_ptr<Curve>> const &c);
Contour(const std::vector<const Curve *> &c, const std::vector<bool> &dir); Contour(std::vector<std::shared_ptr<Curve>> const &c, std::vector<bool> const &dir);
//Public Member Functions //Public Member Functions
std::shared_ptr<Vertex> vertex(size_t i) const { return (Orientation[i] ? Curves[i]->start() : Curves[i]->end()); }; std::shared_ptr<Vertex> vertex(size_t i) const { return (Orientation[i] ? Curves[i]->start() : Curves[i]->end()); };
const Curve *curve(size_t i) const { return Curves[i]; }; std::shared_ptr<Curve> curve(size_t i) const { return Curves[i]; };
const bool orientation(size_t i) const { return Orientation[i]; }; const bool orientation(size_t i) const { return Orientation[i]; };
const size_t size() const { return Curves.size(); }; const size_t size() const { return Curves.size(); };
bool initialize(const std::vector<const Curve *> &c, const std::vector<bool> &dir); bool initialize(std::vector<std::shared_ptr<Curve>> const &c, std::vector<bool> const &dir);
auto begin() { return Curves.begin(); }; auto begin() { return Curves.begin(); };
...@@ -36,7 +36,7 @@ public: ...@@ -36,7 +36,7 @@ public:
double area() const; double area() const;
private: private:
std::vector<const Curve *> Curves; std::vector<std::shared_ptr<Curve>> Curves;
std::vector<bool> Orientation; std::vector<bool> Orientation;
}; };
......
...@@ -46,19 +46,19 @@ public: ...@@ -46,19 +46,19 @@ public:
virtual bool on_segment(std::shared_ptr<Vertex> v, std::shared_ptr<Vertex> origin, const double angle) const final; virtual bool on_segment(std::shared_ptr<Vertex> v, std::shared_ptr<Vertex> origin, const double angle) const final;
// Curve-Curve Comparison // Curve-Curve Comparison
virtual bool is_identical(const Curve *c) const = 0; // true if (input curve) XOR (object curve) is a set with measure < tol virtual bool is_identical(std::shared_ptr<Curve> c) const = 0; // true if (input curve) XOR (object curve) is a set with measure < tol
virtual bool is_identical(const Curve *c, std::shared_ptr<Vertex> origin, const double angle) const = 0; virtual bool is_identical(std::shared_ptr<Curve> c, std::shared_ptr<Vertex> origin, const double angle) const = 0;
// #TODO: virtual bool is_overlapping(const Curve* c) const = 0; // true if (input curve) AND (object curve) is a set with measure > tol // #TODO: virtual bool is_overlapping(const Curve* c) const = 0; // true if (input curve) AND (object curve) is a set with measure > tol
// #TODO: virtual bool is_overlapping(const Curve* c, const Vertex* origin, const double_t angle) const = 0; // #TODO: virtual bool is_overlapping(const Curve* c, const Vertex* origin, const double_t angle) const = 0;
virtual bool is_coincident(const Curve *c) const = 0; // true if (input curve) AND (object curve + parametric extension) is a set with measure > tol virtual bool is_coincident(std::shared_ptr<Curve> c) const = 0; // true if (input curve) AND (object curve + parametric extension) is a set with measure > tol
// #TODO: virtual bool is_coincident(const Curve* c, const Vertex* origin, const double_t angle) const = 0; // #TODO: virtual bool is_coincident(const Curve* c, const Vertex* origin, const double_t angle) const = 0;
// Modification // Modification
void reverse() { std::swap(Start, End); }; void reverse() { std::swap(Start, End); };
virtual Curve *clone() const = 0; virtual std::shared_ptr<Curve> clone() const = 0;
virtual void replace_verticies(std::vector<std::shared_ptr<Vertex>> oldv, std::vector<std::shared_ptr<Vertex>> newv) = 0; virtual void replace_verticies(std::vector<std::shared_ptr<Vertex>> oldv, std::vector<std::shared_ptr<Vertex>> newv) = 0;
......
...@@ -204,17 +204,17 @@ template ...@@ -204,17 +204,17 @@ template
class Distance<LineSegment>; class Distance<LineSegment>;
template<> template<>
size_t Distance<std::shared_ptr<Vertex>>::set_equation_index(size_t i) { size_t Distance<Vertex>::set_equation_index(size_t i) {
EquationIndex = i; EquationIndex = i;
return 1; return 1;
} }
template<> template<>
void Distance<std::shared_ptr<Vertex>>::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) { void Distance<Vertex>::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) {
const double x0 = (*Element0)->x(); const double x0 = Element0->x();
const double y0 = (*Element0)->y(); const double y0 = Element0->y();
const double x1 = (*Element1)->x(); const double x1 = Element1->x();
const double y1 = (*Element1)->y(); const double y1 = Element1->y();
double dx = x1 - x0;