Skip to content
Snippets Groups Projects
Commit eda987f4 authored by Karsten Rink's avatar Karsten Rink
Browse files

changed array to vector and handled re-ordering more elegantly

parent d6c9ad68
No related branches found
No related tags found
No related merge requests found
...@@ -137,14 +137,14 @@ BoundingSphere::BoundingSphere(const std::vector<GeoLib::Point*> &points) ...@@ -137,14 +137,14 @@ BoundingSphere::BoundingSphere(const std::vector<GeoLib::Point*> &points)
for(unsigned int i = 0; i < n_points; i++) for(unsigned int i = 0; i < n_points; i++)
sphere_points[i] = points[i]; sphere_points[i] = points[i];
const BoundingSphere bounding_sphere = recurseCalculation(sphere_points, n_points, 0); const BoundingSphere bounding_sphere = recurseCalculation(points, 0, points.size(), 0);
delete[] sphere_points; delete[] sphere_points;
this->_center = bounding_sphere.getCenter(); this->_center = bounding_sphere.getCenter();
this->_radius = bounding_sphere.getRadius(); this->_radius = bounding_sphere.getRadius();
} }
BoundingSphere BoundingSphere::recurseCalculation(GeoLib::Point* sphere_points[], std::size_t n_points, std::size_t n_boundary_points) BoundingSphere BoundingSphere::recurseCalculation(std::vector<GeoLib::Point*> sphere_points, std::size_t current_index, std::size_t n_points, std::size_t n_boundary_points)
{ {
BoundingSphere sphere; BoundingSphere sphere;
switch(n_boundary_points) switch(n_boundary_points)
...@@ -153,30 +153,29 @@ BoundingSphere BoundingSphere::recurseCalculation(GeoLib::Point* sphere_points[] ...@@ -153,30 +153,29 @@ BoundingSphere BoundingSphere::recurseCalculation(GeoLib::Point* sphere_points[]
sphere = BoundingSphere(); sphere = BoundingSphere();
break; break;
case 1: case 1:
sphere = BoundingSphere(*sphere_points[-1]); sphere = BoundingSphere(*sphere_points[current_index-1]);
break; break;
case 2: case 2:
sphere = BoundingSphere(*sphere_points[-1], *sphere_points[-2]); sphere = BoundingSphere(*sphere_points[current_index-1], *sphere_points[current_index-2]);
break; break;
case 3: case 3:
sphere = BoundingSphere(*sphere_points[-1], *sphere_points[-2], *sphere_points[-3]); sphere = BoundingSphere(*sphere_points[current_index-1], *sphere_points[current_index-2], *sphere_points[current_index-3]);
break; break;
case 4: case 4:
sphere = BoundingSphere(*sphere_points[-1], *sphere_points[-2], *sphere_points[-3], *sphere_points[-4]); sphere = BoundingSphere(*sphere_points[current_index-1], *sphere_points[current_index-2], *sphere_points[current_index-3], *sphere_points[current_index-4]);
return sphere; return sphere;
} }
for(std::size_t i=0; i<n_points; ++i) for(std::size_t i=current_index; i<n_points; ++i)
{ {
// current point is located outside of sphere
if(sphere.sqrPointDist(*sphere_points[i]) > 0) if(sphere.sqrPointDist(*sphere_points[i]) > 0)
{ {
for(unsigned int j = i; j > 0; --j) GeoLib::Point* tmp = sphere_points[i];
{ std::copy(sphere_points.begin(), sphere_points.begin() + i, sphere_points.begin() + 1);
GeoLib::Point* tmp = sphere_points[j]; sphere_points[0] = tmp;
sphere_points[j] = sphere_points[j - 1];
sphere_points[j - 1] = tmp; sphere = recurseCalculation(sphere_points, current_index+1, i, n_boundary_points+1);
}
sphere = recurseCalculation(sphere_points+1, i, n_boundary_points+1);
} }
} }
return sphere; return sphere;
......
...@@ -63,7 +63,7 @@ private: ...@@ -63,7 +63,7 @@ private:
* Algorithm based on Bernd Gärtner: Fast and Robust Smallest Enclosing Balls. ESA99, pages 325-338, 1999. * Algorithm based on Bernd Gärtner: Fast and Robust Smallest Enclosing Balls. ESA99, pages 325-338, 1999.
* Code based on "Smallest Enclosing Spheres" implementation by Nicolas Capens on flipcode's Developer Toolbox (www.flipcode.com) * Code based on "Smallest Enclosing Spheres" implementation by Nicolas Capens on flipcode's Developer Toolbox (www.flipcode.com)
*/ */
static BoundingSphere recurseCalculation(GeoLib::Point* sphere_points[], std::size_t n_points, std::size_t n_boundary_points); static BoundingSphere recurseCalculation(std::vector<GeoLib::Point*> sphere_points, std::size_t current_index, std::size_t n_points, std::size_t n_boundary_points);
double _radius; double _radius;
MathLib::Vector3 _center; MathLib::Vector3 _center;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment