Blender V4.3
voxel.c
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
9#include "BLI_utildefines.h"
10#include "BLI_voxel.h"
11
12#include "BLI_strict_flags.h" /* Keep last. */
13
14BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)
15{
16 CLAMP(x, 0, res[0] - 1);
17 CLAMP(y, 0, res[1] - 1);
18 CLAMP(z, 0, res[2] - 1);
19 return data[BLI_VOXEL_INDEX(x, y, z, res)];
20}
21
22/* *** nearest neighbor *** */
23
24/* returns highest integer <= x as integer (slightly faster than floor()) */
25BLI_INLINE int FLOORI(float x)
26{
27 const int r = (int)x;
28 return ((x >= 0.0f) || (float)r == x) ? r : (r - 1);
29}
30
39BLI_INLINE int64_t _clamp(int a, int b, int c)
40{
41 return (a < b) ? b : ((a > c) ? c : a);
42}
43
44float BLI_voxel_sample_trilinear(const float *data, const int res[3], const float co[3])
45{
46 if (data) {
47
48 const float xf = co[0] * (float)res[0] - 0.5f;
49 const float yf = co[1] * (float)res[1] - 0.5f;
50 const float zf = co[2] * (float)res[2] - 0.5f;
51
52 const int x = FLOORI(xf), y = FLOORI(yf), z = FLOORI(zf);
53
54 const int64_t xc[2] = {
55 _clamp(x, 0, res[0] - 1),
56 _clamp(x + 1, 0, res[0] - 1),
57 };
58 const int64_t yc[2] = {
59 _clamp(y, 0, res[1] - 1) * res[0],
60 _clamp(y + 1, 0, res[1] - 1) * res[0],
61 };
62 const int64_t zc[2] = {
63 _clamp(z, 0, res[2] - 1) * res[0] * res[1],
64 _clamp(z + 1, 0, res[2] - 1) * res[0] * res[1],
65 };
66
67 const float dx = xf - (float)x;
68 const float dy = yf - (float)y;
69 const float dz = zf - (float)z;
70
71 const float u[2] = {1.0f - dx, dx};
72 const float v[2] = {1.0f - dy, dy};
73 const float w[2] = {1.0f - dz, dz};
74
75 return w[0] *
76 (v[0] * (u[0] * data[xc[0] + yc[0] + zc[0]] + u[1] * data[xc[1] + yc[0] + zc[0]]) +
77 v[1] * (u[0] * data[xc[0] + yc[1] + zc[0]] + u[1] * data[xc[1] + yc[1] + zc[0]])) +
78 w[1] *
79 (v[0] * (u[0] * data[xc[0] + yc[0] + zc[1]] + u[1] * data[xc[1] + yc[0] + zc[1]]) +
80 v[1] * (u[0] * data[xc[0] + yc[1] + zc[1]] + u[1] * data[xc[1] + yc[1] + zc[1]]));
81 }
82 return 0.0f;
83}
#define D
#define BLI_INLINE
#define CLAMP(a, b, c)
#define BLI_VOXEL_INDEX(x, y, z, res)
Definition BLI_voxel.h:16
ATTR_WARN_UNUSED_RESULT const BMVert * v
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
local_group_size(16, 16) .push_constant(Type b
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
__int64 int64_t
Definition stdint.h:89
BLI_INLINE int FLOORI(float x)
Definition voxel.c:25
BLI_INLINE int64_t _clamp(int a, int b, int c)
Definition voxel.c:39
float BLI_voxel_sample_trilinear(const float *data, const int res[3], const float co[3])
Definition voxel.c:44