* Saves a cloud into the specified file and output type. The file format is automatically parsed. * @param input[in] The cloud to be saved * @param output_file[out] The output file to be written * @param output_type[in] The output file type * @return True on success, false otherwise. */
| 99 | * @return True on success, false otherwise. |
| 100 | */ |
| 101 | bool |
| 102 | savePointCloud (const pcl::PCLPointCloud2::Ptr& input, |
| 103 | std::string output_file, |
| 104 | int output_type) |
| 105 | { |
| 106 | if (pcl_fs::path (output_file).extension () == ".pcd") |
| 107 | { |
| 108 | //TODO Support precision, origin, orientation |
| 109 | pcl::PCDWriter w; |
| 110 | if (output_type == ASCII) |
| 111 | { |
| 112 | PCL_INFO ("Saving file %s as ASCII.\n", output_file.c_str ()); |
| 113 | if (w.writeASCII (output_file, *input) != 0) |
| 114 | return (false); |
| 115 | } |
| 116 | else if (output_type == BINARY) |
| 117 | { |
| 118 | PCL_INFO ("Saving file %s as binary.\n", output_file.c_str ()); |
| 119 | if (w.writeBinary (output_file, *input) != 0) |
| 120 | return (false); |
| 121 | } |
| 122 | else if (output_type == BINARY_COMPRESSED) |
| 123 | { |
| 124 | PCL_INFO ("Saving file %s as binary compressed.\n", output_file.c_str ()); |
| 125 | if (w.writeBinaryCompressed (output_file, *input) != 0) |
| 126 | return (false); |
| 127 | } |
| 128 | } |
| 129 | else if (pcl_fs::path (output_file).extension () == ".stl") |
| 130 | { |
| 131 | PCL_ERROR ("STL file format does not support point clouds! Aborting.\n"); |
| 132 | return (false); |
| 133 | } |
| 134 | else // OBJ, PLY and VTK |
| 135 | { |
| 136 | //TODO: Support precision |
| 137 | //FIXME: Color is lost during OBJ conversion (OBJ supports color) |
| 138 | pcl::PolygonMesh mesh; |
| 139 | mesh.cloud = *input; |
| 140 | if (!saveMesh (mesh, output_file, output_type)) |
| 141 | return (false); |
| 142 | } |
| 143 | |
| 144 | return (true); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Saves a mesh into the specified file and output type. The file format is automatically parsed. |
no test coverage detected