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());
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)
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>
164 vectorize(normal,
Scalar(0));
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>
189 return calc_face_normal(_fh);
192 template <
class Kernel>
217 Point p1p0 = _p0; p1p0 -= _p1;
218 Point p1p2 = _p2; p1p2 -= _p1;
223 return (length != 0.0) ? n *= (1.0/length) :
Normal(0,0,0);
227 template <
class Kernel>
240 vectorize(normal,
Scalar(0));
246 template <
class Kernel>
252 vectorize(_pt,
Scalar(0));
254 for (
ConstFaceVertexIter cfv_it = this->cfv_iter(_fh); cfv_it.is_valid(); ++cfv_it, valence += 1.0)
256 _pt += this->point(*cfv_it);
264 template<
class Kernel>
269 return calc_face_centroid(_fh);
274 template<
class Kernel>
279 return this->calc_edge_midpoint(_eh);
284 template<
class Kernel>
289 return this->calc_edge_midpoint(this->edge_handle(_heh));
294 template<
class Kernel>
299 return this->point(_vh);
304 template<
class Kernel>
309 return this->vertices().avg(getPointsProperty(*
this));
314 template <
class Kernel>
320 if (Kernel::has_face_normals() ) {
321 update_face_normals();
323 if (Kernel::has_vertex_normals() ) update_vertex_normals();
324 if (Kernel::has_halfedge_normals()) update_halfedge_normals();
332 template <
class Kernel>
337 FaceIter f_it(Kernel::faces_sbegin()), f_end(Kernel::faces_end());
339 for (; f_it != f_end; ++f_it)
340 this->set_normal(*f_it, calc_face_normal(*f_it));
347 template <
class Kernel>
352 HalfedgeIter h_it(Kernel::halfedges_begin()), h_end(Kernel::halfedges_end());
354 for (; h_it != h_end; ++h_it)
355 this->set_normal(*h_it, calc_halfedge_normal(*h_it, _feature_angle));
362 template <
class Kernel>
367 if(Kernel::is_boundary(_heh))
371 std::vector<FaceHandle> fhs; fhs.reserve(10);
373 HalfedgeHandle heh = _heh;
378 fhs.push_back(Kernel::face_handle(heh));
380 heh = Kernel::next_halfedge_handle(heh);
381 heh = Kernel::opposite_halfedge_handle(heh);
383 while(heh != _heh && !Kernel::is_boundary(heh) && !is_estimated_feature_edge(heh, _feature_angle));
386 if(heh != _heh && !is_estimated_feature_edge(_heh, _feature_angle))
388 heh = Kernel::opposite_halfedge_handle(_heh);
390 if ( !Kernel::is_boundary(heh) ) {
394 fhs.push_back(Kernel::face_handle(heh));
396 heh = Kernel::prev_halfedge_handle(heh);
397 heh = Kernel::opposite_halfedge_handle(heh);
399 while(!Kernel::is_boundary(heh) && !is_estimated_feature_edge(heh, _feature_angle));
404 for(
unsigned int i=0; i<fhs.size(); ++i)
405 n += Kernel::normal(fhs[i]);
415 template <
class Kernel>
418 calc_normal(HalfedgeHandle _heh,
const double _feature_angle)
const 420 return calc_halfedge_normal(_heh, _feature_angle);
427 template <
class Kernel>
432 EdgeHandle eh = Kernel::edge_handle(_heh);
434 if(Kernel::has_edge_status())
436 if(Kernel::status(eh).feature())
440 if(Kernel::is_boundary(eh))
444 FaceHandle fh0 = Kernel::face_handle(_heh);
445 FaceHandle fh1 = Kernel::face_handle(Kernel::opposite_halfedge_handle(_heh));
447 Normal fn0 = Kernel::normal(fh0);
448 Normal fn1 = Kernel::normal(fh1);
451 return (
dot(fn0,fn1) < cos(_feature_angle) );
458 template <
class Kernel>
464 calc_vertex_normal_fast(_vh,n);
467 if (length != 0.0) n *= (
Scalar(1.0)/length);
473 template <
class Kernel>
479 _n += this->normal(*vf_it);
483 template <
class Kernel>
489 if (! cvih_it.is_valid() )
494 calc_edge_vector(*cvih_it, in_he_vec);
495 for ( ; cvih_it.is_valid(); ++cvih_it)
497 if (this->is_boundary(*cvih_it))
501 HalfedgeHandle out_heh(this->next_halfedge_handle(*cvih_it));
503 calc_edge_vector(out_heh, out_he_vec);
504 _n +=
cross(in_he_vec, out_he_vec);
505 in_he_vec = out_he_vec;
510 _n *= (
Scalar(1.0)/length);
514 template <
class Kernel>
521 Normal t_v(0.0,0.0,0.0), t_w(0.0,0.0,0.0);
522 unsigned int vh_val = this->valence(_vh);
530 _n =
cross(t_w, t_v);
535 template<
class Kernel>
541 calc_vertex_normal_correct(_vh, n);
547 template <
class Kernel>
552 VertexIter v_it(Kernel::vertices_begin()), v_end(Kernel::vertices_end());
554 for (; v_it!=v_end; ++v_it)
555 this->set_normal(*v_it, calc_vertex_normal(*v_it));
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.
bool is_estimated_feature_edge(HalfedgeHandle _heh, const double _feature_angle) const
Kernel::ConstVertexIHalfedgeIter ConstVertexIHalfedgeIter
Circulator.
Kernel::ConstVertexFaceIter ConstVertexFaceIter
Circulator.
Kernel::ConstFaceVertexIter ConstFaceVertexIter
Circulator.
Handle type for meshes to simplify some template programming.
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Kernel::Normal Normal
Normal type.
Kernel::Point Point
Coordinate type.
virtual Normal calc_face_normal(FaceHandle _fh) const
virtual Normal calc_halfedge_normal(HalfedgeHandle _heh, const double _feature_angle=0.8) const
Calculate halfedge normal for one specific halfedge.
void update_vertex_normals()
Update normal vectors for all vertices.
void calc_vertex_normal_fast(VertexHandle _vh, Normal &_n) const
unsigned int find_feature_edges(Scalar _angle_tresh=OpenMesh::deg_to_rad(44.0))
void calc_vertex_normal_correct(VertexHandle _vh, Normal &_n) const
Compute normals for all primitives.
void update_normals()
Compute normals for all primitives.
Kernel::Scalar Scalar
Scalar type.
void update_face_normals()
Update normal vectors for all faces.
Point calc_centroid(FaceHandle _fh) const
Computes and returns the average of the vertices defining _fh (same as calc_face_centroid) ...
void calc_face_centroid(FaceHandle _fh, Point &_pt) const
calculates the average of the vertices defining _fh
void calc_vertex_normal_loop(VertexHandle _vh, Normal &_n) const
Compute normals for all primitives.
void update_halfedge_normals(const double _feature_angle=0.8)
Update normal vectors for all halfedges.
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Kernel::ConstVertexOHalfedgeIter ConstVertexOHalfedgeIter
Circulator.
Normal calc_normal(FaceHandle _fh) const
same as calc_face_normal
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
T::value_type value_type
Type of the scalar value.
Normal calc_vertex_normal(VertexHandle _vh) const
Calculate vertex normal for one specific vertex.