mirror of https://github.com/CGAL/cgal
Test for read write vtk + data files
This commit is contained in:
parent
876db072d8
commit
5a3dbda022
|
|
@ -423,6 +423,11 @@ bool read_lcc_from_vtk_ascii(std::istream& is, LCC& alcc,
|
|||
{ alcc.erase_vertex_attribute(itv); }
|
||||
}
|
||||
|
||||
if(vertex_scalars!=nullptr)
|
||||
{ vertex_scalars->clear(); }
|
||||
if(cell_scalars!=nullptr)
|
||||
{ cell_scalars->clear(); }
|
||||
|
||||
while(std::getline(is, line))
|
||||
{
|
||||
// Read POINT_DATA scalars if present
|
||||
|
|
|
|||
|
|
@ -6,62 +6,197 @@
|
|||
|
||||
typedef CGAL::Linear_cell_complex_for_combinatorial_map<3, 3> LCC;
|
||||
|
||||
int main() {
|
||||
bool test_file(const char* filename)
|
||||
{
|
||||
LCC lcc1, lcc2;
|
||||
std::vector<float> vertex_scalars1, vertex_scalars2;
|
||||
std::vector<std::size_t> volume_scalars1, volume_scalars2;
|
||||
|
||||
const char* filename = "data/beam-with-mixed-cells.vtk";
|
||||
|
||||
|
||||
bool ok_read1 = CGAL::IO::read_VTK<LCC,float,std::size_t>(lcc1, filename,
|
||||
&vertex_scalars1, &volume_scalars1);
|
||||
assert(ok_read1);
|
||||
|
||||
|
||||
std::size_t nb_vertices = 0;
|
||||
for(auto itv = lcc1.vertex_attributes().begin(), itvend = lcc1.vertex_attributes().end(); itv != itvend; ++itv)
|
||||
++nb_vertices;
|
||||
if(vertex_scalars1.size() != nb_vertices) {
|
||||
vertex_scalars1.resize(nb_vertices);
|
||||
for(std::size_t i=0;i<nb_vertices;++i)
|
||||
vertex_scalars1[i] = static_cast<float>(i);
|
||||
bool res=CGAL::IO::read_VTK(lcc1, filename);
|
||||
if(!res)
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error read_VTK in test_file"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::size_t nb_vertices=lcc1.number_of_vertex_attributes();
|
||||
vertex_scalars1.resize(nb_vertices);
|
||||
for(std::size_t i=0;i<nb_vertices;++i)
|
||||
{ vertex_scalars1[i]=static_cast<float>(i); }
|
||||
|
||||
std::size_t nb_volumes=0;
|
||||
for(auto itvol=lcc1.one_dart_per_cell<3>().begin(),
|
||||
itvolend=lcc1.one_dart_per_cell<3>().end(); itvol!=itvolend; ++itvol)
|
||||
++nb_volumes;
|
||||
{ ++nb_volumes; }
|
||||
|
||||
if(volume_scalars1.size() != nb_volumes) {
|
||||
volume_scalars1.clear();
|
||||
volume_scalars1.reserve(nb_volumes);
|
||||
for(auto itvol=lcc1.one_dart_per_cell<3>().begin(),
|
||||
itvolend = lcc1.one_dart_per_cell<3>().end(); itvol != itvolend; ++itvol) {
|
||||
auto d = lcc1.dart_descriptor(*itvol);
|
||||
std::size_t nbv = lcc1.template one_dart_per_incident_cell<0,3>(d).size();
|
||||
itvolend=lcc1.one_dart_per_cell<3>().end(); itvol!=itvolend; ++itvol)
|
||||
{
|
||||
std::size_t nbv=lcc1.template one_dart_per_incident_cell<0,3>(itvol).size();
|
||||
volume_scalars1.push_back(nbv);
|
||||
}
|
||||
|
||||
res=CGAL::IO::write_VTK(lcc1, "output.vtk",
|
||||
&vertex_scalars1, &volume_scalars1);
|
||||
if(!res)
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error write_VTK in test_file"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool ok_write = CGAL::IO::write_VTK<LCC,float,std::size_t>(lcc1, filename,
|
||||
&vertex_scalars1, &volume_scalars1);
|
||||
assert(ok_write);
|
||||
|
||||
|
||||
bool ok_read2 = CGAL::IO::read_VTK<LCC,float,std::size_t>(lcc2, filename,
|
||||
res=CGAL::IO::read_VTK(lcc2, "output.vtk",
|
||||
&vertex_scalars2, &volume_scalars2);
|
||||
assert(ok_read2);
|
||||
if(!res)
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error read_VTK 2 in test_file"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(lcc1.is_isomorphic_to(lcc2, false, true, true));
|
||||
assert(vertex_scalars1.size() == vertex_scalars2.size());
|
||||
assert(volume_scalars1.size() == volume_scalars2.size());
|
||||
for(std::size_t i=0;i<vertex_scalars1.size();++i)
|
||||
assert(vertex_scalars1[i] == vertex_scalars2[i]);
|
||||
for(std::size_t i=0;i<volume_scalars1.size();++i)
|
||||
assert(volume_scalars1[i] == volume_scalars2[i]);
|
||||
if(!lcc1.is_isomorphic_to(lcc2, false, true, true))
|
||||
{
|
||||
std::cout<<"LCC1: ";
|
||||
lcc1.display_characteristics(std::cout)<<std::endl;
|
||||
std::cout<<"LCC2: ";
|
||||
lcc2.display_characteristics(std::cout)<<std::endl;
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error lcc1 and lcc2 are not isomorphic in test_file"<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
if(vertex_scalars1!=vertex_scalars2)
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error vertex_scalars1 and vertex_scalars2 are different in test_file"<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
if(volume_scalars1!=volume_scalars2)
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error volume_scalars1 and volume_scalars2 are different in test_file"<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool test_different_scalars()
|
||||
{
|
||||
bool res=true;
|
||||
LCC lcc;
|
||||
std::vector<float> vertex_scalars;
|
||||
std::vector<std::size_t> volume_scalars;
|
||||
|
||||
/// Read the last file generated by test_file("data/beam-with-mixed-cells.vtk")
|
||||
/// i.e. beam-with-mixed-cells.vtk with point and cells scalars.
|
||||
if(!CGAL::IO::read_VTK(lcc, "output.vtk",
|
||||
&vertex_scalars, &volume_scalars) ||
|
||||
vertex_scalars.size()!=719 || volume_scalars.size()!=615)
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error read_VTK in test_different_scalars"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Test write with and without scalars
|
||||
if(!CGAL::IO::write_VTK(lcc, "output_vol.vtk", nullptr, &volume_scalars))
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error write_VTK 1 in test_different_scalars"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!CGAL::IO::write_VTK(lcc, "output_vertex.vtk", &vertex_scalars))
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error write_VTK 2 in test_different_scalars"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!CGAL::IO::write_VTK(lcc, "output_none.vtk"))
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error write_VTK 3 in test_different_scalars"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// test read with only some scalars
|
||||
if(!CGAL::IO::read_VTK(lcc, "output.vtk", &vertex_scalars) ||
|
||||
vertex_scalars.size()!=719)
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error read_VTK 2 in test_different_scalars"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!CGAL::IO::read_VTK(lcc, "output.vtk",
|
||||
nullptr, &volume_scalars) ||
|
||||
volume_scalars.size()!=615)
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error read_VTK 3 in test_different_scalars"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!CGAL::IO::read_VTK(lcc, "output.vtk"))
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error read_VTK 4 in test_different_scalars"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// test read all scalars when they are not in the file
|
||||
if(!CGAL::IO::read_VTK(lcc, "output_vertex.vtk", &vertex_scalars, &volume_scalars) ||
|
||||
vertex_scalars.size()!=719 || volume_scalars.size()!=0)
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error read_VTK 5 in test_different_scalars"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!CGAL::IO::read_VTK(lcc, "output_vol.vtk", &vertex_scalars, &volume_scalars) ||
|
||||
vertex_scalars.size()!=0 || volume_scalars.size()!=615)
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error read_VTK 6 in test_different_scalars"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!CGAL::IO::read_VTK(lcc, "output_none.vtk", &vertex_scalars, &volume_scalars) ||
|
||||
vertex_scalars.size()!=0 || volume_scalars.size()!=0)
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error read_VTK 7 in test_different_scalars"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
bool res=true;
|
||||
if(!test_file("data/2tetra.vtk"))
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error for file data/2tetra.vtk"<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
if(!test_file("data/2hexa.vtk"))
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error for file data/2hexa.vtk"<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
if(!test_file("data/2prism.vtk"))
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error for file data/2prism.vtk"<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
if(!test_file("data/2pyramid.vtk"))
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error for file data/2pyramid.vtk"<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
if(!test_file("data/2generic_cell.vtk"))
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error for file data/2generic_cell.vtk"<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
if(!test_file("data/beam-with-mixed-cells.vtk"))
|
||||
{
|
||||
std::cerr<<"[ERROR] LCC_vtk_io_test error for file data/beam-with-mixed-cells.vtk"<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
|
||||
if(!test_different_scalars())
|
||||
{ res=false; }
|
||||
|
||||
if(!res) { return EXIT_FAILURE; }
|
||||
|
||||
std::cout<<"[OK] all tests in Linear_cell_complex_vtk_io_test.cpp"<<std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
# vtk DataFile Version 2.0
|
||||
3D Mesh
|
||||
ASCII
|
||||
DATASET UNSTRUCTURED_GRID
|
||||
POINTS 21 double
|
||||
0.797233 -3.0657 2.80231
|
||||
1.04552 -2.81344 1.77789
|
||||
-0.00261142 -2.87459 1.50879
|
||||
-0.2509 -3.12685 2.53322
|
||||
0.682428 -3.76202 2.31634
|
||||
0.806573 -3.63589 1.80413
|
||||
0.282506 -3.66646 1.66958
|
||||
0.158362 -3.79259 2.1818
|
||||
0.567624 -4.45834 1.83037
|
||||
1.48429 0.147175 1.04918
|
||||
-0.357656 0.0397078 0.576288
|
||||
-0.146018 -1.80958 0.172206
|
||||
1.69593 -1.70211 0.645098
|
||||
-0.66619 -0.27376 1.84928
|
||||
-0.974724 -0.587227 3.12228
|
||||
-0.454552 -2.12305 1.4452
|
||||
-0.763086 -2.43652 2.7182
|
||||
1.38739 -2.01558 1.91809
|
||||
1.07886 -2.32905 3.19109
|
||||
1.17576 -0.166292 2.32218
|
||||
0.867223 -0.47976 3.59517
|
||||
|
||||
CELLS 2 115
|
||||
62 13 3 8 4 5 3 4 8 7 4 5 4 0 1 3 8 5 6 3 7 8 6 4 4 7 3 0 4 1 0 18 17 4 5 1 2 6 4 7 6 2 3 4 0 3 16 18 4 17 18 16 15 4 1 17 15 2 4 3 2 15 16
|
||||
51 10 4 9 19 13 10 4 19 9 12 17 4 13 19 20 14 4 10 13 15 11 4 9 10 11 12 4 17 12 11 15 4 19 17 18 20 4 14 20 18 16 4 13 14 16 15 4 17 15 16 18
|
||||
|
||||
CELL_TYPES 2
|
||||
42
|
||||
42
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
# vtk DataFile Version 2.0
|
||||
3D Mesh
|
||||
ASCII
|
||||
DATASET UNSTRUCTURED_GRID
|
||||
POINTS 12 double
|
||||
-1 -1 -1
|
||||
-1 1 -1
|
||||
-1 -1 1
|
||||
-1 1 1
|
||||
1 -1 -1
|
||||
1 1 -1
|
||||
1 -1 1
|
||||
1 1 1
|
||||
3 -1 1
|
||||
3 -1 -1
|
||||
3 1 1
|
||||
3 1 -1
|
||||
|
||||
CELLS 2 18
|
||||
8 0 1 3 2 4 5 7 6
|
||||
8 5 7 6 4 11 10 8 9
|
||||
|
||||
CELL_TYPES 2
|
||||
12
|
||||
12
|
||||
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
# vtk DataFile Version 2.0
|
||||
3D Mesh
|
||||
ASCII
|
||||
DATASET UNSTRUCTURED_GRID
|
||||
POINTS 14 double
|
||||
-1.78261 2.8477 -1.15226
|
||||
-1.6885 2.94623 2.26566
|
||||
0.921521 1.54537 2.23417
|
||||
1.01511 -1.41435 2.31691
|
||||
-1.59491 -0.0134989 2.3484
|
||||
0.920989 -1.51287 -1.10101
|
||||
-1.68903 -0.112022 -1.06953
|
||||
0.827405 1.44685 -1.18375
|
||||
0.921521 1.54537 2.23417
|
||||
1.01511 -1.41435 2.31691
|
||||
-1.59491 -0.0134989 2.3484
|
||||
0.920989 -1.51287 -1.10101
|
||||
-1.68903 -0.112022 -1.06953
|
||||
0.827405 1.44685 -1.18375
|
||||
|
||||
CELLS 3 21
|
||||
6 6 0 7 4 1 2
|
||||
6 2 4 3 7 6 5
|
||||
6 9 8 10 11 13 12
|
||||
|
||||
CELL_TYPES 3
|
||||
13
|
||||
13
|
||||
13
|
||||
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# vtk DataFile Version 2.0
|
||||
3D Mesh
|
||||
ASCII
|
||||
DATASET UNSTRUCTURED_GRID
|
||||
POINTS 7 double
|
||||
-0.149372 -0.608056 -1.19224
|
||||
-2.05784 -0.0940108 -3.6419
|
||||
-0.607052 -1.32749 -4.22213
|
||||
0.70406 0.167065 -4.12109
|
||||
-0.746726 1.40055 -3.54086
|
||||
-2.13885 -2.38807 -3.52093
|
||||
-1.35014 -2.31961 -1.69441
|
||||
|
||||
CELLS 2 12
|
||||
5 2 1 4 3 0
|
||||
5 2 0 6 5 1
|
||||
|
||||
CELL_TYPES 2
|
||||
14
|
||||
14
|
||||
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
# vtk DataFile Version 2.0
|
||||
CGAL Linear_cell_complex
|
||||
ASCII
|
||||
DATASET UNSTRUCTURED_GRID
|
||||
|
||||
POINTS 5 double
|
||||
-3.38189 0.624914 -0.442232
|
||||
-3.04657 -1.38801 -0.227267
|
||||
-1.24112 -0.450255 -0.494661
|
||||
-1.42311 -1.94845 0.895599
|
||||
-2.49044 0.337128 1.70461
|
||||
|
||||
CELLS 2 10
|
||||
4 1 0 4 2
|
||||
4 1 2 4 3
|
||||
|
||||
CELL_TYPES 2
|
||||
10
|
||||
10
|
||||
|
||||
POINT_DATA 5
|
||||
SCALARS point_scalars float 1
|
||||
LOOKUP_TABLE default
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
CELL_DATA 2
|
||||
SCALARS cell_scalars unsigned_long 1
|
||||
LOOKUP_TABLE default
|
||||
4
|
||||
4
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue