Euclid
Geometry Processing and Shape Analysis in C++
PlyIO.h
1 
14 #pragma once
15 
16 #include <iterator>
17 #include <memory>
18 #include <string>
19 #include <type_traits>
20 #include <vector>
21 
22 namespace Euclid
23 {
24 // Forward declaration
25 class PlyReader;
26 class PlyWriter;
27 
35 enum class PlyFormat
36 {
37  ascii,
40 };
41 
55 {
56 public:
57  explicit PlyProperty(const std::string& name) : _name(name) {}
58 
59  PlyProperty(const std::string& name, bool is_list)
60  : _name(name), _is_list(is_list)
61  {}
62 
63  virtual ~PlyProperty() = default;
64 
65  PlyProperty(const PlyProperty&) = default;
66 
67  PlyProperty(PlyProperty&&) = default;
68 
69  PlyProperty& operator=(const PlyProperty&) = default;
70 
71  PlyProperty& operator=(PlyProperty&&) = default;
72 
76  const std::string& name() const
77  {
78  return _name;
79  }
80 
84  bool is_list() const
85  {
86  return _is_list;
87  }
88 
92  virtual std::string type_str() const = 0;
93 
97  virtual void apply(PlyReader& reader,
98  std::ifstream& stream,
99  PlyFormat format) const = 0;
100 
104  virtual void apply(PlyWriter& writer,
105  std::ofstream& stream,
106  PlyFormat format) const = 0;
107 
108 private:
109  std::string _name;
110  bool _is_list = false;
111 };
112 
117 {
118 public:
119  using value_type = double;
120 
121 public:
122  explicit PlyDoubleProperty(const std::string& name) : PlyProperty(name) {}
123 
124  PlyDoubleProperty(const std::string& name, bool is_list)
125  : PlyProperty(name, is_list)
126  {}
127 
128  std::string type_str() const override
129  {
130  return "double";
131  }
132 
133  void apply(PlyReader& reader,
134  std::ifstream& stream,
135  PlyFormat format) const override;
136 
137  void apply(PlyWriter& writer,
138  std::ofstream& stream,
139  PlyFormat format) const override;
140 
141  value_type get_ascii(std::ifstream& stream) const;
142 
143  value_type get_binary(std::ifstream& stream,
144  bool file_little_endian,
145  bool sys_little_endian) const;
146 
147  void put_ascii(std::ofstream& stream, value_type value) const;
148 
149  void put_binary(std::ofstream& stream,
150  value_type value,
151  bool file_little_endian,
152  bool sys_little_endian) const;
153 };
154 
159 {
160 public:
161  using value_type = float;
162 
163 public:
164  explicit PlyFloatProperty(const std::string& name) : PlyProperty(name) {}
165 
166  PlyFloatProperty(const std::string& name, bool is_list)
167  : PlyProperty(name, is_list)
168  {}
169 
170  std::string type_str() const override
171  {
172  return "float";
173  }
174 
175  void apply(PlyReader& reader,
176  std::ifstream& stream,
177  PlyFormat format) const override;
178 
179  void apply(PlyWriter& writer,
180  std::ofstream& stream,
181  PlyFormat format) const override;
182 
183  value_type get_ascii(std::ifstream& stream) const;
184 
185  value_type get_binary(std::ifstream& stream,
186  bool file_little_endian,
187  bool sys_little_endian) const;
188 
189  void put_ascii(std::ofstream& stream, value_type value) const;
190 
191  void put_binary(std::ofstream& stream,
192  value_type value,
193  bool file_little_endian,
194  bool sys_little_endian) const;
195 };
196 
201 {
202 public:
203  using value_type = int;
204 
205 public:
206  explicit PlyIntProperty(const std::string& name) : PlyProperty(name) {}
207 
208  PlyIntProperty(const std::string& name, bool is_list)
209  : PlyProperty(name, is_list)
210  {}
211 
212  std::string type_str() const override
213  {
214  return "int";
215  }
216 
217  void apply(PlyReader& reader,
218  std::ifstream& stream,
219  PlyFormat format) const override;
220 
221  void apply(PlyWriter& writer,
222  std::ofstream& stream,
223  PlyFormat format) const override;
224 
225  value_type get_ascii(std::ifstream& stream) const;
226 
227  value_type get_binary(std::ifstream& stream,
228  bool file_little_endian,
229  bool sys_little_endian) const;
230 
231  void put_ascii(std::ofstream& stream, value_type value) const;
232 
233  void put_binary(std::ofstream& stream,
234  value_type value,
235  bool file_little_endian,
236  bool sys_little_endian) const;
237 };
238 
243 {
244 public:
245  using value_type = unsigned;
246 
247 public:
248  explicit PlyUintProperty(const std::string& name) : PlyProperty(name) {}
249 
250  PlyUintProperty(const std::string& name, bool is_list)
251  : PlyProperty(name, is_list)
252  {}
253 
254  std::string type_str() const override
255  {
256  return "uint";
257  }
258 
259  void apply(PlyReader& reader,
260  std::ifstream& stream,
261  PlyFormat format) const override;
262 
263  void apply(PlyWriter& writer,
264  std::ofstream& stream,
265  PlyFormat format) const override;
266 
267  value_type get_ascii(std::ifstream& stream) const;
268 
269  value_type get_binary(std::ifstream& stream,
270  bool file_little_endian,
271  bool sys_little_endian) const;
272 
273  void put_ascii(std::ofstream& stream, value_type value) const;
274 
275  void put_binary(std::ofstream& stream,
276  value_type value,
277  bool file_little_endian,
278  bool sys_little_endian) const;
279 };
280 
285 {
286 public:
287  using value_type = int;
288 
289 public:
290  explicit PlyShortProperty(const std::string& name) : PlyProperty(name) {}
291 
292  PlyShortProperty(const std::string& name, bool is_list)
293  : PlyProperty(name, is_list)
294  {}
295 
296  std::string type_str() const override
297  {
298  return "short";
299  }
300 
301  void apply(PlyReader& reader,
302  std::ifstream& stream,
303  PlyFormat format) const override;
304 
305  void apply(PlyWriter& writer,
306  std::ofstream& stream,
307  PlyFormat format) const override;
308 
309  value_type get_ascii(std::ifstream& stream) const;
310 
311  value_type get_binary(std::ifstream& stream,
312  bool file_little_endian,
313  bool sys_little_endian) const;
314 
315  void put_ascii(std::ofstream& stream, value_type value) const;
316 
317  void put_binary(std::ofstream& stream,
318  value_type value,
319  bool file_little_endian,
320  bool sys_little_endian) const;
321 };
322 
327 {
328 public:
329  using value_type = unsigned;
330 
331 public:
332  explicit PlyUshortProperty(const std::string& name) : PlyProperty(name) {}
333 
334  PlyUshortProperty(const std::string& name, bool is_list)
335  : PlyProperty(name, is_list)
336  {}
337 
338  std::string type_str() const override
339  {
340  return "ushort";
341  }
342 
343  void apply(PlyReader& reader,
344  std::ifstream& stream,
345  PlyFormat format) const override;
346 
347  void apply(PlyWriter& writer,
348  std::ofstream& stream,
349  PlyFormat format) const override;
350 
351  value_type get_ascii(std::ifstream& stream) const;
352 
353  value_type get_binary(std::ifstream& stream,
354  bool file_little_endian,
355  bool sys_little_endian) const;
356 
357  void put_ascii(std::ofstream& stream, value_type value) const;
358 
359  void put_binary(std::ofstream& stream,
360  value_type value,
361  bool file_little_endian,
362  bool sys_little_endian) const;
363 };
364 
369 {
370 public:
371  using value_type = int;
372 
373 public:
374  explicit PlyCharProperty(const std::string& name) : PlyProperty(name) {}
375 
376  PlyCharProperty(const std::string& name, bool is_list)
377  : PlyProperty(name, is_list)
378  {}
379 
380  std::string type_str() const override
381  {
382  return "char";
383  }
384 
385  void apply(PlyReader& reader,
386  std::ifstream& stream,
387  PlyFormat format) const override;
388 
389  void apply(PlyWriter& writer,
390  std::ofstream& stream,
391  PlyFormat format) const override;
392 
393  value_type get_ascii(std::ifstream& stream) const;
394 
395  value_type get_binary(std::ifstream& stream,
396  bool file_little_endian,
397  bool sys_little_endian) const;
398 
399  void put_ascii(std::ofstream& stream, value_type value) const;
400 
401  void put_binary(std::ofstream& stream,
402  value_type value,
403  bool file_little_endian,
404  bool sys_little_endian) const;
405 };
406 
411 {
412 public:
413  using value_type = unsigned;
414 
415 public:
416  explicit PlyUcharProperty(const std::string& name) : PlyProperty(name) {}
417 
418  PlyUcharProperty(const std::string& name, bool is_list)
419  : PlyProperty(name, is_list)
420  {}
421 
422  std::string type_str() const override
423  {
424  return "uchar";
425  }
426 
427  void apply(PlyReader& reader,
428  std::ifstream& stream,
429  PlyFormat format) const override;
430 
431  void apply(PlyWriter& writer,
432  std::ofstream& stream,
433  PlyFormat format) const override;
434 
435  value_type get_ascii(std::ifstream& stream) const;
436 
437  value_type get_binary(std::ifstream& stream,
438  bool file_little_endian,
439  bool sys_little_endian) const;
440 
441  void put_ascii(std::ofstream& stream, value_type value) const;
442 
443  void put_binary(std::ofstream& stream,
444  value_type value,
445  bool file_little_endian,
446  bool sys_little_endian) const;
447 };
448 
456 {
457 public:
461  class iterator
462  {
463  public:
464  using iterator_category = std::forward_iterator_tag;
465  using value_type = PlyProperty;
466  using reference = value_type&;
467  using pointer = value_type*;
468  using difference_type = int;
469  using unique_iter = std::vector<std::unique_ptr<PlyProperty>>::iterator;
470 
471  explicit iterator(unique_iter iter) : _iter(iter) {}
472 
473  iterator& operator++()
474  {
475  ++_iter;
476  return *this;
477  }
478 
479  iterator operator++(int)
480  {
481  auto cpy = *this;
482  ++(*this);
483  return cpy;
484  }
485 
486  reference operator*()
487  {
488  return **_iter;
489  }
490 
491  bool operator!=(const iterator& rhs)
492  {
493  return _iter != rhs._iter;
494  }
495 
496  private:
497  unique_iter _iter;
498  };
499 
504  {
505  public:
506  using iterator_category = std::forward_iterator_tag;
507  using value_type = const PlyProperty;
508  using reference = value_type&;
509  using pointer = value_type*;
510  using difference_type = int;
511  using unique_iter =
512  std::vector<std::unique_ptr<PlyProperty>>::const_iterator;
513 
514  explicit const_iterator(unique_iter iter) : _iter(iter) {}
515 
516  const_iterator& operator++()
517  {
518  ++_iter;
519  return *this;
520  }
521 
522  const_iterator operator++(int)
523  {
524  auto cpy = *this;
525  ++(*this);
526  return cpy;
527  }
528 
529  reference operator*()
530  {
531  return **_iter;
532  }
533 
534  bool operator!=(const const_iterator& rhs)
535  {
536  return _iter != rhs._iter;
537  }
538 
539  private:
540  unique_iter _iter;
541  };
542 
546  PlyElement(const std::string& name, unsigned count)
547  : _name(name), _count(count)
548  {}
549 
550  ~PlyElement() = default;
551 
552  PlyElement(const PlyElement& rhs) = delete;
553 
554  PlyElement& operator=(const PlyElement& rhs) = delete;
555 
556  PlyElement(PlyElement&& rhs)
557  {
558  _name = rhs._name;
559  _count = rhs._count;
560  std::copy(std::make_move_iterator(rhs._properties.begin()),
561  std::make_move_iterator(rhs._properties.end()),
562  std::back_inserter(_properties));
563  }
564 
565  PlyElement& operator=(PlyElement&& rhs)
566  {
567  _name = rhs._name;
568  _count = rhs._count;
569  std::copy(std::make_move_iterator(rhs._properties.begin()),
570  std::make_move_iterator(rhs._properties.end()),
571  std::back_inserter(_properties));
572  return *this;
573  }
574 
578  const std::string& name() const
579  {
580  return _name;
581  }
582 
586  unsigned count() const
587  {
588  return _count;
589  }
590 
594  void add_property(std::unique_ptr<PlyProperty> property)
595  {
596  _properties.push_back(std::move(property));
597  }
598 
603  {
604  return _properties[i].get();
605  }
606 
610  const PlyProperty* property(size_t i) const
611  {
612  return _properties[i].get();
613  }
614 
618  size_t n_props() const
619  {
620  return _properties.size();
621  }
622 
627  {
628  return iterator(_properties.begin());
629  }
630 
635  {
636  return const_iterator(_properties.cbegin());
637  }
638 
643  {
644  return iterator(_properties.end());
645  }
646 
651  {
652  return const_iterator(_properties.cend());
653  }
654 
655 private:
656  std::string _name;
657  unsigned _count;
658  std::vector<std::unique_ptr<PlyProperty>> _properties;
659 };
660 
666 {
667 public:
671  explicit PlyHeader(PlyFormat format) : _format(format) {}
672 
673  PlyHeader(const PlyHeader&) = delete;
674 
675  PlyHeader(PlyHeader&&) = default;
676 
677  PlyHeader& operator=(const PlyHeader&) = delete;
678 
679  PlyHeader& operator=(PlyHeader&&) = default;
680 
685  {
686  return _format;
687  }
688 
692  void set_format(PlyFormat format)
693  {
694  _format = format;
695  }
696 
700  PlyElement& element(size_t i)
701  {
702  return _elements[i];
703  }
704 
708  const PlyElement& element(size_t i) const
709  {
710  return _elements[i];
711  }
712 
716  void add_element(PlyElement&& element)
717  {
718  _elements.push_back(std::move(element));
719  }
720 
724  size_t n_elems() const
725  {
726  return _elements.size();
727  }
728 
732  decltype(auto) begin()
733  {
734  return _elements.cbegin();
735  }
736 
740  decltype(auto) begin() const
741  {
742  return _elements.begin();
743  }
744 
748  decltype(auto) end()
749  {
750  return _elements.end();
751  }
752 
756  decltype(auto) end() const
757  {
758  return _elements.cend();
759  }
760 
761 private:
762  PlyFormat _format;
763  std::vector<PlyElement> _elements;
764 };
765 
783 {
784 public:
785  PlyReader();
786 
787  virtual ~PlyReader() = default;
788 
796  virtual void on_read(const PlyHeader&) {}
797 
801  virtual void read(const PlyDoubleProperty*, std::ifstream&, PlyFormat) {}
802 
806  virtual void read(const PlyFloatProperty*, std::ifstream&, PlyFormat) {}
807 
811  virtual void read(const PlyIntProperty*, std::ifstream&, PlyFormat) {}
812 
816  virtual void read(const PlyUintProperty*, std::ifstream&, PlyFormat) {}
817 
821  virtual void read(const PlyShortProperty*, std::ifstream&, PlyFormat) {}
822 
826  virtual void read(const PlyUshortProperty*, std::ifstream&, PlyFormat) {}
827 
831  virtual void read(const PlyCharProperty*, std::ifstream&, PlyFormat) {}
832 
836  virtual void read(const PlyUcharProperty*, std::ifstream&, PlyFormat) {}
837 
838 protected:
839  bool _sys_little_endian;
840 };
841 
860 {
861 public:
862  PlyWriter();
863 
864  virtual ~PlyWriter() = default;
865 
872  virtual void on_write() {}
873 
879  virtual PlyHeader generate_header(PlyFormat format) const
880  {
881  PlyHeader header(format);
882  return header;
883  };
884 
888  virtual void write(const PlyDoubleProperty*, std::ofstream&, PlyFormat) {}
889 
893  virtual void write(const PlyFloatProperty*, std::ofstream&, PlyFormat) {}
894 
898  virtual void write(const PlyIntProperty*, std::ofstream&, PlyFormat) {}
899 
903  virtual void write(const PlyUintProperty*, std::ofstream&, PlyFormat) {}
904 
908  virtual void write(const PlyShortProperty*, std::ofstream&, PlyFormat) {}
909 
913  virtual void write(const PlyUshortProperty*, std::ofstream&, PlyFormat) {}
914 
918  virtual void write(const PlyCharProperty*, std::ofstream&, PlyFormat) {}
919 
923  virtual void write(const PlyUcharProperty*, std::ofstream&, PlyFormat) {}
924 
925 protected:
926  bool _sys_little_endian;
927 };
928 
953 template<int VN, typename FloatType, typename IndexType, typename ColorType>
955 {
956 public:
962  CommonPlyReader(std::vector<FloatType>& positions,
963  std::vector<FloatType>* normals = nullptr,
964  std::vector<FloatType>* texcoords = nullptr,
965  std::vector<IndexType>* indices = nullptr,
966  std::vector<ColorType>* colors = nullptr)
967  : _positions(positions), _normals(normals), _texcoords(texcoords),
968  _indices(indices), _colors(colors)
969  {}
970 
971  void on_read(const PlyHeader& header) override;
972 
973  void read(const PlyDoubleProperty* property,
974  std::ifstream& stream,
975  PlyFormat format) override;
976 
977  void read(const PlyFloatProperty* property,
978  std::ifstream& stream,
979  PlyFormat format) override;
980 
981  void read(const PlyIntProperty* property,
982  std::ifstream& stream,
983  PlyFormat format) override;
984 
985  void read(const PlyUintProperty* property,
986  std::ifstream& stream,
987  PlyFormat format) override;
988 
989  void read(const PlyUcharProperty* property,
990  std::ifstream& stream,
991  PlyFormat format) override;
992 
993 private:
994  template<typename TPlyProperty>
995  void _store_float(const TPlyProperty* property,
996  std::ifstream& stream,
997  PlyFormat format);
998 
999  template<typename TPlyProperty>
1000  void _store_color(const TPlyProperty* property,
1001  std::ifstream& stream,
1002  PlyFormat format);
1003 
1004  template<typename TPlyProperty>
1005  void _store_indices(const TPlyProperty* property,
1006  std::ifstream& stream,
1007  PlyFormat format);
1008 
1009 private:
1010  std::vector<FloatType>& _positions;
1011  std::vector<FloatType>* _normals = nullptr;
1012  std::vector<FloatType>* _texcoords = nullptr;
1013  std::vector<IndexType>* _indices = nullptr;
1014  std::vector<ColorType>* _colors = nullptr;
1015 };
1016 
1041 template<int VN, typename FloatType, typename IndexType, typename ColorType>
1043 {
1044 public:
1050  CommonPlyWriter(const std::vector<FloatType>& positions,
1051  const std::vector<FloatType>* normals = nullptr,
1052  const std::vector<FloatType>* texcoords = nullptr,
1053  const std::vector<IndexType>* indices = nullptr,
1054  const std::vector<ColorType>* colors = nullptr)
1055  : _positions(positions), _normals(normals), _texcoords(texcoords),
1056  _indices(indices), _colors(colors)
1057  {
1058  auto n = positions.size() / 3;
1059  if (_normals != nullptr && _normals->size() != n * 3) {
1060  throw std::invalid_argument(
1061  "Size of normals not compatible with positions");
1062  }
1063  if (_texcoords != nullptr && _texcoords->size() != n * 2) {
1064  throw std::invalid_argument(
1065  "Size of texcoords not compatible with positions");
1066  }
1067  if (_colors != nullptr) {
1068  if (_colors->size() == n * 3) {
1069  _has_alpha = false;
1070  }
1071  else if (_colors->size() == n * 4) {
1072  _has_alpha = true;
1073  }
1074  else {
1075  throw std::invalid_argument(
1076  "Size of colors not compatible with positions");
1077  }
1078  }
1079  if (_indices != nullptr && _indices->size() % VN != 0) {
1080  throw std::invalid_argument(
1081  "Size of indices not compatible with VN");
1082  }
1083  }
1084 
1085  void on_write() override;
1086 
1087  PlyHeader generate_header(PlyFormat format) const override;
1088 
1089  void write(const PlyDoubleProperty* property,
1090  std::ofstream& stream,
1091  PlyFormat format) override;
1092 
1093  void write(const PlyFloatProperty* property,
1094  std::ofstream& stream,
1095  PlyFormat format) override;
1096 
1097  void write(const PlyIntProperty* property,
1098  std::ofstream& stream,
1099  PlyFormat format) override;
1100 
1101  void write(const PlyUintProperty* property,
1102  std::ofstream& stream,
1103  PlyFormat format) override;
1104 
1105  void write(const PlyUcharProperty* property,
1106  std::ofstream& stream,
1107  PlyFormat format) override;
1108 
1109 private:
1110  template<typename TPlyProperty>
1111  void _write_float(const TPlyProperty* property,
1112  std::ofstream& stream,
1113  PlyFormat format);
1114 
1115  template<typename TPlyProperty>
1116  void _write_color(const TPlyProperty* property,
1117  std::ofstream& stream,
1118  PlyFormat format);
1119 
1120  template<typename TPlyProperty>
1121  void _write_indices(const TPlyProperty* property,
1122  std::ofstream& stream,
1123  PlyFormat format);
1124 
1125 private:
1126  const std::vector<FloatType>& _positions;
1127  const std::vector<FloatType>* _normals = nullptr;
1128  const std::vector<FloatType>* _texcoords = nullptr;
1129  const std::vector<IndexType>* _indices = nullptr;
1130  const std::vector<ColorType>* _colors = nullptr;
1131  bool _has_alpha = false;
1132  size_t _piter = 0;
1133  size_t _iiter = 0;
1134  size_t _niter = 0;
1135  size_t _titer = 0;
1136  size_t _citer = 0;
1137 };
1138 
1143 PlyHeader read_ply_header(const std::string& filename);
1144 
1152 void read_ply(const std::string& filename, PlyReader& reader);
1153 
1198 template<int VN,
1199  typename FloatType,
1200  typename IndexType,
1201  typename ColorType,
1202  typename Interface>
1203 void read_ply(const std::string& filename,
1204  std::vector<FloatType>& positions,
1205  std::vector<FloatType>* normals,
1206  std::vector<FloatType>* texcoords,
1207  std::vector<IndexType>* indices,
1208  std::vector<ColorType>* colors);
1209 
1217 void write_ply(const std::string& filename,
1218  PlyWriter& writer,
1219  PlyFormat format = PlyFormat::ascii);
1220 
1267 template<int VN,
1268  typename FloatType,
1269  typename IndexType,
1270  typename ColorType,
1271  typename Interface>
1272 void write_ply(const std::string& filename,
1273  const std::vector<FloatType>& positions,
1274  const std::vector<FloatType>* normals,
1275  const std::vector<FloatType>* texcoords,
1276  const std::vector<IndexType>* indices,
1277  const std::vector<ColorType>* colors,
1278  PlyFormat format = PlyFormat::ascii);
1279 
1281 } // namespace Euclid
1282 
1283 #include "src/PlyIO.cpp"
CommonPlyWriter(const std::vector< FloatType > &positions, const std::vector< FloatType > *normals=nullptr, const std::vector< FloatType > *texcoords=nullptr, const std::vector< IndexType > *indices=nullptr, const std::vector< ColorType > *colors=nullptr)
Constructor.
Definition: PlyIO.h:1050
std::string type_str() const override
Return the string for this type in the header.
Definition: PlyIO.h:380
const_iterator end() const
Return the end const_iterator of the property vector.
Definition: PlyIO.h:650
A ply writer for a common set of properties.
Definition: PlyIO.h:1042
virtual void read(const PlyUcharProperty *, std::ifstream &, PlyFormat)
Read a PlyUcharProperty.
Definition: PlyIO.h:836
A short ply property.
Definition: PlyIO.h:284
virtual void write(const PlyUcharProperty *, std::ofstream &, PlyFormat)
Write a PlyUcharProperty.
Definition: PlyIO.h:923
A double ply property.
Definition: PlyIO.h:116
Iterate through the properties in this element.
Definition: PlyIO.h:503
std::string type_str() const override
Return the string for this type in the header.
Definition: PlyIO.h:338
void add_property(std::unique_ptr< PlyProperty > property)
Add a property to this element.
Definition: PlyIO.h:594
bool is_list() const
Return if this property is a list property.
Definition: PlyIO.h:84
Ply element.
Definition: PlyIO.h:455
Ply header.
Definition: PlyIO.h:665
unsigned count() const
Return the instance count of this element in file.
Definition: PlyIO.h:586
size_t n_elems() const
Return the number of elements in the header specification.
Definition: PlyIO.h:724
virtual void write(const PlyIntProperty *, std::ofstream &, PlyFormat)
Write a PlyIntProperty.
Definition: PlyIO.h:898
PlyFormat format() const
Return the format.
Definition: PlyIO.h:684
std::string type_str() const override
Return the string for this type in the header.
Definition: PlyIO.h:254
std::string type_str() const override
Return the string for this type in the header.
Definition: PlyIO.h:212
std::string type_str() const override
Return the string for this type in the header.
Definition: PlyIO.h:170
virtual void on_write()
On writing the ply file.
Definition: PlyIO.h:872
virtual void write(const PlyCharProperty *, std::ofstream &, PlyFormat)
Write a PlyCharProperty.
Definition: PlyIO.h:918
PlyProperty * property(size_t i)
Get the property by index.
Definition: PlyIO.h:602
virtual void read(const PlyUshortProperty *, std::ifstream &, PlyFormat)
Read a PlyUshortProperty.
Definition: PlyIO.h:826
std::string type_str() const override
Return the string for this type in the header.
Definition: PlyIO.h:296
Definition: AABB.h:6
const PlyProperty * property(size_t i) const
Get the property by index.
Definition: PlyIO.h:610
big endian binary mode.
virtual void read(const PlyDoubleProperty *, std::ifstream &, PlyFormat)
Read a PlyDoubleProperty.
Definition: PlyIO.h:801
void set_format(PlyFormat format)
Set the format.
Definition: PlyIO.h:692
An abstrct class for ply reader.
Definition: PlyIO.h:782
const PlyElement & element(size_t i) const
Get element by index.
Definition: PlyIO.h:708
virtual void write(const PlyFloatProperty *, std::ofstream &, PlyFormat)
Write a PlyFloatProperty.
Definition: PlyIO.h:893
An unsigned int ply property.
Definition: PlyIO.h:242
std::string type_str() const override
Return the string for this type in the header.
Definition: PlyIO.h:128
virtual void on_read(const PlyHeader &)
On reading the header.
Definition: PlyIO.h:796
virtual void read(const PlyIntProperty *, std::ifstream &, PlyFormat)
Read a PlyIntProperty.
Definition: PlyIO.h:811
virtual void write(const PlyUintProperty *, std::ofstream &, PlyFormat)
Write a PlyUintProperty.
Definition: PlyIO.h:903
virtual void read(const PlyShortProperty *, std::ifstream &, PlyFormat)
Read a PlyShortProperty.
Definition: PlyIO.h:821
iterator end()
Return the end iterator of the property vector.
Definition: PlyIO.h:642
iterator begin()
Return the begin iterator of the property vector.
Definition: PlyIO.h:626
size_t n_props() const
Return the size of the property list.
Definition: PlyIO.h:618
An unsigned short ply property.
Definition: PlyIO.h:326
PlyHeader read_ply_header(const std::string &filename)
Read ply header.
Definition: PlyIO.cpp:1179
const std::string & name() const
Return the name of this property.
Definition: PlyIO.h:76
virtual PlyHeader generate_header(PlyFormat format) const
Generate the ply header.
Definition: PlyIO.h:879
virtual void write(const PlyDoubleProperty *, std::ofstream &, PlyFormat)
Write a PlyDoubleProperty.
Definition: PlyIO.h:888
A char ply property.
Definition: PlyIO.h:368
little endian binary mode.
void write_ply(const std::string &filename, const std::vector< FloatType > &positions, const std::vector< FloatType > *normals, const std::vector< FloatType > *texcoords, const std::vector< IndexType > *indices, const std::vector< ColorType > *colors, PlyFormat format=PlyFormat::ascii)
Write ply file using CommonPlyWriter.
Iterate through the properties in this element.
Definition: PlyIO.h:461
An abstract ply writer.
Definition: PlyIO.h:859
A float ply property.
Definition: PlyIO.h:158
virtual void write(const PlyShortProperty *, std::ofstream &, PlyFormat)
Write a PlyShortProperty.
Definition: PlyIO.h:908
virtual void write(const PlyUshortProperty *, std::ofstream &, PlyFormat)
Write a PlyUshortProperty.
Definition: PlyIO.h:913
virtual void read(const PlyCharProperty *, std::ifstream &, PlyFormat)
Read a PlyCharProperty.
Definition: PlyIO.h:831
const std::string & name() const
Return the name of the element.
Definition: PlyIO.h:578
A ply reader for a common set of properties.
Definition: PlyIO.h:954
PlyHeader(PlyFormat format)
Create a PlyHeader with format.
Definition: PlyIO.h:671
CommonPlyReader(std::vector< FloatType > &positions, std::vector< FloatType > *normals=nullptr, std::vector< FloatType > *texcoords=nullptr, std::vector< IndexType > *indices=nullptr, std::vector< ColorType > *colors=nullptr)
Constructor.
Definition: PlyIO.h:962
An unsigned char ply property.
Definition: PlyIO.h:410
std::string type_str() const override
Return the string for this type in the header.
Definition: PlyIO.h:422
An int ply property.
Definition: PlyIO.h:200
Base class for ply property.
Definition: PlyIO.h:54
PlyElement(const std::string &name, unsigned count)
Create a PlyElement with name and instance count.
Definition: PlyIO.h:546
const_iterator begin() const
Return the begin const_iterator of the property vector.
Definition: PlyIO.h:634
PlyFormat
Ply file format.
Definition: PlyIO.h:35
PlyElement & element(size_t i)
Get element by index.
Definition: PlyIO.h:700
void add_element(PlyElement &&element)
Add an element to this header.
Definition: PlyIO.h:716
void read_ply(const std::string &filename, std::vector< FloatType > &positions, std::vector< FloatType > *normals, std::vector< FloatType > *texcoords, std::vector< IndexType > *indices, std::vector< ColorType > *colors)
Read ply file using CommonPlyReader.
virtual void read(const PlyUintProperty *, std::ifstream &, PlyFormat)
Read a PlyUintProperty.
Definition: PlyIO.h:816
virtual void read(const PlyFloatProperty *, std::ifstream &, PlyFormat)
Read a PlyFloatProperty.
Definition: PlyIO.h:806