Commit 05ed4412 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'PLY-Reader-updates' into 'master'

Ply reader updates

See merge request !226
parents 7fff526d 79bf4a77
Pipeline #12117 passed with stage
in 88 minutes and 36 seconds
......@@ -30,6 +30,8 @@
<b>IO</b>
<ul>
<li>PLY Reader: Fix reading doubles from PLY, missing cast (Thanks to Leo Walsh for the patch)</li>
<li>PLY Reader: Some cleanup (Thanks to Morgan Leborgne for the patch)</li>
<li>PLY Reader: Support for ushort (Thanks to Morgan Leborgne for the patch)</li>
</ul>
......
......@@ -219,16 +219,13 @@ void _PLYReader_::readCreateCustomProperty(std::istream& _in, BaseImporter& _bi,
}
//init vector
int numberOfValues;
read(_listType, _in, numberOfValues, OpenMesh::GenProg::Bool2Type<binary>());
std::vector<T> vec;
vec.reserve(numberOfValues);
unsigned int numberOfValues;
readInteger(_listType, _in, numberOfValues, OpenMesh::GenProg::Bool2Type<binary>());
std::vector<T> vec(numberOfValues);
//read and assign
for (int i = 0; i < numberOfValues; ++i)
for (unsigned int i = 0; i < numberOfValues; ++i)
{
T in;
read(_valueType, _in, in, OpenMesh::GenProg::Bool2Type<binary>());
vec.push_back(in);
read(_valueType, _in, vec[i], OpenMesh::GenProg::Bool2Type<binary>());
}
_bi.kernel()->property(prop,_h) = vec;
}
......@@ -974,9 +971,13 @@ void _PLYReader_::readValue(ValueType _type, std::istream& _in, int& _value) con
//-----------------------------------------------------------------------------
template<typename T>
void _PLYReader_::readInteger(ValueType _type, std::istream& _in, T& _value) const {
void _PLYReader_::readInteger(ValueType _type, std::istream& _in, int& _value) const {
static_assert(std::is_integral<T>::value, "Integral required.");
int16_t tmp_int16_t;
uint16_t tmp_uint16_t;
int32_t tmp_int32_t;
uint32_t tmp_uint32_t;
int8_t tmp_char;
......@@ -984,63 +985,30 @@ void _PLYReader_::readInteger(ValueType _type, std::istream& _in, int& _value) c
switch (_type) {
case ValueTypeINT:
case ValueTypeINT32:
restore(_in, tmp_int32_t, options_.check(Options::MSB));
_value = tmp_int32_t;
break;
case ValueTypeUINT:
case ValueTypeUINT32:
case ValueTypeINT16:
restore(_in, tmp_uint32_t, options_.check(Options::MSB));
_value = tmp_uint32_t;
case ValueTypeSHORT:
restore(_in, tmp_int16_t, options_.check(Options::MSB));
_value = tmp_int16_t;
break;
case ValueTypeCHAR:
case ValueTypeINT8:
case ValueTypeUINT16:
restore(_in, tmp_char, options_.check(Options::MSB));
_value = tmp_char;
case ValueTypeUSHORT:
restore(_in, tmp_uint16_t, options_.check(Options::MSB));
_value = tmp_uint16_t;
break;
case ValueTypeUCHAR:
case ValueTypeUINT8:
restore(_in, tmp_uchar, options_.check(Options::MSB));
_value = tmp_uchar;
break;
case ValueTypeINT:
default:
case ValueTypeINT32:
_value = 0;
std::cerr << "unsupported conversion type to int: " << _type << std::endl;
restore(_in, tmp_int32_t, options_.check(Options::MSB));
_value = tmp_int32_t;
break;
}
}
//-----------------------------------------------------------------------------
void _PLYReader_::readInteger(ValueType _type, std::istream& _in, unsigned int& _value) const {
int32_t tmp_int32_t;
uint32_t tmp_uint32_t;
int8_t tmp_char;
uint8_t tmp_uchar;
switch (_type) {
case ValueTypeUINT:
......@@ -1051,12 +1019,12 @@ void _PLYReader_::readInteger(ValueType _type, std::istream& _in, unsigned int&
break;
case ValueTypeINT:
case ValueTypeCHAR:
case ValueTypeINT32:
case ValueTypeINT8:
restore(_in, tmp_int32_t, options_.check(Options::MSB));
_value = tmp_int32_t;
restore(_in, tmp_char, options_.check(Options::MSB));
_value = tmp_char;
break;
......@@ -1069,25 +1037,15 @@ void _PLYReader_::readInteger(ValueType _type, std::istream& _in, unsigned int&
break;
case ValueTypeCHAR:
case ValueTypeINT8:
restore(_in, tmp_char, options_.check(Options::MSB));
_value = tmp_char;
break;
default:
_value = 0;
std::cerr << "unsupported conversion type to unsigned int: " << _type << std::endl;
std::cerr << "unsupported conversion type to integral: " << _type << std::endl;
break;
}
}
//------------------------------------------------------------------------------
......
......@@ -130,8 +130,6 @@ private:
bool read_ascii(std::istream& _in, BaseImporter& _bi, const Options& _opt) const;
bool read_binary(std::istream& _in, BaseImporter& _bi, bool swap, const Options& _opt) const;
float readToFloatValue(ValueType _type , std::fstream& _in) const;
void readValue(ValueType _type , std::istream& _in, float& _value) const;
void readValue(ValueType _type , std::istream& _in, double& _value) const;
void readValue(ValueType _type , std::istream& _in, unsigned int& _value) const;
......@@ -141,8 +139,8 @@ private:
void readValue(ValueType _type , std::istream& _in, short& _value) const;
void readValue(ValueType _type , std::istream& _in, signed char& _value) const;
void readInteger(ValueType _type, std::istream& _in, int& _value) const;
void readInteger(ValueType _type, std::istream& _in, unsigned int& _value) const;
template<typename T>
void readInteger(ValueType _type, std::istream& _in, T& _value) const;
/// Read unsupported properties in PLY file
void consume_input(std::istream& _in, int _count) const {
......@@ -214,6 +212,18 @@ private:
_in >> _value;
}
template<typename T>
inline void readInteger(_PLYReader_::ValueType _type, std::istream& _in, T& _value, OpenMesh::GenProg::TrueType /*_binary*/) const
{
readInteger(_type, _in, _value);
}
template<typename T>
inline void readInteger(_PLYReader_::ValueType _type, std::istream& _in, T& _value, OpenMesh::GenProg::FalseType /*_binary*/) const
{
_in >> _value;
}
//read and assign custom properties with the given type. Also creates property, if not exist
template<bool binary, typename T, typename Handle>
void readCreateCustomProperty(std::istream& _in, BaseImporter& _bi, Handle _h, const std::string& _propName, const ValueType _valueType, const ValueType _listType) const;
......
......@@ -543,6 +543,91 @@ TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithCustomProps) {
}
/*
* Just load a ply with custom properties, binary mode
*/
TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithCustomPropsBinary) {
PolyMesh mesh;
OpenMesh::IO::Options options;
options += OpenMesh::IO::Options::Custom;
options += OpenMesh::IO::Options::Binary;
bool ok = OpenMesh::IO::read_mesh(mesh, "cube-minimal-custom_props-binary.ply", options);
EXPECT_TRUE(ok) << "Unable to load cube-minimal-custom_props.ply";
EXPECT_EQ(8u , mesh.n_vertices()) << "The number of loaded vertices is not correct!";
EXPECT_EQ(12u , mesh.n_edges()) << "The number of loaded edges is not correct!";
EXPECT_EQ(6u , mesh.n_faces()) << "The number of loaded faces is not correct!";
OpenMesh::VPropHandleT<float> qualityProp;
OpenMesh::VPropHandleT<unsigned int> indexProp;
ASSERT_TRUE(mesh.get_property_handle(qualityProp,"quality")) << "Could not access quality property";
ASSERT_TRUE(mesh.get_property_handle(indexProp,"index")) << "Could not access index property";
//check index property
for (unsigned i = 0; i < mesh.n_vertices(); ++i)
EXPECT_EQ(i ,mesh.property(indexProp,OpenMesh::VertexHandle(i))) << "Vertex index at vertex " << i << " is wrong";
//check quality property
EXPECT_EQ(1.f,mesh.property(qualityProp,OpenMesh::VertexHandle(0))) << "Wrong quality value at Vertex 0";
EXPECT_EQ(0.5f,mesh.property(qualityProp,OpenMesh::VertexHandle(1))) << "Wrong quality value at Vertex 1";
EXPECT_EQ(0.7f,mesh.property(qualityProp,OpenMesh::VertexHandle(2))) << "Wrong quality value at Vertex 2";
EXPECT_EQ(1.f,mesh.property(qualityProp,OpenMesh::VertexHandle(3))) << "Wrong quality value at Vertex 3";
EXPECT_EQ(0.1f,mesh.property(qualityProp,OpenMesh::VertexHandle(4))) << "Wrong quality value at Vertex 4";
EXPECT_EQ(0.f,mesh.property(qualityProp,OpenMesh::VertexHandle(5))) << "Wrong quality value at Vertex 5";
EXPECT_EQ(2.f,mesh.property(qualityProp,OpenMesh::VertexHandle(6))) << "Wrong quality value at Vertex 6";
EXPECT_EQ(5.f,mesh.property(qualityProp,OpenMesh::VertexHandle(7))) << "Wrong quality value at Vertex 7";
//check for custom list properties
OpenMesh::VPropHandleT< std::vector<int> > testValues;
ASSERT_TRUE(mesh.get_property_handle(testValues,"test_values")) << "Could not access texcoords per face";
EXPECT_EQ(2u,mesh.property(testValues,OpenMesh::VertexHandle(0)).size()) << "Wrong verctor size";
EXPECT_EQ(1,mesh.property(testValues,OpenMesh::VertexHandle(0))[0]) << "Wrong list value at Vertex 0";
EXPECT_EQ(4,mesh.property(testValues,OpenMesh::VertexHandle(1))[1]) << "Wrong list value at Vertex 1";
EXPECT_EQ(5,mesh.property(testValues,OpenMesh::VertexHandle(2))[0]) << "Wrong list value at Vertex 2";
EXPECT_EQ(8,mesh.property(testValues,OpenMesh::VertexHandle(3))[1]) << "Wrong list value at Vertex 3";
EXPECT_EQ(9,mesh.property(testValues,OpenMesh::VertexHandle(4))[0]) << "Wrong list value at Vertex 4";
EXPECT_EQ(12,mesh.property(testValues,OpenMesh::VertexHandle(5))[1]) << "Wrong list value at Vertex 5";
EXPECT_EQ(13,mesh.property(testValues,OpenMesh::VertexHandle(6))[0]) << "Wrong list value at Vertex 6";
EXPECT_EQ(16,mesh.property(testValues,OpenMesh::VertexHandle(7))[1]) << "Wrong list value at Vertex 7";
OpenMesh::FPropHandleT< std::vector<float> > texCoordsPerFace;
ASSERT_TRUE(mesh.get_property_handle(texCoordsPerFace,"texcoords")) << "Could not access texcoords per face";
for (Mesh::FaceIter f_iter = mesh.faces_begin(); f_iter != mesh.faces_end(); ++f_iter)
{
EXPECT_EQ(8u, mesh.property(texCoordsPerFace, *f_iter).size()) << "Texcoords per face container has wrong size on face: " << f_iter->idx();
if (!mesh.property(texCoordsPerFace, *f_iter).empty())
{
EXPECT_EQ(1.0, mesh.property(texCoordsPerFace, *f_iter)[0]) << "Texcoords wrong on index 0 with face: " << f_iter->idx();
EXPECT_EQ(1.0, mesh.property(texCoordsPerFace, *f_iter)[1]) << "Texcoords wrong on index 1 with face: " << f_iter->idx();
EXPECT_EQ(-1.0f, mesh.property(texCoordsPerFace, *f_iter)[2]) << "Texcoords wrong on index 2 with face: " << f_iter->idx();
EXPECT_EQ(-1.0f, mesh.property(texCoordsPerFace, *f_iter)[3]) << "Texcoords wrong on index 3 with face: " << f_iter->idx();
EXPECT_EQ(0.0f, mesh.property(texCoordsPerFace, *f_iter)[4]) << "Texcoords wrong on index 4 with face: " << f_iter->idx();
EXPECT_EQ(0.0f, mesh.property(texCoordsPerFace, *f_iter)[5]) << "Texcoords wrong on index 5 with face: " << f_iter->idx();
EXPECT_EQ(-0.5f, mesh.property(texCoordsPerFace, *f_iter)[6]) << "Texcoords wrong on index 6 with face: " << f_iter->idx();
EXPECT_EQ(-0.5f, mesh.property(texCoordsPerFace, *f_iter)[7]) << "Texcoords wrong on index 7 with face: " << f_iter->idx();
}
}
OpenMesh::FPropHandleT< unsigned > faceIndex;
ASSERT_TRUE(mesh.get_property_handle(faceIndex,"faceIndex")) << "Could not access faceIndex per face";
EXPECT_EQ(0u,mesh.property(faceIndex,OpenMesh::FaceHandle(0))) << "Wrong index value at FaceHandle 0";
EXPECT_EQ(1u,mesh.property(faceIndex,OpenMesh::FaceHandle(1))) << "Wrong index value at FaceHandle 1";
EXPECT_EQ(2u,mesh.property(faceIndex,OpenMesh::FaceHandle(2))) << "Wrong index value at FaceHandle 2";
EXPECT_EQ(3u,mesh.property(faceIndex,OpenMesh::FaceHandle(3))) << "Wrong index value at FaceHandle 3";
EXPECT_EQ(4u,mesh.property(faceIndex,OpenMesh::FaceHandle(4))) << "Wrong index value at FaceHandle 4";
EXPECT_EQ(5u,mesh.property(faceIndex,OpenMesh::FaceHandle(5))) << "Wrong index value at FaceHandle 5";
}
TEST_F(OpenMeshReadWritePLY, WriteReadSimplePLYWithCustomProps) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment