|
@@ -64,7 +64,7 @@
|
|
|
#include <pcl_ros/point_cloud.h>
|
|
|
#include <pcl_ros/transforms.h>
|
|
|
|
|
|
-
|
|
|
+#include <ndt_cpu/NormalDistributionsTransform.h>
|
|
|
|
|
|
#include "ndt_matching.h"
|
|
|
|
|
@@ -140,9 +140,12 @@ static int map_loaded = 0;
|
|
|
static int _use_gnss = 1;
|
|
|
static int init_pos_set = 0;
|
|
|
|
|
|
-static pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ> ndt;
|
|
|
+bool gbuseanh = true;
|
|
|
|
|
|
+static pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ> ndt;
|
|
|
|
|
|
+static cpu::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ> anh_ndt;
|
|
|
+static cpu::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ> glocalanh_ndt;
|
|
|
|
|
|
static pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>::Ptr ndtraw(new pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>());
|
|
|
static pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>::Ptr glocalndtraw(new pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>());
|
|
@@ -488,22 +491,41 @@ static void UseMap(int index)
|
|
|
gcurmapindex = index;
|
|
|
|
|
|
|
|
|
+ if(gbuseanh)
|
|
|
+ {
|
|
|
+ cpu::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ> localanhraw;
|
|
|
|
|
|
- pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>::Ptr localndtraw(new pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>());
|
|
|
+ localanhraw.setResolution(ndt_res);
|
|
|
+ localanhraw.setInputTarget(map_ptr);
|
|
|
+ localanhraw.setMaximumIterations(max_iter);
|
|
|
+ localanhraw.setStepSize(step_size);
|
|
|
+ localanhraw.setTransformationEpsilon(trans_eps);
|
|
|
|
|
|
+ pthread_mutex_lock(&mutex);
|
|
|
+ // ndt = glocal_ndt;
|
|
|
+ glocalanh_ndt = localanhraw;
|
|
|
+ pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
- localndtraw->setResolution(ndt_res);
|
|
|
- localndtraw->setInputTarget(map_ptr);
|
|
|
- localndtraw->setMaximumIterations(max_iter);
|
|
|
- localndtraw->setStepSize(step_size);
|
|
|
- localndtraw->setTransformationEpsilon(trans_eps);
|
|
|
+ gbNeedUpdate = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
|
|
|
- pthread_mutex_lock(&mutex);
|
|
|
-// ndt = glocal_ndt;
|
|
|
- glocalndtraw = localndtraw;
|
|
|
- pthread_mutex_unlock(&mutex);
|
|
|
+ pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>::Ptr localndtraw(new pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>());
|
|
|
|
|
|
- gbNeedUpdate = true;
|
|
|
+ localndtraw->setResolution(ndt_res);
|
|
|
+ localndtraw->setInputTarget(map_ptr);
|
|
|
+ localndtraw->setMaximumIterations(max_iter);
|
|
|
+ localndtraw->setStepSize(step_size);
|
|
|
+ localndtraw->setTransformationEpsilon(trans_eps);
|
|
|
+
|
|
|
+ pthread_mutex_lock(&mutex);
|
|
|
+ // ndt = glocal_ndt;
|
|
|
+ glocalndtraw = localndtraw;
|
|
|
+ pthread_mutex_unlock(&mutex);
|
|
|
+
|
|
|
+ gbNeedUpdate = true;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
std::cout<<"change map, index is "<<index<<std::endl;
|
|
@@ -1222,9 +1244,19 @@ void point_ndt(pcl::PointCloud<pcl::PointXYZ>::Ptr raw_scan)
|
|
|
}
|
|
|
if(gbNeedUpdate)
|
|
|
{
|
|
|
- pthread_mutex_lock(&mutex);
|
|
|
- ndtraw = glocalndtraw;
|
|
|
- pthread_mutex_unlock(&mutex);
|
|
|
+ if(gbuseanh)
|
|
|
+ {
|
|
|
+ pthread_mutex_lock(&mutex);
|
|
|
+ anh_ndt = glocalanh_ndt;
|
|
|
+ pthread_mutex_unlock(&mutex);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pthread_mutex_lock(&mutex);
|
|
|
+ ndtraw = glocalndtraw;
|
|
|
+ pthread_mutex_unlock(&mutex);
|
|
|
+ }
|
|
|
+
|
|
|
gusemapindex = gcurmapindex;
|
|
|
gbNeedUpdate = false;
|
|
|
|
|
@@ -1295,7 +1327,20 @@ void point_ndt(pcl::PointCloud<pcl::PointXYZ>::Ptr raw_scan)
|
|
|
// ndt.setInputSource(filtered_scan_ptr);
|
|
|
|
|
|
|
|
|
- ndtraw->setInputSource(filtered_scan_ptr);
|
|
|
+ if(gbuseanh)
|
|
|
+ {
|
|
|
+#ifdef TEST_CALCTIME
|
|
|
+ std::cout<<"use anh."<<std::endl;
|
|
|
+#endif
|
|
|
+ anh_ndt.setInputSource(filtered_scan_ptr);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+#ifdef TEST_CALCTIME
|
|
|
+ std::cout<<"use ndt."<<std::endl;
|
|
|
+#endif
|
|
|
+ ndtraw->setInputSource(filtered_scan_ptr);
|
|
|
+ }
|
|
|
|
|
|
// Guess the initial gross estimation of the transformation
|
|
|
// double diff_time = (current_scan_time - previous_scan_time).toSec();
|
|
@@ -1411,7 +1456,12 @@ void point_ndt(pcl::PointCloud<pcl::PointXYZ>::Ptr raw_scan)
|
|
|
// std::cout<<"time is "<<xTime.elapsed()<<std::endl;
|
|
|
pcl::PointCloud<pcl::PointXYZ>::Ptr aligned(new pcl::PointCloud<pcl::PointXYZ>());
|
|
|
align_start = std::chrono::system_clock::now();
|
|
|
- ndtraw->align(*aligned,init_guess);
|
|
|
+ if(gbuseanh)
|
|
|
+ {
|
|
|
+ anh_ndt.align(*aligned,init_guess);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ ndtraw->align(*aligned,init_guess);
|
|
|
align_end = std::chrono::system_clock::now();
|
|
|
|
|
|
if(xTime.elapsed()<90)
|
|
@@ -1431,16 +1481,27 @@ void point_ndt(pcl::PointCloud<pcl::PointXYZ>::Ptr raw_scan)
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
- has_converged = ndtraw->hasConverged();
|
|
|
-
|
|
|
- t = ndtraw->getFinalTransformation();
|
|
|
- iteration = ndtraw->getFinalNumIteration();
|
|
|
-
|
|
|
- getFitnessScore_start = std::chrono::system_clock::now();
|
|
|
- fitness_score = ndtraw->getFitnessScore();
|
|
|
- getFitnessScore_end = std::chrono::system_clock::now();
|
|
|
+ if(gbuseanh)
|
|
|
+ {
|
|
|
+ has_converged = anh_ndt.hasConverged();
|
|
|
+ t = anh_ndt.getFinalTransformation();
|
|
|
+ iteration = anh_ndt.getFinalNumIteration();
|
|
|
+ getFitnessScore_start = std::chrono::system_clock::now();
|
|
|
+ fitness_score = anh_ndt.getFitnessScore();
|
|
|
+ getFitnessScore_end = std::chrono::system_clock::now();
|
|
|
+ trans_probability = anh_ndt.getTransformationProbability();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ has_converged = ndtraw->hasConverged();
|
|
|
+ t = ndtraw->getFinalTransformation();
|
|
|
+ iteration = ndtraw->getFinalNumIteration();
|
|
|
+ getFitnessScore_start = std::chrono::system_clock::now();
|
|
|
+ fitness_score = ndtraw->getFitnessScore();
|
|
|
+ getFitnessScore_end = std::chrono::system_clock::now();
|
|
|
+ trans_probability = ndtraw->getTransformationProbability();
|
|
|
+ }
|
|
|
|
|
|
- trans_probability = ndtraw->getTransformationProbability();
|
|
|
|
|
|
std::cout<<"score: "<<fitness_score<<" trans_probability:"<<trans_probability<<std::endl;
|
|
|
// std::cout<<" scoure is "<<fitness_score<<std::endl;
|