Updated tutorial unittest. Fixed tutorial variable names.
This commit is contained in:
@@ -26,29 +26,28 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// Add a vertex property storing the computed centers of gravity
|
// Add a vertex property storing the computed centers of gravity
|
||||||
auto cog = OpenMesh::makeTemporaryProperty<OpenMesh::VertexHandle, MyMesh::Point>(mesh);
|
auto cog = OpenMesh::makeTemporaryProperty<OpenMesh::VertexHandle, MyMesh::Point>(mesh);
|
||||||
|
|
||||||
// Smooth the mesh several times
|
// Smooth the mesh several times
|
||||||
for (int i = 0; i < iterations; ++i) {
|
for (int i = 0; i < iterations; ++i) {
|
||||||
// Iterate over all vertices to compute centers of gravity
|
// Iterate over all vertices to compute centers of gravity
|
||||||
for (const auto& vh : mesh.vertices()) {
|
for (const auto& vh : mesh.vertices()) {
|
||||||
cog[vv] = {0,0,0};
|
cog[vh] = {0,0,0};
|
||||||
int valence = 0;
|
int valence = 0;
|
||||||
// Iterate over all 1-ring vertices around vh
|
// Iterate over all 1-ring vertices around vh
|
||||||
for (const auto& vvh : mesh.vv_range(vh)) {
|
for (const auto& vvh : mesh.vv_range(vh)) {
|
||||||
cog[vv] += mesh.point(vvh);
|
cog[vh] += mesh.point(vvh);
|
||||||
++valence;
|
++valence;
|
||||||
}
|
}
|
||||||
cog[vv] /= valence;
|
cog[vh] /= valence;
|
||||||
}
|
}
|
||||||
// Move all vertices to the previously computed positions
|
// Move all vertices to the previously computed positions
|
||||||
for (const auto& vh : mesh.vertices()) {
|
for (const auto& vh : mesh.vertices()) {
|
||||||
mesh.point(vv) = cog[vv];
|
mesh.point(vh) = cog[vh];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The cog vertex property is removed from the mesh at the end of this scope
|
} // The cog vertex property is removed from the mesh at the end of this scope
|
||||||
}
|
|
||||||
|
|
||||||
// Write mesh file
|
// Write mesh file
|
||||||
if (!OpenMesh::IO::read_mesh(mesh, outfile)) {
|
if (!OpenMesh::IO::read_mesh(mesh, outfile)) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <OpenMesh/Core/Utils/PropertyManager.hh>
|
||||||
#include <Unittests/unittests_common.hh>
|
#include <Unittests/unittests_common.hh>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -448,36 +449,31 @@ TEST_F(OpenMeshTutorials, using_custom_properties) {
|
|||||||
bool ok = OpenMesh::IO::read_mesh(mesh, "output.off");
|
bool ok = OpenMesh::IO::read_mesh(mesh, "output.off");
|
||||||
EXPECT_TRUE(ok) << "Cannot read mesh from file 'output.off'";
|
EXPECT_TRUE(ok) << "Cannot read mesh from file 'output.off'";
|
||||||
|
|
||||||
// this vertex property stores the computed centers of gravity
|
const int iterations = 100;
|
||||||
OpenMesh::VPropHandleT<MyMesh::Point> cogs;
|
|
||||||
mesh.add_property(cogs);
|
|
||||||
|
|
||||||
// smoothing mesh N times
|
|
||||||
MyMesh::VertexIter v_it, v_end(mesh.vertices_end());
|
|
||||||
MyMesh::VertexVertexIter vv_it;
|
|
||||||
MyMesh::Point cog;
|
|
||||||
MyMesh::Scalar valence;
|
|
||||||
unsigned int i, N(100);
|
|
||||||
|
|
||||||
for (i=0; i < N; ++i)
|
|
||||||
{
|
{
|
||||||
for (v_it = mesh.vertices_begin(); v_it != v_end; ++v_it)
|
// Add a vertex property storing the computed centers of gravity
|
||||||
{
|
auto cog = OpenMesh::makeTemporaryProperty<OpenMesh::VertexHandle, MyMesh::Point>(mesh);
|
||||||
mesh.property(cogs,*v_it).vectorize(0.0f);
|
|
||||||
valence = 0.0;
|
|
||||||
|
|
||||||
for (vv_it = mesh.vv_iter( *v_it ); vv_it.is_valid(); ++vv_it)
|
// Smooth the mesh several times
|
||||||
{
|
for (int i = 0; i < iterations; ++i) {
|
||||||
mesh.property(cogs,*v_it) += mesh.point( *vv_it );
|
// Iterate over all vertices to compute centers of gravity
|
||||||
++valence;
|
for (const auto& vh : mesh.vertices()) {
|
||||||
|
cog[vh] = {0,0,0};
|
||||||
|
int valence = 0;
|
||||||
|
// Iterate over all 1-ring vertices around vh
|
||||||
|
for (const auto& vvh : mesh.vv_range(vh)) {
|
||||||
|
cog[vh] += mesh.point(vvh);
|
||||||
|
++valence;
|
||||||
|
}
|
||||||
|
cog[vh] /= valence;
|
||||||
|
}
|
||||||
|
// Move all vertices to the previously computed positions
|
||||||
|
for (const auto& vh : mesh.vertices()) {
|
||||||
|
mesh.point(vh) = cog[vh];
|
||||||
}
|
}
|
||||||
mesh.property(cogs,*v_it) /= valence;
|
|
||||||
}
|
}
|
||||||
|
} // The cog vertex property is removed from the mesh at the end of this scope
|
||||||
for (v_it = mesh.vertices_begin(); v_it != v_end; ++v_it)
|
|
||||||
if ( !mesh.is_boundary( *v_it ) )
|
|
||||||
mesh.set_point( *v_it, mesh.property(cogs,*v_it) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// write mesh
|
// write mesh
|
||||||
ok = OpenMesh::IO::write_mesh(mesh, "smoothed_custom_properties_output.off");
|
ok = OpenMesh::IO::write_mesh(mesh, "smoothed_custom_properties_output.off");
|
||||||
|
|||||||
Reference in New Issue
Block a user