cgal/Packages/Tutorial/tutorial/Polyhedron/doc/poly_enrich.tex

197 lines
4.4 KiB
TeX

The polyhedron can be parameterized by a \italic{traits} class in
order to extend the vertex, halfedge and facet primitives. In this
tutorial all primitives (facets, halfedges and vertices) are
extended. The facet is extended with a normal and with a
general-purpose integer tag:
{ \scriptsize
\begin{verbatim}
template <class Refs, class T, class P, class Norm>
class Enriched_facet :
public CGAL::HalfedgeDS_face_base<Refs, T>
{
// tag
int m_tag;
// normal
Norm m_normal;
public:
// no constructors to repeat, since only
// default constructor mandatory
Enriched_facet()
{
}
// tag
const int& tag() { return m_tag; }
void tag(const int& t) { m_tag = t; }
// normal
typedef Norm Normal_3;
Normal_3& normal() { return m_normal; }
const Normal_3& normal() const { return m_normal; }
};
\end{verbatim}}
The halfedge is extended with a general-purpose tag and a binary tag
to indicate wether it belongs to the control mesh or not. The latter
tag is used to superimpose the control mesh as shown in
Fig.\ref{fig:teaser}.
{ \scriptsize
\begin{verbatim}
template <class Refs, class Tprev, class Tvertex,
class Tface, class Norm>
class Enriched_halfedge : public
CGAL::HalfedgeDS_halfedge_base<Refs,Tprev,Tvertex,Tface>
{
private:
// tag
int m_tag;
// option for control edge superimposing
bool m_control_edge;
public:
// life cycle
Enriched_halfedge()
{
m_control_edge = true;
}
// tag
const int& tag() const { return m_tag; }
int& tag() { return m_tag; }
void tag(const int& t) { m_tag = t; }
// control edge
bool& control_edge() { return m_control_edge; }
const bool& control_edge() const { return m_control_edge; }
void control_edge(const bool& flag) { m_control_edge = flag; }
};
\end{verbatim}}
The vertex is extended with a normal and a general-purpose integer
tag:
{ \scriptsize
\begin{verbatim}
template <class Refs, class T, class P, class Norm>
class Enriched_vertex :
public CGAL::HalfedgeDS_vertex_base<Refs, T, P>
{
// tag
int m_tag;
// normal
Norm m_normal;
public:
// life cycle
Enriched_vertex() {}
// repeat mandatory constructors
Enriched_vertex(const P& pt)
: CGAL::HalfedgeDS_vertex_base<Refs, T, P>(pt)
{
}
// normal
typedef Norm Normal_3;
Normal_3& normal() { return m_normal; }
const Normal_3& normal() const { return m_normal; }
// tag
int& tag() { return m_tag; }
const int& tag() const { return m_tag; }
void tag(const int& t) { m_tag = t; }
};
\end{verbatim}}
A redefined items class for the polyhedron uses the class wrapper
mechanism to embedd all three extended primitives within one unique
class.
{ \scriptsize
\begin{verbatim}
struct Enriched_items : public CGAL::Polyhedron_items_3
{
// wrap vertex
template <class Refs, class Traits>
struct Vertex_wrapper
{
typedef typename Traits::Point_3 Point;
typedef typename Traits::Vector_3 Normal;
typedef Enriched_vertex<Refs,
CGAL::Tag_true,
Point,
Normal> Vertex;
};
// wrap face
template <class Refs, class Traits>
struct Face_wrapper
{
typedef typename Traits::Point_3 Point;
typedef typename Traits::Vector_3 Normal;
typedef Enriched_facet<Refs,
CGAL::Tag_true,
Point,
Normal> Face;
};
// wrap halfedge
template <class Refs, class Traits>
struct Halfedge_wrapper
{
typedef typename Traits::Vector_3 Normal;
typedef Enriched_halfedge<Refs,
CGAL::Tag_true,
CGAL::Tag_true,
CGAL::Tag_true,
Normal> Halfedge;
};
};
\end{verbatim}}
The trait class is then used for templating a polyhedron
\italic{Enriched\_polyhedron}:
{ \scriptsize
\begin{verbatim}
template <class kernel, class items>
class Enriched_polyhedron :
public CGAL::Polyhedron_3<kernel,items>
{
//...
};
\end{verbatim}}
The corresponding instanciation of an enriched polyhedron follows:
{ \scriptsize
\begin{verbatim}
#include <CGAL/Simple_cartesian.h>
#include "enriched_polyhedron.h"
typedef double number_type;
typedef CGAL::Simple_cartesian<number_type> kernel;
Enriched_polyhedron<kernel,Enriched_items> polyhedron;
\end{verbatim}}