removed old style usage of hash map and substituted with c+11 sytle unordered set and map.
This commit is contained in:
parent
36380231e5
commit
ad95129d02
|
@ -33,55 +33,26 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
// some stuff for portable hashes...
|
namespace std
|
||||||
#ifdef WIN32
|
{
|
||||||
#ifndef __MINGW32__
|
template<>
|
||||||
#include <hash_map>
|
struct hash<vcg::Point3i>
|
||||||
#include <hash_set>
|
{
|
||||||
#define STDEXT stdext
|
typedef vcg::Point3i argument_type;
|
||||||
#else
|
|
||||||
#include <ext/hash_map>
|
|
||||||
#include <ext/hash_set>
|
|
||||||
#define STDEXT __gnu_cxx
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#include <ext/hash_map>
|
|
||||||
#include <ext/hash_set>
|
|
||||||
#define STDEXT __gnu_cxx
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
std::size_t operator()(const vcg::Point3i & s) const
|
||||||
|
{
|
||||||
|
return std::hash<int>()(s[0]) ^ std::hash<int>()(s[1]) ^ std::hash<int>()(s[2]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
namespace vcg{
|
namespace vcg{
|
||||||
namespace tri{
|
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<vcg::tri::HashedPoint3i>{
|
|
||||||
inline size_t operator ()(const vcg::tri::HashedPoint3i &p) const {return size_t(p);}
|
|
||||||
};
|
|
||||||
} namespace vcg{ namespace tri{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//
|
|
||||||
template<class MeshType >
|
template<class MeshType >
|
||||||
class NearestToCenter
|
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[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!
|
if(v[1] > v[2] ) std::swap(v[1],v[2]); // sorted!
|
||||||
}
|
}
|
||||||
// Hashing Function;
|
bool operator ==(const SimpleTri &pt) const
|
||||||
operator size_t () 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<CellType*>()(pt.v[0]) ^ std::hash<CellType*>()(pt.v[1]) ^ std::hash<CellType*>()(pt.v[2]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// The init function Take two parameters
|
// The init function Take two parameters
|
||||||
// _size is the approximate total number of cells composing the grid surrounding the objects (usually a large number)
|
// _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
|
// eg _size==1.000.000 means a 100x100x100 grid
|
||||||
|
@ -263,28 +240,18 @@ class Clustering
|
||||||
|
|
||||||
BasicGrid<ScalarType> Grid;
|
BasicGrid<ScalarType> Grid;
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
std::unordered_set<SimpleTri,SimpleTri> TriSet;
|
||||||
STDEXT::hash_set<SimpleTri> TriSet;
|
typedef typename std::unordered_set<SimpleTri,SimpleTri>::iterator TriHashSetIterator;
|
||||||
typedef typename STDEXT::hash_set<SimpleTri>::iterator TriHashSetIterator;
|
std::unordered_map<Point3i,CellType> GridCell;
|
||||||
#else
|
|
||||||
struct SimpleTriHashFunc{
|
|
||||||
inline size_t operator ()(const SimpleTri &p) const {return size_t(p);}
|
|
||||||
};
|
|
||||||
STDEXT::hash_set<SimpleTri,SimpleTriHashFunc> TriSet;
|
|
||||||
typedef typename STDEXT::hash_set<SimpleTri,SimpleTriHashFunc>::iterator TriHashSetIterator;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
STDEXT::hash_map<HashedPoint3i,CellType> GridCell;
|
|
||||||
|
|
||||||
|
|
||||||
void AddPointSet(MeshType &m, bool UseOnlySelected=false)
|
void AddPointSet(MeshType &m, bool UseOnlySelected=false)
|
||||||
{
|
{
|
||||||
VertexIterator vi;
|
for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
|
||||||
if(!(*vi).IsD())
|
if(!(*vi).IsD())
|
||||||
if(!UseOnlySelected || (*vi).IsS())
|
if(!UseOnlySelected || (*vi).IsS())
|
||||||
{
|
{
|
||||||
HashedPoint3i pi;
|
Point3i pi;
|
||||||
Grid.PToIP((*vi).cP(), pi );
|
Grid.PToIP((*vi).cP(), pi );
|
||||||
GridCell[pi].AddVertex(m,Grid,pi,*(vi));
|
GridCell[pi].AddVertex(m,Grid,pi,*(vi));
|
||||||
}
|
}
|
||||||
|
@ -295,7 +262,7 @@ class Clustering
|
||||||
FaceIterator fi;
|
FaceIterator fi;
|
||||||
for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD())
|
for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD())
|
||||||
{
|
{
|
||||||
HashedPoint3i pi;
|
Point3i pi;
|
||||||
SimpleTri st;
|
SimpleTri st;
|
||||||
for(int i=0;i<3;++i)
|
for(int i=0;i<3;++i)
|
||||||
{
|
{
|
||||||
|
@ -317,7 +284,7 @@ class Clustering
|
||||||
|
|
||||||
void SelectPointSet(MeshType &m)
|
void SelectPointSet(MeshType &m)
|
||||||
{
|
{
|
||||||
typename STDEXT::hash_map<HashedPoint3i,CellType>::iterator gi;
|
typename std::unordered_map<Point3i,CellType>::iterator gi;
|
||||||
UpdateSelection<MeshType>::VertexClear(m);
|
UpdateSelection<MeshType>::VertexClear(m);
|
||||||
for(gi=GridCell.begin();gi!=GridCell.end();++gi)
|
for(gi=GridCell.begin();gi!=GridCell.end();++gi)
|
||||||
{
|
{
|
||||||
|
@ -333,7 +300,7 @@ class Clustering
|
||||||
if (GridCell.empty()) return;
|
if (GridCell.empty()) return;
|
||||||
|
|
||||||
Allocator<MeshType>::AddVertices(m,GridCell.size());
|
Allocator<MeshType>::AddVertices(m,GridCell.size());
|
||||||
typename STDEXT::hash_map<HashedPoint3i,CellType>::iterator gi;
|
typename std::unordered_map<Point3i,CellType>::iterator gi;
|
||||||
int i=0;
|
int i=0;
|
||||||
for(gi=GridCell.begin();gi!=GridCell.end();++gi)
|
for(gi=GridCell.begin();gi!=GridCell.end();++gi)
|
||||||
{
|
{
|
||||||
|
@ -353,7 +320,7 @@ class Clustering
|
||||||
if (GridCell.empty()) return;
|
if (GridCell.empty()) return;
|
||||||
|
|
||||||
Allocator<MeshType>::AddVertices(m,GridCell.size());
|
Allocator<MeshType>::AddVertices(m,GridCell.size());
|
||||||
typename STDEXT::hash_map<HashedPoint3i,CellType>::iterator gi;
|
typename std::unordered_map<Point3i,CellType>::iterator gi;
|
||||||
int i=0;
|
int i=0;
|
||||||
for(gi=GridCell.begin();gi!=GridCell.end();++gi)
|
for(gi=GridCell.begin();gi!=GridCell.end();++gi)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,29 +26,10 @@
|
||||||
|
|
||||||
#include <vcg/space/index/grid_util.h>
|
#include <vcg/space/index/grid_util.h>
|
||||||
#include <vcg/space/index/grid_closest.h>
|
#include <vcg/space/index/grid_closest.h>
|
||||||
|
#include<unordered_map>
|
||||||
//#include <map>
|
//#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#ifdef _WIN32
|
|
||||||
#ifndef __MINGW32__
|
|
||||||
#include <hash_map>
|
|
||||||
#define STDEXT stdext
|
|
||||||
#else
|
|
||||||
#include <ext/hash_map>
|
|
||||||
#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 <ext/hash_map> was deprecated and generate warnings. Relax Deprecation Just for this...
|
|
||||||
#define ___WE_UNDEFINED_DEPRECATED__
|
|
||||||
#endif
|
|
||||||
#include <ext/hash_map>
|
|
||||||
#define STDEXT __gnu_cxx
|
|
||||||
#if defined(___WE_UNDEFINED_DEPRECATED__)
|
|
||||||
#define __DEPRECATED
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
namespace vcg{
|
namespace vcg{
|
||||||
|
|
||||||
|
@ -101,7 +82,7 @@ namespace vcg{
|
||||||
// the hash index directly the grid structure.
|
// 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.
|
// We use a MultiMap because we need to store many object (faces) inside each cell of the grid.
|
||||||
|
|
||||||
typedef typename STDEXT::hash_multimap<Point3i, ObjType *, HashFunctor> HashType;
|
typedef typename std::unordered_multimap<Point3i, ObjType *, HashFunctor> HashType;
|
||||||
typedef typename HashType::iterator HashIterator;
|
typedef typename HashType::iterator HashIterator;
|
||||||
HashType hash_table; // The real HASH TABLE **************************************
|
HashType hash_table; // The real HASH TABLE **************************************
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue