Commit 5f8109c5 authored by Tom Fischer's avatar Tom Fischer Committed by Dmitry Yu. Naumov
Browse files

Use new GEOObjects::addPolylineVec() without unique_ptr<vector>.

parent 93e464a2
......@@ -37,7 +37,7 @@ void FEFLOWGeoInterface::readFEFLOWFile(const std::string& filename,
unsigned dimension = 0;
std::vector<GeoLib::Point*> points{};
std::vector<GeoLib::Polyline*>* lines = nullptr;
std::vector<GeoLib::Polyline*> lines{};
bool isXZplane = false;
......@@ -101,11 +101,10 @@ void FEFLOWGeoInterface::readFEFLOWFile(const std::string& filename,
geo_objects.addPointVec(std::move(points), project_name,
GeoLib::PointVec::NameIdMap{});
}
if (lines)
if (!lines.empty())
{
geo_objects.addPolylineVec(
std::unique_ptr<std::vector<GeoLib::Polyline*>>(lines),
project_name);
geo_objects.addPolylineVec(std::move(lines), project_name,
GeoLib::PolylineVec::NameIdMap{});
}
}
......@@ -147,7 +146,7 @@ void FEFLOWGeoInterface::readPoints(QDomElement& nodesEle,
void FEFLOWGeoInterface::readSuperMesh(std::ifstream& in,
unsigned dimension,
std::vector<GeoLib::Point*>& points,
std::vector<GeoLib::Polyline*>*& lines)
std::vector<GeoLib::Polyline*>& lines)
{
// get XML strings
std::ostringstream oss;
......@@ -192,7 +191,6 @@ void FEFLOWGeoInterface::readSuperMesh(std::ifstream& in,
}
// #polygons
lines = new std::vector<GeoLib::Polyline*>();
QDomElement polygonsEle = docElem.firstChildElement("polygons");
if (polygonsEle.isNull())
{
......@@ -218,7 +216,7 @@ void FEFLOWGeoInterface::readSuperMesh(std::ifstream& in,
QString str_ptId_list = xmlEle.text().simplified();
{
auto* line = new GeoLib::Polyline(points);
lines->push_back(line);
lines.push_back(line);
std::istringstream ss(str_ptId_list.toStdString());
for (std::size_t i = 0; i < n_points; i++)
{
......
......@@ -48,7 +48,7 @@ public:
/// region
static void readSuperMesh(std::ifstream& in, unsigned dimension,
std::vector<GeoLib::Point*>& points,
std::vector<GeoLib::Polyline*>*& lines);
std::vector<GeoLib::Polyline*>& lines);
private:
//// read point data in Supermesh
......
......@@ -37,7 +37,7 @@ MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string& filename)
FEM_CLASS fem_class;
FEM_DIM fem_dim;
std::vector<GeoLib::Point*> points;
std::vector<GeoLib::Polyline*>* lines = nullptr;
std::vector<GeoLib::Polyline*> lines{};
bool isXZplane = false;
......@@ -232,8 +232,8 @@ MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string& filename)
else
{
opt_material_ids->resize(mesh->getNumberOfElements());
setMaterialIDs(fem_class, fem_dim, lines, vec_elementsets, vec_elements,
*opt_material_ids);
setMaterialIDs(fem_class, fem_dim, &lines, vec_elementsets,
vec_elements, *opt_material_ids);
}
if (isXZplane)
......
......@@ -491,22 +491,22 @@ void GMSHPolygonTree::writeAdditionalPointData(std::size_t& pnt_id_offset,
dynamic_cast<GMSHAdaptiveMeshDensity*>(&_mesh_density_strategy))
{
std::vector<GeoLib::Point*> pnts{};
auto plys = std::make_unique<std::vector<GeoLib::Polyline*>>();
adaptive_mesh_density->getQuadTreeGeometry(pnts, *plys);
std::vector<GeoLib::Polyline*> plys{};
adaptive_mesh_density->getQuadTreeGeometry(pnts, plys);
std::string quad_tree_geo("QuadTree");
_geo_objs.addPointVec(std::move(pnts), quad_tree_geo,
GeoLib::PointVec::NameIdMap{});
std::vector<std::size_t> const& id_map(
(_geo_objs.getPointVecObj(quad_tree_geo))->getIDMap());
for (std::size_t k(0); k < plys->size(); k++)
for (std::size_t k(0); k < plys.size(); k++)
{
for (std::size_t j(0); j < (*plys)[k]->getNumberOfPoints(); j++)
for (std::size_t j(0); j < plys[k]->getNumberOfPoints(); j++)
{
((*plys)[k])
->setPointID(j, id_map[((*plys)[k])->getPointID(j)]);
(plys[k])->setPointID(j, id_map[(plys[k])->getPointID(j)]);
}
}
_geo_objs.addPolylineVec(std::move(plys), quad_tree_geo);
_geo_objs.addPolylineVec(std::move(plys), quad_tree_geo,
GeoLib::PolylineVec::NameIdMap{});
}
#endif
}
......
......@@ -155,8 +155,8 @@ void readPolylinePointVector(const std::string& fname,
**************************************************************************/
/** read a single Polyline from stream in into the ply_vec-vector */
std::string readPolyline(std::istream& in,
std::vector<GeoLib::Polyline*>* ply_vec,
std::map<std::string, std::size_t>& ply_vec_names,
std::vector<GeoLib::Polyline*>& ply_vec,
GeoLib::PolylineVec::NameIdMap& ply_vec_names,
std::vector<GeoLib::Point*>& pnt_vec,
bool zero_based_indexing,
const std::vector<std::size_t>& pnt_id_map,
......@@ -252,8 +252,8 @@ std::string readPolyline(std::istream& in,
if (type != 100)
{
ply_vec_names.insert(
std::pair<std::string, std::size_t>(name_of_ply, ply_vec->size()));
ply_vec->push_back(ply);
std::pair<std::string, std::size_t>(name_of_ply, ply_vec.size()));
ply_vec.push_back(ply);
}
return line;
......@@ -271,7 +271,7 @@ polyline 08/2005 CC parameter 01/2010 TF changed signature of function
**************************************************************************/
/** reads polylines */
std::string readPolylines(std::istream& in,
std::vector<GeoLib::Polyline*>* ply_vec,
std::vector<GeoLib::Polyline*>& ply_vec,
std::map<std::string, std::size_t>& ply_vec_names,
std::vector<GeoLib::Point*>& pnt_vec,
bool zero_based_indexing,
......@@ -545,8 +545,8 @@ bool readGLIFileV4(const std::string& fname,
const std::string path = BaseLib::extractPath(fname);
// read names of plys into temporary string-vec
auto ply_names = std::make_unique<std::map<std::string, std::size_t>>();
auto ply_vec = std::make_unique<std::vector<GeoLib::Polyline*>>();
GeoLib::PolylineVec::NameIdMap ply_names{};
std::vector<GeoLib::Polyline*> ply_vec{};
GeoLib::PointVec& point_vec(
*const_cast<GeoLib::PointVec*>(geo.getPointVecObj(unique_name)));
auto* geo_pnt_vec(
......@@ -555,17 +555,17 @@ bool readGLIFileV4(const std::string& fname,
{
INFO("GeoLib::readGLIFile(): read polylines from stream.");
tag = readPolylines(
in, ply_vec.get(), *ply_names, *geo_pnt_vec, zero_based_idx,
in, ply_vec, ply_names, *geo_pnt_vec, zero_based_idx,
geo.getPointVecObj(unique_name)->getIDMap(), path, errors);
INFO("GeoLib::readGLIFile(): \t ok, {:d} polylines read.",
ply_vec->size());
ply_vec.size());
}
else
{
INFO("GeoLib::readGLIFile(): tag #POLYLINE not found.");
}
if (!ply_vec->empty())
if (!ply_vec.empty())
{
geo.addPolylineVec(std::move(ply_vec), unique_name,
std::move(ply_names));
......
......@@ -65,9 +65,10 @@ bool createSurface(GeoLib::Polyline const& ply,
{
polyline->addPoint(ply.getPointID(k));
}
auto polylines = std::make_unique<std::vector<GeoLib::Polyline*>>();
polylines->push_back(polyline.release());
geo.addPolylineVec(std::move(polylines), ply_name);
std::vector<GeoLib::Polyline*> polylines{};
polylines.push_back(polyline.release());
geo.addPolylineVec(std::move(polylines), ply_name,
GeoLib::PolylineVec::NameIdMap{});
// use GMSHInterface to create a mesh from the closed polyline
auto const geo_names = geo.getGeometryNames();
......
......@@ -78,17 +78,16 @@ PetrelInterface::PetrelInterface(std::list<std::string>& sfc_fnames,
}
// store data in GEOObject
geo_obj->addPointVec(
std::move(*pnt_vec), _unique_name, GeoLib::PointVec::NameIdMap{});
geo_obj->addPointVec(std::move(*pnt_vec), _unique_name,
GeoLib::PointVec::NameIdMap{});
if (!well_vec->empty())
{
geo_obj->addStationVec(std::move(*well_vec), _unique_name);
}
if (!ply_vec->empty())
{
geo_obj->addPolylineVec(
std::unique_ptr<std::vector<GeoLib::Polyline*>>(ply_vec),
_unique_name);
geo_obj->addPolylineVec(std::move(*ply_vec), _unique_name,
GeoLib::PolylineVec::NameIdMap{});
}
}
......
......@@ -142,7 +142,7 @@ void SHPInterface::readPolylines(const SHPHandle& hSHP, int numberOfElements,
return;
}
std::vector<GeoLib::Point*> pnts{};
auto lines = std::make_unique<std::vector<GeoLib::Polyline*>>();
std::vector<GeoLib::Polyline*> lines{};
std::size_t pnt_id(0);
// for each polyline
......@@ -191,7 +191,7 @@ void SHPInterface::readPolylines(const SHPHandle& hSHP, int numberOfElements,
INFO(
"Polygon {:d} consists of {:d} parts (PolylineIDs "
"{:d}-{:d}).",
i, noOfParts, lines->size(), lines->size() + noOfParts - 1);
i, noOfParts, lines.size(), lines.size() + noOfParts - 1);
}
int const firstPnt = *(hSHPObject->panPartStart + p);
......@@ -208,11 +208,12 @@ void SHPInterface::readPolylines(const SHPHandle& hSHP, int numberOfElements,
pnt_id++;
}
// add polyline to polyline vector
lines->push_back(line);
lines.push_back(line);
}
SHPDestroyObject(hSHPObject); // de-allocate SHPObject
}
_geoObjects.addPolylineVec(std::move(lines), listName);
_geoObjects.addPolylineVec(std::move(lines), listName,
GeoLib::PolylineVec::NameIdMap{});
}
void SHPInterface::readPolygons(const SHPHandle& hSHP, int numberOfElements,
......
......@@ -20,18 +20,17 @@
#include "GeoLib/Utils.h"
#include "InfoLib/GitInfo.h"
std::tuple<std::unique_ptr<std::vector<GeoLib::Polyline*>>,
std::unique_ptr<std::map<std::string, std::size_t>>>
std::tuple<std::vector<GeoLib::Polyline*>, GeoLib::PolylineVec::NameIdMap>
appendNamedPolyline(std::unique_ptr<GeoLib::Polyline> polyline,
std::string&& polyline_name)
{
auto lines = std::make_unique<std::vector<GeoLib::Polyline*>>();
auto name_map = std::make_unique<std::map<std::string, std::size_t>>();
std::vector<GeoLib::Polyline*> lines{};
GeoLib::PolylineVec::NameIdMap name_map{};
lines->push_back(polyline.release());
(*name_map)[std::move(polyline_name)] = lines->size() - 1;
lines.push_back(polyline.release());
name_map[std::move(polyline_name)] = lines.size() - 1;
return {std::move(lines), std::move(name_map)};
return {lines, name_map};
}
void generateSinglePointGeometry(GeoLib::Point const& point,
......
......@@ -107,9 +107,10 @@ std::vector<std::string> createGeometries(
geo.addPointVec(std::move(points), geo_name,
GeoLib::PointVec::NameIdMap{});
auto lines = std::make_unique<std::vector<GeoLib::Polyline*>>();
lines->push_back(createPolyline(*geo.getPointVec(geo_name)));
geo.addPolylineVec(std::move(lines), geo_name);
std::vector<GeoLib::Polyline*> lines{};
lines.push_back(createPolyline(*geo.getPointVec(geo_name)));
geo.addPolylineVec(std::move(lines), geo_name,
GeoLib::PolylineVec::NameIdMap{});
MeshGeoToolsLib::GeoMapper mapper(geo, geo_name);
mapper.mapOnMesh(layer.get());
......@@ -126,7 +127,7 @@ void mergeGeometries(GeoLib::GEOObjects& geo,
std::string& merged_geo_name)
{
std::vector<GeoLib::Point*> points{};
auto lines = std::make_unique<std::vector<GeoLib::Polyline*>>();
std::vector<GeoLib::Polyline*> lines{};
auto layer_pnts = *geo.getPointVec(geo_names[0]);
std::size_t const pnts_per_line = layer_pnts.size();
......@@ -162,12 +163,13 @@ void mergeGeometries(GeoLib::GEOObjects& geo,
}
// close polygon
line->addPoint(line->getPointID(0));
lines->push_back(line);
lines.push_back(line);
}
geo.addPointVec(std::move(points), merged_geo_name,
GeoLib::PointVec::NameIdMap{});
geo.addPolylineVec(std::move(lines), merged_geo_name);
geo.addPolylineVec(std::move(lines), merged_geo_name,
GeoLib::PolylineVec::NameIdMap{});
}
/// rotates the merged geometry into the XY-plane
......
......@@ -56,10 +56,9 @@ void DuplicateGeometry::duplicate(std::string const& input_name)
if (plys)
{
auto new_plys = copyPolylinesVector(*plys);
auto ply_name_id_map =
std::make_unique<std::map<std::string, std::size_t>>(
_geo_objects.getPolylineVecObj(input_name)->getNameIDMapBegin(),
_geo_objects.getPolylineVecObj(input_name)->getNameIDMapEnd());
PolylineVec::NameIdMap ply_name_id_map{
_geo_objects.getPolylineVecObj(input_name)->getNameIDMapBegin(),
_geo_objects.getPolylineVecObj(input_name)->getNameIDMapEnd()};
_geo_objects.addPolylineVec(std::move(new_plys), _output_name,
std::move(ply_name_id_map));
}
......@@ -78,13 +77,11 @@ void DuplicateGeometry::duplicate(std::string const& input_name)
}
}
std::unique_ptr<std::vector<GeoLib::Polyline*>>
DuplicateGeometry::copyPolylinesVector(
std::vector<GeoLib::Polyline*> DuplicateGeometry::copyPolylinesVector(
std::vector<GeoLib::Polyline*> const& polylines) const
{
std::size_t const n_plys = polylines.size();
auto new_lines =
std::make_unique<std::vector<GeoLib::Polyline*>>(n_plys, nullptr);
std::vector<GeoLib::Polyline*> new_lines{n_plys, nullptr};
for (std::size_t i = 0; i < n_plys; ++i)
{
......@@ -92,12 +89,12 @@ DuplicateGeometry::copyPolylinesVector(
{
continue;
}
(*new_lines)[i] =
new_lines[i] =
new GeoLib::Polyline(*_geo_objects.getPointVec(_output_name));
std::size_t const nLinePnts(polylines[i]->getNumberOfPoints());
for (std::size_t j = 0; j < nLinePnts; ++j)
{
(*new_lines)[i]->addPoint(polylines[i]->getPointID(j));
new_lines[i]->addPoint(polylines[i]->getPointID(j));
}
}
return new_lines;
......
......@@ -52,7 +52,7 @@ private:
void duplicate(std::string const& input_name);
// creates a deep copy of the polyline vector
std::unique_ptr<std::vector<GeoLib::Polyline*>> copyPolylinesVector(
std::vector<GeoLib::Polyline*> copyPolylinesVector(
std::vector<GeoLib::Polyline*> const& polylines) const;
// creates a deep copy of the surface vector
......
......@@ -513,9 +513,8 @@ void GEOObjects::mergePolylines(std::vector<std::string> const& geo_names,
const std::size_t n_geo_names(geo_names.size());
std::vector<std::size_t> ply_offsets(n_geo_names, 0);
auto merged_polylines = std::make_unique<std::vector<GeoLib::Polyline*>>();
auto merged_ply_names =
std::make_unique<std::map<std::string, std::size_t>>();
std::vector<GeoLib::Polyline*> merged_polylines{};
PolylineVec::NameIdMap merged_ply_names;
std::vector<GeoLib::Point*> const* merged_points(
this->getPointVecObj(merged_geo_name)->getVector());
......@@ -542,13 +541,11 @@ void GEOObjects::mergePolylines(std::vector<std::string> const& geo_names,
kth_ply_new->addPoint(
id_map[pnt_offsets[j] + kth_ply_old->getPointID(i)]);
}
merged_polylines->push_back(kth_ply_new);
merged_polylines.push_back(kth_ply_new);
if (this->getPolylineVecObj(geo_names[j])
->getNameOfElementByID(k, tmp_name))
{
merged_ply_names->insert(
std::pair<std::string, std::size_t>(
tmp_name, ply_offsets[j] + k));
merged_ply_names.emplace(tmp_name, ply_offsets[j] + k);
}
}
if (n_geo_names - 1 > j)
......@@ -558,7 +555,7 @@ void GEOObjects::mergePolylines(std::vector<std::string> const& geo_names,
}
}
if (!merged_polylines->empty())
if (!merged_polylines.empty())
{
this->addPolylineVec(std::move(merged_polylines), merged_geo_name,
std::move(merged_ply_names));
......
......@@ -367,43 +367,43 @@ void Grid<POINT>::createGridGeometry(GeoLib::GEOObjects* geo_obj) const
PointVec::NameIdMap{});
}
auto plys = std::make_unique<std::vector<GeoLib::Polyline*>>();
std::vector<GeoLib::Polyline*> plys{};
auto const& points = *geo_obj->getPointVec(grid_names.back());
auto* ply0(new GeoLib::Polyline(points));
auto* ply0(new GeoLib::Polyline(points));
for (std::size_t l(0); l < 4; l++)
ply0->addPoint(l);
ply0->addPoint(0);
plys->push_back(ply0);
plys.push_back(ply0);
auto* ply1(new GeoLib::Polyline(points));
for (std::size_t l(4); l < 8; l++)
ply1->addPoint(l);
ply1->addPoint(4);
plys->push_back(ply1);
plys.push_back(ply1);
auto* ply2(new GeoLib::Polyline(points));
ply2->addPoint(0);
ply2->addPoint(4);
plys->push_back(ply2);
plys.push_back(ply2);
auto* ply3(new GeoLib::Polyline(points));
ply3->addPoint(1);
ply3->addPoint(5);
plys->push_back(ply3);
plys.push_back(ply3);
auto* ply4(new GeoLib::Polyline(points));
ply4->addPoint(2);
ply4->addPoint(6);
plys->push_back(ply4);
plys.push_back(ply4);
auto* ply5(new GeoLib::Polyline(points));
ply5->addPoint(3);
ply5->addPoint(7);
plys->push_back(ply5);
plys.push_back(ply5);
geo_obj->addPolylineVec(std::move(plys), grid_names.back(),
nullptr);
PolylineVec::NameIdMap{});
}
}
}
......
......@@ -45,11 +45,8 @@ bool BoostXmlGmlInterface::readFile(const std::string& fname)
doc->ignoreConfigAttribute("xsi:noNamespaceSchemaLocation");
doc->ignoreConfigAttribute("xmlns:ogs");
auto polylines = std::make_unique<std::vector<GeoLib::Polyline*>>();
auto surfaces = std::make_unique<std::vector<GeoLib::Surface*>>();
using MapNameId = std::map<std::string, std::size_t>;
auto ply_names = std::make_unique<MapNameId>();
auto sfc_names = std::make_unique<MapNameId>();
//! \ogs_file_param{gml__name}
......@@ -69,14 +66,16 @@ bool BoostXmlGmlInterface::readFile(const std::string& fname)
std::move(pnt_names));
}
std::vector<GeoLib::Polyline*> polylines{};
GeoLib::PolylineVec::NameIdMap ply_names{};
//! \ogs_file_param{gml__polylines}
for (auto st : doc->getConfigSubtreeList("polylines"))
{
readPolylines(st,
*polylines,
polylines,
*_geo_objects.getPointVec(geo_name),
_geo_objects.getPointVecObj(geo_name)->getIDMap(),
*ply_names);
ply_names);
}
//! \ogs_file_param{gml__surfaces}
......@@ -89,7 +88,7 @@ bool BoostXmlGmlInterface::readFile(const std::string& fname)
*sfc_names);
}
if (!polylines->empty())
if (!polylines.empty())
{
_geo_objects.addPolylineVec(std::move(polylines), geo_name,
std::move(ply_names));
......
......@@ -23,9 +23,9 @@
namespace
{
void deletePolylines(std::unique_ptr<std::vector<GeoLib::Polyline*>> polylines)
void deletePolylines(std::vector<GeoLib::Polyline*>& polylines)
{
for (GeoLib::Polyline* line : *polylines)
for (GeoLib::Polyline* line : polylines)
{
delete line;
}
......@@ -39,8 +39,7 @@ void deleteSurfaces(std::unique_ptr<std::vector<GeoLib::Surface*>> surfaces)
}
}
void deleteGeometry(std::vector<GeoLib::Point*>& points,
std::unique_ptr<std::vector<GeoLib::Polyline*>>
polylines,
std::vector<GeoLib::Polyline*>& polylines,
std::unique_ptr<std::vector<GeoLib::Surface*>>
surfaces)
{
......@@ -48,7 +47,7 @@ void deleteGeometry(std::vector<GeoLib::Point*>& points,
{
delete point;
}
deletePolylines(std::move(polylines));
deletePolylines(polylines);
deleteSurfaces(std::move(surfaces));
}
} // namespace
......@@ -81,12 +80,12 @@ int XmlGmlInterface::readFile(const QString& fileName)
std::string gliName("[NN]");
std::vector<GeoLib::Point*> points{};
auto polylines = std::make_unique<std::vector<GeoLib::Polyline*>>();
std::vector<GeoLib::Polyline*> polylines{};
auto surfaces = std::make_unique<std::vector<GeoLib::Surface*>>();
using MapNameId = std::map<std::string, std::size_t>;
MapNameId pnt_names;
auto ply_names = std::make_unique<MapNameId>();
MapNameId ply_names{};
auto sfc_names = std::make_unique<MapNameId>();
QDomNodeList geoTypes = docElement.childNodes();
......@@ -99,8 +98,7 @@ int XmlGmlInterface::readFile(const QString& fileName)
if (type_node.toElement().text().isEmpty())
{
ERR("XmlGmlInterface::readFile(): <name>-tag is empty.");
deleteGeometry(points, std::move(polylines),
std::move(surfaces));
deleteGeometry(points, polylines, std::move(surfaces));
return 0;
}
......@@ -116,10 +114,9 @@ int XmlGmlInterface::readFile(const QString& fileName)
{
try
{
readPolylines(type_node, polylines.get(),
*_geo_objs.getPointVec(gliName),
_geo_objs.getPointVecObj(gliName)->getIDMap(),
ply_names.get());
readPolylines(
type_node, polylines, *_geo_objs.getPointVec(gliName),
_geo_objs.getPointVecObj(gliName)->getIDMap(), ply_names);
}
catch (std::runtime_error const&)
{
......@@ -127,11 +124,6 @@ int XmlGmlInterface::readFile(const QString& fileName)
_geo_objs.removePointVec(gliName);
throw;
}
// if names-map is empty, set it to nullptr because it is not needed
if (ply_names->empty())
{
ply_names.reset(nullptr);
}
}
else if (nodeName.compare("surfaces") == 0)
{
......@@ -158,7 +150,7 @@ int XmlGmlInterface::readFile(const QString& fileName)
}
}
if (!polylines->empty())
if (!polylines.empty())
{
_geo_objs.addPolylineVec(std::move(polylines), gliName,
std::move(ply_names));
......@@ -198,28 +190,27 @@ void XmlGmlInterface::readPoints(const QDomNode& pointsRoot,
}
}