00001 #ifndef OPENTISSUE_COLLISION_BVH_BVH_BV_TRAVERSAL_ITERATOR_H 00002 #define OPENTISSUE_COLLISION_BVH_BVH_BV_TRAVERSAL_ITERATOR_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 namespace OpenTissue 00013 { 00014 namespace bvh 00015 { 00016 00021 template<typename bvh_type> 00022 class BVTraversalIterator 00023 : public std::iterator<std::forward_iterator_tag, typename bvh_type::bv_type> 00024 { 00025 public: 00026 00027 typedef typename bvh_type::bv_type bv_type; 00028 typedef typename bvh_type::bv_ptr_container bv_ptr_container; 00029 typedef typename bvh_type::bv_ptr bv_ptr; 00030 typedef typename bvh_type::bv_ptr_iterator bv_ptr_iterator; 00031 typedef typename bvh_type::bv_const_ptr bv_const_ptr; 00032 00033 protected: 00034 00035 bv_ptr m_bv; 00036 bv_ptr_container m_queue; 00037 00038 public: 00039 00040 BVTraversalIterator(bv_ptr bv) 00041 : m_bv(bv) 00042 { 00043 if(bv) 00044 { 00045 bv_ptr_iterator begin = m_bv->child_ptr_begin(); 00046 bv_ptr_iterator end = m_bv->child_ptr_end(); 00047 for(bv_ptr_iterator child = begin; child != end; ++child ) 00048 m_queue.push_back( *child ); 00049 } 00050 } 00051 00052 bool operator== ( BVTraversalIterator const & other ) const{ return (other.m_bv==m_bv); } 00053 00054 bool operator!= ( BVTraversalIterator const & other ) const{ return !((*this)==other); } 00055 00056 bv_type & operator*() {return (*m_bv);} 00057 00058 bv_ptr operator->() {return m_bv;} 00059 00060 bv_type const & operator*()const {return (*m_bv);} 00061 00062 bv_const_ptr operator->()const {return bv_const_ptr(m_bv);} 00063 00064 BVTraversalIterator & operator++() 00065 { 00066 if(m_queue.empty()) 00067 { 00068 // Set bv to null pointer 00069 m_bv.reset(); 00070 return (*this); 00071 } 00072 m_bv = m_queue.front(); 00073 m_queue.pop_front(); 00074 bv_ptr_iterator begin = m_bv->child_ptr_begin(); 00075 bv_ptr_iterator end = m_bv->child_ptr_end(); 00076 for(bv_ptr_iterator child = begin; child != end; ++child ) 00077 m_queue.push_back( *child ); 00078 return (*this); 00079 } 00080 }; 00081 00082 } // namespace bvh 00083 } // namespace OpenTissue 00084 00085 //OPENTISSUE_COLLISION_BVH_BVH_BV_TRAVERSAL_ITERATOR_H 00086 #endif