mirror of https://github.com/CGAL/cgal
Merge pull request #2492 from sloriot/OM-fix_edge_hashing
Fix hashing of edge_descriptor for OpenMesh
This commit is contained in:
commit
d333cc672d
|
|
@ -50,45 +50,6 @@
|
||||||
#endif
|
#endif
|
||||||
namespace CGAL { namespace internal {
|
namespace CGAL { namespace internal {
|
||||||
|
|
||||||
|
|
||||||
template<typename Halfedge_handle>
|
|
||||||
class OMesh_edge {
|
|
||||||
public:
|
|
||||||
OMesh_edge() : halfedge_() {}
|
|
||||||
explicit OMesh_edge(const Halfedge_handle& h) : halfedge_(h) {}
|
|
||||||
Halfedge_handle halfedge() const { return halfedge_; }
|
|
||||||
bool is_valid() const { return halfedge_.is_valid(); }
|
|
||||||
|
|
||||||
bool
|
|
||||||
operator==(const OMesh_edge& other) {
|
|
||||||
if(halfedge_ == other.halfedge_) {
|
|
||||||
return true;
|
|
||||||
} else if(halfedge_ != Halfedge_handle()) {
|
|
||||||
return opposite() == other.halfedge_;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator<(const OMesh_edge& other) const
|
|
||||||
{
|
|
||||||
return this->idx() < other.idx();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
operator!=(const OMesh_edge& other) { return !(*this == other); }
|
|
||||||
|
|
||||||
Halfedge_handle
|
|
||||||
opposite() const { return Halfedge_handle((halfedge_.idx() & 1) ? halfedge_.idx()-1 : halfedge_.idx()+1); }
|
|
||||||
|
|
||||||
OMesh_edge
|
|
||||||
opposite_edge() const { return OMesh_edge(Halfedge_handle((halfedge_.idx() & 1) ? halfedge_.idx()-1 : halfedge_.idx()+1)); }
|
|
||||||
|
|
||||||
unsigned int idx() const { return halfedge_.idx() / 2; }
|
|
||||||
private:
|
|
||||||
Halfedge_handle halfedge_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Halfedge_handle, typename OMeshEdge>
|
template <typename Halfedge_handle, typename OMeshEdge>
|
||||||
struct Convert_omesh_edge
|
struct Convert_omesh_edge
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,49 @@
|
||||||
|
|
||||||
#include <OpenMesh/Core/Mesh/Handles.hh>
|
#include <OpenMesh/Core/Mesh/Handles.hh>
|
||||||
|
|
||||||
|
namespace CGAL { namespace internal {
|
||||||
|
|
||||||
|
|
||||||
|
template<typename Halfedge_handle>
|
||||||
|
class OMesh_edge {
|
||||||
|
public:
|
||||||
|
OMesh_edge() : halfedge_() {}
|
||||||
|
explicit OMesh_edge(const Halfedge_handle& h) : halfedge_(h) {}
|
||||||
|
Halfedge_handle halfedge() const { return halfedge_; }
|
||||||
|
bool is_valid() const { return halfedge_.is_valid(); }
|
||||||
|
|
||||||
|
bool
|
||||||
|
operator==(const OMesh_edge& other) const {
|
||||||
|
if(halfedge_ == other.halfedge_) {
|
||||||
|
return true;
|
||||||
|
} else if(halfedge_ != Halfedge_handle()) {
|
||||||
|
return opposite() == other.halfedge_;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<(const OMesh_edge& other) const
|
||||||
|
{
|
||||||
|
return this->idx() < other.idx();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
operator!=(const OMesh_edge& other) { return !(*this == other); }
|
||||||
|
|
||||||
|
Halfedge_handle
|
||||||
|
opposite() const { return Halfedge_handle((halfedge_.idx() & 1) ? halfedge_.idx()-1 : halfedge_.idx()+1); }
|
||||||
|
|
||||||
|
OMesh_edge
|
||||||
|
opposite_edge() const { return OMesh_edge(Halfedge_handle((halfedge_.idx() & 1) ? halfedge_.idx()-1 : halfedge_.idx()+1)); }
|
||||||
|
|
||||||
|
unsigned int idx() const { return halfedge_.idx() / 2; }
|
||||||
|
private:
|
||||||
|
Halfedge_handle halfedge_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} } // CGAL::internal
|
||||||
|
|
||||||
#if OM_VERSION < 0x60200
|
#if OM_VERSION < 0x60200
|
||||||
|
|
||||||
namespace OpenMesh {
|
namespace OpenMesh {
|
||||||
|
|
@ -31,6 +74,11 @@ inline std::size_t hash_value(const BaseHandle& h) { return h.idx(); }
|
||||||
} // namespace OpenMesh
|
} // namespace OpenMesh
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace OpenMesh {
|
||||||
|
|
||||||
|
inline std::size_t hash_value(const CGAL::internal::OMesh_edge<OpenMesh::HalfedgeHandle>& h) { return h.idx(); }
|
||||||
|
|
||||||
|
} // namespace OpenMesh
|
||||||
|
|
||||||
#ifndef OM_HAS_HASH
|
#ifndef OM_HAS_HASH
|
||||||
|
|
||||||
|
|
@ -90,6 +138,17 @@ struct hash<OpenMesh::EdgeHandle >
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct hash<CGAL::internal::OMesh_edge<OpenMesh::HalfedgeHandle> >
|
||||||
|
: public std::unary_function<OpenMesh::HalfedgeHandle, std::size_t>
|
||||||
|
{
|
||||||
|
|
||||||
|
std::size_t operator()(const CGAL::internal::OMesh_edge<OpenMesh::HalfedgeHandle>& h) const
|
||||||
|
{
|
||||||
|
return h.idx();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct hash<OpenMesh::FaceHandle >
|
struct hash<OpenMesh::FaceHandle >
|
||||||
: public CGAL::unary_function<OpenMesh::FaceHandle, std::size_t>
|
: public CGAL::unary_function<OpenMesh::FaceHandle, std::size_t>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue