52 #ifndef OPENMESH_POLYMESHT_HH 53 #define OPENMESH_POLYMESHT_HH 60 #include <OpenMesh/Core/Geometry/MathDefs.hh> 61 #include <OpenMesh/Core/Mesh/PolyConnectivity.hh> 62 #include <OpenMesh/Core/Mesh/FinalMeshItemsT.hh> 63 #include <OpenMesh/Core/Mesh/Tags.hh> 89 template <
class Kernel>
99 static constexpr
bool is_polymesh() {
return true; }
103 enum { IsPolyMesh = 1 };
104 enum { IsTriMesh = 0 };
109 typedef typename Kernel::Scalar
Scalar;
112 typedef typename Kernel::Point
Point;
128 typedef typename Kernel::Edge
Edge;
130 typedef typename Kernel::Face
Face;
137 typedef typename Kernel::HalfedgeHandle HalfedgeHandle;
138 typedef typename Kernel::EdgeHandle EdgeHandle;
139 typedef typename Kernel::FaceHandle FaceHandle;
143 typedef typename Kernel::VertexIter VertexIter;
144 typedef typename Kernel::HalfedgeIter HalfedgeIter;
145 typedef typename Kernel::EdgeIter EdgeIter;
146 typedef typename Kernel::FaceIter FaceIter;
148 typedef typename Kernel::ConstVertexIter ConstVertexIter;
149 typedef typename Kernel::ConstHalfedgeIter ConstHalfedgeIter;
150 typedef typename Kernel::ConstEdgeIter ConstEdgeIter;
151 typedef typename Kernel::ConstFaceIter ConstFaceIter;
187 explicit PolyMeshT(
const T& t) : Kernel(t) {}
202 {
return make_smart(Kernel::new_vertex(),
this); }
211 VertexHandle vh(Kernel::new_vertex());
212 this->set_point(vh, _p);
229 VertexHandle vh(Kernel::new_vertex_dirty());
230 this->set_point(vh, _p);
273 const Point& _p2)
const;
328 virtual Normal
calc_halfedge_normal(HalfedgeHandle _heh,
const double _feature_angle = 0.8)
const;
331 Normal
calc_normal(HalfedgeHandle,
const double _feature_angle = 0.8)
const;
409 return this->point(this->to_vertex_handle(_heh)) -
410 this->point(this->from_vertex_handle(_heh));
414 Scalar calc_edge_length(EdgeHandle _eh)
const 415 {
return calc_edge_length(this->halfedge_handle(_eh,0)); }
420 {
return (Scalar)sqrt(calc_edge_sqr_length(_heh)); }
422 Scalar calc_edge_sqr_length(EdgeHandle _eh)
const 423 {
return calc_edge_sqr_length(this->halfedge_handle(_eh,0)); }
425 Scalar calc_edge_sqr_length(HalfedgeHandle _heh)
const 429 return sqrnorm(edge_vec);
436 VertexHandle vh0 = this->from_vertex_handle(_heh);
437 VertexHandle vh1 = this->to_vertex_handle(_heh);
438 return 0.5 * (this->point(vh0) + this->point(vh1));
451 HalfedgeHandle _heh = this->halfedge_handle(_eh, 0);
452 VertexHandle vh0 = this->from_vertex_handle(_heh);
453 VertexHandle vh1 = this->to_vertex_handle(_heh);
476 Scalar denom = norm(v0)*norm(v1);
481 Scalar cos_a =
dot(v0 , v1) / denom;
482 if (this->is_boundary(_in_heh))
484 FaceHandle fh(this->face_handle(this->opposite_halfedge_handle(_in_heh)));
486 Scalar sign_a =
dot(
cross(v0, v1), f_n);
487 return angle(cos_a, sign_a);
521 _sector_normal =
cross(vec0, vec1);
529 Normal sector_normal;
531 return norm(sector_normal)/2;
539 assert(Kernel::has_face_normals());
541 if (this->is_boundary(this->edge_handle(_heh)))
545 const Normal& n0 = this->normal(this->face_handle(_heh));
546 const Normal& n1 = this->normal(this->face_handle(this->opposite_halfedge_handle(_heh)));
549 Scalar da_cos =
dot(n0, n1);
551 Scalar da_sin_sign =
dot(
cross(n0, n1), he);
552 return angle(da_cos, da_sin_sign);
561 Scalar calc_dihedral_angle(HalfedgeHandle _heh)
const 563 if (this->is_boundary(this->edge_handle(_heh)))
571 Scalar denom = norm(n0)*norm(n1);
576 Scalar da_cos =
dot(n0, n1)/denom;
578 Scalar da_sin_sign =
dot(
cross(n0, n1), he);
579 return angle(da_cos, da_sin_sign);
583 Scalar calc_dihedral_angle(EdgeHandle _eh)
const 584 {
return calc_dihedral_angle(this->halfedge_handle(_eh,0)); }
592 inline void split(FaceHandle _fh,
const Point& _p)
595 inline void split(FaceHandle _fh, VertexHandle _vh)
596 { Kernel::split(_fh, _vh); }
598 inline void split(EdgeHandle _eh,
const Point& _p)
601 inline void split(EdgeHandle _eh, VertexHandle _vh)
602 { Kernel::split_edge(_eh, _vh); }
607 Normal calc_face_normal_impl(FaceHandle,
PointIs3DTag)
const;
609 Normal calc_face_normal_impl(
const Point&,
const Point&,
const Point&,
PointIs3DTag)
const;
610 Normal calc_face_normal_impl(
const Point&,
const Point&,
const Point&,
PointIsNot3DTag)
const;
638 template<
typename LHS,
typename KERNEL>
643 template<
typename LHS,
typename KERNEL>
648 template<
typename LHS,
typename KERNEL>
653 template<
typename LHS,
typename KERNEL>
661 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_POLYMESH_C) 662 # define OPENMESH_POLYMESH_TEMPLATES 663 # include "PolyMeshT_impl.hh" 666 #endif // OPENMESH_POLYMESHT_HH defined void calc_sector_normal(HalfedgeHandle _in_heh, Normal &_sector_normal) const
Kernel::VertexVertexIter VertexVertexIter
Circulator.
Kernel::FaceFaceIter FaceFaceIter
Circulator.
Add 3D texture coordinates (vertices, halfedges)
Kernel::Edge Edge
Edge type.
Normal calc_edge_vector(HalfedgeHandle _heh) const
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.
void update_normal(VertexHandle _vh)
Update normal for vertex _vh.
void calc_edge_vector(EdgeHandle _eh, Normal &_edge_vec) const
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
void calc_sector_vectors(HalfedgeHandle _in_heh, Normal &_vec0, Normal &_vec1) const
Kernel::Color Color
Color type.
Connectivity tag indicating that the tagged mesh has polygon connectivity.
Normal calc_normal(EdgeHandle _eh) const
calculated and returns the average of the two vertex normals
Kernel::FaceEdgeIter FaceEdgeIter
Circulator.
Kernel::Normal Normal
Normal type.
Kernel::VertexFaceIter VertexFaceIter
Circulator.
Kernel::FaceVertexIter FaceVertexIter
Circulator.
Kernel::Vertex Vertex
Vertex type.
SmartVertexHandle new_vertex(const Point &_p)
Adds a new vertex initialized to a custom position.
Kernel::Point Point
Coordinate type.
void calc_edge_vector(HalfedgeHandle _heh, Normal &_edge_vec) const
virtual Normal calc_face_normal(FaceHandle _fh) const
T angle(T _cos_angle, T _sin_angle)
SmartVertexHandle new_vertex_dirty(const Point &_p)
virtual Normal calc_halfedge_normal(HalfedgeHandle _heh, const double _feature_angle=0.8) const
Calculate halfedge normal for one specific halfedge.
Add 2D texture coordinates (vertices, halfedges)
Kernel::Face Face
Face type.
T sane_aarg(T _aarg)
Trigonometry/angles - related.
Kernel::TexCoord1D TexCoord1D
TexCoord1D type.
SmartVertexHandle add_vertex_dirty(const Point &_p)
Alias for new_vertex_dirty().
Add colors to mesh item (vertices/faces/edges)
Kernel::TexCoord3D TexCoord3D
TexCoord3D type.
Kernel::ConstVertexEdgeIter ConstVertexEdgeIter
Circulator.
Kernel::VertexOHalfedgeIter VertexOHalfedgeIter
Circulator.
Kernel::ConstFaceHalfedgeIter ConstFaceHalfedgeIter
Circulator.
void update_normal(FaceHandle _fh)
Update normal for face _fh.
SmartVertexHandle make_smart(VertexHandle _vh, const PolyConnectivity *_mesh)
Creats a SmartVertexHandle from a VertexHandle and a Mesh.
Scalar calc_sector_area(HalfedgeHandle _in_heh) const
Kernel::VertexIHalfedgeIter VertexIHalfedgeIter
Circulator.
void update_vertex_normals()
Update normal vectors for all vertices.
Kernel::TexCoord2D TexCoord2D
TexCoord2D type.
void calc_vertex_normal_fast(VertexHandle _vh, Normal &_n) const
Scalar calc_edge_length(HalfedgeHandle _heh) const
Kernel::ConstFaceFaceIter ConstFaceFaceIter
Circulator.
SmartVertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Scalar calc_dihedral_angle_fast(EdgeHandle _eh) const
static constexpr bool is_polymesh()
Determine whether this is a PolyMeshT or TriMeshT (This function does not check the per face vertex c...
Cast a mesh with different but identical traits into each other.
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.
PolyMeshT< Kernel > This
Self type. Used to specify iterators/circulators.
static constexpr bool is_trimesh()
Determine whether this is a PolyMeshT or TriMeshT (This function does not check the per face vertex c...
Point calc_edge_midpoint(HalfedgeHandle _heh) const
void split(FaceHandle _fh, const Point &_p)
Face split (= 1-to-n split)
Scalar calc_dihedral_angle_fast(HalfedgeHandle _heh) const
Kernel::FaceHalfedgeIter FaceHalfedgeIter
Circulator.
Smart version of VertexHandle contains a pointer to the corresponding mesh and allows easier access t...
LHS mesh_cast(PolyMeshT< KERNEL > &rhs)
Cast a mesh with different but identical traits into each other.
Add 1D texture coordinates (vertices, halfedges)
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
Normal calc_edge_vector(EdgeHandle _eh) const
Point calc_edge_midpoint(EdgeHandle _eh) const
Scalar calc_sector_angle(HalfedgeHandle _in_heh) const
Kernel::Halfedge Halfedge
Halfedge type.
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.
Kernel::VertexEdgeIter VertexEdgeIter
Circulator.
Kernel::ConstVertexVertexIter ConstVertexVertexIter
Circulator.
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.
void update_normal(HalfedgeHandle _heh, const double _feature_angle=0.8)
Update normal for halfedge _heh.
Normal calc_normal(FaceHandle _fh) const
same as calc_face_normal
Kernel::ConstFaceEdgeIter ConstFaceEdgeIter
Circulator.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Normal calc_vertex_normal(VertexHandle _vh) const
Calculate vertex normal for one specific vertex.
SmartVertexHandle new_vertex()
Adds a new default-initialized vertex.