|
|
@@ -0,0 +1,52 @@
|
|
|
+//
|
|
|
+// Created by zx on 22-11-23.
|
|
|
+//
|
|
|
+
|
|
|
+#include "ndtMap.h"
|
|
|
+#include <pcl/common/centroid.h>
|
|
|
+Ndt::Ndt()
|
|
|
+{
|
|
|
+ inited_=false;
|
|
|
+}
|
|
|
+Ndt::~Ndt()
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void Ndt::Init(PointCloud::Ptr cloud)
|
|
|
+{
|
|
|
+ Eigen::Vector4f centroid;
|
|
|
+ pcl::compute3DCentroid(*cloud, centroid);
|
|
|
+
|
|
|
+ center_[0] = centroid[0];
|
|
|
+ center_[1] = centroid[0];
|
|
|
+ center_[2] = centroid[0];
|
|
|
+
|
|
|
+ Eigen::MatrixXd M;
|
|
|
+ M.resize(3,cloud->size());
|
|
|
+ for(int i=0;i<cloud->size();++i)
|
|
|
+ {
|
|
|
+ Eigen::Vector3d pt(cloud->points[i].x,cloud->points[i].y,cloud->points[i].z);
|
|
|
+ Eigen::Vector3d diff=pt-center_;
|
|
|
+ M.topLeftCorner(3,1)=diff;
|
|
|
+ }
|
|
|
+ sigma_=M*(M.inverse());
|
|
|
+}
|
|
|
+
|
|
|
+template <class T>
|
|
|
+T Ndt::GetProb(Eigen::Matrix<T,3,1> pt)
|
|
|
+{
|
|
|
+ Eigen::Matrix<T,3,1> center;
|
|
|
+ center<<T(center_[0]),T(center_[1]),T(center_[2]);
|
|
|
+ Eigen::Matrix<T,3,1> point(pt[0],pt[1],pt[2]);
|
|
|
+ Eigen::Matrix<T,3,1> diff=point-center;
|
|
|
+
|
|
|
+ Eigen::Matrix<T,3,3> sigma;
|
|
|
+ sigma<<T(sigma_(0,0)),T(sigma_(0,1)),T(sigma_(0,2)),
|
|
|
+ T(sigma_(1,0)),T(sigma_(1,1)),T(sigma_(1,2)),
|
|
|
+ T(sigma_(2,0)),T(sigma_(2,1)),T(sigma_(2,2));
|
|
|
+
|
|
|
+ Eigen::Matrix<T,1,1> P=diff.transpose()*sigma.inverse()*diff;
|
|
|
+ return std::exp(P(0,0));
|
|
|
+}
|
|
|
+
|