-
Notifications
You must be signed in to change notification settings - Fork 0
/
MarchingCubes.h
72 lines (56 loc) · 2.73 KB
/
MarchingCubes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* @Author: Lei Wang [email protected]
* @Date: 2023-03-18 11:31:45
* @LastEditors: Lei Wang
* @LastEditTime: 2023-04-18 22:21:10
* @FilePath: \GPUMarchingCubes\MarchingCubes.h
*/
#pragma once
#include "CUDACheck.h"
#include "utils/Math.h"
#include <vector>
namespace MCKernel {
template <typename T> inline __host__ __device__ T lerp(T v0, T v1, T t) {
return fma(t, v1, fma(-t, v0, v0));
}
__device__ double3 vertexLerp(const double3 &p_0, const double3 &p_1,
const double &sdf_0, const double &sdf_1,
const double &isoVal);
__device__ double computeSDF(double3 pos);
__device__ uint3 getVoxelShift(const uint &index, const uint3 &d_res);
__global__ void
determineVoxelKernel(const uint nVoxels, const double *d_isoVal,
const double3 *d_voxelSize, const double3 *d_origin,
const uint3 *d_res, const cudaTextureObject_t nVertsTex,
uint *d_nVoxelVerts, uint *d_voxelCubeIndex,
double *d_voxelSDF, uint *d_isValidVoxel);
__global__ void compactVoxels(const uint nVoxels, const uint *d_isValidVoxel,
const uint *d_nValidVoxelsScan,
uint *d_compactedVoxelArray);
__global__ void voxelToMeshKernel(
const uint nValidVoxels, const int maxVerts, const double *d_isoVal,
const double3 *d_voxelSize, const double3 *d_origin, const uint3 *d_res,
const uint *d_compactedVoxelArray, const cudaTextureObject_t nVertsTex,
const cudaTextureObject_t triTex, uint *d_voxelCubeIndex,
double *d_voxelSDF, uint *d_nVertsScanned, double3 *d_triPoints);
} // namespace MCKernel
namespace MC {
void d_thrustExclusiveScan(const uint &nElems, uint *input, uint *output);
void setTextureObject(const uint &srcSizeInBytes, int *srcDev,
cudaTextureObject_t *texObj);
void initResources(const bool &sdfFlag, const uint3 &resolution,
const uint &nVoxels, const double &isoVal,
const double3 &gridOrigin, const double3 &voxelSize,
const uint &maxVerts, const std::vector<double> h_voxelSDF);
void freeResources();
void launch_determineVoxelKernel(const uint &nVoxels, const double &isoVal,
const uint &maxVerts);
void launch_compactVoxelsKernel(const int &nVoxels);
void launch_voxelToMeshKernel(const uint &maxVerts, const uint &nVoxels);
void writeToOBJFile(const std::string &filename);
void marching_cubes(
const uint3 &resolution, const double3 &gridOrigin,
const double3 &voxelSize, const double &isoVal, const bool &sdfFlag,
const std::string &filename,
const std::vector<double> &h_voxelSDF = std::vector<double>());
} // namespace MC