31 namespace pointcloud {
40 #if defined(__CUDACC__)
56 const bool have_colors = image_colors.has_value();
72 const auto& imcol = image_colors.value().get();
74 colors.value().get() =
core::Tensor({rows_strided * cols_strided, 3},
80 #if defined(__CUDACC__)
82 int* count_ptr =
count.GetDataPtr<
int>();
84 std::atomic<int> count_atomic(0);
85 std::atomic<int>* count_ptr = &count_atomic;
88 int64_t n = rows_strided * cols_strided;
92 depth.GetDevice(), n, [=] OPEN3D_DEVICE(int64_t workload_idx) {
93 int64_t y = (workload_idx / cols_strided) * stride;
94 int64_t x = (workload_idx % cols_strided) * stride;
96 float d = *depth_indexer.GetDataPtr<scalar_t>(x, y) /
98 if (d > 0 && d < depth_max) {
99 int idx = OPEN3D_ATOMIC_ADD(count_ptr, 1);
101 float x_c = 0, y_c = 0, z_c = 0;
102 ti.Unproject(static_cast<float>(x),
103 static_cast<float>(y), d, &x_c, &y_c,
106 float* vertex = point_indexer.GetDataPtr<float>(idx);
107 ti.RigidTransform(x_c, y_c, z_c, vertex + 0, vertex + 1,
111 colors_indexer.GetDataPtr<float>(idx);
113 image_colors_indexer.GetDataPtr<float>(x,
115 *pcd_pixel = *image_pixel;
116 *(pcd_pixel + 1) = *(image_pixel + 1);
117 *(pcd_pixel + 2) = *(image_pixel + 2);
122 #if defined(__CUDACC__)
123 int total_pts_count =
count.Item<
int>();
125 int total_pts_count = (*count_ptr).load();
133 colors.value().get() =
134 colors.value().get().Slice(0, 0, total_pts_count);
138 #if defined(__CUDACC__)
139 void GetPointMaskWithinAABBCUDA
149 const scalar_t* points_ptr = points.GetDataPtr<scalar_t>();
150 const int64_t n = points.GetLength();
151 const scalar_t* min_bound_ptr = min_bound.GetDataPtr<scalar_t>();
152 const scalar_t* max_bound_ptr = max_bound.GetDataPtr<scalar_t>();
153 bool* mask_ptr = mask.GetDataPtr<bool>();
156 points.GetDevice(), n, [=] OPEN3D_DEVICE(int64_t workload_idx) {
157 const scalar_t x = points_ptr[3 * workload_idx + 0];
158 const scalar_t y = points_ptr[3 * workload_idx + 1];
159 const scalar_t z = points_ptr[3 * workload_idx + 2];
161 if (x >= min_bound_ptr[0] && x <= max_bound_ptr[0] &&
162 y >= min_bound_ptr[1] && y <= max_bound_ptr[1] &&
163 z >= min_bound_ptr[2] && z <= max_bound_ptr[2]) {
164 mask_ptr[workload_idx] = true;
166 mask_ptr[workload_idx] = false;
172 #if defined(__CUDACC__)
173 void GetPointMaskWithinOBBCUDA
187 const int64_t n =
points.GetLength();
190 const scalar_t* pd_ptr = pd.GetDataPtr<scalar_t>();
192 const scalar_t* rotation_ptr = rotation_t.GetDataPtr<scalar_t>();
193 const scalar_t* half_extent_ptr = half_extent.GetDataPtr<scalar_t>();
194 bool* mask_ptr = mask.GetDataPtr<bool>();
196 core::ParallelFor(points.GetDevice(), n,
197 [=] OPEN3D_DEVICE(int64_t workload_idx) {
198 int64_t idx = 3 * workload_idx;
199 if (abs(core::linalg::kernel::dot_3x1(
200 pd_ptr + idx, rotation_ptr)) <=
201 half_extent_ptr[0] &&
202 abs(core::linalg::kernel::dot_3x1(
203 pd_ptr + idx, rotation_ptr + 3)) <=
204 half_extent_ptr[1] &&
205 abs(core::linalg::kernel::dot_3x1(
206 pd_ptr + idx, rotation_ptr + 6)) <=
207 half_extent_ptr[2]) {
208 mask_ptr[workload_idx] = true;
210 mask_ptr[workload_idx] = false;
216 #if defined(__CUDACC__)
217 void NormalizeNormalsCUDA
223 const int64_t n = normals.GetLength();
226 scalar_t* ptr = normals.GetDataPtr<scalar_t>();
230 int64_t idx = 3 * workload_idx;
231 scalar_t x = ptr[idx];
232 scalar_t y = ptr[idx + 1];
233 scalar_t z = ptr[idx + 2];
234 scalar_t norm = sqrt(x * x + y * y + z * z);
247 #if defined(__CUDACC__)
248 void OrientNormalsToAlignWithDirectionCUDA
254 const int64_t n = normals.GetLength();
257 scalar_t* ptr = normals.GetDataPtr<scalar_t>();
258 const scalar_t* direction_ptr = direction.GetDataPtr<scalar_t>();
262 int64_t idx = 3 * workload_idx;
263 scalar_t* normal = ptr + idx;
264 const scalar_t norm = sqrt(normal[0] * normal[0] +
265 normal[1] * normal[1] +
266 normal[2] * normal[2]);
268 normal[0] = direction_ptr[0];
269 normal[1] = direction_ptr[1];
270 normal[2] = direction_ptr[2];
272 normal, direction_ptr) < 0) {
281 #if defined(__CUDACC__)
282 void OrientNormalsTowardsCameraLocationCUDA
290 const int64_t n = normals.GetLength();
293 scalar_t* normals_ptr = normals.GetDataPtr<scalar_t>();
294 const scalar_t* camera_ptr = camera.GetDataPtr<scalar_t>();
295 const scalar_t* points_ptr =
points.GetDataPtr<scalar_t>();
298 normals.GetDevice(), n,
300 int64_t idx = 3 * workload_idx;
301 scalar_t* normal = normals_ptr + idx;
302 const scalar_t* point = points_ptr + idx;
303 const scalar_t reference[3] = {camera_ptr[0] - point[0],
304 camera_ptr[1] - point[1],
305 camera_ptr[2] - point[2]};
306 const scalar_t norm =
307 sqrt(normal[0] * normal[0] + normal[1] * normal[1] +
308 normal[2] * normal[2]);
310 normal[0] = reference[0];
311 normal[1] = reference[1];
312 normal[2] = reference[2];
313 const scalar_t norm_new = sqrt(normal[0] * normal[0] +
314 normal[1] * normal[1] +
315 normal[2] * normal[2]);
316 if (norm_new == 0.0) {
321 normal[0] /= norm_new;
322 normal[1] /= norm_new;
323 normal[2] /= norm_new;
335 template <
typename scalar_t>
344 if (!(abs(query[0] - query[2]) < 1e-6) ||
345 !(abs(query[1] - query[2]) < 1e-6)) {
346 const scalar_t norm2_inv =
347 1.0 / sqrt(query[0] * query[0] + query[1] * query[1]);
348 v[0] = -1 * query[1] * norm2_inv;
349 v[1] = query[0] * norm2_inv;
352 const scalar_t norm2_inv =
353 1.0 / sqrt(query[1] * query[1] + query[2] * query[2]);
355 v[1] = -1 * query[2] * norm2_inv;
356 v[2] = query[1] * norm2_inv;
362 template <
typename scalar_t>
369 template <
typename scalar_t>
372 int l = 2 * root + 1;
373 int r = 2 * root + 2;
375 if (l < n && arr[l] > arr[largest]) {
378 if (r < n && arr[r] > arr[largest]) {
381 if (largest != root) {
382 Swap<scalar_t>(&arr[root], &arr[largest]);
383 Heapify<scalar_t>(arr, n, largest);
387 template <
typename scalar_t>
389 for (
int i = n / 2 - 1; i >= 0; i--)
Heapify(arr, n, i);
391 for (
int i = n - 1; i > 0; i--) {
392 Swap<scalar_t>(&arr[0], &arr[i]);
393 Heapify<scalar_t>(arr, i, 0);
397 template <
typename scalar_t>
400 double angle_threshold) {
402 scalar_t max_diff = 0;
404 for (
int i = 0; i < counts - 1; i++) {
405 diff = angles[i + 1] - angles[i];
406 max_diff = max(max_diff, diff);
410 diff = 2 * M_PI - angles[counts - 1] + angles[0];
411 max_diff = max(max_diff, diff);
413 return max_diff > angle_threshold * M_PI / 180.0 ? true :
false;
416 #if defined(__CUDACC__)
417 void ComputeBoundaryPointsCUDA
426 double angle_threshold) {
427 const int nn_size = indices.GetShape()[1];
430 const scalar_t* points_ptr = points.GetDataPtr<scalar_t>();
431 const scalar_t* normals_ptr = normals.GetDataPtr<scalar_t>();
432 const int64_t n = points.GetLength();
433 const int32_t* indices_ptr = indices.GetDataPtr<int32_t>();
434 const int32_t* counts_ptr = counts.GetDataPtr<int32_t>();
435 bool* mask_ptr = mask.GetDataPtr<bool>();
437 core::Tensor angles = core::Tensor::Full(
438 indices.GetShape(), -10, points.GetDtype(), points.GetDevice());
439 scalar_t* angles_ptr = angles.GetDataPtr<scalar_t>();
442 points.GetDevice(), n, [=] OPEN3D_DEVICE(int64_t workload_idx) {
444 GetCoordinateSystemOnPlane(normals_ptr + 3 * workload_idx,
448 int indices_size = counts_ptr[workload_idx] - 1;
449 if (indices_size > 0) {
450 const scalar_t* query = points_ptr + 3 * workload_idx;
451 for (int i = 1; i < indices_size + 1; i++) {
452 const int idx = workload_idx * nn_size + i;
454 const scalar_t* point_ref =
455 points_ptr + 3 * indices_ptr[idx];
456 const scalar_t delta[3] = {point_ref[0] - query[0],
457 point_ref[1] - query[1],
458 point_ref[2] - query[2]};
459 const scalar_t angle = atan2(
460 core::linalg::kernel::dot_3x1(v, delta),
461 core::linalg::kernel::dot_3x1(u, delta));
463 angles_ptr[idx] = angle;
468 angles_ptr + workload_idx * nn_size + 1,
471 mask_ptr[workload_idx] = IsBoundaryPoints<scalar_t>(
472 angles_ptr + workload_idx * nn_size + 1,
473 indices_size, angle_threshold);
481 template <
typename scalar_t>
483 const scalar_t* points_ptr,
486 scalar_t* covariance_ptr) {
487 if (indices_count < 3) {
488 covariance_ptr[0] = 1.0;
489 covariance_ptr[1] = 0.0;
490 covariance_ptr[2] = 0.0;
491 covariance_ptr[3] = 0.0;
492 covariance_ptr[4] = 1.0;
493 covariance_ptr[5] = 0.0;
494 covariance_ptr[6] = 0.0;
495 covariance_ptr[7] = 0.0;
496 covariance_ptr[8] = 1.0;
500 double centroid[3] = {0};
501 for (
int32_t i = 0; i < indices_count; ++i) {
502 int32_t idx = 3 * indices_ptr[i];
503 centroid[0] += points_ptr[idx];
504 centroid[1] += points_ptr[idx + 1];
505 centroid[2] += points_ptr[idx + 2];
508 centroid[0] /= indices_count;
509 centroid[1] /= indices_count;
510 centroid[2] /= indices_count;
513 double cumulants[6] = {0};
514 for (
int32_t i = 0; i < indices_count; ++i) {
515 int32_t idx = 3 * indices_ptr[i];
516 const double x =
static_cast<double>(points_ptr[idx]) - centroid[0];
517 const double y =
static_cast<double>(points_ptr[idx + 1]) - centroid[1];
518 const double z =
static_cast<double>(points_ptr[idx + 2]) - centroid[2];
520 cumulants[0] += x * x;
521 cumulants[1] += y * y;
522 cumulants[2] += z * z;
524 cumulants[3] += x * y;
525 cumulants[4] += x * z;
526 cumulants[5] += y * z;
532 const double normalization_factor =
static_cast<double>(indices_count - 1);
533 for (
int i = 0; i < 6; ++i) {
534 cumulants[i] /= normalization_factor;
538 covariance_ptr[0] =
static_cast<scalar_t
>(cumulants[0]);
540 covariance_ptr[4] =
static_cast<scalar_t
>(cumulants[1]);
542 covariance_ptr[8] =
static_cast<scalar_t
>(cumulants[2]);
545 covariance_ptr[1] =
static_cast<scalar_t
>(cumulants[3]);
546 covariance_ptr[3] = covariance_ptr[1];
549 covariance_ptr[2] =
static_cast<scalar_t
>(cumulants[4]);
550 covariance_ptr[6] = covariance_ptr[2];
553 covariance_ptr[5] =
static_cast<scalar_t
>(cumulants[5]);
554 covariance_ptr[7] = covariance_ptr[5];
557 #if defined(__CUDACC__)
558 void EstimateCovariancesUsingHybridSearchCUDA
564 const double& radius,
565 const int64_t& max_nn) {
567 int64_t n =
points.GetLength();
576 std::tie(indices, distance, counts) =
580 const scalar_t* points_ptr =
points.GetDataPtr<scalar_t>();
583 scalar_t* covariances_ptr = covariances.GetDataPtr<scalar_t>();
588 const int32_t neighbour_offset = max_nn * workload_idx;
590 const int32_t neighbour_count =
591 neighbour_counts_ptr[workload_idx];
594 const int32_t covariances_offset = 9 * workload_idx;
598 neighbour_indices_ptr + neighbour_offset,
600 covariances_ptr + covariances_offset);
607 #if defined(__CUDACC__)
608 void EstimateCovariancesUsingRadiusSearchCUDA
614 const double& radius) {
616 int64_t n =
points.GetLength();
625 std::tie(indices, distance, counts) =
629 const scalar_t* points_ptr =
points.GetDataPtr<scalar_t>();
632 scalar_t* covariances_ptr = covariances.GetDataPtr<scalar_t>();
636 const int32_t neighbour_offset =
637 neighbour_counts_ptr[workload_idx];
638 const int32_t neighbour_count =
639 (neighbour_counts_ptr[workload_idx + 1] -
640 neighbour_counts_ptr[workload_idx]);
643 const int32_t covariances_offset = 9 * workload_idx;
647 neighbour_indices_ptr + neighbour_offset,
649 covariances_ptr + covariances_offset);
656 #if defined(__CUDACC__)
657 void EstimateCovariancesUsingKNNSearchCUDA
663 const int64_t& max_nn) {
665 int64_t n =
points.GetLength();
681 "Not enough neighbors to compute Covariances / Normals. "
683 "increasing the max_nn parameter.");
687 auto points_ptr =
points.GetDataPtr<scalar_t>();
689 auto covariances_ptr = covariances.GetDataPtr<scalar_t>();
694 const int32_t neighbour_offset = nn_count * workload_idx;
697 const int32_t covariances_offset = 9 * workload_idx;
701 neighbour_indices_ptr + neighbour_offset, nn_count,
702 covariances_ptr + covariances_offset);
709 template <
typename scalar_t>
711 const scalar_t eval0,
712 scalar_t* eigen_vector0) {
713 scalar_t row0[3] = {A[0] - eval0, A[1], A[2]};
714 scalar_t row1[3] = {A[1], A[4] - eval0, A[5]};
715 scalar_t row2[3] = {A[2], A[5], A[8] - eval0};
717 scalar_t r0xr1[3], r0xr2[3], r1xr2[3];
738 scalar_t sqrt_d = sqrt(d0);
739 eigen_vector0[0] = r0xr1[0] / sqrt_d;
740 eigen_vector0[1] = r0xr1[1] / sqrt_d;
741 eigen_vector0[2] = r0xr1[2] / sqrt_d;
743 }
else if (imax == 1) {
744 scalar_t sqrt_d = sqrt(d1);
745 eigen_vector0[0] = r0xr2[0] / sqrt_d;
746 eigen_vector0[1] = r0xr2[1] / sqrt_d;
747 eigen_vector0[2] = r0xr2[2] / sqrt_d;
750 scalar_t sqrt_d = sqrt(d2);
751 eigen_vector0[0] = r1xr2[0] / sqrt_d;
752 eigen_vector0[1] = r1xr2[1] / sqrt_d;
753 eigen_vector0[2] = r1xr2[2] / sqrt_d;
758 template <
typename scalar_t>
760 const scalar_t* evec0,
761 const scalar_t eval1,
762 scalar_t* eigen_vector1) {
764 if (abs(evec0[0]) > abs(evec0[1])) {
765 scalar_t inv_length =
766 1.0 / sqrt(evec0[0] * evec0[0] + evec0[2] * evec0[2]);
767 U[0] = -evec0[2] * inv_length;
769 U[2] = evec0[0] * inv_length;
771 scalar_t inv_length =
772 1.0 / sqrt(evec0[1] * evec0[1] + evec0[2] * evec0[2]);
774 U[1] = evec0[2] * inv_length;
775 U[2] = -evec0[1] * inv_length;
777 scalar_t V[3], AU[3], AV[3];
779 core::linalg::kernel::matmul3x3_3x1(A, U, AU);
780 core::linalg::kernel::matmul3x3_3x1(A, V, AV);
786 scalar_t absM00 = abs(m00);
787 scalar_t absM01 = abs(m01);
788 scalar_t absM11 = abs(m11);
789 scalar_t max_abs_comp;
791 if (absM00 >= absM11) {
792 max_abs_comp = max(absM00, absM01);
793 if (max_abs_comp > 0) {
794 if (absM00 >= absM01) {
796 m00 = 1 / sqrt(1 + m01 * m01);
800 m01 = 1 / sqrt(1 + m00 * m00);
803 eigen_vector1[0] = m01 * U[0] - m00 * V[0];
804 eigen_vector1[1] = m01 * U[1] - m00 * V[1];
805 eigen_vector1[2] = m01 * U[2] - m00 * V[2];
808 eigen_vector1[0] = U[0];
809 eigen_vector1[1] = U[1];
810 eigen_vector1[2] = U[2];
814 max_abs_comp = max(absM11, absM01);
815 if (max_abs_comp > 0) {
816 if (absM11 >= absM01) {
818 m11 = 1 / sqrt(1 + m01 * m01);
822 m01 = 1 / sqrt(1 + m11 * m11);
825 eigen_vector1[0] = m11 * U[0] - m01 * V[0];
826 eigen_vector1[1] = m11 * U[1] - m01 * V[1];
827 eigen_vector1[2] = m11 * U[2] - m01 * V[2];
830 eigen_vector1[0] = U[0];
831 eigen_vector1[1] = U[1];
832 eigen_vector1[2] = U[2];
838 template <
typename scalar_t>
840 const scalar_t* covariance_ptr, scalar_t* normals_ptr) {
844 scalar_t max_coeff = covariance_ptr[0];
846 for (
int i = 1; i < 9; ++i) {
847 if (max_coeff < covariance_ptr[i]) {
848 max_coeff = covariance_ptr[i];
852 if (max_coeff == 0) {
853 normals_ptr[0] = 0.0;
854 normals_ptr[1] = 0.0;
855 normals_ptr[2] = 0.0;
861 for (
int i = 0; i < 9; ++i) {
862 A[i] = covariance_ptr[i] / max_coeff;
865 scalar_t norm = A[1] * A[1] + A[2] * A[2] + A[5] * A[5];
873 scalar_t q = (A[0] + A[4] + A[8]) / 3.0;
875 scalar_t b00 = A[0] - q;
876 scalar_t b11 = A[4] - q;
877 scalar_t b22 = A[8] - q;
880 sqrt((b00 * b00 + b11 * b11 + b22 * b22 + norm * 2.0) / 6.0);
882 scalar_t c00 = b11 * b22 - A[5] * A[5];
883 scalar_t c01 = A[1] * b22 - A[5] * A[2];
884 scalar_t c02 = A[1] * A[5] - b11 * A[2];
885 scalar_t det = (b00 * c00 - A[1] * c01 + A[2] * c02) / (p * p * p);
887 scalar_t half_det = det * 0.5;
888 half_det = min(max(half_det,
static_cast<scalar_t
>(-1.0)),
889 static_cast<scalar_t
>(1.0));
891 scalar_t angle = acos(half_det) / 3.0;
892 const scalar_t two_thrids_pi = 2.09439510239319549;
894 scalar_t beta2 = cos(angle) * 2.0;
895 scalar_t beta0 = cos(angle + two_thrids_pi) * 2.0;
896 scalar_t beta1 = -(beta0 + beta2);
898 eval[0] = q + p * beta0;
899 eval[1] = q + p * beta1;
900 eval[2] = q + p * beta2;
903 ComputeEigenvector0<scalar_t>(A, eval[2], evec2);
905 if (eval[2] < eval[0] && eval[2] < eval[1]) {
906 normals_ptr[0] = evec2[0];
907 normals_ptr[1] = evec2[1];
908 normals_ptr[2] = evec2[2];
913 ComputeEigenvector1<scalar_t>(A, evec2, eval[1], evec1);
915 if (eval[1] < eval[0] && eval[1] < eval[2]) {
916 normals_ptr[0] = evec1[0];
917 normals_ptr[1] = evec1[1];
918 normals_ptr[2] = evec1[2];
923 normals_ptr[0] = evec1[1] * evec2[2] - evec1[2] * evec2[1];
924 normals_ptr[1] = evec1[2] * evec2[0] - evec1[0] * evec2[2];
925 normals_ptr[2] = evec1[0] * evec2[1] - evec1[1] * evec2[0];
929 ComputeEigenvector0<scalar_t>(A, eval[0], evec0);
931 if (eval[0] < eval[1] && eval[0] < eval[2]) {
932 normals_ptr[0] = evec0[0];
933 normals_ptr[1] = evec0[1];
934 normals_ptr[2] = evec0[2];
938 ComputeEigenvector1<scalar_t>(A, evec0, eval[1], evec1);
940 if (eval[1] < eval[0] && eval[1] < eval[2]) {
941 normals_ptr[0] = evec1[0];
942 normals_ptr[1] = evec1[1];
943 normals_ptr[2] = evec1[2];
947 normals_ptr[0] = evec0[1] * evec1[2] - evec0[2] * evec1[1];
948 normals_ptr[1] = evec0[2] * evec1[0] - evec0[0] * evec1[2];
949 normals_ptr[2] = evec0[0] * evec1[1] - evec0[1] * evec1[0];
953 if (covariance_ptr[0] < covariance_ptr[4] &&
954 covariance_ptr[0] < covariance_ptr[8]) {
955 normals_ptr[0] = 1.0;
956 normals_ptr[1] = 0.0;
957 normals_ptr[2] = 0.0;
959 }
else if (covariance_ptr[0] < covariance_ptr[4] &&
960 covariance_ptr[0] < covariance_ptr[8]) {
961 normals_ptr[0] = 0.0;
962 normals_ptr[1] = 1.0;
963 normals_ptr[2] = 0.0;
966 normals_ptr[0] = 0.0;
967 normals_ptr[1] = 0.0;
968 normals_ptr[2] = 1.0;
974 #if defined(__CUDACC__)
975 void EstimateNormalsFromCovariancesCUDA
983 int64_t n = covariances.GetLength();
986 const scalar_t* covariances_ptr = covariances.GetDataPtr<scalar_t>();
987 scalar_t* normals_ptr = normals.GetDataPtr<scalar_t>();
990 covariances.GetDevice(), n,
992 int32_t covariances_offset = 9 * workload_idx;
993 int32_t normals_offset = 3 * workload_idx;
994 scalar_t normals_output[3] = {0};
995 EstimatePointWiseNormalsWithFastEigen3x3<scalar_t>(
996 covariances_ptr + covariances_offset,
999 if ((normals_output[0] * normals_output[0] +
1000 normals_output[1] * normals_output[1] +
1001 normals_output[2] * normals_output[2]) == 0.0 &&
1003 normals_output[0] = 0.0;
1004 normals_output[1] = 0.0;
1005 normals_output[2] = 1.0;
1008 if ((normals_ptr[normals_offset] * normals_output[0] +
1009 normals_ptr[normals_offset + 1] *
1011 normals_ptr[normals_offset + 2] *
1012 normals_output[2]) < 0.0) {
1013 normals_output[0] *= -1;
1014 normals_output[1] *= -1;
1015 normals_output[2] *= -1;
1019 normals_ptr[normals_offset] = normals_output[0];
1020 normals_ptr[normals_offset + 1] = normals_output[1];
1021 normals_ptr[normals_offset + 2] = normals_output[2];
1028 template <
typename scalar_t>
1030 const scalar_t* points_ptr,
1031 const scalar_t* normals_ptr,
1032 const scalar_t* colors_ptr,
1036 scalar_t* color_gradients_ptr) {
1037 if (indices_count < 4) {
1038 color_gradients_ptr[idx_offset] = 0;
1039 color_gradients_ptr[idx_offset + 1] = 0;
1040 color_gradients_ptr[idx_offset + 2] = 0;
1042 scalar_t vt[3] = {points_ptr[idx_offset], points_ptr[idx_offset + 1],
1043 points_ptr[idx_offset + 2]};
1045 scalar_t nt[3] = {normals_ptr[idx_offset], normals_ptr[idx_offset + 1],
1046 normals_ptr[idx_offset + 2]};
1048 scalar_t it = (colors_ptr[idx_offset] + colors_ptr[idx_offset + 1] +
1049 colors_ptr[idx_offset + 2]) /
1052 scalar_t AtA[9] = {0};
1053 scalar_t Atb[3] = {0};
1063 scalar_t s = vt[0] * nt[0] + vt[1] * nt[1] + vt[2] * nt[2];
1066 for (; i < indices_count; i++) {
1067 int64_t neighbour_idx_offset = 3 * indices_ptr[i];
1069 if (neighbour_idx_offset == -1) {
1073 scalar_t vt_adj[3] = {points_ptr[neighbour_idx_offset],
1074 points_ptr[neighbour_idx_offset + 1],
1075 points_ptr[neighbour_idx_offset + 2]};
1079 scalar_t d = vt_adj[0] * nt[0] + vt_adj[1] * nt[1] +
1080 vt_adj[2] * nt[2] - s;
1083 scalar_t vt_proj[3] = {vt_adj[0] - d * nt[0], vt_adj[1] - d * nt[1],
1084 vt_adj[2] - d * nt[2]};
1086 scalar_t it_adj = (colors_ptr[neighbour_idx_offset + 0] +
1087 colors_ptr[neighbour_idx_offset + 1] +
1088 colors_ptr[neighbour_idx_offset + 2]) /
1091 scalar_t A[3] = {vt_proj[0] - vt[0], vt_proj[1] - vt[1],
1092 vt_proj[2] - vt[2]};
1094 AtA[0] += A[0] * A[0];
1095 AtA[1] += A[1] * A[0];
1096 AtA[2] += A[2] * A[0];
1097 AtA[4] += A[1] * A[1];
1098 AtA[5] += A[2] * A[1];
1099 AtA[8] += A[2] * A[2];
1101 scalar_t b = it_adj - it;
1109 scalar_t A[3] = {(i - 1) * nt[0], (i - 1) * nt[1], (i - 1) * nt[2]};
1111 AtA[0] += A[0] * A[0];
1112 AtA[1] += A[0] * A[1];
1113 AtA[2] += A[0] * A[2];
1114 AtA[4] += A[1] * A[1];
1115 AtA[5] += A[1] * A[2];
1116 AtA[8] += A[2] * A[2];
1124 color_gradients_ptr + idx_offset);
1128 #if defined(__CUDACC__)
1129 void EstimateColorGradientsUsingHybridSearchCUDA
1137 const double& radius,
1138 const int64_t& max_nn) {
1140 int64_t n =
points.GetLength();
1150 std::tie(indices, distance, counts) =
1154 auto points_ptr =
points.GetDataPtr<scalar_t>();
1155 auto normals_ptr = normals.GetDataPtr<scalar_t>();
1156 auto colors_ptr = colors.GetDataPtr<scalar_t>();
1159 auto color_gradients_ptr = color_gradients.GetDataPtr<scalar_t>();
1164 int32_t neighbour_offset = max_nn * workload_idx;
1167 neighbour_counts_ptr[workload_idx];
1168 int32_t idx_offset = 3 * workload_idx;
1171 points_ptr, normals_ptr, colors_ptr, idx_offset,
1172 neighbour_indices_ptr + neighbour_offset,
1173 neighbour_count, color_gradients_ptr);
1180 #if defined(__CUDACC__)
1181 void EstimateColorGradientsUsingKNNSearchCUDA
1189 const int64_t& max_nn) {
1191 int64_t n =
points.GetLength();
1204 int64_t nn_count = indices.
GetShape()[1];
1208 "Not enough neighbors to compute Covariances / Normals. "
1210 "changing the search parameter.");
1214 auto points_ptr =
points.GetDataPtr<scalar_t>();
1215 auto normals_ptr = normals.GetDataPtr<scalar_t>();
1216 auto colors_ptr = colors.GetDataPtr<scalar_t>();
1218 auto color_gradients_ptr = color_gradients.GetDataPtr<scalar_t>();
1222 int32_t neighbour_offset = max_nn * workload_idx;
1223 int32_t idx_offset = 3 * workload_idx;
1226 points_ptr, normals_ptr, colors_ptr, idx_offset,
1227 neighbour_indices_ptr + neighbour_offset, nn_count,
1228 color_gradients_ptr);
1235 #if defined(__CUDACC__)
1236 void EstimateColorGradientsUsingRadiusSearchCUDA
1244 const double& radius) {
1246 int64_t n =
points.GetLength();
1256 std::tie(indices, distance, counts) =
1263 auto points_ptr =
points.GetDataPtr<scalar_t>();
1264 auto normals_ptr = normals.GetDataPtr<scalar_t>();
1265 auto colors_ptr = colors.GetDataPtr<scalar_t>();
1268 auto color_gradients_ptr = color_gradients.GetDataPtr<scalar_t>();
1273 neighbour_counts_ptr[workload_idx];
1275 const int32_t neighbour_count =
1276 (neighbour_counts_ptr[workload_idx + 1] -
1277 neighbour_counts_ptr[workload_idx]);
1278 int32_t idx_offset = 3 * workload_idx;
1281 points_ptr, normals_ptr, colors_ptr, idx_offset,
1282 neighbour_indices_ptr + neighbour_offset,
1283 neighbour_count, color_gradients_ptr);
#define OPEN3D_HOST_DEVICE
Definition: CUDAUtils.h:44
#define OPEN3D_DEVICE
Definition: CUDAUtils.h:45
#define DISPATCH_DTYPE_TO_TEMPLATE(DTYPE,...)
Definition: Dispatch.h:30
#define DISPATCH_FLOAT_DTYPE_TO_TEMPLATE(DTYPE,...)
Definition: Dispatch.h:77
#define LogError(...)
Definition: Logging.h:48
size_t stride
Definition: TriangleMeshBuffers.cpp:165
T * GetDataPtr()
Definition: Tensor.h:1133
SizeVector GetShape() const
Definition: Tensor.h:1116
Tensor Div(const Tensor &value) const
Divides a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1135
Tensor Contiguous() const
Definition: Tensor.cpp:739
Tensor Transpose(int64_t dim0, int64_t dim1) const
Transpose a Tensor by swapping dimension dim0 and dim1.
Definition: Tensor.cpp:998
Tensor To(Dtype dtype, bool copy=false) const
Definition: Tensor.cpp:706
A Class for nearest neighbor search.
Definition: NearestNeighborSearch.h:25
std::tuple< Tensor, Tensor, Tensor > HybridSearch(const Tensor &query_points, const double radius, const int max_knn) const
Definition: NearestNeighborSearch.cpp:130
bool FixedRadiusIndex(utility::optional< double > radius={})
Definition: NearestNeighborSearch.cpp:40
std::tuple< Tensor, Tensor, Tensor > FixedRadiusSearch(const Tensor &query_points, double radius, bool sort=true)
Definition: NearestNeighborSearch.cpp:98
bool KnnIndex()
Definition: NearestNeighborSearch.cpp:23
bool HybridIndex(utility::optional< double > radius={})
Definition: NearestNeighborSearch.cpp:60
std::pair< Tensor, Tensor > KnnSearch(const Tensor &query_points, int knn)
Definition: NearestNeighborSearch.cpp:79
Definition: GeometryIndexer.h:161
OPEN3D_HOST_DEVICE index_t GetShape(int i) const
Definition: GeometryIndexer.h:311
Definition: Optional.h:259
void Synchronize()
Definition: CUDAUtils.cpp:58
OPEN3D_HOST_DEVICE OPEN3D_FORCE_INLINE void cross_3x1(const scalar_t *A_3x1_input, const scalar_t *B_3x1_input, scalar_t *C_3x1_output)
Definition: Matrix.h:63
OPEN3D_DEVICE OPEN3D_FORCE_INLINE void solve_svd3x3(const scalar_t *A_3x3, const scalar_t *B_3x1, scalar_t *X_3x1)
Definition: SVD3x3.h:2171
OPEN3D_HOST_DEVICE OPEN3D_FORCE_INLINE scalar_t dot_3x1(const scalar_t *A_3x1_input, const scalar_t *B_3x1_input)
Definition: Matrix.h:77
const Dtype Int32
Definition: Dtype.cpp:46
void ParallelFor(const Device &device, int64_t n, const func_t &func)
Definition: ParallelFor.h:103
const Dtype Float32
Definition: Dtype.cpp:42
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t int32_t
Definition: K4aPlugin.cpp:395
void EstimateCovariancesUsingHybridSearchCPU(const core::Tensor &points, core::Tensor &covariances, const double &radius, const int64_t &max_nn)
Definition: PointCloudImpl.h:562
void EstimateCovariancesUsingRadiusSearchCPU(const core::Tensor &points, core::Tensor &covariances, const double &radius)
Definition: PointCloudImpl.h:612
OPEN3D_HOST_DEVICE void GetCoordinateSystemOnPlane(const scalar_t *query, scalar_t *u, scalar_t *v)
Definition: PointCloudImpl.h:336
void UnprojectCPU(const core::Tensor &depth, utility::optional< std::reference_wrapper< const core::Tensor >> image_colors, core::Tensor &points, utility::optional< std::reference_wrapper< core::Tensor >> colors, const core::Tensor &intrinsics, const core::Tensor &extrinsics, float depth_scale, float depth_max, int64_t stride)
Definition: PointCloudImpl.h:45
void EstimateNormalsFromCovariancesCPU(const core::Tensor &covariances, core::Tensor &normals, const bool has_normals)
Definition: PointCloudImpl.h:979
OPEN3D_HOST_DEVICE void ComputeEigenvector0(const scalar_t *A, const scalar_t eval0, scalar_t *eigen_vector0)
Definition: PointCloudImpl.h:710
void OrientNormalsTowardsCameraLocationCPU(const core::Tensor &points, core::Tensor &normals, const core::Tensor &camera)
Definition: PointCloudImpl.h:286
OPEN3D_HOST_DEVICE void EstimatePointWiseRobustNormalizedCovarianceKernel(const scalar_t *points_ptr, const int32_t *indices_ptr, const int32_t &indices_count, scalar_t *covariance_ptr)
Definition: PointCloudImpl.h:482
void GetPointMaskWithinAABBCPU(const core::Tensor &points, const core::Tensor &min_bound, const core::Tensor &max_bound, core::Tensor &mask)
Definition: PointCloudImpl.h:143
OPEN3D_HOST_DEVICE void Swap(scalar_t *x, scalar_t *y)
Definition: PointCloudImpl.h:363
OPEN3D_HOST_DEVICE bool IsBoundaryPoints(const scalar_t *angles, int counts, double angle_threshold)
Definition: PointCloudImpl.h:398
void ComputeBoundaryPointsCPU(const core::Tensor &points, const core::Tensor &normals, const core::Tensor &indices, const core::Tensor &counts, core::Tensor &mask, double angle_threshold)
Definition: PointCloudImpl.h:421
void EstimateColorGradientsUsingKNNSearchCPU(const core::Tensor &points, const core::Tensor &normals, const core::Tensor &colors, core::Tensor &color_gradient, const int64_t &max_nn)
Definition: PointCloudImpl.h:1185
void NormalizeNormalsCPU(core::Tensor &normals)
Definition: PointCloudImpl.h:221
OPEN3D_HOST_DEVICE void ComputeEigenvector1(const scalar_t *A, const scalar_t *evec0, const scalar_t eval1, scalar_t *eigen_vector1)
Definition: PointCloudImpl.h:759
OPEN3D_HOST_DEVICE void EstimatePointWiseColorGradientKernel(const scalar_t *points_ptr, const scalar_t *normals_ptr, const scalar_t *colors_ptr, const int32_t &idx_offset, const int32_t *indices_ptr, const int32_t &indices_count, scalar_t *color_gradients_ptr)
Definition: PointCloudImpl.h:1029
void EstimateColorGradientsUsingRadiusSearchCPU(const core::Tensor &points, const core::Tensor &normals, const core::Tensor &colors, core::Tensor &color_gradient, const double &radius)
Definition: PointCloudImpl.h:1240
void GetPointMaskWithinOBBCPU(const core::Tensor &points, const core::Tensor ¢er, const core::Tensor &rotation, const core::Tensor &extent, core::Tensor &mask)
Definition: PointCloudImpl.h:177
void EstimateColorGradientsUsingHybridSearchCPU(const core::Tensor &points, const core::Tensor &normals, const core::Tensor &colors, core::Tensor &color_gradient, const double &radius, const int64_t &max_nn)
Definition: PointCloudImpl.h:1133
OPEN3D_HOST_DEVICE void EstimatePointWiseNormalsWithFastEigen3x3(const scalar_t *covariance_ptr, scalar_t *normals_ptr)
Definition: PointCloudImpl.h:839
OPEN3D_HOST_DEVICE void Heapify(scalar_t *arr, int n, int root)
Definition: PointCloudImpl.h:370
void OrientNormalsToAlignWithDirectionCPU(core::Tensor &normals, const core::Tensor &direction)
Definition: PointCloudImpl.h:252
void EstimateCovariancesUsingKNNSearchCPU(const core::Tensor &points, core::Tensor &covariances, const int64_t &max_nn)
Definition: PointCloudImpl.h:661
OPEN3D_HOST_DEVICE void HeapSort(scalar_t *arr, int n)
Definition: PointCloudImpl.h:388
TArrayIndexer< int64_t > NDArrayIndexer
Definition: GeometryIndexer.h:360
core::Tensor InverseTransformation(const core::Tensor &T)
TODO(wei): find a proper place for such functionalities.
Definition: Utility.h:77
Definition: PinholeCameraIntrinsic.cpp:16