fixes in vtp

This commit is contained in:
Maxime Gimeno 2020-04-24 12:45:55 +02:00
parent 6e309fa34b
commit a2a1ebde39
3 changed files with 35 additions and 23 deletions

View File

@ -239,7 +239,7 @@ void write_polys_tag(std::ostream& os,
} }
else else
{ {
os << "\">\n"; os << ">\n";
for(face_descriptor f : faces(g)) for(face_descriptor f : faces(g))
{ {
@ -260,7 +260,7 @@ void write_polys_tag(std::ostream& os,
} }
else else
{ {
os << "\">\n"; os << ">\n";
std::size_t polys_offset = 0; std::size_t polys_offset = 0;
for(face_descriptor f : faces(g)) for(face_descriptor f : faces(g))
@ -283,7 +283,7 @@ void write_polys_tag(std::ostream& os,
} }
else else
{ {
os << "\">\n"; os << ">\n";
for(std::size_t i = 0; i< num_faces(g); ++i) for(std::size_t i = 0; i< num_faces(g); ++i)
os << "5 "; os << "5 ";
os << " </DataArray>\n"; os << " </DataArray>\n";

View File

@ -55,14 +55,14 @@ void test_bgl_read_write(const char* filename)
#ifdef CGAL_USE_VTK #ifdef CGAL_USE_VTK
template<typename Mesh> template<typename Mesh>
bool test_bgl_vtp() bool test_bgl_vtp(bool binary = false)
{ {
Mesh fg; Mesh fg;
CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0),
Point(2, 0, 1), Point(3, 0, 0), fg); Point(2, 0, 1), Point(3, 0, 0), fg);
std::ofstream os("tetrahedron.vtp"); std::ofstream os("tetrahedron.vtp");
CGAL::write_VTP(os, fg); CGAL::write_VTP(os, fg, CGAL::parameters::use_binary_mode(binary));
if(!os) if(!os)
{ {
std::cerr<<"vtp writing failed."<<std::endl; std::cerr<<"vtp writing failed."<<std::endl;
@ -86,7 +86,7 @@ bool test_bgl_vtp()
} }
template<> template<>
bool test_bgl_vtp<Polyhedron>() bool test_bgl_vtp<Polyhedron>(bool binary)
{ {
Polyhedron fg; Polyhedron fg;
CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0),
@ -98,7 +98,7 @@ bool test_bgl_vtp<Polyhedron>()
for(auto v : vertices(fg)) for(auto v : vertices(fg))
put(vid,v, id++); put(vid,v, id++);
std::ofstream os("tetrahedron.vtp"); std::ofstream os("tetrahedron.vtp");
CGAL::write_VTP(os, fg, CGAL::parameters::vertex_index_map(vid)); CGAL::write_VTP(os, fg, CGAL::parameters::vertex_index_map(vid).use_binary_mode(binary));
if(!os) if(!os)
{ {
std::cerr<<"vtp writing failed."<<std::endl; std::cerr<<"vtp writing failed."<<std::endl;
@ -121,7 +121,7 @@ bool test_bgl_vtp<Polyhedron>()
} }
//todo binary tests //todo binary tests
bool test_soup_vtp() bool test_soup_vtp(bool binary = false)
{ {
//generate a test file //generate a test file
std::vector<Point> points(4); std::vector<Point> points(4);
@ -149,7 +149,7 @@ bool test_soup_vtp()
polys[3] = poly; polys[3] = poly;
std::ofstream os("tetrahedron_soup.vtp"); std::ofstream os("tetrahedron_soup.vtp");
CGAL::write_VTP(os, points, polys); CGAL::write_VTP(os, points, polys, CGAL::parameters::use_binary_mode(binary));
if(!os) if(!os)
{ {
std::cerr<<"vtp writing failed."<<std::endl; std::cerr<<"vtp writing failed."<<std::endl;
@ -322,7 +322,7 @@ bool test_PLY(bool binary = false)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
const char* filename=(argc>1) ? argv[1] : "data/prim.off"; const char* filename=(argc>1) ? argv[1] : "data/prim.off";
/*
//PLY //PLY
if(!test_PLY<Polyhedron>()) if(!test_PLY<Polyhedron>())
return 1; return 1;
@ -355,16 +355,25 @@ int main(int argc, char** argv)
return 1; return 1;
if(!test_STL<LCC>()) if(!test_STL<LCC>())
return 1; return 1;
*/
// VTP // VTP
#ifdef CGAL_USE_VTK #ifdef CGAL_USE_VTK
if(!test_bgl_vtp<Polyhedron>()) if(!test_bgl_vtp<Polyhedron>(false))
return 1; return 1;
if(!test_bgl_vtp<SM>()) if(!test_bgl_vtp<SM>(false))
return 1; return 1;
if(!test_bgl_vtp<LCC>()) if(!test_bgl_vtp<LCC>(false))
return 1; return 1;
if(!test_soup_vtp()) if(!test_soup_vtp(false))
return 1;
if(!test_bgl_vtp<Polyhedron>(true))
return 1;
if(!test_bgl_vtp<SM>(true))
return 1;
if(!test_bgl_vtp<LCC>(true))
return 1;
if(!test_soup_vtp(true))
return 1; return 1;
#endif #endif

View File

@ -152,17 +152,20 @@ void write_soup_polys(std::ostream& os,
{ {
std::vector<std::size_t> connectivity_table; std::vector<std::size_t> connectivity_table;
std::size_t off = 0; std::size_t off = 0;
std::vector<std::size_t> cumul_offsets(offsets);
for(const auto& poly : polygons) for(size_t i = 0; i < polygons.size(); ++i)
{ {
const auto& poly = polygons[i];
off+=offsets[i];
cumul_offsets[i]=off;
for(const std::size_t& i : poly) for(const std::size_t& i : poly)
connectivity_table.push_back(i); connectivity_table.push_back(i);
} }
write_vector<std::size_t>(os, connectivity_table); write_vector<std::size_t>(os, connectivity_table);
write_vector<std::size_t>(os, offsets); write_vector<std::size_t>(os, cumul_offsets);
write_vector<unsigned char>(os, cell_type); write_vector<unsigned char>(os, cell_type);
} }
@ -230,8 +233,8 @@ void write_soup_polys_tag(std::ostream& os,
for(std::size_t i = 0; i < polygons.size(); ++i) for(std::size_t i = 0; i < polygons.size(); ++i)
{ {
size_map[i] = polygons[i].size(); size_map[i] = polygons[i].size();
CGAL_assertion(size_map.back()>=3); CGAL_assertion(size_map[i]>=3);
total_size +=size_map.back(); total_size +=size_map[i];
} }
// if binary output, just write the xml tag // if binary output, just write the xml tag
@ -243,7 +246,7 @@ void write_soup_polys_tag(std::ostream& os,
} }
else else
{ {
os << "\">\n"; os << ">\n";
for(const auto& poly : polygons) for(const auto& poly : polygons)
{ {
@ -264,7 +267,7 @@ void write_soup_polys_tag(std::ostream& os,
} }
else else
{ {
os << "\">\n"; os << ">\n";
std::size_t polys_offset = 0; std::size_t polys_offset = 0;
for(std::size_t i = 0; i < polygons.size(); ++i) for(std::size_t i = 0; i < polygons.size(); ++i)
@ -287,7 +290,7 @@ void write_soup_polys_tag(std::ostream& os,
} }
else else
{ {
os << "\">\n"; os << ">\n";
for(std::size_t i = 0; i< polygons.size(); ++i) for(std::size_t i = 0; i< polygons.size(); ++i)
{ {
switch(size_map[i]){ switch(size_map[i]){