CGAL / cgal

The public CGAL repository, see the README below
https://github.com/CGAL/cgal#readme
Other
4.95k stars 1.38k forks source link

Converting objects (ex: Polyhedron_3<>) from one kernel to the other. #5243

Closed ethiy closed 3 years ago

ethiy commented 3 years ago

I am trying to convert a polyhedron using one kernel to another. The idea is to use exact kernels only if necessary. In the following example, I want to compute a minkowski sum which must be done with the CGAL::Epeck kernel. I do not want to make other computations with this kernel as it will be more slow.

Issue Details

Is it possible to develop such a feature? If theoretically impossible, could you explain why?

Example

CGAL::Polyhedron_3<EPECK> exact_shape(shape);
CGAL::Nef_polyhedron_3<EPECK> nef_shape(exact_shape);
auto offset_cube = make_cube(offset);
CGAL::Polyhedron_3<EPECK> exact_cube(offset_cube);
CGAL::Nef_polyhedron_3<EPECK> nef_cube_offset(exact_cube);
auto nef_result = CGAL::minkowski_sum_3(nef_shape, nef_cube_offset);
nef_result.convert_to_polyhedron(exact_shape);
CGAL::Polyhedron_3<Simple_Cartesian> shape_(exact_shape);
shape = shape_;
return shape;

The same works without the attempted conversion. The error message is: no matching function for call to ‘CGAL::Polyhedron_3<CGAL::Epeck>::Polyhedron_3(CGAL::Polyhedron_3<Simple_Cartesian>&)’

Environment

GilesBathgate commented 3 years ago

I think the prefered method is: http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Kernel_23_ref/Class_Cartesian_converter.html

But you could also possibly use: https://github.com/GilesBathgate/RapCAD/blob/master/contrib/Copy_polyhedron_to.h I believe this latter exists somewhere in the examples. You use it like so:

template <class Poly_B, class Poly_A>
void poly_copy(Poly_B& poly_b, const Poly_A& poly_a)
{
        poly_b.clear();
        Copy_polyhedron_to<Poly_A, Poly_B> modifier(poly_a);
        poly_b.delegate(modifier);
}
lrineau commented 3 years ago

Giles' answer is a good one. That is nice to see users answering to users. :smiley:

You can also use CGAL::copy_face_graph. It converts point types from one kernel to another. See that example, where it also converts from a face graph type to another.

ethiy commented 3 years ago

Giles' answer is a good one. That is nice to see users answering to users. 😃

You can also use CGAL::copy_face_graph. It converted point types from one kernel to another. See that example, where it also converts from a face graph type to another.

@lrineau this works very well, thanks!