Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

mitkHalfEdgeStructures.h

00001 /*=========================================================================
00002 
00003   Program:   3DMed
00004   Date:      $Date: 2014-02-25 18:30:00 +0800 $
00005   Version:   $Version: 4.6.0 $
00006   Copyright: MIPG, Institute of Automation, Chinese Academy of Sciences
00007 
00008 =========================================================================*/
00009 
00010 
00011 #ifndef __mitkHalfEdgeStructures_h
00012 #define __mitkHalfEdgeStructures_h
00013 
00014 #include "mitkGeometryTypes.h"
00015 
00016 #define MITK_FLAG_DELETED 0x00000001
00017 
00018 typedef struct _vertex    HEVertex,   *HEVertexPtr;
00019 typedef struct _half_edge HEHalfEdge, *HEHalfEdgePtr;
00020 typedef struct _edge      HEEdge,     *HEEdgePtr;
00021 typedef struct _face      HEFace,     *HEFacePtr;
00022 
00023 template <typename T> class HandleT;
00024 
00025 template <typename T> inline bool operator==(HandleT<T> const &lhs, index_type rhs) { return (lhs._index==rhs); }
00026 template <typename T> inline bool operator==(index_type lhs, HandleT<T> const &rhs) { return (lhs==rhs._index); }
00027 template <typename T> inline bool operator!=(HandleT<T> const &lhs, index_type rhs) { return (lhs._index!=rhs); }
00028 template <typename T> inline bool operator!=(index_type lhs, HandleT<T> const &rhs) { return (lhs!=rhs._index); }
00029 template <typename T> inline bool operator<(HandleT<T> const &lhs, index_type rhs) { return (lhs._index<rhs); }
00030 template <typename T> inline bool operator<(index_type lhs, HandleT<T> const &rhs) { return (lhs<rhs._index); }
00031 template <typename T> inline bool operator<=(HandleT<T> const &lhs, index_type rhs) { return (lhs._index<=rhs); }
00032 template <typename T> inline bool operator<=(index_type lhs, HandleT<T> const &rhs) { return (lhs<=rhs._index); }
00033 template <typename T> inline bool operator>(HandleT<T> const &lhs, index_type rhs) { return (lhs._index>rhs); }
00034 template <typename T> inline bool operator>(index_type lhs, HandleT<T> const &rhs) { return (lhs>rhs._index); }
00035 template <typename T> inline bool operator>=(HandleT<T> const &lhs, index_type rhs) { return (lhs._index>=rhs); }
00036 template <typename T> inline bool operator>=(index_type lhs, HandleT<T> const &rhs) { return (lhs>=rhs._index); }
00037 
00038 #ifdef _MSC_VER
00039 #   if _MSC_VER >= 1310 
00040 #       define _TEMP_ <>
00041 #   else
00042 #       define _TEMP_
00043 #   endif
00044 #else
00045 #   define _TEMP_ <>
00046 #endif
00047 
00048 template <typename T> class HandleT
00049 {
00050     friend bool operator==_TEMP_(HandleT const &lhs, index_type rhs);
00051     friend bool operator==_TEMP_(index_type lhs, HandleT const &rhs);
00052     friend bool operator!=_TEMP_(HandleT const &lhs, index_type rhs);
00053     friend bool operator!=_TEMP_(index_type lhs, HandleT const &rhs);
00054     friend bool operator< _TEMP_(HandleT const &lhs, index_type rhs);
00055     friend bool operator< _TEMP_(index_type lhs, HandleT const &rhs);
00056     friend bool operator<=_TEMP_(HandleT const &lhs, index_type rhs);
00057     friend bool operator<=_TEMP_(index_type lhs, HandleT const &rhs);
00058     friend bool operator>_TEMP_(HandleT const &lhs, index_type rhs);
00059     friend bool operator>_TEMP_(index_type lhs, HandleT const &rhs);
00060     friend bool operator>=_TEMP_(HandleT const &lhs, index_type rhs);
00061     friend bool operator>=_TEMP_(index_type lhs, HandleT const &rhs);
00062 public:
00063     HandleT(index_type idx = INVALID_INDEX) : _index(idx) {}
00064     ~HandleT() {}
00065 
00066     HandleT(HandleT const &h) { _index = h._index; }
00067     HandleT& operator=(HandleT const &rhs) { _index = rhs._index; return *this; }
00068     HandleT& operator=(index_type rhs) { _index = rhs; return *this; }
00069 
00070     bool operator==(HandleT const &rhs) const { return (_index==rhs._index); }
00071     bool operator!=(HandleT const &rhs) const { return (_index!=rhs._index); }
00072     bool operator<(HandleT const &rhs) const { return (_index<rhs._index); }
00073     bool operator<=(HandleT const &rhs) const { return (_index<=rhs._index); }
00074     bool operator>(HandleT const &rhs) const { return (_index>rhs._index); }
00075     bool operator>=(HandleT const &rhs) const { return (_index>=rhs._index); }
00076     
00077 
00078     index_type Idx() { return _index; }
00079     bool IsValid() const { return (_index!=INVALID_INDEX); }
00080 
00081     operator index_type() { return _index; }
00082     operator bool() { return (_index!=INVALID_INDEX); }
00083 
00084 private:
00085     typedef T PrivateType;
00086     index_type _index;
00087 };
00088 
00089 
00090 
00091 typedef HandleT<HEVertex> HEVertexHandle;
00092 typedef HandleT<HEHalfEdge> HEHalfEdgeHandle;
00093 typedef HandleT<HEFace> HEFaceHandle;
00094 typedef HandleT<HEEdge> HEEdgeHandle;
00095 
00096 struct _flag_base
00097 {
00098 public:
00099     enum FLAGS
00100     {
00101         flag0=1, flag1,  flag2,  flag3,  flag4,  flag5,  flag6,  flag7,
00102         flag8,   flag9,  flag10, flag11, flag12, flag13, flag14, flag15,
00103         flag16,  flag17, flag18, flag19, flag20, flag21, flag22, flag23,
00104         flag24,  flag25, flag26, flag27, flag28, flag29, flag30
00105     };
00106 
00107     friend class mitkHEMesh;
00108 
00109     _flag_base() : _flags(0) {}
00110     bool IsDeleted() const { return (_flags & MITK_FLAG_DELETED) != 0; }
00111     void SetFlag(FLAGS const f, bool const flag) { if (flag) _flags |= (1<<f); else _flags &= ~(1<<f); }
00112     void SetFlag(FLAGS const f) { _flags |= (1<<f); }
00113     void UnSetFlag(FLAGS const f) { _flags &= ~(1<<f); }
00114     bool GetFlag(FLAGS const f) const { return (_flags & (1<<f)) != 0; }
00115     void SetFlags(unsigned int const fs) { _flags = (_flags & MITK_FLAG_DELETED) | (fs & (~MITK_FLAG_DELETED)); }
00116     void ClearFlags() { _flags &= MITK_FLAG_DELETED; }  
00117 
00118 private:
00119     void SetDeleted(bool del=true) { if (del) _flags |= MITK_FLAG_DELETED; else _flags &= (~MITK_FLAG_DELETED); }
00120     unsigned int _flags;
00121 };
00122 
00123 struct _vertex : public _flag_base
00124 {
00125     union
00126     {
00127         Vertex3f vert;
00128         struct 
00129         {
00130             Point3f point;
00131             Point3f normal;
00132         };
00133     };
00134     HEHalfEdgeHandle outHalfEdge;   
00135 };
00136 
00137 struct _half_edge
00138 {
00139     HEVertexHandle endVertex;
00140     HEHalfEdgeHandle pairHalfEdge;
00141     HEHalfEdgeHandle nextHalfEdge;
00142     HEHalfEdgeHandle prevHalfEdge;
00143     HEFaceHandle face;
00144 };
00145 
00146 struct _edge : public _flag_base
00147 {
00148     HEHalfEdge halfEdge[2];
00149 };
00150 
00151 struct _face : public _flag_base
00152 {
00153     HEHalfEdgeHandle oneHalfEdge;
00154 };
00155 
00156 
00157 #endif
00158 

Generated on Tue Feb 25 15:00:37 2014 for MITK (Medical Imaging ToolKit) by  doxygen 1.4.3