From 01670ac971fc604f735467c50929d29010206712 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Mon, 19 Jan 2015 08:05:14 +0100 Subject: [PATCH] [GL] Using MathPoint instead of Point in MinimalBoundingSphere. --- GeoLib/MinimalBoundingSphere.cpp | 40 +++++++++++++++++++++----------- GeoLib/MinimalBoundingSphere.h | 29 +++++++++++++++-------- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/GeoLib/MinimalBoundingSphere.cpp b/GeoLib/MinimalBoundingSphere.cpp index 705b4012168..a5af6a2cf7c 100644 --- a/GeoLib/MinimalBoundingSphere.cpp +++ b/GeoLib/MinimalBoundingSphere.cpp @@ -26,12 +26,14 @@ MinimalBoundingSphere::MinimalBoundingSphere() { } -MinimalBoundingSphere::MinimalBoundingSphere(GeoLib::Point const& p, double radius) +MinimalBoundingSphere::MinimalBoundingSphere( + MathLib::MathPoint const& p, double radius) : _radius(radius), _center(p) { } -MinimalBoundingSphere::MinimalBoundingSphere(GeoLib::Point const& p, GeoLib::Point const& q) +MinimalBoundingSphere::MinimalBoundingSphere( + MathLib::MathPoint const& p, MathLib::MathPoint const& q) : _radius(std::numeric_limits<double>::epsilon()), _center(p) { MathLib::Vector3 const a(p, q); @@ -44,7 +46,8 @@ MinimalBoundingSphere::MinimalBoundingSphere(GeoLib::Point const& p, GeoLib::Poi } } -MinimalBoundingSphere::MinimalBoundingSphere(GeoLib::Point const& p, GeoLib::Point const& q, GeoLib::Point const& r) +MinimalBoundingSphere::MinimalBoundingSphere(MathLib::MathPoint const& p, + MathLib::MathPoint const& q, MathLib::MathPoint const& r) { MathLib::Vector3 const a(p,r); MathLib::Vector3 const b(p,q); @@ -72,7 +75,10 @@ MinimalBoundingSphere::MinimalBoundingSphere(GeoLib::Point const& p, GeoLib::Poi } } -MinimalBoundingSphere::MinimalBoundingSphere(GeoLib::Point const& p, GeoLib::Point const& q, GeoLib::Point const& r, GeoLib::Point const& s) +MinimalBoundingSphere::MinimalBoundingSphere(MathLib::MathPoint const& p, + MathLib::MathPoint const& q, + MathLib::MathPoint const& r, + MathLib::MathPoint const& s) { MathLib::Vector3 const a(p, q); MathLib::Vector3 const b(p, r); @@ -115,16 +121,22 @@ MinimalBoundingSphere::MinimalBoundingSphere(GeoLib::Point const& p, GeoLib::Poi } } -MinimalBoundingSphere::MinimalBoundingSphere(std::vector<GeoLib::Point*> const& points) +MinimalBoundingSphere::MinimalBoundingSphere( + std::vector<MathLib::MathPoint*> const& points) : _radius(-1), _center(0,0,0) { - std::vector<GeoLib::Point*> sphere_points(points); + std::vector<MathLib::MathPoint*> sphere_points(points); MinimalBoundingSphere const bounding_sphere = recurseCalculation(sphere_points, 0, sphere_points.size(), 0); _center = bounding_sphere.getCenter(); _radius = bounding_sphere.getRadius(); } -MinimalBoundingSphere MinimalBoundingSphere::recurseCalculation(std::vector<GeoLib::Point*> sphere_points, std::size_t start_idx, std::size_t length, std::size_t n_boundary_points) +MinimalBoundingSphere +MinimalBoundingSphere::recurseCalculation( + std::vector<MathLib::MathPoint*> sphere_points, + std::size_t start_idx, + std::size_t length, + std::size_t n_boundary_points) { MinimalBoundingSphere sphere; switch(n_boundary_points) @@ -153,8 +165,10 @@ MinimalBoundingSphere MinimalBoundingSphere::recurseCalculation(std::vector<GeoL { if (i>start_idx) { - GeoLib::Point* tmp = sphere_points[start_idx+i]; - std::copy(sphere_points.begin() + start_idx, sphere_points.begin() + (start_idx + i), sphere_points.begin() + (start_idx + 1)); + MathLib::MathPoint* tmp = sphere_points[start_idx+i]; + std::copy(sphere_points.begin() + start_idx, + sphere_points.begin() + (start_idx + i), + sphere_points.begin() + (start_idx + 1)); sphere_points[start_idx] = tmp; } sphere = recurseCalculation(sphere_points, start_idx+1, i, n_boundary_points+1); @@ -163,14 +177,14 @@ MinimalBoundingSphere MinimalBoundingSphere::recurseCalculation(std::vector<GeoL return sphere; } -double MinimalBoundingSphere::pointDistanceSquared(GeoLib::Point const& pnt) const +double MinimalBoundingSphere::pointDistanceSquared(MathLib::MathPoint const& pnt) const { return MathLib::sqrDist(_center.getCoords(), pnt.getCoords())-(_radius*_radius); } -std::vector<GeoLib::Point*>* MinimalBoundingSphere::getRandomSpherePoints(std::size_t n_points) const +std::vector<MathLib::MathPoint*>* MinimalBoundingSphere::getRandomSpherePoints(std::size_t n_points) const { - std::vector<GeoLib::Point*> *pnts = new std::vector<GeoLib::Point*>; + std::vector<MathLib::MathPoint*> *pnts = new std::vector<MathLib::MathPoint*>; pnts->reserve(n_points); srand ( static_cast<unsigned>(time(NULL)) ); @@ -184,7 +198,7 @@ std::vector<GeoLib::Point*>* MinimalBoundingSphere::getRandomSpherePoints(std::s sum+=(vec[i]*vec[i]); } double const fac (_radius/sqrt(sum)); - pnts->push_back(new GeoLib::Point(_center[0]+vec[0]*fac, _center[1]+vec[1]*fac, _center[2]+vec[2]*fac)); + pnts->push_back(new MathLib::MathPoint(_center+fac * vec)); } return pnts; } diff --git a/GeoLib/MinimalBoundingSphere.h b/GeoLib/MinimalBoundingSphere.h index f39760c0d62..6b934d1682e 100644 --- a/GeoLib/MinimalBoundingSphere.h +++ b/GeoLib/MinimalBoundingSphere.h @@ -19,7 +19,7 @@ #include <vector> #include "MathLib/Vector3.h" -#include "Point.h" +#include "MathLib/MathPoint.h" namespace GeoLib { @@ -33,28 +33,33 @@ public: /// Copy constructor MinimalBoundingSphere(MinimalBoundingSphere const&) = default; /// Point-Sphere - MinimalBoundingSphere(GeoLib::Point const& p, double radius = std::numeric_limits<double>::epsilon()); + MinimalBoundingSphere(MathLib::MathPoint const& p, double radius = std::numeric_limits<double>::epsilon()); /// Bounding sphere using two points - MinimalBoundingSphere(GeoLib::Point const& p, GeoLib::Point const& q); + MinimalBoundingSphere(MathLib::MathPoint const& p, MathLib::MathPoint const& q); /// Bounding sphere using three points - MinimalBoundingSphere(GeoLib::Point const& p, GeoLib::Point const& q, GeoLib::Point const& r); + MinimalBoundingSphere(MathLib::MathPoint const& p, + MathLib::MathPoint const& q, MathLib::MathPoint const& r); /// Bounding sphere using four points - MinimalBoundingSphere(GeoLib::Point const& p, GeoLib::Point const& q, GeoLib::Point const& r, GeoLib::Point const& s); + MinimalBoundingSphere(MathLib::MathPoint const& p, + MathLib::MathPoint const& q, + MathLib::MathPoint const& r, + MathLib::MathPoint const& s); /// Bounding sphere of n points - MinimalBoundingSphere(std::vector<GeoLib::Point*> const& points); + MinimalBoundingSphere(std::vector<MathLib::MathPoint*> const& points); ~MinimalBoundingSphere() {} /// Returns the center point of the sphere - GeoLib::Point getCenter() const { return GeoLib::Point(_center.getCoords()); } + MathLib::MathPoint getCenter() const { return MathLib::MathPoint(_center.getCoords()); } /// Returns the radius of the sphere double getRadius() const {return _radius; } /// Returns the squared euclidean distance of a point from the sphere (for points within the sphere distance is negative) - double pointDistanceSquared(GeoLib::Point const& pnt) const; + double pointDistanceSquared(MathLib::MathPoint const& pnt) const; /// Creates n_points random points located on the surface of the bounding sphere (useful for visualisation) - std::vector<GeoLib::Point*>* getRandomSpherePoints(std::size_t n_points) const; + std::vector<MathLib::MathPoint*>* + getRandomSpherePoints(std::size_t n_points) const; private: /// Constructor using no points @@ -73,7 +78,11 @@ private: * Bernd Gaertner: Fast and Robust Smallest Enclosing Balls. ESA99, pp. 325--338, 1999. * Code based on "Smallest Enclosing Spheres" implementation by Nicolas Capens on flipcode's Developer Toolbox (www.flipcode.com) */ - static MinimalBoundingSphere recurseCalculation(std::vector<GeoLib::Point*> sphere_points, std::size_t start_idx, std::size_t length, std::size_t n_boundary_points); + static MinimalBoundingSphere recurseCalculation( + std::vector<MathLib::MathPoint*> sphere_points, + std::size_t start_idx, + std::size_t length, + std::size_t n_boundary_points); double _radius; MathLib::Vector3 _center; -- GitLab