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

Function saveMesh

tools/converter.cpp:154–195  ·  view source on GitHub ↗

* Saves a mesh into the specified file and output type. The file format is automatically parsed. * @param input[in] The mesh 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. */

Source from the content-addressed store, hash-verified

152 * @return True on success, false otherwise.
153 */
154bool
155saveMesh (pcl::PolygonMesh& input,
156 std::string output_file,
157 int output_type)
158{
159 if (pcl_fs::path (output_file).extension () == ".obj")
160 {
161 if (output_type == BINARY || output_type == BINARY_COMPRESSED)
162 PCL_WARN ("OBJ file format only supports ASCII.\n");
163
164 //TODO: Support precision
165 //FIXME: Color is lost during conversion (OBJ supports color)
166 PCL_INFO ("Saving file %s as ASCII.\n", output_file.c_str ());
167 if (pcl::io::saveOBJFile (output_file, input) != 0)
168 return (false);
169 }
170 else if (pcl_fs::path (output_file).extension () == ".pcd")
171 {
172 if (!input.polygons.empty ())
173 PCL_WARN ("PCD file format does not support meshes! Only points be saved.\n");
174 pcl::PCLPointCloud2::Ptr cloud = pcl::make_shared<pcl::PCLPointCloud2> (input.cloud);
175 if (!savePointCloud (cloud, output_file, output_type))
176 return (false);
177 }
178 else // PLY, STL and VTK
179 {
180 if (output_type == BINARY_COMPRESSED)
181 PCL_WARN ("PLY, STL and VTK file formats only supports ASCII and binary output file types.\n");
182
183 if (input.polygons.empty() && pcl_fs::path (output_file).extension () == ".stl")
184 {
185 PCL_ERROR ("STL file format does not support point clouds! Aborting.\n");
186 return (false);
187 }
188
189 PCL_INFO ("Saving file %s as %s.\n", output_file.c_str (), (output_type == ASCII) ? "ASCII" : "binary");
190 if (!pcl::io::savePolygonFile (output_file, input, output_type != ASCII))
191 return (false);
192 }
193
194 return (true);
195}
196
197/**
198 * Parse input files and options. Calls the right conversion function.

Callers 2

savePointCloudFunction · 0.85
mainFunction · 0.85

Calls 3

saveOBJFileFunction · 0.85
savePointCloudFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected