- Fixed calc_normals_... functions (Missing this pointer)
- Added unittests for the normal calculation functions M src/OpenMesh/Core/Mesh/PolyMeshT.cc M src/Unittests/unittests_trimesh_normal_calculations.cc git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@1036 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
@@ -343,20 +343,20 @@ void PolyMeshT<Kernel>::
|
|||||||
calc_vertex_normal_correct(VertexHandle _vh, Normal& _n) const
|
calc_vertex_normal_correct(VertexHandle _vh, Normal& _n) const
|
||||||
{
|
{
|
||||||
_n.vectorize(0.0);
|
_n.vectorize(0.0);
|
||||||
ConstVertexIHalfedgeIter cvih_it = cvih_iter(_vh);
|
ConstVertexIHalfedgeIter cvih_it = this->cvih_iter(_vh);
|
||||||
if (!cvih_it)
|
if (! cvih_it.is_valid() )
|
||||||
{//don't crash on isolated vertices
|
{//don't crash on isolated vertices
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Normal in_he_vec;
|
Normal in_he_vec;
|
||||||
calc_edge_vector(cvih_it, in_he_vec);
|
calc_edge_vector(*cvih_it, in_he_vec);
|
||||||
for ( ; cvih_it; ++cvih_it)
|
for ( ; cvih_it.is_valid(); ++cvih_it)
|
||||||
{//calculates the sector normal defined by cvih_it and adds it to _n
|
{//calculates the sector normal defined by cvih_it and adds it to _n
|
||||||
if (is_boundary(cvih_it))
|
if (this->is_boundary(*cvih_it))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
HalfedgeHandle out_heh(next_halfedge_handle(cvih_it));
|
HalfedgeHandle out_heh(this->next_halfedge_handle(*cvih_it));
|
||||||
Normal out_he_vec;
|
Normal out_he_vec;
|
||||||
calc_edge_vector(out_heh, out_he_vec);
|
calc_edge_vector(out_heh, out_he_vec);
|
||||||
_n += cross(in_he_vec, out_he_vec);//sector area is taken into account
|
_n += cross(in_he_vec, out_he_vec);//sector area is taken into account
|
||||||
@@ -374,11 +374,11 @@ calc_vertex_normal_loop(VertexHandle _vh, Normal& _n) const
|
|||||||
LoopSchemeMaskDoubleSingleton::Instance();
|
LoopSchemeMaskDoubleSingleton::Instance();
|
||||||
|
|
||||||
Normal t_v(0.0,0.0,0.0), t_w(0.0,0.0,0.0);
|
Normal t_v(0.0,0.0,0.0), t_w(0.0,0.0,0.0);
|
||||||
unsigned int vh_val = valence(_vh);
|
unsigned int vh_val = this->valence(_vh);
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
for (ConstVertexOHalfedgeIter cvoh_it = cvoh_iter(_vh); cvoh_it; ++cvoh_it, ++i)
|
for (ConstVertexOHalfedgeIter cvoh_it = this->cvoh_iter(_vh); cvoh_it.is_valid(); ++cvoh_it, ++i)
|
||||||
{
|
{
|
||||||
VertexHandle r1_v(to_vertex_handle(cvoh_it));
|
VertexHandle r1_v( this->to_vertex_handle(*cvoh_it) );
|
||||||
t_v += (typename vector_traits<Point>::value_type)(loop_scheme_mask__.tang0_weight(vh_val, i))*this->point(r1_v);
|
t_v += (typename vector_traits<Point>::value_type)(loop_scheme_mask__.tang0_weight(vh_val, i))*this->point(r1_v);
|
||||||
t_w += (typename vector_traits<Point>::value_type)(loop_scheme_mask__.tang1_weight(vh_val, i))*this->point(r1_v);
|
t_w += (typename vector_traits<Point>::value_type)(loop_scheme_mask__.tang1_weight(vh_val, i))*this->point(r1_v);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,4 +105,183 @@ TEST_F(OpenMeshNormals, NormalCalculations) {
|
|||||||
mesh_.update_halfedge_normals();
|
mesh_.update_halfedge_normals();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(OpenMeshNormals, NormalCalculations_calc_vertex_normal_fast) {
|
||||||
|
|
||||||
|
mesh_.clear();
|
||||||
|
|
||||||
|
// Add some vertices
|
||||||
|
Mesh::VertexHandle vhandle[4];
|
||||||
|
|
||||||
|
vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
|
||||||
|
vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
|
||||||
|
vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
|
||||||
|
vhandle[3] = mesh_.add_vertex(Mesh::Point(0, 0, 1));
|
||||||
|
|
||||||
|
// Add four faces
|
||||||
|
std::vector<Mesh::VertexHandle> face_vhandles;
|
||||||
|
|
||||||
|
face_vhandles.push_back(vhandle[0]);
|
||||||
|
face_vhandles.push_back(vhandle[1]);
|
||||||
|
face_vhandles.push_back(vhandle[2]);
|
||||||
|
mesh_.add_face(face_vhandles);
|
||||||
|
|
||||||
|
face_vhandles.clear();
|
||||||
|
|
||||||
|
face_vhandles.push_back(vhandle[0]);
|
||||||
|
face_vhandles.push_back(vhandle[2]);
|
||||||
|
face_vhandles.push_back(vhandle[3]);
|
||||||
|
mesh_.add_face(face_vhandles);
|
||||||
|
|
||||||
|
face_vhandles.clear();
|
||||||
|
|
||||||
|
face_vhandles.push_back(vhandle[2]);
|
||||||
|
face_vhandles.push_back(vhandle[1]);
|
||||||
|
face_vhandles.push_back(vhandle[3]);
|
||||||
|
mesh_.add_face(face_vhandles);
|
||||||
|
|
||||||
|
face_vhandles.clear();
|
||||||
|
|
||||||
|
face_vhandles.push_back(vhandle[3]);
|
||||||
|
face_vhandles.push_back(vhandle[1]);
|
||||||
|
face_vhandles.push_back(vhandle[0]);
|
||||||
|
mesh_.add_face(face_vhandles);
|
||||||
|
|
||||||
|
// ===============================================
|
||||||
|
// Setup complete
|
||||||
|
// ===============================================
|
||||||
|
|
||||||
|
|
||||||
|
mesh_.request_vertex_normals();
|
||||||
|
mesh_.request_halfedge_normals();
|
||||||
|
mesh_.request_face_normals();
|
||||||
|
|
||||||
|
|
||||||
|
OpenMesh::Vec3f normal;
|
||||||
|
|
||||||
|
mesh_.calc_vertex_normal_fast(vhandle[2],normal);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OpenMeshNormals, NormalCalculations_calc_vertex_normal_correct) {
|
||||||
|
|
||||||
|
mesh_.clear();
|
||||||
|
|
||||||
|
// Add some vertices
|
||||||
|
Mesh::VertexHandle vhandle[4];
|
||||||
|
|
||||||
|
vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
|
||||||
|
vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
|
||||||
|
vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
|
||||||
|
vhandle[3] = mesh_.add_vertex(Mesh::Point(0, 0, 1));
|
||||||
|
|
||||||
|
// Add four faces
|
||||||
|
std::vector<Mesh::VertexHandle> face_vhandles;
|
||||||
|
|
||||||
|
face_vhandles.push_back(vhandle[0]);
|
||||||
|
face_vhandles.push_back(vhandle[1]);
|
||||||
|
face_vhandles.push_back(vhandle[2]);
|
||||||
|
mesh_.add_face(face_vhandles);
|
||||||
|
|
||||||
|
face_vhandles.clear();
|
||||||
|
|
||||||
|
face_vhandles.push_back(vhandle[0]);
|
||||||
|
face_vhandles.push_back(vhandle[2]);
|
||||||
|
face_vhandles.push_back(vhandle[3]);
|
||||||
|
mesh_.add_face(face_vhandles);
|
||||||
|
|
||||||
|
face_vhandles.clear();
|
||||||
|
|
||||||
|
face_vhandles.push_back(vhandle[2]);
|
||||||
|
face_vhandles.push_back(vhandle[1]);
|
||||||
|
face_vhandles.push_back(vhandle[3]);
|
||||||
|
mesh_.add_face(face_vhandles);
|
||||||
|
|
||||||
|
face_vhandles.clear();
|
||||||
|
|
||||||
|
face_vhandles.push_back(vhandle[3]);
|
||||||
|
face_vhandles.push_back(vhandle[1]);
|
||||||
|
face_vhandles.push_back(vhandle[0]);
|
||||||
|
mesh_.add_face(face_vhandles);
|
||||||
|
|
||||||
|
|
||||||
|
// ===============================================
|
||||||
|
// Setup complete
|
||||||
|
// ===============================================
|
||||||
|
|
||||||
|
|
||||||
|
mesh_.request_vertex_normals();
|
||||||
|
mesh_.request_halfedge_normals();
|
||||||
|
mesh_.request_face_normals();
|
||||||
|
|
||||||
|
OpenMesh::Vec3f normal;
|
||||||
|
|
||||||
|
|
||||||
|
mesh_.calc_vertex_normal_correct(vhandle[2],normal);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OpenMeshNormals, NormalCalculations_calc_vertex_normal_loop) {
|
||||||
|
|
||||||
|
mesh_.clear();
|
||||||
|
|
||||||
|
// Add some vertices
|
||||||
|
Mesh::VertexHandle vhandle[4];
|
||||||
|
|
||||||
|
vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
|
||||||
|
vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
|
||||||
|
vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
|
||||||
|
vhandle[3] = mesh_.add_vertex(Mesh::Point(0, 0, 1));
|
||||||
|
|
||||||
|
// Add four faces
|
||||||
|
std::vector<Mesh::VertexHandle> face_vhandles;
|
||||||
|
|
||||||
|
face_vhandles.push_back(vhandle[0]);
|
||||||
|
face_vhandles.push_back(vhandle[1]);
|
||||||
|
face_vhandles.push_back(vhandle[2]);
|
||||||
|
mesh_.add_face(face_vhandles);
|
||||||
|
|
||||||
|
face_vhandles.clear();
|
||||||
|
|
||||||
|
face_vhandles.push_back(vhandle[0]);
|
||||||
|
face_vhandles.push_back(vhandle[2]);
|
||||||
|
face_vhandles.push_back(vhandle[3]);
|
||||||
|
mesh_.add_face(face_vhandles);
|
||||||
|
|
||||||
|
face_vhandles.clear();
|
||||||
|
|
||||||
|
face_vhandles.push_back(vhandle[2]);
|
||||||
|
face_vhandles.push_back(vhandle[1]);
|
||||||
|
face_vhandles.push_back(vhandle[3]);
|
||||||
|
mesh_.add_face(face_vhandles);
|
||||||
|
|
||||||
|
face_vhandles.clear();
|
||||||
|
|
||||||
|
face_vhandles.push_back(vhandle[3]);
|
||||||
|
face_vhandles.push_back(vhandle[1]);
|
||||||
|
face_vhandles.push_back(vhandle[0]);
|
||||||
|
mesh_.add_face(face_vhandles);
|
||||||
|
|
||||||
|
// ===============================================
|
||||||
|
// Setup complete
|
||||||
|
// ===============================================
|
||||||
|
|
||||||
|
|
||||||
|
mesh_.request_vertex_normals();
|
||||||
|
mesh_.request_halfedge_normals();
|
||||||
|
mesh_.request_face_normals();
|
||||||
|
|
||||||
|
OpenMesh::Vec3f normal;
|
||||||
|
|
||||||
|
mesh_.calc_vertex_normal_loop(vhandle[2],normal);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user