47 #ifndef _MIRA_STAMPEDDATAQUEUE_H_ 48 #define _MIRA_STAMPEDDATAQUEUE_H_ 83 template <
typename T >
108 mMaxCapacity(maxCapacity), mMaxStorageTime(maxStorageTime) {}
117 mMaxStorageTime = maxStorageTime;
146 bool empty()
const {
return mStorage.empty(); }
156 typename Container::iterator it = mStorage.begin();
159 if(it!=mStorage.end() && it->timestamp > data.
timestamp + mMaxStorageTime)
163 for(;it != mStorage.end(); ++it)
173 if(it!=mStorage.end() && it->timestamp==data.
timestamp)
178 if (it == mStorage.end() && mStorage.size() == mMaxCapacity)
181 mStorage.insert(it, data);
201 if (mStorage.empty())
202 MIRA_THROW(XRuntime,
"Trying to get data from empty StampedDataQueue");
206 if(older==mStorage.begin())
213 if(older==mStorage.end())
217 if( (newer->timestamp - timestamp) <
218 (timestamp - older->timestamp))
245 assert(
size==0 ||
size >= before+after);
256 for(std::size_t i=0; i<before && last!=mStorage.end(); ++i, ++last) ;
260 for(; i<after && first!=mStorage.begin(); ++i, --first) ;
264 std::size_t left =
size-std::distance(first,last);
265 while(left>0 && first!=mStorage.begin()) {
269 while(left>0 && last!=mStorage.end()) {
276 "Not enough items in StampedDataQueue to obtain " 277 "the requested interval: " << left <<
281 return std::make_pair(first, last);
293 Time oldestTimestamp = mStorage.begin()->timestamp - mMaxStorageTime;
296 while(!mStorage.empty() &&
297 (mStorage.rbegin()->timestamp < oldestTimestamp ||
298 mStorage.size() > mMaxCapacity) )
304 typename Container::const_iterator findFirstOlderItem(
const Time& timestamp)
const 307 for(
typename Container::const_iterator it=mStorage.begin();
308 it!=mStorage.end(); ++it)
309 if(it->timestamp < timestamp)
314 return mStorage.end();
320 Duration mMaxStorageTime;
void reserve(size_type n)
Request a change in capacity.
Definition: StampedDataQueue.h:136
Include file for all eigen related things.
StampedDataQueue(size_type maxCapacity=100, Duration maxStorageTime=Duration::seconds(10))
Creates new StampedDataQueue with the specified maximum capacity (default 100) and maximum storage ti...
Definition: StampedDataQueue.h:106
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
std::list< Stamped< T >, Eigen::aligned_allocator< T > > Container
The type of the underlying container.
Definition: StampedDataQueue.h:89
Implements a queue where Stamped data can be added.
Definition: StampedDataQueue.h:84
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:416
void clear()
clears the whole queue and removes all elements
Definition: StampedDataQueue.h:191
Commonly used exception classes.
sec_type seconds() const
Returns normalized number of seconds (0..59)
Definition: Time.h:278
Use this class to represent time durations.
Definition: Time.h:104
std::pair< const_iterator, const_iterator > getInterval(const Time ×tamp, std::size_t size, std::size_t before, std::size_t after)
Returns two iterators that mark the begin and end of an interval of data.
Definition: StampedDataQueue.h:240
size_type capacity() const
Returns the maximum number of items that can be stored in the queue.
Definition: StampedDataQueue.h:127
size_type size() const
Returns the number of stored elements.
Definition: StampedDataQueue.h:143
Mix in for adding a time stamp, an optional frame id and an optional sequence id to data types like P...
Definition: Stamped.h:149
Container::size_type size_type
some typedefs for STL compliance
Definition: StampedDataQueue.h:98
Container::const_iterator const_iterator
some typedefs for STL compliance
Definition: StampedDataQueue.h:95
Mix in for adding a timestamp to data types.
bool empty() const
Returns true, if no element is stored.
Definition: StampedDataQueue.h:146
Stamped< T > value_type
some typedefs for STL compliance
Definition: StampedDataQueue.h:92
void setMaxStorageTime(Duration maxStorageTime)
Sets the maximum storage time.
Definition: StampedDataQueue.h:115
bool insert(const Stamped< T > &data)
Inserts new data to the queue.
Definition: StampedDataQueue.h:154
const Stamped< T > & getData(const Time ×tamp) const
Returns the data from the queue whose time stamp is closest to the specified timestamp.
Definition: StampedDataQueue.h:199