ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Feature.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
12 
13 namespace cloudViewer {
14 namespace t {
15 namespace pipelines {
16 namespace kernel {
17 
19  const core::Tensor &points,
20  const core::Tensor &normals,
21  const core::Tensor &indices,
22  const core::Tensor &distance2,
23  const core::Tensor &counts,
24  core::Tensor &fpfhs,
26  const utility::optional<core::Tensor> &map_info_idx_to_point_idx) {
27  if (mask.has_value()) {
28  const int64_t size =
29  mask.value().To(core::Int64).Sum({0}).Item<int64_t>();
30  core::AssertTensorShape(fpfhs, {size, 33});
31  core::AssertTensorShape(mask.value(), {points.GetLength()});
32  } else {
33  core::AssertTensorShape(fpfhs, {points.GetLength(), 33});
34  }
35  if (map_info_idx_to_point_idx.has_value()) {
36  const bool is_radius_search = indices.GetShape().size() == 1;
38  map_info_idx_to_point_idx.value(),
39  {counts.GetLength() - (is_radius_search ? 1 : 0)});
40  }
41  const core::Tensor points_d = points.Contiguous();
42  const core::Tensor normals_d = normals.Contiguous();
43  const core::Tensor counts_d = counts.To(core::Int32);
44  if (points_d.IsCPU()) {
45  ComputeFPFHFeatureCPU(points_d, normals_d, indices, distance2, counts_d,
46  fpfhs, mask, map_info_idx_to_point_idx);
47  } else {
48  core::CUDAScopedDevice scoped_device(points.GetDevice());
49  CUDA_CALL(ComputeFPFHFeatureCUDA, points_d, normals_d, indices,
50  distance2, counts_d, fpfhs, mask, map_info_idx_to_point_idx);
51  }
53  "[ComputeFPFHFeature] Computed {:d} features from "
54  "input point cloud with {:d} points.",
55  (int)fpfhs.GetLength(), (int)points.GetLength());
56 }
57 
58 } // namespace kernel
59 } // namespace pipelines
60 } // namespace t
61 } // namespace cloudViewer
Common CUDA utilities.
#define CUDA_CALL(cuda_function,...)
Definition: CUDAUtils.h:49
int size
int points
#define AssertTensorShape(tensor,...)
Definition: TensorCheck.h:61
When CUDA is not enabled, this is a dummy class.
Definition: CUDAUtils.h:214
bool IsCPU() const
Definition: Device.h:95
int64_t GetLength() const
Definition: Tensor.h:1125
SizeVector GetShape() const
Definition: Tensor.h:1127
Tensor To(Dtype dtype, bool copy=false) const
Definition: Tensor.cpp:739
constexpr bool has_value() const noexcept
Definition: Optional.h:440
constexpr T const & value() const &
Definition: Optional.h:465
double normals[3]
#define LogDebug(...)
Definition: Logging.h:90
const Dtype Int64
Definition: Dtype.cpp:47
const Dtype Int32
Definition: Dtype.cpp:46
void ComputeFPFHFeature(const core::Tensor &points, const core::Tensor &normals, const core::Tensor &indices, const core::Tensor &distance2, const core::Tensor &counts, core::Tensor &fpfhs, const utility::optional< core::Tensor > &mask, const utility::optional< core::Tensor > &map_info_idx_to_point_idx)
Definition: Feature.cpp:18
void ComputeFPFHFeatureCPU(const core::Tensor &points, const core::Tensor &normals, const core::Tensor &indices, const core::Tensor &distance2, const core::Tensor &counts, core::Tensor &fpfhs, const utility::optional< core::Tensor > &mask=utility::nullopt, const utility::optional< core::Tensor > &map_batch_info_idx_to_point_idx=utility::nullopt)
Definition: FeatureImpl.h:112
Generic file read and write utility for python interface.