mirror of https://github.com/CGAL/cgal
make 'weights' a boost named parameter of create_labeled_image_mesh_domain()
This commit is contained in:
parent
445378f1c5
commit
89a227af80
|
|
@ -110,6 +110,7 @@ BOOST_PARAMETER_NAME( (pointer_to_stop_atomic_boolean, tag ) pointer_to_stop_ato
|
|||
BOOST_PARAMETER_NAME( (function, tag ) function_)
|
||||
BOOST_PARAMETER_NAME( (bounding_object, tag ) bounding_object_)
|
||||
BOOST_PARAMETER_NAME( (relative_error_bound, tag ) relative_error_bound_)
|
||||
BOOST_PARAMETER_NAME( (weights, tag) weights_)
|
||||
BOOST_PARAMETER_NAME( (p_rng, tag ) p_rng_)
|
||||
BOOST_PARAMETER_NAME( (null_subdomain_index, tag ) null_subdomain_index_)
|
||||
BOOST_PARAMETER_NAME( (construct_surface_patch_index, tag ) construct_surface_patch_index_)
|
||||
|
|
|
|||
|
|
@ -157,6 +157,11 @@ public:
|
|||
return ::evaluate(image(),i,j,k);
|
||||
}
|
||||
|
||||
bool is_valid() const
|
||||
{
|
||||
return image_ptr.get() != nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool read(const char* file)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include <CGAL/Mesh_criteria_3.h>
|
||||
|
||||
#include <CGAL/Labeled_mesh_domain_3.h>
|
||||
#include <CGAL/Mesh_3/Image_plus_weights_to_labeled_function_wrapper.h>
|
||||
#include <CGAL/Mesh_3/generate_weights_from_labeled_image.h>
|
||||
#include <CGAL/make_mesh_3.h>
|
||||
#include <CGAL/Image_3.h>
|
||||
|
|
@ -35,38 +34,28 @@ using namespace CGAL::parameters;
|
|||
using Word_type = unsigned char;
|
||||
using Subdomain_index = int;
|
||||
|
||||
using Wrapper = CGAL::Mesh_3::Image_plus_weights_to_labeled_function_wrapper<
|
||||
CGAL::Image_3, K, Word_type,
|
||||
unsigned char, // Weights_type,
|
||||
Subdomain_index>;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
/// [Loads images]
|
||||
/// [Loads image]
|
||||
const char* fname = (argc > 1) ? argv[1] : "data/liver.inr.gz";
|
||||
const float sigma = (argc > 2) ? atof(argv[2]) : 1.f;
|
||||
CGAL::Image_3 image;
|
||||
if(!image.read(fname)){
|
||||
std::cerr << "Error: Cannot read file " << fname << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
/// [Loads images]
|
||||
/// [Loads image]
|
||||
|
||||
/// [Generate weights]
|
||||
CGAL::Image_3 weights =
|
||||
const float sigma = (argc > 2) ? atof(argv[2]) : 1.f;
|
||||
CGAL::Image_3 img_weights =
|
||||
CGAL::Mesh_3::generate_weights(image, sigma, (unsigned char)(1));
|
||||
/// [Generate weights]
|
||||
|
||||
/// [Domain creation]
|
||||
Mesh_domain domain = argc > 2
|
||||
? Mesh_domain(Wrapper(image, weights),
|
||||
CGAL::Mesh_3::internal::compute_bounding_box(image),
|
||||
relative_error_bound = 1e-6)
|
||||
: Mesh_domain::create_labeled_image_mesh_domain(
|
||||
image, // null_subdomain_index
|
||||
// = [](auto) { return true;
|
||||
// },
|
||||
relative_error_bound = 1e-6);
|
||||
Mesh_domain domain
|
||||
= Mesh_domain::create_labeled_image_mesh_domain(image,
|
||||
weights = img_weights,
|
||||
relative_error_bound = 1e-6);
|
||||
/// [Domain creation]
|
||||
|
||||
// Mesh criteria
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@
|
|||
// support for `CGAL::Image_3`
|
||||
#include <CGAL/Image_3.h>
|
||||
#include <CGAL/Mesh_3/Image_to_labeled_function_wrapper.h>
|
||||
#include <CGAL/Mesh_3/Image_plus_weights_to_labeled_function_wrapper.h>
|
||||
#include <CGAL/Mesh_3/generate_weights_from_labeled_image.h>
|
||||
|
||||
// support for implicit functions
|
||||
#include <CGAL/Implicit_to_labeling_function_wrapper.h>
|
||||
|
|
@ -418,6 +420,7 @@ public:
|
|||
(optional
|
||||
(relative_error_bound_, (const FT&),
|
||||
FT(1e-3))
|
||||
(weights_, (const CGAL::Image_3&), CGAL::Image_3())
|
||||
(value_outside_, *, 0)
|
||||
(p_rng_, (CGAL::Random*), (CGAL::Random*)(0))
|
||||
(image_values_to_subdomain_indices_, *,
|
||||
|
|
@ -429,18 +432,37 @@ public:
|
|||
)
|
||||
{
|
||||
namespace p = CGAL::parameters;
|
||||
return Labeled_mesh_domain_3
|
||||
(create_labeled_image_wrapper
|
||||
if (weights_.is_valid())
|
||||
{
|
||||
return Labeled_mesh_domain_3
|
||||
(create_weighted_labeled_image_wrapper
|
||||
(image_,
|
||||
weights_,
|
||||
image_values_to_subdomain_indices_,
|
||||
value_outside_),
|
||||
Mesh_3::internal::compute_bounding_box(image_),
|
||||
p::relative_error_bound = relative_error_bound_,
|
||||
p::p_rng = p_rng_,
|
||||
p::null_subdomain_index =
|
||||
create_null_subdomain_index(null_subdomain_index_),
|
||||
p::construct_surface_patch_index =
|
||||
create_construct_surface_patch_index(construct_surface_patch_index_));
|
||||
Mesh_3::internal::compute_bounding_box(image_),
|
||||
p::relative_error_bound = relative_error_bound_,
|
||||
p::p_rng = p_rng_,
|
||||
p::null_subdomain_index =
|
||||
create_null_subdomain_index(null_subdomain_index_),
|
||||
p::construct_surface_patch_index =
|
||||
create_construct_surface_patch_index(construct_surface_patch_index_));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Labeled_mesh_domain_3
|
||||
(create_labeled_image_wrapper
|
||||
(image_,
|
||||
image_values_to_subdomain_indices_,
|
||||
value_outside_),
|
||||
Mesh_3::internal::compute_bounding_box(image_),
|
||||
p::relative_error_bound = relative_error_bound_,
|
||||
p::p_rng = p_rng_,
|
||||
p::null_subdomain_index =
|
||||
create_null_subdomain_index(null_subdomain_index_),
|
||||
p::construct_surface_patch_index =
|
||||
create_construct_surface_patch_index(construct_surface_patch_index_));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_PARAMETER_MEMBER_FUNCTION(
|
||||
|
|
@ -866,6 +888,32 @@ protected:
|
|||
transform_fct(value_outside));
|
||||
}
|
||||
|
||||
template <typename Image_word_type,
|
||||
typename FT, typename Functor>
|
||||
static
|
||||
Function
|
||||
create_weighted_labeled_image_wrapper_with_know_word_type
|
||||
(const CGAL::Image_3& image,
|
||||
const CGAL::Image_3& weights,
|
||||
const Functor& image_values_to_subdomain_indices,
|
||||
const FT& value_outside)
|
||||
{
|
||||
using Mesh_3::internal::Create_labeled_image_values_to_subdomain_indices;
|
||||
typedef Create_labeled_image_values_to_subdomain_indices<Functor> C_i_v_t_s_i;
|
||||
typedef typename C_i_v_t_s_i::type Image_values_to_subdomain_indices;
|
||||
Image_values_to_subdomain_indices transform_fct =
|
||||
C_i_v_t_s_i()(image_values_to_subdomain_indices);
|
||||
|
||||
typedef Mesh_3::Image_plus_weights_to_labeled_function_wrapper<
|
||||
Image_word_type,
|
||||
unsigned char, // Weights_type,
|
||||
Subdomain_index> Wrapper;
|
||||
return Wrapper(image,
|
||||
weights,
|
||||
transform_fct,
|
||||
transform_fct(value_outside));
|
||||
}
|
||||
|
||||
template <typename FT, typename Functor>
|
||||
static
|
||||
Function
|
||||
|
|
@ -885,6 +933,27 @@ protected:
|
|||
return Function();
|
||||
}
|
||||
|
||||
template <typename FT, typename Functor>
|
||||
static
|
||||
Function
|
||||
create_weighted_labeled_image_wrapper(const CGAL::Image_3& image,
|
||||
const CGAL::Image_3& weights,
|
||||
const Functor& image_values_to_subdomain_indices,
|
||||
const FT& value_outside)
|
||||
{
|
||||
CGAL_IMAGE_IO_CASE(image.image(),
|
||||
return create_weighted_labeled_image_wrapper_with_know_word_type<Word>
|
||||
(image,
|
||||
weights,
|
||||
image_values_to_subdomain_indices,
|
||||
value_outside);
|
||||
);
|
||||
CGAL_error_msg("This place should never be reached, because it would mean "
|
||||
"the image word type is a type that is not handled by "
|
||||
"CGAL_ImageIO.");
|
||||
return Function();
|
||||
}
|
||||
|
||||
static
|
||||
Construct_surface_patch_index
|
||||
create_construct_surface_patch_index(const Null_functor&) {
|
||||
|
|
|
|||
|
|
@ -72,26 +72,25 @@ namespace Mesh_3 {
|
|||
* Wraps a pair of images into a labeled function which takes his values into
|
||||
* N. Uses weighted trilinear interpolation.
|
||||
*/
|
||||
template<class Image_,
|
||||
class BGT,
|
||||
typename Image_word_type = unsigned char,
|
||||
template<typename Image_word_type = unsigned char,
|
||||
typename Weights_type = unsigned char,
|
||||
typename Return_type = int,
|
||||
typename Transform = Identity<Return_type>
|
||||
typename Image_values_to_labels = std::function<Return_type(Image_word_type)>
|
||||
>
|
||||
class Image_plus_weights_to_labeled_function_wrapper
|
||||
{
|
||||
public:
|
||||
|
||||
// Types
|
||||
typedef Return_type return_type;
|
||||
typedef Image_word_type word_type;
|
||||
typedef typename BGT::Point_3 Point_3;
|
||||
typedef CGAL::Image_3 Image_;
|
||||
|
||||
/// Constructor
|
||||
Image_plus_weights_to_labeled_function_wrapper
|
||||
(const Image_& image,
|
||||
const Image_& weights_image,
|
||||
const Transform& transform = Transform(),
|
||||
Image_values_to_labels transform = Identity<Return_type>(),
|
||||
const Return_type value_outside = 0)
|
||||
: r_im_(image)
|
||||
, r_weights_im_(weights_image)
|
||||
|
|
@ -111,9 +110,9 @@ public:
|
|||
* @param p the input point
|
||||
* @return the label at point \c p
|
||||
*/
|
||||
return_type operator()(const Point_3& p, const bool = true) const
|
||||
template <typename Point_3>
|
||||
return_type operator()(const Point_3& p) const
|
||||
{
|
||||
|
||||
return transform(
|
||||
r_im_.template labellized_trilinear_interpolation<Image_word_type>(
|
||||
CGAL::to_double(p.x()),
|
||||
|
|
@ -127,7 +126,7 @@ private:
|
|||
/// Labeled image to wrap
|
||||
const Image_& r_im_;
|
||||
const Image_& r_weights_im_;
|
||||
const Transform transform;
|
||||
const Image_values_to_labels transform;
|
||||
const Return_type value_outside;
|
||||
CGAL::ImageIO::Weighted_indicator_factory<Image_word_type,
|
||||
Weights_type> indicator_factory;
|
||||
|
|
|
|||
Loading…
Reference in New Issue