Fixed PLY reader compilation with Color Trait as Vec3f
This commit is contained in:
@@ -6,13 +6,18 @@
|
|||||||
|
|
||||||
<!-- --------------------------------------------------------------------- -->
|
<!-- --------------------------------------------------------------------- -->
|
||||||
|
|
||||||
<tr valign=top><td><b>11.0</b> (2023/11/14)</td><td>
|
<tr valign=top><td><b>11.0</b> (?/?/?)</td><td>
|
||||||
|
|
||||||
<b>Documentation</b>
|
<b>Documentation</b>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Update Doxygen config format</li>
|
<li>Update Doxygen config format</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<b>IO</b>
|
||||||
|
<ul>
|
||||||
|
<li>PLY reader/writer: Fixed color trait Vec3f compilation for PLY writer</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<b>Build System</b>
|
<b>Build System</b>
|
||||||
<ul>
|
<ul>
|
||||||
<li>GTest is now automatically fetched via official git repository and build when unittests have been enabled</li>
|
<li>GTest is now automatically fetched via official git repository and build when unittests have been enabled</li>
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ public: // inherited from BaseProperty
|
|||||||
virtual void reserve(size_t _n) override { data_.reserve(_n); }
|
virtual void reserve(size_t _n) override { data_.reserve(_n); }
|
||||||
virtual void resize(size_t _n) override { data_.resize(_n); }
|
virtual void resize(size_t _n) override { data_.resize(_n); }
|
||||||
virtual void clear() override { data_.clear(); vector_type().swap(data_); }
|
virtual void clear() override { data_.clear(); vector_type().swap(data_); }
|
||||||
virtual void push_back() override { data_.push_back(); }
|
virtual void push_back() override { data_.push_back(bool()); }
|
||||||
virtual void swap(size_t _i0, size_t _i1) override
|
virtual void swap(size_t _i0, size_t _i1) override
|
||||||
{ bool t(data_[_i0]); data_[_i0]=data_[_i1]; data_[_i1]=t; }
|
{ bool t(data_[_i0]); data_[_i0]=data_[_i1]; data_[_i1]=t; }
|
||||||
virtual void copy(size_t _i0, size_t _i1) override
|
virtual void copy(size_t _i0, size_t _i1) override
|
||||||
|
|||||||
@@ -210,6 +210,20 @@ struct color_caster<Vec4uc,Vec3f>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct color_caster<Vec4ui,Vec3f>
|
||||||
|
{
|
||||||
|
typedef Vec4ui return_type;
|
||||||
|
|
||||||
|
inline static return_type cast(const Vec3f& _src)
|
||||||
|
{
|
||||||
|
return Vec4ui( (unsigned int)(_src[0]* 255.0f + 0.5f),
|
||||||
|
(unsigned int)(_src[1]* 255.0f + 0.5f),
|
||||||
|
(unsigned int)(_src[2]* 255.0f + 0.5f),
|
||||||
|
(unsigned int)(255) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct color_caster<Vec4f,Vec3f>
|
struct color_caster<Vec4f,Vec3f>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,6 +24,32 @@ class OpenMeshReadWritePLY : public OpenMeshBase {
|
|||||||
//Mesh mesh_;
|
//Mesh mesh_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CustomTraits3f : public OpenMesh::DefaultTraits {
|
||||||
|
typedef OpenMesh::Vec3f Color;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef OpenMesh::TriMesh_ArrayKernelT<CustomTraits3f> Mesh3f;
|
||||||
|
|
||||||
|
class OpenMeshReadWritePLYColorVec3f : public testing::Test {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// This function is called before each test is run
|
||||||
|
virtual void SetUp() {
|
||||||
|
|
||||||
|
// Do some initial stuff with the member data here...
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function is called after all tests are through
|
||||||
|
virtual void TearDown() {
|
||||||
|
|
||||||
|
// Do some final stuff with the member data here...
|
||||||
|
}
|
||||||
|
|
||||||
|
// This member will be accessible in all tests
|
||||||
|
Mesh3f mesh_;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
* Define tests below
|
* Define tests below
|
||||||
@@ -1335,4 +1361,146 @@ TEST_F(OpenMeshReadWritePLY, WriteAndReadPLYWithFaceColors) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Just load a ply file of a cube with vertex colors
|
||||||
|
*/
|
||||||
|
TEST_F(OpenMeshReadWritePLYColorVec3f , LoadSimplePLYWithVertexColorsVec3f) {
|
||||||
|
|
||||||
|
mesh_.clear();
|
||||||
|
|
||||||
|
mesh_.request_vertex_colors();
|
||||||
|
|
||||||
|
OpenMesh::IO::Options options;
|
||||||
|
options += OpenMesh::IO::Options::VertexColor;
|
||||||
|
|
||||||
|
bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertexColors.ply",options);
|
||||||
|
|
||||||
|
EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertexColors.ply";
|
||||||
|
|
||||||
|
EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
|
||||||
|
EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
|
||||||
|
EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
|
||||||
|
|
||||||
|
#ifdef TEST_DOUBLE_TRAITS
|
||||||
|
EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
|
||||||
|
EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
|
||||||
|
EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
|
||||||
|
|
||||||
|
EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
|
||||||
|
EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
|
||||||
|
EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
|
||||||
|
|
||||||
|
EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
|
||||||
|
EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
|
||||||
|
EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
|
||||||
|
|
||||||
|
EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
|
||||||
|
EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
|
||||||
|
EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
|
||||||
|
#else
|
||||||
|
EXPECT_EQ(1.0f, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
|
||||||
|
|
||||||
|
EXPECT_EQ(1.0f, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
|
||||||
|
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
|
||||||
|
EXPECT_EQ(1.0f, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
|
||||||
|
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
|
||||||
|
EXPECT_EQ(1.0f, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
|
||||||
|
EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
|
||||||
|
EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
|
||||||
|
|
||||||
|
mesh_.release_vertex_colors();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write and read PLY files with face colors in various formats
|
||||||
|
*/
|
||||||
|
TEST_F(OpenMeshReadWritePLYColorVec3f , WriteAndReadPLYWithFaceColorsVec3f) {
|
||||||
|
struct Format {
|
||||||
|
Format(const char* outFileName, OpenMesh::IO::Options options) :
|
||||||
|
_outFileName(outFileName),
|
||||||
|
_options(options)
|
||||||
|
{}
|
||||||
|
const char* _outFileName;
|
||||||
|
const OpenMesh::IO::Options _options;
|
||||||
|
}
|
||||||
|
formats[] =
|
||||||
|
{
|
||||||
|
Format("cube-minimal-faceColors_ascii_uchar.ply",
|
||||||
|
OpenMesh::IO::Options::Default),
|
||||||
|
Format("cube-minimal-faceColors_ascii_float.ply",
|
||||||
|
OpenMesh::IO::Options::ColorFloat),
|
||||||
|
Format("cube-minimal-faceColors_binary_uchar.ply",
|
||||||
|
OpenMesh::IO::Options::Binary),
|
||||||
|
Format("cube-minimal-faceColors_binary_float.ply",
|
||||||
|
OpenMesh::IO::Options::Binary | OpenMesh::IO::Options::ColorFloat),
|
||||||
|
// Test writing/reading alpha values (all default 1.0/255), but the test mesh
|
||||||
|
// Color type has no alpha channel so there's nothing to test below
|
||||||
|
Format("cube-minimal-faceColors_alpha_ascii_uchar.ply",
|
||||||
|
OpenMesh::IO::Options::ColorAlpha),
|
||||||
|
Format("cube-minimal-faceColors_alpha_ascii_float.ply",
|
||||||
|
OpenMesh::IO::Options::ColorFloat | OpenMesh::IO::Options::ColorAlpha),
|
||||||
|
Format("cube-minimal-faceColors_alpha_binary_uchar.ply",
|
||||||
|
OpenMesh::IO::Options::Binary | OpenMesh::IO::Options::ColorAlpha),
|
||||||
|
Format("cube-minimal-faceColors_alpha_binary_float.ply",
|
||||||
|
OpenMesh::IO::Options::Binary | OpenMesh::IO::Options::ColorFloat | OpenMesh::IO::Options::ColorAlpha),
|
||||||
|
};
|
||||||
|
|
||||||
|
for (size_t i = 0; i < sizeof(formats) / sizeof(Format); ++i)
|
||||||
|
{
|
||||||
|
const char* outFileName = formats[i]._outFileName;
|
||||||
|
|
||||||
|
mesh_.clear();
|
||||||
|
|
||||||
|
mesh_.request_face_colors();
|
||||||
|
|
||||||
|
OpenMesh::IO::Options options;
|
||||||
|
options += OpenMesh::IO::Options::FaceColor;
|
||||||
|
|
||||||
|
bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-faceColors.ply", options);
|
||||||
|
|
||||||
|
EXPECT_TRUE(ok) << "Unable to load cube-minimal-faceColors.ply";
|
||||||
|
|
||||||
|
options = formats[i]._options;
|
||||||
|
options += OpenMesh::IO::Options::FaceColor;
|
||||||
|
ok = OpenMesh::IO::write_mesh(mesh_, outFileName, options);
|
||||||
|
EXPECT_TRUE(ok) << "Unable to write " << outFileName;
|
||||||
|
|
||||||
|
// Reset for reading: let the reader determine binary/float/etc.
|
||||||
|
options = OpenMesh::IO::Options::FaceColor;
|
||||||
|
mesh_.clear();
|
||||||
|
ok = OpenMesh::IO::read_mesh(mesh_, outFileName, options);
|
||||||
|
EXPECT_TRUE(ok) << "Unable to load " << outFileName;
|
||||||
|
|
||||||
|
EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct: " << outFileName;
|
||||||
|
EXPECT_EQ(18u, mesh_.n_edges()) << "The number of loaded edges is not correct: " << outFileName;
|
||||||
|
EXPECT_EQ(12u, mesh_.n_faces()) << "The number of loaded faces is not correct: " << outFileName;
|
||||||
|
|
||||||
|
|
||||||
|
// Just a compilation test and runtime. No value test, as they are float
|
||||||
|
|
||||||
|
EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned: " << outFileName;
|
||||||
|
EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned: " << outFileName;
|
||||||
|
EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned: " << outFileName;
|
||||||
|
EXPECT_TRUE(options.face_has_color()) << "Wrong user options are returned: " << outFileName;
|
||||||
|
EXPECT_EQ(formats[i]._options.color_is_float(), options.color_is_float()) <<
|
||||||
|
"Wrong user options are returned: " << outFileName;
|
||||||
|
EXPECT_EQ(formats[i]._options.is_binary(), options.is_binary()) <<
|
||||||
|
"Wrong user options are returned: " << outFileName;
|
||||||
|
|
||||||
|
mesh_.release_face_colors();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user