Blender V4.3
HashGrid.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
12#if 0
13# if defined(__GNUC__) && (__GNUC__ >= 3)
14// hash_map is not part of the C++ standard anymore;
15// hash_map.h has been kept though for backward compatibility
16# include <hash_map.h>
17# else
18# include <hash_map>
19# endif
20#endif
21
22#include <map>
23
24#include "Grid.h"
25
26namespace Freestyle {
27
29struct GridHasher {
30#define _MUL 950706376UL
31#define _MOD 2147483647UL
32 inline size_t operator()(const Vec3u &p) const
33 {
34 size_t res = (ulong(p[0] * _MUL)) % _MOD;
35 res = ((res + ulong(p[1]) * _MUL)) % _MOD;
36 return ((res + ulong(p[2]) * _MUL)) % _MOD;
37 }
38#undef _MUL
39#undef _MOD
40};
41
43class HashGrid : public Grid {
44 public:
45 typedef map<Vec3u, Cell *> GridHashTable;
46
47 HashGrid() : Grid() {}
48
49 virtual ~HashGrid()
50 {
51 clear();
52 }
53
57 virtual void clear();
58
67 virtual void configure(const Vec3r &orig, const Vec3r &size, uint nb);
68
70 virtual Cell *getCell(const Vec3u &p)
71 {
72 Cell *found_cell = nullptr;
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 */
unsigned long ulong
unsigned int uint
#define _MOD
#define _MUL
Base class to define a cell grid surrounding the bounding box of the scene.
map< Vec3u, Cell * > GridHashTable
Definition HashGrid.h:45
virtual void configure(const Vec3r &orig, const Vec3r &size, uint nb)
Definition HashGrid.cpp:29
virtual ~HashGrid()
Definition HashGrid.h:49
virtual Cell * getCell(const Vec3u &p)
Definition HashGrid.h:70
virtual void fillCell(const Vec3u &p, Cell &cell)
Definition HashGrid.h:82
GridHashTable _cells
Definition HashGrid.h:88
virtual void clear()
Definition HashGrid.cpp:16
inherits from class Rep
Definition AppCanvas.cpp:20
size_t operator()(const Vec3u &p) const
Definition HashGrid.h:32