My Project
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
Container3d< T > Class Template Reference

Generic container to store any information in 3D (features, photos, ...) More...

#include <Container3d.h>

Classes

class  Iterator
 Iterator for going through the items in Container3d in the specified order. More...
 

Public Types

typedef std::pair< cv::Point3f, T > node_type
 node_type for storing data. 3D-position is paired with the data content.
 

Public Member Functions

void Add (const cv::Point3f &_pos, const T &_data)
 Add _data in the container and associate it with 3D position _pos.
 
void Clear ()
 Clear the container.
 
void ResetSearchSpace ()
 Reset the search space to contain whole data.
 
void Erase (size_t index)
 Erase item in the container.
 
template<typename Compare >
int Sort (Compare comp)
 Sort using external Compare method.
 
template<typename Test >
int Limit (Test test)
 Limit the search space with external limitation.
 
Iterator begin ()
 Provides an iterator pointing to the beginning of the limited/sorted 3D content.
 
Iterator end ()
 Provides an iterator pointing to the end of the limited/sorted 3D content.
 
size_t size () const
 Get number of items that can be referenced using operator[]()
 
size_t GetIndex (Iterator &iter)
 Get absolute reference usable with operator[]() based on the iterator.
 
node_typeoperator[] (size_t index)
 Instead of Iterator we can use also absolute references for data with operator[]()
 
size_t GetIndex (T *p)
 Get absolute reference usable with operator[]() based on the content.
 

Protected Attributes

std::vector< node_typedata
 the actual data in using node_type: pair<cv::Point3f, T>
 
std::vector< size_t > search_space
 Possibly limited set of indices for data in somehow "optimal" search order.
 

Detailed Description

template<class T>
class alvar::Container3d< T >

Generic container to store any information in 3D (features, photos, ...)

You can store any information in 3D using this container. Each element in the container has an unique id that it can be referenced with using operator[](). The indices are from 0 to size(). You can find specific index using GetIndex(Iterator &iter) or GetIndex(T *p) .

In addition the Container3d contains also a 'search space' that can be iterated through using begin() and end(). This 'search space' can be limited using Limit() , sorted using Sort() and reseted using ResetSearchSpace(). You specify what to limit/sort using specified functors. In ALVAR there exists functors Container3dLimitDist , Container3dSortSize and Container3dSortDist . But you can quite well make your own versions (see example below).

The implementation is optimized for a situation where there are a lot of searches between every time the search space is limited/ordered. This is the reason we use vector containers internally. The idea is that later we will improve the class by providing more ways for limiting and sorting the search space; for example Frustum culling.

Usage:

template <class T>
class Container3dSortX {
protected:
Container3d<T> &container;
public:
Container3dSortX(Container3d<T> &_container) : container(_container) {}
bool operator()(size_t i1, size_t i2) const {
return (container[i1].first.x < container[i2].first.x);
}
};
template <class T>
class Container3dLimitX {
protected:
int x_min, x_max;
Container3d<T> &container;
public:
Container3dLimitX(Container3d<T> &_container, int _x_min, int _x_max)
: container(_container),x_min(_x_min),x_max(_x_max) {}
bool operator()(size_t i1) const {
if ((container[i1].first.x >= x_min) && (container[i1].first.x <= x_max)) return true;
return false;
}
};
...
Container3d<int> c3d;
c3d.Add(cv::Point3f(0,0,0), 0);
c3d.Add(cv::Point3f(5,0,0), 1);
c3d.Add(cv::Point3f(0,5,0), 2);
c3d.Add(cv::Point3f(0,0,5), 3);
c3d.Add(cv::Point3f(0,0,500), 4);
c3d.Add(cv::Point3f(500,0,0), 5);
c3d.Add(cv::Point3f(1,0,0), 6);
c3d.Add(cv::Point3f(0,0,1), 7);
Container3dSortX<int> sortx(c3d);
Container3dLimitX<int> limitx(c3d, -10, 10);
Container3dLimitDist<int> limit_dist(c3d, cv::Point3f(0,0,0), 10.0);
c3d.ResetSearchSpace(); // Search space: 0,1,2,3,4,5,6,7
c3d.Sort(sortx); // Search space: 0,2,3,4,7,6,1,5
c3d.Limit(limitx); // Search space: 0,2,3,4,7,6,1
c3d.Limit(limit_dist); // Search space: 0,2,3,7,6,1
Container3d<int>::Iterator iter;
for (iter=c3d.begin(); iter != c3d.end(); ++iter) {
cout<<" "<<iter->second;
}

Definition at line 185 of file Container3d.h.


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