2015-04-28 11:54:17 +00:00
|
|
|
/* ========================================================================= *
|
2009-06-04 08:46:29 +00:00
|
|
|
* *
|
|
|
|
|
* OpenMesh *
|
2015-04-28 11:33:32 +00:00
|
|
|
* Copyright (c) 2001-2015, RWTH-Aachen University *
|
2015-04-28 13:07:46 +00:00
|
|
|
* Department of Computer Graphics and Multimedia *
|
2015-04-28 11:33:32 +00:00
|
|
|
* All rights reserved. *
|
|
|
|
|
* www.openmesh.org *
|
|
|
|
|
* *
|
|
|
|
|
*---------------------------------------------------------------------------*
|
|
|
|
|
* This file is part of OpenMesh. *
|
|
|
|
|
*---------------------------------------------------------------------------*
|
|
|
|
|
* *
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without *
|
|
|
|
|
* modification, are permitted provided that the following conditions *
|
|
|
|
|
* are met: *
|
|
|
|
|
* *
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, *
|
|
|
|
|
* this list of conditions and the following disclaimer. *
|
|
|
|
|
* *
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright *
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the *
|
|
|
|
|
* documentation and/or other materials provided with the distribution. *
|
|
|
|
|
* *
|
|
|
|
|
* 3. Neither the name of the copyright holder nor the names of its *
|
|
|
|
|
* contributors may be used to endorse or promote products derived from *
|
|
|
|
|
* this software without specific prior written permission. *
|
|
|
|
|
* *
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
|
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
|
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
|
|
|
|
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
|
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
|
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
|
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
|
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
|
2015-04-28 11:54:17 +00:00
|
|
|
* *
|
|
|
|
|
* ========================================================================= */
|
2009-06-04 08:46:29 +00:00
|
|
|
|
|
|
|
|
/*===========================================================================*\
|
|
|
|
|
* *
|
|
|
|
|
* $Revision$ *
|
|
|
|
|
* $Date$ *
|
|
|
|
|
* *
|
|
|
|
|
\*===========================================================================*/
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
#ifndef OPENMESH_HANDLES_HH
|
|
|
|
|
#define OPENMESH_HANDLES_HH
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//== INCLUDES =================================================================
|
|
|
|
|
|
|
|
|
|
#include <OpenMesh/Core/System/config.h>
|
2015-06-09 08:58:41 +00:00
|
|
|
#include <ostream>
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//== NAMESPACES ===============================================================
|
|
|
|
|
|
|
|
|
|
namespace OpenMesh {
|
|
|
|
|
|
|
|
|
|
//== CLASS DEFINITION =========================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Base class for all handle types
|
|
|
|
|
class BaseHandle
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
explicit BaseHandle(int _idx=-1) : idx_(_idx) {}
|
|
|
|
|
|
|
|
|
|
/// Get the underlying index of this handle
|
|
|
|
|
int idx() const { return idx_; }
|
|
|
|
|
|
|
|
|
|
/// The handle is valid iff the index is not equal to -1.
|
|
|
|
|
bool is_valid() const { return idx_ != -1; }
|
|
|
|
|
|
|
|
|
|
/// reset handle to be invalid
|
|
|
|
|
void reset() { idx_=-1; }
|
|
|
|
|
/// reset handle to be invalid
|
|
|
|
|
void invalidate() { idx_ = -1; }
|
|
|
|
|
|
|
|
|
|
bool operator==(const BaseHandle& _rhs) const {
|
2011-09-08 08:18:36 +00:00
|
|
|
return (this->idx_ == _rhs.idx_);
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator!=(const BaseHandle& _rhs) const {
|
2011-09-08 08:18:36 +00:00
|
|
|
return (this->idx_ != _rhs.idx_);
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator<(const BaseHandle& _rhs) const {
|
2011-09-08 08:18:36 +00:00
|
|
|
return (this->idx_ < _rhs.idx_);
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this is to be used only by the iterators
|
|
|
|
|
void __increment() { ++idx_; }
|
|
|
|
|
void __decrement() { --idx_; }
|
|
|
|
|
|
2015-12-14 17:32:25 +01:00
|
|
|
void __increment(int amount) { idx_ += amount; }
|
2016-02-04 09:40:23 +01:00
|
|
|
void __decrement(int amount) { idx_ -= amount; }
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
int idx_;
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-08 10:29:18 +02:00
|
|
|
// this is used by boost::unordered_set/map
|
|
|
|
|
inline size_t hash_value(const BaseHandle& h) { return h.idx(); }
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/// Write handle \c _hnd to stream \c _os
|
|
|
|
|
inline std::ostream& operator<<(std::ostream& _os, const BaseHandle& _hnd)
|
|
|
|
|
{
|
|
|
|
|
return (_os << _hnd.idx());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Handle for a vertex entity
|
|
|
|
|
struct VertexHandle : public BaseHandle
|
|
|
|
|
{
|
|
|
|
|
explicit VertexHandle(int _idx=-1) : BaseHandle(_idx) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Handle for a halfedge entity
|
|
|
|
|
struct HalfedgeHandle : public BaseHandle
|
|
|
|
|
{
|
|
|
|
|
explicit HalfedgeHandle(int _idx=-1) : BaseHandle(_idx) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Handle for a edge entity
|
|
|
|
|
struct EdgeHandle : public BaseHandle
|
|
|
|
|
{
|
|
|
|
|
explicit EdgeHandle(int _idx=-1) : BaseHandle(_idx) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Handle for a face entity
|
|
|
|
|
struct FaceHandle : public BaseHandle
|
|
|
|
|
{
|
|
|
|
|
explicit FaceHandle(int _idx=-1) : BaseHandle(_idx) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
} // namespace OpenMesh
|
|
|
|
|
//=============================================================================
|
2016-06-08 10:29:18 +02:00
|
|
|
|
|
|
|
|
#ifdef OM_HAS_HASH
|
|
|
|
|
#include <functional>
|
|
|
|
|
namespace std {
|
|
|
|
|
|
|
|
|
|
#if defined(_MSVC_VER)
|
|
|
|
|
# pragma warning(push)
|
|
|
|
|
# pragma warning(disable:4099) // For VC++ it is class hash
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
2016-08-03 10:07:28 +02:00
|
|
|
struct hash<OpenMesh::BaseHandle >
|
2016-06-08 10:29:18 +02:00
|
|
|
: public std::unary_function<OpenMesh::BaseHandle, std::size_t>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
std::size_t operator()(const OpenMesh::BaseHandle& h) const
|
|
|
|
|
{
|
|
|
|
|
return h.idx();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
struct hash<OpenMesh::VertexHandle >
|
|
|
|
|
: public std::unary_function<OpenMesh::VertexHandle, std::size_t>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
std::size_t operator()(const OpenMesh::VertexHandle& h) const
|
|
|
|
|
{
|
|
|
|
|
return h.idx();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
struct hash<OpenMesh::HalfedgeHandle >
|
|
|
|
|
: public std::unary_function<OpenMesh::HalfedgeHandle, std::size_t>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
std::size_t operator()(const OpenMesh::HalfedgeHandle& h) const
|
|
|
|
|
{
|
|
|
|
|
return h.idx();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
struct hash<OpenMesh::EdgeHandle >
|
|
|
|
|
: public std::unary_function<OpenMesh::EdgeHandle, std::size_t>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
std::size_t operator()(const OpenMesh::EdgeHandle& h) const
|
|
|
|
|
{
|
|
|
|
|
return h.idx();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
struct hash<OpenMesh::FaceHandle >
|
|
|
|
|
: public std::unary_function<OpenMesh::FaceHandle, std::size_t>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
std::size_t operator()(const OpenMesh::FaceHandle& h) const
|
|
|
|
|
{
|
|
|
|
|
return h.idx();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#if defined(_MSVC_VER)
|
|
|
|
|
# pragma warning(pop)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endif // OM_HAS_HASH
|
|
|
|
|
|
|
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
#endif // OPENMESH_HANDLES_HH
|
|
|
|
|
//=============================================================================
|