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
23namespace 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
33void 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 std::vector<GeoLib::Point*> new_pnts{};
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 PointVec::NameIdMap pnt_name_id_map(
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 PolylineVec::NameIdMap ply_name_id_map{
62 _geo_objects.addPolylineVec(std::move(new_plys), _output_name,
63 std::move(ply_name_id_map));
64 }
65
66 std::vector<GeoLib::Surface*> const* sfcs(
67 _geo_objects.getSurfaceVec(input_name));
68 if (sfcs)
69 {
70 auto new_sfcs = copySurfacesVector(*sfcs);
71 GeoLib::SurfaceVec::NameIdMap sfc_name_id_map{
74 _geo_objects.addSurfaceVec(std::move(new_sfcs), _output_name,
75 std::move(sfc_name_id_map));
76 }
77}
78
79std::vector<GeoLib::Polyline*> DuplicateGeometry::copyPolylinesVector(
80 std::vector<GeoLib::Polyline*> const& polylines) const
81{
82 std::size_t const n_plys = polylines.size();
83 std::vector<GeoLib::Polyline*> new_lines{n_plys, nullptr};
84
85 for (std::size_t i = 0; i < n_plys; ++i)
86 {
87 if (polylines[i] == nullptr)
88 {
89 continue;
90 }
91 new_lines[i] =
93 std::size_t const nLinePnts(polylines[i]->getNumberOfPoints());
94 for (std::size_t j = 0; j < nLinePnts; ++j)
95 {
96 new_lines[i]->addPoint(polylines[i]->getPointID(j));
97 }
98 }
99 return new_lines;
100}
101
103 std::vector<Surface*> const& surfaces) const
104{
105 std::size_t const n_sfc = surfaces.size();
106 std::vector<GeoLib::Surface*> new_surfaces{n_sfc, nullptr};
107
108 for (std::size_t i = 0; i < n_sfc; ++i)
109 {
110 if (surfaces[i] == nullptr)
111 {
112 continue;
113 }
114 new_surfaces[i] =
116
117 std::size_t const n_tris(surfaces[i]->getNumberOfTriangles());
118 for (std::size_t j = 0; j < n_tris; ++j)
119 {
120 GeoLib::Triangle const* t = (*surfaces[i])[j];
121 new_surfaces[i]->addTriangle(t->getPoint(0)->getID(),
122 t->getPoint(1)->getID(),
123 t->getPoint(2)->getID());
124 }
125 }
126 return new_surfaces;
127}
128
129std::vector<GeoLib::Point*>& DuplicateGeometry::getPointVectorCopy()
130{
131 return const_cast<std::vector<GeoLib::Point*>&>(
133}
134
135std::vector<GeoLib::Polyline*>& DuplicateGeometry::getPolylineVectorCopy()
136{
137 return const_cast<std::vector<GeoLib::Polyline*>&>(
139}
140
141std::vector<GeoLib::Surface*>& DuplicateGeometry::getSurfaceVectorCopy()
142{
143 return const_cast<std::vector<GeoLib::Surface*>&>(
145}
146
147} // namespace GeoLib
Definition of the GEOObjects class.
Definition of the Point class.
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
Definition of the PolyLine class.
std::vector< GeoLib::Surface * > & getSurfaceVectorCopy()
void duplicate(std::string const &input_name)
GeoLib::GEOObjects & _geo_objects
std::vector< Surface * > copySurfacesVector(std::vector< 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()
std::vector< GeoLib::Polyline * > copyPolylinesVector(std::vector< GeoLib::Polyline * > const &polylines) const
Container class for geometric objects.
Definition GEOObjects.h:57
void addPolylineVec(std::vector< Polyline * > &&lines, std::string const &name, PolylineVec::NameIdMap &&ply_names)
const std::vector< Point * > * getPointVec(const std::string &name) const
void addPointVec(std::vector< Point * > &&points, std::string &name, PointVec::NameIdMap &&pnt_id_name_map, double const eps=std::sqrt(std::numeric_limits< double >::epsilon()))
const PointVec * getPointVecObj(const std::string &name) const
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
Definition GEOObjects.h:208
const std::vector< Surface * > * getSurfaceVec(const std::string &name) const
Returns the surface vector with the given name as a const.
void addSurfaceVec(std::vector< Surface * > &&sfc, const std::string &name, SurfaceVec::NameIdMap &&sfc_names)
const PolylineVec * getPolylineVecObj(const std::string &name) const
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition Polyline.h:40
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
Definition Surface.h:33
std::map< std::string, std::size_t > NameIdMap
Definition TemplateVec.h:41
NameIdMap::const_iterator getNameIDMapBegin() const
Returns the begin of the name id mapping structure.
Definition TemplateVec.h:86
NameIdMap::const_iterator getNameIDMapEnd() const
Returns the end of the name id mapping structure.
Definition TemplateVec.h:92
Class Triangle consists of a reference to a point vector and a vector that stores the indices in the ...
Definition Triangle.h:27
const Point * getPoint(std::size_t i) const
const access operator to access the i-th triangle Point
Definition Triangle.h:50
std::size_t getID() const