Make the example more interesting.

Fix const correctness.
Fix the Subconstraint_iterator.
Improve the manual.
This commit is contained in:
Andreas Fabri 2013-04-03 15:28:46 +02:00
parent 530adb1b9e
commit 5e08e87d3d
8 changed files with 131 additions and 49 deletions

View File

@ -291,13 +291,7 @@ template <class PolygonTraits_2, class Container, class CostFunction, class Stop
CostFunction cost,
StopFunction stop)
{
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_2<K> Vb;
typedef CGAL::Constrained_triangulation_face_base_2<K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> TDS;
typedef CGAL::Exact_predicates_tag Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2<K,TDS, Itag> CDT;
typedef CGAL::Polyline_constrained_triangulation_2<CDT> PCT;
typedef CGAL::Polyline_constrained_triangulation_2<> PCT;
typedef PCT::Constraint_id Constraint_id;
typedef PCT::Vertices_in_constraint_iterator Vertices_in_constraint_iterator;

View File

@ -283,7 +283,7 @@ void insert_constraint(InputIterator begin, InputIterator end);
/*!
Inserts the polyline defined by the iterator range `range`.
\tparam InputIterator must be an input iterator with value type `Point`.
\tparam IteratorRange must be an iterator range with value type `Point`.
*/
template <typename IteratorRange>
void insert_constraint(IteratorRange range);

View File

@ -208,7 +208,7 @@ void insert_constraint(Point a, Point b);
/*!
Inserts the constraint `c`.
*/
void push_back(const Constraint& c);
void push_back(const std::pair<Point,Point>& c);
/*!
Inserts a constraint whose endpoints are the vertices
@ -216,6 +216,21 @@ pointed by `va` and `vb` in the triangulation.
*/
void insert_constraint(Vertex_handle va, Vertex_handle vb);
/*!
Inserts a polyline defined by the points in the range `[first,last)`.
\tparam InputIterator must be an input iterator with the value type `Point`.
*/
template < class InputIterator>
insert_constraint(InputIterator first, InputIterator last)
/*!
Inserts the polyline defined by the iterator range `range`.
\tparam IteratorRange must be an iterator range with value type `Point`.
*/
template <typename IteratorRange>
void insert_constraint(IteratorRange range);
/*!
Removes the constraint joining the vertices pointed by `va` and `vb`.
\pre `va` and `vb` have to refer to the endpoint vertices of an input constraint.

View File

@ -222,6 +222,22 @@ pointed by `va` and `vb` in the triangulation.
*/
void insert_constraint(Vertex_handle va, Vertex_handle vb);
/*!
Inserts a polyline defined by the points in the range `[first,last)`.
Returns the constraint id.
\tparam InputIterator must be an input iterator with the value type `Point`.
*/
template < class InputIterator>
Constraint_id insert_constraint(InputIterator first, InputIterator last);
/*!
Inserts the polyline defined by the iterator range `range`.
\tparam IteratorRange must be an iterator range with value type `Point`.
*/
template <typename IteratorRange>
void insert_constraint(IteratorRange range);
/*!
Removes the constraint `cid`, without removing the points from the triangulation.
*/
@ -303,10 +319,19 @@ vertices_in_constraint_end(Constraint_id cid) const;
/// @}
/// \name Polyline Simplification
/// The polyline simplification algorithm described in Chapter
/// \ref Chapter_2D_Polyline_simplification uses the following types and
/// functions.
/*! \name Polyline Simplification
The polyline simplification algorithm described in Chapter
\ref Chapter_2D_Polyline_simplification
operates on polyline constraints. The algorithm removes
vertices of a constraint and at the same time from the triangulation.
The points of removed vertices are nevertheless kept
in the the polyline constraint.
This allows the simplification algorithm to compute the error
introduced by the simplification process by comparing the
current sequence (vertices) to the original sequence (points).
The simplification algorithm uses the following types and functions.
*/
/// @{
@ -321,9 +346,11 @@ typedef Hidden_type Points_in_constraint_iterator;
/*!
Removes vertex at `viq` from the constraint and the triangulation.
Only the vertex but not the point is removed from the constraint `cid`.
\pre The vertex at `viq` must not be the first or last vertex,
must not be fixed, and the line segment between the predecessor `vip` and
the successor `vir` of `viq` must not intersect any constraint.
\pre The vertices `vip`, `viq`, and `vir` must be three successive
vertices in a constraint.
\pre No other constraint must pass through `viq`.
\pre The line segment between `vip` and `vir` must not intersect any constraint.
\pre All vertices of the triangulation are vertex of a constaint.
*/
void

View File

@ -1027,12 +1027,12 @@ constrained edge, the set of input constraints that overlap it.
The class `Polyline_constrained_triangulation_2<Tr>`
is especially useful when the base constrained triangulation class
handles intersections of constraints and uses an exact number type,
i.e. when its intersection tag is `Exact_intersections_tag`.
i.e.\ when its intersection tag is `Exact_intersections_tag`.
Indeed in this case, the `Polyline_constrained_triangulation_2<Tr>`
is specially designed to avoid cascading in the computations of
intersection points.
\subsection Triangulation_2ExampleBuildingaTriangulated Example: Building a Triangulated Arrangement of Segments
\subsection Triangulation_2ExampleBuildingaTriangulated Example: Building a Triangulated Arrangement of Polylines
The following code inserts a set of intersecting constraint segments
into a triangulation

View File

@ -17,12 +17,13 @@ typedef CGAL::Polyline_constrained_triangulation_2<CDT> PCT;
typedef PCT::Point Point;
typedef PCT::Constraint_id Cid;
typedef PCT::Vertices_in_constraint Vertices_in_constraint;
typedef PCT::Vertex_handle Vertex_handle;
void
print(const PCT& cdt, Cid cid)
{
typedef PCT::Vertices_in_constraint Vertices_in_constraint;
std::cout << "Polyline constraint:" << std::endl;
for(Vertices_in_constraint it = cdt.vertices_in_constraint_begin(cid);
it != cdt.vertices_in_constraint_end(cid);
@ -32,6 +33,30 @@ print(const PCT& cdt, Cid cid)
}
}
void
contexts(const PCT& pct)
{
PCT::Subconstraint_iterator beg, end;
beg = pct.subconstraints_begin();
end = pct.subconstraints_end();
for(; beg!=end; ++beg){
Vertex_handle vp = beg->first, vq = beg->second;
if(pct.number_of_enclosing_constraints(vp, vq) == 2){
PCT::Context_iterator cbeg = pct.contexts_begin(vp,vq);
PCT::Context_iterator cend = pct.contexts_end(vp,vq);
std::cout << "subconstraint " << vp->point() << " " << vq->point()
<< " is on constraints starting at:\n";
for(; cbeg != cend; ++cbeg){
PCT::Context c = *cbeg;
std::cout << (*(c.vertices_begin()))->point() << std::endl;
}
}
}
}
int
main( )
{
@ -59,5 +84,7 @@ main( )
print(pct, id1);
print(pct, id2);
contexts(pct);
return 0;
}

View File

@ -39,7 +39,7 @@ namespace CGAL {
template < class Tr_ = Default >
class Polyline_constrained_triangulation_2
: public
Default::Get< Constrained_Delaunay_triangulation_2<
Default::Get< Tr_, Constrained_Delaunay_triangulation_2<
Exact_predicates_inexact_constructions_kernel
, Triangulation_data_structure_2<
Polyline_constrained_triangulation_vertex_base<
@ -48,11 +48,10 @@ class Polyline_constrained_triangulation_2
, Constrained_triangulation_face_base_2<Exact_predicates_inexact_constructions_kernel>
>
, CGAL::Exact_predicates_tag
>
, Tr_>::type
> >::type
{
typedef typename
Default::Get< Constrained_Delaunay_triangulation_2<
Default::Get< Tr_, Constrained_Delaunay_triangulation_2<
Exact_predicates_inexact_constructions_kernel
, Triangulation_data_structure_2<
Polyline_constrained_triangulation_vertex_base<
@ -61,9 +60,7 @@ class Polyline_constrained_triangulation_2
, Constrained_triangulation_face_base_2<Exact_predicates_inexact_constructions_kernel>
>
, CGAL::Exact_predicates_tag
>
, Tr_
>::type Tr;
> >::type Tr;
template<class CDT>
@ -144,7 +141,7 @@ public:
typedef typename Polyline_constraint_hierarchy::Context Context;
typedef typename Polyline_constraint_hierarchy::Context_iterator Context_iterator;
typedef typename Polyline_constraint_hierarchy::C_iterator Constraint_iterator;
typedef typename Polyline_constraint_hierarchy::Sc_iterator Subconstraint_iterator;
typedef typename Polyline_constraint_hierarchy::Subconstraint_iterator Subconstraint_iterator;
typedef typename Polyline_constraint_hierarchy::Constraint_id Constraint_id;
@ -501,7 +498,7 @@ private:
vertices.push_back(vertices.front());
}
int n = vertices.size();
std::size_t n = vertices.size();
if(n == 1){
return NULL;
}
@ -625,16 +622,16 @@ public:
Constraint_iterator constraints_end() const;
Subconstraint_iterator subconstraints_begin() const;
Subconstraint_iterator subconstraints_end() const;
Context context(Vertex_handle va, Vertex_handle vb);
Context context(Vertex_handle va, Vertex_handle vb) const;
bool is_subconstraint(Vertex_handle va,
Vertex_handle vb);
size_type number_of_enclosing_constraints(Vertex_handle va,
Vertex_handle vb);
Vertex_handle vb) const;
Context_iterator contexts_begin(Vertex_handle va,
Vertex_handle vb);
Vertex_handle vb) const;
Context_iterator contexts_end(Vertex_handle va,
Vertex_handle vb);
Vertex_handle vb) const;
Vertices_in_constraint_iterator vertices_in_constraint_begin(Constraint_id cid) const;
Vertices_in_constraint_iterator vertices_in_constraint_end(Constraint_id cid) const ;
@ -1013,7 +1010,7 @@ Polyline_constrained_triangulation_2<Tr>::Subconstraint_iterator
Polyline_constrained_triangulation_2<Tr>::
subconstraints_begin() const
{
return hierarchy.sc_begin();
return hierarchy.subconstraint_begin();
}
template <class Tr>
@ -1023,7 +1020,7 @@ Polyline_constrained_triangulation_2<Tr>::Subconstraint_iterator
Polyline_constrained_triangulation_2<Tr>::
subconstraints_end() const
{
return hierarchy.sc_end();
return hierarchy.subconstraint_end();
}
@ -1031,7 +1028,7 @@ template <class Tr>
inline
typename Polyline_constrained_triangulation_2<Tr>::Context
Polyline_constrained_triangulation_2<Tr>::
context(Vertex_handle va, Vertex_handle vb)
context(Vertex_handle va, Vertex_handle vb) const
{
return hierarchy.context(va,vb);
}
@ -1041,7 +1038,7 @@ template <class Tr>
inline
typename Polyline_constrained_triangulation_2<Tr>::size_type
Polyline_constrained_triangulation_2<Tr>::
number_of_enclosing_constraints(Vertex_handle va, Vertex_handle vb)
number_of_enclosing_constraints(Vertex_handle va, Vertex_handle vb) const
{
return static_cast<size_type>
(hierarchy.number_of_enclosing_constraints(va,vb));
@ -1060,7 +1057,7 @@ template <class Tr>
inline
typename Polyline_constrained_triangulation_2<Tr>::Context_iterator
Polyline_constrained_triangulation_2<Tr>::
contexts_begin(Vertex_handle va, Vertex_handle vb)
contexts_begin(Vertex_handle va, Vertex_handle vb) const
{
return hierarchy.contexts_begin(va,vb);
}
@ -1069,7 +1066,7 @@ template <class Tr>
inline
typename Polyline_constrained_triangulation_2<Tr>::Context_iterator
Polyline_constrained_triangulation_2<Tr>::
contexts_end(Vertex_handle va, Vertex_handle vb)
contexts_end(Vertex_handle va, Vertex_handle vb) const
{
return hierarchy.contexts_end(va,vb);
}

View File

@ -29,6 +29,7 @@
#include <CGAL/Skiplist.h>
#include <CGAL/Iterator_project.h>
#include <CGAL/triangulation_assertions.h>
#include <boost/iterator/transform_iterator.hpp>
namespace CGAL {
@ -113,11 +114,11 @@ public:
: enclosing(hc.enclosing), pos(hc.pos)
{}
Vertex_it vertices_begin() { return enclosing->begin();}
Vertex_it vertices_begin() { return enclosing->skip_begin();}
Vertex_it current() {return pos;}
Vertex_it vertices_end() {return enclosing->end();}
Vertex_it vertices_end() {return enclosing->skip_end();}
Constraint_id id() { return enclosing; }
std::size_t number_of_vertices() {return enclosing->size();}
std::size_t number_of_vertices() const {return enclosing->size();}
};
typedef std::list<Context> Context_list;
@ -128,6 +129,15 @@ public:
typedef typename Constraint_set::const_iterator C_iterator;
typedef typename Sc_to_c_map::const_iterator Sc_iterator;
struct First
: public std::unary_function<std::pair<Edge, Context_list*>,Edge> {
Edge operator()(const std::pair<Edge, Context_list*>& p) const
{
return p.first;
}
};
typedef boost::transform_iterator<First,Sc_iterator> Subconstraint_iterator;
private:
// data for the 1d hierarchy
Constraint_set constraint_set;
@ -164,11 +174,11 @@ public:
void oriented_end(T va, T vb, T& vc) const;
Context context(T va, T vb);
std::size_t number_of_enclosing_constraints(T va, T vb);
Context_iterator contexts_begin(T va, T vb);
Context_iterator contexts_end(T va, T vb);
std::size_t number_of_constraints() { return constraint_set.size();}
std::size_t number_of_subconstraints() {return sc_to_c_map.size();}
std::size_t number_of_enclosing_constraints(T va, T vb) const;
Context_iterator contexts_begin(T va, T vb) const;
Context_iterator contexts_end(T va, T vb) const;
std::size_t number_of_constraints() const { return constraint_set.size();}
std::size_t number_of_subconstraints()const {return sc_to_c_map.size();}
// insert/remove
@ -194,6 +204,18 @@ public:
void remove_Steiner(T v, T va, T vb);
// iterators
Subconstraint_iterator subconstraint_begin() const
{
First f;
return boost::make_transform_iterator(sc_to_c_map.begin(),f);
}
Subconstraint_iterator subconstraint_end() const
{
First f;
return boost::make_transform_iterator(sc_to_c_map.end(),f); }
Sc_iterator sc_begin() const{ return sc_to_c_map.begin(); }
Sc_iterator sc_end() const{ return sc_to_c_map.end(); }
C_iterator c_begin() const{ return constraint_set.begin(); }
@ -389,7 +411,7 @@ context(T va, T vb)
template <class T, class Data>
std::size_t
Polyline_constraint_hierarchy_2<T,Data>::
number_of_enclosing_constraints(T va, T vb)
number_of_enclosing_constraints(T va, T vb) const
{
Context_list* hcl;
if (! get_contexts(va,vb,hcl)) CGAL_triangulation_assertion(false);
@ -399,7 +421,7 @@ number_of_enclosing_constraints(T va, T vb)
template <class T, class Data>
typename Polyline_constraint_hierarchy_2<T,Data>::Context_iterator
Polyline_constraint_hierarchy_2<T,Data>::
contexts_begin(T va, T vb)
contexts_begin(T va, T vb) const
{
Context_iterator first, last;
if( !get_contexts(va,vb,first,last)) CGAL_triangulation_assertion(false);
@ -409,7 +431,7 @@ contexts_begin(T va, T vb)
template <class T, class Data>
typename Polyline_constraint_hierarchy_2<T,Data>::Context_iterator
Polyline_constraint_hierarchy_2<T,Data>::
contexts_end(T va, T vb)
contexts_end(T va, T vb) const
{
Context_iterator first, last;
if( !get_contexts(va,vb,first,last)) CGAL_triangulation_assertion(false);