26 #include <boost/foreach.hpp>
27 #include <boost/exception/errinfo_file_name.hpp>
28 #include <boost/exception/errinfo_at_line.hpp>
29 #include <boost/exception/errinfo_errno.hpp>
39 static int vertex_cb(p_ply_argument argument);
40 static int face_cb(p_ply_argument argument);
41 static int material_cb(p_ply_argument argument);
42 static void error_cb(
p_ply ply,
const char* message);
45 static const double NaN = std::numeric_limits<double>::quiet_NaN();
54 FILE* fp = fopen(filename.c_str(),
"rb");
63 : _fp(fp), _ply(nullptr), _nvertices(-1), _nfaces(-1), _nmaterials(-1)
71 if (!ply_read_header(
_ply))
123 if (material_index == -1)
145 assert(
_points.size() - 1 == vertex_index);
146 _points.back()._value[(unsigned)property] = value;
155 int property_index,
double value)
161 if (nproperties != 3)
167 if (property_index == -1)
169 assert(value == 3.0);
174 assert(property_index < 3);
175 assert(
_faces.size() - 1 == face_index);
176 const unsigned vertex_index = (unsigned)value;
178 triangle.index(property_index) = vertex_index;
194 unsigned nproperties,
int property_index,
double value)
199 if (property_index == -1)
201 assert(value == nproperties);
202 _materials.push_back(std::string(nproperties,
'-'));
206 assert((
unsigned)property_index < nproperties);
207 assert(
_materials.size() - 1 == material_index);
208 _materials.back()[property_index] = (
unsigned char)value;
219 assert(
_ply == NULL || ply ==
_ply);
232 #define DECLARE_AND_FETCH_PLY_CALLBACK_INFO \
235 tympan::AltimetryPLYReader* p_reader; \
236 long instance_index; \
237 p_ply_element element; \
239 ply_get_argument_user_data(argument, &pdata, &idata); \
240 p_reader = (tympan::AltimetryPLYReader*)pdata; \
241 ply_get_argument_element(argument, &element, &instance_index); \
242 value = ply_get_argument_value(argument);
247 static int vertex_cb(p_ply_argument argument)
253 return p_reader->vertex_cb(vertex_property, instance_index, value);
258 static int face_cb(p_ply_argument argument)
265 long length = 0, value_index = 0;
266 p_ply_property
property =
nullptr;
267 ply_get_argument_property(argument, &property, &length, &value_index);
268 return p_reader->face_cb(face_property, instance_index, length, value_index, value);
273 static int material_cb(p_ply_argument argument)
280 long length = 0, value_index = 0;
281 p_ply_property
property =
nullptr;
282 ply_get_argument_property(argument, &property, &length, &value_index);
283 return p_reader->material_cb(material_property, instance_index, length, value_index, value);
287 static void error_cb(
p_ply ply,
const char* message)
290 void* pdata =
nullptr;
294 ply_get_ply_user_data(ply, &pdata, &idata);
#define DECLARE_AND_FETCH_PLY_CALLBACK_INFO
macro which extract all relevant callback information form RPLY
Implementation details header for altimetry_reader.cpp.
read an Altimetry from a PLY file.
std::vector< unsigned > _material_indices
@ NUM_material_properties
bool vertex_cb(vertex_properties property, unsigned vertex_index, double value)
virtual void read()
read the file whose name was given at reader's construction time
bool face_cb(face_properties property, unsigned face_index, unsigned nproperties, int property_index, double value)
materials_array_t _materials
void error_cb(p_ply ply, const char *message)
materials_array_t _material_by_face
virtual ~AltimetryPLYReader()
bool material_cb(material_properties property, unsigned material_index, unsigned nproperties, int property_index, double value)
void build_material_by_face()
AltimetryPLYReader(FILE *fp)
#define tympan_source_loc
This macro build a source_loc object to be attached to a tympan::Exception.
std::unique_ptr< IMeshReader > make_altimetry_ply_reader(const std::string filename)
@ Makes a reader for the file name given as argument