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>
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>
209 Point p1p0 = _p0; p1p0 -= _p1;
210 Point p1p2 = _p2; p1p2 -= _p1;
215 return (length != 0.0) ? n *= (1.0/length) :
Normal(0,0,0);
219 template <
class Kernel>
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);
315 HalfedgeHandle heh = _heh;
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>
362 EdgeHandle eh = Kernel::edge_handle(_heh);
364 if(Kernel::has_edge_status())
366 if(Kernel::status(eh).feature())
370 if(Kernel::is_boundary(eh))
374 FaceHandle fh0 = Kernel::face_handle(_heh);
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))
431 HalfedgeHandle out_heh(this->next_halfedge_handle(*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));
void update_halfedge_normals(const double _feature_angle=0.8)
Update normal vectors for all halfedges.
Definition: PolyMeshT_impl.hh:292
Kernel::Scalar Scalar
Scalar type.
Definition: PolyMeshT.hh:110
Base type for a polygonal mesh.
Definition: PolyMeshT.hh:90
Kernel::Normal Normal
Normal type.
Definition: PolyMeshT.hh:114
void calc_vertex_normal_loop(VertexHandle _vh, Normal &_n) const
Compute normals for all primitives.
Definition: PolyMeshT_impl.hh:443
virtual Normal calc_halfedge_normal(HalfedgeHandle _heh, const double _feature_angle=0.8) const
Calculate halfedge normal for one specific halfedge.
Definition: PolyMeshT_impl.hh:307
void calc_face_centroid(FaceHandle _fh, Point &_pt) const
calculates the average of the vertices defining _fh
Definition: PolyMeshT.hh:275
virtual Normal calc_face_normal(FaceHandle _fh) const
Calculate normal vector for face _fh.
Definition: PolyMeshT_impl.hh:97
void update_vertex_normals()
Update normal vectors for all vertices.
Definition: PolyMeshT_impl.hh:466
void update_normals()
Compute normals for all primitives.
Definition: PolyMeshT_impl.hh:259
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:82
Kernel::ConstVertexFaceIter ConstVertexFaceIter
Circulator.
Definition: PolyMeshT.hh:176
Kernel::ConstVertexIHalfedgeIter ConstVertexIHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:174
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:136
void update_face_normals()
Update normal vectors for all faces.
Definition: PolyMeshT_impl.hh:277
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:176
void calc_vertex_normal_correct(VertexHandle _vh, Normal &_n) const
Compute normals for all primitives.
Definition: PolyMeshT_impl.hh:415
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
Normal calc_vertex_normal(VertexHandle _vh) const
Calculate vertex normal for one specific vertex.
Definition: PolyMeshT_impl.hh:391
implements cache for the weights of the original Loop scheme supported:
Definition: LoopSchemeMaskT.hh:66
Helper class providing information about a vector type.
Definition: vector_traits.hh:88
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:191
void calc_vertex_normal_fast(VertexHandle _vh, Normal &_n) const
Different methods for calculation of the normal at _vh:
Definition: PolyMeshT_impl.hh:405
static T & Instance()
Singleton access function.
Definition: SingletonT.hh:89
Kernel::ConstVertexOHalfedgeIter ConstVertexOHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:173
unsigned int find_feature_edges(Scalar _angle_tresh=OpenMesh::deg_to_rad(44.0))
tags an edge as a feature if its dihedral angle is larger than _angle_tresh returns the number of the...
Definition: PolyMeshT_impl.hh:74
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.
Definition: vector_cast.hh:81
T::value_type value_type
Type of the scalar value.
Definition: vector_traits.hh:94
This file provides the streams omlog, omout, and omerr.
bool is_estimated_feature_edge(HalfedgeHandle _heh, const double _feature_angle) const
identifies feature edges w.r.t.
Definition: PolyMeshT_impl.hh:360
Kernel::ConstFaceVertexIter ConstFaceVertexIter
Circulator.
Definition: PolyMeshT.hh:177