OGS
GeoLib::DuplicateGeometry Class Referencefinal

Detailed Description

Creates a copy of a geometry within GEOObjects

Definition at line 27 of file DuplicateGeometry.h.

#include <DuplicateGeometry.h>

Collaboration diagram for GeoLib::DuplicateGeometry:
[legend]

Public Member Functions

 DuplicateGeometry (GeoLib::GEOObjects &geo_objects, std::string const &input_name, std::string output_name)
 
std::string const & getFinalizedOutputName () const
 
std::vector< GeoLib::Point * > & getPointVectorCopy ()
 
std::vector< GeoLib::Polyline * > & getPolylineVectorCopy ()
 
std::vector< GeoLib::Surface * > & getSurfaceVectorCopy ()
 

Private Member Functions

void duplicate (std::string const &input_name)
 
std::unique_ptr< std::vector< GeoLib::Polyline * > > copyPolylinesVector (std::vector< GeoLib::Polyline * > const &polylines) const
 
std::unique_ptr< std::vector< GeoLib::Surface * > > copySurfacesVector (std::vector< GeoLib::Surface * > const &surfaces) const
 

Private Attributes

std::string _output_name
 
GeoLib::GEOObjects_geo_objects
 

Constructor & Destructor Documentation

◆ DuplicateGeometry()

GeoLib::DuplicateGeometry::DuplicateGeometry ( GeoLib::GEOObjects geo_objects,
std::string const &  input_name,
std::string  output_name 
)

Creates a copy of a geometry within GEOObjects

Parameters
geo_objectsThe container for geometries
input_nameThe geometry to be copied
output_nameThe name of the copy (note: this might be modified by GEOObjects)

Definition at line 25 of file DuplicateGeometry.cpp.

28  : _output_name(std::move(output_name)), _geo_objects(geo_objects)
29 {
30  duplicate(input_name);
31 }
void duplicate(std::string const &input_name)
GeoLib::GEOObjects & _geo_objects

References duplicate().

Member Function Documentation

◆ copyPolylinesVector()

std::unique_ptr< std::vector< GeoLib::Polyline * > > GeoLib::DuplicateGeometry::copyPolylinesVector ( std::vector< GeoLib::Polyline * > const &  polylines) const
private

Definition at line 82 of file DuplicateGeometry.cpp.

84 {
85  std::size_t const n_plys = polylines.size();
86  auto new_lines =
87  std::make_unique<std::vector<GeoLib::Polyline*>>(n_plys, nullptr);
88 
89  for (std::size_t i = 0; i < n_plys; ++i)
90  {
91  if (polylines[i] == nullptr)
92  {
93  continue;
94  }
95  (*new_lines)[i] =
97  std::size_t const nLinePnts(polylines[i]->getNumberOfPoints());
98  for (std::size_t j = 0; j < nLinePnts; ++j)
99  {
100  (*new_lines)[i]->addPoint(polylines[i]->getPointID(j));
101  }
102  }
103  return new_lines;
104 }
const std::vector< Point * > * getPointVec(const std::string &name) const
Definition: GEOObjects.cpp:71
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:51

References _geo_objects, _output_name, and GeoLib::GEOObjects::getPointVec().

Referenced by duplicate().

◆ copySurfacesVector()

std::unique_ptr< std::vector< Surface * > > GeoLib::DuplicateGeometry::copySurfacesVector ( std::vector< GeoLib::Surface * > const &  surfaces) const
private

Definition at line 106 of file DuplicateGeometry.cpp.

108 {
109  std::size_t const n_sfc = surfaces.size();
110  auto new_surfaces =
111  std::make_unique<std::vector<GeoLib::Surface*>>(n_sfc, nullptr);
112 
113  for (std::size_t i = 0; i < n_sfc; ++i)
114  {
115  if (surfaces[i] == nullptr)
116  {
117  continue;
118  }
119  (*new_surfaces)[i] =
121 
122  std::size_t const n_tris(surfaces[i]->getNumberOfTriangles());
123  for (std::size_t j = 0; j < n_tris; ++j)
124  {
125  GeoLib::Triangle const* t = (*surfaces[i])[j];
126  (*new_surfaces)[i]->addTriangle(t->getPoint(0)->getID(),
127  t->getPoint(1)->getID(),
128  t->getPoint(2)->getID());
129  }
130  }
131  return new_surfaces;
132 }
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
Definition: Surface.h:34
Class Triangle consists of a reference to a point vector and a vector that stores the indices in the ...
Definition: Triangle.h:26
const Point * getPoint(std::size_t i) const
const access operator to access the i-th triangle Point
Definition: Triangle.h:49
std::size_t getID() const
Definition: Point3dWithID.h:62

References _geo_objects, _output_name, MathLib::Point3dWithID::getID(), GeoLib::Triangle::getPoint(), and GeoLib::GEOObjects::getPointVec().

Referenced by duplicate().

◆ duplicate()

void GeoLib::DuplicateGeometry::duplicate ( std::string const &  input_name)
private

Definition at line 33 of file DuplicateGeometry.cpp.

34 {
35  std::vector<GeoLib::Point*> const* const pnts(
36  _geo_objects.getPointVec(input_name));
37  if (pnts == nullptr)
38  {
39  ERR("Geometry '{:s}' not found.", input_name);
40  return;
41  }
42 
43  auto new_pnts = std::make_unique<std::vector<GeoLib::Point*>>();
44  new_pnts->reserve(pnts->size());
45  std::transform(pnts->cbegin(), pnts->cend(), std::back_inserter(*new_pnts),
46  [](GeoLib::Point* point)
47  { return new GeoLib::Point(*point); });
48  auto pnt_name_id_map = std::make_unique<std::map<std::string, std::size_t>>(
51  _geo_objects.addPointVec(std::move(new_pnts), _output_name,
52  std::move(pnt_name_id_map));
53 
54  std::vector<GeoLib::Polyline*> const* plys(
55  _geo_objects.getPolylineVec(input_name));
56  if (plys)
57  {
58  auto new_plys = copyPolylinesVector(*plys);
59  auto ply_name_id_map =
60  std::make_unique<std::map<std::string, std::size_t>>(
63  _geo_objects.addPolylineVec(std::move(new_plys), _output_name,
64  std::move(ply_name_id_map));
65  }
66 
67  std::vector<GeoLib::Surface*> const* sfcs(
68  _geo_objects.getSurfaceVec(input_name));
69  if (sfcs)
70  {
71  auto new_sfcs = copySurfacesVector(*sfcs);
72  auto sfc_name_id_map =
73  std::make_unique<std::map<std::string, std::size_t>>(
76  _geo_objects.addSurfaceVec(std::move(new_sfcs), _output_name,
77  std::move(sfc_name_id_map));
78  }
79 }
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
std::unique_ptr< std::vector< GeoLib::Polyline * > > copyPolylinesVector(std::vector< GeoLib::Polyline * > const &polylines) const
std::unique_ptr< std::vector< GeoLib::Surface * > > copySurfacesVector(std::vector< GeoLib::Surface * > const &surfaces) const
void addSurfaceVec(std::unique_ptr< std::vector< Surface * >> sfc, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> sfc_names=nullptr)
Definition: GEOObjects.cpp:261
const PointVec * getPointVecObj(const std::string &name) const
Definition: GEOObjects.cpp:84
void addPointVec(std::unique_ptr< std::vector< Point * >> points, std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> pnt_id_name_map=nullptr, double eps=std::sqrt(std::numeric_limits< double >::epsilon()))
Definition: GEOObjects.cpp:51
const std::vector< Surface * > * getSurfaceVec(const std::string &name) const
Returns the surface vector with the given name as a const.
Definition: GEOObjects.cpp:307
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
Definition: GEOObjects.h:205
const PolylineVec * getPolylineVecObj(const std::string &name) const
Definition: GEOObjects.cpp:227
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
Definition: GEOObjects.cpp:210
void addPolylineVec(std::unique_ptr< std::vector< Polyline * >> lines, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> ply_names=nullptr)
Definition: GEOObjects.cpp:150
NameIdMap::const_iterator getNameIDMapBegin() const
Returns the begin of the name id mapping structure.
Definition: TemplateVec.h:98
NameIdMap::const_iterator getNameIDMapEnd() const
Returns the end of the name id mapping structure.
Definition: TemplateVec.h:101

References _geo_objects, _output_name, GeoLib::GEOObjects::addPointVec(), GeoLib::GEOObjects::addPolylineVec(), GeoLib::GEOObjects::addSurfaceVec(), copyPolylinesVector(), copySurfacesVector(), ERR(), GeoLib::TemplateVec< T >::getNameIDMapBegin(), GeoLib::TemplateVec< T >::getNameIDMapEnd(), GeoLib::GEOObjects::getPointVec(), GeoLib::GEOObjects::getPointVecObj(), GeoLib::GEOObjects::getPolylineVec(), GeoLib::GEOObjects::getPolylineVecObj(), GeoLib::GEOObjects::getSurfaceVec(), and GeoLib::GEOObjects::getSurfaceVecObj().

Referenced by DuplicateGeometry().

◆ getFinalizedOutputName()

std::string const& GeoLib::DuplicateGeometry::getFinalizedOutputName ( ) const
inline

Definition at line 42 of file DuplicateGeometry.h.

42 { return _output_name; }

References _output_name.

Referenced by MainWindow::mapGeometry().

◆ getPointVectorCopy()

std::vector< GeoLib::Point * > & GeoLib::DuplicateGeometry::getPointVectorCopy ( )

Definition at line 134 of file DuplicateGeometry.cpp.

135 {
136  return const_cast<std::vector<GeoLib::Point*>&>(
138 }

References _geo_objects, _output_name, and GeoLib::GEOObjects::getPointVec().

◆ getPolylineVectorCopy()

std::vector< GeoLib::Polyline * > & GeoLib::DuplicateGeometry::getPolylineVectorCopy ( )

Definition at line 140 of file DuplicateGeometry.cpp.

141 {
142  return const_cast<std::vector<GeoLib::Polyline*>&>(
144 }

References _geo_objects, _output_name, and GeoLib::GEOObjects::getPolylineVec().

◆ getSurfaceVectorCopy()

std::vector< GeoLib::Surface * > & GeoLib::DuplicateGeometry::getSurfaceVectorCopy ( )

Definition at line 146 of file DuplicateGeometry.cpp.

147 {
148  return const_cast<std::vector<GeoLib::Surface*>&>(
150 }

References _geo_objects, _output_name, and GeoLib::GEOObjects::getSurfaceVec().

Member Data Documentation

◆ _geo_objects

GeoLib::GEOObjects& GeoLib::DuplicateGeometry::_geo_objects
private

◆ _output_name

std::string GeoLib::DuplicateGeometry::_output_name
private

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