Skip to content

Commit

Permalink
Handle ASCII/Binary in savePolygonFile* methods
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorLamoine committed Jul 30, 2015
1 parent 4ee1941 commit a15c0e6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
16 changes: 12 additions & 4 deletions io/include/pcl/io/vtk_lib_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ 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
* \param[in] binary_format if true, exported file is in binary format
* \return True if successful, false otherwise
* \ingroup io
*/
PCL_EXPORTS bool
savePolygonFile (const std::string &file_name,
const pcl::PolygonMesh& mesh);
const pcl::PolygonMesh& mesh,
const bool binary_format = true);

/** \brief Load a VTK file into a \ref PolygonMesh object
* \param[in] file_name the name of the file that contains the data
Expand Down Expand Up @@ -178,32 +180,38 @@ 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
* \param[in] binary_format if true, exported file is in binary format
* \return True if successful, false otherwise
* \ingroup io
*/
PCL_EXPORTS bool
savePolygonFileVTK (const std::string &file_name,
const pcl::PolygonMesh& mesh);
const pcl::PolygonMesh& mesh,
const bool binary_format = true);

/** \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
* \param[in] binary_format if true, exported file is in binary format
* \return True if successful, false otherwise
* \ingroup io
*/
PCL_EXPORTS bool
savePolygonFilePLY (const std::string &file_name,
const pcl::PolygonMesh& mesh);
const pcl::PolygonMesh& mesh,
const bool binary_format = true);

/** \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
* \param[in] binary_format if true, exported file is in binary format
* \return True if successful, false otherwise
* \ingroup io
*/
PCL_EXPORTS bool
savePolygonFileSTL (const std::string &file_name,
const pcl::PolygonMesh& mesh);
const pcl::PolygonMesh& mesh,
const bool binary_format = true);

/** \brief Write a \ref RangeImagePlanar object to a PNG file
* \param[in] file_name the name of the file to save the data to
Expand Down
46 changes: 30 additions & 16 deletions io/src/vtk_lib_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,20 @@ pcl::io::loadPolygonFile (const std::string &file_name, pcl::PolygonMesh& mesh)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::io::savePolygonFile (const std::string &file_name, const pcl::PolygonMesh& mesh)
pcl::io::savePolygonFile (const std::string &file_name,
const pcl::PolygonMesh& mesh,
const bool binary_format)
{
// TODO: what about binary/ASCII modes?!?!?!
// TODO: what about sensor position and orientation?!?!?!?
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 (false);
return (true);
}
if (extension == "pcd") // no Polygon, but only a point cloud
return (pcl::io::savePCDFile (file_name, mesh.cloud, Eigen::Vector4f::Zero (), Eigen::Quaternionf::Identity (), binary_format) == 0);
else if (extension == "vtk")
return (pcl::io::savePolygonFileVTK (file_name, mesh));
return (pcl::io::savePolygonFileVTK (file_name, mesh, binary_format));
else if (extension == "ply")
return (pcl::io::savePolygonFilePLY (file_name, mesh));
else if (extension == "stl" )
return (pcl::io::savePolygonFileSTL (file_name, mesh));
return (pcl::io::savePolygonFilePLY (file_name, mesh, binary_format));
else if (extension == "stl")
return (pcl::io::savePolygonFileSTL (file_name, mesh, binary_format));
else
{
PCL_ERROR ("[pcl::io::savePolygonFile]: Unsupported file type (%s)\n", extension.c_str ());
Expand Down Expand Up @@ -171,7 +167,9 @@ pcl::io::loadPolygonFileSTL (const std::string &file_name, pcl::PolygonMesh& mes

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::io::savePolygonFileVTK (const std::string &file_name, const pcl::PolygonMesh& mesh)
pcl::io::savePolygonFileVTK (const std::string &file_name,
const pcl::PolygonMesh& mesh,
const bool binary_format)
{
vtkSmartPointer<vtkPolyData> poly_data = vtkSmartPointer<vtkPolyData>::New ();

Expand All @@ -183,13 +181,19 @@ pcl::io::savePolygonFileVTK (const std::string &file_name, const pcl::PolygonMes
#else
poly_writer->SetInputData (poly_data);
#endif

if (!binary_format)
poly_writer->SetFileTypeToASCII ();

poly_writer->SetFileName (file_name.c_str ());
return (poly_writer->Write ());
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::io::savePolygonFilePLY (const std::string &file_name, const pcl::PolygonMesh& mesh)
pcl::io::savePolygonFilePLY (const std::string &file_name,
const pcl::PolygonMesh& mesh,
const bool binary_format)
{
vtkSmartPointer<vtkPolyData> poly_data = vtkSmartPointer<vtkPolyData>::New ();

Expand All @@ -201,14 +205,20 @@ pcl::io::savePolygonFilePLY (const std::string &file_name, const pcl::PolygonMes
#else
poly_writer->SetInputData (poly_data);
#endif

if (!binary_format)
poly_writer->SetFileTypeToASCII ();

poly_writer->SetFileName (file_name.c_str ());
poly_writer->SetArrayName ("Colors");
return (poly_writer->Write ());
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::io::savePolygonFileSTL (const std::string &file_name, const pcl::PolygonMesh& mesh)
pcl::io::savePolygonFileSTL (const std::string &file_name,
const pcl::PolygonMesh& mesh,
const bool binary_format)
{
vtkSmartPointer<vtkPolyData> poly_data = vtkSmartPointer<vtkPolyData>::New ();

Expand All @@ -219,6 +229,10 @@ pcl::io::savePolygonFileSTL (const std::string &file_name, const pcl::PolygonMes
#else
poly_writer->SetInputData (poly_data);
#endif

if (!binary_format)
poly_writer->SetFileTypeToASCII ();

This comment has been minimized.

Copy link
@chambbj

chambbj Sep 2, 2015

Contributor

Doesn't the STL writer default to ASCII though? Looks like the existing logic will never set file type to binary.

This comment has been minimized.

Copy link
@VictorLamoine

VictorLamoine Sep 2, 2015

Author Contributor

You are right; see vtkSTLWriter.cxx.

Fix is here: #1319
Sorry for the inconvenience!


poly_writer->SetFileName (file_name.c_str ());
return (poly_writer->Write ());
}
Expand Down

0 comments on commit a15c0e6

Please sign in to comment.