Subject: CGAL users discussion list
List archive
- From: Andreas Meyer <>
- To:
- Subject: Re: [cgal-discuss] Computing a convex hull with points derived from Point_2
- Date: Mon, 17 Dec 2007 15:39:56 +0100
Michael Hoffmann wrote:
I'm trying to compute a convex hull with points in 2D that
carry some "meta information" (e.g. two unsigned ints).
My first idea was to derive a class from Point_2 which has
two addition member. However, this does not seem to work as
I get a lengthy error message in IO/Tee_for_output_iterator.h,
line 52 where CGAL tries to assign a Point_2 to my derived class.
Did you check the section "Extensible Kernel" in the manual? There is
an example...
http://www.cgal.org/Manual/3.3/doc_html/cgal_manual/Kernel_23/Chapter_main.html#Section_2.5
regards,
Michael
Maybe you want to have a look at a simple preliminary
Kernel_with_attributes wrapper. It is probably included in the next CGAL
release. Be prepared that the interface might change until the official
release of CGAL, so be careful when integrating it into your program.
Use it like this: there is a Kernel_with_attributes class, which accepts
a Kernel and an "Attributes" traits. For the "Attributes", you can use
"Kernel_with_attributes_uniform_attributes<T>" (for example with int) or
create a more fine-grained attributes class, where for each kernel
object O, there is a class O_attribute which is going to be the type of
O().attribute. There is a default attribute class with only void attributes, called "Kernel_with_attributes_default_attributes", which you can inherit from.
An easy example:
#include "Kernel_with_attributes.h"
typedef CGAL::Kernel_with_attributes <
Kernel_to_be_extended,
CGAL::Kernel_with_attributes_uniform_attributes<int>
> My_kernel_with_attributes;
// to access the attribute, given a Point_2 from that kernel:
Point_2 p;
p.attribute = 123;
--------
To come back to the original question: you can also specify arbitrary structs instead of ints, of course.
Best Regards,
Andreas Meyer
#ifndef CGAL_KERNEL_WITH_ATTRIBUTES_H
#define CGAL_KERNEL_WITH_ATTRIBUTES_H
#include <CGAL/basic.h>
#include <CGAL/Kernel/Type_equality_wrapper.h>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
#include <boost/mpl/if.hpp>
#include <boost/type_traits/is_void.hpp>
CGAL_BEGIN_NAMESPACE
template< class K, class K_base, class Attributes >
struct Kernel_with_attributes_base
: public K_base::template Base< K >::Type
{
typedef typename K_base::template Base< K >::Type Kernel_base;
template < typename K2 >
struct Base {
typedef Kernel_with_attributes_base<K2, K_base, Attributes> Type;
};
#define CGAL_KERNEL_WITH_ATTRIBUTES_CONSTRUCTOR(Z,N,TEXT) \
template< BOOST_PP_ENUM_PARAMS(N, typename A) > \
TEXT ## _base( BOOST_PP_ENUM_BINARY_PARAMS(N, const A, &a) ) \
: Kernel_base::TEXT( BOOST_PP_ENUM_PARAMS(N, a) ) \
{}
#define CGAL_Kernel_obj(X)
\
template< bool DummyParam >
\
struct X ## _base : public Kernel_base::X {
\
typename Attributes::X ## _attribute attribute;
\
BOOST_PP_REPEAT_FROM_TO( 1, 15,
CGAL_KERNEL_WITH_ATTRIBUTES_CONSTRUCTOR, X) \
X ## _base() {}
\
};
\
\
typedef
\
typename ::boost::mpl::if_c<
\
::boost::is_void< typename Attributes::X ## _attribute >::value,
\
typename Kernel_base::X,
\
X ## _base<true>
\
>::type X;
#include <CGAL/Kernel/interface_macros.h>
#undef CGAL_KERNEL_WITH_ATTRIBUTES_CONSTRUCTOR
};
template< class K, class Attributes >
struct Kernel_with_attributes
: public Type_equality_wrapper<
Kernel_with_attributes_base< Kernel_with_attributes<K,
Attributes>,
K,
Attributes >,
Kernel_with_attributes<K,
Attributes>
>
{};
struct Kernel_with_attributes_default_attributes {
#define CGAL_Kernel_obj(X) typedef void X ## _attribute;
#include <CGAL/Kernel/interface_macros.h>
};
template< typename Attribute >
struct Kernel_with_attributes_uniform_attributes {
#define CGAL_Kernel_obj(X) typedef Attribute X ## _attribute;
#include <CGAL/Kernel/interface_macros.h>
};
CGAL_END_NAMESPACE
#endif // CGAL_KERNEL_WITH_ATTRIBUTES_H
- Computing a convex hull with points derived from Point_2, Ole Schulz-Trieglaff, 12/17/2007
- Re: [cgal-discuss] Computing a convex hull with points derived from Point_2, Michael Hoffmann, 12/17/2007
- Re: [cgal-discuss] Computing a convex hull with points derived from Point_2, Andreas Meyer, 12/17/2007
- exact constructions kernel + 2D mesher ?, Maarten Moesen, 12/17/2007
- Re: [cgal-discuss] exact constructions kernel + 2D mesher ?, Andreas Fabri, 12/17/2007
- Re: [cgal-discuss] exact constructions kernel + 2D mesher ?, Maarten Moesen, 12/17/2007
- Re: exact constructions kernel + NEF polyhedra?, Maarten Moesen, 12/17/2007
- Re: [cgal-discuss] exact constructions kernel + 2D mesher ?, Laurent Rineau, 12/17/2007
- Re: [cgal-discuss] exact constructions kernel + 2D mesher ?, Maarten Moesen, 12/18/2007
- Re: [cgal-discuss] exact constructions kernel + 2D mesher ?, Andreas Fabri, 12/17/2007
- Re: [cgal-discuss] Computing a convex hull with points derived from Point_2, Michael Hoffmann, 12/17/2007
Archive powered by MHonArc 2.6.16.