Iterator.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef MESH_ITERATOR_H
00025 #define MESH_ITERATOR_H
00026
00027 #include "MeshKernel.h"
00028 #include "Elements.h"
00029 #include <Base/Matrix.h>
00030 #include <Base/Vector3D.h>
00031 #include <climits>
00032
00033 namespace MeshCore {
00034
00035 class MeshKernel;
00036 class MeshGeomFacet;
00037 class MeshPoint;
00038 class MeshGeomEdge;
00039 class MeshIndexEdge;
00040 class MeshHelpEdge;
00041
00047 class MeshFacetIterator
00048 {
00049 public:
00052
00053 inline MeshFacetIterator (const MeshKernel &rclM);
00055 inline MeshFacetIterator (const MeshKernel &rclM, unsigned long ulPos);
00057 inline MeshFacetIterator (const MeshFacetIterator &rclI);
00059
00062
00063 inline void Transform( const Base::Matrix4D& rclTrf );
00065
00068
00069 const MeshGeomFacet& operator*(void)
00070 { return Dereference(); }
00072 const MeshGeomFacet* operator->(void)
00073 { return &Dereference(); }
00076 const MeshFacetIterator& operator ++ (void)
00077 { _clIter++; return *this; }
00080 const MeshFacetIterator& operator -- (void)
00081 { _clIter--; return *this; }
00083 const MeshFacetIterator& operator += (int k)
00084 { _clIter += k; return *this; }
00086 const MeshFacetIterator& operator -= (int k)
00087 { _clIter -= k; return *this; }
00089 inline MeshFacetIterator& operator = (const MeshFacetIterator &rpI);
00091 bool operator < (const MeshFacetIterator &rclI) const
00092 { return _clIter < rclI._clIter; }
00094 bool operator > (const MeshFacetIterator &rclI) const
00095 { return _clIter > rclI._clIter; }
00097 bool operator == (const MeshFacetIterator &rclI) const
00098 { return _clIter == rclI._clIter; }
00100 void Begin (void)
00101 { _clIter = _rclFAry.begin(); }
00103 void End (void)
00104 { _clIter = _rclFAry.end(); }
00106 unsigned long Position (void) const
00107 { return _clIter - _rclFAry.begin(); }
00109 bool EndReached (void) const
00110 { return !(_clIter < _rclFAry.end()); }
00112 void Init (void)
00113 { Begin(); }
00115 bool More (void) const
00116 { return !EndReached(); }
00118 void Next (void)
00119 { operator++(); }
00121 inline bool Set (unsigned long ulIndex);
00123 inline MeshFacet GetIndices (void) const
00124 { return *_clIter; }
00126 inline const MeshFacet& GetReference (void) const
00127 { return *_clIter; }
00129 inline void GetNeighbours (MeshFacetIterator &rclN0, MeshFacetIterator &rclN1, MeshFacetIterator &rclN2) const;
00131 inline void SetToNeighbour (unsigned short usN);
00133 inline unsigned long GetProperty (void) const;
00135 inline bool IsValid (void) const
00136 { return (_clIter >= _rclFAry.begin()) && (_clIter < _rclFAry.end()); }
00138
00141 void SetFlag (MeshFacet::TFlagType tF) const
00142 { this->_clIter->SetFlag(tF); }
00143 void ResetFlag (MeshFacet::TFlagType tF) const
00144 { this->_clIter->ResetFlag(tF); }
00145 bool IsFlag (MeshFacet::TFlagType tF) const
00146 { return this->_clIter->IsFlag(tF); }
00147 void SetProperty(unsigned long uP) const
00148 { this->_clIter->SetProperty(uP); }
00150
00151 protected:
00152 inline const MeshGeomFacet& Dereference (void);
00153
00154 protected:
00155 const MeshKernel& _rclMesh;
00156 const MeshFacetArray& _rclFAry;
00157 const MeshPointArray& _rclPAry;
00158 MeshFacetArray::_TConstIterator _clIter;
00159 MeshGeomFacet _clFacet;
00160 bool _bApply;
00161 Base::Matrix4D _clTrf;
00162
00163
00164 friend class MeshKernel;
00165 };
00166
00171 class MeshExport MeshPointIterator
00172 {
00173 public:
00176 inline MeshPointIterator (const MeshKernel &rclM);
00177 inline MeshPointIterator (const MeshKernel &rclM, unsigned long ulPos);
00178 inline MeshPointIterator (const MeshPointIterator &rclI);
00180
00183
00184 inline void Transform( const Base::Matrix4D& rclTrf );
00186
00189
00190 const MeshPoint& operator*(void) const
00191 { return Dereference(); }
00193 const MeshPoint* operator->(void) const
00194 { return &Dereference(); }
00197 const MeshPointIterator& operator ++ (void)
00198 { _clIter++; return *this; }
00201 const MeshPointIterator& operator -- (void)
00202 { _clIter--; return *this; }
00204 inline MeshPointIterator& operator = (const MeshPointIterator &rpI);
00206 bool operator < (const MeshPointIterator &rclI) const
00207 { return _clIter < rclI._clIter; }
00209 bool operator > (const MeshPointIterator &rclI) const
00210 { return _clIter > rclI._clIter; }
00212 bool operator == (const MeshPointIterator &rclI) const
00213 { return _clIter == rclI._clIter; }
00215 void Begin (void)
00216 { _clIter = _rclPAry.begin(); }
00218 void End (void)
00219 { _clIter = _rclPAry.end(); }
00221 unsigned long Position (void) const
00222 { return _clIter - _rclPAry.begin(); }
00224 bool EndReached (void) const
00225 { return !(_clIter < _rclPAry.end()); }
00227 void Init (void)
00228 { Begin(); }
00230 bool More (void) const
00231 { return !EndReached(); }
00233 void Next (void)
00234 { operator++(); }
00236 inline bool Set (unsigned long ulIndex);
00238 inline bool IsValid (void) const
00239 { return (_clIter >= _rclPAry.begin()) && (_clIter < _rclPAry.end()); }
00241
00244 void SetFlag (MeshPoint::TFlagType tF) const
00245 { this->_clIter->SetFlag(tF); }
00246 void ResetFlag (MeshPoint::TFlagType tF) const
00247 { this->_clIter->ResetFlag(tF); }
00248 bool IsFlag (MeshPoint::TFlagType tF) const
00249 { return this->_clIter->IsFlag(tF); }
00250 void SetProperty(unsigned long uP) const
00251 { this->_clIter->SetProperty(uP); }
00253
00254 protected:
00255 inline const MeshPoint& Dereference (void) const;
00256
00257 protected:
00258 const MeshKernel& _rclMesh;
00259 const MeshPointArray& _rclPAry;
00260 MeshPoint _clPoint;
00261 MeshPointArray::_TConstIterator _clIter;
00262 bool _bApply;
00263 Base::Matrix4D _clTrf;
00264
00265
00266 friend class MeshKernel;
00267 };
00268
00269 class MeshFastFacetIterator
00270 {
00271 public:
00272 inline MeshFastFacetIterator (const MeshKernel &rclM);
00273 virtual ~MeshFastFacetIterator () {}
00274
00275 void Init (void) { _clIter = _rclFAry.begin(); }
00276 inline void Next (void);
00277 bool More (void) { return _clIter != _rclFAry.end(); }
00278
00279 Base::Vector3f _afPoints[3];
00280
00281 protected:
00282 const MeshKernel& _rclMesh;
00283 const MeshFacetArray& _rclFAry;
00284 const MeshPointArray& _rclPAry;
00285 MeshFacetArray::_TConstIterator _clIter;
00286
00287 private:
00288 MeshFastFacetIterator (const MeshFastFacetIterator&);
00289 void operator = (const MeshFastFacetIterator&);
00290 };
00291
00292 inline MeshFastFacetIterator::MeshFastFacetIterator (const MeshKernel &rclM)
00293 : _rclMesh(rclM),
00294 _rclFAry(rclM._aclFacetArray),
00295 _rclPAry(rclM._aclPointArray),
00296 _clIter(_rclFAry.begin())
00297 {
00298 }
00299
00300 inline void MeshFastFacetIterator::Next (void)
00301 {
00302 const unsigned long *paulPt = _clIter->_aulPoints;
00303 Base::Vector3f *pfPt = _afPoints;
00304 *(pfPt++) = _rclPAry[*(paulPt++)];
00305 *(pfPt++) = _rclPAry[*(paulPt++)];
00306 *pfPt = _rclPAry[*paulPt];
00307 }
00308
00309 inline MeshFacetIterator::MeshFacetIterator (const MeshKernel &rclM)
00310 : _rclMesh(rclM),
00311 _rclFAry(rclM._aclFacetArray),
00312 _rclPAry(rclM._aclPointArray),
00313 _clIter(rclM._aclFacetArray.begin()),
00314 _bApply(false)
00315 {
00316 }
00317
00318 inline MeshFacetIterator::MeshFacetIterator (const MeshKernel &rclM, unsigned long ulPos)
00319 : _rclMesh(rclM),
00320 _rclFAry(rclM._aclFacetArray),
00321 _rclPAry(rclM._aclPointArray),
00322 _clIter(rclM._aclFacetArray.begin() + ulPos),
00323 _bApply(false)
00324 {
00325 }
00326
00327 inline MeshFacetIterator::MeshFacetIterator (const MeshFacetIterator &rclI)
00328 : _rclMesh(rclI._rclMesh),
00329 _rclFAry(rclI._rclFAry),
00330 _rclPAry(rclI._rclPAry),
00331 _clIter(rclI._clIter),
00332 _bApply(rclI._bApply),
00333 _clTrf(rclI._clTrf)
00334 {
00335 }
00336
00337 inline void MeshFacetIterator::Transform( const Base::Matrix4D& rclTrf )
00338 {
00339 _clTrf = rclTrf;
00340 Base::Matrix4D tmp;
00341
00342 _clTrf != tmp ? _bApply = true : _bApply = false;
00343 }
00344
00345 inline const MeshGeomFacet& MeshFacetIterator::Dereference (void)
00346 {
00347 MeshFacet rclF = *_clIter;
00348 const unsigned long *paulPt = &(_clIter->_aulPoints[0]);
00349 Base::Vector3f *pclPt = _clFacet._aclPoints;
00350 *(pclPt++) = _rclPAry[*(paulPt++)];
00351 *(pclPt++) = _rclPAry[*(paulPt++)];
00352 *pclPt = _rclPAry[*paulPt];
00353 _clFacet._ulProp = rclF._ulProp;
00354 _clFacet._ucFlag = rclF._ucFlag;
00355 _clFacet.NormalInvalid();
00356 if ( _bApply )
00357 {
00358 _clFacet._aclPoints[0] = _clTrf * _clFacet._aclPoints[0];
00359 _clFacet._aclPoints[1] = _clTrf * _clFacet._aclPoints[1];
00360 _clFacet._aclPoints[2] = _clTrf * _clFacet._aclPoints[2];
00361 }
00362 return _clFacet;
00363 }
00364
00365 inline bool MeshFacetIterator::Set (unsigned long ulIndex)
00366 {
00367 if (ulIndex < _rclFAry.size())
00368 {
00369 _clIter = _rclFAry.begin() + ulIndex;
00370 return true;
00371 }
00372 else
00373 {
00374 _clIter = _rclFAry.end();
00375 return false;
00376 }
00377 }
00378
00379 inline MeshFacetIterator& MeshFacetIterator::operator = (const MeshFacetIterator &rpI)
00380 {
00381 _clIter = rpI._clIter;
00382 _bApply = rpI._bApply;
00383 _clTrf = rpI._clTrf;
00384
00385 memcpy((void*)&_rclMesh, &rpI._rclMesh, sizeof(&_rclMesh));
00386 return *this;
00387 }
00388
00389 inline unsigned long MeshFacetIterator::GetProperty (void) const
00390 {
00391 return _clIter->_ulProp;
00392 }
00393
00394 inline void MeshFacetIterator::GetNeighbours (MeshFacetIterator &rclN0, MeshFacetIterator &rclN1, MeshFacetIterator &rclN2) const
00395 {
00396 if (_clIter->_aulNeighbours[0] != ULONG_MAX)
00397 rclN0.Set(_clIter->_aulNeighbours[0]);
00398 else
00399 rclN0.End();
00400
00401 if (_clIter->_aulNeighbours[1] != ULONG_MAX)
00402 rclN1.Set(_clIter->_aulNeighbours[1]);
00403 else
00404 rclN1.End();
00405
00406 if (_clIter->_aulNeighbours[2] != ULONG_MAX)
00407 rclN2.Set(_clIter->_aulNeighbours[2]);
00408 else
00409 rclN2.End();
00410 }
00411
00412 inline void MeshFacetIterator::SetToNeighbour (unsigned short usN)
00413 {
00414 if (_clIter->_aulNeighbours[usN] != ULONG_MAX)
00415 _clIter = _rclFAry.begin() + _clIter->_aulNeighbours[usN];
00416 else
00417 End();
00418 }
00419
00420 inline MeshPointIterator::MeshPointIterator (const MeshKernel &rclM)
00421 : _rclMesh(rclM), _rclPAry(_rclMesh._aclPointArray), _bApply(false)
00422 {
00423 _clIter = _rclPAry.begin();
00424 }
00425
00426 inline MeshPointIterator::MeshPointIterator (const MeshKernel &rclM, unsigned long ulPos)
00427 : _rclMesh(rclM), _rclPAry(_rclMesh._aclPointArray), _bApply(false)
00428 {
00429 _clIter = _rclPAry.begin() + ulPos;
00430 }
00431
00432 inline MeshPointIterator::MeshPointIterator (const MeshPointIterator &rclI)
00433 : _rclMesh(rclI._rclMesh), _rclPAry(rclI._rclPAry), _clIter(rclI._clIter), _bApply(rclI._bApply), _clTrf(rclI._clTrf)
00434 {
00435 }
00436
00437 inline void MeshPointIterator::Transform( const Base::Matrix4D& rclTrf )
00438 {
00439 _clTrf = rclTrf;
00440 Base::Matrix4D tmp;
00441
00442 _clTrf != tmp ? _bApply = true : _bApply = false;
00443 }
00444
00445 inline const MeshPoint& MeshPointIterator::Dereference (void) const
00446 {
00447 const_cast<MeshPointIterator*>(this)->_clPoint = *_clIter;
00448 if ( _bApply )
00449 const_cast<MeshPointIterator*>(this)->_clPoint = _clTrf * _clPoint;
00450 return _clPoint;
00451 }
00452
00453 inline bool MeshPointIterator::Set (unsigned long ulIndex)
00454 {
00455 if (ulIndex < _rclPAry.size())
00456 {
00457 _clIter = _rclPAry.begin() + ulIndex;
00458 return true;
00459 }
00460 else
00461 {
00462 _clIter = _rclPAry.end();
00463 return false;
00464 }
00465 }
00466
00467 inline MeshPointIterator& MeshPointIterator::operator = (const MeshPointIterator &rpI)
00468 {
00469 _clIter = rpI._clIter;
00470 _bApply = rpI._bApply;
00471 _clTrf = rpI._clTrf;
00472
00473 memcpy((void*)&_rclMesh, &rpI._rclMesh, sizeof(&_rclMesh));
00474 return *this;
00475 }
00476
00477
00478 }
00479
00480
00481 #endif // MESH_ITERATOR_H