Add data/tests for GOCAD/OFF/OBJ

This commit is contained in:
Mael Rouxel-Labbé 2020-05-29 12:06:31 +02:00
parent 1809fc0e56
commit ef9ffb4fd6
3 changed files with 129 additions and 15 deletions

View File

@ -22,6 +22,9 @@ int main(int argc, char** argv)
assert(ok); assert(ok);
std::cout << points.size() << " points and " << polygons.size() << " polygons" << std::endl; std::cout << points.size() << " points and " << polygons.size() << " polygons" << std::endl;
if(argc == 0)
assert(points.size() == 12491 && polygons.size() == 24191);
points.clear(); points.clear();
polygons.clear(); polygons.clear();
std::string gocad_string(gocad_file); std::string gocad_string(gocad_file);

View File

@ -0,0 +1,68 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/IO/GOCAD.h>
#include <CGAL/IO/polygon_soup_io.h>
#include <iostream>
#include <fstream>
#include <vector>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point;
typedef std::vector<std::size_t> Face;
int main(int argc, char** argv)
{
const char* obj_file = (argc > 1) ? argv[1] : "data/90089.obj";
std::vector<Point> points;
std::vector<Face> polygons;
bool ok = CGAL::read_OBJ(obj_file, points, polygons);
assert(ok);
std::cout << points.size() << " points and " << polygons.size() << " polygons" << std::endl;
if(argc == 0)
assert(points.size() == 434 && polygons.size() == 864);
points.clear();
polygons.clear();
std::string obj_string(obj_file);
ok = CGAL::read_OBJ(obj_string, points, polygons);
assert(ok);
points.clear();
polygons.clear();
std::ifstream is(obj_file);
ok = CGAL::read_OBJ(is, points, polygons);
assert(ok);
is.close();
std::ofstream os("tmp.obj", std::ios::binary);
ok = CGAL::write_OBJ(os, points, polygons);
assert(ok);
os.close();
ok = CGAL::write_OBJ("tmp.obj", points, polygons);
assert(ok);
std::vector<Point> pts_backup = points;
std::vector<Face> pls_backup = polygons;
ok = CGAL::write_polygon_soup("tmp.obj", points, polygons);
assert(ok);
points.clear();
polygons.clear();
ok = CGAL::read_polygon_soup("tmp.obj", points, polygons);
assert(ok);
assert(points.size() == pts_backup.size());
for(std::size_t i=0; i<points.size(); ++i)
assert(CGAL::squared_distance(points[i], pts_backup[i]) < 1e-6);
assert(polygons == pls_backup);
std::cout << "Done!" << std::endl;
return EXIT_SUCCESS;
}

View File

@ -1,25 +1,68 @@
#include <iostream> #include <CGAL/Simple_cartesian.h>
#include <fstream>
#include <CGAL/IO/OFF.h> #include <CGAL/IO/OFF.h>
#include <CGAL/IO/polygon_soup_io.h>
#include <CGAL/Simple_cartesian.h> #include <fstream>
#include <iostream>
#include <vector> #include <vector>
typedef CGAL::Simple_cartesian<double> Kernel; typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point; typedef Kernel::Point_3 Point;
typedef std::vector<std::size_t> Face; typedef std::vector<std::size_t> Face;
int main()
int main(int argc, char** argv)
{ {
std::ifstream in("data/cube.off"); const char* off_file = (argc > 1) ? argv[1] : "data/cube.off";
std::vector<Point> points; std::vector<Point> points;
std::vector<Face> faces; std::vector<Face> polygons;
CGAL::read_OFF(in, points, faces);
in.close();
assert(points.size() == 8);
assert(faces.size() == 12);
assert(CGAL::write_OFF(std::cout, points, faces)); bool ok = CGAL::read_OFF(off_file, points, polygons);
assert(ok);
std::cout << points.size() << " points and " << polygons.size() << " polygons" << std::endl;
return 0; if(argc == 0)
assert(points.size() == 8 && polygons.size() == 12);
points.clear();
polygons.clear();
std::string off_string(off_file);
ok = CGAL::read_OFF(off_string, points, polygons);
assert(ok);
points.clear();
polygons.clear();
std::ifstream is(off_file);
ok = CGAL::read_OFF(is, points, polygons);
assert(ok);
is.close();
std::ofstream os("tmp.off", std::ios::binary);
ok = CGAL::write_OFF(os, points, polygons);
assert(ok);
os.close();
ok = CGAL::write_OFF("tmp.off", points, polygons);
assert(ok);
std::vector<Point> pts_backup = points;
std::vector<Face> pls_backup = polygons;
ok = CGAL::write_polygon_soup("tmp.off", points, polygons);
assert(ok);
points.clear();
polygons.clear();
ok = CGAL::read_polygon_soup("tmp.off", points, polygons);
assert(ok);
assert(points.size() == pts_backup.size());
for(std::size_t i=0; i<points.size(); ++i)
assert(CGAL::squared_distance(points[i], pts_backup[i]) < 1e-6);
assert(polygons == pls_backup);
std::cout << "Done!" << std::endl;
return EXIT_SUCCESS;
} }