mirror of https://github.com/CGAL/cgal
Add WKT IO to 2D demos and add saving to stream_lines_2_demo
Also adds traits for Point_3 to be able to interract with weighted points through them.
This commit is contained in:
parent
9fa8cfac54
commit
df980abff6
|
|
@ -6,6 +6,7 @@
|
|||
#include <CGAL/Alpha_shape_2.h>
|
||||
#include <CGAL/Alpha_shape_face_base_2.h>
|
||||
#include <CGAL/Alpha_shape_vertex_base_2.h>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
|
||||
#include <CGAL/point_generators_2.h>
|
||||
|
||||
|
|
@ -250,6 +251,7 @@ MainWindow::on_actionLoadPoints_triggered()
|
|||
tr("Open Points file"),
|
||||
".",
|
||||
tr("CGAL files (*.pts.cgal);;"
|
||||
"WKT files (*.wktk *.WKT);;"
|
||||
"All files (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
open(fileName);
|
||||
|
|
@ -266,14 +268,19 @@ MainWindow::open(QString fileName)
|
|||
// wait cursor
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
std::ifstream ifs(qPrintable(fileName));
|
||||
|
||||
K::Point_2 p;
|
||||
while(ifs >> p) {
|
||||
points.push_back(p);
|
||||
if(fileName.endsWith(".wkt",Qt::CaseInsensitive))
|
||||
{
|
||||
CGAL::read_multi_point_WKT(ifs, points);
|
||||
}
|
||||
else
|
||||
{
|
||||
K::Point_2 p;
|
||||
while(ifs >> p) {
|
||||
points.push_back(p);
|
||||
}
|
||||
}
|
||||
as.make_alpha_shape(points.begin(), points.end());
|
||||
as.set_alpha(alpha);
|
||||
|
||||
// default cursor
|
||||
QApplication::restoreOverrideCursor();
|
||||
this->addToRecentFiles(fileName);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <CGAL/Apollonius_graph_hierarchy_2.h>
|
||||
#include <CGAL/Apollonius_graph_filtered_traits_2.h>
|
||||
#include <CGAL/point_generators_2.h>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
|
||||
#include <boost/random/linear_congruential.hpp>
|
||||
#include <boost/random/uniform_real.hpp>
|
||||
|
|
@ -216,6 +217,7 @@ MainWindow::on_actionLoadPoints_triggered()
|
|||
tr("Open Points file"),
|
||||
".",
|
||||
tr("CGAL files (*.wpts.cgal);;"
|
||||
"WKT files (*.wkt *.WKT);;"
|
||||
"All files (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
open(fileName);
|
||||
|
|
@ -231,10 +233,20 @@ MainWindow::open(QString fileName)
|
|||
if(! fileName.isEmpty()){
|
||||
std::ifstream ifs(qPrintable(fileName));
|
||||
|
||||
K::Weighted_point_2 p;
|
||||
std::vector<Apollonius_site_2> points;
|
||||
while(ifs >> p) {
|
||||
points.push_back(Apollonius_site_2(p.point(),p.weight()));
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
std::vector<K::Point_3> point_3_s;
|
||||
CGAL::read_multi_point_WKT(ifs, point_3_s);
|
||||
BOOST_FOREACH(const K::Point_3& point_3, point_3_s)
|
||||
{
|
||||
points.push_back(Apollonius_site_2(K::Point_2(point_3.x(), point_3.y()), point_3.z()));
|
||||
}
|
||||
} else{
|
||||
K::Weighted_point_2 p;
|
||||
while(ifs >> p) {
|
||||
points.push_back(Apollonius_site_2(p.point(),p.weight()));
|
||||
}
|
||||
}
|
||||
ag.insert(points.begin(), points.end());
|
||||
this->addToRecentFiles(fileName);
|
||||
|
|
@ -251,16 +263,32 @@ MainWindow::on_actionSavePoints_triggered()
|
|||
tr("Save points"),
|
||||
".reg.cgal",
|
||||
tr("Weighted Points (*.wpts.cgal);;"
|
||||
"WKT files(*.wkt *.WKT);;"
|
||||
"All (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
std::ofstream ofs(qPrintable(fileName));
|
||||
for(Apollonius::Sites_iterator
|
||||
vit = ag.sites_begin(),
|
||||
end = ag.sites_end();
|
||||
vit!= end; ++vit)
|
||||
if(fileName.endsWith(".wkt",Qt::CaseInsensitive))
|
||||
{
|
||||
ofs << vit->point()<<" "<<vit->weight()<<std::endl;
|
||||
std::vector<K::Point_3> points;
|
||||
for(Apollonius::Sites_iterator
|
||||
vit = ag.sites_begin(),
|
||||
end = ag.sites_end();
|
||||
vit!= end; ++vit)
|
||||
{
|
||||
points.push_back(K::Point_3(vit->point().x(),
|
||||
vit->point().y(),
|
||||
vit->weight()));
|
||||
}
|
||||
CGAL::write_multi_point_WKT(ofs, points);
|
||||
}
|
||||
else
|
||||
for(Apollonius::Sites_iterator
|
||||
vit = ag.sites_begin(),
|
||||
end = ag.sites_end();
|
||||
vit!= end; ++vit)
|
||||
{
|
||||
ofs << vit->point()<<" "<<vit->weight()<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include <CGAL/Polygon_2.h>
|
||||
#include <CGAL/min_quadrilateral_2.h>
|
||||
#include <CGAL/rectangular_p_center_2.h>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
|
||||
// Qt headers
|
||||
#include <QtGui>
|
||||
|
|
@ -474,6 +475,7 @@ MainWindow::on_actionLoadPoints_triggered()
|
|||
tr("Open Points file"),
|
||||
".",
|
||||
tr("CGAL files (*.pts.cgal);;"
|
||||
"WKT files (*.WKT *.wkt);;"
|
||||
"All files (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
open(fileName);
|
||||
|
|
@ -487,12 +489,23 @@ MainWindow::open(QString fileName)
|
|||
// wait cursor
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
std::ifstream ifs(qPrintable(fileName));
|
||||
|
||||
K::Point_2 p;
|
||||
while(ifs >> p) {
|
||||
mc.insert(p);
|
||||
me.insert(p);
|
||||
points.push_back(p);
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
CGAL::read_multi_point_WKT(ifs, points);
|
||||
BOOST_FOREACH(K::Point_2 p, points)
|
||||
{
|
||||
mc.insert(p);
|
||||
me.insert(p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
K::Point_2 p;
|
||||
while(ifs >> p) {
|
||||
mc.insert(p);
|
||||
me.insert(p);
|
||||
points.push_back(p);
|
||||
}
|
||||
}
|
||||
update_from_points();
|
||||
|
||||
|
|
@ -511,15 +524,29 @@ MainWindow::on_actionSavePoints_triggered()
|
|||
tr("Save points"),
|
||||
".",
|
||||
tr("CGAL files (*.pts.cgal);;"
|
||||
"WKT files (*.WKT *.wkt);;"
|
||||
"All files (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
std::ofstream ofs(qPrintable(fileName));
|
||||
for(Min_circle::Point_iterator
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
std::vector<K::Point_2> out_pts;
|
||||
out_pts.reserve(std::distance(mc.points_begin(),
|
||||
mc.points_end()));
|
||||
for(Min_circle::Point_iterator pit = mc.points_begin();
|
||||
pit != mc.points_end(); ++pit)
|
||||
out_pts.push_back(*pit);
|
||||
CGAL::write_multi_point_WKT(ofs, out_pts);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(Min_circle::Point_iterator
|
||||
vit = mc.points_begin(),
|
||||
end = mc.points_end();
|
||||
vit!= end; ++vit)
|
||||
{
|
||||
ofs << *vit << std::endl;
|
||||
vit!= end; ++vit)
|
||||
{
|
||||
ofs << *vit << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <CGAL/intersections.h>
|
||||
#include <CGAL/Circular_kernel_2.h>
|
||||
#include <CGAL/Object.h>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
|
||||
// Qt headers
|
||||
#include <QtGui>
|
||||
|
|
@ -211,7 +212,8 @@ MainWindow::on_actionLoadLineAndCircularArcs_triggered()
|
|||
QString fileName = QFileDialog::getOpenFileName(this,
|
||||
tr("Open Line and Circular Arc File"),
|
||||
".",
|
||||
tr("Edge files (*.arc)\n"));
|
||||
tr("Edge files (*.arc)\n"
|
||||
"WKT files (*.wkt *.WKT)\n"));
|
||||
if(! fileName.isEmpty()){
|
||||
open(fileName);
|
||||
this->addToRecentFiles(fileName);
|
||||
|
|
@ -223,46 +225,93 @@ void
|
|||
MainWindow::open(QString fileName)
|
||||
{
|
||||
std::ifstream ifs(qPrintable(fileName));
|
||||
|
||||
char c;
|
||||
double x,y;
|
||||
Segment_2 s;
|
||||
|
||||
while(ifs >> c){
|
||||
if(c == 's'){
|
||||
ifs >> x >> y;
|
||||
Point_2 p(x,y);
|
||||
ifs >> x >> y;
|
||||
Point_2 q(x,y);
|
||||
|
||||
Line_arc_2 la(Segment_2(p,q));
|
||||
for(std::vector<CGAL::Object>::iterator it = arcs.begin(); it != arcs.end(); ++it){
|
||||
Circular_arc_2 vca;
|
||||
Line_arc_2 vla;
|
||||
if(assign(vca, *it)){
|
||||
CGAL::intersection(la, vca, std::back_inserter(intersections));
|
||||
} else if(assign(vla, *it)){
|
||||
CGAL::intersection(la, vla, std::back_inserter(intersections));
|
||||
}
|
||||
}
|
||||
arcs.push_back(make_object(la));
|
||||
} else if(c == 'c'){
|
||||
ifs >> x >> y;
|
||||
Point_2 p(x,y);
|
||||
ifs >> x >> y;
|
||||
Point_2 q(x,y);
|
||||
ifs >> x >> y;
|
||||
Point_2 r(x,y);
|
||||
Circular_arc_2 ca(p,q,r);
|
||||
for(std::vector<CGAL::Object>::iterator it = arcs.begin(); it != arcs.end(); ++it){
|
||||
Circular_arc_2 vca;
|
||||
Line_arc_2 vla;
|
||||
if(assign(vca, *it)){
|
||||
CGAL::intersection(ca, vca, std::back_inserter(intersections));
|
||||
} else if(assign(vla, *it)){
|
||||
CGAL::intersection(ca, vla, std::back_inserter(intersections));
|
||||
}
|
||||
}
|
||||
arcs.push_back(make_object(ca));
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
//read pairs as Line_arc_2 and triplets as circular_arc_2
|
||||
do
|
||||
{
|
||||
std::vector<Point_2> multi_points;
|
||||
CGAL::read_multi_point_WKT(ifs, multi_points);
|
||||
if(multi_points.size() == 2)
|
||||
{
|
||||
Line_arc_2 la(Segment_2(multi_points[0],
|
||||
multi_points[1]));
|
||||
for(std::vector<CGAL::Object>::iterator it = arcs.begin(); it != arcs.end(); ++it){
|
||||
Circular_arc_2 vca;
|
||||
Line_arc_2 vla;
|
||||
if(assign(vca, *it)){
|
||||
CGAL::intersection(la, vca, std::back_inserter(intersections));
|
||||
} else if(assign(vla, *it)){
|
||||
CGAL::intersection(la, vla, std::back_inserter(intersections));
|
||||
}
|
||||
}
|
||||
arcs.push_back(make_object(la));
|
||||
}
|
||||
else if(multi_points.size() == 3)
|
||||
{
|
||||
Circular_arc_2 ca(multi_points[0],
|
||||
multi_points[1],
|
||||
multi_points[2]);
|
||||
for(std::vector<CGAL::Object>::iterator it = arcs.begin(); it != arcs.end(); ++it){
|
||||
Circular_arc_2 vca;
|
||||
Line_arc_2 vla;
|
||||
if(assign(vca, *it)){
|
||||
CGAL::intersection(ca, vca, std::back_inserter(intersections));
|
||||
} else if(assign(vla, *it)){
|
||||
CGAL::intersection(ca, vla, std::back_inserter(intersections));
|
||||
}
|
||||
}
|
||||
arcs.push_back(make_object(ca));
|
||||
}
|
||||
else if(multi_points.size()>0)
|
||||
{
|
||||
std::cerr<<"unreadable object."<<std::endl;
|
||||
}
|
||||
}while(ifs.good() && !ifs.eof());
|
||||
ifs.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
while(ifs >> c){
|
||||
if(c == 's'){
|
||||
ifs >> x >> y;
|
||||
Point_2 p(x,y);
|
||||
ifs >> x >> y;
|
||||
Point_2 q(x,y);
|
||||
|
||||
Line_arc_2 la(Segment_2(p,q));
|
||||
for(std::vector<CGAL::Object>::iterator it = arcs.begin(); it != arcs.end(); ++it){
|
||||
Circular_arc_2 vca;
|
||||
Line_arc_2 vla;
|
||||
if(assign(vca, *it)){
|
||||
CGAL::intersection(la, vca, std::back_inserter(intersections));
|
||||
} else if(assign(vla, *it)){
|
||||
CGAL::intersection(la, vla, std::back_inserter(intersections));
|
||||
}
|
||||
}
|
||||
arcs.push_back(make_object(la));
|
||||
} else if(c == 'c'){
|
||||
ifs >> x >> y;
|
||||
Point_2 p(x,y);
|
||||
ifs >> x >> y;
|
||||
Point_2 q(x,y);
|
||||
ifs >> x >> y;
|
||||
Point_2 r(x,y);
|
||||
Circular_arc_2 ca(p,q,r);
|
||||
for(std::vector<CGAL::Object>::iterator it = arcs.begin(); it != arcs.end(); ++it){
|
||||
Circular_arc_2 vca;
|
||||
Line_arc_2 vla;
|
||||
if(assign(vca, *it)){
|
||||
CGAL::intersection(ca, vca, std::back_inserter(intersections));
|
||||
} else if(assign(vla, *it)){
|
||||
CGAL::intersection(ca, vla, std::back_inserter(intersections));
|
||||
}
|
||||
}
|
||||
arcs.push_back(make_object(ca));
|
||||
}
|
||||
}
|
||||
}
|
||||
Q_EMIT( changed());
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include <QActionGroup>
|
||||
#include <QFileDialog>
|
||||
#include <QInputDialog>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
|
@ -279,6 +280,7 @@ MainWindow::on_actionLoadPoints_triggered()
|
|||
tr("Open Points file"),
|
||||
".",
|
||||
tr("CGAL files (*.pts.cgal);;"
|
||||
"WKT files (*.wkt *.WKT);;"
|
||||
"All files (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
open(fileName);
|
||||
|
|
@ -294,10 +296,16 @@ MainWindow::open(QString fileName)
|
|||
m_sites.clear();
|
||||
|
||||
std::ifstream ifs(qPrintable(fileName));
|
||||
|
||||
Kernel::Point_2 p;
|
||||
while(ifs >> p) {
|
||||
m_sites.push_back(p);
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
CGAL::read_multi_point_WKT(ifs, m_sites);
|
||||
}
|
||||
else
|
||||
{
|
||||
Kernel::Point_2 p;
|
||||
while(ifs >> p) {
|
||||
m_sites.push_back(p);
|
||||
}
|
||||
}
|
||||
calculate_envelope();
|
||||
|
||||
|
|
@ -315,11 +323,15 @@ MainWindow::on_actionSavePoints_triggered()
|
|||
tr("Save points"),
|
||||
".",
|
||||
tr("CGAL files (*.pts.cgal);;"
|
||||
"WKT files (*.wkt *.WKT);;"
|
||||
"All files (*)"));
|
||||
if(! fileName.isEmpty()) {
|
||||
std::ofstream ofs(qPrintable(fileName));
|
||||
for(Points::iterator it = m_sites.begin();
|
||||
it != m_sites.end(); ++it)
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
CGAL::write_multi_point_WKT(ofs, m_sites);
|
||||
else
|
||||
for(Points::iterator it = m_sites.begin();
|
||||
it != m_sites.end(); ++it)
|
||||
{
|
||||
ofs << *it << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <CGAL/Periodic_2_Delaunay_triangulation_2.h>
|
||||
#include <CGAL/Periodic_2_Delaunay_triangulation_traits_2.h>
|
||||
#include <CGAL/point_generators_2.h>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
|
||||
// Qt headers
|
||||
#include <QtGui>
|
||||
|
|
@ -350,6 +351,7 @@ MainWindow::on_actionLoadPoints_triggered()
|
|||
tr("Open Points file"),
|
||||
".",
|
||||
tr("CGAL files (*.pts.cgal);;"
|
||||
"WKT files (*.wkt *.WKT);;"
|
||||
"All files (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
open(fileName);
|
||||
|
|
@ -366,8 +368,15 @@ MainWindow::open(QString fileName)
|
|||
|
||||
Point_2 p;
|
||||
std::vector<Point_2> points;
|
||||
while(ifs >> p) {
|
||||
points.push_back(p);
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
CGAL::read_multi_point_WKT(ifs, points);
|
||||
}
|
||||
else
|
||||
{
|
||||
while(ifs >> p) {
|
||||
points.push_back(p);
|
||||
}
|
||||
}
|
||||
triang.clear();
|
||||
triang.insert(points.begin(), points.end());
|
||||
|
|
@ -387,15 +396,33 @@ MainWindow::on_actionSavePoints_triggered()
|
|||
tr("Save points"),
|
||||
".",
|
||||
tr("CGAL files (*.pts.cgal);;"
|
||||
"WKT files (*.wkt *.WKT);;"
|
||||
"All files (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
std::ofstream ofs(qPrintable(fileName));
|
||||
for(Periodic_DT::Unique_vertex_iterator
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
std::vector<Point_2> points;
|
||||
points.reserve(std::distance(triang.unique_vertices_begin(),
|
||||
triang.unique_vertices_end()));
|
||||
for(Periodic_DT::Unique_vertex_iterator
|
||||
vit = triang.unique_vertices_begin(),
|
||||
end = triang.unique_vertices_end();
|
||||
vit!= end; ++vit)
|
||||
vit!= end; ++vit)
|
||||
{
|
||||
points.push_back(vit->point());
|
||||
}
|
||||
CGAL::write_multi_point_WKT(ofs, points);
|
||||
}
|
||||
else
|
||||
{
|
||||
ofs << vit->point() << std::endl;
|
||||
for(Periodic_DT::Unique_vertex_iterator
|
||||
vit = triang.unique_vertices_begin(),
|
||||
end = triang.unique_vertices_end();
|
||||
vit!= end; ++vit)
|
||||
{
|
||||
ofs << vit->point() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <CGAL/linear_least_squares_fitting_2.h>
|
||||
#include <CGAL/extremal_polygon_2.h>
|
||||
#include <CGAL/minkowski_sum_2.h>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
|
||||
// Qt headers
|
||||
#include <QtGui>
|
||||
|
|
@ -229,6 +230,7 @@ MainWindow::on_actionLoadPolygon_triggered()
|
|||
".",
|
||||
tr( "Polyline files (*.polygon.cgal);;"
|
||||
"WSL files (*.wsl);;"
|
||||
"WKT files (*.wkt *.WKT);;"
|
||||
"All file (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
open(fileName);
|
||||
|
|
@ -241,7 +243,17 @@ MainWindow::open(QString fileName)
|
|||
this->actionCreateInputPolygon->setChecked(false);
|
||||
std::ifstream ifs(qPrintable(fileName));
|
||||
poly.clear();
|
||||
ifs >> poly;
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
CGAL::Polygon_with_holes_2<K> P;
|
||||
CGAL::read_polygon_WKT(ifs, P);
|
||||
poly = Polygon2(P.outer_boundary().begin(),
|
||||
P.outer_boundary().end());
|
||||
}
|
||||
else
|
||||
{
|
||||
ifs >> poly;
|
||||
}
|
||||
clear();
|
||||
|
||||
this->addToRecentFiles(fileName);
|
||||
|
|
@ -256,10 +268,19 @@ MainWindow::on_actionSavePolygon_triggered()
|
|||
tr("Save Polygon"),
|
||||
".",
|
||||
tr( "Polyline files (*.polygon.cgal);;"
|
||||
"WKT files (*.wkt *.WKT);;"
|
||||
"All file (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
std::ofstream ofs(qPrintable(fileName));
|
||||
ofs << poly;
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
CGAL::Polygon_2<K> P(poly.begin(),
|
||||
poly.end());
|
||||
CGAL::Polygon_with_holes_2<K> Pwh(P);
|
||||
CGAL::write_polygon_WKT(ofs, Pwh);
|
||||
}
|
||||
else
|
||||
ofs << poly;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include <CGAL/Qt/GraphicsViewPolylineInput.h>
|
||||
#include <CGAL/Qt/SegmentDelaunayGraphGraphicsItem.h>
|
||||
#include <CGAL/Constraints_loader.h>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
//#include <CGAL/Qt/Converter.h>
|
||||
|
||||
// the two base classes
|
||||
|
|
@ -100,6 +101,7 @@ public Q_SLOTS:
|
|||
void loadPolygonConstraints(QString);
|
||||
|
||||
void loadEdgConstraints(QString);
|
||||
void loadWKTConstraints(QString fileName);
|
||||
|
||||
Q_SIGNALS:
|
||||
void changed();
|
||||
|
|
@ -242,6 +244,9 @@ MainWindow::open(QString fileName)
|
|||
} else if(fileName.endsWith(".edg")){
|
||||
loadEdgConstraints(fileName);
|
||||
this->addToRecentFiles(fileName);
|
||||
} else if(fileName.endsWith(".wkt", Qt::CaseInsensitive)){
|
||||
loadWKTConstraints(fileName);
|
||||
this->addToRecentFiles(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -252,8 +257,9 @@ MainWindow::on_actionLoadSegments_triggered()
|
|||
QString fileName = QFileDialog::getOpenFileName(this,
|
||||
tr("Open Constraint File"),
|
||||
".",
|
||||
tr("Edge files (*.edg)\n"
|
||||
"Polyline files (*.polygon.cgal)"));
|
||||
tr("Edge files (*.edg);;"
|
||||
"Polyline files (*.polygon.cgal);;"
|
||||
"WKT files (*.wkt *.WKT)"));
|
||||
open(fileName);
|
||||
}
|
||||
|
||||
|
|
@ -326,6 +332,76 @@ MainWindow::loadEdgConstraints(QString fileName)
|
|||
actionRecenter->trigger();
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::loadWKTConstraints(QString fileName)
|
||||
{
|
||||
typedef CGAL::Polygon_with_holes_2<K> Polygon;
|
||||
typedef std::vector<K::Point_2> LineString;
|
||||
|
||||
//Multipolygon
|
||||
K::Point_2 p,q, first;
|
||||
SVD::Vertex_handle vp, vq, vfirst;
|
||||
std::ifstream ifs(qPrintable(fileName));
|
||||
do{
|
||||
std::vector<Polygon> polygons;
|
||||
CGAL::read_multi_polygon_WKT(ifs, polygons);
|
||||
BOOST_FOREACH(const Polygon& poly, polygons)
|
||||
{
|
||||
if(poly.outer_boundary().is_empty())
|
||||
continue;
|
||||
Polygon::General_polygon_2::const_iterator it
|
||||
=poly.outer_boundary().begin();
|
||||
first = *(it++);
|
||||
p = first;
|
||||
vfirst = vp = svd.insert(p);
|
||||
for(; it !=
|
||||
poly.outer_boundary().end();
|
||||
++it){
|
||||
q = *it;
|
||||
vq = svd.insert(q, vp);
|
||||
svd.insert(vp,vq);
|
||||
p = q;
|
||||
vp = vq;
|
||||
}
|
||||
if(vp != vfirst)
|
||||
svd.insert(vp, vfirst);
|
||||
}
|
||||
}while(ifs.good() && !ifs.eof());
|
||||
ifs.close();
|
||||
//MultiLineString
|
||||
ifs = std::ifstream(qPrintable(fileName));
|
||||
K::Point_2 qold(0,0); // Initialize qold, as otherwise some g++ issue a unjustified warning
|
||||
SVD::Vertex_handle vqold;
|
||||
do{
|
||||
std::vector<LineString > linestrings;
|
||||
CGAL::read_multi_linestring_WKT(ifs, linestrings);
|
||||
BOOST_FOREACH(const LineString& ls, linestrings)
|
||||
{
|
||||
bool first_pass=true;
|
||||
LineString::const_iterator it = ls.begin();
|
||||
for(; it!=ls.end(); ++it){
|
||||
p = *it++;
|
||||
q = *it;
|
||||
if(p == q){
|
||||
continue;
|
||||
}
|
||||
if((!first_pass) && (p == qold)){
|
||||
vp = vqold;
|
||||
} else {
|
||||
vp = svd.insert(p);
|
||||
}
|
||||
vq = svd.insert(q, vp);
|
||||
if(vp != vq)
|
||||
svd.insert(vp,vq);
|
||||
qold = q;
|
||||
vqold = vq;
|
||||
first_pass = false;
|
||||
}
|
||||
}
|
||||
}while(ifs.good() && !ifs.eof());
|
||||
Q_EMIT( changed());
|
||||
actionRecenter->trigger();
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::on_actionRecenter_triggered()
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include <CGAL/Qt/GraphicsViewPolylineInput.h>
|
||||
#include <CGAL/Qt/SegmentDelaunayGraphLinfGraphicsItem.h>
|
||||
#include <CGAL/Constraints_loader.h>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
//#include <CGAL/Qt/Converter.h>
|
||||
|
||||
// the two base classes
|
||||
|
|
@ -105,6 +106,8 @@ public Q_SLOTS:
|
|||
|
||||
void loadPoints(QString);
|
||||
|
||||
void loadWKT(QString);
|
||||
|
||||
void loadPointsInput(QString);
|
||||
|
||||
void loadSitesInput(QString);
|
||||
|
|
@ -265,7 +268,10 @@ MainWindow::open(QString fileName)
|
|||
} else if(fileName.endsWith(".cin")){
|
||||
loadSitesInput(fileName);
|
||||
this->addToRecentFiles(fileName);
|
||||
}
|
||||
} else if(fileName.endsWith(".wkt", Qt::CaseInsensitive)){
|
||||
loadWKT(fileName);
|
||||
this->addToRecentFiles(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -277,11 +283,12 @@ MainWindow::on_actionLoadSegments_triggered()
|
|||
tr("Open Constraint File"),
|
||||
".",
|
||||
tr(
|
||||
"Cin files (*.cin)\n"
|
||||
"Pin files (*.pin)\n"
|
||||
"Pts files (*.pts)\n"
|
||||
"Edge files (*.edg)\n"
|
||||
"Polylines files (*.polygon.cgal)"
|
||||
"Cin files (*.cin);;"
|
||||
"Pin files (*.pin);;"
|
||||
"Pts files (*.pts);;"
|
||||
"Edge files (*.edg);;"
|
||||
"Polylines files (*.polygon.cgal);;"
|
||||
"WKT files (*.WKT *.wkt)"
|
||||
));
|
||||
open(fileName);
|
||||
}
|
||||
|
|
@ -375,6 +382,95 @@ MainWindow::loadPoints(QString fileName)
|
|||
actionRecenter->trigger();
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::loadWKT(QString fileName)
|
||||
{
|
||||
std::ifstream ifs(qPrintable(fileName));
|
||||
//Points
|
||||
do
|
||||
{
|
||||
std::vector<K::Point_2> mpts;
|
||||
CGAL::read_multi_point_WKT(ifs, mpts);
|
||||
BOOST_FOREACH(const K::Point_2& p, mpts)
|
||||
svd.insert(p);
|
||||
}while(ifs.good() && !ifs.eof());
|
||||
//Lines
|
||||
ifs.close();
|
||||
ifs = std::ifstream(qPrintable(fileName));
|
||||
do
|
||||
{
|
||||
typedef std::vector<K::Point_2> LineString;
|
||||
std::vector<LineString> mls;
|
||||
CGAL::read_multi_linestring_WKT(ifs, mls);
|
||||
BOOST_FOREACH(const LineString& ls, mls)
|
||||
{
|
||||
if(ls.empty())
|
||||
continue;
|
||||
|
||||
bool first=true;
|
||||
K::Point_2 p,q, qold(0,0); // Initialize qold, as otherwise some g++ issue a unjustified warning
|
||||
|
||||
SVD::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 = svd.insert(p);
|
||||
}
|
||||
vq = svd.insert(q, vp);
|
||||
svd.insert(vp,vq);
|
||||
qold = q;
|
||||
vqold = vq;
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
}while(ifs.good() && !ifs.eof());
|
||||
|
||||
//Polygons
|
||||
ifs.close();
|
||||
ifs = std::ifstream(qPrintable(fileName));
|
||||
do
|
||||
{
|
||||
typedef CGAL::Polygon_with_holes_2<K> Polygon;
|
||||
std::vector<Polygon> mps;
|
||||
CGAL::read_multi_polygon_WKT(ifs, mps);
|
||||
BOOST_FOREACH(const Polygon& poly, mps)
|
||||
{
|
||||
if(poly.outer_boundary().is_empty())
|
||||
continue;
|
||||
K::Point_2 p,q, first;
|
||||
SVD::Vertex_handle vp, vq, vfirst;
|
||||
Polygon::General_polygon_2::const_iterator it
|
||||
= poly.outer_boundary().begin();
|
||||
|
||||
first = *it;
|
||||
p = first;
|
||||
vfirst = vp = svd.insert(p);
|
||||
for(; it != poly.outer_boundary().end(); ++it)
|
||||
{
|
||||
q = *it;
|
||||
vq = svd.insert(q, vp);
|
||||
if(vp != vq)
|
||||
svd.insert(vp,vq);
|
||||
p = q;
|
||||
vp = vq;
|
||||
}
|
||||
if (vfirst != vp) {
|
||||
svd.insert(vp, vfirst);
|
||||
}
|
||||
}
|
||||
}while(ifs.good() && !ifs.eof());
|
||||
|
||||
Q_EMIT( changed());
|
||||
actionRecenter->trigger();
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::loadPointsInput(QString fileName)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
#include <CGAL/Qt/SegmentsGraphicsItem.h>
|
||||
#include <CGAL/Qt/PolylinesGraphicsItem.h>
|
||||
#include <CGAL/Qt/GraphicsViewPolylineInput.h>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
|
||||
// for viewportsBbox
|
||||
#include <CGAL/Qt/utility.h>
|
||||
|
|
@ -247,6 +248,7 @@ MainWindow::on_actionLoadSegments_triggered()
|
|||
tr("Open segment file"),
|
||||
".",
|
||||
tr("Edge files (*.edg);;"
|
||||
"WKT files (*.wkt *.WKT);;"
|
||||
"All files (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
open(fileName);
|
||||
|
|
@ -260,10 +262,23 @@ MainWindow::open(QString fileName)
|
|||
// wait cursor
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
std::ifstream ifs(qPrintable(fileName));
|
||||
|
||||
std::copy(std::istream_iterator<Segment_2>(ifs),
|
||||
std::istream_iterator<Segment_2>(),
|
||||
std::back_inserter(input));
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
std::vector<std::vector<Point_2> > mls;
|
||||
CGAL::read_multi_linestring_WKT(ifs, mls);
|
||||
BOOST_FOREACH(const std::vector<Point_2>& ls, mls)
|
||||
{
|
||||
if(ls.size() > 2)
|
||||
continue;
|
||||
Segment_2 seg(ls[0], ls[1]);
|
||||
input.push_back(seg);
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::copy(std::istream_iterator<Segment_2>(ifs),
|
||||
std::istream_iterator<Segment_2>(),
|
||||
std::back_inserter(input));
|
||||
}
|
||||
output.clear();
|
||||
CGAL::snap_rounding_2<Traits,std::list<Segment_2>::const_iterator,std::list<std::list<Point_2> > >(input.begin(), input.end(), output, delta, true, false);
|
||||
ifs.close();
|
||||
|
|
@ -281,11 +296,25 @@ MainWindow::on_actionSaveSegments_triggered()
|
|||
tr("Save points"),
|
||||
".",
|
||||
tr("Edge files (*.edg);;"
|
||||
"WKT files (*.wkt *.WKT);;"
|
||||
"All files (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
std::ofstream ofs(qPrintable(fileName));
|
||||
ofs.precision(12);
|
||||
std::copy(input.begin(), input.end(), std::ostream_iterator<Segment_2>(ofs, "\n"));
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
std::vector<std::vector<Point_2> >mls;
|
||||
BOOST_FOREACH(const Segment_2& seg, input)
|
||||
{
|
||||
std::vector<Point_2> ls(2);
|
||||
ls[0] = seg.source();
|
||||
ls[1] = seg.target();
|
||||
mls.push_back(ls);
|
||||
}
|
||||
CGAL::write_multi_linestring_WKT(ofs, mls);
|
||||
}
|
||||
else
|
||||
std::copy(input.begin(), input.end(), std::ostream_iterator<Segment_2>(ofs, "\n"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
// GraphicsView items and event filters (input classes)
|
||||
#include <CGAL/Qt/PointsInKdTreeGraphicsItem.h>
|
||||
#include <CGAL/Qt/utility.h>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
|
||||
// the two base classes
|
||||
#include "ui_Spatial_searching_2.h"
|
||||
|
|
@ -244,6 +245,7 @@ MainWindow::on_actionLoadPoints_triggered()
|
|||
tr("Open Points file"),
|
||||
".",
|
||||
tr("CGAL files (*.pts.cgal);;"
|
||||
"WKT files (*.wkt *.WKT);;"
|
||||
"All files (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
open(fileName);
|
||||
|
|
@ -261,8 +263,14 @@ MainWindow::open(QString fileName)
|
|||
|
||||
K::Point_2 p;
|
||||
std::vector<K::Point_2> points;
|
||||
while(ifs >> p) {
|
||||
points.push_back(p);
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
CGAL::read_multi_point_WKT(ifs, points);
|
||||
}
|
||||
else{
|
||||
while(ifs >> p) {
|
||||
points.push_back(p);
|
||||
}
|
||||
}
|
||||
tree.insert(points.begin(), points.end());
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
// for viewportsBbox
|
||||
#include <CGAL/Qt/utility.h>
|
||||
|
||||
#include <CGAL/IO/WKT.h>
|
||||
// the two base classes
|
||||
#include "ui_Stream_lines_2.h"
|
||||
#include <CGAL/Qt/DemosMainWindow.h>
|
||||
|
|
@ -166,7 +166,8 @@ MainWindow::on_actionLoadPoints_triggered()
|
|||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this,
|
||||
tr("Open grid file"),
|
||||
".");
|
||||
".",
|
||||
tr("WKT files (*.wkt *.WKT)"));
|
||||
if(! fileName.isEmpty()){
|
||||
open(fileName);
|
||||
}
|
||||
|
|
@ -179,23 +180,49 @@ MainWindow::open(QString fileName)
|
|||
// wait cursor
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
std::ifstream ifs(qPrintable(fileName));
|
||||
|
||||
|
||||
runge_kutta_integrator = new Runge_kutta_integrator(integrating);
|
||||
double iXSize, iYSize;
|
||||
iXSize = iYSize = 512;
|
||||
unsigned int x_samples, y_samples;
|
||||
ifs >> x_samples;
|
||||
ifs >> y_samples;
|
||||
regular_grid = new Regular_grid(x_samples, y_samples, iXSize, iYSize);
|
||||
/*fill the grid with the appropriate values*/
|
||||
for (unsigned int i=0;i<x_samples;i++)
|
||||
for (unsigned int j=0;j<y_samples;j++)
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
std::vector<std::vector<Point_2> > mp;
|
||||
int size= -1;
|
||||
do
|
||||
{
|
||||
std::vector<Point_2> ps;
|
||||
CGAL::read_multi_point_WKT(ifs, ps);
|
||||
if(size == -1)
|
||||
size = static_cast<int>(ps.size());
|
||||
else if(ps.size() > 0 && size != static_cast<int>(ps.size()))
|
||||
ps.resize(size);
|
||||
else if(ps.size() == 0)
|
||||
continue;
|
||||
mp.push_back(ps);
|
||||
}while(ifs.good() && !ifs.eof());
|
||||
regular_grid = new Regular_grid(size, static_cast<int>(mp.size()), iXSize, iYSize);
|
||||
/*fill the grid with the appropriate values*/
|
||||
for (unsigned int i=0;i<static_cast<unsigned int>(size);++i)
|
||||
for (unsigned int j=0;j<mp.size();++j)
|
||||
{
|
||||
regular_grid->set_field(i, j, Vector(mp[j][i].x(), mp[j][i].y()));
|
||||
}
|
||||
}
|
||||
else{
|
||||
unsigned int x_samples, y_samples;
|
||||
ifs >> x_samples;
|
||||
ifs >> y_samples;
|
||||
regular_grid = new Regular_grid(x_samples, y_samples, iXSize, iYSize);
|
||||
/*fill the grid with the appropriate values*/
|
||||
for (unsigned int i=0;i<x_samples;i++)
|
||||
for (unsigned int j=0;j<y_samples;j++)
|
||||
{
|
||||
double xval, yval;
|
||||
ifs >> xval;
|
||||
ifs >> yval;
|
||||
regular_grid->set_field(i, j, Vector(xval, yval));
|
||||
}
|
||||
}
|
||||
ifs.close();
|
||||
// default cursor
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
|
@ -208,15 +235,29 @@ MainWindow::open(QString fileName)
|
|||
void
|
||||
MainWindow::on_actionSavePoints_triggered()
|
||||
{
|
||||
/*
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(this,
|
||||
tr("Save points"),
|
||||
".");
|
||||
".",
|
||||
tr("WKT files (*.wkt *.WKT)"));
|
||||
if(! fileName.isEmpty()){
|
||||
std::ofstream ofs(qPrintable(fileName));
|
||||
|
||||
|
||||
std::vector<std::vector<Point_2> >mp;
|
||||
mp.resize(regular_grid->get_dimension().second);
|
||||
for (unsigned int i=0;i<static_cast<unsigned int>(regular_grid->get_dimension().first);++i)
|
||||
{
|
||||
mp[i].reserve(regular_grid->get_dimension().second);
|
||||
for (unsigned int j=0;j<regular_grid->get_dimension().second;++j)
|
||||
{
|
||||
mp[i].push_back(Point_2(regular_grid->get_field(j,i).x(),
|
||||
regular_grid->get_field(j,i).y()));
|
||||
}
|
||||
CGAL::write_multi_point_WKT(ofs, mp[i]);
|
||||
}
|
||||
ofs.close();
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -516,7 +516,7 @@ MainWindow::open(QString fileName)
|
|||
}
|
||||
if(fileName.endsWith(".polygon.cgal")){
|
||||
loadPolygonConstraints(fileName);
|
||||
} else if(fileName.endsWith(".cgal")){
|
||||
} else if(fileName.endsWith(".cpts.cgal")){
|
||||
loadFile(fileName);
|
||||
} else if(fileName.endsWith(".edg")){
|
||||
loadEdgConstraints(fileName);
|
||||
|
|
@ -541,7 +541,7 @@ MainWindow::on_actionLoadConstraints_triggered()
|
|||
"Polyline files (*.polygon.cgal);;"
|
||||
"Poly files (*.poly);;"
|
||||
"CGAL files (*.cpts.cgal);;"
|
||||
"WKT files (*.wkt);;"
|
||||
"WKT files (*.WKT *.wkt);;"
|
||||
"All (*)"));
|
||||
open(fileName);
|
||||
}
|
||||
|
|
@ -549,20 +549,24 @@ MainWindow::on_actionLoadConstraints_triggered()
|
|||
void
|
||||
MainWindow::loadWKT(QString filename)
|
||||
{
|
||||
typedef CGAL::Polygon_with_holes_2<K> Polygon;
|
||||
typedef CGAL::Point_2<K> Point;
|
||||
//Polygons todo : make it multipolygons
|
||||
std::ifstream ifs(qPrintable(filename));
|
||||
do
|
||||
{
|
||||
Polygon p;
|
||||
CGAL::read_polygon_WKT(ifs, p);
|
||||
if(!p.outer_boundary().is_empty())
|
||||
typedef CGAL::Polygon_with_holes_2<K> Polygon;
|
||||
typedef CGAL::Point_2<K> Point;
|
||||
std::vector<Polygon> mps;
|
||||
CGAL::read_multi_polygon_WKT(ifs, mps);
|
||||
BOOST_FOREACH(const Polygon& p, mps)
|
||||
{
|
||||
if(p.outer_boundary().is_empty())
|
||||
continue;
|
||||
|
||||
BOOST_FOREACH(Point point, p.outer_boundary().container())
|
||||
cdt.insert(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());
|
||||
cdt.insert_constraint(e_it->source(), e_it->target());
|
||||
|
||||
for(Polygon::Hole_const_iterator h_it =
|
||||
p.holes_begin(); h_it != p.holes_end(); ++h_it)
|
||||
|
|
@ -572,12 +576,60 @@ MainWindow::loadWKT(QString filename)
|
|||
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());
|
||||
cdt.insert_constraint(e_it->source(), e_it->target());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}while(ifs.good() && !ifs.eof());
|
||||
//Edges
|
||||
ifs.close();
|
||||
ifs = std::ifstream(qPrintable(filename));
|
||||
do
|
||||
{
|
||||
typedef std::vector<K::Point_2> LineString;
|
||||
std::vector<LineString> mls;
|
||||
CGAL::read_multi_linestring_WKT(ifs, mls);
|
||||
BOOST_FOREACH(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
|
||||
ifs.close();
|
||||
ifs = std::ifstream(qPrintable(filename));
|
||||
do
|
||||
{
|
||||
std::vector<K::Point_2> mpts;
|
||||
CGAL::read_multi_point_WKT(ifs, mpts);
|
||||
BOOST_FOREACH(const K::Point_2& p, mpts)
|
||||
{
|
||||
cdt.insert(p);
|
||||
}
|
||||
}while(ifs.good() && !ifs.eof());
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#include "TriangulationPointInputAndConflictZone.h"
|
||||
#include <CGAL/Qt/TriangulationGraphicsItem.h>
|
||||
#include <CGAL/Qt/VoronoiGraphicsItem.h>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
|
||||
// for viewportsBbox
|
||||
#include <CGAL/Qt/utility.h>
|
||||
|
|
@ -317,6 +318,7 @@ MainWindow::on_actionLoadPoints_triggered()
|
|||
tr("Open Points file"),
|
||||
".",
|
||||
tr("CGAL files (*.pts.cgal);;"
|
||||
"WKT files (*.WKT *.wkt);;"
|
||||
"All files (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
open(fileName);
|
||||
|
|
@ -333,11 +335,16 @@ MainWindow::open(QString fileName)
|
|||
|
||||
K::Point_2 p;
|
||||
std::vector<K::Point_2> points;
|
||||
while(ifs >> p) {
|
||||
// ignore whatever comes after x and y
|
||||
ifs.ignore((std::numeric_limits<std::streamsize>::max)(), '\n');
|
||||
points.push_back(p);
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
CGAL::read_multi_point_WKT(ifs, points);
|
||||
}
|
||||
else
|
||||
while(ifs >> p) {
|
||||
// ignore whatever comes after x and y
|
||||
ifs.ignore((std::numeric_limits<std::streamsize>::max)(), '\n');
|
||||
points.push_back(p);
|
||||
}
|
||||
dt.insert(points.begin(), points.end());
|
||||
|
||||
// default cursor
|
||||
|
|
@ -355,16 +362,31 @@ MainWindow::on_actionSavePoints_triggered()
|
|||
tr("Save points"),
|
||||
".",
|
||||
tr("CGAL files (*.pts.cgal);;"
|
||||
"WKT files (*.WKT *.wkt);;"
|
||||
"All files (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
std::ofstream ofs(qPrintable(fileName));
|
||||
for(Delaunay::Finite_vertices_iterator
|
||||
if(fileName.endsWith(".wkt", Qt::CaseInsensitive))
|
||||
{
|
||||
std::vector<K::Point_2> points;
|
||||
points.reserve(dt.number_of_vertices());
|
||||
for(Delaunay::Finite_vertices_iterator
|
||||
vit = dt.finite_vertices_begin(),
|
||||
end = dt.finite_vertices_end();
|
||||
vit!= end; ++vit)
|
||||
{
|
||||
ofs << vit->point() << std::endl;
|
||||
vit!= end; ++vit)
|
||||
{
|
||||
points.push_back(vit->point());
|
||||
}
|
||||
CGAL::write_multi_point_WKT(ofs, points);
|
||||
}
|
||||
else
|
||||
for(Delaunay::Finite_vertices_iterator
|
||||
vit = dt.finite_vertices_begin(),
|
||||
end = dt.finite_vertices_end();
|
||||
vit!= end; ++vit)
|
||||
{
|
||||
ofs << vit->point() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
// CGAL headers
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Regular_triangulation_2.h>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
|
||||
#include <CGAL/point_generators_2.h>
|
||||
|
||||
// Qt headers
|
||||
#include <QtGui>
|
||||
#include <QString>
|
||||
|
|
@ -243,15 +243,27 @@ MainWindow::on_actionLoadPoints_triggered()
|
|||
tr("Open Points file"),
|
||||
".",
|
||||
tr("Weighted Points (*.wpts.cgal);;"
|
||||
"WKT files (*.wkt *.WKT);;"
|
||||
"All (*)"));
|
||||
|
||||
if(! fileName.isEmpty()){
|
||||
std::ifstream ifs(qPrintable(fileName));
|
||||
|
||||
Weighted_point_2 p;
|
||||
std::vector<Weighted_point_2> points;
|
||||
while(ifs >> p) {
|
||||
points.push_back(p);
|
||||
if(fileName.endsWith(".wkt",Qt::CaseInsensitive))
|
||||
{
|
||||
std::vector<K::Point_3> points_3;
|
||||
CGAL::read_multi_point_WKT(ifs, points_3);
|
||||
BOOST_FOREACH(const K::Point_3& p, points_3)
|
||||
{
|
||||
points.push_back(Weighted_point_2(K::Point_2(p.x(), p.y()), p.z()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Weighted_point_2 p;
|
||||
while(ifs >> p) {
|
||||
points.push_back(p);
|
||||
}
|
||||
}
|
||||
dt.insert(points.begin(), points.end());
|
||||
|
||||
|
|
@ -268,15 +280,33 @@ MainWindow::on_actionSavePoints_triggered()
|
|||
tr("Save points"),
|
||||
".reg.cgal",
|
||||
tr("Weighted Points (*.wpts.cgal);;"
|
||||
"WKT files (*.wkt *.WKT);;"
|
||||
"All (*)"));
|
||||
if(! fileName.isEmpty()){
|
||||
std::ofstream ofs(qPrintable(fileName));
|
||||
for(Regular::Finite_vertices_iterator
|
||||
if(fileName.endsWith(".wkt",Qt::CaseInsensitive))
|
||||
{
|
||||
std::vector<K::Point_3> points_3;
|
||||
for(Regular::Finite_vertices_iterator
|
||||
vit = dt.finite_vertices_begin(),
|
||||
end = dt.finite_vertices_end();
|
||||
vit!= end; ++vit)
|
||||
vit!= end; ++vit)
|
||||
{
|
||||
points_3.push_back(K::Point_3(vit->point().x(),
|
||||
vit->point().y(),
|
||||
vit->point().weight()));
|
||||
}
|
||||
CGAL::write_multi_point_WKT(ofs, points_3);
|
||||
}
|
||||
else
|
||||
{
|
||||
ofs << vit->point() << std::endl;
|
||||
for(Regular::Finite_vertices_iterator
|
||||
vit = dt.finite_vertices_begin(),
|
||||
end = dt.finite_vertices_end();
|
||||
vit!= end; ++vit)
|
||||
{
|
||||
ofs << vit->point() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ int main(int argc, char* argv[])
|
|||
LineString ls;
|
||||
{
|
||||
std::ifstream is((argc>1)?argv[1]:"data/linestring.wkt");
|
||||
//std::vector<Point> ls;
|
||||
CGAL::read_linestring_WKT(is, ls);
|
||||
is.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,4 +28,5 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
std::cout<<p<<std::endl;
|
||||
}
|
||||
is.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,10 +28,12 @@
|
|||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <CGAL/Point_2.h>
|
||||
#include <CGAL/Point_3.h>
|
||||
#include <CGAL/Polygon_2.h>
|
||||
#include <CGAL/Polygon_with_holes_2.h>
|
||||
|
||||
#include <CGAL/IO/traits_point.h>
|
||||
#include <CGAL/IO/traits_point_3.h>
|
||||
#include <CGAL/IO/traits_linestring.h>
|
||||
#include <CGAL/IO/traits_polygon.h>
|
||||
#include <CGAL/IO/traits_multipoint.h>
|
||||
|
|
@ -44,9 +46,9 @@ namespace CGAL{
|
|||
//! \ingroup PkgIOstreams
|
||||
//! \brief read_point_WKT reads the content of a .wkt file into a `Point` if possible.
|
||||
//!
|
||||
//! A `Point` must inherit `CGAL::Point_2`.
|
||||
//! A `Point` must inherit `CGAL::Point_2` or `CGAL::Point_3`.
|
||||
//!
|
||||
//! \see CGAL::Point_2
|
||||
//! \see CGAL::Point_2 \see CGAL::Point_3
|
||||
template<typename Point>
|
||||
std::istream&
|
||||
read_point_WKT( std::istream& in,
|
||||
|
|
@ -77,9 +79,10 @@ read_point_WKT( std::istream& in,
|
|||
//! \ingroup PkgIOstreams
|
||||
//! \brief read_multipoint_WKT reads the content of a .wkt file into a `MultiPoint` if possible.
|
||||
//!
|
||||
//! A `MultiPoint` must be a model of `RandomAccessRange` of `CGAL::Point_2`.
|
||||
//! A `MultiPoint` must be a model of `RandomAccessRange` of `CGAL::Point_2` or `CGAL::Point_3`.
|
||||
//!
|
||||
//! \see CGAL::Point_2
|
||||
//! \see CGAL::Point_2
|
||||
//! \see CGAL::Point_3
|
||||
template<typename MultiPoint>
|
||||
std::istream&
|
||||
read_multi_point_WKT( std::istream& in,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,88 @@
|
|||
// Copyright (c) 2018 GeometryFactory Sarl (France).
|
||||
// All rights reserved.
|
||||
//
|
||||
// Licensees holding a valid commercial license may use this file in
|
||||
// accordance with the commercial license agreement provided with the software.
|
||||
//
|
||||
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of the License,
|
||||
// or (at your option) any later version.
|
||||
//
|
||||
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// $URL$
|
||||
// $Id$
|
||||
// SPDX-License-Identifier: LGPL-3.0+
|
||||
//
|
||||
// Author(s) : Maxime Gimeno
|
||||
|
||||
#ifndef CGAL_TRAITS_POINT_3_H
|
||||
#define CGAL_TRAITS_POINT_3_H
|
||||
|
||||
#include <CGAL/number_utils.h>
|
||||
#include <CGAL/Point_3.h>
|
||||
#include <boost/geometry/geometry.hpp>
|
||||
namespace boost{
|
||||
namespace geometry{
|
||||
namespace traits{
|
||||
|
||||
//WKT traits for Points
|
||||
template< typename K > struct tag<CGAL::Point_3<K> >
|
||||
{ typedef point_tag type; };
|
||||
|
||||
template< typename K > struct coordinate_type<CGAL::Point_3<K> >
|
||||
{ typedef typename K::FT type; };
|
||||
|
||||
template< typename K > struct coordinate_system<CGAL::Point_3<K> >
|
||||
{ typedef cs::cartesian type; };
|
||||
|
||||
template< typename K > struct dimension<CGAL::Point_3<K> > : boost::mpl::int_<3> {};
|
||||
|
||||
template< typename K >
|
||||
struct access<CGAL::Point_3<K> , 0>
|
||||
{
|
||||
static double get(CGAL::Point_3<K> const& p)
|
||||
{
|
||||
return CGAL::to_double(p.x());
|
||||
}
|
||||
|
||||
static void set(CGAL::Point_3<K> & p, typename K::FT c)
|
||||
{
|
||||
p = CGAL::Point_3<K> (c, p.y(), p.z());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template< typename K >
|
||||
struct access<CGAL::Point_3<K> , 1>
|
||||
{
|
||||
static double get(CGAL::Point_3<K> const& p)
|
||||
{
|
||||
return CGAL::to_double(p.y());
|
||||
}
|
||||
|
||||
static void set(CGAL::Point_3<K> & p, typename K::FT c)
|
||||
{
|
||||
p = CGAL::Point_3<K> (p.x(), c, p.z());
|
||||
}
|
||||
|
||||
};
|
||||
template< typename K >
|
||||
struct access<CGAL::Point_3<K> , 2>
|
||||
{
|
||||
static double get(CGAL::Point_3<K> const& p)
|
||||
{
|
||||
return CGAL::to_double(p.z());
|
||||
}
|
||||
|
||||
static void set(CGAL::Point_3<K> & p, typename K::FT c)
|
||||
{
|
||||
p = CGAL::Point_3<K> (p.x(), p.y(), c);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}}}//end namespaces
|
||||
#endif
|
||||
Loading…
Reference in New Issue