OGS

Detailed Description

This class manages pointers to Points in a std::vector along with a name. It also handles the deleting of points. Additionally, each vector of points is identified by a unique name from class GEOObject. For this reason PointVec should have a name.

Definition at line 38 of file PointVec.h.

#include <PointVec.h>

Inheritance diagram for GeoLib::PointVec:
[legend]
Collaboration diagram for GeoLib::PointVec:
[legend]

Public Types

enum class  PointType { POINT = 0 , STATION = 1 }
 Signals if the vector contains object of type Point or Station. More...
 

Public Member Functions

 PointVec (const std::string &name, std::unique_ptr< std::vector< Point * >> points, std::unique_ptr< std::map< std::string, std::size_t >> name_id_map=nullptr, PointType type=PointVec::PointType::POINT, double rel_eps=std::numeric_limits< double >::epsilon())
 
std::size_t push_back (Point *pnt)
 
void push_back (Point *pnt, std::string const *const name) override
 
PointType getType () const
 
const std::vector< std::size_t > & getIDMap () const
 
const GeoLib::AABBgetAABB () const
 
std::string const & getItemNameByID (std::size_t id) const
 
void setNameForElement (std::size_t id, std::string const &name) override
 Sets the given name for the element of the given ID. More...
 
void resetInternalDataStructures ()
 
- Public Member Functions inherited from GeoLib::TemplateVec< Point >
 TemplateVec (std::string name, std::unique_ptr< std::vector< Point * >> data_vec, std::unique_ptr< NameIdMap > elem_name_map=nullptr)
 
virtual ~TemplateVec ()
 
void setName (const std::string &n)
 
std::string getName () const
 
NameIdMap::const_iterator getNameIDMapBegin () const
 Returns the begin of the name id mapping structure. More...
 
NameIdMap::const_iterator getNameIDMapEnd () const
 Returns the end of the name id mapping structure. More...
 
std::size_t size () const
 
const std::vector< Point * > * getVector () const
 
bool getElementIDByName (const std::string &name, std::size_t &id) const
 
const PointgetElementByName (const std::string &name) const
 Returns an element with the given name. More...
 
bool getNameOfElementByID (std::size_t id, std::string &element_name) const
 
void setNameOfElementByID (std::size_t id, std::string const &element_name)
 Return the name of an element based on its ID. More...
 
bool getNameOfElement (const Point *data, std::string &name) const
 

Private Member Functions

void correctNameIDMapping ()
 
 PointVec (const PointVec &)
 
 PointVec ()
 
PointVecoperator= (const PointVec &rhs)
 
std::size_t uniqueInsert (Point *pnt)
 

Private Attributes

PointType _type
 
std::vector< std::size_t > _pnt_id_map
 
std::vector< std::string > _id_to_name_map
 
AABB _aabb
 
double _rel_eps
 
std::unique_ptr< GeoLib::OctTree< GeoLib::Point, 16 > > _oct_tree
 

Additional Inherited Members

- Protected Types inherited from GeoLib::TemplateVec< Point >
using NameIdPair = std::pair< std::string, std::size_t >
 
using NameIdMap = std::map< std::string, std::size_t >
 
- Protected Member Functions inherited from GeoLib::TemplateVec< Point >
 TemplateVec (const TemplateVec &)
 
TemplateVecoperator= (const TemplateVec &rhs)
 
- Protected Attributes inherited from GeoLib::TemplateVec< Point >
std::string _name
 
std::unique_ptr< std::vector< Point * > > _data_vec
 
std::unique_ptr< NameIdMap_name_id_map
 

Member Enumeration Documentation

◆ PointType

Signals if the vector contains object of type Point or Station.

Enumerator
POINT 
STATION 

Definition at line 42 of file PointVec.h.

43  {
44  POINT = 0,
45  STATION = 1
46  };

Constructor & Destructor Documentation

◆ PointVec() [1/3]

GeoLib::PointVec::PointVec ( const std::string &  name,
std::unique_ptr< std::vector< Point * >>  points,
std::unique_ptr< std::map< std::string, std::size_t >>  name_id_map = nullptr,
PointType  type = PointVec::PointType::POINT,
double  rel_eps = std::numeric_limits<double>::epsilon() 
)

Constructor initializes the name of the PointVec object, the internal pointer _pnt_vec to the raw points and the internal pointer the vector of names of the points and sets the type of PointVec.

Parameters
namethe name of the point group
pointsPointer to a vector of pointers to GeoLib::Points.
Attention
{PointVec will take the ownership of (the pointer to) the vector, i.e. it deletes the vector in the destructor! The class takes also the ownership of the GeoLib::Points the pointers within the vector points at, i.e. it delete the points!}
Parameters
name_id_mapA std::map that stores the relation name to point.
Attention
{PointVec will take the ownership of the vector, i.e. it deletes the names.}
Parameters
typethe type of the point,
See also
enum PointType
Parameters
rel_epsThis is a relative error tolerance value for the test of identical points. The size of the axis aligned bounding box multiplied with the value of rel_eps gives the real tolerance \(tol\). Two points \(p_0, p_1 \) are identical iff \(|p_1 - p_0| \le tol.\)

Definition at line 22 of file PointVec.cpp.

26  : TemplateVec<Point>(name, std::move(points), std::move(name_id_map)),
27  _type(type),
28  _aabb(_data_vec->begin(), _data_vec->end()),
29  _rel_eps(rel_eps * (_aabb.getMaxPoint() - _aabb.getMinPoint()).norm()),
32 {
33  assert(_data_vec);
34  std::size_t const number_of_all_input_pnts(_data_vec->size());
35 
36  // correct the ids if necessary
37  for (std::size_t k(0); k < _data_vec->size(); ++k)
38  {
39  if ((*_data_vec)[k]->getID() == std::numeric_limits<std::size_t>::max())
40  {
41  (*_data_vec)[k]->setID(k);
42  }
43  }
44 
45  std::vector<std::size_t> rm_pos;
46  // add all points in the oct tree in order to make them unique
47  _pnt_id_map.resize(number_of_all_input_pnts);
48  std::iota(_pnt_id_map.begin(), _pnt_id_map.end(), 0);
49  GeoLib::Point* ret_pnt(nullptr);
50  for (std::size_t k(0); k < _data_vec->size(); ++k)
51  {
52  GeoLib::Point* const pnt((*_data_vec)[k]);
53  if (!_oct_tree->addPoint(pnt, ret_pnt))
54  {
55  assert(ret_pnt != nullptr);
56  _pnt_id_map[pnt->getID()] = ret_pnt->getID();
57  rm_pos.push_back(k);
58  delete (*_data_vec)[k];
59  (*_data_vec)[k] = nullptr;
60  }
61  else
62  {
63  _pnt_id_map[k] = pnt->getID();
64  }
65  }
66 
67  auto const data_vec_end =
68  std::remove(_data_vec->begin(), _data_vec->end(), nullptr);
69  _data_vec->erase(data_vec_end, _data_vec->end());
70 
71  // decrement the ids according to the number of removed points (==k) before
72  // the j-th point (positions of removed points are stored in the vector
73  // rm_pos)
74  for (std::size_t k(1); k < rm_pos.size(); ++k)
75  {
76  // decrement the ids in the interval [rm_pos[k-1]+1, rm_pos[k])
77  for (std::size_t j(rm_pos[k - 1] + 1); j < rm_pos[k]; ++j)
78  {
79  _pnt_id_map[j] -= k;
80  }
81  }
82  // decrement the ids from rm_pos.back()+1 until the end of _pnt_id_map
83  if (!rm_pos.empty())
84  {
85  for (std::size_t j(rm_pos.back() + 1); j < _pnt_id_map.size(); ++j)
86  {
87  _pnt_id_map[j] -= rm_pos.size();
88  }
89  }
90  // decrement the ids within the _pnt_id_map at positions of the removed
91  // points
92  for (std::size_t k(1); k < rm_pos.size(); ++k)
93  {
94  std::size_t cnt(0);
95  for (cnt = 0;
96  cnt < rm_pos.size() && _pnt_id_map[rm_pos[k]] > rm_pos[cnt];)
97  {
98  cnt++;
99  }
100  _pnt_id_map[rm_pos[k]] -= cnt;
101  }
102 
103  // set value of the point id to the position of the point within _data_vec
104  for (std::size_t k(0); k < _data_vec->size(); ++k)
105  {
106  (*_data_vec)[k]->setID(k);
107  }
108 
109  if (number_of_all_input_pnts > _data_vec->size())
110  {
111  WARN("PointVec::PointVec(): there are {:d} double points.",
112  number_of_all_input_pnts - _data_vec->size());
113  }
114 
116  // create the inverse mapping
117  _id_to_name_map.resize(_data_vec->size());
118  // fetch the names from the name id map
119  for (auto p : *_name_id_map)
120  {
121  if (p.second >= _id_to_name_map.size())
122  {
123  continue;
124  }
125  _id_to_name_map[p.second] = p.first;
126  }
127 }
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
Eigen::Vector3d const & getMinPoint() const
Definition: AABB.h:174
Eigen::Vector3d const & getMaxPoint() const
Definition: AABB.h:181
static OctTree< POINT, MAX_POINTS > * createOctTree(Eigen::Vector3d ll, Eigen::Vector3d ur, double eps=std::numeric_limits< double >::epsilon())
Definition: OctTree-impl.h:16
std::vector< std::string > _id_to_name_map
Definition: PointVec.h:152
double _rel_eps
Definition: PointVec.h:155
PointType _type
Definition: PointVec.h:142
std::unique_ptr< GeoLib::OctTree< GeoLib::Point, 16 > > _oct_tree
Definition: PointVec.h:156
std::vector< std::size_t > _pnt_id_map
Definition: PointVec.h:148
void correctNameIDMapping()
Definition: PointVec.cpp:201
std::unique_ptr< NameIdMap > _name_id_map
Definition: TemplateVec.h:256
std::unique_ptr< std::vector< Point * > > _data_vec
Definition: TemplateVec.h:252

References GeoLib::TemplateVec< Point >::_data_vec, _id_to_name_map, GeoLib::TemplateVec< Point >::_name_id_map, _oct_tree, _pnt_id_map, correctNameIDMapping(), MathLib::Point3dWithID::getID(), and WARN().

◆ PointVec() [2/3]

GeoLib::PointVec::PointVec ( const PointVec )
private

copy constructor doesn't have an implementation

◆ PointVec() [3/3]

GeoLib::PointVec::PointVec ( )
private

standard constructor doesn't have an implementation

Member Function Documentation

◆ correctNameIDMapping()

void GeoLib::PointVec::correctNameIDMapping ( )
private

After the point set is modified (for example by makePntsUnique()) the mapping has to be corrected.

Definition at line 201 of file PointVec.cpp.

202 {
203  // create mapping id -> name using the std::vector id_names
204  std::vector<std::string> id_names(_pnt_id_map.size(), std::string(""));
205  for (auto& id_name_pair : *_name_id_map)
206  {
207  id_names[id_name_pair.second] = id_name_pair.first;
208  }
209 
210  for (auto it = _name_id_map->begin(); it != _name_id_map->end();)
211  {
212  // extract the id associated with the name
213  const std::size_t id(it->second);
214 
215  if (_pnt_id_map[id] == id)
216  {
217  ++it;
218  continue;
219  }
220 
221  if (_pnt_id_map[_pnt_id_map[id]] == _pnt_id_map[id])
222  {
223  if (id_names[_pnt_id_map[id]].length() != 0)
224  {
225  // point has already a name, erase the second occurrence
226  it = _name_id_map->erase(it);
227  }
228  else
229  {
230  // until now the point has not a name assign the second
231  // occurrence the correct id
232  it->second = _pnt_id_map[id];
233  ++it;
234  }
235  }
236  else
237  {
238  it->second = _pnt_id_map[id]; // update id associated to the name
239  ++it;
240  }
241  }
242 }

References GeoLib::TemplateVec< Point >::_name_id_map, and _pnt_id_map.

Referenced by PointVec().

◆ getAABB()

const GeoLib::AABB& GeoLib::PointVec::getAABB ( ) const

◆ getIDMap()

◆ getItemNameByID()

std::string const & GeoLib::PointVec::getItemNameByID ( std::size_t  id) const

◆ getType()

PointType GeoLib::PointVec::getType ( ) const
inline

get the type of Point, this can be either POINT or STATION

Definition at line 95 of file PointVec.h.

95 { return _type; }

References _type.

◆ operator=()

PointVec& GeoLib::PointVec::operator= ( const PointVec rhs)
private

assignment operator doesn't have an implementation

◆ push_back() [1/2]

std::size_t GeoLib::PointVec::push_back ( Point pnt)

Method adds a Point to the (internal) standard vector and takes the ownership. If the given point is already included in the vector, the point will be destroyed and the id of the existing point will be returned.

Parameters
pntthe pointer to the Point
Returns
the id of the point within the internal vector

Definition at line 129 of file PointVec.cpp.

130 {
131  _pnt_id_map.push_back(uniqueInsert(pnt));
132  _id_to_name_map.emplace_back("");
133  return _pnt_id_map[_pnt_id_map.size() - 1];
134 }
std::size_t uniqueInsert(Point *pnt)
Definition: PointVec.cpp:161

References _id_to_name_map, _pnt_id_map, and uniqueInsert().

Referenced by FileIO::GMSH::GMSHPolygonTree::checkIntersectionsSegmentExistingPolylines(), GeoLib::computeAndInsertAllIntersectionPoints(), FileIO::GMSH::GMSHPolygonTree::insertPolyline(), MeshGeoToolsLib::insertSubSegments(), and GeoLib::IO::TINInterface::readTIN().

◆ push_back() [2/2]

void GeoLib::PointVec::push_back ( Point pnt,
std::string const *const  name 
)
overridevirtual

push_back adds new elements at the end of the vector _data_vec.

Parameters
pnta pointer to the point, PointVec takes ownership of the point
namethe name of the point

Reimplemented from GeoLib::TemplateVec< Point >.

Definition at line 136 of file PointVec.cpp.

137 {
138  if (name == nullptr)
139  {
140  _pnt_id_map.push_back(uniqueInsert(pnt));
141  _id_to_name_map.emplace_back("");
142  return;
143  }
144 
145  std::map<std::string, std::size_t>::const_iterator it(
146  _name_id_map->find(*name));
147  if (it != _name_id_map->end())
148  {
149  _id_to_name_map.emplace_back("");
150  WARN("PointVec::push_back(): two points share the name {:s}.",
151  name->c_str());
152  return;
153  }
154 
155  std::size_t id(uniqueInsert(pnt));
156  _pnt_id_map.push_back(id);
157  (*_name_id_map)[*name] = id;
158  _id_to_name_map.push_back(*name);
159 }

References _id_to_name_map, GeoLib::TemplateVec< Point >::_name_id_map, _pnt_id_map, MaterialPropertyLib::name, uniqueInsert(), and WARN().

◆ resetInternalDataStructures()

void GeoLib::PointVec::resetInternalDataStructures ( )

Resets the internal data structures, i.e., the axis aligned bounding box, the relative epsilon for the equality tests and the oct tree data structure.

Note
This method have to be called if the coordinates of a point stored by the PointVec is modified from outside.

Definition at line 255 of file PointVec.cpp.

256 {
257  auto const& min(_aabb.getMinPoint());
258  auto const& max(_aabb.getMaxPoint());
259  double const rel_eps(_rel_eps / (max - min).norm());
260 
261  _aabb = GeoLib::AABB(_data_vec->begin(), _data_vec->end());
262 
263  _rel_eps = rel_eps * (_aabb.getMaxPoint() - _aabb.getMinPoint()).norm();
264 
267 
268  GeoLib::Point* ret_pnt(nullptr);
269  for (auto const p : *_data_vec)
270  {
271  _oct_tree->addPoint(p, ret_pnt);
272  }
273 }
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition: AABB.h:49
double norm(MatrixOrVector const &x, MathLib::VecNormType type)
Definition: LinAlg.h:88

References _aabb, GeoLib::TemplateVec< Point >::_data_vec, _oct_tree, _rel_eps, GeoLib::AABB::getMaxPoint(), GeoLib::AABB::getMinPoint(), and MathLib::LinAlg::norm().

Referenced by MeshGeoToolsLib::mapPolylineOnSurfaceMesh().

◆ setNameForElement()

void GeoLib::PointVec::setNameForElement ( std::size_t  id,
std::string const &  name 
)
overridevirtual

Sets the given name for the element of the given ID.

Reimplemented from GeoLib::TemplateVec< Point >.

Definition at line 249 of file PointVec.cpp.

250 {
252  _id_to_name_map[id] = name;
253 }
virtual void setNameForElement(std::size_t id, std::string const &name)
Sets the given name for the element of the given ID.
Definition: TemplateVec.h:214

References _id_to_name_map, MaterialPropertyLib::name, and GeoLib::TemplateVec< T >::setNameForElement().

Referenced by GEOModels::addNameForElement(), and GEOModels::addNameForObjectPoints().

◆ uniqueInsert()

std::size_t GeoLib::PointVec::uniqueInsert ( Point pnt)
private

Inserts the instance of the Point into internal data structures (

See also
TemplateVec::_data_vec, _pnt_id_map) if and only if there does not exist a point with the same coordinates (up to std::numeric_limits<double>::epsilon()). In case there exists already a point with the same coordinates the given pnt-object will be deleted!
Parameters
pntPointer to GeooLib::Point instance
Returns
either the new id or the id of the existing point with the same coordinates

Definition at line 161 of file PointVec.cpp.

162 {
163  GeoLib::Point* ret_pnt(nullptr);
164  if (_oct_tree->addPoint(pnt, ret_pnt))
165  {
166  // set value of the point id to the position of the point within
167  // _data_vec
168  pnt->setID(_data_vec->size());
169  _data_vec->push_back(pnt);
170  return _data_vec->size() - 1;
171  }
172 
173  // pnt is outside of OctTree object
174  if (ret_pnt == nullptr)
175  {
176  // update the axis aligned bounding box
177  _aabb.update(*pnt);
178  // recreate the (enlarged) OctTree
181  // add all points that are already in the _data_vec
182  for (std::size_t k(0); k < _data_vec->size(); ++k)
183  {
184  GeoLib::Point* const p((*_data_vec)[k]);
185  _oct_tree->addPoint(p, ret_pnt);
186  }
187  // add the new point
188  ret_pnt = nullptr;
189  _oct_tree->addPoint(pnt, ret_pnt);
190  // set value of the point id to the position of the point within
191  // _data_vec
192  pnt->setID(_data_vec->size());
193  _data_vec->push_back(pnt);
194  return _data_vec->size() - 1;
195  }
196 
197  delete pnt;
198  return ret_pnt->getID();
199 }
bool update(PNT_TYPE const &p)
Definition: AABB.h:103

References _aabb, GeoLib::TemplateVec< Point >::_data_vec, _oct_tree, _rel_eps, MathLib::Point3dWithID::getID(), GeoLib::AABB::getMaxPoint(), GeoLib::AABB::getMinPoint(), MathLib::Point3dWithID::setID(), and GeoLib::AABB::update().

Referenced by push_back().

Member Data Documentation

◆ _aabb

AABB GeoLib::PointVec::_aabb
private

Definition at line 154 of file PointVec.h.

Referenced by resetInternalDataStructures(), and uniqueInsert().

◆ _id_to_name_map

std::vector<std::string> GeoLib::PointVec::_id_to_name_map
private

The reverse map to the name to id map, for fast lookup of the name to a given point id.

Definition at line 152 of file PointVec.h.

Referenced by PointVec(), getItemNameByID(), push_back(), and setNameForElement().

◆ _oct_tree

std::unique_ptr<GeoLib::OctTree<GeoLib::Point, 16> > GeoLib::PointVec::_oct_tree
private

Definition at line 156 of file PointVec.h.

Referenced by PointVec(), resetInternalDataStructures(), and uniqueInsert().

◆ _pnt_id_map

std::vector<std::size_t> GeoLib::PointVec::_pnt_id_map
private

permutation of the geometric elements according to their lexicographical order

Definition at line 148 of file PointVec.h.

Referenced by PointVec(), correctNameIDMapping(), getIDMap(), and push_back().

◆ _rel_eps

double GeoLib::PointVec::_rel_eps
private

Definition at line 155 of file PointVec.h.

Referenced by resetInternalDataStructures(), and uniqueInsert().

◆ _type

PointType GeoLib::PointVec::_type
private

the type of the point (

See also
enum PointType)

Definition at line 142 of file PointVec.h.

Referenced by getType().


The documentation for this class was generated from the following files: