diff --git a/vcg/complex/algorithms/clustering.h b/vcg/complex/algorithms/clustering.h index 07eff45e..836ee8c0 100644 --- a/vcg/complex/algorithms/clustering.h +++ b/vcg/complex/algorithms/clustering.h @@ -33,55 +33,26 @@ #include #include #include +#include +#include -// some stuff for portable hashes... -#ifdef WIN32 - #ifndef __MINGW32__ - #include - #include - #define STDEXT stdext - #else - #include - #include - #define STDEXT __gnu_cxx - #endif -#else - #include - #include - #define STDEXT __gnu_cxx -#endif - +namespace std +{ + template<> + struct hash + { + typedef vcg::Point3i argument_type; + std::size_t operator()(const vcg::Point3i & s) const + { + return std::hash()(s[0]) ^ std::hash()(s[1]) ^ std::hash()(s[2]); + } + }; +} namespace vcg{ namespace tri{ -#define HASH_P0 73856093 -#define HASH_P1 19349663 -#define HASH_P2 83492791 -class HashedPoint3i : public Point3i -{ -public: - - size_t Hash() const - { - return (V(0)*HASH_P0 ^ V(1)*HASH_P1 ^ V(2)*HASH_P2); - } - - operator size_t () const - {return Hash();} -}; - -// needed for gcc compilation -#ifndef _MSC_VER -}} namespace STDEXT { - template <> struct hash{ - inline size_t operator ()(const vcg::tri::HashedPoint3i &p) const {return size_t(p);} -}; -} namespace vcg{ namespace tri{ -#endif - -// template class NearestToCenter { @@ -220,14 +191,20 @@ class Clustering if(v[0] > v[2] ) std::swap(v[0],v[2]); // now v0 is the minimum if(v[1] > v[2] ) std::swap(v[1],v[2]); // sorted! } - // Hashing Function; - operator size_t () const + bool operator ==(const SimpleTri &pt) const { - return (ii(0)*HASH_P0 ^ ii(1)*HASH_P1 ^ ii(2)*HASH_P2); + return (pt.v[0] == v[0]) + && (pt.v[1] == v[1]) + && (pt.v[2] == v[2]); + } + // Hashing Function; + size_t operator () (const SimpleTri &pt) const + { + // return (ii(0)*HASH_P0 ^ ii(1)*HASH_P1 ^ ii(2)*HASH_P2); + return std::hash()(pt.v[0]) ^ std::hash()(pt.v[1]) ^ std::hash()(pt.v[2]); } }; - // The init function Take two parameters // _size is the approximate total number of cells composing the grid surrounding the objects (usually a large number) // eg _size==1.000.000 means a 100x100x100 grid @@ -263,28 +240,18 @@ class Clustering BasicGrid Grid; -#ifdef _MSC_VER - STDEXT::hash_set TriSet; - typedef typename STDEXT::hash_set::iterator TriHashSetIterator; -#else - struct SimpleTriHashFunc{ - inline size_t operator ()(const SimpleTri &p) const {return size_t(p);} - }; - STDEXT::hash_set TriSet; - typedef typename STDEXT::hash_set::iterator TriHashSetIterator; -#endif - - STDEXT::hash_map GridCell; + std::unordered_set TriSet; + typedef typename std::unordered_set::iterator TriHashSetIterator; + std::unordered_map GridCell; void AddPointSet(MeshType &m, bool UseOnlySelected=false) { - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) + for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) if(!(*vi).IsD()) if(!UseOnlySelected || (*vi).IsS()) { - HashedPoint3i pi; + Point3i pi; Grid.PToIP((*vi).cP(), pi ); GridCell[pi].AddVertex(m,Grid,pi,*(vi)); } @@ -295,7 +262,7 @@ class Clustering FaceIterator fi; for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD()) { - HashedPoint3i pi; + Point3i pi; SimpleTri st; for(int i=0;i<3;++i) { @@ -317,7 +284,7 @@ class Clustering void SelectPointSet(MeshType &m) { - typename STDEXT::hash_map::iterator gi; + typename std::unordered_map::iterator gi; UpdateSelection::VertexClear(m); for(gi=GridCell.begin();gi!=GridCell.end();++gi) { @@ -333,7 +300,7 @@ class Clustering if (GridCell.empty()) return; Allocator::AddVertices(m,GridCell.size()); - typename STDEXT::hash_map::iterator gi; + typename std::unordered_map::iterator gi; int i=0; for(gi=GridCell.begin();gi!=GridCell.end();++gi) { @@ -353,7 +320,7 @@ class Clustering if (GridCell.empty()) return; Allocator::AddVertices(m,GridCell.size()); - typename STDEXT::hash_map::iterator gi; + typename std::unordered_map::iterator gi; int i=0; for(gi=GridCell.begin();gi!=GridCell.end();++gi) { diff --git a/vcg/space/index/spatial_hashing.h b/vcg/space/index/spatial_hashing.h index ea77b81e..7e4af1e5 100644 --- a/vcg/space/index/spatial_hashing.h +++ b/vcg/space/index/spatial_hashing.h @@ -26,29 +26,10 @@ #include #include +#include //#include #include #include -#ifdef _WIN32 - #ifndef __MINGW32__ - #include - #define STDEXT stdext - #else - #include - #define STDEXT __gnu_cxx - #endif -#else // We are in the *nix gcc branch -#if (__GNUC__ ==4) && (__GNUC_MINOR__ > 3) && (defined(__DEPRECATED)) - #undef __DEPRECATED // since gcc 4.4 was deprecated and generate warnings. Relax Deprecation Just for this... - #define ___WE_UNDEFINED_DEPRECATED__ -#endif - #include - #define STDEXT __gnu_cxx -#if defined(___WE_UNDEFINED_DEPRECATED__) -#define __DEPRECATED -#endif -#endif - namespace vcg{ @@ -101,7 +82,7 @@ namespace vcg{ // the hash index directly the grid structure. // We use a MultiMap because we need to store many object (faces) inside each cell of the grid. - typedef typename STDEXT::hash_multimap HashType; + typedef typename std::unordered_multimap HashType; typedef typename HashType::iterator HashIterator; HashType hash_table; // The real HASH TABLE **************************************