Blender  V2.93
FastGrid.cpp
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 
22 #include <cstdlib>
23 
24 #include "FastGrid.h"
25 
26 #include "BKE_global.h"
27 #include "BLI_utildefines.h"
28 
29 namespace Freestyle {
30 
32 {
33  if (!_cells) {
34  return;
35  }
36 
37  for (unsigned int i = 0; i < _cells_size; i++) {
38  if (_cells[i]) {
39  delete _cells[i];
40  }
41  }
42  delete[] _cells;
43  _cells = nullptr;
44  _cells_size = 0;
45 
46  Grid::clear();
47 }
48 
49 void FastGrid::configure(const Vec3r &orig, const Vec3r &size, unsigned nb)
50 {
51  Grid::configure(orig, size, nb);
53  _cells = new Cell *[_cells_size];
54  memset(_cells, 0, _cells_size * sizeof(*_cells));
55 }
56 
58 {
59 #if 0
60  if (G.debug & G_DEBUG_FREESTYLE) {
61  cout << _cells << " " << p << " " << _cells_nb[0] << "-" << _cells_nb[1] << "-" << _cells_nb[2]
62  << " " << _cells_size << endl;
63  }
64 #endif
65  BLI_assert(_cells || ("_cells is a null pointer"));
66  BLI_assert((_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]) < _cells_size);
67  BLI_assert(p[0] < _cells_nb[0]);
68  BLI_assert(p[1] < _cells_nb[1]);
69  BLI_assert(p[2] < _cells_nb[2]);
70  return _cells[_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]];
71 }
72 
73 void FastGrid::fillCell(const Vec3u &p, Cell &cell)
74 {
75  BLI_assert(_cells || ("_cells is a null pointer"));
76  BLI_assert((_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]) < _cells_size);
77  BLI_assert(p[0] < _cells_nb[0]);
78  BLI_assert(p[1] < _cells_nb[1]);
79  BLI_assert(p[2] < _cells_nb[2]);
80  _cells[_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]] = &cell;
81 }
82 
83 } /* namespace Freestyle */
@ G_DEBUG_FREESTYLE
Definition: BKE_global.h:140
#define BLI_assert(a)
Definition: BLI_assert.h:58
Class to define a cell grid surrounding the bounding box of the scene.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
Cell * getCell(const Vec3u &p)
Definition: FastGrid.cpp:57
unsigned _cells_size
Definition: FastGrid.h:70
virtual void configure(const Vec3r &orig, const Vec3r &size, unsigned nb)
Definition: FastGrid.cpp:49
virtual void fillCell(const Vec3u &p, Cell &cell)
Definition: FastGrid.cpp:73
virtual void clear()
Definition: FastGrid.cpp:31
virtual void configure(const Vec3r &orig, const Vec3r &size, unsigned nb)
Definition: Grid.cpp:110
virtual void clear()
Definition: Grid.cpp:94
Vec3u _cells_nb
Definition: Grid.h:391
inherits from class Rep
Definition: AppCanvas.cpp:32
#define G(x, y, z)