[Insight-users] Using itk::hash_table

Luis Ibanez luis.ibanez at kitware.com
Tue Dec 1 19:04:29 EST 2009


Hi Motes,


It seems that this type of spatial hashing has already been
implemented in the following ITK class:

     Insight/Code/Algorithms/ itkAutomaticTopologyMeshSource.h

See lines: 146-150

 typedef itk::hash_map<
    PointType,
    IdentifierType,
    StructHashFunction< PointHashType > >          PointHashMap;


and you will find the definition of "StructHashFunction<>" in the file:

   Insight/Code/Algorithms/itkStructHashFunction.h

while the type "PointHashType" is declared in the Mesh Traits
files:

     Insight/Code/Common/

itkDefaultDynamicMeshTraits.h:

            typedef Point< CoordRepType, VPointDimension >  PointHashType;

itkDefaultStaticMeshTraits.h:

          typedef Point< CoordRepType, VPointDimension >  PointHashType;




      Regards,


               Luis



--------------------------------------------------------------------------------
On Sat, Nov 28, 2009 at 5:02 PM, motes motes <mort.motes at gmail.com> wrote:
> 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?
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list