diff --git a/Point_set_processing_3/examples/Point_set_processing_3/CMakeLists.txt b/Point_set_processing_3/examples/Point_set_processing_3/CMakeLists.txt index 9d51c01e4ae..a2194e8285d 100644 --- a/Point_set_processing_3/examples/Point_set_processing_3/CMakeLists.txt +++ b/Point_set_processing_3/examples/Point_set_processing_3/CMakeLists.txt @@ -53,6 +53,7 @@ if ( CGAL_FOUND ) create_single_source_cgal_program( "random_simplification_example.cpp" ) create_single_source_cgal_program( "read_write_xyz_point_set_example.cpp" ) create_single_source_cgal_program( "read_ply_points_with_colors_example.cpp" ) + create_single_source_cgal_program( "write_ply_points_example.cpp" ) create_single_source_cgal_program( "remove_outliers_example.cpp" ) create_single_source_cgal_program( "scale_estimation_example.cpp" ) create_single_source_cgal_program( "scale_estimation_2d_example.cpp" ) diff --git a/Point_set_processing_3/examples/Point_set_processing_3/write_ply_points_example.cpp b/Point_set_processing_3/examples/Point_set_processing_3/write_ply_points_example.cpp new file mode 100644 index 00000000000..8987cdf00ae --- /dev/null +++ b/Point_set_processing_3/examples/Point_set_processing_3/write_ply_points_example.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +#include +#include +#include + +// types +typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; +typedef Kernel::FT FT; +typedef Kernel::Point_3 Point; +typedef Kernel::Vector_3 Vector; +typedef CGAL::cpp11::array Color; + +// Point with normal, color and intensity +typedef CGAL::cpp11::tuple PCI; +typedef CGAL::Nth_of_tuple_property_map<0, PCI> Point_map; +typedef CGAL::Nth_of_tuple_property_map<1, PCI> Color_map; +typedef CGAL::Nth_of_tuple_property_map<2, PCI> Intensity_map; + + +namespace std +{ + std::ostream& operator<< (std::ostream& stream, const Color& c) + { + stream << int(c[0]) << " " << int(c[1]) << " " << int(c[2]) << " " << int(c[3]); + return stream; + } +} + + +int main(int, char**) +{ + std::vector points; // store points + + for (std::size_t i = 0; i < 10; ++ i) + points.push_back (CGAL::cpp11::make_tuple (Point (i / 10., i / 20., i / 30.), + CGAL::make_array ((unsigned char)(255 / (i + 1)), + (unsigned char)(192 / (i + 1)), + (unsigned char)(128 / (i + 1)), + (unsigned char)(64 / (i + 1))), + i)); + + std::ofstream f("out.ply", std::ios_base::binary); + CGAL::write_ply_points_with_properties + (f, points.begin(), points.end(), + CGAL::Ply::point_writer (Point_map()), + CGAL::cpp11::make_tuple(Color_map(), + CGAL::Ply::Property("red"), + CGAL::Ply::Property("green"), + CGAL::Ply::Property("blue"), + CGAL::Ply::Property("alpha")), + std::make_pair (Intensity_map(), CGAL::Ply::Property("intensity"))); + + return EXIT_SUCCESS; +}