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>
73template <
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)
82 this->status(*e_it).set_feature(
true);
87 this->status(*e_it).set_feature(
false);
90 return n_feature_edges;
95template <
class Kernel>
99 return calc_face_normal_impl(_fh,
typename GenProg::IF<
106template <
class Kernel>
108PolyMeshT<Kernel>::calc_face_normal_impl(
FaceHandle _fh, PointIs3DTag)
const
110 assert(this->halfedge_handle(_fh).is_valid());
111 ConstFaceVertexIter fv_it(this->cfv_iter(_fh));
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)
124 ConstFaceVertexIter fv_itn = 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);
152template <
class Kernel>
154PolyMeshT<Kernel>::calc_face_normal_impl(
FaceHandle, PointIsNot3DTag)
const
170template <
class Kernel>
175 const Point& _p2)
const
177 return calc_face_normal_impl(_p0, _p1, _p2,
typename GenProg::IF<
184template<
class Kernel>
192template <
class Kernel>
207 Normal n = cross(p1p2, p1p0);
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);
227template <
class Kernel>
229PolyMeshT<Kernel>::calc_face_normal_impl(
const Point&,
const Point&,
const Point&, PointIsNot3DTag)
const
246template <
class Kernel>
254 for (
ConstFaceVertexIter cfv_it = this->cfv_iter(_fh); cfv_it.is_valid(); ++cfv_it, valence += 1.0)
256 _pt += this->point(*cfv_it);
264template<
class Kernel>
274template<
class Kernel>
284template<
class Kernel>
294template<
class Kernel>
299 return this->point(_vh);
304template<
class Kernel>
309 return this->vertices().avg([
this](
VertexHandle vh) {
return this->point(vh); });
314template <
class Kernel>
320 if (Kernel::has_face_normals() ) {
332template <
class Kernel>
337 FaceIter f_it(Kernel::faces_sbegin()), f_end(Kernel::faces_end());
339 for (; f_it != f_end; ++f_it)
347template <
class Kernel>
352 HalfedgeIter h_it(Kernel::halfedges_begin()), h_end(Kernel::halfedges_end());
354 for (; h_it != h_end; ++h_it)
362template <
class Kernel>
367 if(Kernel::is_boundary(_heh))
371 std::vector<FaceHandle> fhs; fhs.reserve(10);
378 fhs.push_back(Kernel::face_handle(heh));
380 heh = Kernel::next_halfedge_handle(heh);
381 heh = Kernel::opposite_halfedge_handle(heh);
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);
404 for (
unsigned int i = 0; i < fhs.size(); ++i)
405 n += Kernel::has_face_normals() ? Kernel::normal(fhs[i]) :
calc_face_normal(fhs[i]);
415template <
class Kernel>
427template <
class Kernel>
433 for (
int i = 0; i < 2; ++i)
435 const auto heh = this->halfedge_handle(_eh, i);
436 const auto fh = this->face_handle(heh);
440 const auto length =
norm(n);
449template <
class Kernel>
456 if(Kernel::has_edge_status())
458 if(Kernel::status(eh).feature())
462 if(Kernel::is_boundary(eh))
467 FaceHandle fh1 = Kernel::face_handle(Kernel::opposite_halfedge_handle(_heh));
473 return (
dot(fn0,fn1) < cos(_feature_angle) );
480template <
class Kernel>
489 if (length != 0.0) n *= (
Scalar(1.0)/length);
495template <
class Kernel>
501 _n += this->normal(*vf_it);
505template <
class Kernel>
511 if (! cvih_it.is_valid() )
517 for ( ; cvih_it.is_valid(); ++cvih_it)
519 if (this->is_boundary(*cvih_it))
526 _n += cross(in_he_vec, out_he_vec);
527 in_he_vec = out_he_vec;
532 _n *= (
Scalar(1.0)/length);
536template <
class Kernel>
540 static const LoopSchemeMaskDouble& loop_scheme_mask__ =
543 Normal t_v(0.0,0.0,0.0), t_w(0.0,0.0,0.0);
544 unsigned int vh_val = this->valence(_vh);
552 _n = cross(t_w, t_v);
557template<
class Kernel>
569template <
class Kernel>
574 VertexIter v_it(Kernel::vertices_begin()), v_end(Kernel::vertices_end());
576 for (; v_it!=v_end; ++v_it)
This file provides the streams omlog, omout, and omerr.
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition MeshItems.hh:59
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 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
@ Normal
Add normals to mesh item (vertices/faces)
Definition Attributes.hh:82
VectorT< Scalar, DIM > & normalize(VectorT< Scalar, DIM > &_v)
non-member normalize
Definition Vector11T.hh:769
VectorT< Scalar, DIM > & vectorize(VectorT< Scalar, DIM > &_v, OtherScalar const &_val)
non-member vectorize
Definition Vector11T.hh:762
Scalar norm(const VectorT< Scalar, DIM > &_v)
non-member norm
Definition Vector11T.hh:749
Handle for a face entity.
Definition Handles.hh:142
Handle type for meshes to simplify some template programming.
Definition Handles.hh:149
Base type for a polygonal mesh.
Definition PolyMeshT.hh:91
void calc_face_centroid(FaceHandle _fh, Point &_pt) const
calculates the average of the vertices defining _fh
Definition PolyMeshT.hh:282
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition PolyMeshT.hh:136
Kernel::Scalar Scalar
Scalar type.
Definition PolyMeshT.hh:110
Kernel::EdgeHandle EdgeHandle
Scalar type.
Definition PolyMeshT.hh:138
Kernel::ConstFaceVertexIter ConstFaceVertexIter
Circulator.
Definition PolyMeshT.hh:177
void calc_vertex_normal_fast(VertexHandle _vh, Normal &_n) const
Different methods for calculation of the normal at _vh:
Definition PolyMeshT_impl.hh:497
void calc_vertex_normal_correct(VertexHandle _vh, Normal &_n) const
Compute normals for all primitives.
Definition PolyMeshT_impl.hh:507
Kernel::FaceIter FaceIter
Scalar type.
Definition PolyMeshT.hh:146
Kernel::Normal Normal
Normal type.
Definition PolyMeshT.hh:114
void update_face_normals()
Update normal vectors for all faces.
Definition PolyMeshT_impl.hh:335
void update_halfedge_normals(const double _feature_angle=0.8)
Update normal vectors for all halfedges.
Definition PolyMeshT_impl.hh:350
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
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
void update_normals()
Compute normals for all primitives.
Definition PolyMeshT_impl.hh:317
Kernel::ConstVertexFaceIter ConstVertexFaceIter
Circulator.
Definition PolyMeshT.hh:176
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
Scalar calc_dihedral_angle(HalfedgeHandle _heh) const
Compute normals for all primitives.
Definition PolyMeshT.hh:558
Kernel::ConstVertexIHalfedgeIter ConstVertexIHalfedgeIter
Circulator.
Definition PolyMeshT.hh:174
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:452
void calc_edge_vector(EdgeHandle _eh, Normal &_edge_vec) const
Calculates the edge vector as the vector defined by the halfedge with id #0 (see below)
Definition PolyMeshT.hh:389
Kernel::FaceHandle FaceHandle
Scalar type.
Definition PolyMeshT.hh:139
void calc_vertex_normal_loop(VertexHandle _vh, Normal &_n) const
Compute normals for all primitives.
Definition PolyMeshT_impl.hh:538
Kernel::HalfedgeHandle HalfedgeHandle
Scalar type.
Definition PolyMeshT.hh:137
Kernel::EdgeIter EdgeIter
Scalar type.
Definition PolyMeshT.hh:145
void update_vertex_normals()
Update normal vectors for all vertices.
Definition PolyMeshT_impl.hh:572
Kernel::ConstVertexOHalfedgeIter ConstVertexOHalfedgeIter
Circulator.
Definition PolyMeshT.hh:173
Point calc_edge_midpoint(HalfedgeHandle _heh) const
Calculates the midpoint of the halfedge _heh, defined by the positions of the two incident vertices.
Definition PolyMeshT.hh:437
Kernel::HalfedgeIter HalfedgeIter
Scalar type.
Definition PolyMeshT.hh:144
Kernel::Point Point
Coordinate type.
Definition PolyMeshT.hh:112
Normal calc_normal(FaceHandle _fh) const
same as calc_face_normal
Definition PolyMeshT_impl.hh:187
Kernel::VertexIter VertexIter
Scalar type.
Definition PolyMeshT.hh:143
Normal calc_vertex_normal(VertexHandle _vh) const
Calculate vertex normal for one specific vertex.
Definition PolyMeshT_impl.hh:483
static LoopSchemeMaskDouble & Instance()
Definition SingletonT.hh:86
Helper class providing information about a vector type.
Definition vector_traits.hh:89
T::value_type value_type
Type of the scalar value.
Definition vector_traits.hh:94