Blender V4.3
FastGrid.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#include <cstdlib>
11
12#include "FastGrid.h"
13
14#include "BKE_global.hh"
15#include "BLI_utildefines.h"
16
17namespace Freestyle {
18
20{
21 if (!_cells) {
22 return;
23 }
24
25 for (uint i = 0; i < _cells_size; i++) {
26 if (_cells[i]) {
27 delete _cells[i];
28 }
29 }
30 delete[] _cells;
31 _cells = nullptr;
32 _cells_size = 0;
33
35}
36
37void FastGrid::configure(const Vec3r &orig, const Vec3r &size, uint nb)
38{
39 Grid::configure(orig, size, nb);
41 _cells = new Cell *[_cells_size];
42 memset(_cells, 0, _cells_size * sizeof(*_cells));
43}
44
46{
47#if 0
48 if (G.debug & G_DEBUG_FREESTYLE) {
49 cout << _cells << " " << p << " " << _cells_nb[0] << "-" << _cells_nb[1] << "-" << _cells_nb[2]
50 << " " << _cells_size << endl;
51 }
52#endif
53 BLI_assert_msg(_cells, "_cells is a null pointer");
54 BLI_assert((_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]) < _cells_size);
55 BLI_assert(p[0] < _cells_nb[0]);
56 BLI_assert(p[1] < _cells_nb[1]);
57 BLI_assert(p[2] < _cells_nb[2]);
58 return _cells[_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]];
59}
60
61void FastGrid::fillCell(const Vec3u &p, Cell &cell)
62{
63 BLI_assert_msg(_cells, "_cells is a null pointer");
64 BLI_assert((_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]) < _cells_size);
65 BLI_assert(p[0] < _cells_nb[0]);
66 BLI_assert(p[1] < _cells_nb[1]);
67 BLI_assert(p[2] < _cells_nb[2]);
68 _cells[_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]] = &cell;
69}
70
71} /* namespace Freestyle */
@ G_DEBUG_FREESTYLE
#define BLI_assert(a)
Definition BLI_assert.h:50
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:57
unsigned int uint
Class to define a cell grid surrounding the bounding box of the scene.
Cell * getCell(const Vec3u &p)
Definition FastGrid.cpp:45
virtual void configure(const Vec3r &orig, const Vec3r &size, uint nb)
Definition FastGrid.cpp:37
virtual void fillCell(const Vec3u &p, Cell &cell)
Definition FastGrid.cpp:61
virtual void clear()
Definition FastGrid.cpp:19
virtual void configure(const Vec3r &orig, const Vec3r &size, uint nb)
Definition Grid.cpp:100
virtual void clear()
Definition Grid.cpp:84
Vec3u _cells_nb
Definition Grid.h:365
#define G(x, y, z)
inherits from class Rep
Definition AppCanvas.cpp:20