27#ifndef EASY3D_FILEIO_PLY_READER_WRITER_H
28#define EASY3D_FILEIO_PLY_READER_WRITER_H
34#include <easy3d/core/types.h>
53 template <
typename VT>
61 explicit GenericProperty(
const std::string &prop_name =
"",
const std::vector<VT> &values = std::vector<VT>())
62 : std::vector<VT>(values),
name(prop_name) {}
83 explicit Element(
const std::string &elem_name, std::size_t n_instances = 0) :
name(elem_name),
113 PlyReader() =
default;
122 bool read(
const std::string& file_name, std::vector<Element>& elements);
132 static std::size_t
num_instances(
const std::string& file_name,
const std::string& element_name);
137 void collect_elements(std::vector<Element>& elements)
const;
147 struct ListProperty : PlyProperty,
GenericProperty< std::vector<double> > {
148 ListProperty(
const std::string &elem_name,
const std::string &prop_name)
149 :
GenericProperty<std::vector<double> >(prop_name), element_name(elem_name) {}
150 std::string element_name;
153 struct ValueProperty : PlyProperty, GenericProperty<double> {
154 ValueProperty(
const std::string &elem_name,
const std::string &prop_name)
156 std::string element_name;
159 std::vector< ListProperty* > list_properties_;
160 std::vector< ValueProperty* > value_properties_;
181 const std::string &file_name,
182 const std::vector<Element> &elements,
183 const std::string &comment =
"",
Generic property.
Definition ply_reader_writer.h:54
GenericProperty(const std::string &prop_name="", const std::vector< VT > &values=std::vector< VT >())
Constructor to initialize the property with a name and values.
Definition ply_reader_writer.h:61
std::string name
Definition ply_reader_writer.h:63
bool read(const std::string &file_name, std::vector< Element > &elements)
Reads a PLY file and stores the model as a set of elements.
static std::size_t num_instances(const std::string &file_name, const std::string &element_name)
A quick check of the number of instances of a type of element.
A general purpose PLY file writer.
Definition ply_reader_writer.h:170
static bool write(const std::string &file_name, const std::vector< Element > &elements, const std::string &comment="", bool binary=false)
Saves a model stored as a set of elements to a file.
File input/output functionalities.
Definition graph_io.h:60
GenericProperty< vec2 > Vec2Property
Property for 2D vectors.
Definition ply_reader_writer.h:67
GenericProperty< int > IntProperty
Property for scalar fields of integer values.
Definition ply_reader_writer.h:69
GenericProperty< float > FloatProperty
Property for scalar fields of float values.
Definition ply_reader_writer.h:68
GenericProperty< std::vector< float > > FloatListProperty
Property for properties of a list of float values.
Definition ply_reader_writer.h:70
GenericProperty< vec3 > Vec3Property
Property for 3D vectors.
Definition ply_reader_writer.h:66
GenericProperty< std::vector< int > > IntListProperty
Property for properties of a list of integer values.
Definition ply_reader_writer.h:71
bool is_big_endian()
Returns the endianness of the system.
Definition ply_reader_writer.cpp:695
Definition collider.cpp:182
std::vector< Vec2Property > vec2_properties
Properties for "texcoord".
Definition ply_reader_writer.h:90
std::vector< Vec3Property > vec3_properties
Properties for "point", "normal", "color", and vector fields.
Definition ply_reader_writer.h:89
std::vector< FloatListProperty > float_list_properties
Properties for a list of float values.
Definition ply_reader_writer.h:93
std::vector< FloatProperty > float_properties
Properties for scalar fields of float values.
Definition ply_reader_writer.h:91
std::vector< IntProperty > int_properties
Properties for scalar fields of integer values.
Definition ply_reader_writer.h:92
std::string name
The name of the element, e.g., "vertex", "face", "edge".
Definition ply_reader_writer.h:86
std::vector< IntListProperty > int_list_properties
Properties for a list of integer values.
Definition ply_reader_writer.h:94
Element(const std::string &elem_name, std::size_t n_instances=0)
Constructor to initialize the element with a name and number of instances.
Definition ply_reader_writer.h:83
std::string property_statistics() const
Returns a string representation of the property statistics.
std::size_t num_instances
The number of instances of the element.
Definition ply_reader_writer.h:87