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.
Definition: vector_cast.hh:81
virtual Normal calc_face_normal(FaceHandle _fh) const
Calculate normal vector for face _fh.
Definition: PolyMeshT_impl.hh:97
bool is_estimated_feature_edge(HalfedgeHandle _heh, const double _feature_angle) const
identifies feature edges w.r.t.
Definition: PolyMeshT_impl.hh:430
Kernel::Scalar Scalar
Scalar type.
Definition: PolyMeshT.hh:110
void update_vertex_normals()
Update normal vectors for all vertices.
Definition: PolyMeshT_impl.hh:550
void update_halfedge_normals(const double _feature_angle=0.8)
Update normal vectors for all halfedges.
Definition: PolyMeshT_impl.hh:350
implements cache for the weights of the original Loop scheme supported:
Definition: LoopSchemeMaskT.hh:66
Point calc_centroid(FaceHandle _fh) const
Computes and returns the average of the vertices defining _fh (same as calc_face_centroid) ...
Definition: PolyMeshT_impl.hh:267
void calc_vertex_normal_loop(VertexHandle _vh, Normal &_n) const
Compute normals for all primitives.
Definition: PolyMeshT_impl.hh:516
Kernel::ConstFaceVertexIter ConstFaceVertexIter
Circulator.
Definition: PolyMeshT.hh:177
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:365
Helper class providing information about a vector type.
Definition: vector_traits.hh:88
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
Kernel::ConstVertexOHalfedgeIter ConstVertexOHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:173
Normal calc_normal(FaceHandle _fh) const
same as calc_face_normal
Definition: PolyMeshT_impl.hh:187
void calc_vertex_normal_correct(VertexHandle _vh, Normal &_n) const
Compute normals for all primitives.
Definition: PolyMeshT_impl.hh:485
void update_normals()
Compute normals for all primitives.
Definition: PolyMeshT_impl.hh:317
Kernel::Normal Normal
Normal type.
Definition: PolyMeshT.hh:114
Kernel::ConstVertexFaceIter ConstVertexFaceIter
Circulator.
Definition: PolyMeshT.hh:176
Normal calc_vertex_normal(VertexHandle _vh) const
Calculate vertex normal for one specific vertex.
Definition: PolyMeshT_impl.hh:461
void calc_face_centroid(FaceHandle _fh, Point &_pt) const
calculates the average of the vertices defining _fh
Definition: PolyMeshT.hh:279
T::value_type value_type
Type of the scalar value.
Definition: vector_traits.hh:94
This file provides the streams omlog, omout, and omerr.
void update_face_normals()
Update normal vectors for all faces.
Definition: PolyMeshT_impl.hh:335
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
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:475
Handle type for meshes to simplify some template programming.
Definition: Handles.hh:148
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
Kernel::ConstVertexIHalfedgeIter ConstVertexIHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:174
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:136
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:82
Base type for a polygonal mesh.
Definition: PolyMeshT.hh:90
static T & Instance()
Singleton access function.
Definition: SingletonT.hh:86