[Insight-users] Using itk::hash_table
motes motes
mort.motes at gmail.com
Sat Nov 28 17:02:22 EST 2009
I would like to use a itk::hash_table to store my own objects (for
spatial hashing).
For each index in the hash_table a list of objects should be stored
based on a hash value (pretty much the definition of a hash-table).
I would like to compute this hash value based on the location of each
of the objects which contains a 3D vector corresponding to its
location in space.
Something like (the below is python code use as an example from the
website: http://entitycrisis.blogspot.com/2007/11/spatial-hashing.html):
def key(self, point):
cell_size = self.cell_size
return (
int((floor(point[0]/cell_size))*cell_size),
int((floor(point[1]/cell_size))*cell_size),
int((floor(point[2]/cell_size))*cell_size)
)
So if I do:
void eval(VectorType v) {
std::vector<MyObj> chain = hash_map.get(v);
}
I should get all those elements that hash to the value based on the "key" v.
I have done the following:
typedef itk::Vector<double, Dimension>
VectorType;
typedef MyPoint<VectorType>
MyPointType;
typedef std::pair<MyPointType,int>
ValueType;
typedef unsigned long
IdentifierType;
typedef itk::hash_map<MyPointType, IdentifierType,
MyHashFunction<MyPointType > > HashMap;
HashMap m_HashTable;
MyPointType cp0;
VectorType vec0;
ValueType val0;
val0.first = cp0;
val0.second = 12;
In MyPoint I have implemented the following operators:
bool operator==(const MyPoint & mp) const {
return !(*this == mp);
}
int operator ()(MyPoint & mp) {
// hm what todo here? Return cell size?
return 10;
}
I have created the following hash functor:
template< class TInput >
class MyHashFunction
{
public:
typedef MyHashFunction Self;
typedef TInput InputType;
typedef InputType::VectorType VectorType;
unsigned int operator()( const InputType& key ) const;
};
template< class TInput >
inline unsigned int
MyHashFunction< TInput >
::operator()( const InputType& key ) const
{
VectorType position = key.getPosition();
double cellSize = key.getCellSize();
// Do something like the above pythion scripts....
return hash;
}
But I am not sure what I should use the operator "()" for and what
the: "IdentifierType" represents.
Another think. I need to get all elements associated with the key 'k'.
By all elements I mean the "chain/list" connected to the index
returned by the hash_function. Is that possible with the
itk::hash__table or should I look into the std::map containing lists
instead?
More information about the Insight-users
mailing list