Blender V5.3
voxel.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_utildefines.hh"
10#include "BLI_voxel.hh"
11
12#include "BLI_strict_flags.hh" /* IWYU pragma: keep. Keep last. */
13
14namespace blender {
15
16BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)
17{
18 CLAMP(x, 0, res[0] - 1);
19 CLAMP(y, 0, res[1] - 1);
20 CLAMP(z, 0, res[2] - 1);
21 return data[BLI_VOXEL_INDEX(x, y, z, res)];
22}
23
24/* *** nearest neighbor *** */
25
26/* returns highest integer <= x as integer (slightly faster than floor()) */
28{
29 const int r = int(x);
30 return ((x >= 0.0f) || float(r) == x) ? r : (r - 1);
31}
32
41BLI_INLINE int64_t _clamp(int a, int b, int c)
42{
43 return (a < b) ? b : ((a > c) ? c : a);
44}
45
46float BLI_voxel_sample_trilinear(const float *data, const int res[3], const float co[3])
47{
48 if (data) {
49
50 const float xf = co[0] * float(res[0]) - 0.5f;
51 const float yf = co[1] * float(res[1]) - 0.5f;
52 const float zf = co[2] * float(res[2]) - 0.5f;
53
54 const int x = FLOORI(xf), y = FLOORI(yf), z = FLOORI(zf);
55
56 const int64_t xc[2] = {
57 _clamp(x, 0, res[0] - 1),
58 _clamp(x + 1, 0, res[0] - 1),
59 };
60 const int64_t yc[2] = {
61 _clamp(y, 0, res[1] - 1) * res[0],
62 _clamp(y + 1, 0, res[1] - 1) * res[0],
63 };
64 const int64_t zc[2] = {
65 _clamp(z, 0, res[2] - 1) * res[0] * res[1],
66 _clamp(z + 1, 0, res[2] - 1) * res[0] * res[1],
67 };
68
69 const float dx = xf - float(x);
70 const float dy = yf - float(y);
71 const float dz = zf - float(z);
72
73 const float u[2] = {1.0f - dx, dx};
74 const float v[2] = {1.0f - dy, dy};
75 const float w[2] = {1.0f - dz, dz};
76
77 return w[0] *
78 (v[0] * (u[0] * data[xc[0] + yc[0] + zc[0]] + u[1] * data[xc[1] + yc[0] + zc[0]]) +
79 v[1] * (u[0] * data[xc[0] + yc[1] + zc[0]] + u[1] * data[xc[1] + yc[1] + zc[0]])) +
80 w[1] *
81 (v[0] * (u[0] * data[xc[0] + yc[0] + zc[1]] + u[1] * data[xc[1] + yc[0] + zc[1]]) +
82 v[1] * (u[0] * data[xc[0] + yc[1] + zc[1]] + u[1] * data[xc[1] + yc[1] + zc[1]]));
83 }
84 return 0.0f;
85}
86
87} // namespace blender
#define BLI_VOXEL_INDEX(x, y, z, res)
Definition BLI_voxel.hh:14
#define CLAMP(a, b, c)
#define BLI_INLINE
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
BMesh Iterators.
__int64 int64_t
Definition BKE_text.h:90
BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)
Definition voxel.cc:16
ATTR_WARN_UNUSED_RESULT const BMVert * v
float BLI_voxel_sample_trilinear(const float *data, const int res[3], const float co[3])
Definition voxel.cc:46
BMesh const char void * data
BLI_INLINE int64_t _clamp(int a, int b, int c)
Definition voxel.cc:41
BLI_INLINE int FLOORI(float x)
Definition voxel.cc:27
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float