tsdf_volume.cpp
Go to the documentation of this file.
1 #include <kfusion/precomp.hpp>
2 
3 using namespace kfusion;
4 using namespace kfusion::cuda;
5 
8 
10 { throw "Not implemented"; }
11 
13 { throw "Not implemented"; }
14 
17 
18 kfusion::cuda::TsdfVolume::TsdfVolume(const Vec3i& dims) : data_(), trunc_dist_(0.03f), max_weight_(128), dims_(dims),
19  size_(Vec3f::all(3.f)), pose_(Affine3f::Identity()), gradient_delta_factor_(0.75f), raycast_step_factor_(0.75f)
20 { create(dims_); }
21 
23 
25 {
26  dims_ = dims;
27  int voxels_number = dims_[0] * dims_[1] * dims_[2];
28  data_.create(voxels_number * sizeof(int));
30  clear();
31 }
32 
34 { return dims_; }
35 
37 {
38  return Vec3f(size_[0]/dims_[0], size_[1]/dims_[1], size_[2]/dims_[2]);
39 }
40 
44 
46 { size_ = size; setTruncDist(trunc_dist_); }
47 
49 
51 {
52  Vec3f vsz = getVoxelSize();
53  float max_coeff = std::max<float>(std::max<float>(vsz[0], vsz[1]), vsz[2]);
54  trunc_dist_ = std::max (distance, 2.1f * max_coeff);
55 }
56 
57 ushort2* kfusion::cuda::TsdfVolume::getCoord(int x, int y, int z, int dim_x, int dim_y)
58 {
59  return data_.ptr<ushort2>() + x + y*dim_x + z*dim_y*dim_x;
60 }
61 
65 void kfusion::cuda::TsdfVolume::setPose(const Affine3f& pose) { pose_ = pose; }
71 void kfusion::cuda::TsdfVolume::applyAffine(const Affine3f& affine) { pose_ = affine * pose_; }
72 
74 {
77 
78  device::TsdfVolume volume(data_.ptr<ushort2>(), dims, vsz, trunc_dist_, max_weight_);
79  device::clear_volume(volume);
80 }
81 
82 void kfusion::cuda::TsdfVolume::clearSlice(const kfusion::tsdf_buffer* buffer, const Vec3i offset) const
83 {
86 
87  device::Vec3i offset_c;
88  offset_c.x = offset[0];
89  offset_c.y = offset[1];
90  offset_c.z = offset[2];
91 
92  device::TsdfVolume volume((ushort2*)data_.ptr<ushort2>(), dims, vsz, trunc_dist_, max_weight_);
93  device::clearTSDFSlice(volume, buffer, offset_c);
94 }
95 
96 void kfusion::cuda::TsdfVolume::integrate(const Dists& dists, tsdf_buffer& buffer, const Affine3f& camera_pose, const Intr& intr)
97 {
98  Affine3f vol2cam = camera_pose.inv() * pose_;
99 
100  device::Projector proj(intr.fx, intr.fy, intr.cx, intr.cy);
101 
104  device::Aff3f aff = device_cast<device::Aff3f>(vol2cam);
105 
106  device::TsdfVolume volume(data_.ptr<ushort2>(), dims, vsz, trunc_dist_, max_weight_);
107  device::integrate(dists, volume, buffer, aff, proj);
108 }
109 
110 void kfusion::cuda::TsdfVolume::raycast(const Affine3f& camera_pose, tsdf_buffer& buffer, const Intr& intr, Depth& depth, Normals& normals)
111 {
113 
114  Affine3f cam2vol = pose_.inv() * camera_pose;
115 
116  device::Aff3f aff = device_cast<device::Aff3f>(cam2vol);
117  device::Mat3f Rinv = device_cast<device::Mat3f>(cam2vol.rotation().inv(cv::DECOMP_SVD));
118 
119  device::Reprojector reproj(intr.fx, intr.fy, intr.cx, intr.cy);
120 
123 
124  device::TsdfVolume volume(data_.ptr<ushort2>(), dims, vsz, trunc_dist_, max_weight_);
125  device::raycast(volume, buffer, aff, Rinv, reproj, depth, n, raycast_step_factor_, gradient_delta_factor_);
126 
127 }
128 
129 void kfusion::cuda::TsdfVolume::raycast(const Affine3f& camera_pose, tsdf_buffer& buffer, const Intr& intr, Cloud& points, Normals& normals)
130 {
131  device::Normals& n = (device::Normals&)normals;
132  device::Points& p = (device::Points&)points;
133 
134  Affine3f cam2vol = pose_.inv() * camera_pose;
135 
136  device::Aff3f aff = device_cast<device::Aff3f>(cam2vol);
137  device::Mat3f Rinv = device_cast<device::Mat3f>(cam2vol.rotation().inv(cv::DECOMP_SVD));
138 
139  device::Reprojector reproj(intr.fx, intr.fy, intr.cx, intr.cy);
140 
143 
144  device::TsdfVolume volume(data_.ptr<ushort2>(), dims, vsz, trunc_dist_, max_weight_);
145  device::raycast(volume, buffer, aff, Rinv, reproj, p, n, raycast_step_factor_, gradient_delta_factor_);
146 }
147 
149 {
150  enum { DEFAULT_CLOUD_BUFFER_SIZE = 10 * 1000 * 1000 };
151 
152  if (cloud_buffer.empty ())
153  cloud_buffer.create (DEFAULT_CLOUD_BUFFER_SIZE);
154 
156 
160 
161  device::TsdfVolume volume((ushort2*)data_.ptr<ushort2>(), dims, vsz, trunc_dist_, max_weight_);
162  size_t size = extractCloud(volume, buffer, aff, b);
163 
164  return DeviceArray<Point>((Point*)cloud_buffer.ptr(), size);
165 }
166 
168 {
169  normals.create(cloud.size());
171 
175  device::Mat3f Rinv = device_cast<device::Mat3f>(pose_.rotation().inv(cv::DECOMP_SVD));
176 
177  device::TsdfVolume volume((ushort2*)data_.ptr<ushort2>(), dims, vsz, trunc_dist_, max_weight_);
178  device::extractNormals(volume, buffer, c, aff, Rinv, gradient_delta_factor_, (float4*)normals.ptr());
179 }
180 
182 
184 kfusion::cuda::TsdfVolume::fetchSliceAsCloud (DeviceArray<Point>& cloud_buffer, const kfusion::tsdf_buffer* buffer, const Vec3i minBounds, const Vec3i maxBounds, const Vec3i globalShift ) const
185 {
186 
187  enum { DEFAULT_CLOUD_BUFFER_SIZE = 10 * 1000 * 1000 };
188  if (cloud_buffer.empty ())
189  cloud_buffer.create (DEFAULT_CLOUD_BUFFER_SIZE);
190 
192 
194  device::Vec3i deviceGlobalShift;
195  deviceGlobalShift.x = globalShift[0];
196  deviceGlobalShift.y = globalShift[1];
197  deviceGlobalShift.z = globalShift[2];
198 
199  device::Vec3i minBounds_c;
200  minBounds_c.x = minBounds[0];
201  minBounds_c.y = minBounds[1];
202  minBounds_c.z = minBounds[2];
203 
204  device::Vec3i maxBounds_c;
205  maxBounds_c.x = maxBounds[0];
206  maxBounds_c.y = maxBounds[1];
207  maxBounds_c.z = maxBounds[2];
208 
211 
212  device::TsdfVolume volume((ushort2*)data_.ptr<ushort2>(), dims, vsz, trunc_dist_, max_weight_);
213 
214  size_t size = extractSliceAsCloud (volume, buffer, minBounds_c, maxBounds_c, deviceGlobalShift, aff, b);
215 
216  return DeviceArray<Point>((Point*)cloud_buffer.ptr(), size);
217 }
static float half2float(half value)
TsdfVolume::Entry.
Definition: tsdf_volume.cpp:9
void create(size_t size)
Allocates internal buffer in GPU memory. If internal buffer was created before the function recreates...
void clearTSDFSlice(const TsdfVolume &volume, const kfusion::tsdf_buffer *buffer, const Vec3i offset)
cv::Vec3f Vec3f
Definition: types.hpp:16
virtual void integrate(const Dists &dists, tsdf_buffer &buffer, const Affine3f &camera_pose, const Intr &intr)
Definition: tsdf_volume.cpp:96
Structure to handle buffer addresses.
Definition: tsdf_buffer.h:48
void swap(DeviceMemory &other_arg)
Performs swap of data pointed with another device memory.
void setSize(const Vec3f &size)
Definition: tsdf_volume.cpp:45
float getRaycastStepFactor() const
Definition: tsdf_volume.cpp:66
T * ptr()
Returns pointer for internal buffer in GPU memory.
void swap(CudaData &data)
Definition: tsdf_volume.cpp:70
const CudaData data() const
Definition: tsdf_volume.cpp:41
size_t size() const
Returns size in elements.
cv::Affine3f Affine3f
Definition: types.hpp:18
bool empty() const
Returns true if unallocated otherwise false.
float fx
Definition: types.hpp:22
void raycast(const TsdfVolume &volume, tsdf_buffer &buffer, const Aff3f &aff, const Mat3f &Rinv, const Reprojector &reproj, Depth &depth, Normals &normals, float step_factor, float delta_factor)
void integrate(const Dists &depth, TsdfVolume &volume, tsdf_buffer &buffer, const Aff3f &aff, const Projector &proj)
TsdfVolume(const cv::Vec3i &dims)
TsdfVolume.
Definition: tsdf_volume.cpp:18
size_t extractCloud(const TsdfVolume &volume, const tsdf_buffer &buffer, const Aff3f &aff, PtrSz< Point > output)
void clearSlice(const kfusion::tsdf_buffer *buffer, const Vec3i offset) const
Definition: tsdf_volume.cpp:82
size_t extractSliceAsCloud(const TsdfVolume &volume, const kfusion::tsdf_buffer *buffer, const Vec3i minBounds, const Vec3i maxBounds, const Vec3i globalShift, const Aff3f &aff, PtrSz< Point > output)
float getGradientDeltaFactor() const
Definition: tsdf_volume.cpp:68
void setPose(const Affine3f &pose)
Definition: tsdf_volume.cpp:65
cv::Vec3i Vec3i
Definition: types.hpp:17
void setTruncDist(float distance)
Definition: tsdf_volume.cpp:50
void setGradientDeltaFactor(float factor)
Definition: tsdf_volume.cpp:69
T * ptr()
Returns pointer for internal buffer in GPU memory.
void create(const Vec3i &dims)
Definition: tsdf_volume.cpp:24
float cx
Definition: types.hpp:22
D device_cast(const S &source)
Definition: precomp.hpp:16
Affine3f getPose() const
Definition: tsdf_volume.cpp:64
virtual void raycast(const Affine3f &camera_pose, tsdf_buffer &buffer, const Intr &intr, Depth &depth, Normals &normals)
SharedPointer p
DeviceArray< Point > fetchCloud(DeviceArray< Point > &cloud_buffer, const tsdf_buffer &buffer) const
void create(size_t sizeBytes_arg)
Allocates internal buffer in GPU memory. If internal buffer was created before the function recreates...
static half float2half(float value)
Definition: tsdf_volume.cpp:12
float fy
Definition: types.hpp:22
void extractNormals(const TsdfVolume &volume, const tsdf_buffer &buffer, const PtrSz< Point > &points, const Aff3f &aff, const Mat3f &Rinv, float gradient_delta_factor, float4 *output)
ushort2 * getCoord(int x, int y, int z, int dim_x, int dim_y)
Definition: tsdf_volume.cpp:57
void setMaxWeight(int weight)
Definition: tsdf_volume.cpp:63
virtual void applyAffine(const Affine3f &affine)
Definition: tsdf_volume.cpp:71
Vec3f getVoxelSize() const
Definition: tsdf_volume.cpp:36
float cy
Definition: types.hpp:22
DeviceArray< Point > fetchSliceAsCloud(DeviceArray< Point > &cloud_buffer, const kfusion::tsdf_buffer *buffer, const Vec3i minBounds, const Vec3i maxBounds, const Vec3i globalShift) const
Generates cloud using GPU in connected6 mode only.
Utility.
Definition: capture.hpp:8
void clear_volume(TsdfVolume volume)
float getTruncDist() const
Definition: tsdf_volume.cpp:48
void setRaycastStepFactor(float factor)
Definition: tsdf_volume.cpp:67
void fetchNormals(const DeviceArray< Point > &cloud, const tsdf_buffer &buffer, DeviceArray< Normal > &normals) const


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:09