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

[GL] Surface: clang format + cleanup file header.

parent faacf772
No related branches found
No related tags found
No related merge requests found
/**
* \file
* \author Thomas Fischer
* \date 2010-04-22
* \brief Implementation of the Surface class.
*
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
......@@ -31,20 +27,26 @@
namespace GeoLib
{
Surface::Surface (const std::vector<Point*> &pnt_vec) :
GeoObject(), _sfc_pnts(pnt_vec), _bounding_volume(nullptr),
_surface_grid(nullptr)
{}
Surface::Surface(const std::vector<Point*>& pnt_vec)
: GeoObject(),
_sfc_pnts(pnt_vec),
_bounding_volume(nullptr),
_surface_grid(nullptr)
{
}
Surface::~Surface ()
Surface::~Surface()
{
for (std::size_t k(0); k < _sfc_triangles.size(); k++)
delete _sfc_triangles[k];
}
void Surface::addTriangle(std::size_t pnt_a, std::size_t pnt_b, std::size_t pnt_c)
void Surface::addTriangle(std::size_t pnt_a,
std::size_t pnt_b,
std::size_t pnt_c)
{
assert (pnt_a < _sfc_pnts.size() && pnt_b < _sfc_pnts.size() && pnt_c < _sfc_pnts.size());
assert(pnt_a < _sfc_pnts.size() && pnt_b < _sfc_pnts.size() &&
pnt_c < _sfc_pnts.size());
// Check if two points of the triangle have identical IDs
if (pnt_a == pnt_b || pnt_a == pnt_c || pnt_b == pnt_c)
......@@ -54,92 +56,110 @@ void Surface::addTriangle(std::size_t pnt_a, std::size_t pnt_b, std::size_t pnt_
_surface_grid.reset();
_sfc_triangles.push_back(new Triangle(_sfc_pnts, pnt_a, pnt_b, pnt_c));
if (!_bounding_volume) {
if (!_bounding_volume)
{
std::vector<std::size_t> ids(3);
ids[0] = pnt_a;
ids[1] = pnt_b;
ids[2] = pnt_c;
_bounding_volume.reset(new AABB(_sfc_pnts, ids));
} else {
}
else
{
_bounding_volume->update(*_sfc_pnts[pnt_a]);
_bounding_volume->update(*_sfc_pnts[pnt_b]);
_bounding_volume->update(*_sfc_pnts[pnt_c]);
}
}
Surface* Surface::createSurface(const Polyline &ply)
Surface* Surface::createSurface(const Polyline& ply)
{
if (!ply.isClosed()) {
if (!ply.isClosed())
{
WARN("Error in Surface::createSurface() - Polyline is not closed.");
return nullptr;
}
if (ply.getNumberOfPoints() > 2) {
if (ply.getNumberOfPoints() > 2)
{
// create empty surface
Surface *sfc(new Surface(ply.getPointsVec()));
Surface* sfc(new Surface(ply.getPointsVec()));
Polygon* polygon (new Polygon (ply));
polygon->computeListOfSimplePolygons ();
Polygon* polygon(new Polygon(ply));
polygon->computeListOfSimplePolygons();
// create surfaces from simple polygons
const std::list<GeoLib::Polygon*>& list_of_simple_polygons (polygon->getListOfSimplePolygons());
for (std::list<GeoLib::Polygon*>::const_iterator simple_polygon_it (list_of_simple_polygons.begin());
simple_polygon_it != list_of_simple_polygons.end(); ++simple_polygon_it) {
const std::list<GeoLib::Polygon*>& list_of_simple_polygons(
polygon->getListOfSimplePolygons());
for (std::list<GeoLib::Polygon*>::const_iterator simple_polygon_it(
list_of_simple_polygons.begin());
simple_polygon_it != list_of_simple_polygons.end();
++simple_polygon_it)
{
std::list<GeoLib::Triangle> triangles;
GeoLib::EarClippingTriangulation(*simple_polygon_it, triangles);
// add Triangles to Surface
std::list<GeoLib::Triangle>::const_iterator it (triangles.begin());
while (it != triangles.end()) {
sfc->addTriangle ((*it)[0], (*it)[1], (*it)[2]);
std::list<GeoLib::Triangle>::const_iterator it(triangles.begin());
while (it != triangles.end())
{
sfc->addTriangle((*it)[0], (*it)[1], (*it)[2]);
++it;
}
}
delete polygon;
if (sfc->getNTriangles() == 0) {
WARN("Surface::createSurface(): Triangulation does not contain any triangle.");
if (sfc->getNTriangles() == 0)
{
WARN(
"Surface::createSurface(): Triangulation does not contain any "
"triangle.");
delete sfc;
return nullptr;
}
return sfc;
} else {
WARN("Error in Surface::createSurface() - Polyline consists of less than three points and therefore cannot be triangulated.");
}
else
{
WARN(
"Error in Surface::createSurface() - Polyline consists of less "
"than three points and therefore cannot be triangulated.");
return nullptr;
}
}
std::size_t Surface::getNTriangles () const
std::size_t Surface::getNTriangles() const
{
return _sfc_triangles.size();
}
const Triangle* Surface::operator[] (std::size_t i) const
const Triangle* Surface::operator[](std::size_t i) const
{
assert (i < _sfc_triangles.size());
assert(i < _sfc_triangles.size());
return _sfc_triangles[i];
}
bool Surface::isPntInBoundingVolume(MathLib::Point3d const& pnt) const
{
return _bounding_volume->containsPoint (pnt);
return _bounding_volume->containsPoint(pnt);
}
bool Surface::isPntInSfc(MathLib::Point3d const& pnt) const
{
// Mutable _surface_grid is constructed if method is called the first time.
if (_surface_grid == nullptr) {
if (_surface_grid == nullptr)
{
_surface_grid.reset(new SurfaceGrid(this));
}
return _surface_grid->isPointInSurface(
pnt, std::numeric_limits<double>::epsilon());
}
const Triangle* Surface::findTriangle (MathLib::Point3d const& pnt) const
const Triangle* Surface::findTriangle(MathLib::Point3d const& pnt) const
{
for (std::size_t k(0); k<_sfc_triangles.size(); k++) {
if (_sfc_triangles[k]->containsPoint (pnt)) {
for (std::size_t k(0); k < _sfc_triangles.size(); k++)
{
if (_sfc_triangles[k]->containsPoint(pnt))
{
return _sfc_triangles[k];
}
}
......
/**
* \file
* \author Thomas Fischer
* \date 2010-01-22
* \brief Definition of the Surface class.
*
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
......@@ -39,28 +35,28 @@ class SurfaceGrid;
class Surface : public GeoObject
{
public:
Surface(const std::vector<Point*> &pnt_vec);
virtual ~Surface ();
Surface(const std::vector<Point*>& pnt_vec);
virtual ~Surface();
/// return a geometry type
virtual GEOTYPE getGeoType() const {return GEOTYPE::SURFACE;}
virtual GEOTYPE getGeoType() const { return GEOTYPE::SURFACE; }
/**
* adds three indices describing a triangle and updates the bounding box
* */
void addTriangle (std::size_t pnt_a, std::size_t pnt_b, std::size_t pnt_c);
void addTriangle(std::size_t pnt_a, std::size_t pnt_b, std::size_t pnt_c);
/// Triangulates a new surface based on closed polyline.
static Surface* createSurface(const Polyline &ply);
static Surface* createSurface(const Polyline& ply);
/**
* returns the number of triangles describing the Surface
* */
std::size_t getNTriangles () const;
std::size_t getNTriangles() const;
/** \brief const access operator for the access to the i-th Triangle of the surface.
/** \brief const access operator for the access to the i-th Triangle of the
* surface.
*/
const Triangle* operator[] (std::size_t i) const;
const Triangle* operator[](std::size_t i) const;
/**
* is the given point in the bounding volume of the surface
......@@ -82,17 +78,15 @@ public:
*/
const Triangle* findTriangle(MathLib::Point3d const& pnt) const;
const std::vector<Point*> *getPointVec() const { return &_sfc_pnts; }
const std::vector<Point*>* getPointVec() const { return &_sfc_pnts; }
/**
* method allows access to the internal axis aligned bounding box
* @return axis aligned bounding box
*/
AABB const& getAABB () const { return *_bounding_volume; }
AABB const& getAABB() const { return *_bounding_volume; }
protected:
/** a vector of pointers to Points */
const std::vector<Point*> &_sfc_pnts;
const std::vector<Point*>& _sfc_pnts;
/** position of pointers to the geometric points */
std::vector<Triangle*> _sfc_triangles;
/** bounding volume is an axis aligned bounding box */
......@@ -103,7 +97,6 @@ protected:
/// called and a valid surface grid is not existing.
mutable std::unique_ptr<SurfaceGrid> _surface_grid;
};
}
#endif /* SURFACE_H_ */
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