00001 //============================================================================== 00015 #ifndef MDS_TETRACONTAINER_H 00016 #define MDS_TETRACONTAINER_H 00017 00018 #include "mdsTetraFeatures.h" 00019 00020 // MDSTk 00021 #include <MDSTk/Base/mdsIterator.h> 00022 00023 // VCTL 00024 #include <VectorEntity/mcentity.h> 00025 00026 00027 namespace mds 00028 { 00029 00030 // Declare iterator traits first... 00031 MDS_ITERATOR_TRAITS(seg, CTetraContainerIterator, seg::CTetraFeatures); 00032 00033 namespace seg 00034 { 00035 00036 //============================================================================== 00040 class CTetraContainerIterator 00041 : public mds::base::CIteratorBase<CTetraContainerIterator> 00042 , public mds::base::CPtrHolder<CTetraFeatures> 00043 { 00044 public: 00046 typedef mds::base::CPtrHolder<CTetraFeatures> base; 00047 00048 public: 00050 CTetraContainerIterator(vctl::MCTetra *pFirstTetrahedron) 00051 { 00052 init(pFirstTetrahedron); 00053 } 00054 00056 CTetraContainerIterator(const CTetraContainerIterator& It) 00057 { 00058 base::m_pItem = It.m_pItem; 00059 m_pTetrahedron = It.m_pTetrahedron; 00060 } 00061 00063 ~CTetraContainerIterator() {} 00064 00066 CTetraContainerIterator& operator=(const CTetraContainerIterator& It) 00067 { 00068 base::m_pItem = It.m_pItem; 00069 m_pTetrahedron = It.m_pTetrahedron; 00070 return *this; 00071 } 00072 00073 00075 vctl::MCTetra *getTetrahedron() { return m_pTetrahedron; } 00076 00079 tSize getDistance(const CTetraContainerIterator& End) const 00080 { 00081 if( !m_pTetrahedron ) 00082 { 00083 return 0; 00084 } 00085 00086 // Count the distance 00087 tSize Count = 0; 00088 for( CTetraContainerIterator it = *this; it != End; ++it ) 00089 { 00090 ++Count; 00091 } 00092 return Count; 00093 } 00094 00096 void advance() 00097 { 00098 do { 00099 if( !base::m_pItem ) 00100 { 00101 break; 00102 } 00103 else 00104 { 00105 next(); 00106 } 00107 } while( base::m_pItem && base::m_pItem->isError() ); 00108 } 00109 00110 protected: 00112 vctl::MCTetra *m_pTetrahedron; 00113 00114 protected: 00116 void init(vctl::MCTetra *pTetrahedron) 00117 { 00118 m_pTetrahedron = pTetrahedron; 00119 if( !m_pTetrahedron ) 00120 { 00121 m_pItem = NULL; 00122 return; 00123 } 00124 00125 m_pItem = getTetrahedronFeatures(pTetrahedron); 00126 00127 // Find the first evaluated tetrahedron. 00128 if( m_pItem->isError() ) 00129 { 00130 advance(); 00131 } 00132 } 00133 00135 void next() 00136 { 00137 m_pTetrahedron = m_pTetrahedron->GetNext(); 00138 m_pItem = (m_pTetrahedron) ? getTetrahedronFeatures(m_pTetrahedron) : NULL; 00139 } 00140 }; 00141 00142 00143 //============================================================================== 00147 class CTetraContainer 00148 { 00149 public: 00151 enum { ITERATOR_DECLARED }; 00152 00154 typedef CTetraContainerIterator tIterator; 00155 00157 typedef CTetraContainerIterator tConstIterator; 00158 00159 public: 00161 CTetraContainer(vctl::MCTetra *pFirstTetrahedron) : m_pTetrahedron(pFirstTetrahedron) 00162 { 00163 MDS_ASSERT(m_pTetrahedron); 00164 } 00165 00167 ~CTetraContainer() {} 00168 00169 00171 tIterator getBegin() 00172 { 00173 return tIterator(m_pTetrahedron); 00174 } 00175 tConstIterator getBegin() const 00176 { 00177 return tConstIterator(m_pTetrahedron); 00178 } 00179 00181 tIterator getEnd() 00182 { 00183 return tIterator(NULL); 00184 } 00185 tConstIterator getEnd() const 00186 { 00187 return tConstIterator(NULL); 00188 } 00189 00190 protected: 00192 vctl::MCTetra *m_pTetrahedron; 00193 }; 00194 00195 00196 } // namespace seg 00197 } // namespace mds 00198 00199 #endif // MDS_TETRACONTAINER_H 00200