PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusTimestampedCircularBuffer.h
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2  Program: Plus
3  Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4  See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 #ifndef __vtkPlusTimestampedCircularBuffer_h
8 #define __vtkPlusTimestampedCircularBuffer_h
9 
10 #include "PlusConfigure.h"
11 #include "PlusStreamBufferItem.h"
12 #include "vtkObject.h"
13 #include <deque>
14 
15 #include "vnl/vnl_matrix.h"
16 #include "vnl/vnl_vector.h"
17 
18 #include <float.h> // for DBL_MAX
19 
20 class vtkIGSIORecursiveCriticalSection;
21 class vtkTable;
22 
29 
30 
37 class vtkPlusTimestampedCircularBuffer: public vtkObject
38 {
39 public:
41  void PrintSelf( ostream& os, vtkIndent indent );
42 
47  virtual PlusStatus SetBufferSize( int n );
48  virtual inline int GetBufferSize() { return this->BufferItemContainer.size(); };
49 
56  vtkGetMacro( NumberOfItems, int );
57 
62  virtual ItemStatus GetItemUidFromTime( const double time, BufferItemUidType& uid );
63 
66  {
67  this->Lock();
68  BufferItemUidType latestUid = this->LatestItemUid;
69  this->Unlock();
70  return latestUid;
71  }
72 
75  {
76  this->Lock();
77  // LatestItemUid - ( NumberOfItems - 1 ) is the oldest element in the buffer
78  BufferItemUidType oldestUid = this->LatestItemUid - ( this->NumberOfItems - 1 );
79  this->Unlock();
80  return oldestUid;
81  }
82 
85  {
86  return this->GetTimeStamp( this->GetLatestItemUidInBuffer(), timestamp );
87  }
88 
90  {
91  // The oldest item may be removed from the buffer at any moment
92  // therefore we need to retrieve its UID and timestamp within a single lock
93  this->Lock();
94  // LatestItemUid - ( NumberOfItems - 1 ) is the oldest element in the buffer
95  BufferItemUidType oldestUid = ( this->LatestItemUid - ( this->NumberOfItems - 1 ) );
96  ItemStatus status = this->GetTimeStamp( oldestUid, timestamp );
97  this->Unlock();
98  return status;
99  }
100 
101  virtual ItemStatus GetTimeStamp( const BufferItemUidType uid, double& timestamp ) { return this->GetFilteredTimeStamp( uid, timestamp ); }
102  virtual ItemStatus GetFilteredTimeStamp( const BufferItemUidType uid, double& filteredTimestamp );
103  virtual ItemStatus GetUnfilteredTimeStamp( const BufferItemUidType uid, double& unfilteredTimestamp );
104 
105  virtual bool GetLatestItemHasValidVideoData();
106  virtual bool GetLatestItemHasValidTransformData();
107  virtual bool GetLatestItemHasValidFieldData();
108 
109 
111  virtual ItemStatus GetIndex( const BufferItemUidType uid, unsigned long& index );
112 
117  virtual ItemStatus GetBufferIndexFromTime( const double time, int& bufferIndex );
118 
123  virtual void DeepCopy( vtkPlusTimestampedCircularBuffer* buffer );
124 
126  vtkSetMacro( LocalTimeOffsetSec, double );
128  vtkGetMacro( LocalTimeOffsetSec, double );
129 
139  virtual double GetFrameRate( bool ideal = false, double* framePeriodStdevSecPtr = NULL );
140 
142  virtual void Clear();
143 
149  inline void Lock() { this->Mutex->Lock(); };
155  inline void Unlock() { this->Mutex->Unlock(); };
156 
161  virtual StreamBufferItem* GetBufferItemPointerFromBufferIndex( const int bufferIndex );
162 
168 
169  virtual PlusStatus PrepareForNewItem( const double timestamp, BufferItemUidType& newFrameUid, int& bufferIndex );
170 
181  virtual PlusStatus CreateFilteredTimeStampForItem( unsigned long itemIndex, double inUnfilteredTimestamp, double& outFilteredTimestamp, bool& filteredTimestampProbablyValid );
182 
184  void AddToTimeStampReport( unsigned long itemIndex, double unfilteredTimestamp, double filteredTimestamp );
185 
187  PlusStatus GetTimeStampReportTable( vtkTable* timeStampReportTable );
188 
190  vtkSetMacro( TimeStampReporting, bool );
191  vtkGetMacro( TimeStampReporting, bool );
192  vtkBooleanMacro( TimeStampReporting, bool );
193 
195  vtkSetMacro( TimeStampLogging, bool );
196  vtkGetMacro( TimeStampLogging, bool );
197  vtkBooleanMacro( TimeStampLogging, bool );
198 
200  vtkSetMacro( AveragedItemsForFiltering, unsigned int );
202  vtkGetMacro( AveragedItemsForFiltering, int );
203 
205  vtkSetMacro( StartTime, double );
207  vtkGetMacro( StartTime, double );
208 
209 protected:
212 
213 protected:
214  vtkIGSIORecursiveCriticalSection* Mutex;
215 
217 
220 
222 
225 
231 
232  std::deque<StreamBufferItem> BufferItemContainer;
233 
235  vnl_vector<double> FilterContainerIndexVector;
236 
238  vnl_vector<double> FilterContainerTimestampVector;
239 
242 
245 
248 
255 
257  double StartTime;
258 
261 
272 
278 
279 private:
281  void operator=( const vtkPlusTimestampedCircularBuffer& );
282 };
283 
284 #endif
virtual BufferItemUidType GetOldestItemUidInBuffer()
virtual ItemStatus GetBufferItemPointerFromUid(const BufferItemUidType uid, StreamBufferItem *&itemPtr)
double * timestamp
Definition: phidget22.h:3432
virtual ItemStatus GetLatestTimeStamp(double &timestamp)
vtkIGSIORecursiveCriticalSection * Mutex
virtual void DeepCopy(vtkPlusTimestampedCircularBuffer *buffer)
igsioStatus PlusStatus
Definition: PlusCommon.h:40
virtual double GetFrameRate(bool ideal=false, double *framePeriodStdevSecPtr=NULL)
static vtkPlusTimestampedCircularBuffer * New()
virtual PlusStatus PrepareForNewItem(const double timestamp, BufferItemUidType &newFrameUid, int &bufferIndex)
This class stores an fixed number of timestamped items. It provides element retrieval based on timest...
virtual ItemStatus GetItemUidFromTime(const double time, BufferItemUidType &uid)
virtual PlusStatus CreateFilteredTimeStampForItem(unsigned long itemIndex, double inUnfilteredTimestamp, double &outFilteredTimestamp, bool &filteredTimestampProbablyValid)
virtual BufferItemUidType GetLatestItemUidInBuffer()
void PrintSelf(ostream &os, vtkIndent indent)
PhidgetGPS_Time * time
Definition: phidget22.h:3623
PlusStatus GetTimeStampReportTable(vtkTable *timeStampReportTable)
void AddToTimeStampReport(unsigned long itemIndex, double unfilteredTimestamp, double filteredTimestamp)
virtual ItemStatus GetFilteredTimeStamp(const BufferItemUidType uid, double &filteredTimestamp)
virtual ItemStatus GetOldestTimeStamp(double &timestamp)
std::deque< StreamBufferItem > BufferItemContainer
virtual ItemStatus GetBufferIndexFromTime(const double time, int &bufferIndex)
virtual StreamBufferItem * GetBufferItemPointerFromBufferIndex(const int bufferIndex)
virtual ItemStatus GetIndex(const BufferItemUidType uid, unsigned long &index)
virtual ItemStatus GetTimeStamp(const BufferItemUidType uid, double &timestamp)
virtual ItemStatus GetUnfilteredTimeStamp(const BufferItemUidType uid, double &unfilteredTimestamp)
unsigned long long BufferItemUidType