⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arraykernelt.hh

📁 penMesh is a generic and efficient data structure for representing and manipulating polygonal meshes
💻 HH
📖 第 1 页 / 共 2 页
字号:
//=============================================================================////                               OpenMesh//      Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen//                           www.openmesh.org////-----------------------------------------------------------------------------////                                License////   This library is free software; you can redistribute it and/or modify it//   under the terms of the GNU Library General Public License as published//   by the Free Software Foundation, version 2.////   This library is distributed in the hope that it will be useful, but//   WITHOUT ANY WARRANTY; without even the implied warranty of//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU//   Library General Public License for more details.////   You should have received a copy of the GNU Library General Public//   License along with this library; if not, write to the Free Software//   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.////-----------------------------------------------------------------------------////   $Revision: 1.7 $//   $Date: 2005-12-21 13:51:54 $////=============================================================================//=============================================================================////  CLASS ArrayKernelT////=============================================================================#ifndef OPENMESH_ARRAY_KERNEL_HH#define OPENMESH_ARRAY_KERNEL_HH//== INCLUDES =================================================================#include <OpenMesh/Core/System/config.hh>#include <OpenMesh/Core/Mesh/Kernels/Common/AttribKernelT.hh>#include <OpenMesh/Core/Utils/GenProg.hh>#include <vector>//== NAMESPACES ===============================================================namespace OpenMesh {//== CLASS DEFINITION =========================================================/** \ingroup mesh_kernels_group    Mesh kernel using arrays for mesh item storage.    This mesh kernel uses the std::vector as container to store the    mesh items. Therefore all handle types are internally represented    by integers. To get the index from a handle use the handle's \c    idx() method.    \note For a description of the minimal kernel interface see    OpenMesh::Mesh::BaseKernel.    \note You do not have to use this class directly, use the predefined    mesh-kernel combinations in \ref mesh_types_group.    \see OpenMesh::Concepts::KernelT, \ref mesh_type*/template <class AttribKernel, class FinalMeshItems>class ArrayKernelT : public AttribKernel{public:  typedef ArrayKernelT<AttribKernel, FinalMeshItems>  This;  typedef AttribKernel                                Base;  // attributes  typedef typename Base::HasPrevHalfedge              HasPrevHalfedge;  // item types  typedef typename FinalMeshItems::Vertex             Vertex;  typedef typename FinalMeshItems::Halfedge           Halfedge;  typedef typename FinalMeshItems::Edge               Edge;  typedef typename FinalMeshItems::Face               Face;  typedef typename FinalMeshItems::Point              Point;  typedef typename FinalMeshItems::Scalar             Scalar;  // handles  typedef OpenMesh::VertexHandle       VertexHandle;  typedef OpenMesh::HalfedgeHandle     HalfedgeHandle;  typedef OpenMesh::EdgeHandle         EdgeHandle;  typedef OpenMesh::FaceHandle         FaceHandle;  // --- constructor/destructor ---  ArrayKernelT() {}  ~ArrayKernelT() { clear(); }  void copy_topology_from(const ArrayKernelT& _other)  {    // copy raw data    vertices_ = _other.vertices_;    edges_    = _other.edges_;    faces_    = _other.faces_;    // resize properties    resize(n_vertices(), n_edges(), n_faces());  }  // --- handle -> item ---  VertexHandle handle(const Vertex& _v) const  {    return VertexHandle(&_v - &vertices_.front());  }  HalfedgeHandle handle(const Halfedge& _he) const {    unsigned int eh = ((char*)&_he - (char*)&edges_.front()) / sizeof(Edge);    assert((&_he == &edges_[eh].halfedges_[0]) ||	   (&_he == &edges_[eh].halfedges_[1]));    return ((&_he == &edges_[eh].halfedges_[0]) ?	    HalfedgeHandle(eh<<1) : HalfedgeHandle((eh<<1)+1));  }  EdgeHandle handle(const Edge& _e) const {    return EdgeHandle(&_e - &edges_.front());  }  FaceHandle handle(const Face& _f) const {    return FaceHandle(&_f - &faces_.front());  }#define SIGNED(x) signed( (x) )  //checks handle validity - useful for debugging  bool is_valid_handle(VertexHandle _vh) const  {    return 0 <= _vh.idx() && _vh.idx() < SIGNED(n_vertices());  }  bool is_valid_handle(HalfedgeHandle _heh) const  {    return 0 <= _heh.idx() && _heh.idx() < SIGNED(n_edges()*2);  }  bool is_valid_handle(EdgeHandle _eh) const  {    return 0 <= _eh.idx() && _eh.idx() < SIGNED(n_edges());  }  bool is_valid_handle(FaceHandle _fh) const  {    return 0 <= _fh.idx() && _fh.idx() < SIGNED(n_faces());  }  // --- item -> handle ---  const Vertex& vertex(VertexHandle _vh) const  {    assert(is_valid_handle(_vh));    return vertices_[_vh.idx()];  }  Vertex& vertex(VertexHandle _vh)  {    assert(is_valid_handle(_vh));    return vertices_[_vh.idx()];  }  const Halfedge& halfedge(HalfedgeHandle _heh) const  {    assert(is_valid_handle(_heh));    return edges_[_heh.idx() >> 1].halfedges_[_heh.idx() & 1];  }  Halfedge& halfedge(HalfedgeHandle _heh)  {    assert(is_valid_handle(_heh));    return edges_[_heh.idx() >> 1].halfedges_[_heh.idx() & 1];  }  const Edge& edge(EdgeHandle _eh) const  {    assert(is_valid_handle(_eh));    return edges_[_eh.idx()];  }  Edge& edge(EdgeHandle _eh) {    assert(is_valid_handle(_eh));    return edges_[_eh.idx()];  }  const Face& face(FaceHandle _fh) const {    assert(is_valid_handle(_fh));    return faces_[_fh.idx()];  }  Face& face(FaceHandle _fh) {    assert(is_valid_handle(_fh));    return faces_[_fh.idx()];  }#undef SIGNED  // --- get i'th items ---  VertexHandle vertex_handle(unsigned int _i) const {    return (_i < n_vertices()) ? handle( vertices_[_i] ) : VertexHandle();  }  HalfedgeHandle halfedge_handle(unsigned int _i) const {    return (_i < n_halfedges()) ? halfedge_handle(edge_handle(_i/2), _i%2) : HalfedgeHandle();  }  EdgeHandle edge_handle(unsigned int _i) const {    return (_i < n_edges()) ? handle(edges_[_i]) : EdgeHandle();  }  FaceHandle face_handle(unsigned int _i) const {    return (_i < n_faces()) ? handle(faces_[_i]) : FaceHandle();  }  // --- add new items ---  void reserve( unsigned int _n_vertices,                unsigned int _n_edges,                unsigned int _n_faces )  {    vertices_.reserve(_n_vertices);    edges_.reserve(_n_edges);    faces_.reserve(_n_faces);    AttribKernel::vprops_reserve(_n_vertices);    AttribKernel::hprops_reserve(_n_edges*2);    AttribKernel::eprops_reserve(_n_edges);    AttribKernel::fprops_reserve(_n_faces);  }public:  VertexHandle new_vertex()  {    vertices_.push_back(Vertex());    vprops_resize(n_vertices());    return handle(vertices_.back());  }  VertexHandle new_vertex(const Point& _p)  {    vertices_.push_back(Vertex());    vprops_resize(n_vertices());    VertexHandle vh(handle(vertices_.back()));    set_point(vh, _p);    return vh;  }  HalfedgeHandle new_edge(VertexHandle _start_vertex_handle,                          VertexHandle _end_vertex_handle)  {    assert(_start_vertex_handle != _end_vertex_handle);    edges_.push_back(Edge());    eprops_resize(n_edges());    hprops_resize(n_halfedges());    EdgeHandle eh(handle(edges_.back()));    HalfedgeHandle heh0(halfedge_handle(eh, 0));    HalfedgeHandle heh1(halfedge_handle(eh, 1));    set_vertex_handle(heh0, _end_vertex_handle);    set_vertex_handle(heh1, _start_vertex_handle);    return heh0;  }  FaceHandle new_face()  {    faces_.push_back(Face());    fprops_resize(n_faces());    return handle(faces_.back());  }  FaceHandle new_face(const Face& _f)  {    faces_.push_back(_f);    fprops_resize(n_faces());    return handle(faces_.back());  }public:  // --- deletion ---  void garbage_collection(bool _v=true, bool _e=true, bool _f=true);  void clear()   {    vertices_.clear();    edges_.clear();    faces_.clear();    AttribKernel::vprops_resize(0);    AttribKernel::eprops_resize(0);    AttribKernel::hprops_resize(0);    AttribKernel::fprops_resize(0);  }  void free_mem()  {    VertexContainer(vertices_).swap(vertices_);    EdgeContainer(edges_).swap(edges_);    FaceContainer(faces_).swap(faces_);    Base::vprops_free_mem();    Base::eprops_free_mem();    Base::hprops_free_mem();    Base::fprops_free_mem();  }  void resize( unsigned int _n_vertices,	       unsigned int _n_edges,	       unsigned int _n_faces )  {    vertices_.resize(_n_vertices);    edges_.resize(_n_edges);    faces_.resize(_n_faces);    vprops_resize(n_vertices());    hprops_resize(n_halfedges());    eprops_resize(n_edges());    fprops_resize(n_faces());  }  // --- number of items ---  unsigned int n_vertices()  const { return vertices_.size(); }  unsigned int n_halfedges() const { return 2*edges_.size(); }  unsigned int n_edges()     const { return edges_.size(); }  unsigned int n_faces()     const { return faces_.size(); }  bool empty()           const { return vertices_.empty(); }  bool vertices_empty()  const { return vertices_.empty(); }  bool halfedges_empty() const { return edges_.empty(); }  bool edges_empty()     const { return edges_.empty(); }  bool faces_empty()     const { return faces_.empty(); }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -