Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VTK io fixes #1279

Merged
merged 2 commits into from
Jul 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions io/include/pcl/io/vtk_lib_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +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 int
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 @@ -177,29 +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 int
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 int
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 int
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
67 changes: 37 additions & 30 deletions io/src/vtk_lib_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,21 @@ pcl::io::loadPolygonFile (const std::string &file_name, pcl::PolygonMesh& mesh)
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int
pcl::io::savePolygonFile (const std::string &file_name, const pcl::PolygonMesh& mesh)
bool
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?!?!?!?
// 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));
}
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,8 +166,10 @@ pcl::io::loadPolygonFileSTL (const std::string &file_name, pcl::PolygonMesh& mes
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int
pcl::io::savePolygonFileVTK (const std::string &file_name, const pcl::PolygonMesh& mesh)
bool
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 @@ -184,15 +181,19 @@ pcl::io::savePolygonFileVTK (const std::string &file_name, const pcl::PolygonMes
#else
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));
if (!binary_format)
poly_writer->SetFileTypeToASCII ();

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

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int
pcl::io::savePolygonFilePLY (const std::string &file_name, const pcl::PolygonMesh& mesh)
bool
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 @@ -204,16 +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");
poly_writer->Write ();

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

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int
pcl::io::savePolygonFileSTL (const std::string &file_name, const pcl::PolygonMesh& mesh)
bool
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 @@ -224,10 +229,12 @@ pcl::io::savePolygonFileSTL (const std::string &file_name, const pcl::PolygonMes
#else
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));
if (!binary_format)
poly_writer->SetFileTypeToASCII ();

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

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