Skip to content

Commit

Permalink
add binary management to Point_d, Weighted Point_d and Vector_d and test
Browse files Browse the repository at this point in the history
  • Loading branch information
maxGimeno authored and sloriot committed Oct 11, 2018
1 parent dfd5d38 commit a7a998c
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 35 deletions.
41 changes: 32 additions & 9 deletions NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Point_d.h
Expand Up @@ -258,10 +258,20 @@ 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;
}
Expand All @@ -274,13 +284,26 @@ 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;
is >> dim;
if( is_ascii(is) )
is >> dim;
else
{
read(is, dim);
}

if(!is) return is;

std::vector<FT> coords(dim);
for(int i=0;i<dim;++i)
is >> iformat(coords[i]);

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;
Expand Down
36 changes: 30 additions & 6 deletions NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Vector_d.h
Expand Up @@ -265,10 +265,21 @@ std::ostream& operator <<(std::ostream& os, const Vector_d<R_>& v)
>::type>::type
b = v.cartesian_begin(),
e = v.cartesian_end();
os << v.dimension();
for(; b != e; ++b){
os << " " << *b;
if(is_ascii(os))
{
os << v.dimension();
for(; b != e; ++b){
os << " " << *b;
}
}
else
{
write(os, os << v.dimension());
for(; b != e; ++b){
write(os, *b);
}
}

return os;
}

Expand All @@ -280,12 +291,25 @@ 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;
is >> dim;
if( is_ascii(is) )
is >> dim;
else
{
read(is, dim);
}
if(!is) return is;

std::vector<FT> coords(dim);
for(int i=0;i<dim;++i)
is >> iformat(coords[i]);
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());
Expand Down
21 changes: 19 additions & 2 deletions NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Weighted_point_d.h
Expand Up @@ -129,7 +129,15 @@ class Weighted_point_d : public Get_type<typename R_::Kernel_base, Weighted_poin
template <class R_>
std::ostream& operator<<(std::ostream& os, const Weighted_point_d<R_>& p)
{
return os << p.point() << ' ' << p.weight();
if(is_ascii(os))
{
return os << p.point() << ' ' << p.weight();
}
else
{
write(os, p.point());
write(os, p.weight());
}
}

template <class R_>
Expand All @@ -139,7 +147,16 @@ std::istream& operator>>(std::istream& is, Weighted_point_d<R_>& p)
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 >> q >> iformat(w)) p=CWP()(q,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;
}

Expand Down
14 changes: 0 additions & 14 deletions Triangulation/examples/Triangulation/convex_hull.cpp
Expand Up @@ -4,10 +4,8 @@
#include <CGAL/algorithm.h>
#include <CGAL/Timer.h>
#include <CGAL/assertions.h>
#include <CGAL/NewKernel_d/Wrapper/Point_d.h>

#include <iostream>
#include <fstream>
#include <iterator>
#include <vector>

Expand Down Expand Up @@ -60,17 +58,5 @@ int main(int argc, char **argv)
}

std::cout << c << " points were actually inserted.\n";
std::ofstream ofs("/home/gimeno/test.txt");
//CGAL::set_binary_mode(ofs);
ofs << t;
ofs.close();
T t2(D);
std::ifstream ifs("/home/gimeno/test.txt");
//CGAL::set_binary_mode(ifs);
ifs >> t2;
ifs.close();
if(t.number_of_vertices() != t2.number_of_vertices())
return 1;

return 0;
}
8 changes: 4 additions & 4 deletions Triangulation/include/CGAL/Triangulation.h
Expand Up @@ -1344,7 +1344,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");
Expand Down Expand Up @@ -1396,7 +1396,7 @@ 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 )
Expand All @@ -1411,7 +1411,7 @@ operator<<(std::ostream & os, const Triangulation<TT, TDS> & tr)
if(is_ascii(os))
os << *tr.infinite_vertex() <<"\n";
else
write(os, *tr.infinite_vertex(), io_Read_write());
write(os, *tr.infinite_vertex());

for( Vertex_iterator it = tr.vertices_begin(); it != tr.vertices_end(); ++it )
{
Expand All @@ -1420,7 +1420,7 @@ operator<<(std::ostream & os, const Triangulation<TT, TDS> & tr)
if(is_ascii(os))
os << *it <<"\n"; // write the vertex
else
write(os, *it, io_Read_write());
write(os, *it);
index_of_vertex[it] = i++;
}
CGAL_assertion( i == n+1 );
Expand Down
12 changes: 12 additions & 0 deletions Triangulation/test/Triangulation/test_triangulation.cpp
Expand Up @@ -95,6 +95,18 @@ void test(const int d, const string & type, int N)
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) { \
Expand Down

0 comments on commit a7a998c

Please sign in to comment.