11 #include <boost/foreach.hpp>
12 #include <boost/exception/errinfo_file_name.hpp>
13 #include <boost/exception/errinfo_at_line.hpp>
14 #include <boost/exception/errinfo_errno.hpp>
23 static int vertex_cb(p_ply_argument argument);
24 static int face_cb(p_ply_argument argument);
25 static int material_cb(p_ply_argument argument);
26 static void error_cb(
p_ply ply,
const char* message);
29 static const double NaN = std::numeric_limits<double>::quiet_NaN();
44 : _filename(filename), _ply(nullptr), _nvertices(-1), _nfaces(-1), _nmaterials(-1)
51 if (!ply_read_header(
_ply))
105 if (material_index == -1)
128 assert(
_points.size() - 1 == vertex_index);
129 _points.back()._value[(unsigned)property] = value;
138 int property_index,
double value)
144 if (nproperties != 3)
150 if (property_index == -1)
152 assert(value == 3.0);
157 assert(property_index < 3);
158 assert(
_faces.size() - 1 == face_index);
159 const unsigned vertex_index = (unsigned)value;
161 triangle.index(property_index) = vertex_index;
177 unsigned nproperties,
int property_index,
double value)
182 if (property_index == -1)
184 assert(value == nproperties);
185 _materials.push_back(std::string(nproperties,
'-'));
189 assert((
unsigned)property_index < nproperties);
190 assert(
_materials.size() - 1 == material_index);
191 _materials.back()[property_index] = (
unsigned char)value;
202 assert(
_ply == NULL || ply ==
_ply);
215 #define DECLARE_AND_FETCH_PLY_CALLBACK_INFO \
218 tympan::AltimetryPLYReader* p_reader; \
219 long instance_index; \
220 p_ply_element element; \
222 ply_get_argument_user_data(argument, &pdata, &idata); \
223 p_reader = (tympan::AltimetryPLYReader*)pdata; \
224 ply_get_argument_element(argument, &element, &instance_index); \
225 value = ply_get_argument_value(argument);
230 static int vertex_cb(p_ply_argument argument)
236 return p_reader->vertex_cb(vertex_property, instance_index, value);
241 static int face_cb(p_ply_argument argument)
248 long length = 0, value_index = 0;
249 p_ply_property
property =
nullptr;
250 ply_get_argument_property(argument, &property, &length, &value_index);
251 return p_reader->face_cb(face_property, instance_index, length, value_index, value);
256 static int material_cb(p_ply_argument argument)
263 long length = 0, value_index = 0;
264 p_ply_property
property =
nullptr;
265 ply_get_argument_property(argument, &property, &length, &value_index);
266 return p_reader->material_cb(material_property, instance_index, length, value_index, value);
270 static void error_cb(
p_ply ply,
const char* message)
273 void* pdata =
nullptr;
277 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)
AltimetryPLYReader(const std::string filename)
materials_array_t _materials
void error_cb(p_ply ply, const char *message)
materials_array_t _material_by_face
const std::string _filename
virtual ~AltimetryPLYReader()
bool material_cb(material_properties property, unsigned material_index, unsigned nproperties, int property_index, double value)
void build_material_by_face()
#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