Skip to content

New HashTSDF implementation #2698

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 54 commits into from
Oct 19, 2020

Conversation

DumDereDum
Copy link
Member

@DumDereDum DumDereDum commented Oct 6, 2020

This PR changes

  • Fixes memory leak caused by multiple pixNorm for each volume unit
  • Uses common buffer for voxel data making data allocation faster
  • Common pieces of code between TSDF and HashTSDF moved to tsdf_functions.cpp/hpp
  • A lot of minor changes

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake


vu.pose = subvolumePose;
volumes.push_back(Mat(1, volumeDims.x * volumeDims.y * volumeDims.z, rawType<TsdfVoxel>()));
vu.index = HashS; HashS++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

push_back works here but one of the purposes of this PR is to make a code that'd be easy to port to OpenCL, while OpenCL has no such push_back ability: its buffers have fixed size.
What should be done instead:

  • volumes should be preallocated to some size
  • when this buffer is exhausted, a reallocation should be done to a new buffer of size*sizeFactor where sizeFactor=2.0 for example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, but not the same

cv::Vec3i coord;
volumeIndex index;
cv::Matx44f pose;
Vec4i volDims;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all volume units have the same size, we shouldn't keep volDims for each of them.
Another question is should we keep pose for each of them since it can be calculated from coord and volume pose - I think, we shouldn't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

volDims - done

@@ -33,8 +33,10 @@ class HashTSDFVolume : public Volume
int volumeUnitResolution;
float volumeUnitSize;
bool zFirstMemOrder;
Point3i volumeDims;
Vec4i volDims;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename one of them (or both?) to be more self-descriptive
For example, volDims to volStrides

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
return pixNorm;
}

// use depth instead of distance (optimization)
void TSDFVolumeCPU::integrate(InputArray _depth, float depthFactor, const cv::Matx44f& cameraPose,
const Intr& intrinsics)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since integrateVolumeUnit is in tsdf_functions, the TSDF integration should be rewritten using it. SIMD version is to be taken too.
If this amount of work is too big for that PR, then it's better to postpone it till next PR.

cv::Matx44f _pose, Point3i volResolution, Vec4i volStrides,
InputArray _depth, float depthFactor, const cv::Matx44f& cameraPose,
const cv::kinfu::Intr& intrinsics, InputArray _pixNorms, InputArray _volume)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not forget SIMD version of the code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

//! Out of bounds
CV_DbgAssert((volumeIdx[0] >= volResolution.x || volumeIdx[0] < 0) ||
(volumeIdx[1] >= volResolution.y || volumeIdx[1] < 0) ||
(volumeIdx[2] >= volResolution.z || volumeIdx[2] < 0))
Copy link
Contributor

@savuor savuor Oct 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here compilation fails: no such thing as volResolution
Also semicolon ; missed

cv::Vec3i volumeUnitIdx = volumeToVolumeUnitIdx(point);
VolumeUnitIndexes::const_iterator it = volumeUnits.find(volumeUnitIdx);

CV_DbgAssert (it == volumeUnits.end())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same

Ptr<TSDFVolumeCPU> volumeUnit = std::dynamic_pointer_cast<TSDFVolumeCPU>(it->second.pVolume);
VolumeUnitIndexes::const_iterator it = volumeUnits.find(volumeUnitIdx);

CV_DbgAssert (it == volumeUnits.end())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same

@savuor
Copy link
Contributor

savuor commented Oct 16, 2020

👍

@savuor savuor self-assigned this Oct 16, 2020
@alalek alalek merged commit 0b5ded4 into opencv:master Oct 19, 2020
@alalek alalek mentioned this pull request Nov 27, 2020
@DumDereDum DumDereDum deleted the new_HashTSDF_implementation branch April 19, 2021 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants