diff --git a/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Point_d.h b/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Point_d.h index d6e77a2f422..a4013b983d3 100644 --- a/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Point_d.h +++ b/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Point_d.h @@ -22,6 +22,8 @@ #define CGAL_WRAPPER_POINT_D_H #include +#include +#include #include #include #include @@ -247,8 +249,6 @@ public: template Point_d::Point_d(Point_d &)=default; #endif -//TODO: IO - template std::ostream& operator <<(std::ostream& os, const Point_d& p) { @@ -259,14 +259,57 @@ std::ostream& operator <<(std::ostream& os, const Point_d& p) CPI(typename Point_d::Rep,Begin_tag) >::type>::type b = p.cartesian_begin(), - e = p.cartesian_end(); - os << p.dimension(); - for(; b != e; ++b){ - os << " " << *b; + e = p.cartesian_end(); + if(is_ascii(os)) + { + os << p.dimension(); + for(; b != e; ++b){ + os << " " << *b; + } + } + else + { + write(os, p.dimension()); + for(; b != e; ++b){ + write(os, *b); + } } return os; } +// TODO: test if the stream is binary or text? +template +std::istream & +operator>>(std::istream &is, Point_d & p) +{ + typedef typename Get_type::type P; + typedef typename Get_type::type FT; + int dim; + if( is_ascii(is) ) + is >> dim; + else + { + read(is, dim); + } + + if(!is) return is; + std::vector coords(dim); + if(is_ascii(is)) + { + for(int i=0;i> iformat(coords[i]); + } + else + { + for(int i=0;i //Vector_d operator+(const Vector_d& v,const Vector_d& w) const //{ diff --git a/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Vector_d.h b/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Vector_d.h index 63af4e63976..c85a252891e 100644 --- a/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Vector_d.h +++ b/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Vector_d.h @@ -21,6 +21,9 @@ #ifndef CGAL_WRAPPER_VECTOR_D_H #define CGAL_WRAPPER_VECTOR_D_H +#include +#include +#include #include #include #include @@ -239,6 +242,11 @@ public: return rep.dimension(); } */ + int dimension() const { + typedef typename Get_functor::type VDBase; + return VDBase()(rep()); + } + typename boost::result_of::type squared_length()const{ return SLBase()(rep()); } @@ -247,7 +255,68 @@ public: template Vector_d::Vector_d(Vector_d &)=default; #endif -//TODO: IO +template +std::ostream& operator <<(std::ostream& os, const Vector_d& v) +{ + typedef typename R_::Kernel_base Kbase; + typedef typename Get_functor >::type CVI; + // Should just be "auto"... + typename CGAL::decay::Rep,Begin_tag) + >::type>::type + b = v.cartesian_begin(), + e = v.cartesian_end(); + if(is_ascii(os)) + { + os << v.dimension(); + for(; b != e; ++b){ + os << " " << *b; + } + } + else + { + write(os, v.dimension()); + for(; b != e; ++b){ + write(os, *b); + } + } + + return os; +} + + +template +std::istream & +operator>>(std::istream &is, Vector_d & v) +{ + typedef typename Get_type::type V; + typedef typename Get_type::type FT; + int dim; + if( is_ascii(is) ) + is >> dim; + else + { + read(is, dim); + } + if(!is) return is; + + std::vector coords(dim); + if(is_ascii(is)) + { + for(int i=0;i> iformat(coords[i]); + } + else + { + for(int i=0;i Vector_d operator+(const Vector_d& v,const Vector_d& w) diff --git a/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Weighted_point_d.h b/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Weighted_point_d.h index f11141a3036..3b5ceb6bb31 100644 --- a/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Weighted_point_d.h +++ b/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Weighted_point_d.h @@ -21,6 +21,9 @@ #ifndef CGAL_WRAPPER_WEIGHTED_POINT_D_H #define CGAL_WRAPPER_WEIGHTED_POINT_D_H +#include +#include +#include #include #include #include @@ -124,7 +127,42 @@ public: }; +template +std::ostream& operator<<(std::ostream& os, const Weighted_point_d& p) +{ + if(is_ascii(os)) + { + return os << p.point() << ' ' << p.weight(); + } + else + { + write(os, p.point()); + write(os, p.weight()); + } + return os; +} + +template +std::istream& operator>>(std::istream& is, Weighted_point_d& p) +{ + typedef typename Get_type::type FT_; + typedef typename Get_type::type Point_; + typedef typename Get_functor >::type CWP; + Point_ q; FT_ w; + if(is_ascii(is)) + { + if(is >> q >> iformat(w)) p=CWP()(q,w); + } + else + { + read(is, q); + read(is, w); + p=CWP()(q,w); + } + return is; +} + } //namespace Wrap } //namespace CGAL -#endif // CGAL_WRAPPER_SPHERE_D_H +#endif // CGAL_WRAPPER_WEIGHTED_POINT_D_H diff --git a/NewKernel_d/test/NewKernel_d/Epick_d.cpp b/NewKernel_d/test/NewKernel_d/Epick_d.cpp index 55aa6624adc..30aa5f79882 100644 --- a/NewKernel_d/test/NewKernel_d/Epick_d.cpp +++ b/NewKernel_d/test/NewKernel_d/Epick_d.cpp @@ -633,6 +633,9 @@ void test3(){ std::ostringstream output; output << showit; assert(output.str()=="3 1 2 4"); + std::istringstream input("3 5 6 9"); + input >> showit; + assert(ed(showit,cp(5,6,9))); P t1[]={cp(1,2,3),cp(3,2,1),cp(2,4,2)}; assert(sbds(t1+0,t1+2,cp(2,2,3.414)) == CGAL::ON_BOUNDED_SIDE); assert(sbds(t1+0,t1+2,cp(1,2,3)) == CGAL::ON_BOUNDARY); @@ -661,6 +664,14 @@ void test3(){ WP tabw[]={cwp(x1,0),cwp(x2,0),cwp(x3,0),cwp(x4,0),cwp(x5,0)}; assert(pt(tabw+0,tabw+4,tabw[4])==CGAL::ON_POSITIVE_SIDE); assert(ifpt(fo4,tabw+0,tabw+3,xw6)==CGAL::ON_POSITIVE_SIDE); + std::ostringstream swp; swp << wp; assert(swp.str()=="3 0 1 -1 2"); + std::istringstream swp2("3 4 5 6 7"); + swp2 >> wp; + assert(ed(wp.point(),cp(4,5,6)) && wp.weight()==7); + + V v1=cv(3,2,1); + std::ostringstream sv1; sv1 << v1; assert(sv1.str()=="3 3 2 1"); + std::istringstream sv2("3 4 5 6"); sv2 >> v1; assert(v1[0]==4&&v1[1]==5); } template struct CGAL::Epick_d >; template struct CGAL::Epick_d >; diff --git a/Triangulation/include/CGAL/IO/Triangulation_off_ostream.h b/Triangulation/include/CGAL/IO/Triangulation_off_ostream.h index 016a28be19d..1255d6e7bba 100644 --- a/Triangulation/include/CGAL/IO/Triangulation_off_ostream.h +++ b/Triangulation/include/CGAL/IO/Triangulation_off_ostream.h @@ -118,88 +118,6 @@ input_point(std::istream & is, const Traits &traits, P & p) // TODO: replace these operator>> by an "input_point" function /////////////////////////////////////////////////////////////// -// TODO: test if the stream is binary or text? -template -std::istream & -operator>>(std::istream &is, typename Wrap::Point_d & p) -{ - typedef typename Wrap::Point_d P; - typedef typename K::FT FT; - std::vector coords; - - std::string line; - for(;;) - { - if (!std::getline(is, line)) - return is; - if (line != "") - break; - } - std::stringstream line_sstr(line); - FT temp; - while (line_sstr >> temp) - coords.push_back(temp); - - p = P(coords.begin(), coords.end()); - return is; -} - -// TODO: test if the stream is binary or text? -template -std::istream & -operator>>(std::istream &is, typename Wrap::Weighted_point_d & wp) -{ - typedef typename Wrap::Point_d P; - typedef typename Wrap::Weighted_point_d WP; - typedef typename K::FT FT; - - std::string line; - for(;;) - { - if (!std::getline(is, line)) - return is; - if (line != "") - break; - } - std::stringstream line_sstr(line); - FT temp; - std::vector coords; - while (line_sstr >> temp) - coords.push_back(temp); - - typename std::vector::iterator last = coords.end() - 1; - P p = P(coords.begin(), last); - wp = WP(p, *last); - - return is; -} - -// TODO: test if the stream is binary or text? -template -std::istream & -operator>>(std::istream &is, typename Wrap::Vector_d & v) -{ - typedef typename Wrap::Vector_d V; - typedef typename K::FT FT; - std::vector coords; - - std::string line; - for (;;) - { - if (!std::getline(is, line)) - return is; - if (line != "") - break; - } - std::stringstream line_sstr(line); - FT temp; - while (line_sstr >> temp) - coords.push_back(temp); - - v = V(coords.begin(), coords.end()); - return is; -} - template < class GT, class TDS > std::ostream & export_triangulation_to_off(std::ostream & os, diff --git a/Triangulation/include/CGAL/Triangulation.h b/Triangulation/include/CGAL/Triangulation.h index 2e9a11f5cd5..20cfc0633d8 100644 --- a/Triangulation/include/CGAL/Triangulation.h +++ b/Triangulation/include/CGAL/Triangulation.h @@ -1352,7 +1352,7 @@ operator>>(std::istream & is, Triangulation & tr) else { read(is, cd); - read(is, n, io_Read_write()); + read(is, n); } CGAL_assertion_msg( cd <= tr.maximal_dimension(), "input Triangulation has too high dimension"); @@ -1404,27 +1404,34 @@ operator<<(std::ostream & os, const Triangulation & tr) else { write(os, tr.current_dimension()); - write(os, n, io_Read_write()); + write(os, n); } if( n == 0 ) return os; - size_t i(0); + int i = 0; // write the vertices std::map index_of_vertex; // infinite vertex has index 0 (among all the vertices) index_of_vertex[tr.infinite_vertex()] = i++; - os << *tr.infinite_vertex(); + if(is_ascii(os)) + os << *tr.infinite_vertex() <<"\n"; + else + write(os, *tr.infinite_vertex()); + for( Vertex_iterator it = tr.vertices_begin(); it != tr.vertices_end(); ++it ) { if( tr.is_infinite(it) ) continue; - os << *it; // write the vertex + if(is_ascii(os)) + os << *it <<"\n"; // write the vertex + else + write(os, *it); index_of_vertex[it] = i++; } - CGAL_assertion( i == n+1 ); + CGAL_assertion( size_t(i) == n+1 ); // output the combinatorial information return tr.tds().write_full_cells(os, index_of_vertex); diff --git a/Triangulation/include/CGAL/Triangulation_data_structure.h b/Triangulation/include/CGAL/Triangulation_data_structure.h index 411ac09b6bf..bfd8b078b3a 100644 --- a/Triangulation/include/CGAL/Triangulation_data_structure.h +++ b/Triangulation/include/CGAL/Triangulation_data_structure.h @@ -1392,7 +1392,9 @@ Triangulation_data_structure std::size_t i = 0; while( i < m ) { - Full_cell_handle s = new_full_cell(); + Full_cell_handle s = (i==0 && full_cells_.size()==1 ) + ? full_cells_begin() + : new_full_cell(); full_cells.push_back(s); for( int j = 0; j <= cd; ++j ) { diff --git a/Triangulation/include/CGAL/Triangulation_vertex.h b/Triangulation/include/CGAL/Triangulation_vertex.h index 11094d00f43..bb2b22db17e 100644 --- a/Triangulation/include/CGAL/Triangulation_vertex.h +++ b/Triangulation/include/CGAL/Triangulation_vertex.h @@ -115,7 +115,9 @@ template < class A, typename Data, class B > std::istream & operator>>(std::istream & is, Triangulation_vertex & v) { - is >> v.point(); + typename Triangulation_vertex::Point tmp; + is >> tmp; + v.set_point(tmp); return (is >> v.data()); } diff --git a/Triangulation/test/Triangulation/test_triangulation.cpp b/Triangulation/test/Triangulation/test_triangulation.cpp index 867c3ed7fc7..308b3f10c7d 100644 --- a/Triangulation/test/Triangulation/test_triangulation.cpp +++ b/Triangulation/test/Triangulation/test_triangulation.cpp @@ -15,6 +15,8 @@ int main() #include #include #include +#include +#include using namespace std; @@ -91,11 +93,32 @@ void test(const int d, const string & type, int N) assert( tri.number_of_vertices() == tri2.number_of_vertices() ); assert( tri.number_of_full_cells() == tri2.number_of_full_cells() ); + std::stringstream buffer; + buffer << tri; + // CLEAR tri.clear(); assert(-1==tri.current_dimension()); assert(tri.empty()); assert( tri.is_valid() ); + + buffer >> tri; + assert( tri.current_dimension() == tri2.current_dimension() ); + assert( tri.maximal_dimension() == tri2.maximal_dimension() ); + assert( tri.number_of_vertices() == tri2.number_of_vertices() ); + assert( tri.number_of_full_cells() == tri2.number_of_full_cells() ); + + std::ofstream ofs("tri", std::ios::binary); + ofs << tri; + ofs.close(); + + std::ifstream ifs("tri", std::ios::binary); + ifs >> tri2; + ifs.close(); + assert( tri.current_dimension() == tri2.current_dimension() ); + assert( tri.maximal_dimension() == tri2.maximal_dimension() ); + assert( tri.number_of_vertices() == tri2.number_of_vertices() ); + assert( tri.number_of_full_cells() == tri2.number_of_full_cells() ); } /*#define test_static(DIM) { \