Created
January 11, 2023 18:00
-
-
Save afabri/150da258c9f9da6e78aa23821ec47dd7 to your computer and use it in GitHub Desktop.
Writing and reading PLY files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
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
And when I run it I get