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);
142 n[0] +=
static_cast<typename Normal::value_type
>(a[1] * b[2]);
143 n[1] +=
static_cast<typename Normal::value_type
>(a[2] * b[0]);
144 n[2] +=
static_cast<typename Normal::value_type
>(a[0] * b[1]);
147 const typename vector_traits<Normal>::value_type norm = n.length();
152 return (norm !=
typename vector_traits<Normal>::value_type(0))
157 template <
class Kernel>
159 PolyMeshT<Kernel>::calc_face_normal_impl(FaceHandle, PointIsNot3DTag)
const
162 return Normal(
typename Normal::value_type(0));
167 template <
class Kernel>
172 const Point& _p2)
const
174 return calc_face_normal_impl(_p0, _p1, _p2,
typename GenProg::IF<
181 template <
class Kernel>
204 Point p1p0 = _p0; p1p0 -= _p1;
205 Point p1p2 = _p2; p1p2 -= _p1;
210 return (norm != 0.0) ? n *= (1.0/norm) :
Normal(0,0,0);
214 template <
class Kernel>
216 PolyMeshT<Kernel>::calc_face_normal_impl(
const Point&,
const Point&,
const Point&, PointIsNot3DTag)
const
218 return Normal(
typename Normal::value_type(0));
223 template <
class Kernel>
224 typename PolyMeshT<Kernel>::Point
231 for (
ConstFaceVertexIter cfv_it = this->cfv_iter(_fh); cfv_it.is_valid(); ++cfv_it, valence += 1.0)
233 _pt += this->point(*cfv_it);
241 template <
class Kernel>
247 if (Kernel::has_face_normals() ) {
248 update_face_normals();
250 if (Kernel::has_vertex_normals() ) update_vertex_normals();
251 if (Kernel::has_halfedge_normals()) update_halfedge_normals();
259 template <
class Kernel>
264 FaceIter f_it(Kernel::faces_begin()), f_end(Kernel::faces_end());
266 for (; f_it != f_end; ++f_it)
267 this->set_normal(*f_it, calc_face_normal(*f_it));
274 template <
class Kernel>
279 HalfedgeIter h_it(Kernel::halfedges_begin()), h_end(Kernel::halfedges_end());
281 for (; h_it != h_end; ++h_it)
282 this->set_normal(*h_it, calc_halfedge_normal(*h_it, _feature_angle));
289 template <
class Kernel>
294 if(Kernel::is_boundary(_heh))
298 std::vector<FaceHandle> fhs; fhs.reserve(10);
300 HalfedgeHandle heh = _heh;
305 fhs.push_back(Kernel::face_handle(heh));
307 heh = Kernel::next_halfedge_handle(heh);
308 heh = Kernel::opposite_halfedge_handle(heh);
310 while(heh != _heh && !Kernel::is_boundary(heh) && !is_estimated_feature_edge(heh, _feature_angle));
313 if(heh != _heh && !is_estimated_feature_edge(_heh, _feature_angle))
315 heh = Kernel::opposite_halfedge_handle(_heh);
317 if ( !Kernel::is_boundary(heh) ) {
321 fhs.push_back(Kernel::face_handle(heh));
323 heh = Kernel::prev_halfedge_handle(heh);
324 heh = Kernel::opposite_halfedge_handle(heh);
326 while(!Kernel::is_boundary(heh) && !is_estimated_feature_edge(heh, _feature_angle));
331 for(
unsigned int i=0; i<fhs.size(); ++i)
332 n += Kernel::normal(fhs[i]);
334 return n.normalize();
342 template <
class Kernel>
347 EdgeHandle eh = Kernel::edge_handle(_heh);
349 if(Kernel::has_edge_status())
351 if(Kernel::status(eh).feature())
355 if(Kernel::is_boundary(eh))
359 FaceHandle fh0 = Kernel::face_handle(_heh);
360 FaceHandle fh1 = Kernel::face_handle(Kernel::opposite_halfedge_handle(_heh));
362 Normal fn0 = Kernel::normal(fh0);
363 Normal fn1 = Kernel::normal(fh1);
366 return (
dot(fn0,fn1) < cos(_feature_angle) );
373 template <
class Kernel>
379 calc_vertex_normal_fast(_vh,n);
382 if (norm != 0.0) n *= (
Scalar(1.0)/norm);
388 template <
class Kernel>
394 _n += this->normal(*vf_it);
398 template <
class Kernel>
404 if (! cvih_it.is_valid() )
409 calc_edge_vector(*cvih_it, in_he_vec);
410 for ( ; cvih_it.is_valid(); ++cvih_it)
412 if (this->is_boundary(*cvih_it))
416 HalfedgeHandle out_heh(this->next_halfedge_handle(*cvih_it));
418 calc_edge_vector(out_heh, out_he_vec);
419 _n +=
cross(in_he_vec, out_he_vec);
420 in_he_vec = out_he_vec;
426 template <
class Kernel>
433 Normal t_v(0.0,0.0,0.0), t_w(0.0,0.0,0.0);
434 unsigned int vh_val = this->valence(_vh);
442 _n =
cross(t_w, t_v);
448 template <
class Kernel>
453 VertexIter v_it(Kernel::vertices_begin()), v_end(Kernel::vertices_end());
455 for (; v_it!=v_end; ++v_it)
456 this->set_normal(*v_it, calc_vertex_normal(*v_it));
Kernel::Normal Normal
Normal type.
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
void update_normals()
Compute normals for all primitives.
Add normals to mesh item (vertices/faces)
void update_face_normals()
Update normal vectors for all faces.
void calc_vertex_normal_correct(VertexHandle _vh, Normal &_n) const
Compute normals for all primitives.
T::value_type value_type
Type of the scalar value.
Kernel::ConstVertexFaceIter ConstVertexFaceIter
Circulator.
Normal calc_vertex_normal(VertexHandle _vh) const
Calculate vertex normal for one specific vertex.
virtual Normal calc_halfedge_normal(HalfedgeHandle _heh, const double _feature_angle=0.8) const
Calculate halfedge normal for one specific halfedge.
virtual Normal calc_face_normal(FaceHandle _fh) const
Kernel::ConstVertexOHalfedgeIter ConstVertexOHalfedgeIter
Circulator.
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.
void calc_vertex_normal_fast(VertexHandle _vh, Normal &_n) const
void update_vertex_normals()
Update normal vectors for all vertices.
unsigned int find_feature_edges(Scalar _angle_tresh=OpenMesh::deg_to_rad(44.0))
Kernel::ConstVertexIHalfedgeIter ConstVertexIHalfedgeIter
Circulator.
bool is_estimated_feature_edge(HalfedgeHandle _heh, const double _feature_angle) const
void update_halfedge_normals(const double _feature_angle=0.8)
Update normal vectors for all halfedges.
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
void calc_vertex_normal_loop(VertexHandle _vh, Normal &_n) const
Compute normals for all primitives.
void calc_face_centroid(FaceHandle _fh, Point &_pt) const
calculates the average of the vertices defining _fh
Handle for a face entity.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Kernel::Scalar Scalar
Scalar type.
Kernel::ConstFaceVertexIter ConstFaceVertexIter
Circulator.