OGS

Detailed Description

This class manages pointers to Points in a std::vector along with a name. It also handles the deletion of points. Furthermore, typically, PointVec objects are managed by GEOObjects using the instance name for identification. For this reason PointVec must have a unique name.

Definition at line 37 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 Types inherited from GeoLib::TemplateVec< Point >
using NameIdPair = std::pair< std::string, std::size_t >
 
using NameIdMap = std::map< std::string, std::size_t >
 

Public Member Functions

 PointVec (std::string const &name, std::vector< Point * > &&points, NameIdMap &&name_id_map, PointType const type=PointVec::PointType::POINT, double const rel_eps=std::numeric_limits< double >::epsilon())
 
 PointVec (std::string const &name, std::vector< Point * > &&points, PointType const type=PointVec::PointType::POINT, double const 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 const &name, std::vector< Point * > &&data_vec, NameIdMap &&elem_name_map)
 
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
 
std::vector< Point * > const & 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 (PointVec &&)=delete
 
 PointVec (const PointVec &)=delete
 
 PointVec ()=delete
 
PointVecoperator= (const PointVec &rhs)=delete
 
PointVecoperator= (PointVec &&rhs)=delete
 
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 Member Functions inherited from GeoLib::TemplateVec< Point >
 TemplateVec (TemplateVec const &)=delete
 
 TemplateVec (TemplateVec &&)=delete
 
TemplateVecoperator= (TemplateVec const &rhs)=delete
 
TemplateVecoperator= (TemplateVec &&rhs)=delete
 
- Protected Attributes inherited from GeoLib::TemplateVec< Point >
std::string _name
 
std::vector< Point * > _data_vec
 
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 41 of file PointVec.h.

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

Constructor & Destructor Documentation

◆ PointVec() [1/5]

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

Constructor initializes the name of the PointVec object, and moves the points vector into the internal data structure.

Parameters
namethe name of the point set
pointsR-value reference to a vector of pointers to GeoLib::Points.
Attention
{The PointVec object takes the ownership of the GeoLib::Points in the points vector, i.e. it delete the points during destruction!}
Parameters
name_id_mapA std::map that stores the relation name to point.
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.

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

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(), MaterialPropertyLib::name, and WARN().

◆ PointVec() [2/5]

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

This constructor is similar to the above constructor with the exception that the NameIdMap must not be passed.

Definition at line 127 of file PointVec.cpp.

129  : PointVec(name, std::move(points), NameIdMap{}, type, rel_eps)
130 {
131 }
std::map< std::string, std::size_t > NameIdMap
Definition: TemplateVec.h:44

◆ PointVec() [3/5]

GeoLib::PointVec::PointVec ( PointVec &&  )
privatedelete

◆ PointVec() [4/5]

GeoLib::PointVec::PointVec ( const PointVec )
privatedelete

◆ PointVec() [5/5]

GeoLib::PointVec::PointVec ( )
privatedelete

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 205 of file PointVec.cpp.

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

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 94 of file PointVec.h.

94 { return _type; }

References _type.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

PointVec& GeoLib::PointVec::operator= ( PointVec &&  rhs)
privatedelete

◆ 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 133 of file PointVec.cpp.

134 {
135  _pnt_id_map.push_back(uniqueInsert(pnt));
136  _id_to_name_map.emplace_back("");
137  return _pnt_id_map[_pnt_id_map.size() - 1];
138 }
std::size_t uniqueInsert(Point *pnt)
Definition: PointVec.cpp:165

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 140 of file PointVec.cpp.

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

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 259 of file PointVec.cpp.

260 {
261  auto const& min(_aabb.getMinPoint());
262  auto const& max(_aabb.getMaxPoint());
263  double const rel_eps(_rel_eps / (max - min).norm());
264 
265  _aabb = GeoLib::AABB(_data_vec.begin(), _data_vec.end());
266 
267  _rel_eps = rel_eps * (_aabb.getMaxPoint() - _aabb.getMinPoint()).norm();
268 
271 
272  GeoLib::Point* ret_pnt(nullptr);
273  for (auto const& p : _data_vec)
274  {
275  _oct_tree->addPoint(p, ret_pnt);
276  }
277 }
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 253 of file PointVec.cpp.

254 {
256  _id_to_name_map[id] = name;
257 }
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:215

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 165 of file PointVec.cpp.

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

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 150 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 148 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 152 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 144 of file PointVec.h.

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

◆ _rel_eps

double GeoLib::PointVec::_rel_eps
private

Definition at line 151 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 138 of file PointVec.h.

Referenced by getType().


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