mirror of https://github.com/CGAL/cgal
Merge pull request #3172 from sloriot/Triangulation-fix_IO
Fix vertex istream operator
This commit is contained in:
commit
21d53cd984
|
|
@ -22,6 +22,8 @@
|
|||
#define CGAL_WRAPPER_POINT_D_H
|
||||
|
||||
#include <ostream>
|
||||
#include <istream>
|
||||
#include <CGAL/IO/io.h>
|
||||
#include <CGAL/Origin.h>
|
||||
#include <CGAL/Kernel/mpl.h>
|
||||
#include <CGAL/representation_tags.h>
|
||||
|
|
@ -247,8 +249,6 @@ public:
|
|||
template <class R_> Point_d<R_>::Point_d(Point_d &)=default;
|
||||
#endif
|
||||
|
||||
//TODO: IO
|
||||
|
||||
template <class R_>
|
||||
std::ostream& operator <<(std::ostream& os, const Point_d<R_>& p)
|
||||
{
|
||||
|
|
@ -259,14 +259,57 @@ std::ostream& operator <<(std::ostream& os, const Point_d<R_>& p)
|
|||
CPI(typename Point_d<R_>::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<typename K>
|
||||
std::istream &
|
||||
operator>>(std::istream &is, Point_d<K> & p)
|
||||
{
|
||||
typedef typename Get_type<K, Point_tag>::type P;
|
||||
typedef typename Get_type<K, FT_tag>::type FT;
|
||||
int dim;
|
||||
if( is_ascii(is) )
|
||||
is >> dim;
|
||||
else
|
||||
{
|
||||
read(is, dim);
|
||||
}
|
||||
|
||||
if(!is) return is;
|
||||
std::vector<FT> coords(dim);
|
||||
if(is_ascii(is))
|
||||
{
|
||||
for(int i=0;i<dim;++i)
|
||||
is >> iformat(coords[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i=0;i<dim;++i)
|
||||
read(is, coords[i]);
|
||||
}
|
||||
|
||||
if(is)
|
||||
p = P(coords.begin(), coords.end());
|
||||
return is;
|
||||
}
|
||||
|
||||
//template <class R_>
|
||||
//Vector_d<R_> operator+(const Vector_d<R_>& v,const Vector_d<R_>& w) const
|
||||
//{
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@
|
|||
#ifndef CGAL_WRAPPER_VECTOR_D_H
|
||||
#define CGAL_WRAPPER_VECTOR_D_H
|
||||
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <CGAL/IO/io.h>
|
||||
#include <CGAL/Origin.h>
|
||||
#include <CGAL/Kernel/mpl.h>
|
||||
#include <CGAL/representation_tags.h>
|
||||
|
|
@ -239,6 +242,11 @@ public:
|
|||
return rep.dimension();
|
||||
}
|
||||
*/
|
||||
int dimension() const {
|
||||
typedef typename Get_functor<Kbase, Vector_dimension_tag>::type VDBase;
|
||||
return VDBase()(rep());
|
||||
}
|
||||
|
||||
typename boost::result_of<SLBase(Rep)>::type squared_length()const{
|
||||
return SLBase()(rep());
|
||||
}
|
||||
|
|
@ -247,7 +255,68 @@ public:
|
|||
template <class R_> Vector_d<R_>::Vector_d(Vector_d &)=default;
|
||||
#endif
|
||||
|
||||
//TODO: IO
|
||||
template <class R_>
|
||||
std::ostream& operator <<(std::ostream& os, const Vector_d<R_>& v)
|
||||
{
|
||||
typedef typename R_::Kernel_base Kbase;
|
||||
typedef typename Get_functor<Kbase, Construct_ttag<Vector_cartesian_const_iterator_tag> >::type CVI;
|
||||
// Should just be "auto"...
|
||||
typename CGAL::decay<typename boost::result_of<
|
||||
CVI(typename Vector_d<R_>::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<typename K>
|
||||
std::istream &
|
||||
operator>>(std::istream &is, Vector_d<K> & v)
|
||||
{
|
||||
typedef typename Get_type<K, Vector_tag>::type V;
|
||||
typedef typename Get_type<K, FT_tag>::type FT;
|
||||
int dim;
|
||||
if( is_ascii(is) )
|
||||
is >> dim;
|
||||
else
|
||||
{
|
||||
read(is, dim);
|
||||
}
|
||||
if(!is) return is;
|
||||
|
||||
std::vector<FT> coords(dim);
|
||||
if(is_ascii(is))
|
||||
{
|
||||
for(int i=0;i<dim;++i)
|
||||
is >> iformat(coords[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i=0;i<dim;++i)
|
||||
read(is, coords[i]);
|
||||
}
|
||||
|
||||
if(is)
|
||||
v = V(coords.begin(), coords.end());
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
template <class R_>
|
||||
Vector_d<R_> operator+(const Vector_d<R_>& v,const Vector_d<R_>& w)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@
|
|||
#ifndef CGAL_WRAPPER_WEIGHTED_POINT_D_H
|
||||
#define CGAL_WRAPPER_WEIGHTED_POINT_D_H
|
||||
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <CGAL/IO/io.h>
|
||||
#include <CGAL/representation_tags.h>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
|
|
@ -124,7 +127,42 @@ public:
|
|||
|
||||
};
|
||||
|
||||
template <class R_>
|
||||
std::ostream& operator<<(std::ostream& os, const Weighted_point_d<R_>& p)
|
||||
{
|
||||
if(is_ascii(os))
|
||||
{
|
||||
return os << p.point() << ' ' << p.weight();
|
||||
}
|
||||
else
|
||||
{
|
||||
write(os, p.point());
|
||||
write(os, p.weight());
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template <class R_>
|
||||
std::istream& operator>>(std::istream& is, Weighted_point_d<R_>& p)
|
||||
{
|
||||
typedef typename Get_type<R_, FT_tag>::type FT_;
|
||||
typedef typename Get_type<R_, Point_tag>::type Point_;
|
||||
typedef typename Get_functor<R_, Construct_ttag<Weighted_point_tag> >::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
|
||||
|
|
|
|||
|
|
@ -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<CGAL::Dimension_tag<2> >;
|
||||
template struct CGAL::Epick_d<CGAL::Dimension_tag<3> >;
|
||||
|
|
|
|||
|
|
@ -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<typename K>
|
||||
std::istream &
|
||||
operator>>(std::istream &is, typename Wrap::Point_d<K> & p)
|
||||
{
|
||||
typedef typename Wrap::Point_d<K> P;
|
||||
typedef typename K::FT FT;
|
||||
std::vector<FT> 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<typename K>
|
||||
std::istream &
|
||||
operator>>(std::istream &is, typename Wrap::Weighted_point_d<K> & wp)
|
||||
{
|
||||
typedef typename Wrap::Point_d<K> P;
|
||||
typedef typename Wrap::Weighted_point_d<K> 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<FT> coords;
|
||||
while (line_sstr >> temp)
|
||||
coords.push_back(temp);
|
||||
|
||||
typename std::vector<FT>::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<typename K>
|
||||
std::istream &
|
||||
operator>>(std::istream &is, typename Wrap::Vector_d<K> & v)
|
||||
{
|
||||
typedef typename Wrap::Vector_d<K> V;
|
||||
typedef typename K::FT FT;
|
||||
std::vector<FT> 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,
|
||||
|
|
|
|||
|
|
@ -1352,7 +1352,7 @@ operator>>(std::istream & is, Triangulation<TT, TDS> & 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<TT, TDS> & 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<Vertex_handle, int> 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);
|
||||
|
|
|
|||
|
|
@ -1392,7 +1392,9 @@ Triangulation_data_structure<Dimen, Vb, Fcb>
|
|||
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 )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -115,7 +115,9 @@ template < class A, typename Data, class B >
|
|||
std::istream &
|
||||
operator>>(std::istream & is, Triangulation_vertex<A, Data, B> & v)
|
||||
{
|
||||
is >> v.point();
|
||||
typename Triangulation_vertex<A, Data, B>::Point tmp;
|
||||
is >> tmp;
|
||||
v.set_point(tmp);
|
||||
return (is >> v.data());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ int main()
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <CGAL/IO/Triangulation_off_ostream.h>
|
||||
|
||||
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) { \
|
||||
|
|
|
|||
Loading…
Reference in New Issue