1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
// Copyright (c) 2009 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/next/Mesh_3/include/CGAL/Mesh_3/Image_to_labeled_function_wrapper.h $
// $Id: Image_to_labeled_function_wrapper.h 67117 2012-01-13 18:14:48Z lrineau $
//
//
// Author(s) : Stéphane Tayeb
//
//******************************************************************************
// File Description :
// Image_to_labeled_function_wrapper declaration and implementation. See
// class description.
//******************************************************************************
#ifndef CGAL_MESH_3_IMAGE_TO_LABELED_FUNCTION_WRAPPER_H
#define CGAL_MESH_3_IMAGE_TO_LABELED_FUNCTION_WRAPPER_H
#include <CGAL/Image_3.h>
namespace CGAL {
namespace Mesh_3 {
/**
* @class Image_to_labeled_function_wrapper
*
* Wraps a labeled image into a labeled function which takes his values into
* N. Uses trilinear interpolation.
* Note: Image has to be labeled with unsigned char
*/
template<class Image_,
class BGT,
typename Image_word_type = unsigned char,
typename Return_type = int,
bool use_trilinear_interpolation=true>
class Image_to_labeled_function_wrapper
{
public:
// Types
typedef Return_type return_type;
typedef Image_word_type word_type;
typedef typename BGT::Point_3 Point_3;
/// Constructor
Image_to_labeled_function_wrapper(const Image_& image)
: r_im_(image) {}
// Default copy constructor and assignment operator are ok
/// Destructor
~Image_to_labeled_function_wrapper() {}
/**
* Returns an int corresponding to the label at point \c p
* @param p the input point
* @return the label at point \c p
*/
return_type operator()(const Point_3& p, const bool = true) const
{
if ( use_trilinear_interpolation )
{
return static_cast<return_type>(
r_im_.labellized_trilinear_interpolation(
CGAL::to_double(p.x()),
CGAL::to_double(p.y()),
CGAL::to_double(p.z()),
word_type(0)));
}
else
{
const int px = static_cast<int>(p.x()/r_im_.vx());
const int py = static_cast<int>(p.y()/r_im_.vy());
const int pz = static_cast<int>(p.z()/r_im_.vz());
const int dimx = r_im_.xdim();
const int dimy = r_im_.ydim();
const int dimz = r_im_.zdim();
if(px < 0 ||
py < 0 ||
pz < 0 ||
px+1 >= dimx ||
py+1 >= dimy ||
pz+1 >= dimz)
{
return 0;
}
const word_type* data = static_cast<const word_type*>(r_im_.data());
return data[ pz*dimy*dimx + py*dimx + px ];
}
}
private:
/// Labeled image to wrap
const Image_& r_im_;
}; // end class Image_to_labeled_function_wrapper
} // end namespace Mesh_3
} // end namespace CGAL
#endif // CGAL_MESH_3_IMAGE_TO_LABELED_FUNCTION_WRAPPER_H
|