mirror of https://github.com/CGAL/cgal
Merge pull request #7112 from afabri/T2_demo-read_WKT-GF
Triangulation_2 Demo: Read files with many WKT entities
This commit is contained in:
commit
cda39a3db4
|
|
@ -555,87 +555,32 @@ MainWindow::loadWKT(QString filename)
|
||||||
{
|
{
|
||||||
//Polygons todo : make it multipolygons
|
//Polygons todo : make it multipolygons
|
||||||
std::ifstream ifs(qPrintable(filename));
|
std::ifstream ifs(qPrintable(filename));
|
||||||
do
|
|
||||||
{
|
|
||||||
typedef CGAL::Polygon_with_holes_2<K> Polygon;
|
|
||||||
typedef CGAL::Point_2<K> Point;
|
|
||||||
std::vector<Polygon> mps;
|
|
||||||
CGAL::IO::read_multi_polygon_WKT(ifs, mps);
|
|
||||||
for(const Polygon& p : mps)
|
|
||||||
{
|
|
||||||
if(p.outer_boundary().is_empty())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for(Point point : p.outer_boundary().container())
|
typedef CGAL::Polygon_with_holes_2<K> Polygon;
|
||||||
cdt.insert(point);
|
typedef CGAL::Point_2<K> Point;
|
||||||
for(Polygon::General_polygon_2::Edge_const_iterator
|
|
||||||
e_it=p.outer_boundary().edges_begin(); e_it != p.outer_boundary().edges_end(); ++e_it)
|
|
||||||
cdt.insert_constraint(e_it->source(), e_it->target());
|
|
||||||
|
|
||||||
for(Polygon::Hole_const_iterator h_it =
|
std::deque<Point> points;
|
||||||
p.holes_begin(); h_it != p.holes_end(); ++h_it)
|
std::deque<std::vector<Point>> linestrings;
|
||||||
{
|
std::deque<Polygon> polygons;
|
||||||
for(Point point : h_it->container())
|
|
||||||
cdt.insert(point);
|
|
||||||
for(Polygon::General_polygon_2::Edge_const_iterator
|
|
||||||
e_it=h_it->edges_begin(); e_it != h_it->edges_end(); ++e_it)
|
|
||||||
{
|
|
||||||
cdt.insert_constraint(e_it->source(), e_it->target());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}while(ifs.good() && !ifs.eof());
|
|
||||||
//Edges
|
|
||||||
ifs.clear();
|
|
||||||
ifs.seekg(0, ifs.beg);
|
|
||||||
do
|
|
||||||
{
|
|
||||||
typedef std::vector<K::Point_2> LineString;
|
|
||||||
std::vector<LineString> mls;
|
|
||||||
CGAL::IO::read_multi_linestring_WKT(ifs, mls);
|
|
||||||
for(const LineString& ls : mls)
|
|
||||||
{
|
|
||||||
if(ls.empty())
|
|
||||||
continue;
|
|
||||||
K::Point_2 p,q, qold(0,0); // initialize to avoid maybe-uninitialized warning from GCC6
|
|
||||||
bool first = true;
|
|
||||||
CDT::Vertex_handle vp, vq, vqold;
|
|
||||||
LineString::const_iterator it =
|
|
||||||
ls.begin();
|
|
||||||
for(; it != ls.end(); ++it) {
|
|
||||||
p = *it++;
|
|
||||||
q = *it;
|
|
||||||
if(p == q){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if((!first) && (p == qold)){
|
|
||||||
vp = vqold;
|
|
||||||
} else {
|
|
||||||
vp = cdt.insert(p);
|
|
||||||
}
|
|
||||||
vq = cdt.insert(q, vp->face());
|
|
||||||
if(vp != vq) {
|
|
||||||
cdt.insert_constraint(vp,vq);
|
|
||||||
}
|
|
||||||
qold = q;
|
|
||||||
vqold = vq;
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}while(ifs.good() && !ifs.eof());
|
|
||||||
|
|
||||||
//Points
|
CGAL::IO::read_WKT(ifs, points, linestrings, polygons);
|
||||||
ifs.clear();
|
|
||||||
ifs.seekg(0, ifs.beg);
|
cdt.insert(points.begin(),points.end());
|
||||||
do
|
|
||||||
{
|
for(const std::vector<Point>& line : linestrings){
|
||||||
std::vector<K::Point_2> mpts;
|
cdt.insert_constraint(line.begin(), line.end());
|
||||||
CGAL::IO::read_multi_point_WKT(ifs, mpts);
|
}
|
||||||
for(const K::Point_2& p : mpts)
|
|
||||||
{
|
for(const Polygon& p : polygons){
|
||||||
cdt.insert(p);
|
if(p.outer_boundary().is_empty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
cdt.insert_constraint(p.outer_boundary().vertices_begin(), p.outer_boundary().vertices_end(),true);
|
||||||
|
|
||||||
|
for(Polygon::Hole_const_iterator h_it = p.holes_begin(); h_it != p.holes_end(); ++h_it){
|
||||||
|
cdt.insert_constraint(h_it->vertices_begin(), h_it->vertices_end(),true);
|
||||||
}
|
}
|
||||||
}while(ifs.good() && !ifs.eof());
|
}
|
||||||
|
|
||||||
discoverComponents(cdt, m_seeds);
|
discoverComponents(cdt, m_seeds);
|
||||||
Q_EMIT( changed());
|
Q_EMIT( changed());
|
||||||
|
|
|
||||||
|
|
@ -503,72 +503,74 @@ bool read_WKT(std::istream& is,
|
||||||
if(!is.good())
|
if(!is.good())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
do
|
while(is.good() && !is.eof())
|
||||||
{
|
{
|
||||||
typedef typename MultiPoint::value_type Point;
|
typedef typename MultiPoint::value_type Point;
|
||||||
typedef typename MultiLineString::value_type LineString;
|
typedef typename MultiLineString::value_type LineString;
|
||||||
typedef typename MultiPolygon::value_type Polygon;
|
typedef typename MultiPolygon::value_type Polygon;
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
std::streampos input_pos = is.tellg();
|
|
||||||
std::getline(is, line);
|
std::getline(is, line);
|
||||||
std::istringstream iss(line);
|
std::string::size_type header_end = line.find("("); // }
|
||||||
std::string t;
|
if(header_end == std::string::npos){
|
||||||
std::string type="";
|
continue;
|
||||||
iss >> t;
|
|
||||||
|
|
||||||
for(std::size_t pos=0; pos < t.length(); ++pos)
|
|
||||||
{
|
|
||||||
char c = t[pos];
|
|
||||||
if(c == '(')
|
|
||||||
break;
|
|
||||||
|
|
||||||
type.push_back(c);
|
|
||||||
}
|
}
|
||||||
|
std::string type="";
|
||||||
|
const std::string header = line.substr(0,header_end);
|
||||||
|
const std::string types[6] = { "MULTIPOLYGON", "MULTILINESTRING", "MULTIPOINT", "POLYGON", "LINESTRING", "POINT"};
|
||||||
|
for(int i= 0; i < 6; ++i){
|
||||||
|
if(header.find(types[i]) != std::string::npos){
|
||||||
|
type = types[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(type == ""){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
std::istringstream iss(line);
|
||||||
|
|
||||||
is.seekg(input_pos);
|
|
||||||
if(type == "POINT")
|
if(type == "POINT")
|
||||||
{
|
{
|
||||||
Point p;
|
Point p;
|
||||||
CGAL::IO::read_point_WKT(is, p);
|
CGAL::IO::read_point_WKT(iss, p);
|
||||||
points.push_back(p);
|
points.push_back(p);
|
||||||
}
|
}
|
||||||
else if(type == "LINESTRING")
|
else if(type == "LINESTRING")
|
||||||
{
|
{
|
||||||
LineString l;
|
LineString l;
|
||||||
CGAL::IO::read_linestring_WKT(is, l);
|
CGAL::IO::read_linestring_WKT(iss, l);
|
||||||
polylines.push_back(l);
|
polylines.push_back(l);
|
||||||
}
|
}
|
||||||
else if(type == "POLYGON")
|
else if(type == "POLYGON")
|
||||||
{
|
{
|
||||||
Polygon p;
|
Polygon p;
|
||||||
CGAL::IO::read_polygon_WKT(is, p);
|
CGAL::IO::read_polygon_WKT(iss, p);
|
||||||
if(!p.outer_boundary().is_empty())
|
if(!p.outer_boundary().is_empty())
|
||||||
polygons.push_back(p);
|
polygons.push_back(p);
|
||||||
}
|
}
|
||||||
else if(type == "MULTIPOINT")
|
else if(type == "MULTIPOINT")
|
||||||
{
|
{
|
||||||
MultiPoint mp;
|
MultiPoint mp;
|
||||||
CGAL::IO::read_multi_point_WKT(is, mp);
|
CGAL::IO::read_multi_point_WKT(iss, mp);
|
||||||
for(const Point& point : mp)
|
for(const Point& point : mp)
|
||||||
points.push_back(point);
|
points.push_back(point);
|
||||||
}
|
}
|
||||||
else if(type == "MULTILINESTRING")
|
else if(type == "MULTILINESTRING")
|
||||||
{
|
{
|
||||||
MultiLineString mls;
|
MultiLineString mls;
|
||||||
CGAL::IO::read_multi_linestring_WKT(is, mls);
|
CGAL::IO::read_multi_linestring_WKT(iss, mls);
|
||||||
for(const LineString& ls : mls)
|
for(const LineString& ls : mls)
|
||||||
polylines.push_back(ls);
|
polylines.push_back(ls);
|
||||||
}
|
}
|
||||||
else if(type == "MULTIPOLYGON")
|
else if(type == "MULTIPOLYGON")
|
||||||
{
|
{
|
||||||
MultiPolygon mp;
|
MultiPolygon mp;
|
||||||
CGAL::IO::read_multi_polygon_WKT(is, mp);
|
CGAL::IO::read_multi_polygon_WKT(iss, mp);
|
||||||
for(const Polygon& poly : mp)
|
for(const Polygon& poly : mp)
|
||||||
polygons.push_back(poly);
|
polygons.push_back(poly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while(is.good() && !is.eof());
|
|
||||||
|
|
||||||
return !is.fail();
|
return !is.fail();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue