diff --git a/GeoLib/BoundingSphere.cpp b/GeoLib/BoundingSphere.cpp index f99283ccac721bc2f535a24ce4b3686802569601..db4dddb39087062e3a921a19baf2f15f4c799948 100644 --- a/GeoLib/BoundingSphere.cpp +++ b/GeoLib/BoundingSphere.cpp @@ -85,16 +85,19 @@ BoundingSphere::BoundingSphere(const GeoLib::Point &p, const GeoLib::Point &q, c BoundingSphere::BoundingSphere(const std::vector<GeoLib::Point*> &points) : _center(0,0,0), _radius(-1) { - std::vector<GeoLib::Point*> sphere_points; - sphere_points.reserve(points.size()); - std::copy(points.cbegin(), points.cend(), std::back_inserter(sphere_points)); - - const BoundingSphere bounding_sphere = recurseCalculation(sphere_points, sphere_points.size(), 0); + const std::size_t n_points (points.size()); + GeoLib::Point **sphere_points = new GeoLib::Point*[n_points]; + for(unsigned int i = 0; i < n_points; i++) + sphere_points[i] = points[i]; + + const BoundingSphere bounding_sphere = recurseCalculation(sphere_points, n_points, 0); + delete[] sphere_points; + this->_center = bounding_sphere.getCenter(); this->_radius = bounding_sphere.getRadius(); } -BoundingSphere BoundingSphere::recurseCalculation(std::vector<GeoLib::Point*> &sphere_points, std::size_t idx, std::size_t boundary_points) +BoundingSphere BoundingSphere::recurseCalculation(GeoLib::Point* sphere_points[], std::size_t n_points, std::size_t boundary_points) { BoundingSphere sphere; switch(boundary_points) @@ -103,34 +106,31 @@ BoundingSphere BoundingSphere::recurseCalculation(std::vector<GeoLib::Point*> &s sphere = BoundingSphere(); break; case 1: - sphere = BoundingSphere(*sphere_points[0]); + sphere = BoundingSphere(*sphere_points[-1]); break; case 2: - sphere = BoundingSphere(*sphere_points[0], *sphere_points[1]); + sphere = BoundingSphere(*sphere_points[-1], *sphere_points[-2]); break; case 3: - sphere = BoundingSphere(*sphere_points[0], *sphere_points[1], *sphere_points[2]); + sphere = BoundingSphere(*sphere_points[-1], *sphere_points[-2], *sphere_points[-3]); break; case 4: - { - sphere = BoundingSphere(*sphere_points[0], *sphere_points[1], *sphere_points[2], *sphere_points[3]); + sphere = BoundingSphere(*sphere_points[-1], *sphere_points[-2], *sphere_points[-3], *sphere_points[-4]); return sphere; } - } - for(std::size_t i=0; i<idx; ++i) + for(std::size_t i=0; i<n_points; ++i) { if(sphere.sqrPointDist(*sphere_points[i]) > 0) { - for(std::size_t j=i; j>0; --j) + for(unsigned int j = i; j > 0; j--) { GeoLib::Point* tmp = sphere_points[j]; - sphere_points[j] = sphere_points[j-1]; + sphere_points[j] = sphere_points[j - 1]; sphere_points[j - 1] = tmp; } - - sphere = recurseCalculation(sphere_points, i, boundary_points+1); } + sphere = recurseCalculation(sphere_points+1, i, boundary_points+1); } return sphere; } diff --git a/GeoLib/BoundingSphere.h b/GeoLib/BoundingSphere.h index b39e371eb0892709382b2433215af40420763e54..2650edff4a6ef19c94ec9e843bb5fd699ead70af 100644 --- a/GeoLib/BoundingSphere.h +++ b/GeoLib/BoundingSphere.h @@ -62,7 +62,7 @@ private: * Algorithm based on Bernd Gärtner: Fast and Robust Smallest Enclosing Balls. ESA99, pages 325-338, 1999. * Code based on "Smallest Enclosing Spheres" by Nicolas Capens on flipcode's Developer Toolbox (www.flipcode.com) */ - static BoundingSphere recurseCalculation(std::vector<GeoLib::Point*> &sphere_points, std::size_t idx, std::size_t boundary_points); + static BoundingSphere recurseCalculation(GeoLib::Point* sphere_points[], std::size_t n_points, std::size_t boundary_points); double _radius; MathLib::Vector3 _center; diff --git a/Gui/mainwindow.cpp b/Gui/mainwindow.cpp index b785050a9655558ad2c588488fcfe1294bd7c690..15b39980ecf5eb0040bd416f90aedd797d469203 100644 --- a/Gui/mainwindow.cpp +++ b/Gui/mainwindow.cpp @@ -1302,14 +1302,15 @@ void MainWindow::showDataExplorerSettingsDialog() void MainWindow::FEMTestStart() { std::vector<GeoLib::Point*> *pnts = const_cast<std::vector<GeoLib::Point*>*>(this->_project.getGEOObjects()->getPointVec("testgeo")); - //GeoLib::BoundingSphere s(*pnts); - //std::vector<size_t> perm(4); - //std::iota(perm.begin(), perm.end(), 0); - //BaseLib::Quicksort<GeoLib::Point*>(*pnts, 0, pnts->size(), perm); - GeoLib::BoundingSphere s(*(pnts->at(0)), *(pnts->at(1)), *(pnts->at(2)));//, *(pnts->at(3))); - GeoLib::Point c = s.getCenter(); + //GeoLib::BoundingSphere s(*(pnts->at(0)), *(pnts->at(1)), *(pnts->at(2)), *(pnts->at(3))); + GeoLib::BoundingSphere s(*pnts); + GeoLib::Point* c = new GeoLib::Point(s.getCenter().getCoords()); double r = s.getRadius(); - std::cout << "Center: (" << c[0] << ", " << c[1] << ", " << c[2] << "), Radius: " << r << std::endl; + std::cout << "Center: (" << (*c)[0] << ", " << (*c)[1] << ", " << (*c)[2] << "), Radius: " << r << std::endl; + std::vector<GeoLib::Point*> *result = (s.getSpherePoints(10000)); + result->push_back(c); + std::string geo_name("result"); + _project.getGEOObjects()->addPointVec(result, geo_name); } void MainWindow::showTrackingSettingsDialog()