OGS
GeoLib::DuplicateGeometry Class Referencefinal

Detailed Description

Creates a copy of a geometry within GEOObjects

Definition at line 20 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::vector< GeoLib::Polyline * > copyPolylinesVector (std::vector< GeoLib::Polyline * > const &polylines) const
std::vector< Surface * > copySurfacesVector (std::vector< 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 18 of file DuplicateGeometry.cpp.

21 : _output_name(std::move(output_name)), _geo_objects(geo_objects)
22{
23 duplicate(input_name);
24}
void duplicate(std::string const &input_name)
GeoLib::GEOObjects & _geo_objects

References _geo_objects, _output_name, and duplicate().

Member Function Documentation

◆ copyPolylinesVector()

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

Definition at line 72 of file DuplicateGeometry.cpp.

74{
75 std::size_t const n_plys = polylines.size();
76 std::vector<GeoLib::Polyline*> new_lines{n_plys, nullptr};
77
78 for (std::size_t i = 0; i < n_plys; ++i)
79 {
80 if (polylines[i] == nullptr)
81 {
82 continue;
83 }
84 new_lines[i] =
85 new GeoLib::Polyline(*_geo_objects.getPointVec(_output_name));
86 std::size_t const nLinePnts(polylines[i]->getNumberOfPoints());
87 for (std::size_t j = 0; j < nLinePnts; ++j)
88 {
89 new_lines[i]->addPoint(polylines[i]->getPointID(j));
90 }
91 }
92 return new_lines;
93}

References _geo_objects, and _output_name.

Referenced by duplicate().

◆ copySurfacesVector()

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

Definition at line 95 of file DuplicateGeometry.cpp.

97{
98 std::size_t const n_sfc = surfaces.size();
99 std::vector<GeoLib::Surface*> new_surfaces{n_sfc, nullptr};
100
101 for (std::size_t i = 0; i < n_sfc; ++i)
102 {
103 if (surfaces[i] == nullptr)
104 {
105 continue;
106 }
107 new_surfaces[i] =
108 new GeoLib::Surface(*_geo_objects.getPointVec(_output_name));
109
110 std::size_t const n_tris(surfaces[i]->getNumberOfTriangles());
111 for (std::size_t j = 0; j < n_tris; ++j)
112 {
113 GeoLib::Triangle const* t = (*surfaces[i])[j];
114 new_surfaces[i]->addTriangle(t->getPoint(0)->getID(),
115 t->getPoint(1)->getID(),
116 t->getPoint(2)->getID());
117 }
118 }
119 return new_surfaces;
120}
const Point * getPoint(std::size_t i) const
const access operator to access the i-th triangle Point
Definition Triangle.h:44
std::size_t getID() const

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

Referenced by duplicate().

◆ duplicate()

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

Definition at line 26 of file DuplicateGeometry.cpp.

27{
28 std::vector<GeoLib::Point*> const* const pnts(
29 _geo_objects.getPointVec(input_name));
30 if (pnts == nullptr)
31 {
32 ERR("Geometry '{:s}' not found.", input_name);
33 return;
34 }
35
36 std::vector<GeoLib::Point*> new_pnts{};
37 new_pnts.reserve(pnts->size());
38 std::transform(pnts->cbegin(), pnts->cend(), std::back_inserter(new_pnts),
39 [](GeoLib::Point* point)
40 { return new GeoLib::Point(*point); });
41 PointVec::NameIdMap pnt_name_id_map(
42 _geo_objects.getPointVecObj(input_name)->getNameIDMapBegin(),
43 _geo_objects.getPointVecObj(input_name)->getNameIDMapEnd());
44 _geo_objects.addPointVec(std::move(new_pnts), _output_name,
45 std::move(pnt_name_id_map));
46
47 std::vector<GeoLib::Polyline*> const* plys(
48 _geo_objects.getPolylineVec(input_name));
49 if (plys)
50 {
51 auto new_plys = copyPolylinesVector(*plys);
52 PolylineVec::NameIdMap ply_name_id_map{
53 _geo_objects.getPolylineVecObj(input_name)->getNameIDMapBegin(),
54 _geo_objects.getPolylineVecObj(input_name)->getNameIDMapEnd()};
55 _geo_objects.addPolylineVec(std::move(new_plys), _output_name,
56 std::move(ply_name_id_map));
57 }
58
59 std::vector<GeoLib::Surface*> const* sfcs(
60 _geo_objects.getSurfaceVec(input_name));
61 if (sfcs)
62 {
63 auto new_sfcs = copySurfacesVector(*sfcs);
64 GeoLib::SurfaceVec::NameIdMap sfc_name_id_map{
65 _geo_objects.getSurfaceVecObj(input_name)->getNameIDMapBegin(),
66 _geo_objects.getSurfaceVecObj(input_name)->getNameIDMapEnd()};
67 _geo_objects.addSurfaceVec(std::move(new_sfcs), _output_name,
68 std::move(sfc_name_id_map));
69 }
70}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
std::vector< Surface * > copySurfacesVector(std::vector< Surface * > const &surfaces) const
std::vector< GeoLib::Polyline * > copyPolylinesVector(std::vector< GeoLib::Polyline * > const &polylines) const
std::map< std::string, std::size_t > NameIdMap
Definition TemplateVec.h:30

References _geo_objects, _output_name, copyPolylinesVector(), copySurfacesVector(), and ERR().

Referenced by DuplicateGeometry().

◆ getFinalizedOutputName()

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

Definition at line 35 of file DuplicateGeometry.h.

35{ return _output_name; }

References _output_name.

Referenced by MainWindow::mapGeometry().

◆ getPointVectorCopy()

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

Definition at line 122 of file DuplicateGeometry.cpp.

123{
124 return const_cast<std::vector<GeoLib::Point*>&>(
125 *_geo_objects.getPointVec(_output_name));
126}

References _geo_objects, and _output_name.

◆ getPolylineVectorCopy()

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

Definition at line 128 of file DuplicateGeometry.cpp.

129{
130 return const_cast<std::vector<GeoLib::Polyline*>&>(
131 *_geo_objects.getPolylineVec(_output_name));
132}

References _geo_objects, and _output_name.

◆ getSurfaceVectorCopy()

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

Definition at line 134 of file DuplicateGeometry.cpp.

135{
136 return const_cast<std::vector<GeoLib::Surface*>&>(
137 *_geo_objects.getSurfaceVec(_output_name));
138}

References _geo_objects, and _output_name.

Member Data Documentation

◆ _geo_objects

◆ _output_name

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

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