Skip to content

Commit 7ede658

Browse files
DumDereDumsavuor
andauthored
Merge pull request #2734 from DumDereDum:new_HashTSDF_GPU_class
New HashTSDFVolumeGPU class * create new class * rewrite makeHashTSDFVolume * it builds * minor fi * raycast - done * all code builds * Docs fix * �fetch_normals fix * I want it to work * minor fix * valid points checking passed * it works! * minor fixes * warning fix * last replacements * warning fix * create hash_tsdf.cl * add preCalculationPixNormGPU * add integrateVolumeUnitGPU * Docs fix * create simple volume table * add functionality to the table * add new functions * create new hash table implementation * minor fix * create new hash tsdf implementaton * add expand feature * minorfix * error fix * it builds * new hash table work * Docs fix * warnings fix * warning fix 1 * warning fix 2 * warning fix * remove extra coments * create new function integrateAllVolumeUnitsGPU * add hash table function * extend kernel signature * minor fix * extent Volume_NODE signature and add functionality * kernel args fix * smth * minor fix * kernal args fix * try to fix reading bug * hash table fix * add totalVolUnits feature * it builds * minor fix * integrate fix * fix work with table * minor table fi * I am stumped * try to fix * add checking to find error * add copyto * vol2cam fix * try to fix * we are the champions * remove some comments * remove last comments * docs fix * warning fix * warning fix 1 * warning fix 2 * create raycast kernel * extend raycast gpu signature * minor fix * integrate all volUnits - done * docs fix * warning fix * extend raycast signature * raycast work * bug fix * calc point4 fix * minor fix * add _at function * raycast done, but work incorrect * fin dug * bug fix * getNorm works correctly * minor fix * raycast - done * minor fixes * docs fix * warning fix * minor fix * minor fix * warning fix * warning fix 1 * win warning fix * mac fix * win debug fix * mac cl warning fix * allCam2vol fix * rename num with bufferNum * remove nums hardcode * minor fix * change logic of calculating hash * replace float16 by vload16 * replace true with false in zFirstMemOrder * poses fix * add new tests * debug print * debug print 1 * replace [] with .s * minor fix * minor fix 1 * remove print * hashtsdf work fix * hashtable fix * resrite hashtasble update * test_tsdf fix * override warning fix * docs fix * mutex fix * setUseOptimizes replace false with true * minor fix * merge with master * all minor fixes * add CPU code for debug * settings set * move code from hpp to cpp * minor opencl fix * fid bug * coment fix * minor fix * bug fix * integrate fixed * speed up * remove extra code * raycast fix, but still not work * raycast fix * HT refactoring: constants * HT refactoring: calc_hash() * HT refactoring: methods set shortened * no typedef VolumeIndex * fix a bug in CPU version * VolumeIndex * identation * HashTSDF refactoring: a lot of things * less TODOs * lastVisibleIndex dropped from HT * HT refactor: find -> findRow * interpolate & getNormal small hash: no queried * totalVolUnits, indexes -> volumeUnitIndices, better iteration * raycast artifacts fixed * interpolation in getNormal is on * minors * findRow() refactored * volStrides, lastVolIndex, volDims, neighbourCoords * normals, vectorization * interpolation in getNormalVoxel() * no 16*16*16, use volumeUnitResolution instead * resolution, stride... * raycast: cur idx, etc. * CPU debugging code removed * volUnitsData moved to OpenCL memory * raycast: no copy * allocate accelerated a bit * hash_tsdf.cl: pointers fixed * allVol2cam, poses moved to kernel; rowRange for volUnitsData init * TSDF voxel: constructor; row range fixed * rowRange * pixNorms fix + minors * depth is now UMat * markActive is done on GPU, lastVisibleIndices and isActiveFlags moved to GPU * CL: minor * volumeUnitIndices -> GPU * ToyHashMap instead of HT, volumeUnitIndices removed, lastVolIndex removed, + a lot of debugging code * warning about local pix capacity * CPU allocation: find in global HT first * ToyHashMap: -> tsdf_functions.hpp * debugging code + to be removed * ptr -> at * volumeUnitResolution is limited to a power of 2 * rename ToyHashMap to ToyHashSet, hashMap to hashTable * minor * getNormalVoxel .cl: no float conversions * getNormalVoxel does not need voxelSizeInv anymore; orig and dir pre-scaled to get rid of extra multiplication * minor fix * linux critical bug fix * docs fix * mac warning fix * remove extra test code * linux warning fix * remove comments * capacity = 2048 * capacity = 1024 * hashtables fixes * minor code removement * change pixNorm calculation * remove buff_lvl and neighboorCoords; rename degree * move volStrides to HashTSDFVolume * HashTSDFVolumeGPU constructor fix * move preCalculatePixNormsGPU to tsdf_functions * minor code removement * replace copyto() with getUMat() * remove debug code * replace copyTo with getUmat again * replace types in cl * remove NAN_ELEMENT * remove Volume_NODE struct and findRow() * make hash_divisor constant * uncomment camTrans * rename data; remove extra val * fix merge conflict * create empty UMat * cl fix * build error fix * clear HashTSDFVolumeGPU() * use constuctor delegation at HashTSDFVolumeCPU * remove cam2volTransGPU * add minor fix Co-authored-by: Saratovtsev <[email protected]> Co-authored-by: Rostislav Vasilikhin <[email protected]>
1 parent 4e85f8c commit 7ede658

14 files changed

+2046
-257
lines changed

modules/rgbd/samples/large_kinfu_demo.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ int main(int argc, char** argv)
127127
// These params can be different for each depth sensor
128128
ds->updateParams(*params);
129129

130-
// Disabled until there is no OpenCL accelerated HashTSDF is available
131-
cv::setUseOptimized(false);
130+
cv::setUseOptimized(true);
132131

133132
if (!idle)
134133
largeKinfu = LargeKinfu::create(params);

modules/rgbd/src/hash_tsdf.cpp

+1,042-71
Large diffs are not rendered by default.

modules/rgbd/src/hash_tsdf.hpp

+10-92
Original file line numberDiff line numberDiff line change
@@ -26,108 +26,26 @@ class HashTSDFVolume : public Volume
2626

2727
virtual ~HashTSDFVolume() = default;
2828

29+
virtual int getVisibleBlocks(int currFrameId, int frameThreshold) const = 0;
30+
virtual size_t getTotalVolumeUnits() const = 0;
31+
2932
public:
3033
int maxWeight;
3134
float truncDist;
3235
float truncateThreshold;
3336
int volumeUnitResolution;
37+
int volumeUnitDegree;
3438
float volumeUnitSize;
3539
bool zFirstMemOrder;
40+
Vec4i volStrides;
3641
};
3742

38-
//! Spatial hashing
39-
struct tsdf_hash
40-
{
41-
size_t operator()(const Vec3i& x) const noexcept
42-
{
43-
size_t seed = 0;
44-
constexpr uint32_t GOLDEN_RATIO = 0x9e3779b9;
45-
for (uint16_t i = 0; i < 3; i++)
46-
{
47-
seed ^= std::hash<int>()(x[i]) + GOLDEN_RATIO + (seed << 6) + (seed >> 2);
48-
}
49-
return seed;
50-
}
51-
};
52-
53-
typedef unsigned int VolumeIndex;
54-
struct VolumeUnit
55-
{
56-
cv::Vec3i coord;
57-
VolumeIndex index;
58-
cv::Matx44f pose;
59-
int lastVisibleIndex = 0;
60-
bool isActive;
61-
};
62-
63-
typedef std::unordered_set<cv::Vec3i, tsdf_hash> VolumeUnitIndexSet;
64-
typedef std::unordered_map<cv::Vec3i, VolumeUnit, tsdf_hash> VolumeUnitIndexes;
65-
66-
class HashTSDFVolumeCPU : public HashTSDFVolume
67-
{
68-
public:
69-
// dimension in voxels, size in meters
70-
HashTSDFVolumeCPU(float _voxelSize, const Matx44f& _pose, float _raycastStepFactor, float _truncDist, int _maxWeight,
71-
float _truncateThreshold, int _volumeUnitRes, bool zFirstMemOrder = true);
72-
73-
HashTSDFVolumeCPU(const VolumeParams& _volumeParams, bool zFirstMemOrder = true);
74-
75-
void integrate(InputArray _depth, float depthFactor, const Matx44f& cameraPose, const kinfu::Intr& intrinsics,
76-
const int frameId = 0) override;
77-
void raycast(const Matx44f& cameraPose, const kinfu::Intr& intrinsics, const Size& frameSize, OutputArray points,
78-
OutputArray normals) const override;
79-
80-
void fetchNormals(InputArray points, OutputArray _normals) const override;
81-
void fetchPointsNormals(OutputArray points, OutputArray normals) const override;
82-
83-
void reset() override;
84-
size_t getTotalVolumeUnits() const { return volumeUnits.size(); }
85-
int getVisibleBlocks(int currFrameId, int frameThreshold) const;
86-
87-
//! Return the voxel given the voxel index in the universal volume (1 unit = 1 voxel_length)
88-
TsdfVoxel at(const Vec3i& volumeIdx) const;
89-
90-
//! Return the voxel given the point in volume coordinate system i.e., (metric scale 1 unit =
91-
//! 1m)
92-
virtual TsdfVoxel at(const cv::Point3f& point) const;
93-
virtual TsdfVoxel _at(const cv::Vec3i& volumeIdx, VolumeIndex indx) const;
94-
95-
TsdfVoxel atVolumeUnit(const Vec3i& point, const Vec3i& volumeUnitIdx, VolumeUnitIndexes::const_iterator it) const;
96-
97-
98-
float interpolateVoxelPoint(const Point3f& point) const;
99-
float interpolateVoxel(const cv::Point3f& point) const;
100-
Point3f getNormalVoxel(const cv::Point3f& p) const;
101-
102-
//! Utility functions for coordinate transformations
103-
Vec3i volumeToVolumeUnitIdx(const Point3f& point) const;
104-
Point3f volumeUnitIdxToVolume(const Vec3i& volumeUnitIdx) const;
105-
106-
Point3f voxelCoordToVolume(const Vec3i& voxelIdx) const;
107-
Vec3i volumeToVoxelCoord(const Point3f& point) const;
108-
109-
public:
110-
Vec4i volStrides;
111-
Vec6f frameParams;
112-
Mat pixNorms;
113-
VolumeUnitIndexes volumeUnits;
114-
cv::Mat volUnitsData;
115-
VolumeIndex lastVolIndex;
116-
};
117-
118-
template<typename T>
119-
Ptr<HashTSDFVolume> makeHashTSDFVolume(const VolumeParams& _volumeParams)
120-
{
121-
return makePtr<T>(_volumeParams);
122-
}
123-
124-
template<typename T>
43+
//template<typename T>
44+
Ptr<HashTSDFVolume> makeHashTSDFVolume(const VolumeParams& _volumeParams);
45+
//template<typename T>
12546
Ptr<HashTSDFVolume> makeHashTSDFVolume(float _voxelSize, Matx44f _pose, float _raycastStepFactor, float _truncDist,
126-
int _maxWeight, float truncateThreshold, int volumeUnitResolution = 16)
127-
{
128-
return makePtr<T>(_voxelSize, _pose, _raycastStepFactor, _truncDist, _maxWeight, truncateThreshold,
129-
volumeUnitResolution);
130-
}
47+
int _maxWeight, float truncateThreshold, int volumeUnitResolution = 16);
48+
13149
} // namespace kinfu
13250
} // namespace cv
13351
#endif

modules/rgbd/src/large_kinfu.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -316,21 +316,21 @@ template<typename MatType>
316316
void LargeKinfuImpl<MatType>::getCloud(OutputArray p, OutputArray n) const
317317
{
318318
auto currSubmap = submapMgr->getCurrentSubmap();
319-
currSubmap->volume.fetchPointsNormals(p, n);
319+
currSubmap->volume->fetchPointsNormals(p, n);
320320
}
321321

322322
template<typename MatType>
323323
void LargeKinfuImpl<MatType>::getPoints(OutputArray points) const
324324
{
325325
auto currSubmap = submapMgr->getCurrentSubmap();
326-
currSubmap->volume.fetchPointsNormals(points, noArray());
326+
currSubmap->volume->fetchPointsNormals(points, noArray());
327327
}
328328

329329
template<typename MatType>
330330
void LargeKinfuImpl<MatType>::getNormals(InputArray points, OutputArray normals) const
331331
{
332332
auto currSubmap = submapMgr->getCurrentSubmap();
333-
currSubmap->volume.fetchNormals(points, normals);
333+
currSubmap->volume->fetchNormals(points, normals);
334334
}
335335

336336
// importing class

0 commit comments

Comments
 (0)