API
 
Loading...
Searching...
No Matches
stuff.hpp
Go to the documentation of this file.
1class CircularBuffer {
2 private:
3 size_t num_rows, num_cols; // Dimensions of each image (rows x columns)
4 size_t historySize; // Total number of images the buffer can hold
5 size_t size; // Total number of elements in each image (rows * columns)
6 float* buffer; // Buffer holding the images
7 size_t head; // Index for the next write position
8 size_t tail; // Index for the next read position
9 bool is_full; // Flag to check if buffer is full
10
11 public:
12 CircularBuffer(size_t _num_rows, size_t _num_cols, size_t _historySize)
13 : num_rows(_num_rows), num_cols(_num_cols),
14 historySize(_historySize),
15 size(_num_rows * _num_cols),
16 head(0), tail(0), is_full(false) {
17
18 buffer = new float[size * historySize];
19 }
20
22 delete buffer;
23 }
24
25 // Adds an image (array of floats) to the buffer (overwrites if full)
26 void add(float* image) {
27 memcpy(buffer[(head % historySize) * size], image, sizeof(float) * size);
28 head = head + 1;
29 }
30
31 void get(float* dest, int index, int length){
32 if(index < num_elements()){
33 int data_index = (head - 1 - index) % historySize;
34 memcpy(dest, buffer[data_index * size], sizeof(float) * size);
35 }
36 }
37
38 void add_eigenimage(Eigen::Map<eigenImage<unsigned short>> image) {
39 for (size_t i = 0; i < image.size(); ++i) {
40 buffer[head][i] = image(i); // Cast to float if needed
41 }
42 }
43
45 if( head > historySize){
46 return historySize;
47 }else{
48 return head;
49 }
50 }
51
52 void reset_head(){
53 head = 0;
54 }
55
56 // Returns the n-th image in the buffer in the order of addition
57 std::vector<float> getItem(size_t n) const {
58 std::cout << "HOI" << std::endl;
59 std::cout << head << std::endl;
60 size_t index = head - n;
61 std::cout << "Accessing index " << index << std::endl;
62 return buffer[index];
63 }
64
65 std::vector<std::vector<float>> getBuffer() const {
66 return buffer;
67 }
68
69
70};
size_t num_cols
Definition po4ao.hpp:37
CircularBuffer(size_t _num_rows, size_t _num_cols, size_t _historySize)
Definition stuff.hpp:12
void add_eigenimage(Eigen::Map< eigenImage< unsigned short > > image)
Definition stuff.hpp:38
size_t head
Definition po4ao.hpp:41
size_t tail
Definition po4ao.hpp:42
size_t size
Definition po4ao.hpp:39
size_t historySize
Definition po4ao.hpp:38
int num_elements()
Definition po4ao.hpp:83
float * buffer
Definition po4ao.hpp:40
void reset_head()
Definition stuff.hpp:52
void get(float *dest, int index, int length)
Definition stuff.hpp:31
std::vector< std::vector< float > > getBuffer() const
Definition stuff.hpp:65
std::vector< float > getItem(size_t n) const
Definition stuff.hpp:57
size_t num_rows
Definition po4ao.hpp:37
void add(float *image)
Definition stuff.hpp:26