This commit is contained in:
Efi Fogel 2013-08-25 01:26:53 +03:00
parent b99a327ab0
commit 40d1879c5e
8 changed files with 139 additions and 134 deletions

View File

@ -16,6 +16,7 @@
// $Id$ // $Id$
// //
// Author(s) : Ron Wein <wein@post.tau.ac.il> // Author(s) : Ron Wein <wein@post.tau.ac.il>
// Efi Fogel <efifogel@gmail.com>
#ifndef CGAL_POLYGON_DECOMPOSITION_STRATEGY_ADAPTER_H #ifndef CGAL_POLYGON_DECOMPOSITION_STRATEGY_ADAPTER_H
#define CGAL_POLYGON_DECOMPOSITION_STRATEGY_ADAPTER_H #define CGAL_POLYGON_DECOMPOSITION_STRATEGY_ADAPTER_H
@ -27,50 +28,73 @@
namespace CGAL { namespace CGAL {
struct Tag_optimal_convex_parition struct Tag_optimal_convex_parition { bool dummy; };
{
bool dummy;
};
struct Tag_approx_convex_parition struct Tag_approx_convex_parition { bool dummy; };
{
bool dummy;
};
struct Tag_Greene_convex_parition struct Tag_Greene_convex_parition { bool dummy; };
{
bool dummy;
};
/*! /*!
* \class * \class
* An adapter of the global planar polygonal partitioning functions * An adapter of the global planar polygonal partitioning functions
* to a decomposition strategy-class. * to a decomposition strategy-class.
*/ */
template <class Kernel_, class Container_, class StrategyTag_> template <typename Kernel_, typename Container_, typename StrategyTag_>
class Polygon_decomposition_strategy_adapter class Polygon_decomposition_strategy_adapter {
{
public: public:
typedef Kernel_ Kernel; typedef Kernel_ Kernel;
typedef CGAL::Polygon_2<Kernel, Container_> Polygon_2; typedef CGAL::Polygon_2<Kernel, Container_> Polygon_2;
typedef typename Kernel::Point_2 Point_2; typedef typename Kernel::Point_2 Point_2;
typedef StrategyTag_ Strategy_tag; typedef StrategyTag_ Strategy_tag;
protected: protected:
typedef Partition_traits_2<Kernel> Traits_2; typedef Partition_traits_2<Kernel> Traits_2;
typedef typename Traits_2::Polygon_2 Traits_polygon_2; typedef typename Traits_2::Polygon_2 Traits_polygon_2;
// Data members: // Data members:
Traits_2 traits; const Traits_2* m_traits;
bool m_own_traits; // inidicates whether the kernel should be freed up.
public: public:
/*! Default constructor. */ /*! Default constructor. */
Polygon_decomposition_strategy_adapter() : Polygon_decomposition_strategy_adapter() :
traits() m_traits(NULL),
{} m_own_traits(false)
{ init(); }
/*! Constructor. */
Polygon_decomposition_strategy_adapter(const Traits_2& traits) :
m_traits(traits),
m_own_traits(false)
{ init(); }
/*! Destructor */
~Polygon_decomposition_strategy_adapter()
{
if (m_own_traits) {
if (m_traits != NULL) {
delete m_traits;
m_traits = NULL;
}
m_own_traits = false;
}
}
//! Initialize
void init()
{
// Allocate the traits if not provided.
if (m_traits == NULL) {
m_traits = new Traits_2;
m_own_traits = true;
}
}
/*!
* Obtain the traits
* \return the traits
*/
const Traits_2* traits() const { return m_traits; }
/*! /*!
* Decompose a simple polygon to convex sub-polygons. * Decompose a simple polygon to convex sub-polygons.
@ -78,15 +102,13 @@ public:
* \param oi An output iterator of convex polygons. * \param oi An output iterator of convex polygons.
* \return A past-the-end iterator for the sub-polygons. * \return A past-the-end iterator for the sub-polygons.
*/ */
template <class OutputIterator> template <typename OutputIterator>
OutputIterator operator() (const Polygon_2& pgn, OutputIterator operator()(const Polygon_2& pgn, OutputIterator oi) const
OutputIterator oi) const
{ {
std::list<Traits_polygon_2> pgns; std::list<Traits_polygon_2> pgns;
typename std::list<Traits_polygon_2>::const_iterator pgn_it; typename std::list<Traits_polygon_2>::const_iterator pgn_it;
if (pgn.orientation() == CLOCKWISE) if (pgn.orientation() == CLOCKWISE) {
{
// Make a local copy of the polygon, and reverse the order of its // Make a local copy of the polygon, and reverse the order of its
// vertices to make it counterclockwise oriented. // vertices to make it counterclockwise oriented.
Polygon_2 my_pgn = pgn; Polygon_2 my_pgn = pgn;
@ -96,67 +118,59 @@ public:
// Perform the decomposition. // Perform the decomposition.
_decompose (my_pgn, Strategy_tag(), std::back_inserter(pgns)); _decompose (my_pgn, Strategy_tag(), std::back_inserter(pgns));
} }
else else {
{
// Perform the decomposition on the original polygon. // Perform the decomposition on the original polygon.
_decompose (pgn, Strategy_tag(), std::back_inserter(pgns)); _decompose (pgn, Strategy_tag(), std::back_inserter(pgns));
} }
// Copy the polygons to the output iterator. // Copy the polygons to the output iterator.
for (pgn_it = pgns.begin(); pgn_it != pgns.end(); ++pgn_it) for (pgn_it = pgns.begin(); pgn_it != pgns.end(); ++pgn_it)
{ *oi++ = Polygon_2(pgn_it->vertices_begin(), pgn_it->vertices_end());
*oi = Polygon_2 (pgn_it->vertices_begin(), pgn_it->vertices_end());
++oi;
}
return (oi); return (oi);
} }
private: private:
/*! /*!
* Decompose the given counter clockwise-oriented polygon using the optimal * Decompose the given counter clockwise-oriented polygon using the optimal
* convex-partition method. * convex-partition method.
*/ */
template <class OutputIterator> template <typename OutputIterator>
OutputIterator _decompose(const Polygon_2& pgn, OutputIterator _decompose(const Polygon_2& pgn,
Tag_optimal_convex_parition , Tag_optimal_convex_parition ,
OutputIterator oi) const OutputIterator oi) const
{ {
return (optimal_convex_partition_2(pgn.vertices_begin(), return (optimal_convex_partition_2(pgn.vertices_begin(),
pgn.vertices_end(), pgn.vertices_end(),
oi, oi, *m_traits));
traits));
} }
/*! /*!
* Decompose the given counter clockwise-oriented polygon using the * Decompose the given counter clockwise-oriented polygon using the
* approximated convex-partition method. * approximated convex-partition method.
*/ */
template <class OutputIterator> template <typename OutputIterator>
OutputIterator _decompose(const Polygon_2& pgn, OutputIterator _decompose(const Polygon_2& pgn,
Tag_approx_convex_parition , Tag_approx_convex_parition ,
OutputIterator oi) const OutputIterator oi) const
{ {
return (approx_convex_partition_2(pgn.vertices_begin(), return (approx_convex_partition_2(pgn.vertices_begin(),
pgn.vertices_end(), pgn.vertices_end(),
oi, oi, *m_traits));
traits));
} }
/*! /*!
* Decompose the given counter clockwise-oriented polygon using Greene's * Decompose the given counter clockwise-oriented polygon using Greene's
* approximated convex-partition method. * approximated convex-partition method.
*/ */
template <class OutputIterator> template <typename OutputIterator>
OutputIterator _decompose(const Polygon_2& pgn, OutputIterator _decompose(const Polygon_2& pgn,
Tag_Greene_convex_parition , Tag_Greene_convex_parition ,
OutputIterator oi) const OutputIterator oi) const
{ {
return (greene_approx_convex_partition_2(pgn.vertices_begin(), return (greene_approx_convex_partition_2(pgn.vertices_begin(),
pgn.vertices_end(), pgn.vertices_end(),
oi, oi, *m_traits));
traits));
} }
}; };

View File

@ -16,6 +16,7 @@
// $Id$ // $Id$
// //
// Author(s) : Ron Wein <wein@post.tau.ac.il> // Author(s) : Ron Wein <wein@post.tau.ac.il>
// Efi Fogel <efifogel@gmail.com>
#ifndef CGAL_MINKOWSKI_SUM_CONV_H #ifndef CGAL_MINKOWSKI_SUM_CONV_H
#define CGAL_MINKOWSKI_SUM_CONV_H #define CGAL_MINKOWSKI_SUM_CONV_H
@ -123,8 +124,8 @@ private:
public: public:
/*! Default constructor. */ /*! Default constructor. */
Minkowski_sum_by_convolution_2() : Minkowski_sum_by_convolution_2() :
m_kernel(new Kernel), m_kernel(NULL),
m_own_kernel(true) m_own_kernel(false)
{ init(); } { init(); }
/*! Constructor. */ /*! Constructor. */
@ -181,11 +182,10 @@ public:
* \pre Both input polygons are simple. * \pre Both input polygons are simple.
* \return A past-the-end iterator for the holes in the sum. * \return A past-the-end iterator for the holes in the sum.
*/ */
template <class OutputIterator> template <typename OutputIterator>
OutputIterator operator()(const Polygon_2& pgn1, OutputIterator operator()(const Polygon_2& pgn1, const Polygon_2& pgn2,
const Polygon_2& pgn2, Polygon_2& sum_bound, OutputIterator sum_holes)
Polygon_2& sum_bound, const
OutputIterator sum_holes) const
{ {
CGAL_precondition(pgn1.is_simple()); CGAL_precondition(pgn1.is_simple());
CGAL_precondition(pgn2.is_simple()); CGAL_precondition(pgn2.is_simple());

View File

@ -152,7 +152,7 @@ public:
} }
// Allocate the strategy if not provided. // Allocate the strategy if not provided.
if (m_decomposition_strategy == NULL) { if (m_decomposition_strategy == NULL) {
m_decomposition_strategy = new Decomposition_strategy(*m_traits); m_decomposition_strategy = new Decomposition_strategy;
m_own_strategy = true; m_own_strategy = true;
} }
// Obtain kernel functors. // Obtain kernel functors.

View File

@ -30,18 +30,16 @@ namespace CGAL {
* The O(n^4) optimal strategy for decomposing a polygon into convex * The O(n^4) optimal strategy for decomposing a polygon into convex
* sub-polygons. * sub-polygons.
*/ */
template <class Kernel_, template <typename Kernel_,
class Container_ = std::vector<typename Kernel_::Point_2> > typename Container_ = std::vector<typename Kernel_::Point_2> >
class Optimal_convex_decomposition_2 : class Optimal_convex_decomposition_2 :
public Polygon_decomposition_strategy_adapter<Kernel_, Container_, public Polygon_decomposition_strategy_adapter<Kernel_, Container_,
Tag_optimal_convex_parition> Tag_optimal_convex_parition>
{ {
public: public:
typedef Kernel_ Kernel; typedef Kernel_ Kernel;
typedef CGAL::Polygon_2<Kernel, Container_> Polygon_2; typedef CGAL::Polygon_2<Kernel, Container_> Polygon_2;
typedef typename Kernel::Point_2 Point_2; typedef typename Kernel::Point_2 Point_2;
}; };
/*! /*!
@ -49,18 +47,16 @@ public:
* Hertel and Mehlhorn's O(n) approximation strategy for decomposing a * Hertel and Mehlhorn's O(n) approximation strategy for decomposing a
* polygon into convex sub-polygons. * polygon into convex sub-polygons.
*/ */
template <class Kernel_, template <typename Kernel_,
class Container_ = std::vector<typename Kernel_::Point_2> > typename Container_ = std::vector<typename Kernel_::Point_2> >
class Hertel_Mehlhorn_convex_decomposition_2 : class Hertel_Mehlhorn_convex_decomposition_2 :
public Polygon_decomposition_strategy_adapter<Kernel_, Container_, public Polygon_decomposition_strategy_adapter<Kernel_, Container_,
Tag_approx_convex_parition> Tag_approx_convex_parition>
{ {
public: public:
typedef Kernel_ Kernel; typedef Kernel_ Kernel;
typedef CGAL::Polygon_2<Kernel, Container_> Polygon_2; typedef CGAL::Polygon_2<Kernel, Container_> Polygon_2;
typedef typename Kernel::Point_2 Point_2; typedef typename Kernel::Point_2 Point_2;
}; };
/*! /*!
@ -68,18 +64,16 @@ public:
* Greene's O(n log(n)) approximation strategy for decomposing a polygon into * Greene's O(n log(n)) approximation strategy for decomposing a polygon into
* convex sub-polygons. * convex sub-polygons.
*/ */
template <class Kernel_, template <typename Kernel_,
class Container_ = std::vector<typename Kernel_::Point_2> > typename Container_ = std::vector<typename Kernel_::Point_2> >
class Greene_convex_decomposition_2 : class Greene_convex_decomposition_2 :
public Polygon_decomposition_strategy_adapter<Kernel_, Container_, public Polygon_decomposition_strategy_adapter<Kernel_, Container_,
Tag_Greene_convex_parition> Tag_Greene_convex_parition>
{ {
public: public:
typedef Kernel_ Kernel; typedef Kernel_ Kernel;
typedef CGAL::Polygon_2<Kernel, Container_> Polygon_2; typedef CGAL::Polygon_2<Kernel, Container_> Polygon_2;
typedef typename Kernel::Point_2 Point_2; typedef typename Kernel::Point_2 Point_2;
}; };
} //namespace CGAL } //namespace CGAL

View File

@ -15,8 +15,7 @@
// $URL$ // $URL$
// $Id$ // $Id$
// //
// Author(s) : Ron Wein <wein@post.tau.ac.il> // Author(s) : Efi Fogel <efifogel@gmail.com>
// (based on an old version by Eyal Flato)
#ifndef CGAL_SMALL_SIDE_ANGLE_BISECTOR_DECOMPOSITION_2_H #ifndef CGAL_SMALL_SIDE_ANGLE_BISECTOR_DECOMPOSITION_2_H
#define CGAL_SMALL_SIDE_ANGLE_BISECTOR_DECOMPOSITION_2_H #define CGAL_SMALL_SIDE_ANGLE_BISECTOR_DECOMPOSITION_2_H

View File

@ -17,6 +17,7 @@
// //
// Author(s) : Ron Wein <wein@post.tau.ac.il> // Author(s) : Ron Wein <wein@post.tau.ac.il>
// (based on an old version by Eyal Flato) // (based on an old version by Eyal Flato)
// Efi Fogel <efifogel@gmail.com>
#ifndef CGAL_SMALL_SIDE_ANGLE_BISECTOR_DECOMPOSITION_2_H #ifndef CGAL_SMALL_SIDE_ANGLE_BISECTOR_DECOMPOSITION_2_H
#define CGAL_SMALL_SIDE_ANGLE_BISECTOR_DECOMPOSITION_2_H #define CGAL_SMALL_SIDE_ANGLE_BISECTOR_DECOMPOSITION_2_H
@ -31,8 +32,8 @@ namespace CGAL {
* \class * \class
* Small-side angle-bisector decomposition strategy. * Small-side angle-bisector decomposition strategy.
*/ */
template <class Kernel_, template <typename Kernel_,
class Container_ = std::vector<typename Kernel_::Point_2> > typename Container_ = std::vector<typename Kernel_::Point_2> >
class Small_side_angle_bisector_decomposition_2 { class Small_side_angle_bisector_decomposition_2 {
public: public:
typedef Kernel_ Kernel; typedef Kernel_ Kernel;
@ -152,7 +153,7 @@ public:
* \param oi An output iterator of convex polygons. * \param oi An output iterator of convex polygons.
* \return A past-the-end iterator for the sub-polygons. * \return A past-the-end iterator for the sub-polygons.
*/ */
template <class OutputIterator> template <typename OutputIterator>
OutputIterator operator()(const Polygon_2& pgn, OutputIterator oi) const OutputIterator operator()(const Polygon_2& pgn, OutputIterator oi) const
{ {
// Construct a point-info vector that represents the input polygon. // Construct a point-info vector that represents the input polygon.
@ -763,21 +764,20 @@ private:
const double succ_y = CGAL::to_double(succ_pt.y()); const double succ_y = CGAL::to_double(succ_pt.y());
// Compute the edge length and the diagonal length. // Compute the edge length and the diagonal length.
const double len_uv = ::sqrt((ux - vx) * (ux - vx) + const double len_uv =
(uy - vy) * (uy - vy)); ::sqrt((ux - vx) * (ux - vx) + (uy - vy) * (uy - vy));
const double len_pred = ::sqrt((pred_x - vx) * (pred_x - vx) + const double len_pred =
(pred_y - vy) * (pred_y - vy)); ::sqrt((pred_x - vx) * (pred_x - vx) + (pred_y - vy) * (pred_y - vy));
const double len_succ = ::sqrt((succ_x - vx) * (succ_x - vx) + const double len_succ =
(succ_y - vy) * (succ_y - vy)); ::sqrt((succ_x - vx) * (succ_x - vx) + (succ_y - vy) * (succ_y - vy));
// Compute the angle a1 = <) (pred_pt, v_pt, u_pt): // Compute the angle a1 = <) (pred_pt, v_pt, u_pt):
const double cos_a1 = ((ux - vx) * (pred_x - vx) + const double cos_a1 = ((ux - vx) * (pred_x - vx) +
(uy - vy) * (pred_y - vy)) / (len_uv * len_pred); (uy - vy) * (pred_y - vy)) / (len_uv * len_pred);
double a1 = ::acos(cos_a1); double a1 = ::acos(cos_a1);
if (f_orientation(pred_pt, v_pt, u_pt) == RIGHT_TURN)
// The angle a1 is larger than 180 degree: // The angle a1 is larger than 180 degree:
a1 = _2_PI - a1; if (f_orientation(pred_pt, v_pt, u_pt) == RIGHT_TURN) a1 = _2_PI - a1;
// Compute the angle a2 = <) (u_pt, v_pt, succ_pt): // Compute the angle a2 = <) (u_pt, v_pt, succ_pt):
const double cos_a2 = ((ux - vx) * (succ_x - vx) + const double cos_a2 = ((ux - vx) * (succ_x - vx) +
@ -855,17 +855,14 @@ private:
* \param oi The output iterator. * \param oi The output iterator.
* \return A past-the-end iterator for the sub-polygons. * \return A past-the-end iterator for the sub-polygons.
*/ */
template <class OutputIterator> template <typename OutputIterator>
OutputIterator _output_polygon(const Point_vector_2& vec, OutputIterator _output_polygon(const Point_vector_2& vec,
OutputIterator oi) const OutputIterator oi) const
{ {
const unsigned int n = static_cast<int>(vec.size()); const unsigned int n = static_cast<int>(vec.size());
Polygon_2 pgn; Polygon_2 pgn;
unsigned int k; for (unsigned int k = 0; k < n; ++k) pgn.push_back(vec[k].point);
*oi++ = pgn;
for (k = 0; k < n; ++k) pgn.push_back(vec[k].point);
*oi = pgn;
++oi;
return (oi); return (oi);
} }
}; };

View File

@ -16,6 +16,7 @@
// $Id$ // $Id$
// //
// Author(s) : Ron Wein <wein@post.tau.ac.il> // Author(s) : Ron Wein <wein@post.tau.ac.il>
// Efi Fogel <efifogel@gmail.com>
#ifndef CGAL_MINKOWSKI_SUM_2_H #ifndef CGAL_MINKOWSKI_SUM_2_H
#define CGAL_MINKOWSKI_SUM_2_H #define CGAL_MINKOWSKI_SUM_2_H