Skip to content

Instantly share code, notes, and snippets.

@afabri
Created January 11, 2023 18:00
Show Gist options
  • Save afabri/150da258c9f9da6e78aa23821ec47dd7 to your computer and use it in GitHub Desktop.
Save afabri/150da258c9f9da6e78aa23821ec47dd7 to your computer and use it in GitHub Desktop.
Writing and reading PLY files
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/boost/graph/IO/PLY.h>
#include <CGAL/Surface_mesh/IO/PLY.h>
#include <CGAL/boost/graph/generators.h>
#include <CGAL/IO/Color.h>
#include <iostream>
#include <fstream>
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_3 Point_3;
typedef CGAL::Surface_mesh<Point_3> Mesh;
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;
typedef CGAL::IO::Color Color;
int main()
{
{
Mesh m;
Mesh::Property_map<face_descriptor,Color> color;
bool created;
boost::tie(color, created) = m.add_property_map<face_descriptor,Color>("f:color",Color());
assert(created);
CGAL::make_triangle(Point_3(0,0,0), Point_3(1,0,0), Point_3(0,1,0),m);
face_descriptor fd = *faces(m).begin();
Color red(255,0,0);
put(color,fd,red);
std::ofstream out("m.ply");
CGAL::IO::write_PLY(out, m);
out.close();
}
{
Mesh m;
std::ifstream in("m.ply");
CGAL::IO::read_PLY(in, m);
in.close();
std::cout << m << std::endl;
}
return 0;
}
@afabri
Copy link
Author

afabri commented Jan 12, 2023

And it also works when I write/read a binary ply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment