OGS
Surface.cpp
Go to the documentation of this file.
1 
10 #include "Surface.h"
11 
12 #include <list>
13 
14 // GeoLib
15 #include "AABB.h"
16 #include "AnalyticalGeometry.h"
17 #include "Polygon.h"
18 #include "Polyline.h"
19 #include "SurfaceGrid.h"
20 #include "Triangle.h"
21 
22 namespace GeoLib
23 {
24 Surface::Surface(const std::vector<Point*>& pnt_vec)
25  : _sfc_pnts(pnt_vec), _bounding_volume(nullptr), _surface_grid(nullptr)
26 {
27 }
28 
30  : _sfc_pnts(src._sfc_pnts),
31  _bounding_volume(new AABB(*(src._bounding_volume))),
32  _surface_grid(nullptr)
33 {
34  _sfc_triangles.reserve(src._sfc_triangles.size());
35  std::transform(src._sfc_triangles.cbegin(),
36  src._sfc_triangles.cend(),
37  std::back_inserter(_sfc_triangles),
38  [](Triangle* t) { return new Triangle(*t); });
39 }
40 
42 {
43  for (auto& _sfc_triangle : _sfc_triangles)
44  {
45  delete _sfc_triangle;
46  }
47 }
48 
49 void Surface::addTriangle(std::size_t pnt_a,
50  std::size_t pnt_b,
51  std::size_t pnt_c)
52 {
53  assert(pnt_a < _sfc_pnts.size() && pnt_b < _sfc_pnts.size() &&
54  pnt_c < _sfc_pnts.size());
55 
56  // Check if two points of the triangle have identical IDs
57  if (pnt_a == pnt_b || pnt_a == pnt_c || pnt_b == pnt_c)
58  {
59  return;
60  }
61 
62  // Adding a new triangle invalides the surface grid.
63  _surface_grid.reset();
64 
65  _sfc_triangles.push_back(new Triangle(_sfc_pnts, pnt_a, pnt_b, pnt_c));
66  if (!_bounding_volume)
67  {
68  std::vector<std::size_t> ids(3);
69  ids[0] = pnt_a;
70  ids[1] = pnt_b;
71  ids[2] = pnt_c;
72  _bounding_volume = std::make_unique<GeoLib::AABB>(_sfc_pnts, ids);
73  }
74  else
75  {
76  _bounding_volume->update(*_sfc_pnts[pnt_a]);
77  _bounding_volume->update(*_sfc_pnts[pnt_b]);
78  _bounding_volume->update(*_sfc_pnts[pnt_c]);
79  }
80 }
81 
82 std::size_t Surface::getNumberOfTriangles() const
83 {
84  return _sfc_triangles.size();
85 }
86 
87 const Triangle* Surface::operator[](std::size_t i) const
88 {
89  assert(i < _sfc_triangles.size());
90  return _sfc_triangles[i];
91 }
92 
94  double eps) const
95 {
96  return _bounding_volume->containsPoint(pnt, eps);
97 }
98 
99 bool Surface::isPntInSfc(MathLib::Point3d const& pnt, double eps) const
100 {
101  // Mutable _surface_grid is constructed if method is called the first time.
102  if (_surface_grid == nullptr)
103  {
104  _surface_grid = std::make_unique<GeoLib::SurfaceGrid>(this);
105  }
106  return _surface_grid->isPointInSurface(pnt, eps);
107 }
108 
109 bool operator==(Surface const& lhs, Surface const& rhs)
110 {
111  return &lhs == &rhs;
112 }
113 
114 } // namespace GeoLib
Definition of the AABB class.
Definition of analytical geometry functions.
Definition of the Polygon class.
Definition of the PolyLine class.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition: AABB.h:49
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
Definition: Surface.h:34
std::unique_ptr< AABB > _bounding_volume
Definition: Surface.h:87
std::unique_ptr< SurfaceGrid > _surface_grid
Definition: Surface.h:92
const Triangle * operator[](std::size_t i) const
const access operator for the access to the i-th Triangle of the surface.
Definition: Surface.cpp:87
const std::vector< Point * > & _sfc_pnts
Definition: Surface.h:83
std::vector< Triangle * > _sfc_triangles
Definition: Surface.h:85
std::size_t getNumberOfTriangles() const
Definition: Surface.cpp:82
~Surface() override
Definition: Surface.cpp:41
void addTriangle(std::size_t pnt_a, std::size_t pnt_b, std::size_t pnt_c)
Definition: Surface.cpp:49
bool isPntInBoundingVolume(MathLib::Point3d const &pnt, double eps) const
Definition: Surface.cpp:93
Surface(const std::vector< Point * > &pnt_vec)
Definition: Surface.cpp:24
bool isPntInSfc(MathLib::Point3d const &pnt, double eps) const
Definition: Surface.cpp:99
Class Triangle consists of a reference to a point vector and a vector that stores the indices in the ...
Definition: Triangle.h:26
bool operator==(LineSegment const &s0, LineSegment const &s1)