amanatidesWoo3DIterator.h

Go to the documentation of this file.
00001 
00015 #ifndef _DLR_NUMERIC_AMANATIDESWOO3DITERATOR_H_
00016 #define _DLR_NUMERIC_AMANATIDESWOO3DITERATOR_H_
00017 
00018 #include <iostream>
00019 #include <dlrCommon/exception.h>
00020 
00021 namespace dlr {
00022 
00023   namespace numeric {
00024     
00037     template <class ARRAY3D>
00038     class AmanatidesWoo3DIterator
00039       : public std::iterator<std::forward_iterator_tag,
00040                              typename ARRAY3D::value_type>
00041     {
00042     public:
00097       AmanatidesWoo3DIterator(ARRAY3D& data,
00098                               int U, int V, int W,
00099                               int stepU, int stepV, int stepW,
00100                               double tMaxU, double tMaxV, double tMaxW,
00101                               double tDeltaU, double tDeltaV, double tDeltaW,
00102                               double tStart);
00103 
00110       AmanatidesWoo3DIterator(const AmanatidesWoo3DIterator& source);
00111 
00115       ~AmanatidesWoo3DIterator() {};
00116 
00126       double
00127       tEntry() {return m_tEntry;}
00128 
00139       double
00140       tExit() {return std::min(m_tMaxU, std::min(m_tMaxV, m_tMaxW));}
00141 
00150       int
00151       U() {return m_U;}
00152 
00161       int
00162       V() {return m_V;}
00163 
00172       int
00173       W() {return m_W;}
00174 
00184       inline typename ARRAY3D::value_type& // element_type?
00185       operator*();
00186 
00196       inline typename ARRAY3D::value_type* // element_type?
00197       operator->();
00198 
00205       inline AmanatidesWoo3DIterator&
00206       operator++();                  // prefix
00207 
00221       inline AmanatidesWoo3DIterator
00222       operator++(int dummy);                 // postfix
00223 
00232       AmanatidesWoo3DIterator&
00233       operator=(const AmanatidesWoo3DIterator& source);
00234 
00251       inline bool
00252       operator==(const AmanatidesWoo3DIterator& other);
00253 
00270       inline bool
00271       operator!=(const AmanatidesWoo3DIterator& other);
00272 
00273     private:
00274       ARRAY3D& m_data;
00275       bool m_inBounds;
00276       int m_stepU;
00277       int m_stepV;
00278       int m_stepW;
00279       double m_tDeltaU;
00280       double m_tDeltaV;
00281       double m_tDeltaW;
00282       double m_tEntry;
00283       double m_tMaxU;
00284       double m_tMaxV;
00285       double m_tMaxW;
00286       int m_U;
00287       int m_uLimit;
00288       int m_V;
00289       int m_vLimit;
00290       int m_W;
00291       int m_wLimit;
00292     };
00293 
00294   } // namespace numeric
00295 
00296 } // namespace dlr
00297 
00298 
00299 /* ======= Declarations to maintain compatibility with legacy code. ======= */
00300 
00301 namespace dlr {
00302 
00303   using numeric::AmanatidesWoo3DIterator;
00304 
00305 } // namespace dlr
00306 
00307 
00308 /* ========================================================= */
00309 /* Implementation follows                                    */
00310 /* ========================================================= */
00311 
00312 namespace dlr {
00313 
00314   namespace numeric {
00315     
00316     // The class constructor is initialized with all of the internal
00317     // variables of the voxel traversal algorithm, plus the starting
00318     // value of the ray parameter.
00319     template<class ARRAY3D>
00320     AmanatidesWoo3DIterator<ARRAY3D>::
00321     AmanatidesWoo3DIterator(ARRAY3D& data,
00322                             int U, int V, int W,
00323                             int stepU, int stepV, int stepW,
00324                             double tMaxU, double tMaxV, double tMaxW,
00325                             double tDeltaU, double tDeltaV, double tDeltaW,
00326                             double tStart)
00327       : m_data(data),
00328         m_inBounds(true),
00329         m_stepU(stepU),
00330         m_stepV(stepV),
00331         m_stepW(stepW),
00332         m_tDeltaU(tDeltaU),
00333         m_tDeltaV(tDeltaV),
00334         m_tDeltaW(tDeltaW),
00335         m_tEntry(tStart),
00336         m_tMaxU(tMaxU),
00337         m_tMaxV(tMaxV),
00338         m_tMaxW(tMaxW),
00339         m_U(U),
00340         m_uLimit(stepU > 0 ? static_cast<int>(data.shape()[2]) : -1),
00341         m_V(V),
00342         m_vLimit(stepV > 0 ? static_cast<int>(data.shape()[1]) : -1),
00343         m_W(W),
00344         m_wLimit(stepW > 0 ? static_cast<int>(data.shape()[0]) : -1)
00345     {
00346       if((m_U < 0)
00347          || (m_V < 0)
00348          || (m_W < 0)
00349          || (m_U >= static_cast<int>(data.shape()[2]))
00350          || (m_V >= static_cast<int>(data.shape()[1]))
00351          || (m_W >= static_cast<int>(data.shape()[0]))) {
00352         m_inBounds = false;      
00353       }
00354     }
00355 
00356     // Copy constructor.
00357     template<class ARRAY3D>
00358     AmanatidesWoo3DIterator<ARRAY3D>::
00359     AmanatidesWoo3DIterator(const AmanatidesWoo3DIterator& source)
00360       : m_data(source.m_data),
00361         m_inBounds(source.m_inBounds),
00362         m_stepU(source.m_stepU),
00363         m_stepV(source.m_stepV),
00364         m_stepW(source.m_stepW),
00365         m_tDeltaU(source.m_tDeltaU),
00366         m_tDeltaV(source.m_tDeltaV),
00367         m_tDeltaW(source.m_tDeltaW),
00368         m_tEntry(source.m_tEntry),
00369         m_tMaxU(source.m_tMaxU),
00370         m_tMaxV(source.m_tMaxV),
00371         m_tMaxW(source.m_tMaxW),
00372         m_U(source.m_U),
00373         m_uLimit(source.m_uLimit),
00374         m_V(source.m_V),
00375         m_vLimit(source.m_vLimit),
00376         m_W(source.m_W),
00377         m_wLimit(source.m_wLimit)
00378     {
00379       // Empty
00380     }
00381 
00382     // This operator returns a reference to the Array3D element at the
00383     // current voxel.
00384     template<class ARRAY3D>
00385     inline typename ARRAY3D::value_type& // element_type?
00386     AmanatidesWoo3DIterator<ARRAY3D>::
00387     operator*()
00388     {
00389       return m_data(m_W, m_V, m_U);
00390     }
00391 
00392     // This operator returns a pointer to the Array3D element at the
00393     // current voxel.
00394     template<class ARRAY3D>
00395     inline typename ARRAY3D::value_type* // element_type?
00396     AmanatidesWoo3DIterator<ARRAY3D>::
00397     operator->()
00398     {
00399       return &(this->operator*());
00400     }
00401 
00402     // The pre-increment operator increments the iterator so that it
00403     // points to the next voxel along the path.
00404     template<class ARRAY3D>
00405     inline AmanatidesWoo3DIterator<ARRAY3D>&
00406     AmanatidesWoo3DIterator<ARRAY3D>::
00407     operator++()
00408     {
00409       if(m_tMaxU < m_tMaxV) {
00410         if(m_tMaxW < m_tMaxU) {
00411           m_tEntry = m_tMaxW;
00412           m_W += m_stepW;
00413           m_tMaxW += m_tDeltaW;
00414           if(m_W == m_wLimit) {
00415             m_inBounds = false;
00416           }
00417         } else {
00418           m_tEntry = m_tMaxU;
00419           m_U += m_stepU;
00420           m_tMaxU += m_tDeltaU;
00421           if(m_U == m_uLimit) {
00422             m_inBounds = false;
00423           }
00424         }
00425       } else {
00426         if(m_tMaxW < m_tMaxV) {
00427           m_tEntry = m_tMaxW;
00428           m_W += m_stepW;
00429           m_tMaxW += m_tDeltaW;
00430           if(m_W == m_wLimit) {
00431             m_inBounds = false;
00432           }
00433         } else {
00434           m_tEntry = m_tMaxV;
00435           m_V += m_stepV;
00436           m_tMaxV += m_tDeltaV;
00437           if(m_V == m_vLimit) {
00438             m_inBounds = false;
00439           }
00440         }
00441       }
00442       return *this;
00443     }
00444 
00445     // The post-increment operator increments the iterator so that it
00446     // points to the next voxel along the path.  It differs from the
00447     // pre-increment operator in its return value.
00448     template<class ARRAY3D>
00449     inline AmanatidesWoo3DIterator<ARRAY3D>
00450     AmanatidesWoo3DIterator<ARRAY3D>::
00451     operator++(int)
00452     {
00453       AmanatidesWoo3DIterator<ARRAY3D> thisCopy(*this);
00454       ++this;
00455       return thisCopy;
00456     }
00457 
00458     // This is the assignment operator.  It copies the value of its
00459     // argument into *this.
00460     template<class ARRAY3D>
00461     AmanatidesWoo3DIterator<ARRAY3D>&
00462     AmanatidesWoo3DIterator<ARRAY3D>::
00463     operator=(const AmanatidesWoo3DIterator& source)
00464     {
00465       m_data = source.m_data;
00466       m_inBounds = source.m_inBounds;
00467       m_stepU = source.m_stepU;
00468       m_stepV = source.m_stepV;
00469       m_stepW = source.m_stepW;
00470       m_tDeltaU = source.m_tDeltaU;
00471       m_tDeltaV = source.m_tDeltaV;
00472       m_tDeltaW = source.m_tDeltaW;
00473       m_tEntry = source.m_tEntry;
00474       m_tMaxU = source.m_tMaxU;
00475       m_tMaxV = source.m_tMaxV;
00476       m_tMaxW = source.m_tMaxW;
00477       m_U = source.m_U;
00478       m_uLimit = source.m_uLimit;
00479       m_V = source.m_V;
00480       m_vLimit = source.m_vLimit;
00481       m_W = source.m_W;
00482       m_wLimit = source.m_wLimit;
00483       return *this;
00484     }
00485 
00486     // The equality operator returns true if *this currently
00487     // references the same voxel as the argument.
00488     template<class ARRAY3D>
00489     inline bool
00490     AmanatidesWoo3DIterator<ARRAY3D>::
00491     operator==(const AmanatidesWoo3DIterator& other)
00492     {
00493       // Return true if both refer to valid voxels or if both refer to
00494       // invalid voxels.
00495       return (m_inBounds == other.m_inBounds);
00496     }
00497 
00498     // The inequality operator returns true if *this currently
00499     // references the a different voxel than the argument.
00500     template<class ARRAY3D>
00501     inline bool
00502     AmanatidesWoo3DIterator<ARRAY3D>::
00503     operator!=(const AmanatidesWoo3DIterator& other)
00504     {
00505       return !(this->operator==(other));
00506     }
00507   
00508   } // namespace numeric
00509 
00510 } // namespace dlr
00511 
00512 #endif // #ifndef _DLR_NUMERIC_AMANATIDESWOO3DITERATOR_H_

Generated on Wed Nov 25 00:42:40 2009 for dlrUtilities Utility Library by  doxygen 1.5.8