33 #define DISPATCH_BYTESIZE_TO_VOXEL(BYTESIZE, ...) \ 35 if (BYTESIZE == sizeof(ColoredVoxel32f)) { \ 36 using voxel_t = ColoredVoxel32f; \ 37 return __VA_ARGS__(); \ 38 } else if (BYTESIZE == sizeof(ColoredVoxel16i)) { \ 39 using voxel_t = ColoredVoxel16i; \ 40 return __VA_ARGS__(); \ 41 } else if (BYTESIZE == sizeof(Voxel32f)) { \ 42 using voxel_t = Voxel32f; \ 43 return __VA_ARGS__(); \ 45 utility::LogError("Unsupported voxel bytesize"); \ 69 tsdf = (weight * tsdf + dsdf) / (weight + 1);
76 printf(
"[Voxel32f] should never reach here.\n");
86 static const uint16_t kMaxUint16 = 65535;
87 static constexpr
float kColorFactor = 255.0f;
100 return static_cast<float>(r / kColorFactor);
103 return static_cast<float>(g / kColorFactor);
106 return static_cast<float>(b / kColorFactor);
109 float inc_wsum =
static_cast<float>(
weight) + 1;
110 float inv_wsum = 1.0f / inc_wsum;
111 tsdf = (
static_cast<float>(
weight) * tsdf + dsdf) * inv_wsum;
112 weight =
static_cast<uint16_t
>(inc_wsum < static_cast<float>(kMaxUint16)
120 float inc_wsum =
static_cast<float>(
weight) + 1;
121 float inv_wsum = 1.0f / inc_wsum;
122 tsdf = (weight * tsdf + dsdf) * inv_wsum;
123 r =
static_cast<uint16_t
>(
124 roundf((weight * r + dr * kColorFactor) * inv_wsum));
125 g =
static_cast<uint16_t
>(
126 roundf((weight * g + dg * kColorFactor) * inv_wsum));
127 b =
static_cast<uint16_t
>(
128 roundf((weight * b + db * kColorFactor) * inv_wsum));
129 weight =
static_cast<uint16_t
>(inc_wsum < static_cast<float>(kMaxUint16)
152 float inv_wsum = 1.0f / (weight + 1);
153 tsdf = (weight * tsdf + dsdf) * inv_wsum;
160 float inv_wsum = 1.0f / (weight + 1);
161 tsdf = (weight * tsdf + dsdf) * inv_wsum;
162 r = (weight * r + dr) * inv_wsum;
163 g = (weight * g + dg) * inv_wsum;
164 b = (weight * b + db) * inv_wsum;
171 template <
typename voxel_t>
181 int xn = (xo + resolution) % resolution;
182 int yn = (yo + resolution) % resolution;
183 int zn = (zo + resolution) % resolution;
185 int64_t dxb =
Sign(xo - xn);
186 int64_t dyb =
Sign(yo - yn);
187 int64_t dzb =
Sign(zo - zn);
189 int64_t nb_idx = (dxb + 1) + (dyb + 1) * 3 + (dzb + 1) * 9;
192 *nb_block_masks_indexer.
GetDataPtr<
bool>(curr_block_idx, nb_idx);
193 if (!block_mask_i)
return nullptr;
195 int64_t block_idx_i = *nb_block_indices_indexer.
GetDataPtr<int64_t>(
196 curr_block_idx, nb_idx);
198 return blocks_indexer.
GetDataPtr<voxel_t>(xn, yn, zn, block_idx_i);
203 template <
typename voxel_t>
215 auto GetVoxelAt = [&]
OPEN3D_DEVICE(
int xo,
int yo,
int zo) {
216 return DeviceGetVoxelAt<voxel_t>(
217 xo, yo, zo, curr_block_idx, resolution, nb_block_masks_indexer,
218 nb_block_indices_indexer, blocks_indexer);
220 voxel_t* vxp = GetVoxelAt(xo + 1, yo, zo);
221 voxel_t* vxn = GetVoxelAt(xo - 1, yo, zo);
222 voxel_t* vyp = GetVoxelAt(xo, yo + 1, zo);
223 voxel_t* vyn = GetVoxelAt(xo, yo - 1, zo);
224 voxel_t* vzp = GetVoxelAt(xo, yo, zo + 1);
225 voxel_t* vzn = GetVoxelAt(xo, yo, zo - 1);
226 if (vxp && vxn) n[0] = (vxp->GetTSDF() - vxn->GetTSDF()) / (2 * voxel_size);
227 if (vyp && vyn) n[1] = (vyp->GetTSDF() - vyn->GetTSDF()) / (2 * voxel_size);
228 if (vzp && vzn) n[2] = (vzp->GetTSDF() - vzn->GetTSDF()) / (2 * voxel_size);
239 int xn = (xo + resolution) % resolution;
240 int yn = (yo + resolution) % resolution;
241 int zn = (zo + resolution) % resolution;
243 int64_t dxb =
Sign(xo - xn);
244 int64_t dyb =
Sign(yo - yn);
245 int64_t dzb =
Sign(zo - zn);
247 int64_t nb_idx = (dxb + 1) + (dyb + 1) * 3 + (dzb + 1) * 9;
250 *nb_block_masks_indexer.
GetDataPtr<
bool>(curr_block_idx, nb_idx);
251 if (!block_mask_i)
return -1;
254 *nb_block_indices_indexer.
GetDataPtr<
int>(curr_block_idx, nb_idx);
256 return (((block_idx_i * resolution) + zn) * resolution + yn) * resolution +
OPEN3D_HOST_DEVICE void Integrate(float dsdf, float dr, float dg, float db)
Definition: TSDFVoxel.h:156
Definition: GeometryIndexer.h:180
OPEN3D_HOST_DEVICE float GetR()
Definition: TSDFVoxel.h:64
Definition: TSDFVoxel.h:57
OPEN3D_HOST_DEVICE void * GetDataPtr() const
Definition: GeometryIndexer.h:335
float tsdf
Definition: TSDFVoxel.h:89
OPEN3D_HOST_DEVICE int Sign(int x)
Definition: GeometryMacros.h:96
OPEN3D_HOST_DEVICE void Integrate(float dsdf)
Definition: TSDFVoxel.h:108
OPEN3D_DEVICE void DeviceGetNormalAt(int xo, int yo, int zo, int curr_block_idx, float *n, int resolution, float voxel_size, const NDArrayIndexer &nb_block_masks_indexer, const NDArrayIndexer &nb_block_indices_indexer, const NDArrayIndexer &blocks_indexer)
Definition: TSDFVoxel.h:204
OPEN3D_HOST_DEVICE void Integrate(float dsdf, float dr, float dg, float db)
Definition: TSDFVoxel.h:116
OPEN3D_HOST_DEVICE float GetTSDF()
Definition: TSDFVoxel.h:146
float weight
Definition: TSDFVoxel.h:59
float tsdf
Definition: TSDFVoxel.h:58
static bool HasColor()
Definition: TSDFVoxel.h:61
Definition: TSDFVoxel.h:85
OPEN3D_HOST_DEVICE float GetB()
Definition: TSDFVoxel.h:66
OPEN3D_HOST_DEVICE void Integrate(float dsdf, float dr, float dg, float db)
Definition: TSDFVoxel.h:72
float b
Definition: TSDFVoxel.h:143
#define OPEN3D_DEVICE
Definition: CUDAUtils.h:64
#define OPEN3D_HOST_DEVICE
Definition: CUDAUtils.h:63
float g
Definition: TSDFVoxel.h:142
static bool HasColor()
Definition: TSDFVoxel.h:96
Definition: TSDFVoxel.h:137
OPEN3D_DEVICE voxel_t * DeviceGetVoxelAt(int xo, int yo, int zo, int curr_block_idx, int resolution, const NDArrayIndexer &nb_block_masks_indexer, const NDArrayIndexer &nb_block_indices_indexer, const NDArrayIndexer &blocks_indexer)
Definition: TSDFVoxel.h:172
OPEN3D_HOST_DEVICE float GetTSDF()
Definition: TSDFVoxel.h:62
OPEN3D_HOST_DEVICE float GetWeight()
Definition: TSDFVoxel.h:63
float weight
Definition: TSDFVoxel.h:139
float tsdf
Definition: TSDFVoxel.h:138
OPEN3D_HOST_DEVICE float GetG()
Definition: TSDFVoxel.h:149
OPEN3D_HOST_DEVICE float GetR()
Definition: TSDFVoxel.h:99
float r
Definition: TSDFVoxel.h:141
OPEN3D_HOST_DEVICE float GetG()
Definition: TSDFVoxel.h:65
uint16_t g
Definition: TSDFVoxel.h:93
OPEN3D_HOST_DEVICE float GetB()
Definition: TSDFVoxel.h:105
OPEN3D_HOST_DEVICE void Integrate(float dsdf)
Definition: TSDFVoxel.h:68
OPEN3D_HOST_DEVICE float GetTSDF()
Definition: TSDFVoxel.h:97
static bool HasColor()
Definition: TSDFVoxel.h:145
Definition: PinholeCameraIntrinsic.cpp:35
OPEN3D_HOST_DEVICE float GetWeight()
Definition: TSDFVoxel.h:98
OPEN3D_DEVICE int64_t DeviceGetLinearIdx(int xo, int yo, int zo, int curr_block_idx, int resolution, const NDArrayIndexer &nb_block_masks_indexer, const NDArrayIndexer &nb_block_indices_indexer)
Definition: TSDFVoxel.h:232
OPEN3D_HOST_DEVICE float GetG()
Definition: TSDFVoxel.h:102
uint16_t weight
Definition: TSDFVoxel.h:90
OPEN3D_HOST_DEVICE float GetB()
Definition: TSDFVoxel.h:150
OPEN3D_HOST_DEVICE float GetR()
Definition: TSDFVoxel.h:148
OPEN3D_HOST_DEVICE float GetWeight()
Definition: TSDFVoxel.h:147
uint16_t b
Definition: TSDFVoxel.h:94
OPEN3D_HOST_DEVICE void Integrate(float dsdf)
Definition: TSDFVoxel.h:151
uint16_t r
Definition: TSDFVoxel.h:92