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

Function main

tools/mesh_sampling.cpp:208–314  ·  view source on GitHub ↗

---[ */

Source from the content-addressed store, hash-verified

206
207/* ---[ */
208int
209main (int argc, char **argv)
210{
211 print_info ("Convert a CAD model to a point cloud using uniform sampling. For more information, use: %s -h\n",
212 argv[0]);
213
214 if (argc < 3)
215 {
216 printHelp (argc, argv);
217 return (-1);
218 }
219
220 // Parse command line arguments
221 int SAMPLE_POINTS_ = default_number_samples;
222 parse_argument (argc, argv, "-n_samples", SAMPLE_POINTS_);
223 float leaf_size = default_leaf_size;
224 parse_argument (argc, argv, "-leaf_size", leaf_size);
225 bool vis_result = ! find_switch (argc, argv, "-no_vis_result");
226 const bool write_normals = find_switch (argc, argv, "-write_normals");
227 const bool write_colors = find_switch (argc, argv, "-write_colors");
228
229 // Parse the command line arguments for .ply and PCD files
230 std::vector<int> pcd_file_indices = parse_file_extension_argument (argc, argv, ".pcd");
231 if (pcd_file_indices.size () != 1)
232 {
233 print_error ("Need a single output PCD file to continue.\n");
234 return (-1);
235 }
236 std::vector<int> ply_file_indices = parse_file_extension_argument (argc, argv, ".ply");
237 std::vector<int> obj_file_indices = parse_file_extension_argument (argc, argv, ".obj");
238 if (ply_file_indices.size () != 1 && obj_file_indices.size () != 1)
239 {
240 print_error ("Need a single input PLY/OBJ file to continue.\n");
241 return (-1);
242 }
243
244 vtkSmartPointer<vtkPolyData> polydata1 = vtkSmartPointer<vtkPolyData>::New ();
245 if (ply_file_indices.size () == 1)
246 {
247 pcl::PolygonMesh mesh;
248 pcl::io::loadPLYFile (argv[ply_file_indices[0]], mesh);
249 pcl::io::mesh2vtk (mesh, polydata1);
250 }
251 else if (obj_file_indices.size () == 1)
252 {
253 vtkSmartPointer<vtkOBJReader> readerQuery = vtkSmartPointer<vtkOBJReader>::New ();
254 readerQuery->SetFileName (argv[obj_file_indices[0]]);
255 readerQuery->Update ();
256 polydata1 = readerQuery->GetOutput ();
257 }
258
259 //make sure that the polygons are triangles!
260 vtkSmartPointer<vtkTriangleFilter> triangleFilter = vtkSmartPointer<vtkTriangleFilter>::New ();
261 triangleFilter->SetInputData (polydata1);
262 triangleFilter->Update ();
263
264 vtkSmartPointer<vtkPolyDataMapper> triangleMapper = vtkSmartPointer<vtkPolyDataMapper>::New ();
265 triangleMapper->SetInputConnection (triangleFilter->GetOutputPort ());

Callers

nothing calls this directly

Calls 12

parse_argumentFunction · 0.85
NewFunction · 0.85
loadPLYFileFunction · 0.85
savePCDFileASCIIFunction · 0.85
copyPointCloudFunction · 0.85
setLeafSizeMethod · 0.80
printHelpFunction · 0.70
uniform_samplingFunction · 0.70
sizeMethod · 0.45
setInputCloudMethod · 0.45
filterMethod · 0.45
spinMethod · 0.45

Tested by

no test coverage detected