Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh 3 - Triangulation IO and Save and load C3t3 features #7821

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
10 changes: 8 additions & 2 deletions Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ try_load_a_cdt_3(std::istream& is, C3t3& c3t3)
}
std::getline(is, s);
if(s != "") {
if(s[s.size()-1] == '\r') { // deal with Windows EOL
s.resize(s.size() - 1);
}
if(s != std::string(" ") + CGAL::Get_io_signature<Fake_CDT_3>()()) {
ange-clement marked this conversation as resolved.
Show resolved Hide resolved
std::cerr << "load_binary_file:"
<< "\n expected format: " << CGAL::Get_io_signature<Fake_CDT_3>()()
Expand All @@ -507,7 +510,7 @@ try_load_a_cdt_3(std::istream& is, C3t3& c3t3)
}
}
if(binary) CGAL::IO::set_binary_mode(is);
if(c3t3.triangulation().file_input<
if(c3t3.file_input<
Fake_CDT_3,
Update_vertex_from_CDT_3<Fake_CDT_3, C3t3::Triangulation>,
Update_cell_from_CDT_3>(is))
Expand Down Expand Up @@ -582,6 +585,9 @@ try_load_other_binary_format(std::istream& is, C3t3& c3t3)
}
std::getline(is, s);
if(s != "") {
if(s[s.size()-1] == '\r') { // deal with Windows EOL
s.resize(s.size() - 1);
}
ange-clement marked this conversation as resolved.
Show resolved Hide resolved
if(s != std::string(" ") + CGAL::Get_io_signature<Fake_c3t3>()()) {
std::cerr << "Polyhedron_demo_c3t3_binary_io_plugin::try_load_other_binary_format:"
<< "\n expected format: " << CGAL::Get_io_signature<Fake_c3t3>()()
Expand All @@ -591,7 +597,7 @@ try_load_other_binary_format(std::istream& is, C3t3& c3t3)
}
if(binary) CGAL::IO::set_binary_mode(is);
else CGAL::IO::set_ascii_mode(is);
std::istream& f_is = c3t3.triangulation().file_input<
std::istream& f_is = c3t3.file_input<
Fake_c3t3::Triangulation,
Update_vertex<Fake_c3t3::Triangulation, C3t3::Triangulation>,
Update_cell>(is);
Expand Down
180 changes: 175 additions & 5 deletions SMDS_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -1205,11 +1205,90 @@ class Mesh_complex_3_in_triangulation_3
std::istream& operator>>(std::istream& is,
Mesh_complex_3_in_triangulation_3<Tr2, CoI, CuI>& c3t3);

template <typename Tr2, typename CoI, typename CuI>
friend
std::ostream & operator<<(std::ostream& os,
const Mesh_complex_3_in_triangulation_3<Tr2, CoI, CuI> &c3t3);


static std::string io_signature()
{
return Get_io_signature<Tr>()();
}

std::istream& read_edges(std::istream& is, const std::vector< Vertex_handle >& vertices_handles)
{
// Reads 1D features
std::size_t nEdges;
if(IO::is_ascii(is))
{
is >> nEdges;
}
else
{
read(is, nEdges);
}
// If the file did not have edges
if (!is) {
return is;
}

ange-clement marked this conversation as resolved.
Show resolved Hide resolved
for (std::size_t i = 0; i < nEdges; i++)
{
std::size_t iv1;
std::size_t iv2;
Curve_index index;
if (IO::is_ascii(is))
is >> iv1 >> iv2 >> index;
else {
read(is, iv1);
read(is, iv2);
read(is, index);
}
Internal_edge edge(vertices_handles[iv1], vertices_handles[iv2]);
add_to_complex(edge, index);
}
return is;
}

template <typename Tr_src,
typename ConvertVertex,
typename ConvertCell>
std::istream& file_input(std::istream& is,
ConvertVertex convert_vertex = ConvertVertex(),
ConvertCell convert_cell = ConvertCell())
{
// Reads:
// - the dimension
// - the number of finite vertices
// - the non combinatorial information on vertices (point, etc)
// - the number of cells
// - the cells by the indices of their vertices in the preceding list
// of vertices, plus the non combinatorial information on each cell
// - the neighbors of each cell by their index in the preceding list of cells
// - when dimension < 3 : the same with faces of maximal dimension
// - the number of edges
// - the edges by the indices of their vertices and their curve_index

// If this is used for a TDS, the vertices are processed from 0 to n.
// Else, we make V[0] the infinite vertex and work from 1 to n+1.

// Reads triangulation
std::vector< Vertex_handle > vertices_handles;
if (!tr_.template file_input<Tr_src, ConvertVertex, ConvertCell>
(is, vertices_handles, convert_vertex, convert_cell))
{
clear();
is.setstate(std::ios_base::failbit);
return is;
}

// Reads 1D Features
read_edges(is, vertices_handles);

return is;
}

/**
* @cond SKIP_IN_MANUAL
* creates an `Internal_edge` object (i.e a pair of ordered `Vertex_handle`)
Expand Down Expand Up @@ -2071,8 +2150,69 @@ std::ostream &
operator<< (std::ostream& os,
const Mesh_complex_3_in_triangulation_3<Tr,CI_,CSI_> &c3t3)
{
// TODO: implement edge saving
return os << c3t3.triangulation();
/* Writes:
* [Triangulation]
* [Header]
* - the dimension
* [Vertices]
* - the number of finite vertices
* - the non combinatorial information on vertices (point, etc)
* [Cells]
* - the number of cells
* - the cells by the indices of their vertices in the preceding list
* of vertices, plus the non combinatorial information on each cell
* [Cells combinatorial information]
* - the neighbors of each cell by their index in the preceding list of cells
* [Cells other info]
* - when dimension < 3 : the same with faces of maximal dimension
* [1D features]
* - the number of edges
* - the edges by the indices of their vertices and their curve_index
*/
using C3t3 = Mesh_complex_3_in_triangulation_3<Tr,CI_,CSI_>;
using Vertex_handle = typename C3t3::Vertex_handle;
using Curve_index = typename C3t3::Curve_index;

// Writes triangulation
Unique_hash_map<Vertex_handle, std::size_t> vertices_map;
if (!CGAL::IO::export_triangulation_3(os, c3t3.triangulation(), vertices_map))
{
os.setstate(std::ios_base::failbit);
return os;
}

// Writes 1D features
std::size_t nEdges = c3t3.edges_.size();
if(IO::is_ascii(os))
{
os << nEdges << '\n';
}
else
{
write(os, nEdges);
}

if (!os)
return os;

for ( typename C3t3::Edge_map::const_iterator it = c3t3.edges_.begin(),
end = c3t3.edges_.end() ; it != end ; ++it )
{
const Vertex_handle& v1 = it->left;
const Vertex_handle& v2 = it->right;
const std::size_t& iv1 = vertices_map[v1];
const std::size_t& iv2 = vertices_map[v2];
const Curve_index& index = it->info;
if (IO::is_ascii(os))
os << iv1 << ' ' << iv2 << ' ' << index << '\n';
else {
write(os, iv1);
write(os, iv2);
write(os, index);
}
}

return os;
}


Expand All @@ -2081,15 +2221,45 @@ std::istream &
operator>> (std::istream& is,
Mesh_complex_3_in_triangulation_3<Tr,CI_,CSI_> &c3t3)
{
// TODO: implement edge loading
/* Reads:
* [Triangulation]
* [Header]
* - the dimension
* [Vertices]
* - the number of finite vertices
* - the non combinatorial information on vertices (point, etc)
* [Cells]
* - the number of cells
* - the cells by the indices of their vertices in the preceding list
* of vertices, plus the non combinatorial information on each cell
* [Cells combinatorial information]
* - the neighbors of each cell by their index in the preceding list of cells
* [Cells other info]
* - when dimension < 3 : the same with faces of maximal dimension
* [1D features]
* - the number of edges
* - the edges by the indices of their vertices and their curve_index
*/
using C3t3 = Mesh_complex_3_in_triangulation_3<Tr,CI_,CSI_>;
using Vertex_handle = typename C3t3::Vertex_handle;
using Curve_index = typename C3t3::Curve_index;
using Internal_edge = typename C3t3::Internal_edge;
ange-clement marked this conversation as resolved.
Show resolved Hide resolved

c3t3.clear();
is >> c3t3.triangulation();

if (!is) {
// Reads triangulation
std::vector< Vertex_handle > vertices_handles;
if (!CGAL::IO::import_triangulation_3(is, c3t3.triangulation(), vertices_handles))
{
c3t3.clear();
is.setstate(std::ios_base::failbit);
return is;
}

c3t3.read_edges(is, vertices_handles);
if (!is)
return is;

c3t3.rescan_after_load_of_triangulation();
return is;
}
Expand Down
Loading