00001
00015 #ifndef _DLR_NUMERIC_AMANATIDESWOO2DITERATOR_H_
00016 #define _DLR_NUMERIC_AMANATIDESWOO2DITERATOR_H_
00017
00018 #include <iostream>
00019 #include <dlrCommon/exception.h>
00020
00021 namespace dlr {
00022
00023 namespace numeric {
00024
00037 template <class ARRAY2D>
00038 class AmanatidesWoo2DIterator
00039 : public std::iterator<std::forward_iterator_tag,
00040 typename ARRAY2D::value_type>
00041 {
00042 public:
00082 AmanatidesWoo2DIterator(ARRAY2D& data,
00083 int U, int V,
00084 int stepU, int stepV,
00085 double tMaxU, double tMaxV,
00086 double tDeltaU, double tDeltaV,
00087 double tStart);
00088
00095 AmanatidesWoo2DIterator(const AmanatidesWoo2DIterator& source);
00096
00100 ~AmanatidesWoo2DIterator() {};
00101
00111 double
00112 tEntry() {return m_tEntry;}
00113
00124 double
00125 tExit() {return std::min(m_tMaxU, m_tMaxV);}
00126
00135 int
00136 U() {return m_U;}
00137
00146 int
00147 V() {return m_V;}
00148
00158 inline typename ARRAY2D::value_type&
00159 operator*();
00160
00170 inline typename ARRAY2D::value_type*
00171 operator->();
00172
00179 inline AmanatidesWoo2DIterator&
00180 operator++();
00181
00195 inline AmanatidesWoo2DIterator
00196 operator++(int dummy);
00197
00206 AmanatidesWoo2DIterator&
00207 operator=(const AmanatidesWoo2DIterator& source);
00208
00225 inline bool
00226 operator==(const AmanatidesWoo2DIterator& other);
00227
00244 inline bool
00245 operator!=(const AmanatidesWoo2DIterator& other);
00246
00247 private:
00248 ARRAY2D& m_data;
00249 bool m_inBounds;
00250 int m_stepU;
00251 int m_stepV;
00252 double m_tDeltaU;
00253 double m_tDeltaV;
00254 double m_tEntry;
00255 double m_tMaxU;
00256 double m_tMaxV;
00257 int m_U;
00258 int m_uLimit;
00259 int m_V;
00260 int m_vLimit;
00261 };
00262
00263 }
00264
00265 }
00266
00267
00268
00269
00270 namespace dlr {
00271
00272 using numeric::AmanatidesWoo2DIterator;
00273
00274 }
00275
00276
00277
00278
00279
00280
00281 namespace dlr {
00282
00283 namespace numeric {
00284
00285
00286
00287
00288 template<class ARRAY2D>
00289 AmanatidesWoo2DIterator<ARRAY2D>::
00290 AmanatidesWoo2DIterator(ARRAY2D& data,
00291 int U, int V,
00292 int stepU, int stepV,
00293 double tMaxU, double tMaxV,
00294 double tDeltaU, double tDeltaV,
00295 double tStart)
00296 : m_data(data),
00297 m_inBounds(true),
00298 m_stepU(stepU),
00299 m_stepV(stepV),
00300 m_tDeltaU(tDeltaU),
00301 m_tDeltaV(tDeltaV),
00302 m_tEntry(tStart),
00303 m_tMaxU(tMaxU),
00304 m_tMaxV(tMaxV),
00305 m_U(U),
00306 m_uLimit(stepU > 0 ? static_cast<int>(data.columns()) : -1),
00307 m_V(V),
00308 m_vLimit(stepV > 0 ? static_cast<int>(data.rows()) : -1)
00309 {
00310 if((m_U < 0)
00311 || (m_V < 0)
00312 || (m_U >= static_cast<int>(m_data.columns()))
00313 || (m_V >= static_cast<int>(m_data.rows()))) {
00314 m_inBounds = false;
00315 }
00316 }
00317
00318
00319 template<class ARRAY2D>
00320 AmanatidesWoo2DIterator<ARRAY2D>::
00321 AmanatidesWoo2DIterator(const AmanatidesWoo2DIterator& source)
00322 : m_data(source.m_data),
00323 m_inBounds(source.m_inBounds),
00324 m_stepU(source.m_stepU),
00325 m_stepV(source.m_stepV),
00326 m_tDeltaU(source.m_tDeltaU),
00327 m_tDeltaV(source.m_tDeltaV),
00328 m_tEntry(source.m_tEntry),
00329 m_tMaxU(source.m_tMaxU),
00330 m_tMaxV(source.m_tMaxV),
00331 m_U(source.m_U),
00332 m_uLimit(source.m_uLimit),
00333 m_V(source.m_V),
00334 m_vLimit(source.m_vLimit)
00335 {
00336
00337 }
00338
00339
00340
00341 template<class ARRAY2D>
00342 inline typename ARRAY2D::value_type&
00343 AmanatidesWoo2DIterator<ARRAY2D>::
00344 operator*()
00345 {
00346 return m_data(m_V, m_U);
00347 }
00348
00349
00350
00351 template<class ARRAY2D>
00352 inline typename ARRAY2D::value_type*
00353 AmanatidesWoo2DIterator<ARRAY2D>::
00354 operator->()
00355 {
00356 return &(this->operator*());
00357 }
00358
00359
00360
00361 template<class ARRAY2D>
00362 inline AmanatidesWoo2DIterator<ARRAY2D>&
00363 AmanatidesWoo2DIterator<ARRAY2D>::
00364 operator++()
00365 {
00366 if(m_tMaxU < m_tMaxV) {
00367 m_tEntry = m_tMaxU;
00368 m_U += m_stepU;
00369 m_tMaxU += m_tDeltaU;
00370 if(m_U == m_uLimit) {
00371 m_inBounds = false;
00372 }
00373 } else {
00374 m_tEntry = m_tMaxV;
00375 m_V += m_stepV;
00376 m_tMaxV += m_tDeltaV;
00377 if(m_V == m_vLimit) {
00378 m_inBounds = false;
00379 }
00380 }
00381 return *this;
00382 }
00383
00384
00385
00386
00387 template<class ARRAY2D>
00388 inline AmanatidesWoo2DIterator<ARRAY2D>
00389 AmanatidesWoo2DIterator<ARRAY2D>::
00390 operator++(int)
00391 {
00392 AmanatidesWoo2DIterator<ARRAY2D> thisCopy(*this);
00393 ++this;
00394 return thisCopy;
00395 }
00396
00397
00398
00399 template<class ARRAY2D>
00400 AmanatidesWoo2DIterator<ARRAY2D>&
00401 AmanatidesWoo2DIterator<ARRAY2D>::
00402 operator=(const AmanatidesWoo2DIterator& source)
00403 {
00404 m_data = source.m_data;
00405 m_inBounds = source.m_inBounds;
00406 m_stepU = source.m_stepU;
00407 m_stepV = source.m_stepV;
00408 m_tDeltaU = source.m_tDeltaU;
00409 m_tDeltaV = source.m_tDeltaV;
00410 m_tEntry = source.m_tEntry;
00411 m_tMaxU = source.m_tMaxU;
00412 m_tMaxV = source.m_tMaxV;
00413 m_U = source.m_U;
00414 m_uLimit = source.m_uLimit;
00415 m_V = source.m_V;
00416 m_vLimit = source.m_vLimit;
00417 return *this;
00418 }
00419
00420
00421
00422 template<class ARRAY2D>
00423 inline bool
00424 AmanatidesWoo2DIterator<ARRAY2D>::
00425 operator==(const AmanatidesWoo2DIterator& other)
00426 {
00427
00428
00429 return (m_inBounds == other.m_inBounds);
00430 }
00431
00432
00433
00434 template<class ARRAY2D>
00435 inline bool
00436 AmanatidesWoo2DIterator<ARRAY2D>::
00437 operator!=(const AmanatidesWoo2DIterator& other)
00438 {
00439 return !(this->operator==(other));
00440 }
00441
00442 }
00443
00444 }
00445
00446 #endif // #ifndef _DLR_NUMERIC_AMANATIDESWOO2DITERATOR_H_