2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-12-22 18:25:01 +00:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
|
|
|
|
* \brief Class to define a cell grid surrounding the bounding box of the scene
|
2012-12-22 18:25:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
# if defined(__GNUC__) && (__GNUC__ >= 3)
|
2008-04-30 15:41:54 +00:00
|
|
|
// hash_map is not part of the C++ standard anymore;
|
|
|
|
|
// hash_map.h has been kept though for backward compatibility
|
2012-12-22 18:25:01 +00:00
|
|
|
# include <hash_map.h>
|
|
|
|
|
# else
|
|
|
|
|
# include <hash_map>
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
#include "Grid.h"
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Defines a hash table used for searching the Cells */
|
2012-12-22 18:25:01 +00:00
|
|
|
struct GridHasher {
|
2008-04-30 15:41:54 +00:00
|
|
|
#define _MUL 950706376UL
|
|
|
|
|
#define _MOD 2147483647UL
|
2012-12-22 18:25:01 +00:00
|
|
|
inline size_t operator()(const Vec3u &p) const
|
|
|
|
|
{
|
2023-07-25 12:51:50 +10:00
|
|
|
size_t res = (ulong(p[0] * _MUL)) % _MOD;
|
|
|
|
|
res = ((res + ulong(p[1]) * _MUL)) % _MOD;
|
|
|
|
|
return ((res + ulong(p[2]) * _MUL)) % _MOD;
|
2012-12-22 18:25:01 +00:00
|
|
|
}
|
|
|
|
|
#undef _MUL
|
|
|
|
|
#undef _MOD
|
2008-04-30 15:41:54 +00:00
|
|
|
};
|
|
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Class to define a regular grid used for ray casting computations */
|
2014-04-17 14:19:10 +09:00
|
|
|
class HashGrid : public Grid {
|
2012-12-22 18:25:01 +00:00
|
|
|
public:
|
|
|
|
|
typedef map<Vec3u, Cell *> GridHashTable;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
HashGrid() : Grid() {}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-22 18:25:01 +00:00
|
|
|
virtual ~HashGrid()
|
|
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** clears the grid
|
2022-08-19 13:49:13 +10:00
|
|
|
* Deletes all the cells, clears the hash-table, resets size, size of cell, number of cells.
|
2012-12-22 18:25:01 +00:00
|
|
|
*/
|
|
|
|
|
virtual void clear();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Sets the different parameters of the grid
|
2012-12-22 18:25:01 +00:00
|
|
|
* orig
|
|
|
|
|
* The grid origin
|
|
|
|
|
* size
|
|
|
|
|
* The grid's dimensions
|
|
|
|
|
* nb
|
|
|
|
|
* The number of cells of the grid
|
|
|
|
|
*/
|
2023-07-25 12:51:50 +10:00
|
|
|
virtual void configure(const Vec3r &orig, const Vec3r &size, uint nb);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** returns the cell whose coordinates are passed as argument */
|
2013-03-07 23:17:23 +00:00
|
|
|
virtual Cell *getCell(const Vec3u &p)
|
2012-12-22 18:25:01 +00:00
|
|
|
{
|
2023-08-01 21:15:52 +10:00
|
|
|
Cell *found_cell = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-22 18:25:01 +00:00
|
|
|
GridHashTable::const_iterator found = _cells.find(p);
|
2019-05-31 22:51:19 +10:00
|
|
|
if (found != _cells.end()) {
|
2012-12-22 18:25:01 +00:00
|
|
|
found_cell = (*found).second;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-22 18:25:01 +00:00
|
|
|
return found_cell;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Fills the case p with the cell iCell */
|
2012-12-22 18:25:01 +00:00
|
|
|
virtual void fillCell(const Vec3u &p, Cell &cell)
|
|
|
|
|
{
|
|
|
|
|
_cells[p] = &cell;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-22 18:25:01 +00:00
|
|
|
protected:
|
|
|
|
|
GridHashTable _cells;
|
2008-04-30 15:41:54 +00:00
|
|
|
};
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
} /* namespace Freestyle */
|