From 35cb7bd5b8481e48ef5ea1b3bc37511b6fc82906 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 14 Apr 2016 19:36:20 +0200 Subject: [PATCH] Improve CGAL::Image_3 - The type of `value_outside` is now directory `Return_type`: no need to apply the transformation. - The indicator functions of the labelized trilinear interpolation can be changed. --- CGAL_ImageIO/include/CGAL/Image_3.h | 86 ++++++++++++------- .../Image_to_labeled_function_wrapper.h | 6 +- 2 files changed, 60 insertions(+), 32 deletions(-) diff --git a/CGAL_ImageIO/include/CGAL/Image_3.h b/CGAL_ImageIO/include/CGAL/Image_3.h index 3e865b36eec..06befbc5d3d 100644 --- a/CGAL_ImageIO/include/CGAL/Image_3.h +++ b/CGAL_ImageIO/include/CGAL/Image_3.h @@ -47,15 +47,22 @@ namespace CGAL { namespace ImageIO { template -class Indicator : public std::unary_function +struct Indicator_factory { - const T label; -public: - Indicator(T i) : label(i) {}; - - double operator()(T x) const + class Indicator : public std::unary_function { - return (x == label) ? 1. : 0.; + const T label; + public: + Indicator(T i) : label(i) {}; + + double operator()(T x) const + { + return (x == label) ? 1. : 0.; + } + }; // end nested class Indicator + + Indicator indicator(T i) const { + return Indicator(i); } }; @@ -185,8 +192,8 @@ public: trilinear_interpolation(const Coord_type&x, const Coord_type&y, const Coord_type&z, - const Image_word_type& value_outside = - Image_word_type(), + const Target_word_type& value_outside = + Target_word_type(), Image_transform transform = Image_transform() ) const; @@ -198,8 +205,8 @@ public: trilinear_interpolation(const Coord_type&x, const Coord_type&y, const Coord_type&z, - const Image_word_type& value_outside = - Image_word_type()) const + const Target_word_type& value_outside = + Target_word_type()) const { return trilinear_interpolation< Image_word_type, @@ -208,13 +215,31 @@ public: } template - Image_word_type - labellized_trilinear_interpolation(const Coord_type&x, - const Coord_type&y, + typename Coord_type, + typename Target_word_type> + Target_word_type + labellized_trilinear_interpolation(const Coord_type&x, + const Coord_type&y, const Coord_type&z, - const Image_word_type& value_outside = - Image_word_type()) const; + const Target_word_type& value_outside = + Target_word_type()) const + { + CGAL::ImageIO::Indicator_factory indicator_factory; + return labellized_trilinear_interpolation + (x, y, z, value_outside, indicator_factory); + } + + template + Target_word_type + labellized_trilinear_interpolation + (const Coord_type&x, + const Coord_type&y, + const Coord_type&z, + const Target_word_type& value_outside, + const Indicator_factory indicator_factory) const; }; // end Image_3 @@ -226,12 +251,12 @@ Target_word_type Image_3::trilinear_interpolation(const Coord_type& x, const Coord_type& y, const Coord_type& z, - const Image_word_type& value_outside, + const Target_word_type& value_outside, Image_transform transform) const { // Check on double/float coordinates, because (int)-0.1 gives 0 if ( x < 0 || y < 0 || z < 0 ) - return Target_word_type(value_outside); + return value_outside; const Coord_type lx = x / image()->vx; const Coord_type ly = y / image()->vy; @@ -248,7 +273,7 @@ Image_3::trilinear_interpolation(const Coord_type& x, ly >= dimy-1 || lx >= dimx-1) { - return Target_word_type(transform(value_outside)); + return value_outside; } // images are indexed by (z,y,x) @@ -411,12 +436,16 @@ Image_3::trilinear_interpolation(const Coord_type& x, template -Image_word_type -Image_3::labellized_trilinear_interpolation(const Coord_type& x, - const Coord_type& y, - const Coord_type& z, - const Image_word_type& value_outside) const + typename Coord_type, + typename Target_word_type, + typename Indicator_factory> +Target_word_type +Image_3::labellized_trilinear_interpolation + (const Coord_type& x, + const Coord_type& y, + const Coord_type& z, + const Target_word_type& value_outside, + const Indicator_factory indicator_factory) const { // Check on double/float coordinates, because (int)-0.1 gives 0 if ( x < 0 || y < 0 || z < 0 ) return value_outside; @@ -481,15 +510,14 @@ Image_3::labellized_trilinear_interpolation(const Coord_type& x, return labels[0]; } - typedef ImageIO::Indicator Indicator; double best_value = 0.; Image_word_type best = 0; for(int i = 0; i < lc; ++i) { Image_word_type iwt = labels[i]; const double r = - trilinear_interpolation( - x, y, z, value_outside, Indicator(iwt)); + trilinear_interpolation( + x, y, z, value_outside, indicator_factory.indicator(iwt)); CGAL_assertion(r >= 0.); CGAL_assertion(r <= 1.); 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 db2592bf883..0e89f72418a 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 @@ -60,7 +60,7 @@ public: /// Constructor Image_to_labeled_function_wrapper(const Image_& image, const Transform& transform = Transform(), - const Image_word_type value_outside = 0) + const Return_type value_outside = 0) : r_im_(image) , transform(transform) , value_outside(value_outside) @@ -85,7 +85,7 @@ public: if ( labeled_image ) { return static_cast(transform( - r_im_.labellized_trilinear_interpolation( + r_im_.template labellized_trilinear_interpolation( CGAL::to_double(p.x()), CGAL::to_double(p.y()), CGAL::to_double(p.z()), @@ -130,7 +130,7 @@ private: /// Labeled image to wrap const Image_& r_im_; const Transform transform; - const Image_word_type value_outside; + const Return_type value_outside; }; // end class Image_to_labeled_function_wrapper