Blender  V3.3
HashGrid.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #if 0
11 # if defined(__GNUC__) && (__GNUC__ >= 3)
12 // hash_map is not part of the C++ standard anymore;
13 // hash_map.h has been kept though for backward compatibility
14 # include <hash_map.h>
15 # else
16 # include <hash_map>
17 # endif
18 #endif
19 
20 #include <map>
21 
22 #include "Grid.h"
23 
24 namespace Freestyle {
25 
27 struct GridHasher {
28 #define _MUL 950706376UL
29 #define _MOD 2147483647UL
30  inline size_t operator()(const Vec3u &p) const
31  {
32  size_t res = ((unsigned long)(p[0] * _MUL)) % _MOD;
33  res = ((res + (unsigned long)(p[1]) * _MUL)) % _MOD;
34  return ((res + (unsigned long)(p[2]) * _MUL)) % _MOD;
35  }
36 #undef _MUL
37 #undef _MOD
38 };
39 
41 class HashGrid : public Grid {
42  public:
43  typedef map<Vec3u, Cell *> GridHashTable;
44 
45  HashGrid() : Grid()
46  {
47  }
48 
49  virtual ~HashGrid()
50  {
51  clear();
52  }
53 
57  virtual void clear();
58 
67  virtual void configure(const Vec3r &orig, const Vec3r &size, unsigned nb);
68 
70  virtual Cell *getCell(const Vec3u &p)
71  {
72  Cell *found_cell = NULL;
73 
74  GridHashTable::const_iterator found = _cells.find(p);
75  if (found != _cells.end()) {
76  found_cell = (*found).second;
77  }
78  return found_cell;
79  }
80 
82  virtual void fillCell(const Vec3u &p, Cell &cell)
83  {
84  _cells[p] = &cell;
85  }
86 
87  protected:
89 };
90 
91 } /* namespace Freestyle */
Base class to define a cell grid surrounding the bounding box of the scene.
#define _MOD
Definition: HashGrid.h:29
#define _MUL
Definition: HashGrid.h:28
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
map< Vec3u, Cell * > GridHashTable
Definition: HashGrid.h:43
virtual ~HashGrid()
Definition: HashGrid.h:49
virtual void fillCell(const Vec3u &p, Cell &cell)
Definition: HashGrid.h:82
virtual Cell * getCell(const Vec3u &p)
Definition: HashGrid.h:70
GridHashTable _cells
Definition: HashGrid.h:88
virtual void configure(const Vec3r &orig, const Vec3r &size, unsigned nb)
Definition: HashGrid.cpp:25
virtual void clear()
Definition: HashGrid.cpp:12
inherits from class Rep
Definition: AppCanvas.cpp:18
size_t operator()(const Vec3u &p) const
Definition: HashGrid.h:30