📄 basekernel.hh
字号:
//=============================================================================//// 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.3 $// $Date: 2005-12-21 13:51:57 $////=============================================================================//=============================================================================//// CLASS BaseKernel////=============================================================================#ifndef OPENMESH_BASE_KERNEL_HH#define OPENMESH_BASE_KERNEL_HH//== INCLUDES =================================================================#include <OpenMesh/Core/System/config.hh>// --------------------#include <vector>#include <string>#include <algorithm>// --------------------#include <OpenMesh/Core/Utils/Property.hh>//== NAMESPACES ===============================================================namespace OpenMesh {//== CLASS DEFINITION =========================================================/// This class provides the basic property management like adding/removing/// properties and access to properties./// All operations provided by %BaseKernel need at least a property handle/// (VPropHandleT, EPropHandleT, HPropHandleT, FPropHandleT, MPropHandleT)./// which keeps the data type of the property, too.////// There are two types of properties:/// -# Standard properties - mesh data (e.g. vertex normal or face color)/// -# Custom properties - user defined data////// The differentiation is only semantically, technically both are/// equally handled. Therefore the methods provided by the %BaseKernel/// are applicable to both property types.////// \attention Since the class PolyMeshT derives from a kernel, hence all public/// elements of %BaseKernel are usable.class BaseKernel{public: //-------------------------------------------- constructor / destructor BaseKernel() {} virtual ~BaseKernel() {}public: //-------------------------------------------------- add new properties /// \name Add a property to a mesh item //@{ /** Adds a property * * Depending on the property handle type a vertex, (half-)edge, face or * mesh property is added to the mesh. If the action fails the handle * is invalid. * On success the handle must be used to access the property data with * property(). * * \param _ph A property handle defining the data type to bind to mesh. * On success the handle is valid else invalid. * \param _name Optional name of property. Following restrictions apply * to the name: * -# Maximum length of name is 256 characters * -# The prefixes matching "^[vhefm]:" are reserved for * internal usage. * -# The expression "^<.*>$" is reserved for internal usage. * \return \c true on success else \c false. * */ template <class T> void add_property( VPropHandleT<T>& _ph, const std::string& _name="<vprop>" ) { _ph = VPropHandleT<T>( vprops_.add(T(), _name) ); vprops_.resize(n_vertices()); } template <class T> void add_property( HPropHandleT<T>& _ph, const std::string& _name="<hprop>" ) { _ph = HPropHandleT<T>( hprops_.add(T(), _name) ); hprops_.resize(n_halfedges()); } template <class T> void add_property( EPropHandleT<T>& _ph, const std::string& _name="<eprop>" ) { _ph = EPropHandleT<T>( eprops_.add(T(), _name) ); eprops_.resize(n_edges()); } template <class T> void add_property( FPropHandleT<T>& _ph, const std::string& _name="<fprop>" ) { _ph = FPropHandleT<T>( fprops_.add(T(), _name) ); fprops_.resize(n_faces()); } template <class T> void add_property( MPropHandleT<T>& _ph, const std::string& _name="<mprop>" ) { _ph = MPropHandleT<T>( mprops_.add(T(), _name) ); mprops_.resize(1); } //@}public: //--------------------------------------------------- remove properties /// \name Removing a property from a mesh tiem //@{ /** Remove a property. * * Removes the property represented by the handle from the apropriate * mesh item. * \param _ph Property to be removed. The handle is invalid afterwords. */ template <typename T> void remove_property(VPropHandleT<T>& _ph) { if (_ph.is_valid()) vprops_.remove(_ph); _ph.reset(); } template <typename T> void remove_property(HPropHandleT<T>& _ph) { if (_ph.is_valid()) hprops_.remove(_ph); _ph.reset(); } template <typename T> void remove_property(EPropHandleT<T>& _ph) { if (_ph.is_valid()) eprops_.remove(_ph); _ph.reset(); } template <typename T> void remove_property(FPropHandleT<T>& _ph) { if (_ph.is_valid()) fprops_.remove(_ph); _ph.reset(); } template <typename T> void remove_property(MPropHandleT<T>& _ph) { if (_ph.is_valid()) mprops_.remove(_ph); _ph.reset(); } //@}public: //------------------------------------------------ get handle from name /// \name Get property handle by name //@{ /** Retrieves the handle to a named property by it's name. * * \param _ph A property handle. On success the handle is valid else * invalid. * \param _name Name of wanted property. * \return \c true if such a named property is available, else \c false. */ template <class T> bool get_property_handle(VPropHandleT<T>& _ph, const std::string& _name) const { return (_ph = VPropHandleT<T>(vprops_.handle(T(), _name))).is_valid(); } template <class T> bool get_property_handle(HPropHandleT<T>& _ph, const std::string& _name) const { return (_ph = HPropHandleT<T>(hprops_.handle(T(), _name))).is_valid(); } template <class T> bool get_property_handle(EPropHandleT<T>& _ph, const std::string& _name) const { return (_ph = EPropHandleT<T>(eprops_.handle(T(), _name))).is_valid(); } template <class T> bool get_property_handle(FPropHandleT<T>& _ph, const std::string& _name) const { return (_ph = FPropHandleT<T>(fprops_.handle(T(), _name))).is_valid(); } template <class T> bool get_property_handle(MPropHandleT<T>& _ph, const std::string& _name) const { return (_ph = MPropHandleT<T>(mprops_.handle(T(), _name))).is_valid(); } //@}public: //--------------------------------------------------- access properties /// \name Access a property //@{ /** Access a property * * This method returns a reference to property. The property handle * must be valid! The result is unpredictable if the handle is invalid! * * \param _ph A \em valid (!) property handle. * \return The wanted property if the handle is valid. */ template <class T> PropertyT<T>& property(VPropHandleT<T> _ph) { return vprops_.property(_ph); } template <class T> const PropertyT<T>& property(VPropHandleT<T> _ph) const { return vprops_.property(_ph); } template <class T> PropertyT<T>& property(HPropHandleT<T> _ph) { return hprops_.property(_ph); } template <class T> const PropertyT<T>& property(HPropHandleT<T> _ph) const { return hprops_.property(_ph); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -