Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy > Class Template Reference

#include <spatial_hashing_query.h>

Inherited by OpenTissue::spatial_hashing::AABBDataQuery< typename collision_policy::hash_grid, collision_policy >, and OpenTissue::spatial_hashing::PointDataQuery< typename policy::hash_grid, policy >.

List of all members.

Classes

struct  all_tag
struct  no_collisions_tag

Public Member Functions

template<typename data_iterator , typename query_iterator , typename result_container , typename report_type >
void operator() (data_iterator d0, data_iterator d1, query_iterator q0, query_iterator q1, result_container &results, report_type const &type)
template<typename query_iterator , typename result_container , typename report_type >
void operator() (query_iterator q0, query_iterator q1, result_container &results, report_type const &type)
template<typename query_type , typename result_container , typename report_type >
void operator() (query_type const &q, result_container &results, report_type const &type)
template<typename data_iterator >
void init_data (data_iterator d0, data_iterator d1)
template<typename data_iterator >
void add_data (data_iterator d0, data_iterator d1)
template<typename data_iterator >
void remove_data (data_iterator d0, data_iterator d1)
template<typename iterator >
void auto_init_settings (iterator begin, iterator end)

Protected Types

typedef hash_grid::cell_type cell_type
typedef hash_grid::triplet_type triplet_type
typedef hash_grid::point_type point_type
typedef hash_grid::real_type real_type
typedef hash_grid::data_type data_type
typedef std::list< cell_type * > cell_queue
typedef std::map< data_type
*, bool > 
data_tag_queue

Protected Member Functions

void init_query ()
template<typename query_type , typename result_container >
void query (query_type const &query, result_container &results, no_collisions_tag)
template<typename query_type , typename result_container >
void query (query_type const &query, result_container &results, all_tag)

Protected Attributes

size_t m_query_stamp
 Internally used time stamp, used to guard against hash collisions during queries.

Detailed Description

template<typename child_type, typename hash_grid, typename collision_policy>
class OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >

Spatial Query Class. This class is a generic type for all types of queries on a spatial hash grid. All queries should be inherited from this class.

Notice, that the report behavior are controlled by passing along a tag to the queries. The tag indicates wether the query will guard against reporting multiple identical (data, query) pairs. Optional the end user can implement such guarding himself in the collision_policy::report method.

End user must supply a collision_policy type which defines two methods:

reset(results) report(data_type,query_type, results_container)

and depeding on the type of query the collision policy also surplies all or a subset of following methods

point_type position( data_type ) // only for point_data_query point_type min_coord data_type ) // only for aabb_data_query point_type max_coord( data_type ) // only for aabb_data_query point_type min_coord( query_type ) // for points, line and aabb data queries point_type max_coord( query_type ) // for points, line and aabb data queries point_type origin( data_type ) // only for line_data_query point_type destination( data_type ) // only for line_data_query

The report method must implement a collision test, this could for instance be a point in box test. The report method is responsible for adding collision test results to the result container, also the report method is responsible for guarding against self-collisions and possible double reported pairs (with order exchanged).

The reset method is responsible for making the results container ready for a new query. This may be an advantage if one wants to re-use allocated memory for collision results.

The spatial query expects a hash_grid type as a template argument. This hash_grid type must support the following interface:

typedef ... cell_type typedef ... triplet_type typedef ... point_type typedef ... real_type typedef ... data_type

resize(new_size) set_spacing(new_spacing) cell_iterator begin() cell_iterator end() triplet_point get_triplet(point_type) cell_type & get_cell(triplet_type)

Hash cells must support the following interface:

m_query_stamp data_iterator begin() data_iterator end() empty() add( data_type )


Member Typedef Documentation

template<typename child_type, typename hash_grid, typename collision_policy>
typedef std::list<cell_type*> OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::cell_queue [protected]
template<typename child_type, typename hash_grid, typename collision_policy>
typedef hash_grid::cell_type OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::cell_type [protected]
template<typename child_type, typename hash_grid, typename collision_policy>
typedef std::map<data_type*,bool> OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::data_tag_queue [protected]
template<typename child_type, typename hash_grid, typename collision_policy>
typedef hash_grid::data_type OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::data_type [protected]
template<typename child_type, typename hash_grid, typename collision_policy>
typedef hash_grid::point_type OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::point_type [protected]
template<typename child_type, typename hash_grid, typename collision_policy>
typedef hash_grid::real_type OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::real_type [protected]
template<typename child_type, typename hash_grid, typename collision_policy>
typedef hash_grid::triplet_type OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::triplet_type [protected]

Member Function Documentation

template<typename child_type, typename hash_grid, typename collision_policy>
template<typename data_iterator >
void OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::add_data ( data_iterator  d0,
data_iterator  d1 
) [inline]

Data Remapping. This method maps the specified data without first clearing the spatial hashgrid.

template<typename child_type, typename hash_grid, typename collision_policy>
template<typename iterator >
void OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::auto_init_settings ( iterator  begin,
iterator  end 
) [inline]

Automatically Initialization of Settings. This method performs some simple statistics to find resonable values for the hash table size and grid spacing.

This method should only be invoked once during the life-time of an application. If values are not satisfactory an end user can always omit invoking this init method and set up hash table size and grid spacing by invoking resize() method and set_spacing() mehtod.

Parameters:
begin Iterator to position of first query object.
end Iterator to position one past last query object.
template<typename child_type, typename hash_grid, typename collision_policy>
template<typename data_iterator >
void OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::init_data ( data_iterator  d0,
data_iterator  d1 
) [inline]

Data Mapping This method is provided in case the end-user wants greater control of the two pass queries.

Example scenario:

query.init_data(d0,d1); for(each query_type q){ query.run(q, results) std::cout << "near by neighbours of " << q << " are " << results << std::endl; }

Parameters:
d0 Iterator to position of first data object.
d1 Iterator to position one past last data object.
template<typename child_type, typename hash_grid, typename collision_policy>
void OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::init_query (  )  [inline, protected]
template<typename child_type, typename hash_grid, typename collision_policy>
template<typename query_iterator , typename result_container , typename report_type >
void OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::operator() ( query_iterator  q0,
query_iterator  q1,
result_container &  results,
report_type const &  type 
) [inline]

Re-run query. This method reruns the query on any previous mapped data.

Prior to invoking this method either data should have been mapped into grid by using the operator()(data_iter,data_iter) method, or a full query should have been performed.

Parameters:
q0 Iterator to position of first query object.
q1 Iterator to position one past last query object.
results Upon return contains results of query.
type This argument specifies the report type, possible types are all_tag or no_collisions_tag.
template<typename child_type, typename hash_grid, typename collision_policy>
template<typename data_iterator , typename query_iterator , typename result_container , typename report_type >
void OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::operator() ( data_iterator  d0,
data_iterator  d1,
query_iterator  q0,
query_iterator  q1,
result_container &  results,
report_type const &  type 
) [inline]

Full Query. This is a two-pass query. In first pass data is mapped into a grid, in the second pass query data is tested against content of overlapping grid cells.

Parameters:
d0 Iterator to position of first data object.
d1 Iterator to position one past last data object.
q0 Iterator to position of first query object.
q1 Iterator to position one past last query object.
results Upon return contains results of query.
type This argument specifies the report type, possible types are all_tag or no_collisions_tag.
template<typename child_type, typename hash_grid, typename collision_policy>
template<typename query_type , typename result_container , typename report_type >
void OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::operator() ( query_type const &  q,
result_container &  results,
report_type const &  type 
) [inline]

Single Shoot Query. This method runs a single shoot query on any previous mapped data.

Prior to invoking this method either data should have been mapped into grid by using the operator()(data_iter,data_iter) method, or a full query should have been performed.

Parameters:
q Query data to perform query with.
results Upon return contains results of query.
type This argument specifies the report type, possible types are all_tag or no_collisions_tag.
template<typename child_type, typename hash_grid, typename collision_policy>
template<typename query_type , typename result_container >
void OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::query ( query_type const &  query,
result_container &  results,
no_collisions_tag   
) [inline, protected]
template<typename child_type, typename hash_grid, typename collision_policy>
template<typename query_type , typename result_container >
void OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::query ( query_type const &  query,
result_container &  results,
all_tag   
) [inline, protected]
template<typename child_type, typename hash_grid, typename collision_policy>
template<typename data_iterator >
void OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::remove_data ( data_iterator  d0,
data_iterator  d1 
) [inline]

Member Data Documentation

template<typename child_type, typename hash_grid, typename collision_policy>
size_t OpenTissue::spatial_hashing::Query< child_type, hash_grid, collision_policy >::m_query_stamp [protected]

Internally used time stamp, used to guard against hash collisions during queries.


The documentation for this class was generated from the following file: