Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions Mesh_3/include/CGAL/IO/File_binary_mesh_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ save_binary_file(std::ostream& os,
{
typedef typename C3T3::Triangulation::Geom_traits::FT FT;
if(binary) os << "binary ";
os << "CGAL c3t3 " << CGAL::Get_io_signature<C3T3>()() << "\n";
os << "CGAL c3t3 " << CGAL::Get_io_signature<C3T3>()() <<"+C3t3_data<"<<Get_io_signature<typename C3T3::Curve_index>()()<<">\n";
if(binary) {
CGAL::IO::set_binary_mode(os);
} else {
Expand All @@ -59,20 +59,50 @@ bool load_binary_file(std::istream& is, C3T3& c3t3)
{
return false;
}
bool has_curve_index_type = false;
std::getline(is, s);
if(!s.empty()) {
if(s[s.size()-1] == '\r') { // deal with Windows EOL
s.resize(s.size() - 1);
}
if(s != std::string(" ") + CGAL::Get_io_signature<C3T3>()()) {
std::cerr << "load_binary_file:"
<< "\n expected format: " << CGAL::Get_io_signature<C3T3>()()
<< "\n got format:" << s << std::endl;
return false;
if(s.find("+C3t3_data") !=std::string::npos)
{
std::size_t splitter = s.find("+C3t3_data");
std::string first_part = s.substr(0, splitter);
std::string second_part = s.substr(splitter);

if(first_part != std::string(" ") + CGAL::Get_io_signature<C3T3>()()) {
std::cerr << "load_binary_file:"
<< "\n expected format: " << CGAL::Get_io_signature<C3T3>()()
<< "\n got format:" << s << std::endl;
return false;
}
if(second_part != std::string("+C3t3_data<")+Get_io_signature<typename C3T3::Curve_index>()()+">"){
std::cout<< "load_binary_file warning:"
<< "\n expected format: " << CGAL::Get_io_signature<C3T3>()()<<"+C3t3_data<"<<CGAL::Get_io_signature<typename C3T3::Curve_index>()()<<">"
<< "\n got format:" << s << std::endl
<< "\n not loading edges in complex."<<std::endl;
has_curve_index_type = false;
}
else
has_curve_index_type = true;
}
else
{
if(s != std::string(" ") + CGAL::Get_io_signature<C3T3>()()) {
std::cerr << "load_binary_file:"
<< "\n expected format: " << CGAL::Get_io_signature<C3T3>()()
<< "\n got format:" << s << std::endl;
return false;
}
has_curve_index_type = false;
}
}
if(binary) CGAL::IO::set_binary_mode(is);
is >> c3t3;
if(has_curve_index_type)
is >> c3t3;
else
c3t3.load_without_edges(is);
return !!is;
// call operator!() twice, because operator bool() is C++11
}
Expand Down
116 changes: 113 additions & 3 deletions Mesh_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,87 @@ class Mesh_complex_3_in_triangulation_3 :
Vertex_iterator_not_in_complex(*this));
}

std::ostream& write_edges_in_complex(std::ostream& os,
const Unique_hash_map<Vertex_handle, std::size_t >& vertex_index_map) const
{
if(is_ascii(os))
{
os << number_of_edges_in_complex()<<std::endl;
for(auto it = edges_.begin(); it != edges_.end(); ++it)
{
os<<vertex_index_map[it->left]<<" "<<vertex_index_map[it->right]<< " "<< CGAL::oformat(it->info)<<std::endl;
}
}
else
{
write(os, number_of_edges_in_complex());
for(auto it = edges_.begin(); it != edges_.end(); ++it)
{
write(os, vertex_index_map[it->left]);
write(os, vertex_index_map[it->right]);
write(os, it->info);
}
}
return os;
}

std::istream& read_edges_in_complex(std::istream& is,
const std::vector<Vertex_handle >& index_vertex_map)
{
std::size_t n;
if(is_ascii(is))
{
is >> n;
}
else
{
CGAL::read(is, n);
}
if(!is)
return is;

if(is_ascii(is))
{
for(std::size_t i=0; i < n; ++i)
{
//read edge and curve index
std::size_t l,r;
Curve_index c;
is >> CGAL::iformat(l);
is >> CGAL::iformat(r);
is >> CGAL::iformat(c);
if(!is)
return is;
add_to_complex(index_vertex_map[l],index_vertex_map[r], c);
}
}
else
{
for(std::size_t i=0; i < n; ++i)
{
//read edge and curve index
std::size_t l,r;
Curve_index c;
CGAL::read(is,l);
CGAL::read(is,r);
CGAL::read(is,c);
if(!is)
return is;
add_to_complex(index_vertex_map[l],index_vertex_map[r], c);
}
}
return is;
}

std::istream& load_without_edges(std::istream& is)
{
is >> static_cast<
Mesh_3::Mesh_complex_3_in_triangulation_3_base<Tr, Concurrency_tag>&>(*this);

rescan_after_load_of_triangulation();
return is;

}
private:
/**
* Creates an Internal_edge object (i.e a pair of ordered Vertex_handle)
Expand Down Expand Up @@ -772,10 +852,28 @@ std::ostream &
operator<< (std::ostream& os,
const Mesh_complex_3_in_triangulation_3<Tr,CI_,CSI_> &c3t3)
{
// TODO: implement edge saving
typedef typename Mesh_complex_3_in_triangulation_3<Tr,CI_,CSI_>::Concurrency_tag Concurrency_tag;
return os << static_cast<
os << static_cast<
const Mesh_3::Mesh_complex_3_in_triangulation_3_base<Tr, Concurrency_tag>&>(c3t3);
if(os.good() && c3t3.triangulation().dimension() > 0)
{
Unique_hash_map<typename Tr::Vertex_handle, std::size_t > vertex_index_map;


typename Tr::size_type i = 0;
vertex_index_map[c3t3.triangulation().infinite_vertex()] = 0;
auto vit = c3t3.triangulation().vertices_begin();
//skip infinite vertex
++vit;
for(; vit != c3t3.triangulation().vertices_end(); ++vit)
{
vertex_index_map[vit] = ++i;
}
CGAL_triangulation_assertion(i == c3t3.triangulation().number_of_vertices());
CGAL_triangulation_assertion(c3t3.triangulation().is_infinite(c3t3.triangulation().vertices_begin()));
c3t3.write_edges_in_complex(os, vertex_index_map);
}
return os;
}


Expand All @@ -784,11 +882,23 @@ std::istream &
operator>> (std::istream& is,
Mesh_complex_3_in_triangulation_3<Tr,CI_,CSI_> &c3t3)
{
// TODO: implement edge loading
typedef typename Mesh_complex_3_in_triangulation_3<Tr,CI_,CSI_>::Concurrency_tag Concurrency_tag;
is >> static_cast<
Mesh_3::Mesh_complex_3_in_triangulation_3_base<Tr, Concurrency_tag>&>(c3t3);

c3t3.rescan_after_load_of_triangulation();
//rebuild index_vertex_map
std::vector< typename Tr::Vertex_handle > V(c3t3.triangulation().number_of_vertices()+1);
//V[0] = c3t3.triangulation().infinite_vertex(); // the infinite vertex is numbered 0
std::size_t i = 0;
auto vit = c3t3.triangulation().vertices_begin();
for(vit; vit != c3t3.triangulation().vertices_end(); ++vit)
{
V[i++] = vit;
}

//load edges_in_complex
c3t3.read_edges_in_complex(is, V);
return is;
}

Expand Down
Binary file modified Mesh_3/test/Mesh_3/data/c3t3_io-hetero.binary.cgal
Binary file not shown.
3 changes: 3 additions & 0 deletions Mesh_3/test/Mesh_3/data/c3t3_io-hetero.cgal
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ CGAL c3t3 Triangulation_3(Weighted_point<Point_3>,Vb(Tvb_3+i+boost::variant<enum
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
2
1 3 5
1 4 6
Binary file modified Mesh_3/test/Mesh_3/data/c3t3_io-homo.binary.cgal
Binary file not shown.
3 changes: 3 additions & 0 deletions Mesh_3/test/Mesh_3/data/c3t3_io-homo.cgal
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ CGAL c3t3 Triangulation_3(Weighted_point<Point_3>,Vb(Tvb_3+i+i),Cb(i+RTcb_3+(i)[
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
2
1 3 5
1 4 6
Binary file added Mesh_3/test/Mesh_3/data/c3t3_io-pairs.binary.cgal
Binary file not shown.
49 changes: 49 additions & 0 deletions Mesh_3/test/Mesh_3/data/c3t3_io-pairs.cgal
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
CGAL c3t3 Triangulation_3(Weighted_point<Point_3>,Vb(Tvb_3+i+i),Cb(i+RTcb_3+(i)[4]))+C3t3_data<std::pair<i,i>>
3
6
10 11 12 0 0 7
11 13 10 0 0 8
7 4 6 0 1 5
5 2 14 0 1 6
1 2 3 0 2 3
3 9 13 0 3 1
12
0 1 3 4
4 0 1 6
4 3 5 6
5 0 4 6
3 2 1 0
3 0 4 5
0 3 2 5
4 1 3 6
5 3 2 6
2 3 1 6
2 0 5 6
0 2 1 6
7 5 1 4
11 7 3 0
8 3 7 5
1 2 10 5
11 0 6 9
3 2 6 0
8 10 5 4
9 2 1 0
9 10 2 6
7 11 8 4
3 8 11 6
9 1 10 4
0 3 0 0 0
0 0 4 0 0
1 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
2 0 0 4 3
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
2
1 3 5 6
1 4 6 7
Loading