From c1126ecfb6535d0199827615676a92b648b98a16 Mon Sep 17 00:00:00 2001
From: Markus Vieth <mvieth@techfak.uni-bielefeld.de>
Date: Thu, 6 Aug 2026 15:26:55 +0200
Subject: [PATCH] Replace deprecated thrust function, fix problems with thrust

---
 cuda/io/src/disparity_to_cloud.cu   | 14 +++++++-------
 gpu/features/src/centroid.cu        |  9 +++++++++
 gpu/surface/src/cuda/convex_hull.cu |  5 +++++
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/cuda/io/src/disparity_to_cloud.cu b/cuda/io/src/disparity_to_cloud.cu
index 877f1d63585..29fd3fb3260 100644
--- a/cuda/io/src/disparity_to_cloud.cu
+++ b/cuda/io/src/disparity_to_cloud.cu
@@ -222,14 +222,14 @@ DisparityToCloud::compute (const std::uint16_t* depth_image,
 
     for (int iter = 0; iter < smoothing_nr_iterations; iter++)
     {
-      transform (
+      thrust::transform (
           thrust::make_zip_iterator (make_tuple (depth.begin (), thrust::counting_iterator<int>(0))),
           thrust::make_zip_iterator (make_tuple (depth.begin (), thrust::counting_iterator<int>(0))) + output_size,
           depth.begin (), DisparityClampedSmoothing (thrust::raw_pointer_cast(&depth[0]), thrust::raw_pointer_cast(&disp_helper_map[0]), width, height, smoothing_filter_size));
     }
 
     // Send the data to the device
-    transform (
+    thrust::transform (
         thrust::make_zip_iterator (make_tuple (depth.begin (), rgb.begin(), thrust::counting_iterator<int>(0))),
         thrust::make_zip_iterator (make_tuple (depth.begin (), rgb.begin(), thrust::counting_iterator<int>(0))) + output_size,
         output->points.begin (), 
@@ -238,7 +238,7 @@ DisparityToCloud::compute (const std::uint16_t* depth_image,
   }
   else
   {
-    transform (
+    thrust::transform (
         thrust::make_zip_iterator (make_tuple (depth.begin(), rgb.begin(), thrust::counting_iterator<int>(0))),
         thrust::make_zip_iterator (make_tuple (depth.begin(), rgb.begin(), thrust::counting_iterator<int>(0))) + output_size,
         output->points.begin (), 
@@ -356,14 +356,14 @@ DisparityToCloud::compute (const openni_wrapper::DepthImage::Ptr& depth_image,
 
     for (int iter = 0; iter < smoothing_nr_iterations; iter++)
     {
-      transform (
+      thrust::transform (
           thrust::make_zip_iterator (make_tuple (depth.begin (), thrust::counting_iterator<int>(0))),
           thrust::make_zip_iterator (make_tuple (depth.begin (), thrust::counting_iterator<int>(0))) + output_size,
           depth.begin (), DisparityClampedSmoothing (thrust::raw_pointer_cast(&depth[0]), thrust::raw_pointer_cast(&disp_helper_map[0]), output->width, output->height, smoothing_filter_size));
     }
 
     // Send the data to the device
-    transform (
+    thrust::transform (
         thrust::make_zip_iterator (make_tuple (depth.begin (), rgb.begin (), thrust::counting_iterator<int>(0))),
         thrust::make_zip_iterator (make_tuple (depth.begin (), rgb.begin (), thrust::counting_iterator<int>(0))) + output_size,
         output->points.begin (), 
@@ -404,7 +404,7 @@ DisparityToCloud::compute (const openni_wrapper::DepthImage::Ptr& depth_image,
     else
     {
       // Send the data to the device
-      transform (
+      thrust::transform (
           thrust::make_zip_iterator (make_tuple (depth.begin (), rgb.begin (), thrust::counting_iterator<int>(0))),
           thrust::make_zip_iterator (make_tuple (depth.begin (), rgb.begin (), thrust::counting_iterator<int>(0))) + output_size,
           output->points.begin (), 
@@ -415,7 +415,7 @@ DisparityToCloud::compute (const openni_wrapper::DepthImage::Ptr& depth_image,
   else
   {
     // Send the data to the device
-    transform (
+    thrust::transform (
         thrust::make_zip_iterator (make_tuple (depth.begin (), thrust::counting_iterator<int>(0))),
         thrust::make_zip_iterator (make_tuple (depth.begin (), thrust::counting_iterator<int>(0))) + 
                            output->width * output->height,
diff --git a/gpu/features/src/centroid.cu b/gpu/features/src/centroid.cu
index 1dbd029cdf6..4761ece9e32 100644
--- a/gpu/features/src/centroid.cu
+++ b/gpu/features/src/centroid.cu
@@ -36,6 +36,7 @@
 
 #include "internal.hpp"
 
+#include <thrust/version.h>
 #include <thrust/tuple.h>
 #include <thrust/device_ptr.h>
 #include <thrust/transform_reduce.h>
@@ -123,7 +124,11 @@ float3 pcl::device::getMaxDistance(const DeviceArray<PointT>& cloud, const float
     thrust::counting_iterator<int> ce = cf + cloud.size();
 
     thrust::tuple<float, int> init(0.f, 0);
+#if THRUST_VERSION >= 300100
+    cuda::maximum<thrust::tuple<float, int>> op;
+#else
     thrust::maximum<thrust::tuple<float, int>> op;
+#endif
 
     thrust::tuple<float, int> res =
         thrust::transform_reduce(
@@ -151,7 +156,11 @@ float3 pcl::device::getMaxDistance(const DeviceArray<PointT>& cloud, const Indic
     thrust::counting_iterator<int> ce = cf + indices.size();
 
     thrust::tuple<float, int> init(0.f, 0);
+#if THRUST_VERSION >= 300100
+    cuda::maximum<thrust::tuple<float, int>> op;
+#else
     thrust::maximum<thrust::tuple<float, int>> op;
+#endif
 
     thrust::tuple<float, int> res = thrust::transform_reduce(
         make_zip_iterator(make_tuple( make_permutation_iterator(src_beg, map_beg), cf )),
diff --git a/gpu/surface/src/cuda/convex_hull.cu b/gpu/surface/src/cuda/convex_hull.cu
index 00b49dc082f..13417c8be9c 100644
--- a/gpu/surface/src/cuda/convex_hull.cu
+++ b/gpu/surface/src/cuda/convex_hull.cu
@@ -44,6 +44,7 @@
 //#include <pcl/gpu/utils/device/funcattrib.hpp>
 #include <pcl/gpu/utils/safe_call.hpp>
 
+#include <thrust/distance.h>
 #include <thrust/tuple.h>
 #include <thrust/iterator/counting_iterator.h>
 #include <thrust/iterator/zip_iterator.h>
@@ -136,7 +137,11 @@ namespace pcl
       int transform_reduce_index(It beg, It end, Unary unop, Init init, Binary binary)
 	  {
 	    thrust::counting_iterator<int> cbeg(0);
+#if THRUST_VERSION >= 300100
+		thrust::counting_iterator<int> cend = cbeg + cuda::std::distance(beg, end);
+#else
 		thrust::counting_iterator<int> cend = cbeg + thrust::distance(beg, end);
+#endif
 
 	    thrust::tuple<float, int> t = thrust::transform_reduce(
 		  thrust::make_zip_iterator(thrust::make_tuple(beg, cbeg)),
