Skip to content

Commit

Permalink
Improve return value of savePolygonFile* methods
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorLamoine committed Jul 30, 2015
1 parent 0920162 commit 4ee1941
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
12 changes: 8 additions & 4 deletions io/include/pcl/io/vtk_lib_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ namespace pcl
/** \brief Save a \ref PolygonMesh object given an input file name, based on the file extension
* \param[in] file_name the name of the file to save the data to
* \param[in] mesh the object that contains the data
* \return True if successful, false otherwise
* \ingroup io
*/
PCL_EXPORTS int
PCL_EXPORTS bool
savePolygonFile (const std::string &file_name,
const pcl::PolygonMesh& mesh);

Expand Down Expand Up @@ -177,27 +178,30 @@ namespace pcl
/** \brief Save a \ref PolygonMesh object into a VTK file
* \param[in] file_name the name of the file to save the data to
* \param[in] mesh the object that contains the data
* \return True if successful, false otherwise
* \ingroup io
*/
PCL_EXPORTS int
PCL_EXPORTS bool
savePolygonFileVTK (const std::string &file_name,
const pcl::PolygonMesh& mesh);

/** \brief Save a \ref PolygonMesh object into a PLY file
* \param[in] file_name the name of the file to save the data to
* \param[in] mesh the object that contains the data
* \return True if successful, false otherwise
* \ingroup io
*/
PCL_EXPORTS int
PCL_EXPORTS bool
savePolygonFilePLY (const std::string &file_name,
const pcl::PolygonMesh& mesh);

/** \brief Save a \ref PolygonMesh object into an STL file
* \param[in] file_name the name of the file to save the data to
* \param[in] mesh the object that contains the data
* \return True if successful, false otherwise
* \ingroup io
*/
PCL_EXPORTS int
PCL_EXPORTS bool
savePolygonFileSTL (const std::string &file_name,
const pcl::PolygonMesh& mesh);

Expand Down
25 changes: 9 additions & 16 deletions io/src/vtk_lib_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,18 @@ pcl::io::loadPolygonFile (const std::string &file_name, pcl::PolygonMesh& mesh)
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int
bool
pcl::io::savePolygonFile (const std::string &file_name, const pcl::PolygonMesh& mesh)
{
// TODO: what about binary/ASCII modes?!?!?!
// TODO: what about sensor position and orientation?!?!?!?
// TODO: how to adequately catch exceptions thrown by the vtk writers?!
std::string extension = file_name.substr (file_name.find_last_of (".") + 1);
if (extension == "pcd") // no Polygon, but only a point cloud
{
int error_code = pcl::io::savePCDFile (file_name, mesh.cloud);
if (error_code != 0)
return (0);
return (static_cast<int> (mesh.cloud.width * mesh.cloud.height));
return (false);
return (true);
}
else if (extension == "vtk")
return (pcl::io::savePolygonFileVTK (file_name, mesh));
Expand Down Expand Up @@ -171,7 +170,7 @@ pcl::io::loadPolygonFileSTL (const std::string &file_name, pcl::PolygonMesh& mes
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int
bool
pcl::io::savePolygonFileVTK (const std::string &file_name, const pcl::PolygonMesh& mesh)
{
vtkSmartPointer<vtkPolyData> poly_data = vtkSmartPointer<vtkPolyData>::New ();
Expand All @@ -185,13 +184,11 @@ pcl::io::savePolygonFileVTK (const std::string &file_name, const pcl::PolygonMes
poly_writer->SetInputData (poly_data);
#endif
poly_writer->SetFileName (file_name.c_str ());
poly_writer->Write ();

return (static_cast<int> (mesh.cloud.width * mesh.cloud.height));
return (poly_writer->Write ());
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int
bool
pcl::io::savePolygonFilePLY (const std::string &file_name, const pcl::PolygonMesh& mesh)
{
vtkSmartPointer<vtkPolyData> poly_data = vtkSmartPointer<vtkPolyData>::New ();
Expand All @@ -206,13 +203,11 @@ pcl::io::savePolygonFilePLY (const std::string &file_name, const pcl::PolygonMes
#endif
poly_writer->SetFileName (file_name.c_str ());
poly_writer->SetArrayName ("Colors");
poly_writer->Write ();

return (static_cast<int> (mesh.cloud.width * mesh.cloud.height));
return (poly_writer->Write ());
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int
bool
pcl::io::savePolygonFileSTL (const std::string &file_name, const pcl::PolygonMesh& mesh)
{
vtkSmartPointer<vtkPolyData> poly_data = vtkSmartPointer<vtkPolyData>::New ();
Expand All @@ -225,9 +220,7 @@ pcl::io::savePolygonFileSTL (const std::string &file_name, const pcl::PolygonMes
poly_writer->SetInputData (poly_data);
#endif
poly_writer->SetFileName (file_name.c_str ());
poly_writer->Write ();

return (static_cast<int> (mesh.cloud.width * mesh.cloud.height));
return (poly_writer->Write ());
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 4ee1941

Please sign in to comment.