OGS
DuplicateGeometry.cpp
Go to the documentation of this file.
1 
11 #include "DuplicateGeometry.h"
12 
13 #include <map>
14 #include <utility>
15 
16 #include "BaseLib/Logging.h"
17 #include "GeoLib/GEOObjects.h"
18 #include "GeoLib/Point.h"
19 #include "GeoLib/Polyline.h"
20 #include "GeoLib/Surface.h"
21 #include "GeoLib/Triangle.h"
22 
23 namespace GeoLib
24 {
26  std::string const& input_name,
27  std::string output_name)
28  : _output_name(std::move(output_name)), _geo_objects(geo_objects)
29 {
30  duplicate(input_name);
31 }
32 
33 void DuplicateGeometry::duplicate(std::string const& input_name)
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 }
80 
81 std::unique_ptr<std::vector<GeoLib::Polyline*>>
83  std::vector<GeoLib::Polyline*> const& polylines) const
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 }
105 
106 std::unique_ptr<std::vector<Surface*>> DuplicateGeometry::copySurfacesVector(
107  std::vector<Surface*> const& surfaces) const
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 }
133 
134 std::vector<GeoLib::Point*>& DuplicateGeometry::getPointVectorCopy()
135 {
136  return const_cast<std::vector<GeoLib::Point*>&>(
138 }
139 
140 std::vector<GeoLib::Polyline*>& DuplicateGeometry::getPolylineVectorCopy()
141 {
142  return const_cast<std::vector<GeoLib::Polyline*>&>(
144 }
145 
146 std::vector<GeoLib::Surface*>& DuplicateGeometry::getSurfaceVectorCopy()
147 {
148  return const_cast<std::vector<GeoLib::Surface*>&>(
150 }
151 
152 } // namespace GeoLib
Definition of the GEOObjects class.
Definition of the Point class.
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
Definition of the PolyLine class.
std::vector< GeoLib::Surface * > & getSurfaceVectorCopy()
void duplicate(std::string const &input_name)
std::unique_ptr< std::vector< GeoLib::Polyline * > > copyPolylinesVector(std::vector< GeoLib::Polyline * > const &polylines) const
GeoLib::GEOObjects & _geo_objects
std::unique_ptr< std::vector< GeoLib::Surface * > > copySurfacesVector(std::vector< GeoLib::Surface * > const &surfaces) const
DuplicateGeometry(GeoLib::GEOObjects &geo_objects, std::string const &input_name, std::string output_name)
std::vector< GeoLib::Point * > & getPointVectorCopy()
std::vector< GeoLib::Polyline * > & getPolylineVectorCopy()
Container class for geometric objects.
Definition: GEOObjects.h:61
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 std::vector< Point * > * getPointVec(const std::string &name) const
Definition: GEOObjects.cpp:71
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
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:51
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
Definition: Surface.h:34
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
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