From 06eb921215157f846e04a698438b1a5a8639a40a Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Mon, 20 Oct 2014 12:39:03 +0200 Subject: [PATCH 01/13] fix the use of integers patch suggested by Bryn Lloyd on cgal-discuss to avoid an integer overflow problem that occurs when generating a 3D mesh from very large images --- CGAL_ImageIO/include/CGAL/Image_3.h | 24 +++++++++---------- .../Image_to_labeled_function_wrapper.h | 6 ++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CGAL_ImageIO/include/CGAL/Image_3.h b/CGAL_ImageIO/include/CGAL/Image_3.h index 4fea8f4e90b..3050dcfb774 100644 --- a/CGAL_ImageIO/include/CGAL/Image_3.h +++ b/CGAL_ImageIO/include/CGAL/Image_3.h @@ -32,7 +32,7 @@ #include #include - +#include #if defined(BOOST_MSVC) # pragma warning(push) @@ -124,11 +124,11 @@ public: image()->data = d; } - unsigned int xdim() const { return image_ptr->xdim; } - unsigned int ydim() const { return image_ptr->ydim; } - unsigned int zdim() const { return image_ptr->zdim; } + std::size_t xdim() const { return image_ptr->xdim; } + std::size_t ydim() const { return image_ptr->ydim; } + std::size_t zdim() const { return image_ptr->zdim; } - unsigned int size() const { return xdim() * ydim() * zdim(); } + std::size_t size() const { return xdim() * ydim() * zdim(); } double vx() const { return image_ptr->vx; } double vy() const { return image_ptr->vy; } @@ -237,10 +237,10 @@ Image_3::trilinear_interpolation(const Coord_type& x, const Coord_type lx = x / image()->vx; const Coord_type ly = y / image()->vy; const Coord_type lz = z / image()->vz; - const int dimx = xdim(); - const int dimy = ydim(); - const int dimz = zdim(); - const int dimxy = dimx*dimy; + const std::size_t dimx = xdim(); + const std::size_t dimy = ydim(); + const std::size_t dimz = zdim(); + const std::size_t dimxy = dimx*dimy; if(lx < 0 || ly < 0 || @@ -425,9 +425,9 @@ Image_3::labellized_trilinear_interpolation(const Coord_type& x, Coord_type lx = x / image()->vx; Coord_type ly = y / image()->vy; Coord_type lz = z / image()->vz; - const int dimx = xdim(); - const int dimy = ydim(); - const int dimz = zdim(); + const std::size_t dimx = xdim(); + const std::size_t dimy = ydim(); + const std::size_t dimz = zdim(); if( lx < 0 || ly < 0 || diff --git a/Mesh_3/include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h b/Mesh_3/include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h index 2bc4051397e..8b95beb6417 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h +++ b/Mesh_3/include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h @@ -86,9 +86,9 @@ public: const int py = static_cast(p.y()/r_im_.vy()); const int pz = static_cast(p.z()/r_im_.vz()); - const int dimx = r_im_.xdim(); - const int dimy = r_im_.ydim(); - const int dimz = r_im_.zdim(); + const std::size_t dimx = r_im_.xdim(); + const std::size_t dimy = r_im_.ydim(); + const std::size_t dimz = r_im_.zdim(); if(px < 0 || py < 0 || From b4a8992e2a3c6b12de07470d7ad3f7c2f2336fa2 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Mon, 20 Oct 2014 13:06:33 +0200 Subject: [PATCH 02/13] complete the use of std::size_t instead of unsigned int in Image_IO --- CGAL_ImageIO/include/CGAL/ImageIO.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/CGAL_ImageIO/include/CGAL/ImageIO.h b/CGAL_ImageIO/include/CGAL/ImageIO.h index 0ae846c772f..50b64465135 100644 --- a/CGAL_ImageIO/include/CGAL/ImageIO.h +++ b/CGAL_ImageIO/include/CGAL/ImageIO.h @@ -211,13 +211,13 @@ typedef struct imformat { /** Image descriptor */ typedef struct point_image { /** Image x dimension (number of columns) */ - unsigned int xdim; + std::size_t xdim; /** Image y dimension (number of rows) */ - unsigned int ydim; + std::size_t ydim; /** Image z dimension (number of planes) */ - unsigned int zdim; + std::size_t zdim; /** Image vectorial dimension */ - unsigned int vdim; + std::size_t vdim; /** Image voxel size in x dimension */ double vx; @@ -599,13 +599,13 @@ struct Word_type_generator typedef boost::uint32_t type; }; -template +template inline typename Word_type_generator::type static_evaluate(const _image* image, - const unsigned int i, - const unsigned int j, - const unsigned int k) + const std::size_t i, + const std::size_t j, + const std::size_t k) { typedef typename Word_type_generator::type Word; @@ -616,9 +616,9 @@ template inline Word static_evaluate(const _image* image, - const unsigned int i, - const unsigned int j, - const unsigned int k) + const std::size_t i, + const std::size_t j, + const std::size_t k) { return ((Word*)image->data)[(k * image->ydim + j) * image->xdim + i]; } @@ -693,7 +693,7 @@ static_evaluate(const _image* image, break; \ } -CGAL_IMAGEIO_EXPORT float evaluate(const _image* image,const unsigned int i,const unsigned int j,const unsigned int k); +CGAL_IMAGEIO_EXPORT float evaluate(const _image* image,const std::size_t i,const std::size_t j,const std::size_t k); /** convert the data of the image to float From 52c44375395a6039aefb1f1d13826e2800f6342c Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 20 Oct 2014 14:41:14 +0200 Subject: [PATCH 03/13] This branch needs to bump the SONAME --- Installation/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Installation/CMakeLists.txt b/Installation/CMakeLists.txt index 142ed5e8875..bc9fdfd7c9c 100644 --- a/Installation/CMakeLists.txt +++ b/Installation/CMakeLists.txt @@ -340,10 +340,11 @@ endif() # CGAL-4.3 : 10.0.2 (Nothing different in CGAL compiled libraries¹.) # CGAL-4.4 : 10.0.3 (Nothing different in CGAL compiled libraries¹.) # CGAL-4.5 : 10.0.4 (Nothing different in CGAL compiled libraries¹.) +# CGAL-4.6 : 11.0.0 (int->size_t in CGAL_ImageIO) # ¹) According to http://upstream-tracker.org/versions/cgal.html -set( CGAL_SONAME_VERSION "10" ) -set( CGAL_SOVERSION "10.0.4" ) +set( CGAL_SONAME_VERSION "11" ) +set( CGAL_SOVERSION "11.0.0" ) message( STATUS "CGAL_SONAME_VERSION=${CGAL_SONAME_VERSION}" ) message( STATUS "CGAL_SOVERSION =${CGAL_SOVERSION}" ) From 127a07b0b149d4e24c5b22ad9d22c881eced4d0c Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 21 Oct 2014 10:47:49 +0200 Subject: [PATCH 04/13] fix warnings --- CGAL_ImageIO/src/CGAL_ImageIO/gis.cpp | 8 ++++---- CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp | 10 +++++----- CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/gis.cpp b/CGAL_ImageIO/src/CGAL_ImageIO/gis.cpp index 5fdb370cde5..ab2ec722de5 100644 --- a/CGAL_ImageIO/src/CGAL_ImageIO/gis.cpp +++ b/CGAL_ImageIO/src/CGAL_ImageIO/gis.cpp @@ -246,7 +246,7 @@ int readGisHeader( const char* name,_image* im) if ( !fgetns(str, _LGTH_STRING_, im) ) { ImageIO_free( str ); return -1; } - status = sscanf( str,"%u %u %u %u", &(im->xdim), &(im->ydim), + status = sscanf( str,"%zu %zu %zu %zu", &(im->xdim), &(im->ydim), &(im->zdim), &(im->vdim) ); switch ( status ) { case 2 : im->zdim = 1; @@ -635,12 +635,12 @@ int writeGisHeader( const _image* inr ) /* dimensions */ - sprintf( str, "%d %d", inr->xdim, inr->ydim ); + sprintf( str, "%zu %zu", inr->xdim, inr->ydim ); if ( inr->vdim > 1 ) { - sprintf( str+strlen(str), " %d %d", inr->zdim, inr->vdim ); + sprintf( str+strlen(str), " %zu %zu", inr->zdim, inr->vdim ); } else if ( inr->zdim > 1 ) { - sprintf( str+strlen(str), " %d", inr->zdim ); + sprintf( str+strlen(str), " %zu", inr->zdim ); } sprintf( str+strlen(str), "\n" ); diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp b/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp index 0fc020574cc..3dbb1b73f61 100644 --- a/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp +++ b/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp @@ -116,7 +116,7 @@ int _writeInrimageHeader(const _image *im, ENDIANNESS end) { } /* write header information */ - sprintf(buf, "%s\nXDIM=%i\nYDIM=%i\nZDIM=%i\nVDIM=%d\nTYPE=%s\nPIXSIZE=%i bits\n%sCPU=%s\nVX=%f\nVY=%f\nVZ=%f\n", + sprintf(buf, "%s\nXDIM=%zu\nYDIM=%zu\nZDIM=%zu\nVDIM=%zu\nTYPE=%s\nPIXSIZE=%zu bits\n%sCPU=%s\nVX=%f\nVY=%f\nVZ=%f\n", INR4_MAGIC, im->xdim, im->ydim, im->zdim, im->vdim, type, im->wdim*8, scale, endianness, im->vx, im->vy, im->vz); @@ -237,16 +237,16 @@ int readInrimageHeader(const char *,_image *im) { while(str[0] != '#' && str[0] != '\0') { if(!strncmp(str, "XDIM=", 5)) { - if(sscanf(str+5, "%u", &im->xdim) != 1) return -1; + if(sscanf(str+5, "%zu", &im->xdim) != 1) return -1; } else if(!strncmp(str, "YDIM=", 5)) { - if(sscanf(str+5, "%u", &im->ydim) != 1) return -1; + if(sscanf(str+5, "%zu", &im->ydim) != 1) return -1; } else if(!strncmp(str, "ZDIM=", 5)) { - if(sscanf(str+5, "%u", &im->zdim) != 1) return -1; + if(sscanf(str+5, "%zu", &im->zdim) != 1) return -1; } else if(!strncmp(str, "VDIM=", 5)) { - if(sscanf(str+5, "%u", &im->vdim) != 1) return -1; + if(sscanf(str+5, "%zu", &im->vdim) != 1) return -1; if(im->vdim == 1) im->vectMode = VM_SCALAR; else im->vectMode = VM_INTERLACED; } diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp b/CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp index f05f397640c..11e905b4ef7 100644 --- a/CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp +++ b/CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp @@ -219,7 +219,7 @@ int writePpmImage( char *name,_image *im ) ImageIO_write( im, string, strlen( string ) ); sprintf( string, "# CREATOR: pnm.c $Revision$ $Date$\n" ); ImageIO_write( im, string, strlen( string ) ); - sprintf( string, "%d %d\n", im->xdim, im->ydim ); + sprintf( string, "%zu %zu\n", im->xdim, im->ydim ); ImageIO_write( im, string, strlen( string ) ); max = 0; switch ( im->wdim ) { @@ -527,7 +527,7 @@ int writePgmImage(char *name,_image *im ) ImageIO_write( im, string, strlen( string ) ); sprintf( string, "# CREATOR: pnm.c $Revision$ $Date$\n" ); ImageIO_write( im, string, strlen( string ) ); - sprintf( string, "%d %d\n", im->xdim, im->ydim ); + sprintf( string, "%zu %zu\n", im->xdim, im->ydim ); ImageIO_write( im, string, strlen( string ) ); max = 0; switch ( im->wdim ) { From 6529a1391518fe6d0edd1f622380ffe7f4020b41 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 24 Oct 2014 13:51:23 +0200 Subject: [PATCH 05/13] wdim should also be a std::size_t --- CGAL_ImageIO/include/CGAL/ImageIO.h | 4 ++-- CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CGAL_ImageIO/include/CGAL/ImageIO.h b/CGAL_ImageIO/include/CGAL/ImageIO.h index 50b64465135..29978fdd3da 100644 --- a/CGAL_ImageIO/include/CGAL/ImageIO.h +++ b/CGAL_ImageIO/include/CGAL/ImageIO.h @@ -255,7 +255,7 @@ typedef struct point_image { void *data; /** Image word size (in bytes) */ - unsigned int wdim; + std::size_t wdim; /** Image format to use for I/0. Should not be set by user */ PTRIMAGE_FORMAT imageFormat; /** Data buffer vectors are interlaced or non interlaced */ @@ -545,7 +545,7 @@ namespace IMAGEIO { // // The following definition are for the evaluate function. // -template +template struct Word_type_generator { }; diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp b/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp index 3dbb1b73f61..7c64ae5d92c 100644 --- a/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp +++ b/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp @@ -293,7 +293,7 @@ int readInrimageHeader(const char *,_image *im) { insight (GM). */ else if(!strncmp(str, "PIXSIZE=", 8)) { - if(sscanf(str+8, "%u", &im->wdim) != 1) return -1; + if(sscanf(str+8, "%zu", &im->wdim) != 1) return -1; if(im->wdim != 8 && im->wdim != 16 && im->wdim != 32 && im->wdim != 64) return -1; From 42abb4db5aa08c4e4156f6f227e4e09fb29167bd Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 24 Oct 2014 14:24:29 +0200 Subject: [PATCH 06/13] fix a warning --- .../include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Mesh_3/include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h b/Mesh_3/include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h index 8b95beb6417..53fa774a634 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h +++ b/Mesh_3/include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h @@ -93,9 +93,9 @@ public: if(px < 0 || py < 0 || pz < 0 || - px+1 >= dimx || - py+1 >= dimy || - pz+1 >= dimz) + px+1 >= static_cast(dimx) || + py+1 >= static_cast(dimy) || + pz+1 >= static_cast(dimz) ) { return 0; } From b49e7b7f8825540223b8c13d9318f0922901bdd5 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 24 Oct 2014 14:50:08 +0200 Subject: [PATCH 07/13] fix conversion warnings --- .../Mesh_3/Scene_segmented_image_item.cpp | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.cpp b/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.cpp index 5f8afd1173b..f8ba4b73811 100644 --- a/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.cpp +++ b/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.cpp @@ -35,27 +35,27 @@ class Image_accessor public: Image_accessor(const Image& im, int dx=1, int dy=1, int dz=1); - bool is_vertex_active(unsigned int i, unsigned int j, unsigned int k) const; - const QColor& vertex_color(unsigned int i, unsigned int j, unsigned int k) const; - void normal(unsigned int i, unsigned int j, unsigned int k, + bool is_vertex_active(std::size_t i, std::size_t j, std::size_t k) const; + const QColor& vertex_color(std::size_t i, std::size_t j, std::size_t k) const; + void normal(std::size_t i, std::size_t j, std::size_t k, float& x, float& y, float& z) const; int dx() const { return dx_; } int dy() const { return dy_; } int dz() const { return dz_; } - unsigned int xdim() const { return im_.xdim(); } - unsigned int ydim() const { return im_.ydim(); } - unsigned int zdim() const { return im_.zdim(); } + std::size_t xdim() const { return im_.xdim(); } + std::size_t ydim() const { return im_.ydim(); } + std::size_t zdim() const { return im_.zdim(); } double vx() const { return im_.vx(); } double vy() const { return im_.vy(); } double vz() const { return im_.vz(); } private: - unsigned char non_null_neighbor_data(unsigned int i, - unsigned int j, - unsigned int k) const; + unsigned char non_null_neighbor_data(std::size_t i, + std::size_t j, + std::size_t k) const; - unsigned char image_data(unsigned int i, unsigned int j, unsigned int k) const; + unsigned char image_data(std::size_t i, std::size_t j, std::size_t k) const; void add_to_normal(unsigned char v, float& x, float& y, float& z, @@ -77,15 +77,15 @@ Image_accessor::Image_accessor(const Image& im, int dx, int dy, int dz) , default_color_() , colors_() { - const unsigned int xdim = im_.xdim(); - const unsigned int ydim = im_.ydim(); - const unsigned int zdim = im_.zdim(); + const std::size_t xdim = im_.xdim(); + const std::size_t ydim = im_.ydim(); + const std::size_t zdim = im_.zdim(); - for(unsigned int i=0 ; i(im_.image(),i,j,k); @@ -151,7 +151,7 @@ Image_accessor::image_data(unsigned int i, unsigned int j, unsigned int k) const unsigned char Image_accessor:: -non_null_neighbor_data(unsigned int i, unsigned int j, unsigned int k) const +non_null_neighbor_data(std::size_t i, std::size_t j, std::size_t k) const { unsigned char v = image_data(i-dx_, j-dy_, k-dz_); if ( v != 0 ) { return v; } @@ -182,7 +182,7 @@ non_null_neighbor_data(unsigned int i, unsigned int j, unsigned int k) const void Image_accessor:: -normal(unsigned int i, unsigned int j, unsigned int k, +normal(std::size_t i, std::size_t j, std::size_t k, float& x, float& y, float& z) const { unsigned char v = image_data(i-dx_, j-dy_, k-dz_); @@ -245,16 +245,16 @@ public: std::size_t quad_size() const { return quad_size_*sizeof(GLuint); } private: - void treat_vertex(unsigned int i, unsigned int j, unsigned int k); + void treat_vertex(std::size_t i, std::size_t j, std::size_t k); - void push_color(unsigned int i, unsigned int j, unsigned int k); - void push_normal(unsigned int i, unsigned int j, unsigned int k); - void push_vertex(unsigned int i, unsigned int j, unsigned int k); - void push_quads(unsigned int i, unsigned int j, unsigned int k); + void push_color(std::size_t i, std::size_t j, std::size_t k); + void push_normal(std::size_t i, std::size_t j, std::size_t k); + void push_vertex(std::size_t i, std::size_t j, std::size_t k); + void push_quads(std::size_t i, std::size_t j, std::size_t k); void push_quad(int pos1, int pos2, int pos3, int pos4); - int compute_position(unsigned int i, unsigned int j, unsigned int k) const; - int vertex_index(unsigned int i, unsigned int j, unsigned int k) const; + int compute_position(std::size_t i, std::size_t j, std::size_t k) const; + int vertex_index(std::size_t i, std::size_t j, std::size_t k) const; void create_arrays(); @@ -308,7 +308,7 @@ void Vertex_buffer_helper:: fill_buffer_data() { - unsigned int i,j,k; + std::size_t i,j,k; for ( i = 0 ; i <= data_.xdim() ; i+=dx() ) { @@ -325,7 +325,7 @@ fill_buffer_data() } void -Vertex_buffer_helper::treat_vertex(unsigned int i, unsigned int j, unsigned int k) +Vertex_buffer_helper::treat_vertex(std::size_t i, std::size_t j, std::size_t k) { if ( data_.is_vertex_active(i,j,k) ) { @@ -337,7 +337,7 @@ Vertex_buffer_helper::treat_vertex(unsigned int i, unsigned int j, unsigned int } void -Vertex_buffer_helper::push_color(unsigned int i, unsigned int j, unsigned int k) +Vertex_buffer_helper::push_color(std::size_t i, std::size_t j, std::size_t k) { const QColor& color = data_.vertex_color(i,j,k); if ( ! color.isValid() ) { return; } @@ -348,7 +348,7 @@ Vertex_buffer_helper::push_color(unsigned int i, unsigned int j, unsigned int k) } void -Vertex_buffer_helper::push_normal(unsigned int i, unsigned int j, unsigned int k) +Vertex_buffer_helper::push_normal(std::size_t i, std::size_t j, std::size_t k) { float x=0.f, y=0.f, z=0.f; data_.normal(i,j,k,x,y,z); @@ -364,7 +364,7 @@ Vertex_buffer_helper::push_normal(unsigned int i, unsigned int j, unsigned int k } void -Vertex_buffer_helper::push_vertex(unsigned int i, unsigned int j, unsigned int k) +Vertex_buffer_helper::push_vertex(std::size_t i, std::size_t j, std::size_t k) { indices_.insert(std::make_pair(compute_position(i,j,k), vertices_.size()/3)); @@ -375,7 +375,7 @@ Vertex_buffer_helper::push_vertex(unsigned int i, unsigned int j, unsigned int k } void -Vertex_buffer_helper::push_quads(unsigned int i, unsigned int j, unsigned int k) +Vertex_buffer_helper::push_quads(std::size_t i, std::size_t j, std::size_t k) { int pos1 = vertex_index(i-dx(), j , k); int pos2 = vertex_index(i-dx(), j-dy(), k); @@ -410,16 +410,17 @@ Vertex_buffer_helper::push_quad(int pos1, int pos2, int pos3, int pos4) int Vertex_buffer_helper:: -compute_position(unsigned int i, unsigned int j, unsigned int k) const +compute_position(std::size_t i, std::size_t j, std::size_t k) const { - return i/dx() * (data_.ydim()/dy()+1) * (data_.zdim()/dz()+1) + return static_cast( + i/dx() * (data_.ydim()/dy()+1) * (data_.zdim()/dz()+1) + j/dy() * (data_.zdim()/dz()+1) - + k/dz(); + + k/dz()); } int Vertex_buffer_helper:: -vertex_index(unsigned int i, unsigned int j, unsigned int k) const +vertex_index(std::size_t i, std::size_t j, std::size_t k) const { if ( i > data_.xdim() || j > data_.ydim() || k > data_.zdim() ) { From 1957fe9d9272108df04a0c8084d0f65224f18c7f Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Thu, 6 Nov 2014 14:22:59 +0100 Subject: [PATCH 08/13] %zu in printf/scanf is not supported by most windows compilers %zu does not match the ANSI norm either We should use %Iu on Windows, %zu on other platforms. So let's remove %zu and %Iu, and use C++ stringstream(s) instead --- CGAL_ImageIO/src/CGAL_ImageIO/gis.cpp | 69 +++++++++----------- CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp | 94 +++++++++++++++++---------- CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp | 24 +++---- 3 files changed, 104 insertions(+), 83 deletions(-) diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/gis.cpp b/CGAL_ImageIO/src/CGAL_ImageIO/gis.cpp index ab2ec722de5..80ede0fec02 100644 --- a/CGAL_ImageIO/src/CGAL_ImageIO/gis.cpp +++ b/CGAL_ImageIO/src/CGAL_ImageIO/gis.cpp @@ -19,7 +19,8 @@ // // Author(s) : ASCLEPIOS Project (INRIA Sophia-Antipolis), Laurent Rineau -#include +#include +#include #include "gis.h" #include "inr.h" @@ -240,14 +241,17 @@ int readGisHeader( const char* name,_image* im) char *s, *str = NULL; int status; int n=0, nusermax = 20; - str = (char*)ImageIO_alloc( _LGTH_STRING_+1 ); if ( !fgetns(str, _LGTH_STRING_, im) ) { ImageIO_free( str ); return -1; } - status = sscanf( str,"%zu %zu %zu %zu", &(im->xdim), &(im->ydim), - &(im->zdim), &(im->vdim) ); + + std::istringstream iss; + iss.str(str); + iss >> im->xdim >> im->ydim >> im->zdim >> im->vdim; + + status = iss.str().length(); switch ( status ) { case 2 : im->zdim = 1; case 3 : im->vdim = 1; @@ -624,95 +628,86 @@ int readGisHeader( const char* name,_image* im) int writeGisHeader( const _image* inr ) { const char *proc = "writeGisHeader"; - char *str = NULL; - + std::ostringstream oss; + if ( inr->vectMode == VM_NON_INTERLACED ) { fprintf( stderr, "%s: can not write non interlaced data\n", proc ); return -1; } - str = (char*)ImageIO_alloc( _LGTH_STRING_ ); - /* dimensions */ - sprintf( str, "%zu %zu", inr->xdim, inr->ydim ); + oss << " " << inr->xdim << " " << inr->ydim; if ( inr->vdim > 1 ) { - sprintf( str+strlen(str), " %zu %zu", inr->zdim, inr->vdim ); + oss << " " << inr->zdim << " " << inr->vdim; } else if ( inr->zdim > 1 ) { - sprintf( str+strlen(str), " %zu", inr->zdim ); + oss << " " << inr->zdim; } - sprintf( str+strlen(str), "\n" ); + oss << "\n"; /* type */ - sprintf( str+strlen(str), "-type " ); + oss << "-type "; switch ( inr->wordKind ) { case WK_FIXED : switch( inr->sign ) { case SGN_UNSIGNED : - sprintf( str+strlen(str), "U" ); - sprintf( str+strlen(str), "%d", 8*inr->wdim ); + oss << "U" << 8*inr->wdim; break; case SGN_SIGNED : - sprintf( str+strlen(str), "S" ); - sprintf( str+strlen(str), "%d", 8*inr->wdim ); + oss << "S" << 8*inr->wdim; break; default : fprintf( stderr, "%s: unknown wordSign\n", proc ); - ImageIO_free( str ); return -1; } break; case WK_FLOAT : if ( inr->wdim == sizeof( float ) ) { - sprintf( str+strlen(str), "FLOAT" ); + oss << "FLOAT"; } else if ( inr->wdim == sizeof( double ) ) { - sprintf( str+strlen(str), "DOUBLE" ); + oss << "DOUBLE"; } else { fprintf( stderr, "%s: unknown WK_FLOAT word dim\n", proc ); - ImageIO_free( str ); return -1; } break; default : fprintf( stderr, "%s: unknown wordKind for image\n", proc ); - ImageIO_free( str ); return -1; } - sprintf( str+strlen(str), "\n" ); - - sprintf( str+strlen(str), "-dx %f\n", inr->vx ); - sprintf( str+strlen(str), "-dy %f\n", inr->vy ); - if ( inr->zdim > 1 ) - sprintf( str+strlen(str), "-dz %f\n", inr->vz ); + oss << "\n"; + oss << "-dx "<< inr->vx <<"\n"; + oss << "-dy "<< inr->vy <<"\n"; + if ( inr->zdim > 1 ) + oss << "-dz " << inr->vz << "\n"; + if ( inr->wdim > 1 ) { - sprintf( str+strlen(str), "-bo " ); + oss << "-bo "; switch ( _getEndianness() ) { default : case END_LITTLE : - sprintf( str+strlen(str), "DCBA" ); break; + oss << "DCBA"; break; case END_BIG : - sprintf( str+strlen(str), "ABCD" ); break; + oss << "ABCD"; break; } - sprintf( str+strlen(str), "\n" ); + oss << "\n"; } switch ( inr->dataMode ) { default : case DM_BINARY : - sprintf( str+strlen(str), "-om binar\n" ); + oss << "-om binar\n"; break; case DM_ASCII : - sprintf( str+strlen(str), "-om ascii\n" ); + oss << "-om ascii\n"; } - if( ImageIO_write( inr, str, strlen(str)) == 0) { - ImageIO_free( str ); + if( ImageIO_write( inr, oss.str().data(), oss.str().length()) == 0) { return -1; } - ImageIO_free( str ); return 1; } diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp b/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp index 7c64ae5d92c..ee3bf0ef397 100644 --- a/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp +++ b/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp @@ -22,7 +22,8 @@ #include "inr.h" #include "fgetns.h" -#include +#include +#include /* Magic header for inrimages v4 */ #define INR4_MAGIC "#INRIMAGE-4#{" @@ -69,6 +70,7 @@ static void concatStringElement(const stringListHead *strhead, int _writeInrimageHeader(const _image *im, ENDIANNESS end) { unsigned int pos, i; char type[30], endianness[5], buf[257], scale[20]; + std::ostringstream oss; Set_numeric_locale num_locale("C"); @@ -116,34 +118,41 @@ int _writeInrimageHeader(const _image *im, ENDIANNESS end) { } /* write header information */ - sprintf(buf, "%s\nXDIM=%zu\nYDIM=%zu\nZDIM=%zu\nVDIM=%zu\nTYPE=%s\nPIXSIZE=%zu bits\n%sCPU=%s\nVX=%f\nVY=%f\nVZ=%f\n", - INR4_MAGIC, im->xdim, im->ydim, im->zdim, im->vdim, - type, im->wdim*8, scale, endianness, im->vx, im->vy, im->vz); + oss << INR4_MAGIC << "\n"; + oss << "XDIM=" << im->xdim << "\n"; + oss << "YDIM=" << im->ydim << "\n"; + oss << "ZDIM=" << im->zdim << "\n"; + oss << "VDIM=" << im->vdim << "\n"; + oss << "TYPE=" << type << "\n"; + oss << "PIXSIZE=" << im->wdim*8 <<" bits\n"; + oss << scale << "CPU=" << endianness << "\n"; + oss << "VX=" << im->vx << "\n"; + oss << "VY=" << im->vy << "\n"; + oss << "VZ=" << im->vz << "\n"; if ( im->cx != 0 ) - sprintf(buf+strlen(buf), "XO=%d\n", im->cx ); + oss << "XO="<< im->cx << "\n"; if ( im->cy != 0 ) - sprintf(buf+strlen(buf), "YO=%d\n", im->cy ); + oss << "YO="<< im->cy << "\n"; if ( im->cz != 0 ) - sprintf(buf+strlen(buf), "ZO=%d\n", im->cz ); + oss << "ZO="<< im->cz << "\n"; if ( im->tx != 0.0 ) - sprintf(buf+strlen(buf), "TX=%f\n", im->tx ); + oss << "TX="<< im->tx << "\n"; if ( im->ty != 0.0 ) - sprintf(buf+strlen(buf), "TY=%f\n", im->ty ); + oss << "TY="<< im->ty << "\n"; if ( im->tz != 0.0 ) - sprintf(buf+strlen(buf), "TZ=%f\n", im->tz ); - + oss << "TZ="<< im->tz << "\n"; if ( im->rx != 0.0 ) - sprintf(buf+strlen(buf), "RX=%f\n", im->rx ); + oss << "RX="<< im->rx <<"\n"; if ( im->ry != 0.0 ) - sprintf(buf+strlen(buf), "RY=%f\n", im->ry ); + oss << "RY="<< im->ry << "\n"; if ( im->rz != 0.0 ) - sprintf(buf+strlen(buf), "RZ=%f\n", im->rz ); + oss << "RZ=" << im->rz <<"\n"; - - pos = strlen(buf); + pos = oss.str().length(); - if(ImageIO_write(im, buf, strlen(buf)) == 0) return -1; + if(ImageIO_write(im, oss.str().data(), oss.str().length()) == 0) + return -1; /* write user strings */ @@ -237,27 +246,34 @@ int readInrimageHeader(const char *,_image *im) { while(str[0] != '#' && str[0] != '\0') { if(!strncmp(str, "XDIM=", 5)) { - if(sscanf(str+5, "%zu", &im->xdim) != 1) return -1; + std::istringstream iss(str+5); + if(!(iss >> im->xdim).good()) return -1; } else if(!strncmp(str, "YDIM=", 5)) { - if(sscanf(str+5, "%zu", &im->ydim) != 1) return -1; + std::istringstream iss(str+5); + if(!(iss >> im->ydim).good()) return -1; } else if(!strncmp(str, "ZDIM=", 5)) { - if(sscanf(str+5, "%zu", &im->zdim) != 1) return -1; + std::istringstream iss(str+5); + if(!(iss >> im->zdim).good()) return -1; } else if(!strncmp(str, "VDIM=", 5)) { - if(sscanf(str+5, "%zu", &im->vdim) != 1) return -1; + std::istringstream iss(str+5); + if(!(iss >> im->vdim).good()) return -1; if(im->vdim == 1) im->vectMode = VM_SCALAR; else im->vectMode = VM_INTERLACED; } else if(!strncmp(str, "VX=", 3)) { - if(sscanf(str+3, "%lf", &im->vx) != 1) return -1; + std::istringstream iss(str+3); + if(!(iss >> im->vx).good()) return -1; } else if(!strncmp(str, "VY=", 3)) { - if(sscanf(str+3, "%lf", &im->vy) != 1) return -1; + std::istringstream iss(str+3); + if(!(iss >> im->vy).good()) return -1; } else if(!strncmp(str, "VZ=", 3)) { - if(sscanf(str+3, "%lf", &im->vz) != 1) return -1; + std::istringstream iss(str+3); + if(!(iss >> im->vz).good()) return -1; } else if(!strncmp(str, "TYPE=", 5)) { if(!strncmp(str+5, "float", 5)) im->wordKind = WK_FLOAT; @@ -293,7 +309,8 @@ int readInrimageHeader(const char *,_image *im) { insight (GM). */ else if(!strncmp(str, "PIXSIZE=", 8)) { - if(sscanf(str+8, "%zu", &im->wdim) != 1) return -1; + std::istringstream iss(str+8); + if(!(iss >> im->wdim).good()) return -1; if(im->wdim != 8 && im->wdim != 16 && im->wdim != 32 && im->wdim != 64) return -1; @@ -320,32 +337,41 @@ int readInrimageHeader(const char *,_image *im) { } else if(!strncmp(str, "XO=", 3)) { - if(sscanf(str+3, "%d", &im->cx) != 1) return -1; + std::istringstream iss(str+3); + if(!(iss >> im->cx).good()) return -1; } else if(!strncmp(str, "YO=", 3)) { - if(sscanf(str+3, "%d", &im->cy) != 1) return -1; + std::istringstream iss(str+3); + if(!(iss >> im->cy).good()) return -1; } else if(!strncmp(str, "ZO=", 3)) { - if(sscanf(str+3, "%d", &im->cz) != 1) return -1; + std::istringstream iss(str+3); + if(!(iss >> im->cz).good()) return -1; } else if(!strncmp(str, "TX=", 3)) { - if(sscanf(str+3, "%f", &im->tx) != 1) return -1; + std::istringstream iss(str+3); + if(!(iss >> im->tx).good()) return -1; } else if(!strncmp(str, "TY=", 3)) { - if(sscanf(str+3, "%f", &im->ty) != 1) return -1; + std::istringstream iss(str+3); + if(!(iss >> im->ty).good()) return -1; } else if(!strncmp(str, "TZ=", 3)) { - if(sscanf(str+3, "%f", &im->tz) != 1) return -1; + std::istringstream iss(str+3); + if(!(iss >> im->tz).good()) return -1; } else if(!strncmp(str, "RX=", 3)) { - if(sscanf(str+3, "%f", &im->rx) != 1) return -1; + std::istringstream iss(str+3); + if(!(iss >> im->rx).good()) return -1; } else if(!strncmp(str, "RY=", 3)) { - if(sscanf(str+3, "%f", &im->ry) != 1) return -1; + std::istringstream iss(str+3); + if(!(iss >> im->ry).good()) return -1; } else if(!strncmp(str, "RZ=", 3)) { - if(sscanf(str+3, "%f", &im->rz) != 1) return -1; + std::istringstream iss(str+3); + if(!(iss >> im->rz).good()) return -1; } if(!fgetns(str, 257, im)) return -1; diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp b/CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp index 11e905b4ef7..ad0c5a59fae 100644 --- a/CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp +++ b/CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp @@ -24,6 +24,7 @@ #endif #include +#include #include "pnm.h" #include "fgetns.h" @@ -167,8 +168,8 @@ int readPpmImage(const char *name,_image *im) } while ( max == 0 ); - im->xdim = x; - im->ydim = y; + im->xdim = static_cast(x); + im->ydim = static_cast(y); im->zdim = 1; im->vdim = 3; @@ -194,7 +195,7 @@ int readPpmImage(const char *name,_image *im) int writePpmImage( char *name,_image *im ) { - char string[256]; + std::ostringstream string; int max; unsigned int i; @@ -214,13 +215,11 @@ int writePpmImage( char *name,_image *im ) fprintf(stderr, "writeInrimage: error: unable to open file \'%s\'\n", name ); return ImageIO_OPENING; } - - sprintf( string, "%s\n", PPM_MAGIC ); - ImageIO_write( im, string, strlen( string ) ); - sprintf( string, "# CREATOR: pnm.c $Revision$ $Date$\n" ); - ImageIO_write( im, string, strlen( string ) ); - sprintf( string, "%zu %zu\n", im->xdim, im->ydim ); - ImageIO_write( im, string, strlen( string ) ); + + string << PPM_MAGIC << "\n"; + string << "# CREATOR: pnm.c $Revision$ $Date$\n"; + string << im->xdim << " " << im->ydim << "\n"; + max = 0; switch ( im->wdim ) { case 1 : @@ -240,8 +239,9 @@ int writePpmImage( char *name,_image *im ) } if ( max == 0 ) max = 1; - sprintf( string, "%d\n", max ); - ImageIO_write( im, string, strlen( string ) ); + string << max << "\n"; + ImageIO_write(im, string.str().data(), string.str().length()); + if ( im->wdim == 1 || ( im->wdim == 2 && max > 255 ) ) { ImageIO_write( im, im->data, im->xdim*im->ydim*3*im->wdim ); } From f59acabc9b9a73b55b5cd619b235eec5ede01e1e Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 7 Nov 2014 11:19:20 +0100 Subject: [PATCH 09/13] avoid using info when casting --- .../Mesh_3/Image_to_labeled_function_wrapper.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Mesh_3/include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h b/Mesh_3/include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h index 53fa774a634..c200376f8df 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h +++ b/Mesh_3/include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h @@ -82,20 +82,20 @@ public: } else { - const int px = static_cast(p.x()/r_im_.vx()); - const int py = static_cast(p.y()/r_im_.vy()); - const int pz = static_cast(p.z()/r_im_.vz()); + const std::ptrdiff_t px = static_cast(p.x()/r_im_.vx()); + const std::ptrdiff_t py = static_cast(p.y()/r_im_.vy()); + const std::ptrdiff_t pz = static_cast(p.z()/r_im_.vz()); - const std::size_t dimx = r_im_.xdim(); - const std::size_t dimy = r_im_.ydim(); - const std::size_t dimz = r_im_.zdim(); + const std::ptrdiff_t dimx = static_cast(r_im_.xdim()); + const std::ptrdiff_t dimy = static_cast(r_im_.ydim()); + const std::ptrdiff_t dimz = static_cast(r_im_.zdim()); if(px < 0 || py < 0 || pz < 0 || - px+1 >= static_cast(dimx) || - py+1 >= static_cast(dimy) || - pz+1 >= static_cast(dimz) ) + px+1 >= dimx || + py+1 >= dimy || + pz+1 >= dimz) { return 0; } From f9e7e834a85ea1c3cfbf08078c4e340822593d76 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Wed, 12 Nov 2014 10:46:43 +0100 Subject: [PATCH 10/13] fix the use of istringstream --- CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp b/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp index ee3bf0ef397..94d5571e340 100644 --- a/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp +++ b/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp @@ -247,33 +247,33 @@ int readInrimageHeader(const char *,_image *im) { if(!strncmp(str, "XDIM=", 5)) { std::istringstream iss(str+5); - if(!(iss >> im->xdim).good()) return -1; + if(!(iss >> im->xdim)) return -1; } else if(!strncmp(str, "YDIM=", 5)) { std::istringstream iss(str+5); - if(!(iss >> im->ydim).good()) return -1; + if(!(iss >> im->ydim)) return -1; } else if(!strncmp(str, "ZDIM=", 5)) { std::istringstream iss(str+5); - if(!(iss >> im->zdim).good()) return -1; + if(!(iss >> im->zdim)) return -1; } else if(!strncmp(str, "VDIM=", 5)) { std::istringstream iss(str+5); - if(!(iss >> im->vdim).good()) return -1; + if(!(iss >> im->vdim)) return -1; if(im->vdim == 1) im->vectMode = VM_SCALAR; else im->vectMode = VM_INTERLACED; } else if(!strncmp(str, "VX=", 3)) { std::istringstream iss(str+3); - if(!(iss >> im->vx).good()) return -1; + if(!(iss >> im->vx)) return -1; } else if(!strncmp(str, "VY=", 3)) { std::istringstream iss(str+3); - if(!(iss >> im->vy).good()) return -1; + if(!(iss >> im->vy)) return -1; } else if(!strncmp(str, "VZ=", 3)) { std::istringstream iss(str+3); - if(!(iss >> im->vz).good()) return -1; + if(!(iss >> im->vz)) return -1; } else if(!strncmp(str, "TYPE=", 5)) { if(!strncmp(str+5, "float", 5)) im->wordKind = WK_FLOAT; @@ -310,7 +310,7 @@ int readInrimageHeader(const char *,_image *im) { */ else if(!strncmp(str, "PIXSIZE=", 8)) { std::istringstream iss(str+8); - if(!(iss >> im->wdim).good()) return -1; + if(!(iss >> im->wdim)) return -1; if(im->wdim != 8 && im->wdim != 16 && im->wdim != 32 && im->wdim != 64) return -1; @@ -338,40 +338,40 @@ int readInrimageHeader(const char *,_image *im) { else if(!strncmp(str, "XO=", 3)) { std::istringstream iss(str+3); - if(!(iss >> im->cx).good()) return -1; + if(!(iss >> im->cx)) return -1; } else if(!strncmp(str, "YO=", 3)) { std::istringstream iss(str+3); - if(!(iss >> im->cy).good()) return -1; + if(!(iss >> im->cy)) return -1; } else if(!strncmp(str, "ZO=", 3)) { std::istringstream iss(str+3); - if(!(iss >> im->cz).good()) return -1; + if(!(iss >> im->cz)) return -1; } else if(!strncmp(str, "TX=", 3)) { std::istringstream iss(str+3); - if(!(iss >> im->tx).good()) return -1; + if(!(iss >> im->tx)) return -1; } else if(!strncmp(str, "TY=", 3)) { std::istringstream iss(str+3); - if(!(iss >> im->ty).good()) return -1; + if(!(iss >> im->ty)) return -1; } else if(!strncmp(str, "TZ=", 3)) { std::istringstream iss(str+3); - if(!(iss >> im->tz).good()) return -1; + if(!(iss >> im->tz)) return -1; } else if(!strncmp(str, "RX=", 3)) { std::istringstream iss(str+3); - if(!(iss >> im->rx).good()) return -1; + if(!(iss >> im->rx)) return -1; } else if(!strncmp(str, "RY=", 3)) { std::istringstream iss(str+3); - if(!(iss >> im->ry).good()) return -1; + if(!(iss >> im->ry)) return -1; } else if(!strncmp(str, "RZ=", 3)) { std::istringstream iss(str+3); - if(!(iss >> im->rz).good()) return -1; + if(!(iss >> im->rz)) return -1; } if(!fgetns(str, 257, im)) return -1; From 9c4038d2676d33ed7758d6f026a26fd11b306c2b Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Thu, 13 Nov 2014 11:13:35 +0100 Subject: [PATCH 11/13] add consistency in the use of size_t everywhere --- CGAL_ImageIO/include/CGAL/Image_3.h | 6 +++--- CGAL_ImageIO/src/CGAL_ImageIO/ImageIO.cpp | 6 +++--- .../CGAL_ImageIO/test_trilinear_interpolation.cpp | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CGAL_ImageIO/include/CGAL/Image_3.h b/CGAL_ImageIO/include/CGAL/Image_3.h index 3050dcfb774..3ae3164931a 100644 --- a/CGAL_ImageIO/include/CGAL/Image_3.h +++ b/CGAL_ImageIO/include/CGAL/Image_3.h @@ -134,9 +134,9 @@ public: double vy() const { return image_ptr->vy; } double vz() const { return image_ptr->vz; } - float value(const unsigned int i, - const unsigned int j, - const unsigned int k) const + float value(const std::size_t i, + const std::size_t j, + const std::size_t k) const { return ::evaluate(image(),i,j,k); } diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/ImageIO.cpp b/CGAL_ImageIO/src/CGAL_ImageIO/ImageIO.cpp index 33ee5d2b4f2..9198b14a801 100644 --- a/CGAL_ImageIO/src/CGAL_ImageIO/ImageIO.cpp +++ b/CGAL_ImageIO/src/CGAL_ImageIO/ImageIO.cpp @@ -1543,9 +1543,9 @@ float triLinInterp(const _image* image, // Gives the value of the image at pixel (i,j,k), converted in float. float evaluate(const _image* image, - const unsigned int i, - const unsigned int j, - const unsigned int k) + const std::size_t i, + const std::size_t j, + const std::size_t k) { using CGAL::IMAGEIO::static_evaluate; diff --git a/CGAL_ImageIO/test/CGAL_ImageIO/test_trilinear_interpolation.cpp b/CGAL_ImageIO/test/CGAL_ImageIO/test_trilinear_interpolation.cpp index f8d99408e45..47246d8f366 100644 --- a/CGAL_ImageIO/test/CGAL_ImageIO/test_trilinear_interpolation.cpp +++ b/CGAL_ImageIO/test/CGAL_ImageIO/test_trilinear_interpolation.cpp @@ -195,7 +195,7 @@ int main() { "../Surface_mesher_Examples/data/skull_2.9.inr" }; - unsigned int file_index = 0; + 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 ); @@ -242,18 +242,18 @@ int main() { if(diff > 0.0001 ) { std::cerr.precision(20); - const int i1 = (int)(d_z / image2.image()->vz); - const int j1 = (int)(d_y / image2.image()->vy); - const int k1 = (int)(d_x / image2.image()->vx); + const std::size_t i1 = static_cast(d_z / image2.image()->vz); + const std::size_t j1 = static_cast(d_y / image2.image()->vy); + const std::size_t k1 = static_cast(d_x / image2.image()->vx); std::cerr << "pos = (" << d_x << ", " << d_y << ", " << d_z << ") => (" << i1 << ", " << j1 << ", " << k1 << ")\n"; std::cerr << "value1 = " << value1 << "\nvalue2 = " << value2 << std::endl; - for(int di = 0; di < 2 ; ++di) - for(int dj = 0; dj < 2 ; ++dj) - for(int dk = 0; dk < 2 ; ++dk) + for(std::size_t di = 0; di < 2 ; ++di) + for(std::size_t dj = 0; dj < 2 ; ++dj) + for(std::size_t dk = 0; dk < 2 ; ++dk) { std::cerr << "value(" << i1 + di << ", " << j1 + dj From 4c6de9ab46e2638b4d8001a205138fd9eecfe20b Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Mon, 24 Nov 2014 15:57:51 +0100 Subject: [PATCH 12/13] fix conversion warnings --- Surface_mesher/demo/Surface_mesher/volume.cpp | 6 ++--- Surface_mesher/demo/Surface_mesher/volume.h | 27 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Surface_mesher/demo/Surface_mesher/volume.cpp b/Surface_mesher/demo/Surface_mesher/volume.cpp index 9245c573a5b..9016fdf9c54 100644 --- a/Surface_mesher/demo/Surface_mesher/volume.cpp +++ b/Surface_mesher/demo/Surface_mesher/volume.cpp @@ -801,9 +801,9 @@ void Volume::display_surface_mesher_result() values_list->save_values(fileinfo.absoluteFilePath()); - unsigned int nx = m_image.xdim(); - unsigned int ny = m_image.ydim(); - unsigned int nz = m_image.zdim(); + std::size_t nx = m_image.xdim(); + std::size_t ny = m_image.ydim(); + std::size_t nz = m_image.zdim(); if(nx * ny * nz == 0) { status_message("No volume loaded."); diff --git a/Surface_mesher/demo/Surface_mesher/volume.h b/Surface_mesher/demo/Surface_mesher/volume.h index 5ad76e02158..9abda286215 100644 --- a/Surface_mesher/demo/Surface_mesher/volume.h +++ b/Surface_mesher/demo/Surface_mesher/volume.h @@ -208,9 +208,9 @@ void Volume::search_for_connected_components(PointsOutputIterator it, DomainsOutputIterator dom_it, TransformOperator transform) { - const unsigned int nx = m_image.xdim(); - const unsigned int ny = m_image.ydim(); - const unsigned int nz = m_image.zdim(); + const std::size_t nx = m_image.xdim(); + const std::size_t ny = m_image.ydim(); + const std::size_t nz = m_image.zdim(); const double max_v = (std::max)((std::max)(m_image.vx(), m_image.vy()), @@ -220,14 +220,15 @@ void Volume::search_for_connected_components(PointsOutputIterator it, typedef typename TransformOperator::result_type Label; boost::multi_array visited(boost::extents[nx][ny][nz]); - typedef boost::tuple Indices; - typedef std::queue Indices_queue; - typedef std::vector Border_vector; + typedef boost::tuple + Indices; + typedef std::queue Indices_queue; + typedef std::vector Border_vector; int number_of_connected_components = 0; - for(unsigned int i=0;i0) continue; @@ -272,10 +273,10 @@ void Volume::search_for_connected_components(PointsOutputIterator it, queue.pop(); // warning: those indices i, j and k are local to the while loop - const int i = boost::get<0>(indices); - const int j = boost::get<1>(indices); - const int k = boost::get<2>(indices); - const int depth = boost::get<3>(indices); + const std::size_t i = boost::get<0>(indices); + const std::size_t j = boost::get<1>(indices); + const std::size_t k = boost::get<2>(indices); + const std::size_t depth = boost::get<3>(indices); if(visited[i][j][k] < pass) { From 9026aa612221008e8a98d7a1d357145192f93b14 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 25 Nov 2014 17:39:29 +0100 Subject: [PATCH 13/13] fix warnings in surface mesher demo --- .../demo/Surface_mesher/binary_image.h | 18 +++++++++--------- Surface_mesher/demo/Surface_mesher/volume.h | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Surface_mesher/demo/Surface_mesher/binary_image.h b/Surface_mesher/demo/Surface_mesher/binary_image.h index ed7ea390a1d..16b0e6e0e71 100644 --- a/Surface_mesher/demo/Surface_mesher/binary_image.h +++ b/Surface_mesher/demo/Surface_mesher/binary_image.h @@ -99,9 +99,9 @@ public: return (std::max)((std::max)(xmax(),ymax()),zmax()); } - Point point(const unsigned int i, - const unsigned int j, - const unsigned int k) const + Point point(const std::size_t i, + const std::size_t j, + const std::size_t k) const { return Point(i * (image_ptr->vx), j * (image_ptr->vy), @@ -160,9 +160,9 @@ public: } } else { - const int i = static_cast(x/image()->vx + 0.5f); - const int j = static_cast(y/image()->vy + 0.5f); - const int k = static_cast(z/image()->vz + 0.5f); + const std::ptrdiff_t i = static_cast(x/image()->vx + 0.5f); + const std::ptrdiff_t j = static_cast(y/image()->vy + 0.5f); + const std::ptrdiff_t k = static_cast(z/image()->vz + 0.5f); if( i < 0 || j < 0 || k < 0 ) @@ -171,9 +171,9 @@ public: } else { - const unsigned int ui = static_cast(i); - const unsigned int uj = static_cast(j); - const unsigned int uk = static_cast(k); + const std::size_t ui = static_cast(i); + const std::size_t uj = static_cast(j); + const std::size_t uk = static_cast(k); if( ui >= image()->xdim || uj >= image()->ydim || uk >= image()->zdim ) diff --git a/Surface_mesher/demo/Surface_mesher/volume.h b/Surface_mesher/demo/Surface_mesher/volume.h index 9abda286215..4599911332c 100644 --- a/Surface_mesher/demo/Surface_mesher/volume.h +++ b/Surface_mesher/demo/Surface_mesher/volume.h @@ -304,12 +304,12 @@ void Volume::search_for_connected_components(PointsOutputIterator it, // (i_n, j_n, k_n) are indices of neighbors. for(int n = 0; n < 6; ++n) { - const int i_n = i + neighbors_offset[n][0]; - const int j_n = j + neighbors_offset[n][1]; - const int k_n = k + neighbors_offset[n][2]; - if(i_n < 0 || i_n >= static_cast(nx) || - j_n < 0 || j_n >= static_cast(ny) || - k_n < 0 || k_n >= static_cast(nz)) + const ptrdiff_t i_n = i + neighbors_offset[n][0]; + const ptrdiff_t j_n = j + neighbors_offset[n][1]; + const ptrdiff_t k_n = k + neighbors_offset[n][2]; + if(i_n < 0 || i_n >= static_cast(nx) || + j_n < 0 || j_n >= static_cast(ny) || + k_n < 0 || k_n >= static_cast(nz)) { voxel_is_on_border = true; continue;