mirror of https://github.com/CGAL/cgal
Add a test for file_input()
This commit is contained in:
parent
9fe491adfb
commit
065a7ac0c6
|
|
@ -60,6 +60,7 @@
|
|||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/utility/result_of.hpp>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <CGAL/IO/Triangulation_file_input.h>
|
||||
|
||||
#ifndef CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO
|
||||
#include <CGAL/internal/info_check.h>
|
||||
|
|
@ -2193,8 +2194,20 @@ public:
|
|||
bool is_valid(bool verbose = false, int level = 0) const;
|
||||
bool is_valid(Cell_handle c, bool verbose = false, int level = 0) const;
|
||||
bool is_valid_finite(Cell_handle c, bool verbose = false, int level=0) const;
|
||||
|
||||
//IO
|
||||
template <typename Tr_src,
|
||||
typename ConvertVertex,
|
||||
typename ConvertCell>
|
||||
std::istream& file_input(std::istream& is,
|
||||
ConvertVertex convert_vertex = ConvertVertex(),
|
||||
ConvertCell convert_cell = ConvertCell())
|
||||
{
|
||||
return CGAL::file_input<Tr_src, Self, ConvertVertex, ConvertCell>(is, *this, convert_vertex, convert_cell);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template < class GT, class Tds, class Lds >
|
||||
std::istream& operator>> (std::istream& is, Triangulation_3<GT, Tds, Lds>& tr)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ if ( CGAL_FOUND )
|
|||
create_single_source_cgal_program( "test_simplex_3.cpp" )
|
||||
create_single_source_cgal_program( "test_static_filters.cpp" )
|
||||
create_single_source_cgal_program( "test_triangulation_3.cpp" )
|
||||
create_single_source_cgal_program( "test_io_triangulation_3.cpp" )
|
||||
|
||||
if(TBB_FOUND)
|
||||
foreach(target
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
|
||||
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
#include <CGAL/Triangulation_3.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Cartesian_converter.h>
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> K1;
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K2;
|
||||
typedef CGAL::Triangulation_3<K1> Tr1;
|
||||
typedef CGAL::Triangulation_3<K2> Tr2;
|
||||
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct Update_vertex
|
||||
{
|
||||
typedef typename T1::Vertex V1;
|
||||
typedef typename T2::Vertex V2;
|
||||
typedef typename T2::Point Point;
|
||||
|
||||
V2 operator()(const V1&)
|
||||
{
|
||||
return V2();
|
||||
}
|
||||
|
||||
void operator()(const V1& v1, V2& v2)
|
||||
{
|
||||
CGAL::Cartesian_converter<K1, K2> c;
|
||||
v2.set_point(Point(c(v1.point())));
|
||||
}
|
||||
}; // end struct Update_vertex
|
||||
|
||||
struct Update_cell {
|
||||
template <typename C1, typename C2>
|
||||
void operator()(const C1&, C2&) {}
|
||||
}; // end struct Update_cell
|
||||
int main()
|
||||
{
|
||||
// construction from a list of points :
|
||||
std::list<Tr1::Point> L;
|
||||
L.push_back(Tr1::Point(0,0,0));
|
||||
L.push_back(Tr1::Point(1,0,0));
|
||||
L.push_back(Tr1::Point(0,1,0));
|
||||
L.push_back(Tr1::Point(0,0,1));
|
||||
Tr1 T1(L.begin(), L.end());
|
||||
std::ofstream out("tr");
|
||||
out << T1;
|
||||
out.close();
|
||||
|
||||
Tr2 T2;
|
||||
std::ifstream in("tr");
|
||||
T2.file_input<Tr1,Update_vertex<Tr1, Tr2>, Update_cell>(in);
|
||||
in.close();
|
||||
assert(T2.is_valid());
|
||||
Tr2::Point_iterator pit = T2.points_begin();
|
||||
assert(*(pit)++ == Tr2::Point(0,0,0));
|
||||
assert(*(pit)++ == Tr2::Point(1,0,0));
|
||||
assert(*(pit)++ == Tr2::Point(0,1,0));
|
||||
assert(*(pit)++ == Tr2::Point(0,0,1));
|
||||
|
||||
|
||||
std::cout << "done" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue