57 #define OPENMESH_POLYMESH_C
62 #include <OpenMesh/Core/Mesh/PolyMeshT.hh>
63 #include <OpenMesh/Core/Geometry/LoopSchemeMaskT.hh>
64 #include <OpenMesh/Core/Utils/GenProg.hh>
65 #include <OpenMesh/Core/Utils/vector_cast.hh>
66 #include <OpenMesh/Core/Utils/vector_traits.hh>
78 template <
class Kernel>
81 assert(Kernel::has_edge_status());
82 uint n_feature_edges = 0;
83 for (EdgeIter e_it = Kernel::edges_begin(); e_it != Kernel::edges_end(); ++e_it)
85 if (fabs(calc_dihedral_angle(*e_it)) > _angle_tresh)
87 this->status(*e_it).set_feature(
true);
92 this->status(*e_it).set_feature(
false);
95 return n_feature_edges;
100 template <
class Kernel>
104 return calc_face_normal_impl(_fh,
typename GenProg::IF<
111 template <
class Kernel>
115 assert(this->halfedge_handle(_fh).is_valid());
116 ConstFaceVertexIter fv_it(this->cfv_iter(_fh));
119 if (!(++fv_it).is_valid())
return Normal(0, 0, 0);
122 if (!(++fv_it).is_valid())
return Normal(0, 0, 0);
126 for(fv_it = this->cfv_iter(_fh); fv_it.is_valid(); ++fv_it)
129 ConstFaceVertexIter fv_itn = fv_it;
132 if (!fv_itn.is_valid())
133 fv_itn = this->cfv_iter(_fh);
136 const Point a = this->point(*fv_it) - this->point(*fv_itn);
137 const Point b = this->point(*fv_it) + this->point(*fv_itn);
144 const typename vector_traits<Normal>::value_type norm = n.length();
149 return (norm !=
typename vector_traits<Normal>::value_type(0))
154 template <
class Kernel>
156 PolyMeshT<Kernel>::calc_face_normal_impl(FaceHandle, PointIsNot3DTag)
const
159 return Normal(
typename Normal::value_type(0));
164 template <
class Kernel>
169 const Point& _p2)
const
171 return calc_face_normal_impl(_p0, _p1, _p2,
typename GenProg::IF<
178 template <
class Kernel>
201 Point p1p0 = _p0; p1p0 -= _p1;
202 Point p1p2 = _p2; p1p2 -= _p1;
207 return (norm != 0.0) ? n *= (1.0/norm) :
Normal(0,0,0);
211 template <
class Kernel>
213 PolyMeshT<Kernel>::calc_face_normal_impl(
const Point&,
const Point&,
const Point&, PointIsNot3DTag)
const
215 return Normal(
typename Normal::value_type(0));
220 template <
class Kernel>
221 typename PolyMeshT<Kernel>::Point
228 for (
ConstFaceVertexIter cfv_it = this->cfv_iter(_fh); cfv_it.is_valid(); ++cfv_it, valence += 1.0)
230 _pt += this->point(*cfv_it);
238 template <
class Kernel>
244 if (Kernel::has_face_normals() ) {
245 update_face_normals();
247 if (Kernel::has_vertex_normals() ) update_vertex_normals();
248 if (Kernel::has_halfedge_normals()) update_halfedge_normals();
256 template <
class Kernel>
261 FaceIter f_it(Kernel::faces_begin()), f_end(Kernel::faces_end());
263 for (; f_it != f_end; ++f_it)
264 this->set_normal(*f_it, calc_face_normal(*f_it));
271 template <
class Kernel>
276 HalfedgeIter h_it(Kernel::halfedges_begin()), h_end(Kernel::halfedges_end());
278 for (; h_it != h_end; ++h_it)
279 this->set_normal(*h_it, calc_halfedge_normal(*h_it, _feature_angle));
286 template <
class Kernel>
291 if(Kernel::is_boundary(_heh))
295 std::vector<FaceHandle> fhs; fhs.reserve(10);
297 HalfedgeHandle heh = _heh;
302 fhs.push_back(Kernel::face_handle(heh));
304 heh = Kernel::next_halfedge_handle(heh);
305 heh = Kernel::opposite_halfedge_handle(heh);
307 while(heh != _heh && !Kernel::is_boundary(heh) && !is_estimated_feature_edge(heh, _feature_angle));
310 if(heh != _heh && !is_estimated_feature_edge(_heh, _feature_angle))
312 heh = Kernel::opposite_halfedge_handle(_heh);
314 if ( !Kernel::is_boundary(heh) ) {
318 fhs.push_back(Kernel::face_handle(heh));
320 heh = Kernel::prev_halfedge_handle(heh);
321 heh = Kernel::opposite_halfedge_handle(heh);
323 while(!Kernel::is_boundary(heh) && !is_estimated_feature_edge(heh, _feature_angle));
328 for(
unsigned int i=0; i<fhs.size(); ++i)
329 n += Kernel::normal(fhs[i]);
331 return n.normalize();
339 template <
class Kernel>
344 EdgeHandle eh = Kernel::edge_handle(_heh);
346 if(Kernel::has_edge_status())
348 if(Kernel::status(eh).feature())
352 if(Kernel::is_boundary(eh))
356 FaceHandle fh0 = Kernel::face_handle(_heh);
357 FaceHandle fh1 = Kernel::face_handle(Kernel::opposite_halfedge_handle(_heh));
359 Normal fn0 = Kernel::normal(fh0);
360 Normal fn1 = Kernel::normal(fh1);
363 return (
dot(fn0,fn1) < cos(_feature_angle) );
370 template <
class Kernel>
376 calc_vertex_normal_fast(_vh,n);
379 if (norm != 0.0) n *= (
Scalar(1.0)/norm);
385 template <
class Kernel>
391 _n += this->normal(*vf_it);
395 template <
class Kernel>
401 if (! cvih_it.is_valid() )
406 calc_edge_vector(*cvih_it, in_he_vec);
407 for ( ; cvih_it.is_valid(); ++cvih_it)
409 if (this->is_boundary(*cvih_it))
413 HalfedgeHandle out_heh(this->next_halfedge_handle(*cvih_it));
415 calc_edge_vector(out_heh, out_he_vec);
416 _n +=
cross(in_he_vec, out_he_vec);
417 in_he_vec = out_he_vec;
423 template <
class Kernel>
430 Normal t_v(0.0,0.0,0.0), t_w(0.0,0.0,0.0);
431 unsigned int vh_val = this->valence(_vh);
439 _n =
cross(t_w, t_v);
445 template <
class Kernel>
450 VertexIter v_it(Kernel::vertices_begin()), v_end(Kernel::vertices_end());
452 for (; v_it!=v_end; ++v_it)
453 this->set_normal(*v_it, calc_vertex_normal(*v_it));
Kernel::ConstFaceVertexIter ConstFaceVertexIter
Circulator.
Kernel::ConstVertexOHalfedgeIter ConstVertexOHalfedgeIter
Circulator.
void calc_face_centroid(FaceHandle _fh, Point &_pt) const
calculates the average of the vertices defining _fh
virtual Normal calc_halfedge_normal(HalfedgeHandle _heh, const double _feature_angle=0.8) const
Calculate halfedge normal for one specific halfedge.
T::value_type value_type
Type of the scalar value.
void update_halfedge_normals(const double _feature_angle=0.8)
Update normal vectors for all halfedges.
void vector_cast(const src_t &_src, dst_t &_dst, GenProg::Int2Type< n >)
Cast vector type to another vector type by copying the vector elements.
Kernel::Point Point
Coordinate type.
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Normal calc_vertex_normal(VertexHandle _vh) const
Calculate vertex normal for one specific vertex.
unsigned int find_feature_edges(Scalar _angle_tresh=OpenMesh::deg_to_rad(44.0))
Kernel::ConstVertexIHalfedgeIter ConstVertexIHalfedgeIter
Circulator.
void update_vertex_normals()
Update normal vectors for all vertices.
void calc_vertex_normal_fast(VertexHandle _vh, Normal &_n) const
void update_face_normals()
Update normal vectors for all faces.
void calc_vertex_normal_loop(VertexHandle _vh, Normal &_n) const
Compute normals for all primitives.
Handle for a face entity.
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Kernel::Scalar Scalar
Scalar type.
Kernel::ConstVertexFaceIter ConstVertexFaceIter
Circulator.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
void calc_vertex_normal_correct(VertexHandle _vh, Normal &_n) const
Compute normals for all primitives.
void update_normals()
Compute normals for all primitives.
Add normals to mesh item (vertices/faces)
bool is_estimated_feature_edge(HalfedgeHandle _heh, const double _feature_angle) const
Kernel::Normal Normal
Normal type.
virtual Normal calc_face_normal(FaceHandle _fh) const