OGS
GeoLib::PointVec Class Referencefinal

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 24 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
using NameIdMap

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.
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.
NameIdMap::const_iterator getNameIDMapEnd () const
 Returns the end of the name id mapping structure.
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.
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.
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 >
TemplateVecoperator= (TemplateVec const &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

enum class GeoLib::PointVec::PointType
strong

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

Enumerator
POINT 
STATION 

Definition at line 28 of file PointVec.h.

29 {
30 POINT = 0,
31 STATION = 1
32 };

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.
name_id_mapA std::map that stores the relation name to point.
typethe type of the point, defaults to PointVec::PointType::POINT.
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 rel_eps value gives the real tolerance \(\varepsilon\). Two points \(p_0\) and \(p_1\) are considered identical if \(|p_1 - p_0| \le \varepsilon.\)
Attention
The PointVec object takes the ownership of the GeoLib::Points in the points vector, i.e. it delete the points during destruction!

Definition at line 13 of file PointVec.cpp.

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

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

Referenced by PointVec(), PointVec(), PointVec(), operator=(), and operator=().

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

120 : PointVec(name, std::move(points), NameIdMap{}, type, rel_eps)
121{
122}
std::map< std::string, std::size_t > NameIdMap
Definition TemplateVec.h:30

References PointVec().

◆ PointVec() [3/5]

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

References PointVec().

◆ PointVec() [4/5]

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

References PointVec().

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

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

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

84{ return _type; }

References _type.

Referenced by GeoLib::GEOObjects::getStationVec().

◆ operator=() [1/2]

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

References PointVec().

◆ operator=() [2/2]

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

References PointVec().

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

125{
126 _pnt_id_map.push_back(uniqueInsert(pnt));
127 _id_to_name_map.emplace_back("");
128 return _pnt_id_map[_pnt_id_map.size() - 1];
129}
std::size_t uniqueInsert(Point *pnt)
Definition PointVec.cpp:156

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

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

References _id_to_name_map, GeoLib::TemplateVec< Point >::_name_id_map, _pnt_id_map, 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 250 of file PointVec.cpp.

251{
252 auto const [min, max] = _aabb.getMinMaxPoints();
253 double const rel_eps(_rel_eps / (max - min).norm());
254
255 _aabb = GeoLib::AABB(_data_vec.begin(), _data_vec.end());
256
257 _rel_eps = rel_eps * (_aabb.getMaxPoint() - _aabb.getMinPoint()).norm();
258
260 _aabb.getMinPoint(), _aabb.getMaxPoint(), _rel_eps));
261
262 GeoLib::Point* ret_pnt(nullptr);
263 for (auto const& p : _data_vec)
264 {
265 _oct_tree->addPoint(p, ret_pnt);
266 }
267}
double norm(MatrixOrVector const &x, MathLib::VecNormType type)
Definition LinAlg.h:89

References _aabb, GeoLib::TemplateVec< Point >::_data_vec, _oct_tree, _rel_eps, and GeoLib::OctTree< POINT, MAX_POINTS >::createOctTree().

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

245{
247 _id_to_name_map[id] = name;
248}
virtual void setNameForElement(std::size_t id, std::string const &name)
Sets the given name for the element of the given ID.

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

Referenced by 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 156 of file PointVec.cpp.

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

References _aabb, GeoLib::TemplateVec< Point >::_data_vec, _oct_tree, _rel_eps, GeoLib::OctTree< POINT, MAX_POINTS >::createOctTree(), MathLib::Point3dWithID::getID(), and MathLib::Point3dWithID::setID().

Referenced by push_back(), and push_back().

Member Data Documentation

◆ _aabb

AABB GeoLib::PointVec::_aabb
private

Definition at line 140 of file PointVec.h.

Referenced by PointVec(), 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 138 of file PointVec.h.

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

◆ _oct_tree

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

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

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

◆ _rel_eps

double GeoLib::PointVec::_rel_eps
private

Definition at line 141 of file PointVec.h.

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

◆ _type

PointType GeoLib::PointVec::_type
private

the type of the point (

See also
enum PointType)

Definition at line 128 of file PointVec.h.

Referenced by PointVec(), and getType().


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