Biomechanical Joint Model
 Author: Anderson Maciel

hash_map.h

Go to the documentation of this file.
00001 
00002 /*@#---------------------------------------------------------------------------
00003  PROJECT            : PHD THESIS
00004  MODULE             : PHYSICALLY-BASED DEFORMATION
00005 
00006  FILE               : hash_map.h
00007  CREATION DATE      : Mon Nov 29 12:10:54 MET 1999
00008  CREATION AUTHOR(S) : aubel 
00009  ------------------------------------------------------------------------------
00010  KEYWORD(S)         : marching cubes, voxelisation, volume
00011  DEFINED TYPE(S)    : HashMap
00012  RELATED TYPE(S)    : Voxel, Edge
00013 
00014  FUNCTIONALITY      : 
00015  ------------------------------------------------------------------------------
00016  LANGAGE            : Ansi C++
00017  SYSTEM             : UNIX V 6.x / SGI
00018  GRAPHIC LIBRARY    : SGI  
00019  ------------------------------------------------------------------------------
00020  PROJECT DIRECTOR   : D. THALMANN
00021  LAB                : EPFL- LIG
00022  --------------------------------------------------------------------------#@*/
00023 #ifndef MC_HASH_MAP_VOXEL_H
00024 #define MC_HASH_MAP_VOXEL_H
00025 
00026 #include <vector>
00027 
00028 //namespace MarchingCubes {
00029 
00030 template <class T>
00031 class HashMap
00032 {
00033 public:
00034    HashMap(int l=8, int m=8, int n=8) : l_(l), m_(m), n_(n), 
00035       elements( new vector<T> [l*m*n] ) {};   
00036    ~HashMap() { delete [] elements; };
00037       
00038    T& operator[](const idx3 &id);
00039    const T& operator[](const idx3 &id) const;  
00040 
00041 private:
00042    int hash_func(const idx3 &id) const { return ((id.i%l_)*m_ + (id.j%m_))*n_ + id.k%n_; };
00043    
00044    vector<T> *elements;
00045    int l_, m_, n_;
00046 };
00047 
00048 template <class T>
00049 T& HashMap<T>::operator[](const idx3 &id) 
00050 { 
00051    int index = hash_func(id);
00052 
00053    for (typename vector<T>::iterator it = elements[index].begin(); 
00054         it != elements[index].end(); it++)
00055    {      
00056       if (it->id == id) return *it;
00057    }
00058 
00059    // insert new element
00060    elements[index].push_back(T(id));
00061    return elements[index].back();
00062 }
00063 
00064 template <class T>
00065 const T& HashMap<T>::operator[](const idx3 &id) const
00066 { 
00067    int index = hash_func(id);
00068 
00069    for ( typename vector<T>::iterator it = elements[index].begin(); 
00070         it != elements[index].end(); it++)
00071    {      
00072       if (it->id == id) return *it;
00073    }
00074    cout << "HashMap: cannot find element whose index is " << id << endl;
00075    exit(-1);
00076    // suppress cmpiler warning
00077    return elements[index][0];
00078 }
00079 
00080 //}
00081 #endif

Generated on Thu Dec 1 10:13:38 2005 for COME - Biomechanical Joint Model by  doxygen 1.4.5