27 #include "searchspacepool.h" 28 #include "distancefunction.h" 29 #include "frozendistance.h" 41 template <
typename DataSetType,
typename Po
intType,
typename SearchPo
intType,
typename DistanceType>
46 typedef BaseResultSet<SearchPointType, DataSetType> ResultSetType;
47 typedef BaseSearchSpace<SearchPointType, DataSetType> SearchSpaceType;
49 BaseView(DataSetType* dataset);
52 ResultSetType nnSearch(
const PointType& p,
const DistanceType* dist,
const Filter* filter = 0);
53 ResultSetType nnSearch(
const PointType& p,
const DistanceType* dist,
const QString& filter);
55 ResultSetType nnSearch(
const PointType& p, ResultSetType inputSpace,
56 const DistanceType* dist,
const Filter* filter = 0);
57 ResultSetType nnSearch(
const PointType& p, ResultSetType inputSpace,
58 const DistanceType* dist,
const QString& filter);
62 ResultSetType nnSearch(
const QString&
id, T x) {
64 return nnSearch(*_dataset->point(
id), x);
67 template <
typename T,
typename U>
68 ResultSetType nnSearch(
const QString&
id, T x, U y) {
70 return nnSearch(*_dataset->point(
id), x, y);
73 template <
typename T,
typename U,
typename V>
74 ResultSetType nnSearch(
const QString&
id, T x, U y, V z) {
76 return nnSearch(*_dataset->point(
id), x, y, z);
95 void indexOn(
const QString& descriptorName);
100 QPointer<DataSetType> _dataset;
103 BaseSearchSpacePool<SearchPointType, DataSetType> _searchSpacePool;
109 static Filter* createFilter(
const QString& filterString);
110 static void bindFilter(
const Filter* filter,
const DataSetType* dataset);
112 static SearchResults formatResults(std::priority_queue<SearchPointType>& results);
117 void checkPoint(
const PointType& p);
118 void checkDistance(
const DistanceType* dist);
131 const Filter* filter = 0,
132 bool spaceOwnsFilter =
true);
139 const QString& filterString);
145 ResultSetType nnSearch(
const PointType& p,
146 SearchSpaceType* sspace,
147 const DistanceType* dist);
152 typedef BaseView<DataSet, Point, SearchPoint, DistanceFunction> View;
153 typedef BaseView<FrozenDataSet, FrozenPoint, FrozenSearchPoint, FrozenDistance> FrozenView;
154 typedef BaseResultSet<FrozenSearchPoint, FrozenDataSet> FrozenResultSet;
157 inline void View::checkPoint(
const Point& p) {
158 if (p.layout() != _dataset->layout()) {
160 msg <<
"Cannot query for point '" << p.name() <<
"', because it has a different " 161 <<
"layout than the one from the dataset which the view points at.";
162 throw GaiaException(msg);
167 inline void View::checkDistance(
const DistanceFunction* dist) {
168 if (dist->layout() != _dataset->layout()) {
170 msg <<
"View: cannot use given distance because the DataSet and the DistanceFunction " 171 <<
"don't share the same layout\n" 172 <<
"Different descriptors: " 173 << dist->layout().symmetricDifferenceWith(_dataset->layout()).join(
", ");
174 throw GaiaException(msg);
179 inline void FrozenView::checkPoint(
const FrozenPoint& p) {
180 if (p.cols() != _dataset->cols()) {
182 msg <<
"Cannot query for point because it has a different dimension " 183 <<
"than the one from the dataset which the view points at.";
184 throw GaiaException(msg);
189 inline void FrozenView::checkDistance(
const FrozenDistance* dist) {
190 if (&dist->dataset() != _dataset) {
192 msg <<
"View: you can only use a distance which has been created with " 193 <<
"the same dataset as the one that was used to create this view.";
194 throw GaiaException(msg);
199 template <>
template <
typename T>
200 FrozenResultSet FrozenView::nnSearch(
const QString&
id, T x) {
202 return nnSearch(_dataset->row(_dataset->pointIndex(
id)), x);
205 template <>
template <
typename T,
typename U>
206 FrozenResultSet FrozenView::nnSearch(
const QString&
id, T x, U y) {
208 return nnSearch(_dataset->row(_dataset->pointIndex(
id)), x, y);
211 template <>
template <
typename T,
typename U,
typename V>
212 FrozenResultSet FrozenView::nnSearch(
const QString&
id, T x, U y, V z) {
214 return nnSearch(_dataset->row(_dataset->pointIndex(
id)), x, y, z);
223 #include "view_impl.h" 226 #endif // GAIA_VIEW_H Main Gaia namespace, which contains all the library functions.
Definition: addfield.cpp:22
SearchSpaceType * getSearchSpace(SearchSpaceType *sspace=0, const Filter *filter=0, bool spaceOwnsFilter=true)
Returns a valid SearchSpace with associated filter.
Definition: view_impl.h:194
void indexOn(const QString &descriptorName)
This methods creates an index on the given descriptor name, in the hope that future queries using thi...
Definition: view_impl.h:51
void invalidate()
This function is called whenever the DataSet it points to changes, so it knows it needs to recompute ...
Definition: view_impl.h:58
void validate()
This function is called to make sure that the View is valid (ie: its sorting structure and filters ac...
Definition: view_impl.h:64