From ee0dfa30ab4d806dc92be101ffe2f5f722b44d54 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Mon, 18 Feb 2013 16:46:42 +0100 Subject: [PATCH] Updated compact cell + bugfix when CGAL_LINKED_WITH_TBB is not defined --- .../include/CGAL/Compact_mesh_cell_base_3.h | 141 ++++++++++++------ Mesh_3/include/CGAL/Mesh_triangulation_3.h | 19 ++- .../include/CGAL/Profile_counter.h | 5 + 3 files changed, 109 insertions(+), 56 deletions(-) diff --git a/Mesh_3/include/CGAL/Compact_mesh_cell_base_3.h b/Mesh_3/include/CGAL/Compact_mesh_cell_base_3.h index 483eabf8538..dbd9f00b216 100644 --- a/Mesh_3/include/CGAL/Compact_mesh_cell_base_3.h +++ b/Mesh_3/include/CGAL/Compact_mesh_cell_base_3.h @@ -32,41 +32,29 @@ #include namespace CGAL { - -// Class Mesh_cell_base_3_base -// Base for Compact_mesh_cell_base_3, with specialization for Parallel_tag -// Sequential +// Class Mesh_cell_base_3_base +// Base for Compact_mesh_cell_base_3, with specializations +// for different walues of Parallel_tag and Use_erase_counter +template +class Compact_mesh_cell_base_3_base; + +// Class Mesh_cell_base_3_base +// Specialization for sequential - no erase counter template -class Compact_mesh_cell_base_3_base +class Compact_mesh_cell_base_3_base { -protected: + protected: Compact_mesh_cell_base_3_base() : bits_(0) {} -#if defined(CGAL_MESH_3_USE_LAZY_SORTED_REFINEMENT_QUEUE)\ - || defined(CGAL_MESH_3_USE_LAZY_UNSORTED_REFINEMENT_QUEUE) -public: - // Erase counter (cf. Compact_container) - unsigned int get_erase_counter() const - { - return this->m_erase_counter; - } - void set_erase_counter(unsigned int c) - { - this->m_erase_counter = c; - } - void increment_erase_counter() - { - ++this->m_erase_counter; - } - -protected: - typedef unsigned int Erase_counter_type; - Erase_counter_type m_erase_counter; -#endif - public: + // Erase counter (cf. Compact_container) + // Dummy functions + unsigned int get_erase_counter() const { return 0; } + void set_erase_counter(unsigned int c) {} + void increment_erase_counter() {} + /// Marks \c facet as visited void set_facet_visited (const int facet) { @@ -92,10 +80,67 @@ private: char bits_; }; + + +// Class Mesh_cell_base_3_base +// Specialization for sequential - WITH erase counter +template +class Compact_mesh_cell_base_3_base +{ +protected: + Compact_mesh_cell_base_3_base() + : bits_(0) {} + +public: + // Erase counter (cf. Compact_container) + unsigned int get_erase_counter() const + { + return this->m_erase_counter; + } + void set_erase_counter(unsigned int c) + { + this->m_erase_counter = c; + } + void increment_erase_counter() + { + ++this->m_erase_counter; + } + + /// Marks \c facet as visited + void set_facet_visited (const int facet) + { + CGAL_precondition(facet>=0 && facet <4); + bits_ |= (1 << facet); + } + + /// Marks \c facet as not visited + void reset_visited (const int facet) + { + CGAL_precondition(facet>=0 && facet<4); + bits_ &= (15 & ~(1 << facet)); + } + + /// Returns \c true if \c facet is marked as visited + bool is_facet_visited (const int facet) const + { + CGAL_precondition(facet>=0 && facet<4); + return ( (bits_ & (1 << facet)) != 0 ); + } + +private: + typedef unsigned int Erase_counter_type; + Erase_counter_type m_erase_counter; + /// Stores visited facets (4 first bits) + char bits_; +}; + + + #ifdef CGAL_LINKED_WITH_TBB -// Specialized version (Parallel) +// Class Mesh_cell_base_3_base +// Specialization for parallel - WITH erase counter template <> -class Compact_mesh_cell_base_3_base +class Compact_mesh_cell_base_3_base { protected: Compact_mesh_cell_base_3_base() @@ -146,28 +191,28 @@ public: CGAL_precondition(facet>=0 && facet<4); return ( (bits_ & (1 << facet)) != 0 ); } - -protected: - typedef tbb::atomic Erase_counter_type; - - Erase_counter_type m_erase_counter; - + private: + typedef tbb::atomic Erase_counter_type; + Erase_counter_type m_erase_counter; /// Stores visited facets (4 first bits) tbb::atomic bits_; }; + #endif // CGAL_LINKED_WITH_TBB + // Class Mesh_cell_base_3 // Cell base class used in 3D meshing process. // Adds information to Cb about the cell of the input complex containing it template< class GT, class MD, - typename Concurrency_tag = Sequential_tag, class TDS = void > class Compact_mesh_cell_base_3 - : public Compact_mesh_cell_base_3_base + : public Compact_mesh_cell_base_3_base< + TDS::Cell_container_strategy::Uses_erase_counter, + typename TDS::Concurrency_tag> { typedef typename GT::FT FT; @@ -182,7 +227,7 @@ public: template struct Rebind_TDS { - typedef Compact_mesh_cell_base_3 Other; + typedef Compact_mesh_cell_base_3 Other; }; @@ -598,12 +643,12 @@ private: -template < class GT, class MT, class CT, class Cb > +template < class GT, class MT, class Cb > std::istream& operator>>(std::istream &is, - Compact_mesh_cell_base_3 &c) + Compact_mesh_cell_base_3 &c) { - typename Compact_mesh_cell_base_3::Subdomain_index index; + typename Compact_mesh_cell_base_3::Subdomain_index index; if(is_ascii(is)) is >> index; else @@ -612,7 +657,7 @@ operator>>(std::istream &is, c.set_subdomain_index(index); for(int i = 0; i < 4; ++i) { - typename Compact_mesh_cell_base_3::Surface_patch_index i2; + typename Compact_mesh_cell_base_3::Surface_patch_index i2; if(is_ascii(is)) is >> i2; else @@ -625,10 +670,10 @@ operator>>(std::istream &is, return is; } -template < class GT, class MT, class CT, class Cb > +template < class GT, class MT, class Cb > std::ostream& operator<<(std::ostream &os, - const Compact_mesh_cell_base_3 &c) + const Compact_mesh_cell_base_3 &c) { if(is_ascii(os)) os << c.subdomain_index(); @@ -646,15 +691,15 @@ operator<<(std::ostream &os, // Specialization for void. -template -class Compact_mesh_cell_base_3 +template +class Compact_mesh_cell_base_3 { public: typedef internal::Dummy_tds_3 Triangulation_data_structure; typedef Triangulation_data_structure::Vertex_handle Vertex_handle; typedef Triangulation_data_structure::Cell_handle Cell_handle; template - struct Rebind_TDS { typedef Compact_mesh_cell_base_3 Other; }; + struct Rebind_TDS { typedef Compact_mesh_cell_base_3 Other; }; }; } // end namespace CGAL diff --git a/Mesh_3/include/CGAL/Mesh_triangulation_3.h b/Mesh_3/include/CGAL/Mesh_triangulation_3.h index 71250799e7e..3ffe1a46761 100644 --- a/Mesh_3/include/CGAL/Mesh_triangulation_3.h +++ b/Mesh_3/include/CGAL/Mesh_triangulation_3.h @@ -32,8 +32,6 @@ #include #include -#include - #ifdef CGAL_COMPACT_MESH_VERTEX_CELL #include #include @@ -102,7 +100,7 @@ private: # ifdef CGAL_COMPACT_MESH_VERTEX_CELL typedef Compact_mesh_vertex_base_3 Vertex_base; - typedef Compact_mesh_cell_base_3 Cell_base; + typedef Compact_mesh_cell_base_3 Cell_base; # else // NOT CGAL_COMPACT_MESH_VERTEX_CELL typedef Mesh_vertex_base_3 Vertex_base; typedef Mesh_cell_base_3 Cell_base; @@ -113,10 +111,7 @@ private: Compact_container_strategy_with_counter, Compact_container_strategy_with_counter, Parallel_tag> Tds; - typedef Regular_triangulation_3< - Geom_traits, Tds, - Spatial_grid_lock_data_structure_3< - Tag_priority_blocking_with_atomics> > Triangulation; + typedef Regular_triangulation_3 Triangulation; #else // !CGAL_LINKED_WITH_TBB @@ -128,9 +123,17 @@ private: typedef Mesh_cell_base_3 Cell_base; # endif // NOT CGAL_COMPACT_MESH_VERTEX_CELL +# if defined(CGAL_MESH_3_USE_LAZY_SORTED_REFINEMENT_QUEUE)\ + || defined(CGAL_MESH_3_USE_LAZY_UNSORTED_REFINEMENT_QUEUE) typedef Triangulation_data_structure_3< - Vertex_base, Cell_base> Tds; + Vertex_base, Cell_base, + Compact_container_strategy_with_counter, + Compact_container_strategy_with_counter> Tds; +# else + typedef Triangulation_data_structure_3 Tds; +# endif typedef Regular_triangulation_3 Triangulation; + #endif // CGAL_LINKED_WITH_TBB public: diff --git a/Profiling_tools/include/CGAL/Profile_counter.h b/Profiling_tools/include/CGAL/Profile_counter.h index 8ad36944f47..69c9a417475 100644 --- a/Profiling_tools/include/CGAL/Profile_counter.h +++ b/Profiling_tools/include/CGAL/Profile_counter.h @@ -61,6 +61,11 @@ # ifndef CGAL_CONCURRENT_PROFILE # define CGAL_CONCURRENT_PROFILE # endif +#else +// Automatically UNdefine CGAL_CONCURRENT_PROFILE if we're NOT linked with TBB +# ifdef CGAL_CONCURRENT_PROFILE +# undef CGAL_CONCURRENT_PROFILE +# endif #endif #ifdef CGAL_CONCURRENT_PROFILE