mirror of https://github.com/CGAL/cgal
IO in binary mode
This commit is contained in:
parent
ac1b06a265
commit
ed87889d39
|
|
@ -118,15 +118,26 @@ inline Point_3<K> operator+(const Point_3<K> &p, const Periodic_3_offset_3 &off)
|
||||||
|
|
||||||
inline std::ostream
|
inline std::ostream
|
||||||
&operator<<(std::ostream &os, const Periodic_3_offset_3 &off) {
|
&operator<<(std::ostream &os, const Periodic_3_offset_3 &off) {
|
||||||
return os << off.x() << " "
|
if (is_ascii(os))
|
||||||
<< off.y() << " "
|
os << off.x() << " " << off.y() << " " << off.z();
|
||||||
<< off.z();
|
else {
|
||||||
|
write(os,off.x());
|
||||||
|
write(os,off.y());
|
||||||
|
write(os,off.z());
|
||||||
|
}
|
||||||
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::istream
|
inline std::istream
|
||||||
&operator>>(std::istream &is, Periodic_3_offset_3 &off) {
|
&operator>>(std::istream &is, Periodic_3_offset_3 &off) {
|
||||||
int x,y,z;
|
int x,y,z;
|
||||||
is >> x >> y >> z;
|
if (is_ascii(is))
|
||||||
|
is >> x >> y >> z;
|
||||||
|
else {
|
||||||
|
read(is,x);
|
||||||
|
read(is,y);
|
||||||
|
read(is,z);
|
||||||
|
}
|
||||||
off = Periodic_3_offset_3(x,y,z);
|
off = Periodic_3_offset_3(x,y,z);
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3308,12 +3308,22 @@ operator>> (std::istream& is, Periodic_3_triangulation_3<GT,TDS> &tr)
|
||||||
|
|
||||||
tr.clear();
|
tr.clear();
|
||||||
|
|
||||||
int n, cx, cy, cz;
|
unsigned int n;
|
||||||
|
int cx, cy, cz;
|
||||||
Iso_cuboid domain;
|
Iso_cuboid domain;
|
||||||
|
|
||||||
is >> n;
|
if (is_ascii(is)) {
|
||||||
is >> domain;
|
is >> n;
|
||||||
is >> cx >> cy >> cz;
|
is >> domain;
|
||||||
|
is >> cx >> cy >> cz;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
read(is,n);
|
||||||
|
is >> domain;
|
||||||
|
read(is,cx);
|
||||||
|
read(is,cy);
|
||||||
|
read(is,cz);
|
||||||
|
}
|
||||||
|
|
||||||
CGAL_assertion((n/(cx*cy*cz))*cx*cy*cz == n);
|
CGAL_assertion((n/(cx*cy*cz))*cx*cy*cz == n);
|
||||||
|
|
||||||
|
|
@ -3327,7 +3337,7 @@ operator>> (std::istream& is, Periodic_3_triangulation_3<GT,TDS> &tr)
|
||||||
std::map< int, Vertex_handle > V;
|
std::map< int, Vertex_handle > V;
|
||||||
|
|
||||||
if (cx==1 && cy==1 && cz==1) {
|
if (cx==1 && cy==1 && cz==1) {
|
||||||
for (int i=0; i < n; i++) {
|
for (unsigned int i=0; i < n; i++) {
|
||||||
V[i] = tr.tds().create_vertex();
|
V[i] = tr.tds().create_vertex();
|
||||||
is >> *V[i];
|
is >> *V[i];
|
||||||
}
|
}
|
||||||
|
|
@ -3335,7 +3345,7 @@ operator>> (std::istream& is, Periodic_3_triangulation_3<GT,TDS> &tr)
|
||||||
Vertex_handle v,w;
|
Vertex_handle v,w;
|
||||||
std::vector<Vertex_handle> vv;
|
std::vector<Vertex_handle> vv;
|
||||||
Offset off;
|
Offset off;
|
||||||
for (int i=0; i < n; i++) {
|
for (unsigned int i=0; i < n; i++) {
|
||||||
v = tr.tds().create_vertex();
|
v = tr.tds().create_vertex();
|
||||||
V[i] = v;
|
V[i] = v;
|
||||||
is >> *V[i] >> off;
|
is >> *V[i] >> off;
|
||||||
|
|
@ -3359,7 +3369,14 @@ operator>> (std::istream& is, Periodic_3_triangulation_3<GT,TDS> &tr)
|
||||||
// read offsets
|
// read offsets
|
||||||
int off[4];
|
int off[4];
|
||||||
for (int j=0 ; j < m; j++) {
|
for (int j=0 ; j < m; j++) {
|
||||||
is >> off[0] >> off[1] >> off[2] >> off[3];
|
if (is_ascii(is))
|
||||||
|
is >> off[0] >> off[1] >> off[2] >> off[3];
|
||||||
|
else {
|
||||||
|
read(is,off[0]);
|
||||||
|
read(is,off[1]);
|
||||||
|
read(is,off[2]);
|
||||||
|
read(is,off[3]);
|
||||||
|
}
|
||||||
C[j]->set_offsets(off[0],off[1],off[2],off[3]);
|
C[j]->set_offsets(off[0],off[1],off[2],off[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3388,7 +3405,6 @@ operator>> (std::istream& is, Periodic_3_triangulation_3<GT,TDS> &tr)
|
||||||
template < class GT, class TDS >
|
template < class GT, class TDS >
|
||||||
std::ostream &
|
std::ostream &
|
||||||
operator<< (std::ostream& os,const Periodic_3_triangulation_3<GT,TDS> &tr)
|
operator<< (std::ostream& os,const Periodic_3_triangulation_3<GT,TDS> &tr)
|
||||||
// TODO: new version into the doc
|
|
||||||
// writes :
|
// writes :
|
||||||
// the number of vertices
|
// the number of vertices
|
||||||
// the domain as six coordinates: xmin ymin zmin xmax ymax zmax
|
// the domain as six coordinates: xmin ymin zmin xmax ymax zmax
|
||||||
|
|
@ -3424,9 +3440,11 @@ operator<< (std::ostream& os,const Periodic_3_triangulation_3<GT,TDS> &tr)
|
||||||
<< domain << std::endl
|
<< domain << std::endl
|
||||||
<< cover[0] << " " << cover[1] << " " << cover[2] << std::endl;
|
<< cover[0] << " " << cover[1] << " " << cover[2] << std::endl;
|
||||||
else {
|
else {
|
||||||
os << n*cover[0]*cover[1]*cover[2]
|
write(os,n*cover[0]*cover[1]*cover[2]);
|
||||||
<< domain
|
os << domain;
|
||||||
<< cover[0] << cover[1] << cover[2];
|
write(os,cover[0]);
|
||||||
|
write(os,cover[1]);
|
||||||
|
write(os,cover[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
|
|
@ -3479,13 +3497,14 @@ operator<< (std::ostream& os,const Periodic_3_triangulation_3<GT,TDS> &tr)
|
||||||
//Cell_handle ch = std::find(tr.cells_begin(), tr.cells_end(), i);
|
//Cell_handle ch = std::find(tr.cells_begin(), tr.cells_end(), i);
|
||||||
Cell_handle ch(it);
|
Cell_handle ch(it);
|
||||||
for (int j=0; j<4; j++) {
|
for (int j=0; j<4; j++) {
|
||||||
os << ch->offset(j);
|
|
||||||
if(is_ascii(os)) {
|
if(is_ascii(os)) {
|
||||||
|
os << ch->offset(j);
|
||||||
if ( j==3 )
|
if ( j==3 )
|
||||||
os << std::endl;
|
os << std::endl;
|
||||||
else
|
else
|
||||||
os << ' ';
|
os << ' ';
|
||||||
}
|
}
|
||||||
|
else write(os,ch->offset(j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
@ -577,25 +578,19 @@ _test_cls_periodic_3_triangulation_3(const PeriodicTriangulation &T,
|
||||||
assert(PT3.mirror_facet(Facet(ch,0)).first == ch->neighbor(0));
|
assert(PT3.mirror_facet(Facet(ch,0)).first == ch->neighbor(0));
|
||||||
|
|
||||||
std::cout << "I/O" << std::endl;
|
std::cout << "I/O" << std::endl;
|
||||||
// TODO: write to string streams instead of file streams
|
|
||||||
std::cout << " ascii" << std::endl;
|
std::cout << " ascii" << std::endl;
|
||||||
|
|
||||||
std::ofstream os1("data/test_PT1.tri");
|
std::stringstream ss1;
|
||||||
std::ofstream os3("data/test_PT3.tri");
|
std::stringstream ss3;
|
||||||
os1 << PT1;
|
ss1 << PT1;
|
||||||
os3 << PT3;
|
ss3 << PT3;
|
||||||
|
|
||||||
std::ifstream is1("data/test_PT1.tri");
|
|
||||||
std::ifstream is3("data/test_PT3.tri");
|
|
||||||
|
|
||||||
P3T3 PT1r, PT3r;
|
P3T3 PT1r, PT3r;
|
||||||
is1 >> PT1r;
|
ss1 >> PT1r;
|
||||||
is3 >> PT3r;
|
ss3 >> PT3r;
|
||||||
|
|
||||||
assert(CGAL::is_ascii(os1));
|
assert(CGAL::is_ascii(ss1));
|
||||||
assert(CGAL::is_ascii(os3));
|
assert(CGAL::is_ascii(ss3));
|
||||||
assert(CGAL::is_ascii(is1));
|
|
||||||
assert(CGAL::is_ascii(is3));
|
|
||||||
if (!ex) assert(PT1 == PT1r);
|
if (!ex) assert(PT1 == PT1r);
|
||||||
if (!ex) assert(PT3 == PT3r);
|
if (!ex) assert(PT3 == PT3r);
|
||||||
|
|
||||||
|
|
@ -603,39 +598,35 @@ _test_cls_periodic_3_triangulation_3(const PeriodicTriangulation &T,
|
||||||
|
|
||||||
PT1r.clear();
|
PT1r.clear();
|
||||||
PT3r.clear();
|
PT3r.clear();
|
||||||
std::ofstream os1b("data/test_PT1.btr");
|
// There are problems with the IO of exact number types in binary mode.
|
||||||
std::ofstream os3b("data/test_PT3.btr");
|
if (!ex) {
|
||||||
CGAL::set_binary_mode(os1b);
|
std::stringstream ss1b;
|
||||||
CGAL::set_binary_mode(os3b);
|
std::stringstream ss3b;
|
||||||
os1b << PT1;
|
CGAL::set_binary_mode(ss1b);
|
||||||
os3b << PT3;
|
CGAL::set_binary_mode(ss3b);
|
||||||
|
ss1b << PT1;
|
||||||
std::ifstream is1b("data/test_PT1.btr");
|
ss3b << PT3;
|
||||||
std::ifstream is3b("data/test_PT3.btr");
|
|
||||||
CGAL::set_binary_mode(is1b);
|
ss1b >> PT1r;
|
||||||
CGAL::set_binary_mode(is3b);
|
ss3b >> PT3r;
|
||||||
// TODO: fix the bug
|
assert(CGAL::is_binary(ss1b));
|
||||||
// is1b >> PT1r;
|
assert(CGAL::is_binary(ss3b));
|
||||||
//is3b >> PT3r;
|
|
||||||
|
assert(PT1 == PT1r);
|
||||||
assert(CGAL::is_binary(os1b));
|
assert(PT3 == PT3r);
|
||||||
assert(CGAL::is_binary(os3b));
|
}
|
||||||
assert(CGAL::is_binary(is1b));
|
|
||||||
assert(CGAL::is_binary(is3b));
|
|
||||||
// assert(PT1 == PT1r);
|
|
||||||
//6 87 25 66 81 assert(PT3 == PT3r);
|
|
||||||
|
|
||||||
std::cout << " pretty" << std::endl;
|
std::cout << " pretty" << std::endl;
|
||||||
|
|
||||||
PT1r.clear();
|
PT1r.clear();
|
||||||
PT3r.clear();
|
PT3r.clear();
|
||||||
std::ofstream os1p("data/test_PT1.ptr");
|
std::stringstream ss1p;
|
||||||
std::ofstream os3p("data/test_PT3.ptr");
|
std::stringstream ss3p;
|
||||||
CGAL::set_pretty_mode(os1p);
|
CGAL::set_pretty_mode(ss1p);
|
||||||
CGAL::set_pretty_mode(os3p);
|
CGAL::set_pretty_mode(ss3p);
|
||||||
os1p << PT1;
|
ss1p << PT1;
|
||||||
os3p << PT3;
|
ss3p << PT3;
|
||||||
|
|
||||||
assert(CGAL::is_pretty(os1p));
|
assert(CGAL::is_pretty(ss1p));
|
||||||
assert(CGAL::is_pretty(os3p));
|
assert(CGAL::is_pretty(ss3p));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue