00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __mitkHEMesh_h
00012 #define __mitkHEMesh_h
00013
00014 #include "mitkMesh.h"
00015 #include "mitkHalfEdgeStructures.h"
00016
00096 class MITK_COMMON_API mitkHEMesh : public mitkMesh
00097 {
00098 public:
00099 typedef HEVertex Vertex;
00100 typedef HEHalfEdge HalfEdge;
00101 typedef HEEdge Edge;
00102 typedef HEFace Face;
00103
00104 typedef HEVertexPtr VertexPtr;
00105 typedef HEHalfEdgePtr HalfEdgePtr;
00106 typedef HEEdgePtr EdgePtr;
00107 typedef HEFacePtr FacePtr;
00108
00109 typedef HEVertexHandle VertexHandle;
00110 typedef HEHalfEdgeHandle HalfEdgeHandle;
00111 typedef HEEdgeHandle EdgeHandle;
00112 typedef HEFaceHandle FaceHandle;
00113
00114 MITK_TYPE(mitkHEMesh, mitkMesh)
00115
00116 virtual void PrintSelf(ostream &os);
00117
00121 mitkHEMesh();
00122
00127 virtual int GetDataObjectType() const { return MITK_HE_MESH; }
00128
00132 virtual void Initialize();
00133
00138
00139
00144 virtual void ShallowCopy(mitkDataObject *src);
00145
00150 virtual void DeepCopy(mitkDataObject *src);
00151
00158
00159
00164 virtual size_type GetVertexNumber() const { return m_VertNum; }
00165
00172
00173
00178 virtual size_type GetFaceNumber() const { return m_FaceNum; }
00179
00183 size_type GetEdgeNumber() const { return m_EdgeNum; }
00184
00189 void ClearGarbage();
00190
00196 VertexHandle AddVertex(Vertex const &vert)
00197 {
00198 return _addNewVertex(vert.point.x, vert.point.y, vert.point.z,
00199 vert.normal.x, vert.normal.y, vert.normal.z,
00200 vert.outHalfEdge);
00201 }
00202
00209 VertexHandle AddVertex(Point3f const &point, Point3f const &normal)
00210 {
00211 return _addNewVertex(point.x, point.y, point.z, normal.x, normal.y, normal.z);
00212 }
00213
00224 VertexHandle AddVertex(float x, float y, float z,
00225 float nx = 0.0f, float ny = 0.0f, float nz = 0.0f)
00226 {
00227 return _addNewVertex(x, y, z, nx, ny, nz);
00228 }
00229
00240 VertexHandle AddVertex(float v[6])
00241 {
00242 return _addNewVertex(v[0], v[1], v[2], v[3], v[4], v[5]);
00243 }
00244
00253 FaceHandle AddFace(unsigned int n, VertexHandle *vertices);
00254
00259 void DeleteVertex(VertexHandle vert);
00260
00267 void DeleteEdge(EdgeHandle edge, bool deleteIsolatedVertices);
00268
00275 void DeleteFace(FaceHandle face, bool deleteIsolatedVertices);
00276
00285 HalfEdgeHandle FindHalfEdge(VertexHandle vert0, VertexHandle vert1);
00286
00293 bool IsBoundary(HalfEdgeHandle halfedge) const { return !(this->IsValid(this->AdjFace(halfedge))); }
00294
00301 bool IsBoundary(VertexHandle vert) const
00302 {
00303 HalfEdgeHandle edge = this->OutHalfEdge(vert);
00304 return ( ! (this->IsValid(edge) && this->IsValid(this->AdjFace(edge))) );
00305 }
00306
00313 bool IsBoundary(EdgeHandle edge) const
00314 {
00315 assert(this->IsValid(edge));
00316 return ( this->IsBoundary(this->GetHandle(this->GetEdge(edge).halfEdge[0])) ||
00317 this->IsBoundary(this->GetHandle(this->GetEdge(edge).halfEdge[1])) );
00318 }
00319
00329 bool IsManifold(VertexHandle vert)
00330 {
00331 VertexOHalfedgeIterator ei(this, vert);
00332 ++ei;
00333 for ( ; ei; ++ei) if (this->IsBoundary(ei)) return false;
00334 return true;
00335 }
00336
00342 virtual Vertex& GetVertex(VertexHandle v) const = 0;
00343
00344
00350 virtual Edge& GetEdge(EdgeHandle e) const = 0;
00351
00352
00359 virtual Edge& GetEdge(HalfEdgeHandle he) const = 0;
00360
00361
00367 virtual HalfEdge& GetHalfEdge(HalfEdgeHandle he) const = 0;
00368
00369
00375 virtual Face& GetFace(FaceHandle f) const = 0;
00376
00377
00383 virtual VertexHandle GetHandle(Vertex const &vert) const = 0;
00384
00385
00391 virtual EdgeHandle GetHandle(Edge const &edge) const = 0;
00392
00393
00399 virtual HalfEdgeHandle GetHandle(HalfEdge const &he) const = 0;
00400
00401
00407 virtual FaceHandle GetHandle(Face const &face) const = 0;
00408
00409
00416 EdgeHandle GetEdgeHandle(HalfEdgeHandle he) const
00417 { return EdgeHandle(he.Idx() >> 1); }
00418
00424 HalfEdgeHandle PairHalfEdge(HalfEdgeHandle he) const
00425 { return this->GetHalfEdge(he).pairHalfEdge; }
00426
00432 HalfEdgeHandle NextHalfEdge(HalfEdgeHandle he) const
00433 { return this->GetHalfEdge(he).nextHalfEdge; }
00434
00440 HalfEdgeHandle PrevHalfEdge(HalfEdgeHandle he) const
00441 { return this->GetHalfEdge(he).prevHalfEdge; }
00442
00448 VertexHandle EndVertex(HalfEdgeHandle he) const
00449 { return this->GetHalfEdge(he).endVertex; }
00450
00457 FaceHandle AdjFace(HalfEdgeHandle he) const
00458 { return this->GetHalfEdge(he).face; }
00459
00465 HalfEdgeHandle OutHalfEdge(VertexHandle v) const
00466 { return this->GetVertex(v).outHalfEdge; }
00467
00474 HalfEdgeHandle OneHalfEdge(FaceHandle f) const
00475 { return this->GetFace(f).oneHalfEdge; }
00476
00482 bool IsValid(VertexHandle v) const { return (v.Idx()<m_VertNum && v.Idx()>=0); }
00483
00489 bool IsValid(EdgeHandle e) const { return (e.Idx()<m_EdgeNum && e.Idx()>=0); }
00490
00496 bool IsValid(HalfEdgeHandle he) const { return (he.Idx()<(m_EdgeNum<<1) && he.Idx()>=0); }
00497
00503 bool IsValid(FaceHandle f) const { return (f.Idx()<m_FaceNum && f.Idx()>=0); }
00504
00516 size_type GetValidVertexNumber() const { return m_ValidVertNum; }
00517
00529 size_type GetValidEdgeNumber() const { return m_ValidEdgeNum; }
00530
00542 size_type GetValidFaceNumber() const { return m_ValidFaceNum; }
00543
00549 virtual bool TestClockwise();
00550
00554 void ClearFlags();
00555
00556 protected:
00557 virtual ~mitkHEMesh();
00558
00559 void _init();
00560
00561 virtual index_type _addVertex(Vertex3f &vert);
00562 virtual index_type _addFace(unsigned int num, index_type *verts);
00563 virtual Vertex3f const* _getVertex(index_type vertIdx);
00564 virtual index_type const* _getFace(index_type faceIdx);
00565 virtual Vertex3f* _getVertexForWrite(index_type vertIdx);
00566 virtual index_type* _getFaceForWrite(index_type faceIdx);
00567 virtual bool _setFace(index_type faceIdx, unsigned int num, index_type *verts);
00568
00569
00570
00571 virtual VertexHandle _addNewVertex(float x, float y, float z,
00572 float nx = 0.0f, float ny = 0.0f, float nz = 0.0f,
00573 HalfEdgeHandle edge = HalfEdgeHandle()) = 0;
00574 virtual HalfEdgeHandle _addNewEdge(VertexHandle start, VertexHandle end) = 0;
00575 virtual FaceHandle _addNewFace(HalfEdgeHandle halfedge = HalfEdgeHandle()) = 0;
00576
00577
00578
00579
00580 void _adjustOutHalfEdge(VertexHandle vert);
00581
00582 void _deleteVert(VertexHandle v) { this->GetVertex(v).SetDeleted(true); m_ValidVertNum--; m_NeedClearVert=true; }
00583 void _deleteEdge(EdgeHandle e) { this->GetEdge(e).SetDeleted(true); m_ValidEdgeNum--; m_NeedClearEdge=true; }
00584 void _deleteFace(FaceHandle f) { this->GetFace(f).SetDeleted(true); m_ValidFaceNum--; m_NeedClearFace=true; }
00585
00586
00587 virtual void _clearDeletedVertices() = 0;
00588 virtual void _clearDeletedEdges() = 0;
00589 virtual void _clearDeletedFaces() = 0;
00590
00591 VertexPtr _getVertexPtr(index_type idx) const { return &(this->GetVertex(VertexHandle(idx))); }
00592 EdgePtr _getEdgePtr(index_type idx) const { return &(this->GetEdge(EdgeHandle(idx))); }
00593 HalfEdgePtr _getHalfEdgePtr(index_type idx) const { return &(this->GetEdge(EdgeHandle(idx>>1)).halfEdge[idx%2]); }
00594 FacePtr _getFacePtr(index_type idx) const { return &(this->GetFace(FaceHandle(idx))); }
00595
00596
00597 Orientation _testOrientation(FaceHandle fh);
00598
00599 void _clearEdgeFlags();
00600 void _clearVertFlags();
00601 void _clearFaceFlags();
00602
00603
00604 size_type m_VertNum;
00605 size_type m_EdgeNum;
00606 size_type m_FaceNum;
00607 size_type m_ValidVertNum;
00608 size_type m_ValidEdgeNum;
00609 size_type m_ValidFaceNum;
00610 size_type m_MaxVertNum;
00611 size_type m_MaxEdgeNum;
00612 size_type m_MaxFaceNum;
00613
00614
00615
00616
00617
00618
00619 index_type *m_TempFace;
00620
00621 bool m_NeedClearVert;
00622 bool m_NeedClearEdge;
00623 bool m_NeedClearFace;
00624
00625 private:
00626 mitkHEMesh(const mitkHEMesh&);
00627 void operator = (const mitkHEMesh&);
00628
00629 public:
00630
00631 #define CirculatorT VertexVertexIterT
00632 #define SourceHandle VertexHandle
00633 #define TargetHandle VertexHandle
00634 #define TargetType Vertex
00635 #define HANDLE (_mesh->EndVertex(_current))
00636 #define TARGET (_mesh->GetVertex(HANDLE))
00637 #define START (_mesh->OutHalfEdge(roundCenter))
00638 #define NEXT _current = _mesh->NextHalfEdge(_mesh->PairHalfEdge(_current));
00639 #define PREV _current = _mesh->PairHalfEdge(_mesh->PrevHalfEdge(_current));
00640 #define POSTINIT
00641 #include "mitkHEMeshCirculatorTemplate.t"
00642 #undef CirculatorT
00643 #undef SourceHandle
00644 #undef TargetHandle
00645 #undef TargetType
00646 #undef HANDLE
00647 #undef TARGET
00648 #undef START
00649 #undef NEXT
00650 #undef PREV
00651 #undef POSTINIT
00652
00653 #define CirculatorT VertexOHalfedgeIterT
00654 #define SourceHandle VertexHandle
00655 #define TargetHandle HalfEdgeHandle
00656 #define TargetType HalfEdge
00657 #define HANDLE (_current)
00658 #define TARGET (_mesh->GetHalfEdge(HANDLE))
00659 #define START (_mesh->OutHalfEdge(roundCenter))
00660 #define NEXT _current = _mesh->NextHalfEdge(_mesh->PairHalfEdge(_current));
00661 #define PREV _current = _mesh->PairHalfEdge(_mesh->PrevHalfEdge(_current));
00662 #define POSTINIT
00663 #include "mitkHEMeshCirculatorTemplate.t"
00664 #undef CirculatorT
00665 #undef SourceHandle
00666 #undef TargetHandle
00667 #undef TargetType
00668 #undef HANDLE
00669 #undef TARGET
00670 #undef START
00671 #undef NEXT
00672 #undef PREV
00673 #undef POSTINIT
00674
00675 #define CirculatorT VertexIHalfedgeIterT
00676 #define SourceHandle VertexHandle
00677 #define TargetHandle HalfEdgeHandle
00678 #define TargetType HalfEdge
00679 #define HANDLE (_current)
00680 #define TARGET (_mesh->GetHalfEdge(HANDLE))
00681 #define START (_mesh->PairHalfEdge(_mesh->OutHalfEdge(roundCenter)))
00682 #define NEXT _current = _mesh->pairHalfEdge(_mesh->nextHalfEdge(_current));
00683 #define PREV _current = _mesh->PrevHalfEdge(_mesh->PairHalfEdge(_current));
00684 #define POSTINIT
00685 #include "mitkHEMeshCirculatorTemplate.t"
00686 #undef CirculatorT
00687 #undef SourceHandle
00688 #undef TargetHandle
00689 #undef TargetType
00690 #undef HANDLE
00691 #undef TARGET
00692 #undef START
00693 #undef NEXT
00694 #undef PREV
00695 #undef POSTINIT
00696
00697 #define CirculatorT VertexEdgeIterT
00698 #define SourceHandle VertexHandle
00699 #define TargetHandle EdgeHandle
00700 #define TargetType Edge
00701 #define HANDLE (_mesh->GetEdgeHandle(_current))
00702 #define TARGET (_mesh->GetEdge(HANDLE))
00703 #define START (_mesh->OutHalfEdge(roundCenter))
00704 #define NEXT _current = _mesh->NextHalfEdge(_mesh->PairHalfEdge(_current));
00705 #define PREV _current = _mesh->PairHalfEdge(_mesh->PrevHalfEdge(_current));
00706 #define POSTINIT
00707 #include "mitkHEMeshCirculatorTemplate.t"
00708 #undef CirculatorT
00709 #undef SourceHandle
00710 #undef TargetHandle
00711 #undef TargetType
00712 #undef HANDLE
00713 #undef TARGET
00714 #undef START
00715 #undef NEXT
00716 #undef PREV
00717 #undef POSTINIT
00718
00719 #define CirculatorT VertexFaceIterT
00720 #define SourceHandle VertexHandle
00721 #define TargetHandle FaceHandle
00722 #define TargetType Face
00723 #define HANDLE (_mesh->AdjFace(_current))
00724 #define TARGET (_mesh->GetFace(HANDLE))
00725 #define START (_mesh->OutHalfEdge(roundCenter))
00726 #define NEXT do _current = _mesh->NextHalfEdge(_mesh->PairHalfEdge(_current)); while ((this->NotEnd()) && !(HANDLE.IsValid()));
00727 #define PREV do _current = _mesh->PairHalfEdge(_mesh->PrevHalfEdge(_current)); while ((this->NotEnd()) && !(HANDLE.IsValid()));
00728 #define POSTINIT if (_current.IsValid() && !(HANDLE.IsValid())) this->operator++();
00729 #include "mitkHEMeshCirculatorTemplate.t"
00730 #undef CirculatorT
00731 #undef SourceHandle
00732 #undef TargetHandle
00733 #undef TargetType
00734 #undef HANDLE
00735 #undef TARGET
00736 #undef START
00737 #undef NEXT
00738 #undef PREV
00739 #undef POSTINIT
00740
00741 #define CirculatorT FaceVertexIterT
00742 #define SourceHandle FaceHandle
00743 #define TargetHandle VertexHandle
00744 #define TargetType Vertex
00745 #define HANDLE (_mesh->EndVertex(_current))
00746 #define TARGET (_mesh->GetVertex(HANDLE))
00747 #define START (_mesh->OneHalfEdge(roundCenter))
00748 #define NEXT _current = _mesh->NextHalfEdge(_current);
00749 #define PREV _current = _mesh->PrevHalfEdge(_current);
00750 #define POSTINIT
00751 #include "mitkHEMeshCirculatorTemplate.t"
00752 #undef CirculatorT
00753 #undef SourceHandle
00754 #undef TargetHandle
00755 #undef TargetType
00756 #undef HANDLE
00757 #undef TARGET
00758 #undef START
00759 #undef NEXT
00760 #undef PREV
00761 #undef POSTINIT
00762
00763 #define CirculatorT FaceHalfedgeIterT
00764 #define SourceHandle FaceHandle
00765 #define TargetHandle HalfEdgeHandle
00766 #define TargetType HalfEdge
00767 #define HANDLE (_current)
00768 #define TARGET (_mesh->GetHalfEdge(HANDLE))
00769 #define START (_mesh->OneHalfEdge(roundCenter))
00770 #define NEXT _current = _mesh->NextHalfEdge(_current);
00771 #define PREV _current = _mesh->PrevHalfEdge(_current);
00772 #define POSTINIT
00773 #include "mitkHEMeshCirculatorTemplate.t"
00774 #undef CirculatorT
00775 #undef SourceHandle
00776 #undef TargetHandle
00777 #undef TargetType
00778 #undef HANDLE
00779 #undef TARGET
00780 #undef START
00781 #undef NEXT
00782 #undef PREV
00783 #undef POSTINIT
00784
00785 #define CirculatorT FaceEdgeIterT
00786 #define SourceHandle FaceHandle
00787 #define TargetHandle EdgeHandle
00788 #define TargetType Edge
00789 #define HANDLE (_mesh->GetEdgeHandle(_current))
00790 #define TARGET (_mesh->GetEdge(HANDLE))
00791 #define START (_mesh->OneHalfEdge(roundCenter))
00792 #define NEXT _current = _mesh->NextHalfEdge(_current);
00793 #define PREV _current = _mesh->PrevHalfEdge(_current);
00794 #define POSTINIT
00795 #include "mitkHEMeshCirculatorTemplate.t"
00796 #undef CirculatorT
00797 #undef SourceHandle
00798 #undef TargetHandle
00799 #undef TargetType
00800 #undef HANDLE
00801 #undef TARGET
00802 #undef START
00803 #undef NEXT
00804 #undef PREV
00805 #undef POSTINIT
00806
00807 #define CirculatorT FaceFaceIterT
00808 #define SourceHandle FaceHandle
00809 #define TargetHandle FaceHandle
00810 #define TargetType Face
00811 #define HANDLE (_mesh->AdjFace(_mesh->PairHalfEdge(_current)))
00812 #define TARGET (_mesh->GetFace(HANDLE))
00813 #define START (_mesh->OneHalfEdge(roundCenter))
00814 #define NEXT do _current = _mesh->NextHalfEdge(_current); while ((this->NotEnd()) && !(HANDLE.IsValid()));
00815 #define PREV do _current = _mesh->PrevHalfEdge(_current); while ((this->NotEnd()) && !(HANDLE.IsValid()));
00816 #define POSTINIT if (_current.IsValid() && !(HANDLE.IsValid())) this->operator++();
00817 #include "mitkHEMeshCirculatorTemplate.t"
00818 #undef CirculatorT
00819 #undef SourceHandle
00820 #undef TargetHandle
00821 #undef TargetType
00822 #undef HANDLE
00823 #undef TARGET
00824 #undef START
00825 #undef NEXT
00826 #undef PREV
00827 #undef POSTINIT
00828
00829
00830 #define IteratorT VertexIterT
00831 #define TargetType Vertex
00832 #define TargetHandle VertexHandle
00833 #define HANDLE (VertexHandle(_current))
00834 #define TARGETPTR (_mesh->_getVertexPtr(_current))
00835 #define TOTAL (_mesh->GetVertexNumber())
00836 #include "mitkHEMeshIteratorTemplate.t"
00837 #undef IteratorT
00838 #undef TargetType
00839 #undef TargetHandle
00840 #undef HANDLE
00841 #undef TARGETPTR
00842 #undef TOTAL
00843
00844 #define IteratorT EdgeIterT
00845 #define TargetType Edge
00846 #define TargetHandle EdgeHandle
00847 #define HANDLE (EdgeHandle(_current))
00848 #define TARGETPTR (_mesh->_getEdgePtr(_current))
00849 #define TOTAL (_mesh->GetEdgeNumber())
00850 #include "mitkHEMeshIteratorTemplate.t"
00851 #undef IteratorT
00852 #undef TargetType
00853 #undef TargetHandle
00854 #undef HANDLE
00855 #undef TARGETPTR
00856 #undef TOTAL
00857
00858 #define IteratorT FaceIterT
00859 #define TargetType Face
00860 #define TargetHandle FaceHandle
00861 #define HANDLE (FaceHandle(_current))
00862 #define TARGETPTR (_mesh->_getFacePtr(_current))
00863 #define TOTAL (_mesh->GetFaceNumber())
00864 #include "mitkHEMeshIteratorTemplate.t"
00865 #undef IteratorT
00866 #undef TargetType
00867 #undef TargetHandle
00868 #undef HANDLE
00869 #undef TARGETPTR
00870 #undef TOTAL
00871
00872 friend class VertexVertexIterT<mitkHEMesh>;
00873 friend class VertexOHalfedgeIterT<mitkHEMesh>;
00874 friend class VertexIHalfedgeIterT<mitkHEMesh>;
00875 friend class VertexEdgeIterT<mitkHEMesh>;
00876 friend class FaceVertexIterT<mitkHEMesh>;
00877 friend class FaceHalfedgeIterT<mitkHEMesh>;
00878 friend class FaceEdgeIterT<mitkHEMesh>;
00879 friend class FaceFaceIterT<mitkHEMesh>;
00880
00881 friend class VertexIterT<mitkHEMesh>;
00882 friend class EdgeIterT<mitkHEMesh>;
00883 friend class FaceIterT<mitkHEMesh>;
00884
00903 typedef VertexVertexIterT<mitkHEMesh> VertexVertexIterator;
00904
00923 typedef VertexOHalfedgeIterT<mitkHEMesh> VertexOHalfedgeIterator;
00924
00943 typedef VertexIHalfedgeIterT<mitkHEMesh> VertexIHalfedgeIterator;
00944
00963 typedef VertexEdgeIterT<mitkHEMesh> VertexEdgeIterator;
00964
00983 typedef VertexFaceIterT<mitkHEMesh> VertexFaceIterator;
00984
01003 typedef FaceVertexIterT<mitkHEMesh> FaceVertexIterator;
01004
01023 typedef FaceHalfedgeIterT<mitkHEMesh> FaceHalfedgeIterator;
01024
01043 typedef FaceEdgeIterT<mitkHEMesh> FaceEdgeIterator;
01044
01063 typedef FaceFaceIterT<mitkHEMesh> FaceFaceIterator;
01064
01082 typedef VertexIterT<mitkHEMesh> VertexIterator;
01083
01101 typedef EdgeIterT<mitkHEMesh> EdgeIterator;
01102
01120 typedef FaceIterT<mitkHEMesh> FaceIterator;
01121
01122 };
01123
01124
01125 #endif
01126