10 constexpr std::size_t vertex_count_string_length_ = 15;
14 file_(filename, std::ios_base::out | std::ios_base::trunc | std::ios_base::binary),
20 if(ascii_) write_line_(
"format ascii 1.0");
22 else write_line_(
"format binary_big_endian 1.0");
24 write_line_(
"comment PLY file generated using tlz::ply_exporter");
26 file_ <<
"element vertex ";
28 vertex_count_string_position_ = file_.tellp();
29 file_ << std::setfill(
' ') << std::left << std::setw(vertex_count_string_length_) << 0;
32 write_line_(
"property float x");
33 write_line_(
"property float y");
34 write_line_(
"property float z");
36 write_line_(
"property uchar red");
37 write_line_(
"property uchar green");
38 write_line_(
"property uchar blue");
41 write_line_(
"end_header");
52 file_.seekp(vertex_count_string_position_);
53 file_ << std::setfill(
' ') << std::left << std::setw(vertex_count_string_length_) << count_;
60 void ply_exporter::write_line_(
const std::string& ln) {
65 void ply_exporter::write_binary_(
const point_xyz& p) {
66 float pos[3] = { p.
x, p.
y, p.
z };
67 file_.write(reinterpret_cast<const char*>(&pos), 3 *
sizeof(
float));
72 void ply_exporter::write_ascii_(
const point_xyz& p) {
73 file_ << p.
x <<
' ' << p.
y <<
' ' << p.
z;
79 void ply_exporter::write_full_binary_(
const point_full& p) {
80 float pos[3] = { p.
x, p.
y, p.
z };
83 file_.write(reinterpret_cast<const char*>(&pos), 3 *
sizeof(
float));
84 file_.write(reinterpret_cast<const char*>(&col), 3);
89 void ply_exporter::write_full_ascii_(
const point_full& p) {
90 file_ << p.
x <<
' ' << p.
y <<
' ' << p.
z 91 <<
' ' << (unsigned)p.
color.
r <<
' ' << (
unsigned)p.
color.
g <<
' ' << (unsigned)p.
color.
b;
const bool host_is_little_endian
void end_line(std::ostream &str, line_delimitor ld)
ply_exporter(const std::string &filename, bool full=true, bool ascii=false, line_delimitor ld=line_delimitor::LF)
void write_line(std::ostream &str, const std::string &line, line_delimitor ld)