Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 #include <pcl/console/print.h>
00041 #include <pcl/console/parse.h>
00042 #include <pcl/io/vtk_lib_io.h>
00043 
00044 using namespace pcl;
00045 using namespace pcl::io;
00046 using namespace pcl::console;
00047 
00048 void
00049 printHelp (int, char **argv)
00050 {
00051   print_error ("Syntax is: %s input.vtk output.ply\n", argv[0]);
00052 }
00053 
00054 
00055 int
00056 main (int argc, char** argv)
00057 {
00058   print_info ("Convert a VTK file to PLY format. For more information, use: %s -h\n", argv[0]);
00059 
00060   if (argc < 3)
00061   {
00062     printHelp (argc, argv);
00063     return (-1);
00064   }
00065 
00066   
00067   std::vector<int> vtk_file_indices = parse_file_extension_argument (argc, argv, ".vtk");
00068   std::vector<int> ply_file_indices = parse_file_extension_argument (argc, argv, ".ply");
00069   if (vtk_file_indices.size () != 1 || ply_file_indices.size () != 1)
00070   {
00071     print_error ("Need one input VTK file and one output PLY file.\n");
00072     return (-1);
00073   }
00074 
00075   
00076   vtkSmartPointer<vtkPolyData> polydata;
00077   vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New ();
00078   reader->SetFileName (argv[vtk_file_indices[0]]);
00079   polydata = reader->GetOutput ();
00080   polydata->Update ();
00081   print_info ("Loaded %s with %zu points/vertices.\n", argv[vtk_file_indices[0]], polydata->GetNumberOfPoints ());
00082 
00083   
00084   vtkSmartPointer<vtkPLYWriter> writer = vtkSmartPointer<vtkPLYWriter>::New ();
00085   writer->SetInput (polydata);
00086   writer->SetArrayName ("Colors");
00087   writer->SetFileTypeToASCII ();
00088   writer->SetFileName (argv[ply_file_indices[0]]);
00089   writer->Write ();
00090 
00091   return (0);
00092 }
00093