MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / main

Function main

tools/obj2pcd.cpp:76–135  ·  view source on GitHub ↗

---[ */

Source from the content-addressed store, hash-verified

74
75/* ---[ */
76int
77main (int argc, char** argv)
78{
79 print_info ("Convert a OBJ file to PCD format. For more information, use: %s -h\n", argv[0]);
80
81 if (argc < 3)
82 {
83 printHelp (argc, argv);
84 return (-1);
85 }
86
87 // Parse the command line arguments for .pcd and .obj files
88 std::vector<int> pcd_file_indices = parse_file_extension_argument (argc, argv, ".pcd");
89 std::vector<int> obj_file_indices = parse_file_extension_argument (argc, argv, ".obj");
90 if (pcd_file_indices.size () != 1 || obj_file_indices.size () != 1)
91 {
92 print_error ("Need one input OBJ file and one output PCD file.\n");
93 return (-1);
94 }
95
96 // Load the OBJ file
97 TicToc tt;
98 print_highlight ("Loading "); print_value ("%s ", argv[obj_file_indices[0]]);
99
100 // Load the input file
101 vtkSmartPointer<vtkPolyData> polydata;
102 vtkSmartPointer<vtkOBJReader> reader = vtkSmartPointer<vtkOBJReader>::New ();
103 reader->SetFileName (argv[obj_file_indices[0]]);
104 reader->Update ();
105 polydata = reader->GetOutput ();
106 print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : "); print_value ("%d", polydata->GetNumberOfPoints ()); print_info (" points]\n");
107
108 bool copy_normals = false;
109 parse_argument (argc, argv, "-copy_normals", copy_normals);
110 PCL_INFO ("Copy normals: %s.\n", copy_normals ? "true" : "false");
111
112 if (copy_normals)
113 {
114 vtkSmartPointer<vtkPolyDataNormals> ng = vtkSmartPointer<vtkPolyDataNormals>::New ();
115 ng->SetInputData (polydata);
116 ng->ComputePointNormalsOn ();
117 ng->ComputeCellNormalsOff ();
118 ng->Update ();
119 polydata = ng->GetOutput ();
120
121 pcl::PointCloud<pcl::PointNormal> cloud;
122 vtkPolyDataToPointCloud (polydata, cloud);
123 // Convert to pcd and save
124 saveCloud (argv[pcd_file_indices[0]], cloud);
125 }
126 else
127 {
128 pcl::PointCloud<pcl::PointXYZ> cloud;
129 vtkPolyDataToPointCloud (polydata, cloud);
130 // Convert to pcd and save
131 saveCloud (argv[pcd_file_indices[0]], cloud);
132 }
133

Callers

nothing calls this directly

Calls 7

print_valueFunction · 0.85
NewFunction · 0.85
parse_argumentFunction · 0.85
tocMethod · 0.80
printHelpFunction · 0.70
saveCloudFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected