Enhanced operator(). Made the type of the coordinate index iterator a template parameter

Patch exceptionally accepted in master on a file not used by CGAL.
Approved by the interim release manager.
This commit is contained in:
Efi Fogel 2014-09-27 22:31:40 +03:00 committed by Sébastien Loriot
parent aabd9dc557
commit 16151c46ff
1 changed files with 116 additions and 120 deletions

View File

@ -12,9 +12,6 @@
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// //
// $URL$
// $Id$
//
// Author(s): Efi Fogel <efif@post.tau.ac.il> // Author(s): Efi Fogel <efif@post.tau.ac.il>
// Naama mayer <naamamay@post.tau.ac.il> // Naama mayer <naamamay@post.tau.ac.il>
@ -73,9 +70,6 @@ private:
typedef typename Geometry_traits_2::Point_3 Point_3; typedef typename Geometry_traits_2::Point_3 Point_3;
typedef typename Geometry_traits_2::Vector_3 Vector_3; typedef typename Geometry_traits_2::Vector_3 Vector_3;
/*! */
typedef unsigned int* Coord_index_iter;
// Polyhedron types: // Polyhedron types:
typedef typename Polyhedron::Vertex_const_handle typedef typename Polyhedron::Vertex_const_handle
Polyhedron_vertex_const_handle; Polyhedron_vertex_const_handle;
@ -94,9 +88,13 @@ private:
typedef boost::is_same<typename Polyhedron::Plane_3, Vector_3> typedef boost::is_same<typename Polyhedron::Plane_3, Vector_3>
Polyhedron_has_normal; Polyhedron_has_normal;
typedef typename Polyhedron::HalfedgeDS HDS;
typedef Polyhedron_incremental_builder_3<HDS> Builder;
typedef typename Builder::size_type size_type;
/*! Transforms a (planar) facet into a normal */ /*! Transforms a (planar) facet into a normal */
struct Normal_equation { struct Normal_equation {
template <class Facet> template <typename Facet>
typename Facet::Plane_3 operator()(Facet& f) { typename Facet::Plane_3 operator()(Facet& f) {
typename Facet::Halfedge_handle h = f.halfedge(); typename Facet::Halfedge_handle h = f.halfedge();
return CGAL::cross_product(h->next()->vertex()->point() - return CGAL::cross_product(h->next()->vertex()->point() -
@ -130,7 +128,7 @@ private:
} }
/*! A point adder */ /*! A point adder */
template <class HDS, class PointIterator_3> template <typename HDS, typename PointIterator>
class Point_adder { class Point_adder {
private: private:
typedef Polyhedron_incremental_builder_3<HDS> Builder; typedef Polyhedron_incremental_builder_3<HDS> Builder;
@ -143,7 +141,7 @@ private:
/*! Constructor */ /*! Constructor */
Point_adder(Builder& B) : m_B(B) {} Point_adder(Builder& B) : m_B(B) {}
Polyhedron_vertex_handle operator()(PointIterator_3 pi) Polyhedron_vertex_handle operator()(PointIterator pi)
{ {
typedef typename HDS::Vertex Vertex; typedef typename HDS::Vertex Vertex;
typedef typename Vertex::Point Point; typedef typename Vertex::Point Point;
@ -152,7 +150,7 @@ private:
}; };
/*! Specialized point adder */ /*! Specialized point adder */
template <class HDS> class Point_adder<HDS, Point_3*> { template <typename HDS> class Point_adder<HDS, Point_3*> {
private: private:
typedef Polyhedron_incremental_builder_3<HDS> Builder; typedef Polyhedron_incremental_builder_3<HDS> Builder;
Builder& m_B; Builder& m_B;
@ -169,7 +167,7 @@ private:
}; };
/*! */ /*! */
template <class PointIterator_3> template <typename PointIterator, typename CoordIndexIter>
class Build_surface : public Modifier_base<typename Polyhedron::HalfedgeDS> class Build_surface : public Modifier_base<typename Polyhedron::HalfedgeDS>
{ {
private: private:
@ -180,22 +178,21 @@ private:
typedef typename Polyhedron::HalfedgeDS HDS; typedef typename Polyhedron::HalfedgeDS HDS;
typedef Polyhedron_incremental_builder_3<HDS> Builder; typedef Polyhedron_incremental_builder_3<HDS> Builder;
typedef typename Builder::size_type size_type; typedef typename Builder::size_type size_type;
typedef unsigned int* Coord_index_iter;
/*! The begin iterator of the points */ /*! The begin iterator of the points */
const PointIterator_3& m_points_begin; const PointIterator& m_points_begin;
/*! The end iterator of the points */ /*! The end iterator of the points */
const PointIterator_3& m_points_end; const PointIterator& m_points_end;
/*! The number of points */ /*! The number of points */
size_type m_num_points; size_type m_num_points;
/*! The begin iterator of the indices */ /*! The begin iterator of the indices */
const Coord_index_iter& m_indices_begin; const CoordIndexIter& m_indices_begin;
/*! The end iterator of the indices */ /*! The end iterator of the indices */
const Coord_index_iter& m_indices_end; const CoordIndexIter& m_indices_end;
/*! The number of facest */ /*! The number of facest */
size_type m_num_facets; size_type m_num_facets;
@ -204,21 +201,21 @@ private:
size_type m_num_vertices_per_facet; size_type m_num_vertices_per_facet;
/*! The index of the marked vertex */ /*! The index of the marked vertex */
unsigned int m_marked_vertex_index; size_type m_marked_vertex_index;
/*! The index of the marked edge */ /*! The index of the marked edge */
unsigned int m_marked_edge_index; size_type m_marked_edge_index;
/*! The index of the marked face */ /*! The index of the marked face */
unsigned int m_marked_facet_index; size_type m_marked_facet_index;
public: public:
/*! Constructor */ /*! Constructor */
Build_surface(const PointIterator_3& points_begin, Build_surface(const PointIterator& points_begin,
const PointIterator_3& points_end, const PointIterator& points_end,
unsigned int num_points, size_type num_points,
const Coord_index_iter& indices_begin, const CoordIndexIter& indices_begin,
const Coord_index_iter& indices_end, const CoordIndexIter& indices_end,
size_type num_facets, size_type num_facets,
size_type num_vertices_per_facet = 0) : size_type num_vertices_per_facet = 0) :
m_points_begin(points_begin), m_points_end(points_end), m_points_begin(points_begin), m_points_end(points_end),
@ -235,13 +232,13 @@ private:
virtual ~Build_surface() {} virtual ~Build_surface() {}
/*! Set the marked-vertex index */ /*! Set the marked-vertex index */
void set_marked_vertex_index(unsigned int id) {m_marked_vertex_index = id;} void set_marked_vertex_index(size_type id) {m_marked_vertex_index = id;}
/*! Set the marked-edge index */ /*! Set the marked-edge index */
void set_marked_edge_index(unsigned int id) {m_marked_edge_index = id;} void set_marked_edge_index(size_type id) {m_marked_edge_index = id;}
/*! Set the marked-face index */ /*! Set the marked-face index */
void set_marked_facet_index(unsigned int id) {m_marked_facet_index = id;} void set_marked_facet_index(size_type id) {m_marked_facet_index = id;}
/*! builds the polyhedron */ /*! builds the polyhedron */
void operator()(HDS& hds) void operator()(HDS& hds)
@ -250,9 +247,9 @@ private:
Builder B(hds, true); Builder B(hds, true);
B.begin_surface(m_num_points, m_num_facets); B.begin_surface(m_num_points, m_num_facets);
// Add the points: // Add the points:
unsigned int counter = 0; size_type counter = 0;
Point_adder<HDS, PointIterator_3> add(B); Point_adder<HDS, PointIterator> add(B);
for (PointIterator_3 pi = m_points_begin; pi != m_points_end; ++pi) { for (PointIterator pi = m_points_begin; pi != m_points_end; ++pi) {
Polyhedron_vertex_handle vh = add(pi); Polyhedron_vertex_handle vh = add(pi);
if (counter == m_marked_vertex_index) vh->set_marked(true); if (counter == m_marked_vertex_index) vh->set_marked(true);
++counter; ++counter;
@ -263,7 +260,7 @@ private:
switch (m_num_vertices_per_facet) { switch (m_num_vertices_per_facet) {
case 0: // '0' indicates variant number of vertices per facet case 0: // '0' indicates variant number of vertices per facet
{ {
Coord_index_iter ii = m_indices_begin; CoordIndexIter ii = m_indices_begin;
while (ii != m_indices_end) { while (ii != m_indices_end) {
Polyhedron_facet_handle fh = B.begin_facet(); Polyhedron_facet_handle fh = B.begin_facet();
if (counter == m_marked_facet_index) fh->set_marked(true); if (counter == m_marked_facet_index) fh->set_marked(true);
@ -280,7 +277,7 @@ private:
case 3: case 3:
// Unfold for to improve preformance: // Unfold for to improve preformance:
for (Coord_index_iter ii = m_indices_begin; ii != m_indices_end; for (CoordIndexIter ii = m_indices_begin; ii != m_indices_end;
ii += m_num_vertices_per_facet) ii += m_num_vertices_per_facet)
{ {
Polyhedron_facet_handle fh = B.begin_facet(); Polyhedron_facet_handle fh = B.begin_facet();
@ -294,7 +291,7 @@ private:
break; break;
default: default:
for (Coord_index_iter ii = m_indices_begin; ii != m_indices_end; for (CoordIndexIter ii = m_indices_begin; ii != m_indices_end;
ii += m_num_vertices_per_facet) ii += m_num_vertices_per_facet)
{ {
Polyhedron_facet_handle fh = B.begin_facet(); Polyhedron_facet_handle fh = B.begin_facet();
@ -314,13 +311,13 @@ private:
Visitor* m_visitor; Visitor* m_visitor;
/*! The index of the marked vertex */ /*! The index of the marked vertex */
unsigned int m_marked_vertex_index; size_type m_marked_vertex_index;
/*! The index of the marked edge */ /*! The index of the marked edge */
unsigned int m_marked_edge_index; size_type m_marked_edge_index;
/*! The index of the marked face */ /*! The index of the marked face */
unsigned int m_marked_facet_index; size_type m_marked_facet_index;
/*! */ /*! */
Polyhedron_vertex_const_handle m_src_vertex; Polyhedron_vertex_const_handle m_src_vertex;
@ -356,18 +353,18 @@ private:
} }
/*! Update the polyhedron */ /*! Update the polyhedron */
template <class PointIterator_3> template <typename PointIterator, typename CoordIndexIter>
void update_polyhedron(Polyhedron& polyhedron, void update_polyhedron(Polyhedron& polyhedron,
const PointIterator_3& points_begin, const PointIterator& points_begin,
const PointIterator_3& points_end, const PointIterator& points_end,
unsigned int num_points, size_type num_points,
const Coord_index_iter indices_begin, const CoordIndexIter indices_begin,
Coord_index_iter indices_end, const CoordIndexIter indices_end,
unsigned int num_facets, size_type num_facets,
unsigned int num_vertices_per_facet = 0) size_type num_vertices_per_facet = 0)
{ {
/*! The builder */ /*! The builder */
Build_surface<PointIterator_3> Build_surface<PointIterator, CoordIndexIter>
surface(points_begin, points_end, num_points, surface(points_begin, points_end, num_points,
indices_begin, indices_end, num_facets, num_vertices_per_facet); indices_begin, indices_end, num_facets, num_vertices_per_facet);
surface.set_marked_vertex_index(m_marked_vertex_index); surface.set_marked_vertex_index(m_marked_vertex_index);
@ -376,7 +373,7 @@ private:
polyhedron.delegate(surface); polyhedron.delegate(surface);
// Mark the marked (half) edges: // Mark the marked (half) edges:
unsigned int counter = 0; size_type counter = 0;
typedef typename Polyhedron::Edge_iterator Polyhedron_edge_iterator; typedef typename Polyhedron::Edge_iterator Polyhedron_edge_iterator;
Polyhedron_edge_iterator ei; Polyhedron_edge_iterator ei;
for (ei = polyhedron.edges_begin(); ei != polyhedron.edges_end(); ++ei) { for (ei = polyhedron.edges_begin(); ei != polyhedron.edges_end(); ++ei) {
@ -594,14 +591,14 @@ public:
} }
/*! Initialize the Spherical Gaussian map */ /*! Initialize the Spherical Gaussian map */
template <class PointIterator_3> template <typename PointIterator, typename CoordIndexIter>
void operator()(const PointIterator_3& points_begin, void operator()(const PointIterator& points_begin,
const PointIterator_3& points_end, const PointIterator& points_end,
unsigned int num_points, size_type num_points,
const Coord_index_iter indices_begin, const CoordIndexIter indices_begin,
Coord_index_iter indices_end, const CoordIndexIter indices_end,
unsigned int num_facets, size_type num_facets,
unsigned int num_vertices_per_facet = 0, size_type num_vertices_per_facet = 0,
Visitor* visitor = NULL) Visitor* visitor = NULL)
{ {
m_visitor = visitor; m_visitor = visitor;
@ -631,35 +628,37 @@ public:
} }
/*! Set the marked-vertex index */ /*! Set the marked-vertex index */
void set_marked_vertex_index(unsigned int id) {m_marked_vertex_index = id;} void set_marked_vertex_index(size_type id) {m_marked_vertex_index = id;}
/*! Set the marked-edge index */ /*! Set the marked-edge index */
void set_marked_edge_index(unsigned int id) {m_marked_edge_index = id;} void set_marked_edge_index(size_type id) {m_marked_edge_index = id;}
/*! Set the marked-face index */ /*! Set the marked-face index */
void set_marked_facet_index(unsigned int id) {m_marked_facet_index = id;} void set_marked_facet_index(size_type id) {m_marked_facet_index = id;}
}; };
/*! /*!
*/ */
template <class Geometry_traits_2, template <typename Geometry_traits_2,
template <class T> template <class T>
class T_Dcel = Arr_polyhedral_sgm_arr_dcel> class Dcel_T = Arr_polyhedral_sgm_arr_dcel>
class Arr_polyhedral_sgm : class Arr_polyhedral_sgm :
public Arr_spherical_gaussian_map_3<Geometry_traits_2, T_Dcel> public Arr_spherical_gaussian_map_3<Geometry_traits_2, Dcel_T>
{ {
private: private:
typedef Arr_polyhedral_sgm<Geometry_traits_2, T_Dcel> Self; typedef Arr_polyhedral_sgm<Geometry_traits_2, Dcel_T> Self;
public: public:
typedef typename Geometry_traits_2::Point_3 Point_3; typedef typename Geometry_traits_2::Point_3 Point_3;
typedef typename Geometry_traits_2::Vector_3 Vector_3; typedef typename Geometry_traits_2::Vector_3 Vector_3;
typedef T_Dcel<Geometry_traits_2> Dcel; typedef Dcel_T<Geometry_traits_2> Dcel;
typedef typename Dcel::Size size_type;
// For some reason MSVC barfs on the friend statement below. Therefore, // For some reason MSVC barfs on the friend statement below. Therefore,
// we declare the Base to be public to overcome the problem. // we declare the Base to be public to overcome the problem.
typedef Arr_spherical_gaussian_map_3<Geometry_traits_2, T_Dcel> Base; typedef Arr_spherical_gaussian_map_3<Geometry_traits_2, Dcel_T> Base;
// WE NEED TO ADD THE CGAL NAMESPACE TO PACIFY THE G++ 4.3.3 COMPILER. // WE NEED TO ADD THE CGAL NAMESPACE TO PACIFY THE G++ 4.3.3 COMPILER.
typedef CGAL::Arr_polyhedral_sgm_overlay<Self> typedef CGAL::Arr_polyhedral_sgm_overlay<Self>
@ -667,7 +666,7 @@ public:
#if 0 #if 0
/*! Allow the initializer to update the SGM data members */ /*! Allow the initializer to update the SGM data members */
template <class Polyhedron, class Visitor> template <typename Polyhedron, typename Visitor>
friend class Arr_polyhedral_sgm_initializer<Self, Polyhedron, Visitor>; friend class Arr_polyhedral_sgm_initializer<Self, Polyhedron, Visitor>;
#endif #endif
@ -701,10 +700,7 @@ public:
Arr_polyhedral_sgm() : m_dirty_center(true) {} Arr_polyhedral_sgm() : m_dirty_center(true) {}
/*! Copy Constructor */ /*! Copy Constructor */
Arr_polyhedral_sgm(const Self& sgm) Arr_polyhedral_sgm(const Self& sgm) { assign(sgm); }
{
assign(sgm);
}
/*! Assign a spherical Gaussian map to this */ /*! Assign a spherical Gaussian map to this */
void assign(const Self& sgm) void assign(const Self& sgm)
@ -719,7 +715,7 @@ public:
for (fit = this->_dcel().faces_begin(); fit != this->_dcel().faces_end(); for (fit = this->_dcel().faces_begin(); fit != this->_dcel().faces_end();
++fit) ++fit)
{ {
fit->set_point (fit1->point()); fit->set_point(fit1->point());
++fit1; ++fit1;
} }
@ -750,7 +746,7 @@ public:
// /*! Compute the minkowski sum of a range of objects of type // /*! Compute the minkowski sum of a range of objects of type
// * Arr_polyhedral_sgm // * Arr_polyhedral_sgm
// */ // */
// template <class SgmIterator> // template <typename SgmIterator>
// void minkowski_sum(SgmIterator begin, SgmIterator end) // void minkowski_sum(SgmIterator begin, SgmIterator end)
// { // {
//typename SgmIterator::value_type* sgm1 = *begin++; //typename SgmIterator::value_type* sgm1 = *begin++;
@ -774,7 +770,7 @@ public:
* \param sgm1 the first Arr_polyhedral_sgm object * \param sgm1 the first Arr_polyhedral_sgm object
* \param sgm2 the second Arr_polyhedral_sgm object * \param sgm2 the second Arr_polyhedral_sgm object
*/ */
template <class Arr_polyhedral_sgm> template <typename Arr_polyhedral_sgm>
void minkowski_sum(const Arr_polyhedral_sgm& sgm1, void minkowski_sum(const Arr_polyhedral_sgm& sgm1,
const Arr_polyhedral_sgm& sgm2) const Arr_polyhedral_sgm& sgm2)
{ {
@ -788,14 +784,14 @@ public:
* \param sgm1 the first Arr_polyhedral_sgm object * \param sgm1 the first Arr_polyhedral_sgm object
* \param sgm2 the second Arr_polyhedral_sgm object * \param sgm2 the second Arr_polyhedral_sgm object
*/ */
template <class Arr_polyhedral_sgm, typename OverlayTraits> template <typename Arr_polyhedral_sgm, typename OverlayTraits>
void minkowski_sum(const Arr_polyhedral_sgm& sgm1, void minkowski_sum(const Arr_polyhedral_sgm& sgm1,
const Arr_polyhedral_sgm& sgm2, const Arr_polyhedral_sgm& sgm2,
OverlayTraits& overlay_traits) OverlayTraits& overlay_traits)
{ CGAL::overlay(sgm1, sgm2, *this, overlay_traits); } { CGAL::overlay(sgm1, sgm2, *this, overlay_traits); }
/*! Obtain the number of (primal) vertices */ /*! Obtain the number of (primal) vertices */
unsigned int number_of_vertices() const size_type number_of_vertices() const
{ return (static_cast<const Base*>(this))->number_of_faces(); } { return (static_cast<const Base*>(this))->number_of_faces(); }
/*! Obtain the number of (primal) edges /*! Obtain the number of (primal) edges
@ -804,9 +800,9 @@ public:
* been introduced only to make non-x-monotone curves x-monotone. * been introduced only to make non-x-monotone curves x-monotone.
* *
*/ */
unsigned int number_of_edges() const size_type number_of_edges() const
{ {
unsigned int size = 0; size_type size = 0;
typename Base::Vertex_const_iterator vit; typename Base::Vertex_const_iterator vit;
for (vit = this->vertices_begin(); vit != this->vertices_end(); ++vit) for (vit = this->vertices_begin(); vit != this->vertices_end(); ++vit)
if (vit->degree() == 2) size++; if (vit->degree() == 2) size++;
@ -818,9 +814,9 @@ public:
* Vertices of degree 2 are not counted, as they have been introduced only * Vertices of degree 2 are not counted, as they have been introduced only
* to make non-x-monotone curves x-monotone. * to make non-x-monotone curves x-monotone.
*/ */
unsigned int number_of_facets() const size_type number_of_facets() const
{ {
unsigned int size = 0; size_type size = 0;
typename Base::Vertex_const_iterator vit; typename Base::Vertex_const_iterator vit;
for (vit = this->vertices_begin(); vit != this->vertices_end(); ++vit) for (vit = this->vertices_begin(); vit != this->vertices_end(); ++vit)
if (vit->degree() > 2) size++; if (vit->degree() > 2) size++;