|
@@ -59,7 +59,7 @@
|
|
|
|
|
|
#include <QFile>
|
|
|
|
|
|
-#include <ndt_gpu/NormalDistributionsTransform.h>
|
|
|
+//#include <ndt_gpu/NormalDistributionsTransform.h>
|
|
|
#include "ndtpos.pb.h"
|
|
|
#include "ndtgpspos.pb.h"
|
|
|
|
|
@@ -147,17 +147,13 @@ static int _use_gnss = 1;
|
|
|
static int init_pos_set = 0;
|
|
|
|
|
|
static pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ> ndt;
|
|
|
-//static cpu::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ> anh_ndt;
|
|
|
-#ifdef CUDA_FOUND
|
|
|
-static std::shared_ptr<gpu::GNormalDistributionsTransform> anh_gpu_ndt_ptr =
|
|
|
- std::make_shared<gpu::GNormalDistributionsTransform>();
|
|
|
-#endif
|
|
|
-#ifdef USE_PCL_OPENMP
|
|
|
-static pcl_omp::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ> omp_ndt;
|
|
|
-#endif
|
|
|
+
|
|
|
|
|
|
pclomp::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>::Ptr ndt_omp(new pclomp::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>());
|
|
|
|
|
|
+pclomp::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>::Ptr glocalndt_omp(new pclomp::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>());
|
|
|
+
|
|
|
+
|
|
|
// Default values
|
|
|
static int max_iter = 30; // Maximum iterations
|
|
|
static float ndt_res = 1.0; // Resolution
|
|
@@ -304,7 +300,6 @@ static bool gbGFRun = true;
|
|
|
static bool gbLMRun= true;
|
|
|
static std::thread * gpmapthread, * gpgpsfixthread,*gpsavelastthread;
|
|
|
static bool gbNeedUpdate = false;
|
|
|
-static std::shared_ptr<gpu::GNormalDistributionsTransform> glocal_ndt;
|
|
|
|
|
|
extern iv::gpspos glastndtgpspos;
|
|
|
extern iv::gpspos gcurndtgpspos;
|
|
@@ -467,7 +462,6 @@ static void getmindistrace(int & index, double & ftracedis)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-std::vector<std::shared_ptr<gpu::GNormalDistributionsTransform>> gvectoranh;
|
|
|
#include <QTime>
|
|
|
|
|
|
extern void pausecomm();
|
|
@@ -493,42 +487,44 @@ static void UseMap(int index)
|
|
|
|
|
|
qDebug("load map time is %d",xTime.elapsed());
|
|
|
|
|
|
- pausecomm(); //Because cuda can pause process, avoid mutex comm, stop this process's comm
|
|
|
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
pcl::PointCloud<pcl::PointXYZ>::Ptr map_ptr(new pcl::PointCloud<pcl::PointXYZ>(*xmap));
|
|
|
+// gvectoranh.push_back(new_anh_gpu_ndt_ptr);
|
|
|
|
|
|
- std::shared_ptr<gpu::GNormalDistributionsTransform> new_anh_gpu_ndt_ptr =
|
|
|
- std::make_shared<gpu::GNormalDistributionsTransform>();
|
|
|
- new_anh_gpu_ndt_ptr->setResolution(ndt_res);
|
|
|
- new_anh_gpu_ndt_ptr->setInputTarget(map_ptr);
|
|
|
- new_anh_gpu_ndt_ptr->setMaximumIterations(max_iter);
|
|
|
- new_anh_gpu_ndt_ptr->setStepSize(step_size);
|
|
|
- new_anh_gpu_ndt_ptr->setTransformationEpsilon(trans_eps);
|
|
|
+ qDebug("ndt load finish time is %d",xTime.elapsed());
|
|
|
|
|
|
- pcl::PointCloud<pcl::PointXYZ>::Ptr dummy_scan_ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
|
- pcl::PointXYZ dummy_point;
|
|
|
- dummy_scan_ptr->push_back(dummy_point);
|
|
|
- new_anh_gpu_ndt_ptr->setInputSource(dummy_scan_ptr);
|
|
|
+ gcurmapindex = index;
|
|
|
+
|
|
|
+ std::cout<<" max threads. "<<omp_get_max_threads()<<std::endl;
|
|
|
+
|
|
|
+ int nthread = omp_get_max_threads();
|
|
|
+ nthread = nthread - 2;
|
|
|
+ if(nthread <1)nthread = 1;
|
|
|
|
|
|
- new_anh_gpu_ndt_ptr->align(Eigen::Matrix4f::Identity());
|
|
|
+ std::cout<<" use threads: "<<nthread<<std::endl;
|
|
|
+
|
|
|
+ pclomp::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>::Ptr localndt_omp(new pclomp::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ localndt_omp->setNumThreads(nthread);
|
|
|
+ localndt_omp->setNeighborhoodSearchMethod(pclomp::DIRECT7);
|
|
|
+
|
|
|
+
|
|
|
+ localndt_omp->setResolution(ndt_res);
|
|
|
+ localndt_omp->setInputTarget(map_ptr);
|
|
|
+ localndt_omp->setMaximumIterations(max_iter);
|
|
|
+ localndt_omp->setStepSize(step_size);
|
|
|
+ localndt_omp->setTransformationEpsilon(trans_eps);
|
|
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
- glocal_ndt = new_anh_gpu_ndt_ptr;
|
|
|
+// ndt = glocal_ndt;
|
|
|
+ glocalndt_omp = localndt_omp;
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
- continuecomm();
|
|
|
-// gvectoranh.push_back(new_anh_gpu_ndt_ptr);
|
|
|
-
|
|
|
- qDebug("ndt load finish time is %d",xTime.elapsed());
|
|
|
gbNeedUpdate = true;
|
|
|
- gcurmapindex = index;
|
|
|
|
|
|
- ndt_omp->setResolution(ndt_res);
|
|
|
- ndt_omp->setInputTarget(map_ptr);
|
|
|
- ndt_omp->setMaximumIterations(max_iter);
|
|
|
- ndt_omp->setStepSize(step_size);
|
|
|
- ndt_omp->setTransformationEpsilon(trans_eps);
|
|
|
- std::cout<<" ndt_omp init success. "<<std::endl;
|
|
|
+
|
|
|
+ std::cout<<" ndt_omp init successfully. "<<std::endl;
|
|
|
|
|
|
|
|
|
std::cout<<"change map, index is "<<index<<std::endl;
|
|
@@ -740,17 +736,6 @@ void ndt_match_Init(pcl::PointCloud<pcl::PointXYZ>::Ptr mappcd)
|
|
|
angular_velocity = 0;
|
|
|
|
|
|
|
|
|
-// ndt.setResolution(ndt_res);
|
|
|
-// ndt.setStepSize(step_size);
|
|
|
-// ndt.setTransformationEpsilon(trans_eps);
|
|
|
-// ndt.setMaximumIterations(max_iter);
|
|
|
-
|
|
|
- // anh_gpu_ndt_ptr->setResolution();
|
|
|
-
|
|
|
- anh_gpu_ndt_ptr->setResolution(ndt_res);
|
|
|
- anh_gpu_ndt_ptr->setStepSize(step_size);
|
|
|
- anh_gpu_ndt_ptr->setTransformationEpsilon(trans_eps);
|
|
|
- anh_gpu_ndt_ptr->setMaximumIterations(max_iter);
|
|
|
|
|
|
|
|
|
// ndt.align(*output_cloud, Eigen::Matrix4f::Identity());
|
|
@@ -790,30 +775,22 @@ void ndt_match_Init(pcl::PointCloud<pcl::PointXYZ>::Ptr mappcd)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- std::shared_ptr<gpu::GNormalDistributionsTransform> new_anh_gpu_ndt_ptr =
|
|
|
- std::make_shared<gpu::GNormalDistributionsTransform>();
|
|
|
- new_anh_gpu_ndt_ptr->setResolution(ndt_res);
|
|
|
- new_anh_gpu_ndt_ptr->setInputTarget(map_ptr);
|
|
|
- new_anh_gpu_ndt_ptr->setMaximumIterations(max_iter);
|
|
|
- new_anh_gpu_ndt_ptr->setStepSize(step_size);
|
|
|
- new_anh_gpu_ndt_ptr->setTransformationEpsilon(trans_eps);
|
|
|
+
|
|
|
|
|
|
pcl::PointCloud<pcl::PointXYZ>::Ptr dummy_scan_ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
|
pcl::PointXYZ dummy_point;
|
|
|
dummy_scan_ptr->push_back(dummy_point);
|
|
|
- new_anh_gpu_ndt_ptr->setInputSource(dummy_scan_ptr);
|
|
|
|
|
|
- new_anh_gpu_ndt_ptr->align(Eigen::Matrix4f::Identity());
|
|
|
-
|
|
|
- pthread_mutex_lock(&mutex);
|
|
|
- anh_gpu_ndt_ptr = new_anh_gpu_ndt_ptr;
|
|
|
- pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
ndt_omp->setResolution(ndt_res);
|
|
|
ndt_omp->setInputTarget(map_ptr);
|
|
|
ndt_omp->setMaximumIterations(max_iter);
|
|
|
ndt_omp->setStepSize(step_size);
|
|
|
ndt_omp->setTransformationEpsilon(trans_eps);
|
|
|
+
|
|
|
+ ndt_omp->setNumThreads(6);
|
|
|
+ ndt_omp->setNeighborhoodSearchMethod(pclomp::DIRECT7);
|
|
|
+
|
|
|
std::cout<<" ndt_omp init success. "<<std::endl;
|
|
|
|
|
|
|
|
@@ -883,10 +860,6 @@ void ndt_match_Init_nomap()
|
|
|
current_velocity_z = 0;
|
|
|
angular_velocity = 0;
|
|
|
|
|
|
- anh_gpu_ndt_ptr->setResolution(ndt_res);
|
|
|
- anh_gpu_ndt_ptr->setStepSize(step_size);
|
|
|
- anh_gpu_ndt_ptr->setTransformationEpsilon(trans_eps);
|
|
|
- anh_gpu_ndt_ptr->setMaximumIterations(max_iter);
|
|
|
|
|
|
gpmapthread = new std::thread(LocalMapUpdate,1);
|
|
|
gbGFRun = true;
|
|
@@ -906,35 +879,15 @@ void ndt_match_SetMap(pcl::PointCloud<pcl::PointXYZ>::Ptr mappcd)
|
|
|
pcl::PointCloud<pcl::PointXYZ>::Ptr map_ptr(new pcl::PointCloud<pcl::PointXYZ>(*mappcd));
|
|
|
|
|
|
|
|
|
- std::shared_ptr<gpu::GNormalDistributionsTransform> new_anh_gpu_ndt_ptr =
|
|
|
- std::make_shared<gpu::GNormalDistributionsTransform>();
|
|
|
- new_anh_gpu_ndt_ptr->setResolution(ndt_res);
|
|
|
- new_anh_gpu_ndt_ptr->setInputTarget(map_ptr);
|
|
|
- new_anh_gpu_ndt_ptr->setMaximumIterations(max_iter);
|
|
|
- new_anh_gpu_ndt_ptr->setStepSize(step_size);
|
|
|
- new_anh_gpu_ndt_ptr->setTransformationEpsilon(trans_eps);
|
|
|
+
|
|
|
|
|
|
pcl::PointCloud<pcl::PointXYZ>::Ptr dummy_scan_ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
|
pcl::PointXYZ dummy_point;
|
|
|
dummy_scan_ptr->push_back(dummy_point);
|
|
|
- new_anh_gpu_ndt_ptr->setInputSource(dummy_scan_ptr);
|
|
|
|
|
|
- new_anh_gpu_ndt_ptr->align(Eigen::Matrix4f::Identity());
|
|
|
|
|
|
- pthread_mutex_lock(&mutex);
|
|
|
- anh_gpu_ndt_ptr = new_anh_gpu_ndt_ptr;
|
|
|
- pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
|
|
|
- ndt_omp->setResolution(ndt_res);
|
|
|
- ndt_omp->setInputTarget(map_ptr);
|
|
|
- ndt_omp->setMaximumIterations(max_iter);
|
|
|
- ndt_omp->setStepSize(step_size);
|
|
|
- ndt_omp->setTransformationEpsilon(trans_eps);
|
|
|
-
|
|
|
- ndt_omp->setNumThreads(6);
|
|
|
- ndt_omp->setNeighborhoodSearchMethod(pclomp::DIRECT7);
|
|
|
- std::cout<<" ndt_omp init success. "<<std::endl;
|
|
|
|
|
|
|
|
|
|
|
@@ -1298,8 +1251,7 @@ void point_ndt(pcl::PointCloud<pcl::PointXYZ>::Ptr raw_scan)
|
|
|
if(gbNeedUpdate)
|
|
|
{
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
-// ndt = glocal_ndt;
|
|
|
- anh_gpu_ndt_ptr = glocal_ndt;
|
|
|
+ ndt_omp = glocalndt_omp;
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
gusemapindex = gcurmapindex;
|
|
|
gbNeedUpdate = false;
|