mirror of https://github.com/CGAL/cgal
Defining the IO operators for polyline curves inside the main module.
This commit is contained in:
parent
893a2a9c5a
commit
f712bca76c
|
|
@ -16,7 +16,6 @@
|
|||
#include <CGAL/Arr_polyline_traits.h>
|
||||
|
||||
#include <CGAL/IO/Pm_iostream.h>
|
||||
#include <CGAL/IO/Arr_polyline_traits_iostream.h>
|
||||
|
||||
|
||||
//uncomment if you have LEDA installed.
|
||||
|
|
@ -28,7 +27,7 @@
|
|||
//#endif
|
||||
//#include <CGAL/IO/leda_window.h> //used for visualization.
|
||||
|
||||
using namespace std;
|
||||
//using namespace std;
|
||||
|
||||
typedef CGAL::Quotient<int> NT;
|
||||
typedef CGAL::Cartesian<NT> R;
|
||||
|
|
@ -40,6 +39,46 @@ typedef Traits::Curve Curve;
|
|||
|
||||
typedef CGAL::Pm_default_dcel<Traits> Dcel;
|
||||
typedef CGAL::Planar_map_2<Dcel, Traits> PM;
|
||||
typedef CGAL::Pm_file_writer<PM> Pm_writer;
|
||||
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
std::ostream& operator<<(std::ostream& os,
|
||||
const Curve& cv)
|
||||
{
|
||||
typedef Curve::const_iterator Points_iterator;
|
||||
|
||||
os<<cv.size()<<std::endl;
|
||||
for (Points_iterator points_iter = cv.begin();
|
||||
points_iter != cv.end(); points_iter++)
|
||||
os<<" "<<*points_iter;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
std::istream& operator>>(std::istream& in,
|
||||
Curve& cv)
|
||||
{
|
||||
typedef Curve::value_type Point;
|
||||
|
||||
std::size_t size;
|
||||
|
||||
in >> size;
|
||||
|
||||
for (unsigned int i = 0; i < size; i++){
|
||||
Point p;
|
||||
|
||||
in >> p;
|
||||
|
||||
cv.push_back(p);
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
template <class Container>
|
||||
void read_polylines(Container& curves)
|
||||
|
|
@ -52,33 +91,27 @@ void read_polylines(Container& curves)
|
|||
|
||||
while (num_polylines--) {
|
||||
Curve polyline;
|
||||
int num_points;
|
||||
|
||||
std::cin >> num_points;
|
||||
|
||||
while (num_points--) {
|
||||
std::cin >> x >> y;
|
||||
Point s(x, y);
|
||||
|
||||
polyline.push_back(s);
|
||||
}
|
||||
|
||||
std::cin>>polyline;
|
||||
curves.push_back(polyline);
|
||||
|
||||
polyline.clear();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(/*int argc, char* argv[]*/)
|
||||
{
|
||||
PM pm;
|
||||
vector<Curve> polylines;
|
||||
std::vector<Curve> polylines;
|
||||
|
||||
read_polylines(polylines);
|
||||
|
||||
CGAL::sweep_to_construct_planar_map(polylines.begin(),polylines.end(), pm);
|
||||
|
||||
std::cout << pm;
|
||||
std::cout << " * * * Printing list of all halfedges of the resulting Planar map" << endl;
|
||||
|
||||
Pm_writer verbose_writer(cout, pm, true);
|
||||
|
||||
verbose_writer.write_halfedges(pm.halfedges_begin(), pm.halfedges_end());
|
||||
|
||||
|
||||
//CGAL::Window_stream W(700, 700);
|
||||
//W.init(-10, 10, -10);
|
||||
|
|
|
|||
|
|
@ -14,11 +14,9 @@
|
|||
#include <CGAL/sweep_to_produce_planar_map_subcurves.h>
|
||||
|
||||
#include <CGAL/Arr_polyline_traits.h>
|
||||
#include <CGAL/IO/Arr_polyline_traits_iostream.h>
|
||||
//#include <CGAL/IO/Arr_polyline_traits_iostream.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef CGAL::Quotient<int> NT;
|
||||
typedef CGAL::Cartesian<NT> R;
|
||||
typedef CGAL::Arr_polyline_traits<R> Traits;
|
||||
|
|
@ -29,6 +27,46 @@ typedef Traits::Curve Curve;
|
|||
|
||||
using namespace std;
|
||||
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
std::ostream& operator<<(std::ostream& os,
|
||||
const Curve& cv)
|
||||
{
|
||||
typedef Curve::const_iterator Points_iterator;
|
||||
|
||||
os<<cv.size()<<std::endl;
|
||||
for (Points_iterator points_iter = cv.begin();
|
||||
points_iter != cv.end(); points_iter++)
|
||||
os<<" "<<*points_iter;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
std::istream& operator>>(std::istream& in,
|
||||
Curve& cv)
|
||||
{
|
||||
typedef Curve::value_type Point;
|
||||
|
||||
std::size_t size;
|
||||
|
||||
in >> size;
|
||||
|
||||
for (unsigned int i = 0; i < size; i++){
|
||||
Point p;
|
||||
|
||||
in >> p;
|
||||
|
||||
cv.push_back(p);
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
|
||||
template <class Container>
|
||||
void read_polylines(Container& curves)
|
||||
{
|
||||
|
|
@ -40,16 +78,19 @@ void read_polylines(Container& curves)
|
|||
|
||||
while (num_polylines--) {
|
||||
Curve polyline;
|
||||
int num_points;
|
||||
|
||||
cin >> num_points;
|
||||
|
||||
while (num_points--) {
|
||||
cin >> x >> y;
|
||||
Point s(x, y);
|
||||
|
||||
polyline.push_back(s);
|
||||
}
|
||||
/* int num_points;
|
||||
|
||||
cin >> num_points;
|
||||
|
||||
while (num_points--) {
|
||||
cin >> x >> y;
|
||||
Point s(x, y);
|
||||
|
||||
polyline.push_back(s);
|
||||
}*/
|
||||
|
||||
std::cin>>polyline;
|
||||
|
||||
curves.push_back(polyline);
|
||||
|
||||
|
|
@ -57,7 +98,7 @@ void read_polylines(Container& curves)
|
|||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(/*int argc, char* argv[]*/)
|
||||
{
|
||||
list<Curve> polylines;
|
||||
|
||||
|
|
@ -67,10 +108,9 @@ int main(int argc, char* argv[])
|
|||
list<Curve> subcurves;
|
||||
CGAL::sweep_to_produce_planar_map_subcurves(polylines.begin(),polylines.end(), traits, subcurves);
|
||||
|
||||
for (list<Curve>::iterator scv_iter = subcurves.begin(); scv_iter != subcurves.end(); scv_iter++)
|
||||
for (list<Curve>::iterator scv_iter = subcurves.begin(); scv_iter != subcurves.end(); scv_iter++)
|
||||
cout<<*scv_iter<<endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue