20 "Grid8NbVertexInterpRatios";
22 "Grid8NbNormalInterpRatios";
27 : grid_size_(grid_size), device_(device) {
28 ctr_hashmap_ = std::make_shared<core::HashMap>(
37 : grid_size_(grid_size), device_(device) {
38 ctr_hashmap_ = std::make_shared<core::HashMap>(
43 ctr_hashmap_->Insert(keys, values, buf_indices, masks);
57 for (
int nb = 0; nb < 8; ++nb) {
58 int x_sel = (nb & 4) >> 2;
59 int y_sel = (nb & 2) >> 1;
64 keys_nb[nb] = keys + dt;
67 keys_nb = keys_nb.
View({8 * n, 3});
70 vals_nb = vals_nb.
View({8 * n, 3}) * grid_size_;
75 unique_hashset.Insert(keys_nb, buf_indices_unique, masks_unique);
78 ctr_hashmap_->Insert(keys_nb.IndexGet({masks_unique}),
79 vals_nb.IndexGet({masks_unique}), buf_indices, masks);
83 ctr_hashmap_->Reserve(ctr_hashmap_->Size() * 2);
86 ctr_hashmap_->GetActiveIndices(active_buf_indices);
89 core::Tensor active_keys = ctr_hashmap_->GetKeyTensor().IndexGet(
92 std::vector<Eigen::Vector3i> active_keys_vec =
95 std::vector<Eigen::Vector4i> active_keys_indexed(active_keys_vec.size());
96 for (
size_t i = 0; i < active_keys_vec.size(); ++i) {
97 active_keys_indexed[i](0) = active_keys_vec[i](0);
98 active_keys_indexed[i](1) = active_keys_vec[i](1);
99 active_keys_indexed[i](2) = active_keys_vec[i](2);
100 active_keys_indexed[i](3) = i;
103 std::sort(active_keys_indexed.begin(), active_keys_indexed.end(),
105 return (a(2) < b(2)) || (a(2) == b(2) && a(1) < b(1)) ||
106 (a(2) == b(2) && a(1) == b(1) && a(0) < b(0));
109 active_buf_indices[active_keys_indexed[active_keys_indexed.size() /
114 std::tuple<core::Tensor, core::Tensor, core::Tensor>
117 ctr_hashmap_->GetActiveIndices(active_buf_indices);
121 ctr_hashmap_->GetKeyTensor().IndexGet({active_indices});
132 keys_nb[0] = active_keys - dx;
133 keys_nb[1] = active_keys + dx;
134 keys_nb[2] = active_keys - dy;
135 keys_nb[3] = active_keys + dy;
136 keys_nb[4] = active_keys - dz;
137 keys_nb[5] = active_keys + dz;
140 keys_nb = keys_nb.
View({6 * n, 3});
143 ctr_hashmap_->Find(keys_nb, buf_indices_nb, masks_nb);
145 return std::make_tuple(active_buf_indices,
163 core::Tensor residual = pts_quantized - pts_quantized_floor;
164 std::vector<std::vector<core::Tensor>> residuals(3);
165 for (
int axis = 0; axis < 3; ++axis) {
170 residuals[axis].emplace_back(1.f - residual_axis);
171 residuals[axis].emplace_back(residual_axis);
178 for (
int nb = 0; nb < 8; ++nb) {
179 int x_sel = (nb & 4) >> 2;
180 int y_sel = (nb & 2) >> 1;
181 int z_sel = (nb & 1);
183 float x_sign = x_sel * 2.0 - 1.0;
184 float y_sign = y_sel * 2.0 - 1.0;
185 float z_sign = z_sel * 2.0 - 1.0;
189 keys_nb[nb] = keys + dt;
190 point_ratios_nb[nb] =
191 residuals[0][x_sel] * residuals[1][y_sel] * residuals[2][z_sel];
193 normal_ratios_nb[nb] =
194 x_sign * nms[0] * residuals[1][y_sel] *
195 residuals[2][z_sel] +
196 y_sign * nms[1] * residuals[0][x_sel] *
197 residuals[2][z_sel] +
198 z_sign * nms[2] * residuals[0][x_sel] * residuals[1][y_sel];
202 keys_nb = keys_nb.
View({8 * n, 3});
205 ctr_hashmap_->Find(keys_nb, buf_indices_nb, masks_nb);
210 point_ratios_nb = point_ratios_nb.
T().
Contiguous();
222 buf_indices_nb.
IndexGet({valid_mask}));
224 point_ratios_nb.IndexGet({valid_mask}));
233 normal_ratios_nb = normal_ratios_nb.T().Contiguous();
235 normal_ratios_nb.IndexGet({valid_mask}));
238 return pcd_with_params;
245 "Please use ControlGrid.Parameterize to obtain attributes "
246 "regarding neighbor grids before calling Deform");
250 core::Tensor grid_positions = ctr_hashmap_->GetValueTensor();
265 (nb_grid_positions * nb_grid_point_interp.
View({-1, 8, 1}))
276 (nb_grid_positions * nb_grid_normal_interp.
View({-1, 8, 1}))
279 (interp_normals * interp_normals).Sum({1}).
Sqrt();
280 interp_normals = interp_normals / interp_normals_len.
View({-1, 1});
296 depth, intrinsics, extrinsics, depth_scale, depth_max);
302 intrinsics, extrinsics, depth_scale,
312 rgbd, intrinsics, extrinsics, depth_scale, depth_max);
321 depth_scale, depth_max);
void Sqrt(const double in[2], double out[2])
static TensorKey Index(int64_t index)
static TensorKey Slice(utility::optional< int64_t > start, utility::optional< int64_t > stop, utility::optional< int64_t > step)
Tensor Contiguous() const
Tensor Sum(const SizeVector &dims, bool keepdim=false) const
int64_t GetLength() const
Tensor GetItem(const TensorKey &tk) const
Tensor IndexGet(const std::vector< Tensor > &index_tensors) const
Advanced indexing getter. This will always allocate a new Tensor.
Tensor View(const SizeVector &dst_shape) const
Tensor T() const
Expects input to be <= 2-D Tensor by swapping dimension 0 and 1.
Tensor To(Dtype dtype, bool copy=false) const
Tensor Floor() const
Element-wise floor value of a tensor, returning a new tensor.
The Image class stores image with customizable rows, cols, channels, dtype and device.
int64_t GetCols() const
Get the number of columns of the image.
int64_t GetRows() const
Get the number of rows of the image.
A point cloud contains a list of 3D points.
void SetPointNormals(const core::Tensor &value)
Set the value of the "normals" attribute. Convenience function.
core::Tensor & GetPointNormals()
Get the value of the "normals" attribute. Convenience function.
void SetPointColors(const core::Tensor &value)
Set the value of the "colors" attribute. Convenience function.
bool HasPointAttr(const std::string &key) const
void SetPointPositions(const core::Tensor &value)
Set the value of the "positions" attribute. Convenience function.
core::Tensor & GetPointPositions()
Get the value of the "positions" attribute. Convenience function.
static PointCloud CreateFromDepthImage(const Image &depth, const core::Tensor &intrinsics, const core::Tensor &extrinsics=core::Tensor::Eye(4, core::Float32, core::Device("CPU:0")), float depth_scale=1000.0f, float depth_max=3.0f, int stride=1, bool with_normals=false)
Factory function to create a point cloud from a depth image and a camera model.
geometry::RGBDImage ProjectToRGBDImage(int width, int height, const core::Tensor &intrinsics, const core::Tensor &extrinsics=core::Tensor::Eye(4, core::Float32, core::Device("CPU:0")), float depth_scale=1000.0f, float depth_max=3.0f)
Project a point cloud to an RGBD image.
geometry::Image ProjectToDepthImage(int width, int height, const core::Tensor &intrinsics, const core::Tensor &extrinsics=core::Tensor::Eye(4, core::Float32, core::Device("CPU:0")), float depth_scale=1000.0f, float depth_max=3.0f)
Project a point cloud to a depth image.
bool HasPointNormals() const
const TensorMap & GetPointAttr() const
Getter for point_attr_ TensorMap. Used in Pybind.
void SetPointAttr(const std::string &key, const core::Tensor &value)
core::Tensor & GetPointColors()
Get the value of the "colors" attribute. Convenience function.
bool HasPointColors() const
static PointCloud CreateFromRGBDImage(const RGBDImage &rgbd_image, const core::Tensor &intrinsics, const core::Tensor &extrinsics=core::Tensor::Eye(4, core::Float32, core::Device("CPU:0")), float depth_scale=1000.0f, float depth_max=3.0f, int stride=1, bool with_normals=false)
Factory function to create a point cloud from an RGB-D image and a camera model.
RGBDImage A pair of color and depth images.
Image depth_
The depth image.
Image color_
The color image.
static const std::string kGrid8NbVertexInterpRatios
8 neighbor grid interpolation ratio for vertex per point.
ControlGrid()=default
Default constructor.
static const std::string kGrid8NbIndices
geometry::PointCloud Deform(const geometry::PointCloud &pcd)
Non-rigidly deform a point cloud using the control grid.
void Touch(const geometry::PointCloud &pcd)
Allocate control grids in the shared camera space.
std::tuple< core::Tensor, core::Tensor, core::Tensor > GetNeighborGridMap()
geometry::PointCloud Parameterize(const geometry::PointCloud &pcd)
static const std::string kGrid8NbNormalInterpRatios
8 neighbor grid interpolation ratio for normal per point.
std::vector< Eigen::Vector3i > TensorToEigenVector3iVector(const core::Tensor &tensor)
Converts a tensor of shape (N, 3) to std::vector<Eigen::Vector3i>. An exception will be thrown if the...
constexpr utility::nullopt_t None
void To(const core::Tensor &src, core::Tensor &dst, double scale, double offset)
Generic file read and write utility for python interface.
Eigen::Matrix< Index, 4, 1 > Vector4i