-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSDF_Hashtable.cpp
90 lines (72 loc) · 3.38 KB
/
SDF_Hashtable.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifdef _WIN32
#include <windows.h>
#endif
#include "prereq.h"
#include "SDF_Hashtable.h"
#include "SDFRenderer.h"
#include "VoxelUtils.h"
#include "common.h"
void SDF_Hashtable::integrate(const float4x4& viewMat, const float4* verts, const float4* normals) {
mapGLobjectsToCUDApointers(numVisibleBlocks_res, compactHashtable_res, sdfBlocks_res);
//first update the device HashParams variable
float4x4 inv_global_transform = viewMat.getInverse();
h_hashtableParams.global_transform = viewMat;
h_hashtableParams.inv_global_transform = inv_global_transform;
//upload to device
updateConstantHashTableParams(h_hashtableParams);
//TODO : reset hash-table mutexes
resetHashTableMutexes(h_hashtableParams);
//launch kernel to insert voxelentries into hashtable
allocBlocks(verts, normals);
//consolidate visible entries into a flat buffer
int occupiedBlockCount = flattenIntoBuffer(h_hashtableParams);
std::cout<<"occupiedBlockCount : "<<occupiedBlockCount<<"\n";
h_hashtableParams.numOccupiedBlocks = occupiedBlockCount;
updateConstantHashTableParams(h_hashtableParams);
//integrate vertices into SDF volume
integrateDepthMap(h_hashtableParams, verts);
std::cout << "depth map integrated into volume! \n";
unmapCUDApointers();
}
void SDF_Hashtable::registerGLtoCUDA(SDFRenderer& renderer) {
//rendererRef = &renderer;
checkCudaErrors(cudaGraphicsGLRegisterBuffer(&numVisibleBlocks_res, renderer.numOccupiedBlocks_handle, cudaGraphicsRegisterFlagsNone));
checkCudaErrors(cudaGraphicsGLRegisterBuffer(&compactHashtable_res, renderer.compactHashTable_handle, cudaGraphicsRegisterFlagsNone));
checkCudaErrors(cudaGraphicsGLRegisterBuffer(&sdfBlocks_res, renderer.SDF_VolumeBuffer_handle, cudaGraphicsRegisterFlagsNone));
//int numVisibleBlocks_handle = renderer.numOccupiedBlocks_handle;
//mapGLobjectsToCUDApointers(*rendererRef);
std::cout << "GL resources registered to CUDA hashtable\n";
}
void SDF_Hashtable::unmapCUDApointers()
{
checkCudaErrors(cudaGraphicsUnmapResources(1, &numVisibleBlocks_res, 0));
checkCudaErrors(cudaGraphicsUnmapResources(1, &compactHashtable_res, 0));
checkCudaErrors(cudaGraphicsUnmapResources(1, &sdfBlocks_res, 0));
std::cout << "CUDA device pointers unmapped!\n";
}
SDF_Hashtable::SDF_Hashtable() {
h_hashtableParams.numBuckets = numBuckets;
h_hashtableParams.bucketSize = bucketSize; //10
h_hashtableParams.attachedLinkedListSize = attachedLinkedListSize; //7
h_hashtableParams.numVoxelBlocks = numVoxelBlocks;
h_hashtableParams.voxelBlockSize = voxelBlockSize;
h_hashtableParams.voxelSize = voxelSize;
h_hashtableParams.numOccupiedBlocks = numOccupiedBlocks;
h_hashtableParams.maxIntegrationDistance = maxIntegrationDistance;
h_hashtableParams.truncScale = truncScale;
h_hashtableParams.truncation = truncation;
h_hashtableParams.integrationWeightSample = integrationWeightSample;
h_hashtableParams.integrationWeightMax = integrationWeightMax;
updateConstantHashTableParams(h_hashtableParams);
deviceAllocate(h_hashtableParams);
std::cout<<"CUDA device memory allocated\n";
calculateKinectProjectionMatrix();
std::cout<<"Kinect projection matrix calculated\n";
}
SDF_Hashtable::~SDF_Hashtable() {
deviceFree();
checkCudaErrors(cudaGraphicsUnregisterResource(numVisibleBlocks_res));
checkCudaErrors(cudaGraphicsUnregisterResource(sdfBlocks_res));
checkCudaErrors(cudaGraphicsUnregisterResource(compactHashtable_res));
std::cout<<"CUDA device memory freed\n";
}