Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CGAL_ImageIO/include/CGAL/Image_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <limits>
#include <set>
#include <cstdlib>
#include <string>

#if defined(BOOST_MSVC)
# pragma warning(push)
Expand Down Expand Up @@ -164,6 +165,11 @@ class CGAL_IMAGEIO_EXPORT Image_3
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,
Expand Down
22 changes: 3 additions & 19 deletions CGAL_ImageIO/test/CGAL_ImageIO/test_trilinear_interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};

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) );
const std::string filename = CGAL::data_file_path("images/skull_2.9.inr");

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:"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions Documentation/doc/Documentation/CGAL/config.h
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lrineau @gdamiand @MaelRL @afabri I'd appreciate a review of this paragraph

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would that to be tested, in various configurations. In particular, I wonder what happens if CGAL is installed. Are data installed as well, and where?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would that to be tested, in various configurations. In particular, I wonder what happens if CGAL is installed. Are data installed as well, and where?

It can be tested in Installation/test/Installation/test_configuration.cpp: that file is compiled and run in a lot of various configuration/installation of CGAL, both in the CI (for the Git layout), and in the testsuite (for releases layout).

Copy link
Copy Markdown
Member Author

@sloriot sloriot Oct 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply add a thumb up if you don't have any comment so that we know that it has been reviewed.

See also the text added in the developer wiki:
https://github.com/CGAL/cgal/wiki/Directory-Structure-for-Packages#shared-data-directory

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply add a thumb up if you don't have any comment so that we know that it has been reviewed.

See also the text added in the developer wiki: CGAL/cgal/wiki/Directory-Structure-for-Packages#shared-data-directory

My review of the wiki section led to the fix of a typo: https://github.com/CGAL/cgal/wiki/Directory-Structure-for-Packages/_compare/4545a717e0e2802299b894ec3a6c9b96adf0ace3...8fb212d5989c65b1274386f1096232cda485323e

Copy link
Copy Markdown
Member Author

@sloriot sloriot Oct 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lrineau I agree but it does not have anything to do with the review of the doc (or maybe you want to know what I meant by standard). Examples are not installed so neither will data be. About the -example packages of linux distributions, I haven't done anything but with your feedback and @joachim-reichel 's I can update scripts accordingly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me sketch my idea for .deb packaging: Since data files are only used by demos/examples (tests are not included in the tarball), I would probably not ship them with the library/header packages, but in the -example package (actually libcgal-demo). This package contains two tarballs for the demos/examples, and I would probably add another one for the data files. The user can extract them anywhere on the system (probably in the home directory). Will the data directory be automatically found, if "data" is e.g. next to "examples" (as in a tarball layout)? (There will be only the "examples"/"demo" and "data" directory trees, everything else is either installed or not present at all.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, the cases of automatic detection of data dir are only done with reference to the CGAL_DIR (be it a branch checkout or a regular release). I guess we can probably add another fallback rule based on CMAKE_SOURCE_DIR. Thinking about it, I'm in favor of adding another rule only if the data dir is in the same archive as the examples so that the layout is somehow imposed. What do you think?

Copy link
Copy Markdown
Member Author

@sloriot sloriot Oct 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joachim-reichel @lrineau what should we do?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the data files should be in the same tarball as the examples, and in the same component of the CMake installation rules.

And the automatic detection should work:

  • when CGAL is installed, with or without examples,
  • or when a user decompress the examples tarball in the home directory.

}
Binary file removed Mesh_3/examples/Mesh_3/data/skull_2.9.inr
Binary file not shown.
2 changes: 1 addition & 1 deletion Mesh_3/examples/Mesh_3/mesh_3D_gray_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion Mesh_3/examples/Mesh_3/mesh_3D_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Mesh_3/examples/Mesh_3/mesh_3D_image_variable_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down
6 changes: 3 additions & 3 deletions Mesh_3/examples/Mesh_3/mesh_3D_image_with_features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)){
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Mesh_3/examples/Mesh_3/mesh_optimization_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down
2 changes: 1 addition & 1 deletion Mesh_3/examples/Mesh_3/mesh_optimization_lloyd_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down
2 changes: 1 addition & 1 deletion Mesh_3/examples/Mesh_3/read_polylines.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <fstream>

template <typename Point_3>
bool read_polylines(const char* fname,
bool read_polylines(const std::string fname,
std::vector<std::vector<Point_3> >& polylines)
{
std::ifstream ifs(fname);
Expand Down
Binary file removed Mesh_3/test/Mesh_3/data/liver.inr.gz
Binary file not shown.
Binary file removed Mesh_3/test/Mesh_3/data/skull_2.9.inr
Binary file not shown.
2 changes: 1 addition & 1 deletion Mesh_3/test/Mesh_3/test_meshing_3D_gray_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct Image_tester : public Tester<K_e_i>
// 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Image_tester : public Tester<K_e_i>
// 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;
Expand Down
2 changes: 1 addition & 1 deletion Mesh_3/test/Mesh_3/test_meshing_3D_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct Image_tester : public Tester<K_e_i>
// 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;
Expand Down
2 changes: 1 addition & 1 deletion Mesh_3/test/Mesh_3/test_meshing_3D_image_deprecated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct Image_tester : public Tester<K_e_i>
// 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;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Surface_mesher/include/CGAL/Gray_level_image_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <CGAL/auto_link/ImageIO.h>

#include <memory>
#include <string>

#ifdef CGAL_SURFACE_MESHER_DEBUG_GRAY_LEVEL_IMAGE_3_CONSTRUCTOR
#include <boost/format.hpp>
Expand All @@ -44,7 +45,7 @@ class Gray_level_image_3 : public Image_3
{
}

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_),
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down