NodeData.hpp
Go to the documentation of this file.
1 
28 /*
29  * NodeData.hpp
30  *
31  * Created on: Dec 11, 2015
32  * Author: Isaak Mitschke
33  */
34 
35 #ifndef LAS_VEGAS_NODEDATA_H
36 #define LAS_VEGAS_NODEDATA_H
37 #include <boost/timer/timer.hpp>
38 #include <ctime>
39 #include <fstream>
40 #include <iostream>
41 #include <string>
42 #include <vector>
43 
44 using namespace std;
45 
46 namespace lvr2
47 {
51 template <typename BaseVecT>
52 class NodeData
53 {
54  static boost::timer::cpu_timer itimer;
55  static boost::timer::cpu_timer otimer;
56  static bool timer_init;
57 
58  // Iterator
59  class Iterator;
60 
61  public:
67  NodeData(size_t bufferSize);
73  NodeData(NodeData& origin);
74 
80  NodeData& operator=(NodeData& origin);
81 
86  void open(string path);
87 
92  const string& getDataPath() const { return m_dataPath; }
93 
98  const string getFolder() const { return to_string(c_tstamp).insert(0, "node-"); }
99 
104  Iterator begin();
105 
110  Iterator end();
111 
115  void remove();
116 
121  void remove(unsigned int i);
122 
127  void add(BaseVecT input);
128 
129  void addNormal(BaseVecT input);
130 
135  void addBuffered(BaseVecT input);
136 
137  void addBufferedNormal(BaseVecT input);
138 
142  void writeBuffer();
143 
148  size_t getMaxWriteBufferSize();
153  BaseVecT get(int);
154 
155  BaseVecT getNormal(int);
160  BaseVecT next();
161 
166  size_t size();
167 
172  size_t getBufferSize();
173 
174  static void printTimer()
175  {
176  std::cout << "IO-Timer of Octree:" << std::endl
177  << "READ: " << itimer.format() << std::endl
178  << "WRITE: " << otimer.format() << std::endl;
179  }
180 
181  private:
182  // copys the data from origin to this
183  void copy(NodeData& origin);
184  // fills the buffer, copys from start_id to buffersize elements into buffer
185  void fillBuffer(size_t start_id);
186  void fillBufferNormal(size_t start_id);
187  // path to data
188  string m_dataPath;
189 
191  // if m_gotSize is set, the m_size will be used, else the size will be calculated
192  bool m_gotSize;
193  // amount of points stored in data
194  size_t m_size;
195  // current id of the dataobject, used to generate file name
196  int m_id;
197  // input buffer
198  vector<float> m_readBuffer;
199  // output buffer
200  vector<float> m_writeBuffer;
201 
202  vector<float> m_readBufferNormal;
203  // output buffer
204  vector<float> m_writeBufferNormal;
205 
206  // maximum buffer size
207  size_t m_bufferSize;
208  // current inputbuffer position
210 
212  // last id
213  static int c_last_id;
214  // timestamp, of first creation
215  static time_t c_tstamp;
216 };
217 
221 template <typename BaseVecT>
222 class NodeData<BaseVecT>::Iterator
223 {
224  public:
225  Iterator(NodeData& nodeData, size_t pos) : m_NodeData(nodeData), m_pos(pos) {}
226  Iterator(NodeData& nodeData) : m_NodeData(nodeData), m_pos(0) {}
227  Iterator(const Iterator& copy) : m_pos(copy.m_pos), m_NodeData(copy.m_NodeData) {}
228 
230  {
231  Iterator tmp(*this);
232  operator++();
233  return tmp;
234  }
235 
236  bool operator==(const Iterator& rhs) { return m_pos == rhs.m_pos; }
237  bool operator!=(const Iterator& rhs) { return m_pos != rhs.m_pos; }
238  // Todo: more if needed
239  void operator+(int i) { m_pos += i; }
240  void operator-(int i) { m_pos -= i; }
241  void operator++() { ++m_pos; }
242  void operator--() { --m_pos; }
243 
244  BaseVecT operator*() { return m_NodeData.get(m_pos); }
245  BaseVecT operator->() { return m_NodeData.get(m_pos); }
246 
247  private:
249  size_t m_pos;
250 };
251 
252 } // namespace lvr2
253 
254 #include "NodeData.tcc"
255 
256 #endif // LAS_VEGAS_NODEDATA_H
vector< float > m_readBufferNormal
Definition: NodeData.hpp:202
string m_dataPathNormal
Definition: NodeData.hpp:190
static void printTimer()
Definition: NodeData.hpp:174
size_t m_readBufferIndexNormal
Definition: NodeData.hpp:211
Iterator operator++(int)
Definition: NodeData.hpp:229
static time_t c_tstamp
Definition: NodeData.hpp:215
size_t m_bufferSize
Definition: NodeData.hpp:207
NodeData< BaseVecT > & m_NodeData
Definition: NodeData.hpp:248
const string & getDataPath() const
Definition: NodeData.hpp:92
size_t m_readBufferIndex
Definition: NodeData.hpp:209
static boost::timer::cpu_timer itimer
Definition: NodeData.hpp:54
vector< float > m_writeBuffer
Definition: NodeData.hpp:200
Iterator(const Iterator &copy)
Definition: NodeData.hpp:227
bool operator==(const Iterator &rhs)
Definition: NodeData.hpp:236
vector< float > m_writeBufferNormal
Definition: NodeData.hpp:204
string m_dataPath
Definition: NodeData.hpp:188
vector< float > m_readBuffer
Definition: NodeData.hpp:198
Iterator(NodeData &nodeData, size_t pos)
Definition: NodeData.hpp:225
static boost::timer::cpu_timer otimer
Definition: NodeData.hpp:55
Iterator(NodeData &nodeData)
Definition: NodeData.hpp:226
static bool timer_init
Definition: NodeData.hpp:56
static int c_last_id
Definition: NodeData.hpp:213
std::shared_ptr< HighFive::File > open(const std::string &filename)
Definition: Hdf5Util.cpp:202
const string getFolder() const
Definition: NodeData.hpp:98
bool operator!=(const Iterator &rhs)
Definition: NodeData.hpp:237


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:08