点群からマーチングキューブス(Hoppe)で面を作成(PCLライブラリ)†
PCLライブラリを使用して、マーチングキューブス法(Hoppe)で点群から面を作成します。
ここでは、ねこの点群を入力にします。
では早速、下のプログラムでマーチングキューブス法で面を作成してみます。
うまくいきません。。ねこの周りに、いらない面が残ってしまいます。0の等値面はどのように定義されているのでしょうか?
pcl_marching_cubes_hoppe.cxx†
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/vtk_io.h>
#include <pcl/features/normal_3d.h>
#include <pcl/surface/marching_cubes_hoppe.h>
int
main (int argc, char** argv)
{
std::string input_file, output_file;
if (argc < 3)
{
printf ("\nUsage: marching_cubes_hoppe pcd<PointXYZ>-in-file vtk-out-file\n\n");
exit(0);
}
input_file = argv[1];
output_file = argv[2];
// Load input file into a PointCloud<T> with an appropriate type
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PCLPointCloud2 cloud_blob;
pcl::io::loadPCDFile (input_file, cloud_blob);
pcl::fromPCLPointCloud2 (cloud_blob, *cloud);
//* the data should be available in cloud
// Normal estimation*
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n;
pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);
tree->setInputCloud (cloud);
n.setInputCloud (cloud);
n.setSearchMethod (tree);
n.setKSearch (20);
n.compute (*normals);
//* normals should not contains the point normals + surface curvatures
// Concatenate the XYZ and normal fields*
pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals (new pcl::PointCloud<pcl::PointNormal>);
pcl::concatenateFields (*cloud, *normals, *cloud_with_normals);
//* cloud_with_normals = cloud + normals
// Create search tree
pcl::search::KdTree<pcl::PointNormal>::Ptr tree2 (new pcl::search::KdTree<pcl::PointNormal>);
tree2->setInputCloud (cloud_with_normals);
// Initialize objects
pcl::MarchingCubesHoppe<pcl::PointNormal> mc;
pcl::PolygonMesh triangles;
// Set parameters
mc.setIsoLevel (0.0);
mc.setGridResolution(100, 100, 100);
mc.setPercentageExtendGrid(0.3f);
// Get result
mc.setInputCloud (cloud_with_normals);
mc.setSearchMethod (tree2);
mc.reconstruct (triangles);
pcl::io::saveVTKFile (output_file, triangles);
// Finish
return (0);
}
ダウンロードとビルド†
ソースコードとCMakeLists.txtファイル:
添付ファイル:
pcl_marching_cubes_hoppe.zip 1294件
[詳細]
neko_surface1.png 2006件
[詳細]
neko_cloud_ponits.png 2061件
[詳細]
Last-modified: 2014-05-23 (金) 19:00:20

