52 #define OPENMESH_POLYMESH_C
57 #include <OpenMesh/Core/Mesh/PolyMeshT.hh>
58 #include <OpenMesh/Core/Geometry/LoopSchemeMaskT.hh>
59 #include <OpenMesh/Core/Utils/GenProg.hh>
60 #include <OpenMesh/Core/Utils/vector_cast.hh>
61 #include <OpenMesh/Core/Utils/vector_traits.hh>
73 template <
class Kernel>
76 assert(Kernel::has_edge_status());
77 uint n_feature_edges = 0;
78 for (
EdgeIter e_it = Kernel::edges_begin(); e_it != Kernel::edges_end(); ++e_it)
80 if (fabs(calc_dihedral_angle(*e_it)) > _angle_tresh)
82 this->status(*e_it).set_feature(
true);
87 this->status(*e_it).set_feature(
false);
90 return n_feature_edges;
95 template <
class Kernel>
99 return calc_face_normal_impl(_fh,
typename GenProg::IF<
106 template <
class Kernel>
110 assert(this->halfedge_handle(_fh).is_valid());
111 ConstFaceVertexIter fv_it(this->cfv_iter(_fh));
114 if (!(++fv_it).is_valid())
return Normal(0, 0, 0);
117 if (!(++fv_it).is_valid())
return Normal(0, 0, 0);
121 for(fv_it = this->cfv_iter(_fh); fv_it.is_valid(); ++fv_it)
124 ConstFaceVertexIter fv_itn = fv_it;
127 if (!fv_itn.is_valid())
128 fv_itn = this->cfv_iter(_fh);
131 const Point a = this->point(*fv_it) - this->point(*fv_itn);
132 const Point b = this->point(*fv_it) + this->point(*fv_itn);
152 template <
class Kernel>
154 PolyMeshT<Kernel>::calc_face_normal_impl(FaceHandle, PointIsNot3DTag)
const
170 template <
class Kernel>
175 const Point& _p2)
const
177 return calc_face_normal_impl(_p0, _p1, _p2,
typename GenProg::IF<
184 template <
class Kernel>
196 Normal p1p0(vector_cast<Normal>(_p0)); p1p0 -= vector_cast<Normal>(_p1);
197 Normal p1p2(vector_cast<Normal>(_p2)); p1p2 -= vector_cast<Normal>(_p1);
199 Normal n = cross(p1p2, p1p0);
209 Point p1p0 = _p0; p1p0 -= _p1;
210 Point p1p2 = _p2; p1p2 -= _p1;
212 Normal n = vector_cast<Normal>(cross(p1p2, p1p0));
215 return (length != 0.0) ? n *= (1.0/length) :
Normal(0,0,0);
219 template <
class Kernel>
221 PolyMeshT<Kernel>::calc_face_normal_impl(
const Point&,
const Point&,
const Point&, PointIsNot3DTag)
const
238 template <
class Kernel>
246 for (
ConstFaceVertexIter cfv_it = this->cfv_iter(_fh); cfv_it.is_valid(); ++cfv_it, valence += 1.0)
248 _pt += this->point(*cfv_it);
256 template <
class Kernel>
262 if (Kernel::has_face_normals() ) {
263 update_face_normals();
265 if (Kernel::has_vertex_normals() ) update_vertex_normals();
266 if (Kernel::has_halfedge_normals()) update_halfedge_normals();
274 template <
class Kernel>
279 FaceIter f_it(Kernel::faces_sbegin()), f_end(Kernel::faces_end());
281 for (; f_it != f_end; ++f_it)
282 this->set_normal(*f_it, calc_face_normal(*f_it));
289 template <
class Kernel>
294 HalfedgeIter h_it(Kernel::halfedges_begin()), h_end(Kernel::halfedges_end());
296 for (; h_it != h_end; ++h_it)
297 this->set_normal(*h_it, calc_halfedge_normal(*h_it, _feature_angle));
304 template <
class Kernel>
309 if(Kernel::is_boundary(_heh))
313 std::vector<FaceHandle> fhs; fhs.reserve(10);
320 fhs.push_back(Kernel::face_handle(heh));
322 heh = Kernel::next_halfedge_handle(heh);
323 heh = Kernel::opposite_halfedge_handle(heh);
325 while(heh != _heh && !Kernel::is_boundary(heh) && !is_estimated_feature_edge(heh, _feature_angle));
328 if(heh != _heh && !is_estimated_feature_edge(_heh, _feature_angle))
330 heh = Kernel::opposite_halfedge_handle(_heh);
332 if ( !Kernel::is_boundary(heh) ) {
336 fhs.push_back(Kernel::face_handle(heh));
338 heh = Kernel::prev_halfedge_handle(heh);
339 heh = Kernel::opposite_halfedge_handle(heh);
341 while(!Kernel::is_boundary(heh) && !is_estimated_feature_edge(heh, _feature_angle));
346 for(
unsigned int i=0; i<fhs.size(); ++i)
347 n += Kernel::normal(fhs[i]);
357 template <
class Kernel>
364 if(Kernel::has_edge_status())
366 if(Kernel::status(eh).feature())
370 if(Kernel::is_boundary(eh))
375 FaceHandle fh1 = Kernel::face_handle(Kernel::opposite_halfedge_handle(_heh));
377 Normal fn0 = Kernel::normal(fh0);
378 Normal fn1 = Kernel::normal(fh1);
381 return (
dot(fn0,fn1) < cos(_feature_angle) );
388 template <
class Kernel>
394 calc_vertex_normal_fast(_vh,n);
397 if (length != 0.0) n *= (
Scalar(1.0)/length);
403 template <
class Kernel>
409 _n += this->normal(*vf_it);
413 template <
class Kernel>
419 if (! cvih_it.is_valid() )
424 calc_edge_vector(*cvih_it, in_he_vec);
425 for ( ; cvih_it.is_valid(); ++cvih_it)
427 if (this->is_boundary(*cvih_it))
433 calc_edge_vector(out_heh, out_he_vec);
434 _n += cross(in_he_vec, out_he_vec);
435 in_he_vec = out_he_vec;
441 template <
class Kernel>
448 Normal t_v(0.0,0.0,0.0), t_w(0.0,0.0,0.0);
449 unsigned int vh_val = this->valence(_vh);
457 _n = cross(t_w, t_v);
463 template <
class Kernel>
468 VertexIter v_it(Kernel::vertices_begin()), v_end(Kernel::vertices_end());
470 for (; v_it!=v_end; ++v_it)
471 this->set_normal(*v_it, calc_vertex_normal(*v_it));