Skip to content
Snippets Groups Projects
Commit 304cfd65 authored by Tom Fischer's avatar Tom Fischer
Browse files

Merge pull request #1053 from TomFischer/ReworkSurface

Avoid warning/error/debug messages in SurfaceGrid
parents ded4ab13 ca15be85
No related branches found
No related tags found
No related merge requests found
......@@ -40,8 +40,6 @@ Surface::~Surface ()
{
for (std::size_t k(0); k < _sfc_triangles.size(); k++)
delete _sfc_triangles[k];
delete _bounding_volume;
delete _surface_grid;
}
void Surface::addTriangle(std::size_t pnt_a, std::size_t pnt_b, std::size_t pnt_c)
......@@ -52,31 +50,20 @@ void Surface::addTriangle(std::size_t pnt_a, std::size_t pnt_b, std::size_t pnt_
if (pnt_a == pnt_b || pnt_a == pnt_c || pnt_b == pnt_c)
return;
// Adding a new triangle invalides the surface grid.
_surface_grid.reset();
_sfc_triangles.push_back(new Triangle(_sfc_pnts, pnt_a, pnt_b, pnt_c));
if (!_bounding_volume) {
std::vector<std::size_t> ids(3);
ids[0] = pnt_a;
ids[1] = pnt_b;
ids[2] = pnt_c;
_bounding_volume = new AABB(_sfc_pnts, ids);
if (_surface_grid == nullptr) {
_surface_grid = new SurfaceGrid(this);
}
_bounding_volume.reset(new AABB(_sfc_pnts, ids));
} else {
bool bbx_updated(_bounding_volume->update(*_sfc_pnts[pnt_a]));
bbx_updated = bbx_updated || _bounding_volume->update(*_sfc_pnts[pnt_b]);
bbx_updated = bbx_updated || _bounding_volume->update(*_sfc_pnts[pnt_c]);
if (bbx_updated) {
delete _surface_grid;
_surface_grid = new SurfaceGrid(this);
} else {
if (! _surface_grid->sortTriangleInGridCells(_sfc_triangles.back())) {
ERR("Fatal: Could not insert triangle into surface grid. "
"To keep things consistent, the triangle is removed from "
"the surface!");
_sfc_triangles.pop_back();
}
}
_bounding_volume->update(*_sfc_pnts[pnt_a]);
_bounding_volume->update(*_sfc_pnts[pnt_b]);
_bounding_volume->update(*_sfc_pnts[pnt_c]);
}
}
......@@ -141,6 +128,10 @@ bool Surface::isPntInBoundingVolume(MathLib::Point3d const& pnt) const
bool Surface::isPntInSfc(MathLib::Point3d const& pnt) const
{
// Mutable _surface_grid is constructed if method is called the first time.
if (_surface_grid == nullptr) {
_surface_grid.reset(new SurfaceGrid(this));
}
return _surface_grid->isPointInSurface(
pnt, std::numeric_limits<double>::epsilon());
}
......
......@@ -16,6 +16,7 @@
#define SURFACE_H_
#include <vector>
#include <memory>
#include "GeoObject.h"
#include "Point.h"
......@@ -95,9 +96,12 @@ protected:
/** position of pointers to the geometric points */
std::vector<Triangle*> _sfc_triangles;
/** bounding volume is an axis aligned bounding box */
AABB *_bounding_volume;
/** a helper structure to accelerate the search */
SurfaceGrid * _surface_grid;
std::unique_ptr<AABB> _bounding_volume;
/// The surface grid is a helper data structure to accelerate the point
/// search. The method addTriangle() invalidates/resets the surface grid.
/// A valid surface grid is created in case the const method isPntInSfc() is
/// called and a valid surface grid is not existing.
mutable std::unique_ptr<SurfaceGrid> _surface_grid;
};
}
......
......@@ -120,10 +120,11 @@ void SurfaceGrid::sortTrianglesInGridCells(Surface const*const sfc)
Point const& p0(*((*sfc)[l]->getPoint(0)));
Point const& p1(*((*sfc)[l]->getPoint(1)));
Point const& p2(*((*sfc)[l]->getPoint(2)));
DBUG("Sorting triangle %d [(%f,%f,%f), (%f,%f,%f), (%f,%f,%f) into "
ERR("Sorting triangle %d [(%f,%f,%f), (%f,%f,%f), (%f,%f,%f) into "
"grid.",
l, p0[0], p0[1], p0[2], p1[0], p1[1], p1[2], p2[0], p2[1], p2[2]
);
std::abort();
}
}
}
......
......@@ -34,7 +34,6 @@ public:
double eps = std::numeric_limits<double>::epsilon()) const;
private:
friend GeoLib::Surface;
void sortTrianglesInGridCells(GeoLib::Surface const*const surface);
bool sortTriangleInGridCells(GeoLib::Triangle const*const triangle);
boost::optional<std::array<std::size_t,3>>
......
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