int GEOObjects::mergeGeometries (std::vector<std::string> const & geo_names, std::string &merged_geo_name) { const std::size_t n_geo_names(geo_names.size()); if (n_geo_names < 2) return 0; std::vector<std::size_t> pnt_offsets(n_geo_names, 0); if (! mergePoints(geo_names, merged_geo_name, pnt_offsets)) return -1; mergePolylines(geo_names, merged_geo_name, pnt_offsets); mergeSurfaces(geo_names, merged_geo_name, pnt_offsets); return 1; }
void GEOObjects::mergeGeometries (std::vector<std::string> const & geo_names, std::string &merged_geo_name) { const size_t n_geo_names(geo_names.size()); std::vector<size_t> pnt_offsets(n_geo_names, 0); // *** merge points std::vector<GeoLib::Point*>* merged_points (new std::vector<GeoLib::Point*>); for (size_t j(0); j < n_geo_names; j++) { const std::vector<GeoLib::Point*>* pnts (this->getPointVec(geo_names[j])); if (pnts) { size_t n_pnts(0); // do not consider stations if (dynamic_cast<GeoLib::Station*>((*pnts)[0]) == NULL) { n_pnts = pnts->size(); for (size_t k(0); k < n_pnts; k++) merged_points->push_back (new GeoLib::Point (((*pnts)[k])->getCoords())); } if (n_geo_names - 1 > j) { pnt_offsets[j + 1] = n_pnts + pnt_offsets[j]; } } } addPointVec (merged_points, merged_geo_name, NULL, 1e-6); std::vector<size_t> const& id_map (this->getPointVecObj(merged_geo_name)->getIDMap ()); // *** merge polylines std::vector<GeoLib::Polyline*>* merged_polylines (new std::vector<GeoLib::Polyline*>); for (size_t j(0); j < n_geo_names; j++) { const std::vector<GeoLib::Polyline*>* plys (this->getPolylineVec(geo_names[j])); if (plys) { for (size_t k(0); k < plys->size(); k++) { GeoLib::Polyline* kth_ply_new(new GeoLib::Polyline (*merged_points)); GeoLib::Polyline const* const kth_ply_old ((*plys)[k]); const size_t size_of_kth_ply (kth_ply_old->getNumberOfPoints()); // copy point ids from old ply to new ply (considering the offset) for (size_t i(0); i < size_of_kth_ply; i++) { kth_ply_new->addPoint (id_map[pnt_offsets[j] + kth_ply_old->getPointID(i)]); } merged_polylines->push_back (kth_ply_new); } } } this->addPolylineVec (merged_polylines, merged_geo_name); // *** merge surfaces std::vector<GeoLib::Surface*>* merged_sfcs (new std::vector<GeoLib::Surface*>); for (size_t j(0); j < n_geo_names; j++) { const std::vector<GeoLib::Surface*>* sfcs (this->getSurfaceVec(geo_names[j])); if (sfcs) { for (size_t k(0); k < sfcs->size(); k++) { GeoLib::Surface* kth_sfc_new(new GeoLib::Surface (*merged_points)); GeoLib::Surface const* const kth_sfc_old ((*sfcs)[k]); const size_t size_of_kth_sfc (kth_sfc_old->getNTriangles()); // copy point ids from old ply to new ply (considering the offset) for (size_t i(0); i < size_of_kth_sfc; i++) { const GeoLib::Triangle* tri ((*kth_sfc_old)[i]); const size_t id0 (id_map[pnt_offsets[j] + (*tri)[0]]); const size_t id1 (id_map[pnt_offsets[j] + (*tri)[1]]); const size_t id2 (id_map[pnt_offsets[j] + (*tri)[2]]); kth_sfc_new->addTriangle (id0, id1, id2); } merged_sfcs->push_back (kth_sfc_new); } } } this->addSurfaceVec (merged_sfcs, merged_geo_name); }