-
Notifications
You must be signed in to change notification settings - Fork 7
/
obj2pcd.cpp
67 lines (53 loc) · 2.11 KB
/
obj2pcd.cpp
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
67
//simple point cloud sampler for obj file
//wei jiang
//part of the code from scratchapixel.com, opengl-tutorial.org and learnopengl.com
//using glm, pcl library
//compile command: make
//sample run command:
// default sample density is 100
// ./obj2pcd ../models/monkey_v.obj ../output/monkey.pcd
// use sample density as 200
// ./obj2pcd ../models/monkey_v.obj ../output/monkey.pcd -sample_density 200
// no normals interpolation
// ./obj2pcd ../models/monkey_v.obj ../output/monkey.pcd -sample_density 200 -normal_flag 0
// pcd_viewer
// ./pcd_viewer ../output/monkey.pcd -ps 5 -normals 1 -normals_scale 1
#include <iostream>
#include <vector>
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include "glm/glm.hpp"
#include "glm/gtx/string_cast.hpp"
#include "modelloader.h"
#include "sampler.h"
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_types.h>
#include <pcl/console/parse.h>
using namespace glm;
//do not using namespace std overlap with glm; some common functions abiguous, like min/max
int main(int argc, char **argv)
{
if (argc < 3)
{
pcl::console::print_error("argv: objfile_path pcdfile_path sample_density optioanl_normal_flag optional_flip_flag\n", argv[0]);
return 1;
}
//set sample density
int sample_density = 100;
pcl::console::parse_argument(argc, argv, "-sample_density", sample_density);
bool normal_flag = true;
pcl::console::parse_argument(argc, argv, "-normal_flag", normal_flag);
bool flip = false;
pcl::console::parse_argument(argc, argv, "-flip_flag", flip);
std::cout << "sample_density: " << sample_density << std::endl;
std::cout << "normal_flag: " << normal_flag << std::endl;
std::cout << "flip_flag: " << flip << std::endl;
//set random seed
srand(time(NULL));
Sampler sampler = Sampler(argv[1], normal_flag, flip);
pcl::PointCloud<pcl::PointNormal> out_cloud = sampler.getPointCloud(sample_density);
pcl::io::savePCDFileASCII(argv[2], out_cloud);
std::cerr << "saved " << out_cloud.points.size() << " data points to " << argv[2] << "." << std::endl;
return 0;
}