A modern C++ library for parsing the PLY file format.
The PLY file format was developed at Stanford University. Several well-known models in Computer Graphics, such as the models of The Stanford 3D Scanning Repository (including the Stanford Bunny, the Happy Buddha and the Dragon), the samples of Cyberware, the models of the Large Geometric Models Archive, and the Power Plant Model are in the PLY format.
Libply is a modern C++ library for parsing the PLY file format. Libply consists of an event-based error-reporting parser for the PLY file format. Libply is available under the GNU General Public License.
Libply's ply parser supports the complete PLY file format. However, the ply parser is considerably more complex than parsers for other 3D file formats. This is because a PLY file can contain any kind of data, a PLY file consist of a header containing a specification of the kind of data, and the data itself. For more information, refer to the ply specification.
Libply's Wavefront ply parser is event-based, which makes it easy to integrate and well suited for parsing very large files (such as the 28 million triangles Lucy model). Libply's Wavefront ply parser reports errors, which is especially useful for handling the large variety of ply files out there. Libply is a modern C++ library written in standard C++, and uses TR1's function objects as an efficient and flexible callback mechanism.
Libply comes with the ply2ply, ply2obj and plyheader command line programs. The ply2ply command line program supports transformations on ply files, such as binary to ascii conversion. The ply2obj command line program converts from the PLY file format to the Wavefront OBJ file format. The plyheader command line program displays the header of a PLY file. Libply also includes the powerplant program, a program that shows how to load the Power Plant Model, which consists of 13 million triangles in 1185 files.
Libply was written by Ares Lagae. Ares Lagae is a researcher in the Computer Graphics Research Group at the Katholieke Universiteit Leuven, and a C++ enthusiast. In his spare time, he writes C++ libraries that he uses in his research. Libply is one of these libraries. Other libraries include libobj, a modern C++ library for parsing the Wavefront OBJ file format, and libply, a modern C++ library for parsing the Neutral File Format.
Libply does not depend on any external libraries, except Boost, and requires <tr1/cstdint>, <tr1/functional>, <tr1/memory>, <tr1/tuple>. Libply was developed with gcc version 4.2.0.
Please send bug reports, feature requests, questions and comments to Ares Lagae.
To install libply, download the source distribution, unpack the archive (tar xzf ply-0.1.tar.gz), move into the directory (cd ply-0.1/), configure the package (./configure --prefix=/home/ares), compile the programs and libraries (make), install the programs and libraries (make install), and clean the package (make clean).
To use libply, create a ply file (cube.ply),
ply format ascii 1.0 comment made by anonymous comment this file is a cube element vertex 8 property float32 x property float32 y property float32 z element face 6 property list uint8 int32 vertex_index end_header 0 0 0 0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 0 4 0 1 2 3 4 7 6 5 4 4 0 4 5 1 4 1 5 6 2 4 2 6 7 3 4 3 7 4 0create an example program (
ply.cpp),
#include <iostream>
#include <ply.hpp>
void vertex_x_callback(ply::float32 x)
{
std::cout << x;
}
void vertex_y_callback(ply::float32 y)
{
std::cout << " " << y;
}
void vertex_z_callback(ply::float32 z)
{
std::cout << " " << z << "\n";
}
template <typename ScalarType>
std::tr1::function <void (ScalarType)> scalar_property_definition_callback(const std::string& element_name, const std::string& property_name);
template <>
std::tr1::function <void (ply::float32)> scalar_property_definition_callback(const std::string& element_name, const std::string& property_name)
{
if (element_name == "vertex") {
if (property_name == "x") {
return vertex_x_callback;
}
else if (property_name == "y") {
return vertex_y_callback;
}
else if (property_name == "z") {
return vertex_z_callback;
}
else {
return 0;
}
}
else {
return 0;
}
}
int main(int argc, char* argv[])
{
ply::ply_parser ply_parser;
ply::ply_parser::scalar_property_definition_callbacks_type scalar_property_definition_callbacks;
ply::at <ply::float32>(scalar_property_definition_callbacks) = scalar_property_definition_callback <ply::float32>;
ply_parser.scalar_property_definition_callbacks(scalar_property_definition_callbacks);
ply_parser.parse("cube.ply");
}
compile the program (g++ -Wall -I ~/include ply.cpp -L ~/lib/ -l ply -o ply), and execute the program (./ply). In order to locate the locate the dynamic libraries, update the dynamic library search path of the linker (export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/lib). If libply was installed system-wide (./configure withouth --prefix=/home/ares), then reconfigure the dynamic linker run time bindings (ldconfig). Alternatively, the example program can be linked statically (g++ -Wall -I ~/include ply.cpp -L ~/lib/ -l ply -static -o ply).
To uninstall libply, move into the directory (cd ply-0.1/), uninstall the programs and libraries (make uninstall), move out of the directory (cd ..), remove the directory (rm -r ply-0.1/), and remove the source distribution (rm ply-0.1.tar.gz).
Libply does not have detailed documentation. Please refer to the Doxygen documentation, to the source code of the ply2ply and ply2obj programs that come with libply, and to TR1 documentation.
Ares Lagae - Personal site (disclaimer) -