diff --git a/CGAL_ImageIO/include/CGAL/Image_3.h b/CGAL_ImageIO/include/CGAL/Image_3.h index 8ede8eefec5..243f13068ed 100644 --- a/CGAL_ImageIO/include/CGAL/Image_3.h +++ b/CGAL_ImageIO/include/CGAL/Image_3.h @@ -28,6 +28,7 @@ #include #include #include +#include #if defined(BOOST_MSVC) # pragma warning(push) @@ -164,6 +165,11 @@ public: return private_read(::_readImage(file)); } + bool read(const std::string& file) + { + return read(file.c_str()); + } + bool read_raw(const char* file, const unsigned int rx, const unsigned int ry, diff --git a/CGAL_ImageIO/test/CGAL_ImageIO/test_trilinear_interpolation.cpp b/CGAL_ImageIO/test/CGAL_ImageIO/test_trilinear_interpolation.cpp index a3789dc632d..f4bdb80a1cb 100644 --- a/CGAL_ImageIO/test/CGAL_ImageIO/test_trilinear_interpolation.cpp +++ b/CGAL_ImageIO/test/CGAL_ImageIO/test_trilinear_interpolation.cpp @@ -191,28 +191,12 @@ int main() { image.set_data(nullptr); // trick to avoid ~Image_3 segfault. - const char* filenames[] = { - "data/skull_2.9.inr", - "../../examples/Surface_mesher/data/skull_2.9.inr", - "../../../Surface_mesher/examples/Surface_mesher/data/skull_2.9.inr", - "../Surface_mesher_Examples/data/skull_2.9.inr" - }; + const std::string filename = CGAL::data_file_path("images/skull_2.9.inr"); - std::size_t file_index = 0; - for( ; file_index < sizeof(filenames); ++file_index) - { - std::ifstream image_file(filenames[file_index], std::ios_base::binary | std::ios_base::in ); - if(image_file) { - break; - } - } - - assert(file_index < sizeof(filenames) ); - - std::cerr << "Opening file " << filenames[file_index] << "...\n"; + std::cerr << "Opening file " << filename << "...\n"; CGAL::Image_3 image2; - const bool result = image2.read(filenames[file_index]); + const bool result = image2.read(filename); assert(result); std::cerr << "Image info:" diff --git a/Mesh_3/examples/Mesh_3/data/12323.inr b/Data/data/images/12323.inr similarity index 100% rename from Mesh_3/examples/Mesh_3/data/12323.inr rename to Data/data/images/12323.inr diff --git a/Mesh_3/examples/Mesh_3/data/20012323.inr b/Data/data/images/20012323.inr similarity index 100% rename from Mesh_3/examples/Mesh_3/data/20012323.inr rename to Data/data/images/20012323.inr diff --git a/Mesh_3/examples/Mesh_3/data/40420.inr b/Data/data/images/40420.inr similarity index 100% rename from Mesh_3/examples/Mesh_3/data/40420.inr rename to Data/data/images/40420.inr diff --git a/Mesh_3/examples/Mesh_3/data/420.inr b/Data/data/images/420.inr similarity index 100% rename from Mesh_3/examples/Mesh_3/data/420.inr rename to Data/data/images/420.inr diff --git a/Mesh_3/examples/Mesh_3/data/420.polylines.txt b/Data/data/images/420.polylines.txt similarity index 100% rename from Mesh_3/examples/Mesh_3/data/420.polylines.txt rename to Data/data/images/420.polylines.txt diff --git a/Mesh_3/examples/Mesh_3/data/liver.inr.gz b/Data/data/images/liver.inr.gz similarity index 100% rename from Mesh_3/examples/Mesh_3/data/liver.inr.gz rename to Data/data/images/liver.inr.gz diff --git a/CGAL_ImageIO/test/CGAL_ImageIO/data/skull_2.9.inr b/Data/data/images/skull_2.9.inr similarity index 100% rename from CGAL_ImageIO/test/CGAL_ImageIO/data/skull_2.9.inr rename to Data/data/images/skull_2.9.inr diff --git a/Mesh_3/examples/Mesh_3/data/small-scalar.inr b/Data/data/images/small-scalar.inr similarity index 100% rename from Mesh_3/examples/Mesh_3/data/small-scalar.inr rename to Data/data/images/small-scalar.inr diff --git a/Documentation/doc/Documentation/CGAL/config.h b/Documentation/doc/Documentation/CGAL/config.h new file mode 100644 index 00000000000..8c45f77d309 --- /dev/null +++ b/Documentation/doc/Documentation/CGAL/config.h @@ -0,0 +1,13 @@ +namespace CGAL{ +/// returns the full path of a data file from \cgal. +/// The data files are located in the `data` directory of a \cgal release +/// or in the directory `Data/data` from a git branch checkout. +/// That function uses as prefix the environment variable `CGAL_DATA_DIR` if set, and +/// the value of the macro `CGAL_DATA_DIR` otherwise. +/// When using `cmake` and a standard \cgal setup, linking the target using that function +/// with the target `CGAL::Data` will automatically set the macro `CGAL_DATA_DIR` +/// pointing to the data directory of the \cgal version used. +/// The function will attempt to open the file at the returned location +/// and will print a warning message via `std::cerr` if the file could not be opened. +std::string data_file_path(const std::string& filename); +} diff --git a/Mesh_3/examples/Mesh_3/data/skull_2.9.inr b/Mesh_3/examples/Mesh_3/data/skull_2.9.inr deleted file mode 100644 index d8dc23e59d9..00000000000 Binary files a/Mesh_3/examples/Mesh_3/data/skull_2.9.inr and /dev/null differ diff --git a/Mesh_3/examples/Mesh_3/mesh_3D_gray_image.cpp b/Mesh_3/examples/Mesh_3/mesh_3D_gray_image.cpp index 222fe1cf4c3..40dddc6a1a9 100644 --- a/Mesh_3/examples/Mesh_3/mesh_3D_gray_image.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_3D_gray_image.cpp @@ -28,7 +28,7 @@ using namespace CGAL::parameters; int main(int argc, char*argv[]) { - const char* fname = (argc>1)?argv[1]:"data/skull_2.9.inr"; + const std::string fname = (argc>1)?argv[1]:CGAL::data_file_path("images/skull_2.9.inr"); // Load image CGAL::Image_3 image; if(!image.read(fname)){ diff --git a/Mesh_3/examples/Mesh_3/mesh_3D_gray_image_multiple_values.cpp b/Mesh_3/examples/Mesh_3/mesh_3D_gray_image_multiple_values.cpp index bd75587d29d..3ead928edf7 100644 --- a/Mesh_3/examples/Mesh_3/mesh_3D_gray_image_multiple_values.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_3D_gray_image_multiple_values.cpp @@ -42,7 +42,7 @@ struct Image_to_multiple_iso_level_sets { int main(int argc, char*argv[]) { - const char* fname = (argc>1)?argv[1]:"data/skull_2.9.inr"; + const std::string fname = (argc>1)?argv[1]:CGAL::data_file_path("images/skull_2.9.inr"); // Load image CGAL::Image_3 image; if(!image.read(fname)){ diff --git a/Mesh_3/examples/Mesh_3/mesh_3D_gray_image_with_custom_initialization.cpp b/Mesh_3/examples/Mesh_3/mesh_3D_gray_image_with_custom_initialization.cpp index 533637a3f75..86edd7f2e78 100644 --- a/Mesh_3/examples/Mesh_3/mesh_3D_gray_image_with_custom_initialization.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_3D_gray_image_with_custom_initialization.cpp @@ -37,7 +37,7 @@ using namespace CGAL::parameters; int main(int argc, char* argv[]) { - const char* fname = (argc > 1) ? argv[1] : "data/skull_2.9.inr"; + const std::string fname = (argc > 1) ? argv[1] : CGAL::data_file_path("images/skull_2.9.inr"); /// [Load image] CGAL::Image_3 image; if (!image.read(fname)) { diff --git a/Mesh_3/examples/Mesh_3/mesh_3D_image.cpp b/Mesh_3/examples/Mesh_3/mesh_3D_image.cpp index c7dad626119..d573dde7c96 100644 --- a/Mesh_3/examples/Mesh_3/mesh_3D_image.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_3D_image.cpp @@ -32,7 +32,7 @@ using namespace CGAL::parameters; int main(int argc, char* argv[]) { /// [Loads image] - const char* fname = (argc>1)?argv[1]:"data/liver.inr.gz"; + const std::string fname = (argc>1)?argv[1]:CGAL::data_file_path("images/liver.inr.gz"); CGAL::Image_3 image; if(!image.read(fname)){ std::cerr << "Error: Cannot read file " << fname << std::endl; diff --git a/Mesh_3/examples/Mesh_3/mesh_3D_image_variable_size.cpp b/Mesh_3/examples/Mesh_3/mesh_3D_image_variable_size.cpp index 150a2ac74ec..051f07dba4c 100644 --- a/Mesh_3/examples/Mesh_3/mesh_3D_image_variable_size.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_3D_image_variable_size.cpp @@ -36,7 +36,7 @@ using namespace CGAL::parameters; int main(int argc, char* argv[]) { - const char* fname = (argc>1)?argv[1]:"data/liver.inr.gz"; + const std::string fname = (argc>1)?argv[1]:CGAL::data_file_path("images/liver.inr.gz"); // Loads image CGAL::Image_3 image; if(!image.read(fname)){ diff --git a/Mesh_3/examples/Mesh_3/mesh_3D_image_with_features.cpp b/Mesh_3/examples/Mesh_3/mesh_3D_image_with_features.cpp index e2334150529..3f8a0fe362a 100644 --- a/Mesh_3/examples/Mesh_3/mesh_3D_image_with_features.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_3D_image_with_features.cpp @@ -44,7 +44,7 @@ using namespace CGAL::parameters; // not documented. bool add_1D_features(const CGAL::Image_3& image, Mesh_domain& domain, - const char* lines_fname) + const std::string lines_fname) { typedef K::Point_3 Point_3; typedef unsigned char Word_type; @@ -72,7 +72,7 @@ bool add_1D_features(const CGAL::Image_3& image, int main(int argc, char* argv[]) { - const char* fname = (argc>1)?argv[1]:"data/420.inr"; + const std::string fname = (argc>1)?argv[1]:CGAL::data_file_path("images/420.inr"); // Loads image CGAL::Image_3 image; if(!image.read(fname)){ @@ -84,7 +84,7 @@ int main(int argc, char* argv[]) Mesh_domain domain = Mesh_domain::create_labeled_image_mesh_domain(image); /// Declare 1D-features, see above [Call add_1D_features] - const char* lines_fname = (argc>2)?argv[2]:"data/420.polylines.txt"; + const std::string lines_fname = (argc>2)?argv[2]:CGAL::data_file_path("images/420.polylines.txt"); if(!add_1D_features(image, domain, lines_fname)) { return EXIT_FAILURE; diff --git a/Mesh_3/examples/Mesh_3/mesh_optimization_example.cpp b/Mesh_3/examples/Mesh_3/mesh_optimization_example.cpp index 065fcae0d87..9f72d6c276a 100644 --- a/Mesh_3/examples/Mesh_3/mesh_optimization_example.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_optimization_example.cpp @@ -31,7 +31,7 @@ using namespace CGAL::parameters; int main(int argc, char* argv[]) { - const char* fname = (argc>1)?argv[1]:"data/liver.inr.gz"; + const std::string fname = (argc>1)?argv[1]:CGAL::data_file_path("images/liver.inr.gz"); // Domain CGAL::Image_3 image; if(!image.read(fname)){ diff --git a/Mesh_3/examples/Mesh_3/mesh_optimization_lloyd_example.cpp b/Mesh_3/examples/Mesh_3/mesh_optimization_lloyd_example.cpp index 881cd143ad4..e4a6e6a5dcb 100644 --- a/Mesh_3/examples/Mesh_3/mesh_optimization_lloyd_example.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_optimization_lloyd_example.cpp @@ -31,7 +31,7 @@ using namespace CGAL::parameters; int main(int argc, char*argv[]) { - const char* fname = (argc>1)?argv[1]:"data/liver.inr.gz"; + const std::string fname = (argc>1)?argv[1]:CGAL::data_file_path("images/liver.inr.gz"); // Domain CGAL::Image_3 image; if(!image.read(fname)){ diff --git a/Mesh_3/examples/Mesh_3/read_polylines.h b/Mesh_3/examples/Mesh_3/read_polylines.h index 54d1203b2f2..082c1ae4410 100644 --- a/Mesh_3/examples/Mesh_3/read_polylines.h +++ b/Mesh_3/examples/Mesh_3/read_polylines.h @@ -6,7 +6,7 @@ #include template -bool read_polylines(const char* fname, +bool read_polylines(const std::string fname, std::vector >& polylines) { std::ifstream ifs(fname); diff --git a/Mesh_3/test/Mesh_3/data/liver.inr.gz b/Mesh_3/test/Mesh_3/data/liver.inr.gz deleted file mode 100644 index 9eb7a60fdfe..00000000000 Binary files a/Mesh_3/test/Mesh_3/data/liver.inr.gz and /dev/null differ diff --git a/Mesh_3/test/Mesh_3/data/skull_2.9.inr b/Mesh_3/test/Mesh_3/data/skull_2.9.inr deleted file mode 100644 index d8dc23e59d9..00000000000 Binary files a/Mesh_3/test/Mesh_3/data/skull_2.9.inr and /dev/null differ diff --git a/Mesh_3/test/Mesh_3/test_meshing_3D_gray_image.cpp b/Mesh_3/test/Mesh_3/test_meshing_3D_gray_image.cpp index 4b232d42d20..191ea47fafa 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_3D_gray_image.cpp +++ b/Mesh_3/test/Mesh_3/test_meshing_3D_gray_image.cpp @@ -55,7 +55,7 @@ public: // Data generation //------------------------------------------------------- Image image; - if (!image.read("data/skull_2.9.inr")) + if (!image.read(CGAL::data_file_path("images/skull_2.9.inr"))) { std::cout << "Image reading error. Exit test.\n"; return; diff --git a/Mesh_3/test/Mesh_3/test_meshing_3D_gray_image_deprecated.cpp b/Mesh_3/test/Mesh_3/test_meshing_3D_gray_image_deprecated.cpp index 89fa946ff26..b2ba365111f 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_3D_gray_image_deprecated.cpp +++ b/Mesh_3/test/Mesh_3/test_meshing_3D_gray_image_deprecated.cpp @@ -48,7 +48,7 @@ public: // Data generation //------------------------------------------------------- Image image; - if (!image.read("data/skull_2.9.inr")) + if (!image.read(CGAL::data_file_path("images/skull_2.9.inr"))) { std::cout << "Image reading error. Exit test.\n"; return; diff --git a/Mesh_3/test/Mesh_3/test_meshing_3D_image.cpp b/Mesh_3/test/Mesh_3/test_meshing_3D_image.cpp index 471112ef772..62efe80cde0 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_3D_image.cpp +++ b/Mesh_3/test/Mesh_3/test_meshing_3D_image.cpp @@ -42,7 +42,7 @@ public: // Data generation //------------------------------------------------------- Image image; - image.read("data/liver.inr.gz"); + image.read(CGAL::data_file_path("images/liver.inr.gz")); std::cout << "\tSeed is\t" << CGAL::get_default_random().get_seed() << std::endl; diff --git a/Mesh_3/test/Mesh_3/test_meshing_3D_image_deprecated.cpp b/Mesh_3/test/Mesh_3/test_meshing_3D_image_deprecated.cpp index ac8e39f21df..ed1a1fbd14b 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_3D_image_deprecated.cpp +++ b/Mesh_3/test/Mesh_3/test_meshing_3D_image_deprecated.cpp @@ -29,7 +29,7 @@ public: // Data generation //------------------------------------------------------- Image image; - image.read("data/liver.inr.gz"); + image.read(CGAL::data_file_path("images/liver.inr.gz")); std::cout << "\tSeed is\t" << CGAL::get_default_random().get_seed() << std::endl; diff --git a/Surface_mesher/examples/Surface_mesher/data/skull_2.9.inr b/Surface_mesher/examples/Surface_mesher/data/skull_2.9.inr deleted file mode 100644 index d8dc23e59d9..00000000000 Binary files a/Surface_mesher/examples/Surface_mesher/data/skull_2.9.inr and /dev/null differ diff --git a/Surface_mesher/examples/Surface_mesher/mesh_a_3d_gray_image.cpp b/Surface_mesher/examples/Surface_mesher/mesh_a_3d_gray_image.cpp index 5373cf751cd..00508fc121b 100644 --- a/Surface_mesher/examples/Surface_mesher/mesh_a_3d_gray_image.cpp +++ b/Surface_mesher/examples/Surface_mesher/mesh_a_3d_gray_image.cpp @@ -22,7 +22,7 @@ int main() { C2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation // the 'function' is a 3D gray level image - Gray_level_image image("data/skull_2.9.inr", 2.9f); + Gray_level_image image(CGAL::data_file_path("images/skull_2.9.inr"), 2.9f); // Carefully chosen bounding sphere: the center must be inside the // surface defined by 'image' and the radius must be high enough so that diff --git a/Surface_mesher/include/CGAL/Gray_level_image_3.h b/Surface_mesher/include/CGAL/Gray_level_image_3.h index 5cf37cd2c28..64c00a06f3f 100644 --- a/Surface_mesher/include/CGAL/Gray_level_image_3.h +++ b/Surface_mesher/include/CGAL/Gray_level_image_3.h @@ -20,6 +20,7 @@ #include #include +#include #ifdef CGAL_SURFACE_MESHER_DEBUG_GRAY_LEVEL_IMAGE_3_CONSTRUCTOR #include @@ -44,7 +45,7 @@ public: { } - Gray_level_image_3(const char* file, float isoval, bool positive_inside_=true, float value_outside = 0.f) + Gray_level_image_3(const std::string& file, float isoval, bool positive_inside_=true, float value_outside = 0.f) : Image_3(), isovalue(isoval), positive_inside(positive_inside_), diff --git a/Tetrahedral_remeshing/test/Tetrahedral_remeshing/data/liver.inr.gz b/Tetrahedral_remeshing/test/Tetrahedral_remeshing/data/liver.inr.gz deleted file mode 100644 index 1b711130c11..00000000000 Binary files a/Tetrahedral_remeshing/test/Tetrahedral_remeshing/data/liver.inr.gz and /dev/null differ diff --git a/Tetrahedral_remeshing/test/Tetrahedral_remeshing/test_mesh_and_remesh_image.cpp b/Tetrahedral_remeshing/test/Tetrahedral_remeshing/test_mesh_and_remesh_image.cpp index 890a018d2fb..cf75b94c0a5 100644 --- a/Tetrahedral_remeshing/test/Tetrahedral_remeshing/test_mesh_and_remesh_image.cpp +++ b/Tetrahedral_remeshing/test/Tetrahedral_remeshing/test_mesh_and_remesh_image.cpp @@ -32,7 +32,7 @@ using namespace CGAL::parameters; int main() { - const char* filename = "data/liver.inr.gz"; + const std::string filename = CGAL::data_file_path("images/liver.inr.gz"); CGAL::Image_3 image; if (!image.read(filename)) {