Added functionality to models of GeneralPolygonSetTraits_2

This commit is contained in:
Guy Zucker 2008-09-02 10:54:01 +00:00
parent dd3c3d189d
commit b1334aa718
12 changed files with 342 additions and 31 deletions

2
.gitattributes vendored
View File

@ -1241,6 +1241,8 @@ Boolean_set_operations_2/doc_tex/Boolean_set_operations_2/fig/triangles.pdf -tex
Boolean_set_operations_2/doc_tex/Boolean_set_operations_2/fig/unique.eps -text svneol=unset#application/postscript
Boolean_set_operations_2/doc_tex/Boolean_set_operations_2/fig/unique.gif -text svneol=unset#image/gif
Boolean_set_operations_2/doc_tex/Boolean_set_operations_2/fig/unique.pdf -text svneol=unset#application/pdf
Boolean_set_operations_2/doc_tex/Boolean_set_operations_2_ref/GpsGeneralPolygonWithHoles_2.tex -text
Boolean_set_operations_2/doc_tex/Boolean_set_operations_2_ref/GpsGeneralPolygon_2.tex -text
Boolean_set_operations_2/examples/Boolean_set_operations_2/char_g.dat -text
Boolean_set_operations_2/examples/Boolean_set_operations_2/char_m.dat -text
Boolean_set_operations_2/examples/Boolean_set_operations_2/pgn_holes.dat -text

View File

@ -1,5 +1,5 @@
\ccRefPageBegin
\def\ccLongParamLayout{\ccFalse}
\begin{ccRefConcept}{GeneralPolygonWithHoles_2}

View File

@ -13,7 +13,7 @@ polygon edges. Its value type is \ccc{X_monotone_curve_2}.}
\ccGlue
\ccNestedType{Curve_const_iterator}{a const iterator over the geometric
mapping of the polygon edges. Its value type is \ccc{X_monotone_curve_2}.}
\ccDefinition
% ===========
A model of this concept represents a simple general-polygon. The
@ -81,7 +81,7 @@ The value type of \ccc{Iterator} must be \ccc{X_monotone_curve_2}.
\ccHasModels
% ==========
\ccc{CGAL::General_polygon_2<ArrTraits>}
\ccc{CGAL::General_polygon_2<ArrTraits>} {CGAL::Polygon_2<PolygonTraits_2, Container>}
\end{ccRefConcept}

View File

@ -0,0 +1,68 @@
\ccRefPageBegin
\def\ccLongParamLayout{\ccFalse}
\begin{ccRefConcept}{Gps::GeneralPolygonWithHoles_2}
\ccTypes
% ======
\ccThree{GeneralPolygonWithHoles}{Hole_const_iterator~}{}
\ccThreeToTwo
% \ccNestedType{Size}{number of holes size type.}
\ccNestedType{General_polygon_2}{the general-polygon type used to
represent the outer boundary and each hole. Must model the Gps::GeneralPolygon_2 concept.}
\ccNestedType{Hole_const_iterator}{a bidirectional iterator
over the polygonal holes. Its value type is
\ccc{General_polygon_2}.}
\ccDefinition
% ===========
A model of this concept represents a general polygon with holes. This is the
base concept for polygon with holes, and therefore does not require the ability
to access its boundary or holes, but only to be default constructable, copy
constructable, and assignable.
% \lcTex{\ccwParamIndent=0mm}
\ccThree{GeneralPolygonWithHoles_2}{polygon.outer_boundary()~~~}{}
\ccThreeToTwo
\ccCreation
\ccCreationVariable{polygon}
\ccConstructor{GeneralPolygonWithHoles_2();}{default constructor.}
\ccGlue
\ccConstructor{GeneralPolygonWithHoles_2(GeneralPolygonWithHoles_2 other);}
{copy constructor.}
\ccGlue
\ccMethod{GeneralPolygonWithHoles_2 operator=(other);}{assignment operator.}
\ccConstructor{template <class InputIterator>
GeneralPolygonWithHoles_2(General_polygon_2 & outer,
InputIterator begin, InputIterator end);}
{constructs a general polygon with holes using a given general polygon \ccc{outer}
as the outer boundary and a given range of holes. If \ccc{outer} is an empty
general polygon, then an unbounded polygon with holes will be created. The holes must be
contained inside the outer boundary, and the polygons representing the holes
must be strictly simple and pairwise disjoint, except perhaps at the vertices.}
\ccPredicates
% ===========
\ccMethod{bool is_unbounded();}
{returns \ccc{true} if the outer boundary is empty, and \ccc{false}
otherwise.}
\ccAccessFunctions
% ================
\ccHasModels
%===========
\ccc{CGAL::General_polygon_with_holes_2<General_polygon>}\\
\ccc{CGAL::Polygon_with_holes_2<Kernel,Container>}\\
\ccc{CGAL::Gps_circle_segment_traits_2<Kernel>::Polygon_with_holes_2}\\
\ccc{CGAL::Gps_traits_2<ArrTraits,GeneralPolygon>::Polygon_with_holes_2}
\end{ccRefConcept}
\ccRefPageEnd

View File

@ -0,0 +1,78 @@
\ccRefPageBegin
\begin{ccRefConcept}{Gps::GeneralPolygon_2}
\ccTypes
%=======
\ccNestedType{X_monotone_curve_2}{represents a planar (weakly) $x$-monotone
curve. The type of the geometric mapping of the polygonal edges.}
\ccNestedType{Curve_iterator}{an iterator over the geometric mapping of the
polygon edges. Its value type is \ccc{X_monotone_curve_2}.}
\ccGlue
\ccNestedType{Curve_const_iterator}{a const iterator over the geometric
mapping of the polygon edges. Its value type is \ccc{X_monotone_curve_2}.}
\ccDefinition
% ===========
A model of this concept represents a simple general-polygon. The
geometric mapping of the edges of the polygon must be $x$-monotone curves.
This is the base concept for polygons, and therefore does not require the ability
to access these curves, but only to be default constructable, copy constructable,
and assignable.
The general polygon represented must be simple. That is, the
only points of the plane belonging to two curves are the geometric mapping
of the polygon vertices. In addition, the vertices of the represented
polygon must be ordered consistently, and the curved must be directed
accordingly. Only counterclockwise oriented polygons are valid operands
of Boolean set-operations. General polygon that represent holes must be
clockwise oriented.
\ccCreation
\ccCreationVariable{polygon}
\ccThree{Edge_const_iterator~~~}{}{\hspace*{7cm}}
\ccThreeToTwo
\ccConstructor{GeneralPolygon_2();}{default constructor.}
\ccGlue
\ccConstructor{GeneralPolygon_2(GeneralPolygon_2 other);}
{copy constructor.}
\ccGlue
\ccMethod{GeneralPolygon_2 operator=(other);}{assignment operator.}
\ccGlue
\ccConstructor{template <class InputIterator>
GeneralPolygon_2(InputIterator begin, InputIterator end);}
{constructs a general polygon from a given range of curves.}
\ccAccessFunctions
%=================
\ccModifiers
% ==========
\ccMethod{template <class Iterator>
void init(Iterator begin, Iterator end);}
{initializes the polygon with the polygonal chain given by the range.
The value type of \ccc{Iterator} must be \ccc{X_monotone_curve_2}.
\ccPrecond{The curves in the range must define a simple polygon.}}
% \ccPredicates
% % ===========
%
% \ccMethod{bool is_simple();}{returns \ccc{true} if the polygon is simple,
% and \ccc{false} otherwise. Used as precondition for some of the operations.}
% \ccGlue
% \ccMethod{bool is_strictly_simple();}{returns \ccc{true} if the polygon
% is strictly simple, and \ccc{false} otherwise. Used as precondition for
% some of the operations.
% \ccPrecond{\ccStyle{is_simple()}.}}
\ccHasModels
% ==========
\ccc{CGAL::General_polygon_2<ArrTraits>}
\end{ccRefConcept}
\ccRefPageEnd

View File

@ -42,8 +42,8 @@ typedef Rat_kernel::Point_2 Rat_point_2;
typedef Traits_2::Curve_2 Bezier_curve_2;
typedef Traits_2::X_monotone_curve_2 X_monotone_curve_2;
typedef CGAL::Gps_traits_2<Traits_2> Gps_traits_2;
typedef Gps_traits_2::Polygon_2 Polygon_2;
typedef Gps_traits_2::Polygon_with_holes_2 Polygon_with_holes_2;
typedef Gps_traits_2::General_polygon_2 Polygon_2;
typedef Gps_traits_2::General_polygon_with_holes_2 Polygon_with_holes_2;
typedef std::list<Polygon_with_holes_2> Polygon_set;
/*! Read a general polygon with holes, formed by Bezier curves, from the

View File

@ -18,8 +18,8 @@ typedef Kernel::Circle_2 Circle_2;
typedef CGAL::Gps_circle_segment_traits_2<Kernel> Traits_2;
typedef CGAL::General_polygon_set_2<Traits_2> Polygon_set_2;
typedef Traits_2::Polygon_2 Polygon_2;
typedef Traits_2::Polygon_with_holes_2 Polygon_with_holes_2;
typedef Traits_2::General_polygon_2 Polygon_2;
typedef Traits_2::General_polygon_with_holes_2 Polygon_with_holes_2;
typedef Traits_2::Curve_2 Curve_2;
typedef Traits_2::X_monotone_curve_2 X_monotone_curve_2;

View File

@ -40,7 +40,7 @@ struct Conic_traits_2 :
typedef CGAL::General_polygon_2<Conic_traits_2> Polygon_2;
typedef CGAL::Gps_traits_2<Conic_traits_2, Polygon_2> Traits_2;
typedef Traits_2::Polygon_with_holes_2 Polygon_with_holes_2;
typedef Traits_2::General_polygon_with_holes_2 Polygon_with_holes_2;
typedef Traits_2::Curve_2 Curve_2;
typedef Traits_2::X_monotone_curve_2 X_monotone_curve_2;
typedef Traits_2::Point_2 Point_2;

View File

@ -454,8 +454,6 @@ _insert(PolygonIter p_begin, PolygonIter p_end, Polygon_with_holes_2 & /*pgn*/)
}
//insert non-sipmle poloygons with holes (non incident edges may have
// common vertex, but they dont intersect at their interior
template <class Traits_, class Dcel_>
@ -536,10 +534,12 @@ typename General_polygon_set_2<Traits_, Dcel_>::Size
General_polygon_set_2<Traits_, Dcel_>::
number_of_polygons_with_holes() const
{
typedef Arr_bfs_scanner<Arrangement_2, Counting_output_iterator>
Arr_bfs_scanner;
std::size_t res;
Arr_bfs_scanner scanner(this->m_traits, Counting_output_iterator(&res));
//counting_output_operator CTOR reqires a parameter
std::size_t *cc = new size_t();
Arr_bfs_scanner scanner(this->m_traits, Counting_output_iterator(cc));
scanner.scan(*(this->m_arr));
return (scanner.output_iterator().current_counter());
}

View File

@ -27,14 +27,15 @@ CGAL_BEGIN_NAMESPACE
template <class Polygon_>
class General_polygon_with_holes_2
{
public:
typedef General_polygon_with_holes_2<Polygon_> Self;
typedef Polygon_ Polygon_2;
typedef typename Self::Polygon_2 General_polygon_2;
typedef std::list<Polygon_> Holes_container;
typedef Polygon_ General_polygon_2;
typedef std::list<Polygon_> Holes_containter;
typedef typename Holes_containter::iterator Hole_iterator;
typedef typename Holes_containter::const_iterator Hole_const_iterator;
typedef typename Holes_container::iterator Hole_iterator;
typedef typename Holes_container::const_iterator Hole_const_iterator;
typedef unsigned int Size;
@ -42,7 +43,8 @@ public:
{}
explicit General_polygon_with_holes_2(const General_polygon_2& pgn_boundary) : m_pgn(pgn_boundary)
explicit General_polygon_with_holes_2(const General_polygon_2& pgn_boundary)
: m_pgn(pgn_boundary)
{}
@ -124,7 +126,7 @@ public:
protected:
General_polygon_2 m_pgn;
Holes_containter m_holes;
Holes_container m_holes;
};

View File

@ -43,20 +43,27 @@ class Gps_segment_traits_2 : public Arr_seg_traits_
public:
//Polygon_2 type is required by GeneralPolygonSetTraits Concept
typedef CGAL::Polygon_2<Kernel_, Container_> Polygon_2;
//Polygon_2 is a model of the GeneralPolygon2 concept.
typedef Polygon_2 General_polygon_2;
//Polygon_with_holes_2 can be a simple polygon , with holes that are
//entirely inside him , or some vertices of the polygon and its holes
// may overlap.
//Polygon_with_holes_2 type required by GeneralPolygonSetTraits Concept.
typedef CGAL::Polygon_with_holes_2<Kernel_, Container_>
Polygon_with_holes_2;
//Polygon_with_Holes_2 is a model of the GeneralPolygonWithHoles2 concept.
typedef Polygon_with_holes_2 General_polygon_with_holes_2;
typedef typename Base::X_monotone_curve_2 X_monotone_curve_2;
typedef Polygon_2_curve_iterator<X_monotone_curve_2,
Polygon_2> Curve_const_iterator;
typedef typename Polygon_with_holes_2::Hole_const_iterator
Hole_const_iterator;
typedef typename Base::Point_2 Point_2;
@ -101,7 +108,7 @@ public:
public:
std::pair<Curve_const_iterator,
Curve_const_iterator> operator()(const Polygon_2& pgn)
Curve_const_iterator> operator()(const General_polygon_2& pgn)
{
Curve_const_iterator c_begin(&pgn, pgn.edges_begin());
Curve_const_iterator c_end(&pgn, pgn.edges_end());
@ -127,6 +134,76 @@ public:
return (Is_valid_2 (*this, tr_adp));
}
//Added Functionality from GeneralPolygonWithHoles Concept to the traits.
/*A functor for constructing the outer boundary of a polygon with holes*/
class Construct_outer_boundary {
public:
General_polygon_2 operator()(const General_polygon_with_holes_2& pol_wh)
{
return pol_wh.outer_boundary();
}
};
Construct_outer_boundary construct_outer_boundary_object() const {
return Construct_outer_boundary();
}
/*typedef from General_polygon_with_holes_2. Hole_const_iterator nested type is required by
GeneralPolygonWithHoles2 concept*/
/*A functor for constructing the container of holes of a polygon with holes*/
class Construct_holes {
public:
std::pair<Hole_const_iterator, Hole_const_iterator> operator()(const General_polygon_with_holes_2& pol_wh)
{
return std::make_pair(pol_wh.holes_begin(), pol_wh.holes_end());
}
};
Construct_holes construct_holes_object() const {
return Construct_holes();
}
/* A functor for constructing a General_polygon_with_holes from a General_Polygon
(and possibly a range of holes).*/
// constructs a general polygon with holes using a given general polygon outer
// as the outer boundary and a given range of holes. If outer is an empty general
// polygon, then an unbounded polygon with holes will be created. The holes must
// be contained inside the outer boundary, and the polygons representing the holes
// must be strictly simple and pairwise disjoint, except perhaps at the vertices.
class Construct_general_polygon_with_holes_2 {
public:
General_polygon_with_holes_2 operator()(const General_polygon_2& pgn_boundary)
{
return General_polygon_with_holes_2(pgn_boundary);
}
template <class HolesInputIterator>
General_polygon_with_holes_2 operator()(const General_polygon_2& pgn_boundary,
HolesInputIterator h_begin,
HolesInputIterator h_end)
{
return General_polygon_with_holes_2(pgn_boundary, h_begin,h_end);
}
};
Construct_general_polygon_with_holes_2 construct_polygon_with_holes_2_object() const
{
return Construct_general_polygon_with_holes_2();
}
//functor returns true if the outer boundary is empty, and false otherwise.
class Is_unbounded_pred {
public:
bool operator()(const General_polygon_with_holes_2& pol_wh)
{
return pol_wh.is_unbounded();
}
};
Is_unbounded_pred construct_is_unbounded_pred_object() {
return Is_unbounded_pred();
}
};

View File

@ -27,25 +27,39 @@
CGAL_BEGIN_NAMESPACE
template <class Arr_traits,
class Gen_polygon_ = General_polygon_2<Arr_traits> >
template <typename Arr_traits,
typename General_polygon_t = General_polygon_2<Arr_traits> >
class Gps_traits_2 : public Arr_traits
{
typedef Arr_traits Base;
typedef Gps_traits_2<Arr_traits> Self;
typedef Gps_traits_2<Arr_traits,General_polygon_t> Self;
public:
typedef typename Base::Point_2 Point_2;
typedef typename Base::X_monotone_curve_2 X_monotone_curve_2;
typedef Gen_polygon_ Polygon_2;
typedef General_polygon_with_holes_2<Polygon_2> Polygon_with_holes_2;
typedef typename Polygon_2::Curve_const_iterator Curve_const_iterator;
//Polygon_2 type is required by GeneralPolygonSetTraits Concept
typedef General_polygon_t Polygon_2;
//Polygon_2 is a model of the GeneralPolygon2 concept
typedef Polygon_2 General_polygon_2;
//Polygon_with_holes_2 type required by GeneralPolygonSetTraits Concept.
typedef General_polygon_with_holes_2<General_polygon_2> Polygon_with_holes_2;
//Polygon_with_Holes_2 is a model of the GeneralPolygonWithHoles2 concept.
typedef Polygon_with_holes_2 General_polygon_with_holes_2;
typedef typename General_polygon_2::Curve_const_iterator Curve_const_iterator;
typedef typename General_polygon_with_holes_2::Hole_const_iterator
Hole_const_iterator;
typedef typename Base::Equal_2 Equal_2;
typedef typename Base::Compare_endpoints_xy_2 Compare_endpoints_xy_2;
typedef typename Base::Construct_min_vertex_2 Construct_min_vertex_2;
typedef typename Base::Construct_max_vertex_2 Construct_max_vertex_2;
/*!
* A functor for constructing a polygon from a range of x-monotone curves.
*/
@ -56,7 +70,7 @@ public:
template<class XCurveIterator>
void operator()(XCurveIterator begin,
XCurveIterator end,
Polygon_2& pgn)
General_polygon_2& pgn)
{
pgn.init(begin, end);
}
@ -75,7 +89,7 @@ public:
public:
std::pair<Curve_const_iterator,
Curve_const_iterator> operator()(const Polygon_2& pgn)
Curve_const_iterator> operator()(const General_polygon_2& pgn)
{
return std::make_pair(pgn.curves_begin(), pgn.curves_end());
}
@ -97,7 +111,77 @@ public:
Traits_adaptor tr_adp;
return (Is_valid_2 (*this, tr_adp));
}
//Added Functionality from GeneralPolygonWithHoles Concept to the traits.
/*A functor for constructing the outer boundary of a polygon with holes*/
class Construct_outer_boundary {
public:
General_polygon_2 operator()(const General_polygon_with_holes_2& pol_wh)
{
return pol_wh.outer_boundary();
}
};
Construct_outer_boundary construct_outer_boundary_object() const {
return Construct_outer_boundary();
}
/*typedef from General_polygon_with_holes_2. Hole_const_iterator nested type is required by
GeneralPolygonWithHoles2 concept*/
/*A functor for constructing the container of holes of a polygon with holes*/
class Construct_holes {
public:
std::pair<Hole_const_iterator, Hole_const_iterator> operator()(const General_polygon_with_holes_2& pol_wh)
{
return std::make_pair(pol_wh.holes_begin(), pol_wh.holes_end());
}
};
Construct_holes construct_holes_object() const {
return Construct_holes();
}
/* A functor for constructing a General_polygon_with_holes from a General_Polygon
(and possibly a range of holes).*/
// constructs a general polygon with holes using a given general polygon outer
// as the outer boundary and a given range of holes. If outer is an empty general
// polygon, then an unbounded polygon with holes will be created. The holes must
// be contained inside the outer boundary, and the polygons representing the holes
// must be strictly simple and pairwise disjoint, except perhaps at the vertices.
class Construct_general_polygon_with_holes_2 {
public:
General_polygon_with_holes_2 operator()(const General_polygon_2& pgn_boundary)
{
return General_polygon_with_holes_2(pgn_boundary);
}
template <class HolesInputIterator>
General_polygon_with_holes_2 operator()(const General_polygon_2& pgn_boundary,
HolesInputIterator h_begin,
HolesInputIterator h_end)
{
return General_polygon_with_holes_2(pgn_boundary, h_begin,h_end);
}
};
Construct_general_polygon_with_holes_2 construct_polygon_with_holes_2_object() const
{
return Construct_general_polygon_with_holes_2();
}
//functor returns true if the outer boundary is empty, and false otherwise.
class Is_unbounded {
public:
bool operator()(const General_polygon_with_holes_2& pol_wh)
{
return pol_wh.is_unbounded();
}
};
Is_unbounded construct_is_unbounded_object() {
return Is_unbounded();
}
};
CGAL_END_NAMESPACE