39 #ifndef PCL_SURFACE_IMPL_MARCHING_CUBES_RBF_H_
40 #define PCL_SURFACE_IMPL_MARCHING_CUBES_RBF_H_
42 #include <pcl/surface/marching_cubes_rbf.h>
43 #include <pcl/common/common.h>
44 #include <pcl/common/vector_average.h>
45 #include <pcl/Vertices.h>
46 #include <pcl/kdtree/kdtree_flann.h>
49 template <
typename Po
intNT>
52 off_surface_epsilon_ (0.1f)
57 template <
typename Po
intNT>
63 template <
typename Po
intNT>
void
67 unsigned int N =
static_cast<unsigned int> (input_->size ());
68 Eigen::MatrixXd M (2*N, 2*N),
71 for (
unsigned int row_i = 0; row_i < 2*N; ++row_i)
74 bool row_off = (row_i >= N) ? 1 : 0;
75 for (
unsigned int col_i = 0; col_i < 2*N; ++col_i)
78 bool col_off = (col_i >= N) ? 1 : 0;
79 M (row_i, col_i) = kernel (Eigen::Vector3f (input_->points[col_i%N].getVector3fMap ()).cast<double> () + Eigen::Vector3f (input_->points[col_i%N].getNormalVector3fMap ()).cast<double> () * col_off * off_surface_epsilon_,
80 Eigen::Vector3f (input_->points[row_i%N].getVector3fMap ()).cast<double> () + Eigen::Vector3f (input_->points[row_i%N].getNormalVector3fMap ()).cast<double> () * row_off * off_surface_epsilon_);
83 d (row_i, 0) = row_off * off_surface_epsilon_;
87 Eigen::MatrixXd w (2*N, 1);
90 w = M.fullPivLu ().solve (d);
92 std::vector<double> weights (2*N);
93 std::vector<Eigen::Vector3d> centers (2*N);
94 for (
unsigned int i = 0; i < N; ++i)
96 centers[i] = Eigen::Vector3f (input_->points[i].getVector3fMap ()).cast<double> ();
97 centers[i + N] = Eigen::Vector3f (input_->points[i].getVector3fMap ()).cast<double> () + Eigen::Vector3f (input_->points[i].getNormalVector3fMap ()).cast<double> () * off_surface_epsilon_;
98 weights[i] = w (i, 0);
99 weights[i + N] = w (i + N, 0);
102 for (
int x = 0; x < res_x_; ++x)
103 for (
int y = 0; y < res_y_; ++y)
104 for (
int z = 0; z < res_z_; ++z)
106 Eigen::Vector3d point;
107 point[0] = min_p_[0] + (max_p_[0] - min_p_[0]) *
float (x) / float (res_x_);
108 point[1] = min_p_[1] + (max_p_[1] - min_p_[1]) *
float (y) / float (res_y_);
109 point[2] = min_p_[2] + (max_p_[2] - min_p_[2]) *
float (z) / float (res_z_);
112 std::vector<double>::const_iterator w_it (weights.begin());
113 for (std::vector<Eigen::Vector3d>::const_iterator c_it = centers.begin ();
114 c_it != centers.end (); ++c_it, ++w_it)
115 f += *w_it * kernel (*c_it, point);
117 grid_[x * res_y_*res_z_ + y * res_z_ + z] = float (f);
122 template <
typename Po
intNT>
double
125 double r = (x - c).norm ();
129 #define PCL_INSTANTIATE_MarchingCubesRBF(T) template class PCL_EXPORTS pcl::MarchingCubesRBF<T>;
131 #endif // PCL_SURFACE_IMPL_MARCHING_CUBES_HOPPE_H_
double kernel(Eigen::Vector3d c, Eigen::Vector3d x)
the Radial Basis Function kernel.
~MarchingCubesRBF()
Destructor.
The marching cubes surface reconstruction algorithm.
MarchingCubesRBF()
Constructor.
void voxelizeData()
Convert the point cloud into voxel data.