Blender  V2.93
HashGrid.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
24 #if 0
25 # if defined(__GNUC__) && (__GNUC__ >= 3)
26 // hash_map is not part of the C++ standard anymore;
27 // hash_map.h has been kept though for backward compatibility
28 # include <hash_map.h>
29 # else
30 # include <hash_map>
31 # endif
32 #endif
33 
34 #include <map>
35 
36 #include "Grid.h"
37 
38 namespace Freestyle {
39 
41 struct GridHasher {
42 #define _MUL 950706376UL
43 #define _MOD 2147483647UL
44  inline size_t operator()(const Vec3u &p) const
45  {
46  size_t res = ((unsigned long)(p[0] * _MUL)) % _MOD;
47  res = ((res + (unsigned long)(p[1]) * _MUL)) % _MOD;
48  return ((res + (unsigned long)(p[2]) * _MUL)) % _MOD;
49  }
50 #undef _MUL
51 #undef _MOD
52 };
53 
55 class HashGrid : public Grid {
56  public:
57  typedef map<Vec3u, Cell *> GridHashTable;
58 
59  HashGrid() : Grid()
60  {
61  }
62 
63  virtual ~HashGrid()
64  {
65  clear();
66  }
67 
71  virtual void clear();
72 
81  virtual void configure(const Vec3r &orig, const Vec3r &size, unsigned nb);
82 
84  virtual Cell *getCell(const Vec3u &p)
85  {
86  Cell *found_cell = NULL;
87 
88  GridHashTable::const_iterator found = _cells.find(p);
89  if (found != _cells.end()) {
90  found_cell = (*found).second;
91  }
92  return found_cell;
93  }
94 
96  virtual void fillCell(const Vec3u &p, Cell &cell)
97  {
98  _cells[p] = &cell;
99  }
100 
101  protected:
103 };
104 
105 } /* namespace Freestyle */
Base class to define a cell grid surrounding the bounding box of the scene.
#define _MOD
Definition: HashGrid.h:43
#define _MUL
Definition: HashGrid.h:42
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
map< Vec3u, Cell * > GridHashTable
Definition: HashGrid.h:57
virtual ~HashGrid()
Definition: HashGrid.h:63
virtual void fillCell(const Vec3u &p, Cell &cell)
Definition: HashGrid.h:96
virtual Cell * getCell(const Vec3u &p)
Definition: HashGrid.h:84
GridHashTable _cells
Definition: HashGrid.h:102
virtual void configure(const Vec3r &orig, const Vec3r &size, unsigned nb)
Definition: HashGrid.cpp:39
virtual void clear()
Definition: HashGrid.cpp:26
inherits from class Rep
Definition: AppCanvas.cpp:32
size_t operator()(const Vec3u &p) const
Definition: HashGrid.h:44