Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_SPATIAL_HASHING_HASH_QUERIES_SPATIAL_HASHING_AABB_DATA_QUERY_H
00002 #define OPENTISSUE_COLLISION_SPATIAL_HASHING_HASH_QUERIES_SPATIAL_HASHING_AABB_DATA_QUERY_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/collision/spatial_hashing/spatial_hashing_query.h>
00013
00014 #include <list>
00015 #include <cassert>
00016
00017 namespace OpenTissue
00018 {
00019 namespace spatial_hashing
00020 {
00021
00022 template<typename hash_grid, typename collision_policy>
00023 class AABBDataQuery
00024 : public Query< AABBDataQuery<hash_grid,collision_policy>, hash_grid, collision_policy >
00025 {
00026 protected:
00027
00028 typedef typename hash_grid::cell_type cell_type;
00029 typedef typename hash_grid::triplet_type triplet_type;
00030 typedef typename hash_grid::point_type point_type;
00031 typedef typename std::list<cell_type*> cell_queue;
00032
00033 public:
00034
00035 template< typename data_iterator >
00036 void first_pass(data_iterator begin,data_iterator end )
00037 {
00038 size_t stamp = 0;
00039
00040 typename hash_grid::cell_iterator Cbegin = this->begin();
00041 typename hash_grid::cell_iterator Cend = this->end();
00042 for( typename hash_grid::cell_iterator cell = Cbegin; cell!=Cend; ++cell)
00043 cell->m_query_stamp = stamp;
00044
00045 for(data_iterator data=begin; data!=end; ++data)
00046 {
00047 ++stamp;
00048
00049 point_type min_corner = min_coord( *data );
00050 point_type max_corner = max_coord( *data );
00051 triplet_type m = get_triplet(min_corner);
00052 triplet_type M = get_triplet(max_corner);
00053
00054 assert( m(0) <= M(0) || !"Minimum was larger than maximum");
00055 assert( m(1) <= M(1) || !"Minimum was larger than maximum");
00056 assert( m(2) <= M(2) || !"Minimum was larger than maximum");
00057
00058 triplet_type triplet(m);
00059 for ( triplet(0)= m(0) ; triplet(0) <= M(0); ++triplet(0) )
00060 for ( triplet(1)= m(1) ; triplet(1) <= M(1); ++triplet(1) )
00061 for ( triplet(2)= m(2) ; triplet(2) <= M(2); ++triplet(2) )
00062 {
00063 cell_type & cell = get_cell(triplet);
00064 if(cell.m_query_stamp==stamp)
00065 continue;
00066 cell.m_query_stamp=stamp;
00067 cell.add( *data );
00068 }
00069 }
00070 }
00071
00072 template< typename data_iterator >
00073 void remove_data(data_iterator begin,data_iterator end )
00074 {
00075 for(data_iterator data=begin; data!=end; ++data)
00076 {
00077 point_type min_corner = min_coord( *data );
00078 point_type max_corner = max_coord( *data );
00079 triplet_type m = get_triplet(min_corner);
00080 triplet_type M = get_triplet(max_corner);
00081
00082 assert( m(0) <= M(0) || !"Minimum was larger than maximum");
00083 assert( m(1) <= M(1) || !"Minimum was larger than maximum");
00084 assert( m(2) <= M(2) || !"Minimum was larger than maximum");
00085
00086 triplet_type triplet(m);
00087 for ( triplet(0)= m(0) ; triplet(0) <= M(0); ++triplet(0) )
00088 for ( triplet(1)= m(1) ; triplet(1) <= M(1); ++triplet(1) )
00089 for ( triplet(2)= m(2) ; triplet(2) <= M(2); ++triplet(2) )
00090 {
00091 cell_type & cell = get_cell(triplet);
00092 cell.remove( *data );
00093 }
00094 }
00095 }
00096
00097 };
00098
00099 }
00100 }
00101
00102
00103 #endif