I want to write a template function that does something to a mesh, but without assuming anything about how the mesh is defined (i.e. I don't know what the kernel is).
I thought I could do something like this: template<class Mesh> void someFn(const Mesh &m) { typedef typename CGAL::Kernel_traits<Mesh>::Kernel Kernel; typedef typename Kernel::Point_3 Point; ... but this gives me errors like: 'CGAL::internal_kernel_traits::Dummy_kernel<CGAL::Surface_mesh<CGAL::Point_3<CGAL::Epeck> > >' typedef typename CGAL::Kernel_traits<Mesh>::Kernel::Point_3 Point; What am I doing wrong? -- You are currently subscribed to cgal-discuss. To unsubscribe or access the archives, go to https://sympa.inria.fr/sympa/info/cgal-discuss |
Hi, If you look at the documentation of Kernel_traits (https://doc.cgal.org/latest/Kernel_23/structCGAL_1_1Kernel__traits.html),
you'll see that this traits class searches for a `R` typedef,
which is the kernel. This `R` typedef exists for CGAL kernel
objects (e.g. CGAL::Point_2, Point_3, etc.) but not for mesh types
such as `Surface_mesh`. What you would usually do here is to extract the point type from the mesh vertex->point property map of your mesh and call `Kernel_traits` on that point type, so something like: typedef typename property_map_value<Mesh,
CGAL::vertex_point_t>::type
Point; Note that this still assumes that your mesh is compatible with the BGL interface, which is valid for all meshes in CGAL and so more from other libraries, see https://doc.cgal.org/latest/BGL/index.html#title0. Furthermore, your `Point` type must be compatible with `Kernel_traits` (i.e. it defines a `R` typedef), otherwise you will need a partial specialization of `Kernel_traits`. Best, On 2020-08-09 14:00, Ben Laurie wrote:
-- You are currently subscribed to cgal-discuss. To unsubscribe or access the archives, go to https://sympa.inria.fr/sympa/info/cgal-discuss |
On Sun, 9 Aug 2020 at 22:07, Mael <[hidden email]> wrote:
Any particular reason why not?
If I try that, I get: error: expected a qualified name after 'typename' If I take out the typename, I get: error: no template named 'property_map_value' Not sure what header defines it, but if I include this header, which also uses property_map_value, I get the same error...
I am using CGAL::Surface_mesh.
-- You are currently subscribed to cgal-discuss. To unsubscribe or access the archives, go to https://sympa.inria.fr/sympa/info/cgal-discuss |
It turns out, BTW, that you can do this: typedef typename Mesh::Point Point; typedef typename CGAL::Kernel_traits<Point>::Kernel Kernel; On Thu, 13 Aug 2020 at 05:23, Ben Laurie <[hidden email]> wrote:
-- You are currently subscribed to cgal-discuss. To unsubscribe or access the archives, go to https://sympa.inria.fr/sympa/info/cgal-discuss |
Le jeu. 13 août 2020 à 06:36, Ben Laurie <[hidden email]> a écrit :
You can do that if you know your mesh is a Surface_mesh. If it can be another type, then you can't, all types don't define the Point type.
Because a mesh is not a Kernel object. It is not expected to work with that function.
The right code would be typedef boost::property_traits< boost::property_map< Mesh, vertex_point_t>::type >::value_type Point; But again, with a Surface_mesh, you can just use the typename Surface_mesh<K>::Point.
-- You are currently subscribed to cgal-discuss. To unsubscribe or access the archives, go to https://sympa.inria.fr/sympa/info/cgal-discuss |
Free forum by Nabble | Edit this page |