Skip to content

New HashTSDFVolumeGPU class #2734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 221 commits into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
221 commits
Select commit Hold shift + click to select a range
1a48772
create new class
DumDereDum Oct 30, 2020
8f2b15f
rewrite makeHashTSDFVolume
DumDereDum Nov 2, 2020
003b80c
it builds
Nov 2, 2020
afe9448
minor fi
Nov 2, 2020
1acff75
raycast - done
Nov 2, 2020
6ba4dba
all code builds
Nov 2, 2020
be30c1a
Docs fix
Nov 2, 2020
868955c
–fetch_normals fix
Nov 3, 2020
ad795f4
I want it to work
Nov 4, 2020
8878cf4
minor fix
Nov 4, 2020
fb51216
valid points checking passed
Nov 4, 2020
c15ea28
it works!
Nov 5, 2020
057c451
minor fixes
Nov 5, 2020
b8b88be
warning fix
Nov 5, 2020
d35ce44
last replacements
Nov 5, 2020
191c2e4
warning fix
Nov 5, 2020
8e14904
create hash_tsdf.cl
Nov 6, 2020
0603845
add preCalculationPixNormGPU
Nov 6, 2020
eb3cf3e
add integrateVolumeUnitGPU
Nov 6, 2020
a4894ba
Docs fix
Nov 6, 2020
db6f867
create simple volume table
Nov 9, 2020
adc0d21
add functionality to the table
Nov 10, 2020
6ce9add
add new functions
Nov 10, 2020
9f30f12
create new hash table implementation
Nov 10, 2020
6dae10d
minor fix
Nov 11, 2020
eaed8d2
create new hash tsdf implementaton
Nov 11, 2020
cd2c3e2
add expand feature
Nov 12, 2020
b2f64c8
minorfix
Nov 12, 2020
d00fe0f
error fix
Nov 13, 2020
8ccf21d
it builds
Nov 13, 2020
b75cdf6
new hash table work
Nov 16, 2020
ad61d80
Docs fix
Nov 16, 2020
ca82124
warnings fix
Nov 16, 2020
c19ef2e
warning fix 1
Nov 16, 2020
f87e0d3
warning fix 2
Nov 16, 2020
a3254ef
warning fix
Nov 17, 2020
b6af0a0
remove extra coments
Nov 17, 2020
40f3f11
create new function integrateAllVolumeUnitsGPU
Nov 17, 2020
3dcfd5a
add hash table function
Nov 17, 2020
f2bea7c
extend kernel signature
Nov 18, 2020
0b29831
minor fix
Nov 18, 2020
e3bd423
extent Volume_NODE signature and add functionality
Nov 19, 2020
ce19cf6
kernel args fix
Nov 20, 2020
386396c
smth
Nov 20, 2020
036c0db
minor fix
Nov 23, 2020
06a5013
kernal args fix
Nov 23, 2020
abfb7c7
try to fix reading bug
Nov 23, 2020
ad0019e
hash table fix
Nov 24, 2020
a363277
add totalVolUnits feature
Nov 24, 2020
7db1817
it builds
Nov 25, 2020
168f190
minor fix
Nov 26, 2020
a4d20a8
integrate fix
Nov 26, 2020
1ace155
fix work with table
Nov 27, 2020
2089684
minor table fi
Nov 30, 2020
66c09bd
I am stumped
Nov 30, 2020
a1aa11a
try to fix
Nov 30, 2020
c43339e
add checking to find error
Dec 1, 2020
230ac40
add copyto
Dec 1, 2020
59e6da4
vol2cam fix
Dec 2, 2020
9015bef
try to fix
Dec 2, 2020
fc0ce51
we are the champions
Dec 2, 2020
33fa2f9
Merge branch 'master' of https://github.com/opencv/opencv_contrib int…
Dec 3, 2020
307d5ba
remove some comments
Dec 3, 2020
4fd73d3
remove last comments
Dec 3, 2020
0260138
docs fix
Dec 3, 2020
027f051
warning fix
Dec 3, 2020
5213c78
warning fix 1
Dec 3, 2020
06d2b26
warning fix 2
Dec 3, 2020
85296cc
create raycast kernel
Dec 4, 2020
df69ed7
extend raycast gpu signature
Dec 4, 2020
5d53025
minor fix
Dec 8, 2020
b5dc584
integrate all volUnits - done
Dec 9, 2020
edf0ad4
docs fix
Dec 9, 2020
2143ec6
warning fix
Dec 9, 2020
7cfc39c
extend raycast signature
Dec 10, 2020
ea528bb
raycast work
Dec 11, 2020
0a9f59f
bug fix
Dec 11, 2020
a590ae3
calc point4 fix
Dec 14, 2020
1f5a5e6
minor fix
Dec 14, 2020
427667c
add _at function
Dec 16, 2020
fcaaf2c
raycast done, but work incorrect
Dec 16, 2020
57f8614
fin dug
Dec 17, 2020
e1fd7c8
bug fix
Dec 17, 2020
091fb86
getNorm works correctly
Dec 18, 2020
69a5034
minor fix
Dec 21, 2020
5b0d59c
raycast - done
Dec 22, 2020
fd5384d
minor fixes
Dec 23, 2020
61e2d4b
docs fix
Dec 23, 2020
069e882
warning fix
Dec 23, 2020
3fc630f
minor fix
Dec 23, 2020
85e7dec
minor fix
Dec 24, 2020
9a243a4
warning fix
Dec 24, 2020
ca67f0a
warning fix 1
Dec 24, 2020
693bedc
win warning fix
Dec 24, 2020
b3d0567
mac fix
Dec 24, 2020
5388f75
win debug fix
Dec 25, 2020
d01c7ce
mac cl warning fix
Dec 25, 2020
b296279
allCam2vol fix
Dec 28, 2020
db1a876
rename num with bufferNum
Dec 28, 2020
85dcd2b
remove nums hardcode
Dec 28, 2020
b5e86e8
minor fix
Dec 28, 2020
0c62905
change logic of calculating hash
Dec 28, 2020
16c0840
replace float16 by vload16
Dec 28, 2020
50358d4
replace true with false in zFirstMemOrder
Dec 28, 2020
ef2f417
poses fix
Dec 28, 2020
3cf1e29
add new tests
Dec 29, 2020
4cb3a38
debug print
Dec 29, 2020
6a4c76d
debug print 1
Dec 29, 2020
69582fb
replace [] with .s
Dec 29, 2020
12db52c
minor fix
Dec 29, 2020
b0177e2
minor fix 1
Dec 29, 2020
3b05163
remove print
Dec 30, 2020
9f1e8fb
hashtsdf work fix
Dec 31, 2020
6c6405d
hashtable fix
Dec 31, 2020
4ca4dd8
resrite hashtasble update
Jan 12, 2021
781bedd
test_tsdf fix
Jan 12, 2021
9abbfd2
override warning fix
Jan 12, 2021
3166fbb
docs fix
Jan 12, 2021
5cfc78a
mutex fix
Jan 13, 2021
2209af8
setUseOptimizes replace false with true
Jan 13, 2021
0a064b9
minor fix
Jan 14, 2021
ba8169a
merge with master
Jan 18, 2021
3718467
Merge branch 'master' of https://github.com/opencv/opencv_contrib int…
Jan 19, 2021
2468b13
all minor fixes
Jan 19, 2021
c076b89
add CPU code for debug
Jan 19, 2021
2b8cf75
settings set
Jan 19, 2021
0c38e8e
move code from hpp to cpp
Jan 19, 2021
deb94c5
minor opencl fix
Jan 19, 2021
3ea8a72
fid bug
Jan 19, 2021
42494d3
coment fix
Jan 19, 2021
164993b
minor fix
Jan 20, 2021
265b742
bug fix
Jan 20, 2021
e469b2f
integrate fixed
Jan 21, 2021
1da1bb4
speed up
Jan 21, 2021
e8da147
remove extra code
Jan 21, 2021
dfcddd2
raycast fix, but still not work
Jan 22, 2021
5cb7271
raycast fix
Jan 22, 2021
1eeefac
HT refactoring: constants
savuor Jan 25, 2021
da6005d
HT refactoring: calc_hash()
savuor Jan 25, 2021
298701f
HT refactoring: methods set shortened
savuor Jan 25, 2021
d23514e
no typedef VolumeIndex
savuor Jan 25, 2021
18471c9
fix a bug in CPU version
savuor Jan 25, 2021
b177f7e
VolumeIndex
savuor Jan 25, 2021
af1f2a2
identation
savuor Jan 25, 2021
9e1a6c9
HashTSDF refactoring: a lot of things
savuor Jan 25, 2021
5724d2f
isActive dropped from volume node
savuor Jan 25, 2021
a1fddd2
less TODOs
savuor Jan 25, 2021
e6a69fb
lastVisibleIndex dropped from HT
savuor Jan 26, 2021
8652e74
HT refactor: find -> findRow
savuor Jan 26, 2021
6b8ef0a
interpolate & getNormal small hash: no queried
savuor Jan 26, 2021
012c137
totalVolUnits, indexes -> volumeUnitIndices, better iteration
savuor Jan 26, 2021
eb828c3
raycast artifacts fixed
savuor Jan 26, 2021
1114c02
interpolation in getNormal is on
savuor Jan 26, 2021
ce92dd6
minors
savuor Jan 26, 2021
4bec743
findRow() refactored
savuor Jan 26, 2021
9dee84b
volStrides, lastVolIndex, volDims, neighbourCoords
savuor Jan 26, 2021
3bc21c2
normals, vectorization
savuor Jan 26, 2021
b3cbc9c
interpolation in getNormalVoxel()
savuor Jan 27, 2021
f9d9a53
no 16*16*16, use volumeUnitResolution instead
savuor Jan 27, 2021
f000fd1
resolution, stride...
savuor Jan 27, 2021
a7491cd
raycast: cur idx, etc.
savuor Jan 27, 2021
061793d
CPU debugging code removed
savuor Jan 27, 2021
b284597
volUnitsData moved to OpenCL memory
savuor Jan 27, 2021
2b5efd0
raycast: no copy
savuor Jan 27, 2021
7e0df4e
allocate accelerated a bit
savuor Jan 27, 2021
4cd30ef
hash_tsdf.cl: pointers fixed
savuor Jan 28, 2021
6ed14d7
allVol2cam, poses moved to kernel; rowRange for volUnitsData init
savuor Jan 28, 2021
4deeacf
TSDF voxel: constructor; row range fixed
savuor Jan 28, 2021
bb1b64a
rowRange
savuor Jan 28, 2021
488a66a
pixNorms fix + minors
savuor Jan 28, 2021
ce76aef
depth is now UMat
savuor Jan 28, 2021
0ace4c2
markActive is done on GPU, lastVisibleIndices and isActiveFlags moved…
savuor Jan 28, 2021
109b675
CL: minor
savuor Jan 29, 2021
e7bef78
volumeUnitIndices -> GPU
savuor Jan 31, 2021
73457a1
HT: small fixes
savuor Feb 4, 2021
8c7d77b
ToyHashMap instead of HT, volumeUnitIndices removed, lastVolIndex rem…
savuor Feb 4, 2021
a4cc40d
warning about local pix capacity
savuor Feb 4, 2021
4e3df85
CPU allocation: find in global HT first
savuor Feb 8, 2021
3999088
ToyHashMap: -> tsdf_functions.hpp
savuor Feb 8, 2021
b1b00b1
debugging code + to be removed
savuor Feb 8, 2021
f5c0e17
ptr -> at
savuor Feb 8, 2021
1a65ad8
volumeUnitResolution is limited to a power of 2
savuor Feb 9, 2021
97cc435
rename ToyHashMap to ToyHashSet, hashMap to hashTable
savuor Feb 9, 2021
0a168b6
minor
savuor Feb 9, 2021
53f91d2
getNormalVoxel .cl: no float conversions
savuor Feb 10, 2021
7a7f04e
getNormalVoxel does not need voxelSizeInv anymore; orig and dir pre-s…
savuor Feb 10, 2021
789e0c9
minor fix
DumDereDum Feb 11, 2021
c79611b
linux critical bug fix
DumDereDum Feb 11, 2021
594a768
docs fix
Feb 11, 2021
9e65354
mac warning fix
Feb 11, 2021
7db345d
remove extra test code
Feb 11, 2021
9b7a0f2
linux warning fix
Feb 11, 2021
a39ee06
remove comments
Feb 13, 2021
5f42078
capacity = 2048
Feb 13, 2021
6174923
capacity = 1024
Feb 13, 2021
0943708
hashtables fixes
Feb 16, 2021
fbc1825
minor code removement
Feb 16, 2021
7d9fda1
change pixNorm calculation
Feb 17, 2021
dfd35e7
remove buff_lvl and neighboorCoords; rename degree
Feb 17, 2021
ec037bd
move volStrides to HashTSDFVolume
Feb 17, 2021
45a1b34
HashTSDFVolumeGPU constructor fix
Feb 17, 2021
b3507d1
move preCalculatePixNormsGPU to tsdf_functions
Feb 17, 2021
22817a1
minor code removement
Feb 17, 2021
b3be2d1
replace copyto() with getUMat()
Feb 17, 2021
5a6e7a4
remove debug code
Feb 17, 2021
41dc901
replace copyTo with getUmat again
Feb 17, 2021
3bbd6ea
replace types in cl
Feb 17, 2021
852fca6
remove NAN_ELEMENT
Feb 17, 2021
bb87cb6
remove Volume_NODE struct and findRow()
Feb 17, 2021
d2bcdb0
make hash_divisor constant
Feb 17, 2021
df7b4e4
uncomment camTrans
Feb 17, 2021
5f8bd0d
rename data; remove extra val
Feb 17, 2021
9f1d46f
tsdf pixNorm fix
Feb 17, 2021
b9891c5
fix merge conflict
Feb 17, 2021
2b3fce7
create empty UMat
Feb 17, 2021
36d15a4
cl fix
Feb 17, 2021
63d516c
build error fix
Feb 18, 2021
ec12ba7
clear HashTSDFVolumeGPU()
Feb 18, 2021
f274e15
use constuctor delegation at HashTSDFVolumeCPU
Feb 18, 2021
dd45b0a
remove cam2volTransGPU
Feb 18, 2021
499047d
add minor fix
Feb 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions modules/rgbd/samples/large_kinfu_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ int main(int argc, char** argv)
// These params can be different for each depth sensor
ds->updateParams(*params);

// Disabled until there is no OpenCL accelerated HashTSDF is available
cv::setUseOptimized(false);
cv::setUseOptimized(true);

if (!idle)
largeKinfu = LargeKinfu::create(params);
Expand Down
1,113 changes: 1,042 additions & 71 deletions modules/rgbd/src/hash_tsdf.cpp

Large diffs are not rendered by default.

102 changes: 10 additions & 92 deletions modules/rgbd/src/hash_tsdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,108 +26,26 @@ class HashTSDFVolume : public Volume

virtual ~HashTSDFVolume() = default;

virtual int getVisibleBlocks(int currFrameId, int frameThreshold) const = 0;
virtual size_t getTotalVolumeUnits() const = 0;

public:
int maxWeight;
float truncDist;
float truncateThreshold;
int volumeUnitResolution;
int volumeUnitDegree;
float volumeUnitSize;
bool zFirstMemOrder;
Vec4i volStrides;
};

//! Spatial hashing
struct tsdf_hash
{
size_t operator()(const Vec3i& x) const noexcept
{
size_t seed = 0;
constexpr uint32_t GOLDEN_RATIO = 0x9e3779b9;
for (uint16_t i = 0; i < 3; i++)
{
seed ^= std::hash<int>()(x[i]) + GOLDEN_RATIO + (seed << 6) + (seed >> 2);
}
return seed;
}
};

typedef unsigned int VolumeIndex;
struct VolumeUnit
{
cv::Vec3i coord;
VolumeIndex index;
cv::Matx44f pose;
int lastVisibleIndex = 0;
bool isActive;
};

typedef std::unordered_set<cv::Vec3i, tsdf_hash> VolumeUnitIndexSet;
typedef std::unordered_map<cv::Vec3i, VolumeUnit, tsdf_hash> VolumeUnitIndexes;

class HashTSDFVolumeCPU : public HashTSDFVolume
{
public:
// dimension in voxels, size in meters
HashTSDFVolumeCPU(float _voxelSize, const Matx44f& _pose, float _raycastStepFactor, float _truncDist, int _maxWeight,
float _truncateThreshold, int _volumeUnitRes, bool zFirstMemOrder = true);

HashTSDFVolumeCPU(const VolumeParams& _volumeParams, bool zFirstMemOrder = true);

void integrate(InputArray _depth, float depthFactor, const Matx44f& cameraPose, const kinfu::Intr& intrinsics,
const int frameId = 0) override;
void raycast(const Matx44f& cameraPose, const kinfu::Intr& intrinsics, const Size& frameSize, OutputArray points,
OutputArray normals) const override;

void fetchNormals(InputArray points, OutputArray _normals) const override;
void fetchPointsNormals(OutputArray points, OutputArray normals) const override;

void reset() override;
size_t getTotalVolumeUnits() const { return volumeUnits.size(); }
int getVisibleBlocks(int currFrameId, int frameThreshold) const;

//! Return the voxel given the voxel index in the universal volume (1 unit = 1 voxel_length)
TsdfVoxel at(const Vec3i& volumeIdx) const;

//! Return the voxel given the point in volume coordinate system i.e., (metric scale 1 unit =
//! 1m)
virtual TsdfVoxel at(const cv::Point3f& point) const;
virtual TsdfVoxel _at(const cv::Vec3i& volumeIdx, VolumeIndex indx) const;

TsdfVoxel atVolumeUnit(const Vec3i& point, const Vec3i& volumeUnitIdx, VolumeUnitIndexes::const_iterator it) const;


float interpolateVoxelPoint(const Point3f& point) const;
float interpolateVoxel(const cv::Point3f& point) const;
Point3f getNormalVoxel(const cv::Point3f& p) const;

//! Utility functions for coordinate transformations
Vec3i volumeToVolumeUnitIdx(const Point3f& point) const;
Point3f volumeUnitIdxToVolume(const Vec3i& volumeUnitIdx) const;

Point3f voxelCoordToVolume(const Vec3i& voxelIdx) const;
Vec3i volumeToVoxelCoord(const Point3f& point) const;

public:
Vec4i volStrides;
Vec6f frameParams;
Mat pixNorms;
VolumeUnitIndexes volumeUnits;
cv::Mat volUnitsData;
VolumeIndex lastVolIndex;
};

template<typename T>
Ptr<HashTSDFVolume> makeHashTSDFVolume(const VolumeParams& _volumeParams)
{
return makePtr<T>(_volumeParams);
}

template<typename T>
//template<typename T>
Ptr<HashTSDFVolume> makeHashTSDFVolume(const VolumeParams& _volumeParams);
//template<typename T>
Ptr<HashTSDFVolume> makeHashTSDFVolume(float _voxelSize, Matx44f _pose, float _raycastStepFactor, float _truncDist,
int _maxWeight, float truncateThreshold, int volumeUnitResolution = 16)
{
return makePtr<T>(_voxelSize, _pose, _raycastStepFactor, _truncDist, _maxWeight, truncateThreshold,
volumeUnitResolution);
}
int _maxWeight, float truncateThreshold, int volumeUnitResolution = 16);

} // namespace kinfu
} // namespace cv
#endif
6 changes: 3 additions & 3 deletions modules/rgbd/src/large_kinfu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,21 +316,21 @@ template<typename MatType>
void LargeKinfuImpl<MatType>::getCloud(OutputArray p, OutputArray n) const
{
auto currSubmap = submapMgr->getCurrentSubmap();
currSubmap->volume.fetchPointsNormals(p, n);
currSubmap->volume->fetchPointsNormals(p, n);
}

template<typename MatType>
void LargeKinfuImpl<MatType>::getPoints(OutputArray points) const
{
auto currSubmap = submapMgr->getCurrentSubmap();
currSubmap->volume.fetchPointsNormals(points, noArray());
currSubmap->volume->fetchPointsNormals(points, noArray());
}

template<typename MatType>
void LargeKinfuImpl<MatType>::getNormals(InputArray points, OutputArray normals) const
{
auto currSubmap = submapMgr->getCurrentSubmap();
currSubmap->volume.fetchNormals(points, normals);
currSubmap->volume->fetchNormals(points, normals);
}

// importing class
Expand Down
Loading