24 using t::geometry::PointCloud;
28 static PointCloud CreateTPCDFromFile(
29 const std::string& fname,
30 const core::Device& device = core::Device(
"CPU:0")) {
31 std::shared_ptr<open3d::geometry::PointCloud> pcd =
45 const float threshold) {
50 tpcd_i.GetPointPositions(),
51 tpcd_j.GetPointPositions(),
52 tpcd_i.GetPointNormals(), i, j, threshold);
55 void FillInRigidAlignmentTerm(
Tensor& AtA,
58 const std::vector<std::string>& fnames,
65 for (
auto& edge : pose_graph.
edges_) {
66 int i = edge.source_node_id_;
67 int j = edge.target_node_id_;
69 std::string corres_fname =
fmt::format(
"{}/{:03d}_{:03d}.npy",
76 PointCloud tpcd_i = CreateTPCDFromFile(fnames[i], device);
77 PointCloud tpcd_j = CreateTPCDFromFile(fnames[j], device);
91 FillInRigidAlignmentTerm(AtA, Atb, residual, tpcd_i_indexed,
92 tpcd_j_indexed, Ti, Tj, i, j,
102 static void FillInSLACAlignmentTerm(Tensor& AtA,
105 ControlGrid& ctr_grid,
112 const int n_fragments,
113 const float threshold) {
115 Tensor cgrid_index_ps =
117 Tensor cgrid_ratio_ps =
120 Tensor cgrid_index_qs =
122 Tensor cgrid_ratio_qs =
126 PointCloud tpcd_nonrigid_i = ctr_grid.Deform(tpcd_param_i);
127 PointCloud tpcd_nonrigid_j = ctr_grid.Deform(tpcd_param_j);
129 Tensor Cps = tpcd_nonrigid_i.GetPointPositions();
130 Tensor Cqs = tpcd_nonrigid_j.GetPointPositions();
131 Tensor Cnormal_ps = tpcd_nonrigid_i.GetPointNormals();
133 Tensor Ri = Ti.Slice(0, 0, 3).Slice(1, 0, 3);
134 Tensor ti = Ti.Slice(0, 0, 3).Slice(1, 3, 4);
136 Tensor Rj = Tj.Slice(0, 0, 3).Slice(1, 0, 3);
137 Tensor tj = Tj.Slice(0, 0, 3).Slice(1, 3, 4);
140 Tensor Ti_Cps = (Ri.Matmul(Cps.T())).Add_(ti).T().Contiguous();
141 Tensor Tj_Cqs = (Rj.Matmul(Cqs.T())).Add_(tj).T().Contiguous();
142 Tensor Ri_Cnormal_ps = (Ri.Matmul(Cnormal_ps.T())).T().Contiguous();
143 Tensor RjT_Ri_Cnormal_ps =
144 (Rj.T().Matmul(Ri_Cnormal_ps.T())).T().Contiguous();
147 AtA, Atb, residual, Ti_Cps, Tj_Cqs, Cnormal_ps, Ri_Cnormal_ps,
148 RjT_Ri_Cnormal_ps, cgrid_index_ps, cgrid_index_qs, cgrid_ratio_ps,
149 cgrid_ratio_qs, i, j, n_fragments, threshold);
152 void FillInSLACAlignmentTerm(
Tensor& AtA,
156 const std::vector<std::string>& fnames,
161 int n_frags = pose_graph.
nodes_.size();
164 for (
auto& edge : pose_graph.
edges_) {
165 int i = edge.source_node_id_;
166 int j = edge.target_node_id_;
168 std::string corres_fname =
fmt::format(
"{}/{:03d}_{:03d}.npy",
176 PointCloud tpcd_i = CreateTPCDFromFile(fnames[i], device);
177 PointCloud tpcd_j = CreateTPCDFromFile(fnames[j], device);
202 FillInSLACAlignmentTerm(AtA, Atb, residual, ctr_grid, tpcd_param_i,
203 tpcd_param_j, Ti, Tj, i, j, n_frags,
222 Tensor active_buf_indices, nb_buf_indices, nb_masks;
223 std::tie(active_buf_indices, nb_buf_indices, nb_masks) =
229 nb_buf_indices, nb_masks, positions_init,
233 if (debug_option.
debug_) {
filament::Texture::InternalFormat format
Definition: FilamentResourceManager.cpp:195
#define LogWarning(...)
Definition: Logging.h:60
Tensor Inverse() const
Definition: Tensor.cpp:1891
static Tensor Load(const std::string &file_name)
Load tensor from numpy's npy format.
Definition: Tensor.cpp:1790
Tensor Matmul(const Tensor &rhs) const
Definition: Tensor.cpp:1828
Tensor To(Dtype dtype, bool copy=false) const
Definition: Tensor.cpp:706
Tensor IndexGet(const std::vector< Tensor > &index_tensors) const
Advanced indexing getter. This will always allocate a new Tensor.
Definition: Tensor.cpp:872
A point cloud consists of point coordinates, and optionally point colors and point normals.
Definition: PointCloud.h:36
Data structure defining the pose graph.
Definition: PoseGraph.h:96
std::vector< PoseGraphNode > nodes_
List of PoseGraphNode.
Definition: PoseGraph.h:108
std::vector< PoseGraphEdge > edges_
List of PoseGraphEdge.
Definition: PoseGraph.h:110
A point cloud contains a list of 3D points.
Definition: PointCloud.h:80
core::Tensor & GetPointNormals()
Get the value of the "normals" attribute. Convenience function.
Definition: PointCloud.h:128
core::Tensor & GetPointPositions()
Get the value of the "positions" attribute. Convenience function.
Definition: PointCloud.h:122
static PointCloud FromLegacy(const open3d::geometry::PointCloud &pcd_legacy, core::Dtype dtype=core::Float32, const core::Device &device=core::Device("CPU:0"))
Create a PointCloud from a legacy Open3D PointCloud.
Definition: PointCloud.cpp:990
void SetPointNormals(const core::Tensor &value)
Set the value of the "normals" attribute. Convenience function.
Definition: PointCloud.h:178
Definition: ControlGrid.h:30
int64_t GetAnchorIdx()
Definition: ControlGrid.h:116
static const std::string kGrid8NbIndices
Definition: ControlGrid.h:34
static const std::string kGrid8NbVertexInterpRatios
8 neighbor grid interpolation ratio for vertex per point.
Definition: ControlGrid.h:36
core::Tensor GetInitPositions()
Get control grid original positions directly from tensor keys.
Definition: ControlGrid.h:104
core::Tensor GetCurrPositions()
Definition: ControlGrid.h:110
std::tuple< core::Tensor, core::Tensor, core::Tensor > GetNeighborGridMap()
Definition: ControlGrid.cpp:115
geometry::PointCloud Parameterize(const geometry::PointCloud &pcd)
Definition: ControlGrid.cpp:150
Definition: EigenConverter.cpp:18
core::Tensor EigenMatrixToTensor(const Eigen::MatrixBase< Derived > &matrix)
Converts a eigen matrix of shape (M, N) with alignment A and type T to a tensor.
Definition: EigenConverter.h:29
const Dtype Float32
Definition: Dtype.cpp:42
std::shared_ptr< geometry::PointCloud > CreatePointCloudFromFile(const std::string &filename, const std::string &format, bool print_progress)
Definition: PointCloudIO.cpp:49
void FillInSLACRegularizerTerm(core::Tensor &AtA, core::Tensor &Atb, core::Tensor &residual, const core::Tensor &grid_idx, const core::Tensor &grid_nbs_idx, const core::Tensor &grid_nbs_mask, const core::Tensor &positions_init, const core::Tensor &positions_curr, float weight, int n, int anchor_idx)
Definition: FillInLinearSystem.cpp:133
void FillInSLACAlignmentTerm(core::Tensor &AtA, core::Tensor &Atb, core::Tensor &residual, const core::Tensor &Ti_ps, const core::Tensor &Tj_qs, const core::Tensor &normal_ps, const core::Tensor &Ri_normal_ps, const core::Tensor &RjT_Ri_normal_ps, const core::Tensor &cgrid_idx_ps, const core::Tensor &cgrid_idx_qs, const core::Tensor &cgrid_ratio_qs, const core::Tensor &cgrid_ratio_ps, int i, int j, int n, float threshold)
Definition: FillInLinearSystem.cpp:69
void FillInRigidAlignmentTerm(core::Tensor &AtA, core::Tensor &Atb, core::Tensor &residual, const core::Tensor &Ti_ps, const core::Tensor &Tj_qs, const core::Tensor &Ri_normal_ps, int i, int j, float threshold)
Definition: FillInLinearSystem.cpp:18
void VisualizePointCloudDeformation(const geometry::PointCloud &tpcd_param, ControlGrid &ctr_grid)
Definition: Visualization.cpp:139
void VisualizeGridDeformation(ControlGrid &cgrid)
Definition: Visualization.cpp:187
void VisualizePointCloudCorrespondences(const t::geometry::PointCloud &tpcd_i, const t::geometry::PointCloud &tpcd_j, const core::Tensor correspondences, const core::Tensor &T_ij)
Visualize pairs with correspondences.
Definition: Visualization.cpp:46
void VisualizePointCloudEmbedding(t::geometry::PointCloud &tpcd_param, ControlGrid &ctr_grid, bool show_lines)
Definition: Visualization.cpp:80
void FillInSLACRegularizerTerm(Tensor &AtA, Tensor &Atb, Tensor &residual, ControlGrid &ctr_grid, int n_frags, const SLACOptimizerParams ¶ms, const SLACDebugOption &debug_option)
Definition: FillInLinearSystemImpl.h:215
bool FileExists(const std::string &filename)
Definition: FileSystem.cpp:269
Definition: PinholeCameraIntrinsic.cpp:16
Definition: SLACOptimizer.h:90
bool debug_
Enable debug.
Definition: SLACOptimizer.h:92
int debug_start_node_idx_
Definition: SLACOptimizer.h:96
Definition: SLACOptimizer.h:24
float distance_threshold_
Distance threshold to filter inconsistent correspondences.
Definition: SLACOptimizer.h:33
float regularizer_weight_
Weight of the regularizer.
Definition: SLACOptimizer.h:39
std::string GetSubfolderName() const
Definition: SLACOptimizer.h:46
core::Device device_
Device to use.
Definition: SLACOptimizer.h:42