Skip to content
Snippets Groups Projects
Commit f3e38c00 authored by Tom Fischer's avatar Tom Fischer
Browse files

Merge pull request #492 from rinkk/TINConversionSingleGeometries

TIN conversion for single geometries
parents 59f6bec2 b5da9bfc
No related branches found
No related tags found
No related merge requests found
......@@ -565,6 +565,39 @@ bool readGLIFileV4(const std::string& fname,
return false;
}
std::size_t writeTINSurfaces(std::ofstream &os, GeoLib::SurfaceVec const* sfcs_vec, std::size_t sfc_count, std::string const& path)
{
const std::vector<GeoLib::Surface*>* sfcs (sfcs_vec->getVector());
for (std::size_t k(0); k < sfcs->size(); k++)
{
os << "#SURFACE" << "\n";
std::string sfc_name;
if (sfcs_vec->getNameOfElementByID (sfc_count, sfc_name)) {
os << "\t$NAME " << "\n" << "\t\t" << sfc_name << "\n";
} else {
os << "\t$NAME " << "\n" << "\t\t" << sfc_count << "\n";
sfc_name = std::to_string (sfc_count);
}
sfc_name += ".tin";
os << "\t$TIN" << "\n";
os << "\t\t" << sfc_name << "\n";
// create tin file
sfc_name = path + sfc_name;
std::ofstream tin_os (sfc_name.c_str());
GeoLib::Surface const& sfc (*(*sfcs)[k]);
const std::size_t n_tris (sfc.getNTriangles());
for (std::size_t l(0); l < n_tris; l++) {
GeoLib::Triangle const& tri (*(sfc[l]));
tin_os << l << " " << *(tri.getPoint(0)) << " " <<
*(tri.getPoint(1)) << " " << *(tri.getPoint(2)) <<
"\n";
}
tin_os.close();
sfc_count++;
}
return sfc_count;
}
void writeGLIFileV4 (const std::string& fname,
const std::string& geo_name,
const GeoLib::GEOObjects& geo)
......@@ -603,19 +636,13 @@ void writeGLIFileV4 (const std::string& fname,
for (std::size_t j(0); j < (*plys)[k]->getNumberOfPoints(); j++)
os << " " << ((*plys)[k])->getPointID(j) << "\n";
}
INFO("GeoLib::writeGLIFileV4(): write closed polylines as surfaces to file %s.",
fname.c_str());
for (std::size_t k(0); k < plys->size(); k++)
if ((*plys)[k]->isClosed())
{
os << "#SURFACE" << "\n";
os << " $NAME " << "\n" << " " << k << "\n"; //plys_vec->getNameOfElement ((*plys)[k]) << "\n";
os << " $TYPE " << "\n" << " 0" << "\n";
os << " $POLYLINES" << "\n" << " " << k << "\n"; //plys_vec->getNameOfElement ((*plys)[k]) << "\n";
}
}
// writing surfaces as TIN files
const GeoLib::SurfaceVec* sfcs_vec (geo.getSurfaceVecObj (geo_name));
if (sfcs_vec)
writeTINSurfaces(os, sfcs_vec, 0, BaseLib::extractPath(fname));
os << "#STOP" << "\n";
os.close ();
}
......@@ -706,37 +733,8 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects
for (std::size_t j(0); j < geo_names.size(); j++)
{
const GeoLib::SurfaceVec* sfcs_vec (geo.getSurfaceVecObj (geo_names[j]));
if (sfcs_vec) {
const std::vector<GeoLib::Surface*>* sfcs (sfcs_vec->getVector());
for (std::size_t k(0); k < sfcs->size(); k++)
{
os << "#SURFACE" << "\n";
std::string sfc_name;
if (sfcs_vec->getNameOfElementByID (sfcs_cnt, sfc_name)) {
os << "\t$NAME " << "\n" << "\t\t" << sfc_name << "\n";
} else {
os << "\t$NAME " << "\n" << "\t\t" << sfcs_cnt << "\n";
sfc_name = std::to_string (sfcs_cnt);
}
sfc_name += ".tin";
os << "\t$TIN" << "\n";
os << "\t\t" << sfc_name << "\n";
// create tin file
sfc_name = path + sfc_name;
std::ofstream tin_os (sfc_name.c_str());
GeoLib::Surface const& sfc (*(*sfcs)[k]);
const std::size_t n_tris (sfc.getNTriangles());
for (std::size_t l(0); l < n_tris; l++) {
GeoLib::Triangle const& tri (*(sfc[l]));
tin_os << l << " " << *(tri.getPoint(0)) << " " <<
*(tri.getPoint(1)) << " " << *(tri.getPoint(2)) <<
"\n";
}
tin_os.close();
sfcs_cnt++;
}
}
if (sfcs_vec)
sfcs_cnt += writeTINSurfaces(os, sfcs_vec, sfcs_cnt, path);
}
os << "#STOP" << "\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment