点群からマーチングキューブス(Hoppe)で面を作成(PCLライブラリ) †
PCLライブラリを使用して、マーチングキューブス法(Hoppe)で点群から面を作成します。
ここでは、ねこの点群を入力にします。
では早速、下のプログラムでマーチングキューブス法で面を作成してみます。
うまくいきません。。ねこの周りに、いらない面が残ってしまいます。0の等値面はどのように定義されているのでしょうか?
pcl_marching_cubes_hoppe.cxx †
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
-
|
|
|
-
|
|
!
|
|
|
-
!
|
|
|
-
!
-
!
|
|
|
|
|
|
|
-
!
-
!
|
-
!
-
!
|
|
-
!
|
|
-
!
|
|
|
-
!
|
|
|
|
|
-
!
!
| #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];
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);
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);
pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals (new pcl::PointCloud<pcl::PointNormal>);
pcl::concatenateFields (*cloud, *normals, *cloud_with_normals);
pcl::search::KdTree<pcl::PointNormal>::Ptr tree2 (new pcl::search::KdTree<pcl::PointNormal>);
tree2->setInputCloud (cloud_with_normals);
pcl::MarchingCubesHoppe<pcl::PointNormal> mc;
pcl::PolygonMesh triangles;
mc.setIsoLevel (0.0);
mc.setGridResolution(100, 100, 100);
mc.setPercentageExtendGrid(0.3f);
mc.setInputCloud (cloud_with_normals);
mc.setSearchMethod (tree2);
mc.reconstruct (triangles);
pcl::io::saveVTKFile (output_file, triangles);
return (0);
}
|
ダウンロードとビルド †
ソースコードとCMakeLists.txtファイル: