DirectoryKernel.hpp
Go to the documentation of this file.
1 #ifndef DIRECTORY_KERNEL_HPP
2 #define DIRECTORY_KERNEL_HPP
3 
4 #include <boost/filesystem.hpp>
5 #include <iostream>
6 #include <regex>
7 
10 #include "lvr2/io/ModelFactory.hpp"
11 #include "lvr2/io/Timestamp.hpp"
12 
13 namespace lvr2
14 {
15 
17 {
18 public:
19  DirectoryKernel(const std::string &root) : FileKernel(root){};
20  virtual ~DirectoryKernel() = default;
21 
22  virtual void saveMeshBuffer(
23  const std::string& group,
24  const std::string& container,
25  const MeshBufferPtr& buffer) const;
26 
27  virtual void savePointBuffer(
28  const std::string& group,
29  const std::string& container,
30  const PointBufferPtr& buffer) const;
31 
32  virtual void saveImage(
33  const std::string& group,
34  const std::string& container,
35  const cv::Mat& image) const;
36 
37  virtual void saveMetaYAML(
38  const std::string& group,
39  const std::string& metaName,
40  const YAML::Node& node) const;
41 
43  const std::string& group,
44  const std::string container) const;
45 
47  const std::string& group,
48  const std::string& container) const;
49 
50  virtual boost::optional<cv::Mat> loadImage(
51  const std::string& group,
52  const std::string& container) const;
53 
54  virtual void loadMetaYAML(
55  const std::string& group,
56  const std::string& container,
57  YAML::Node& node) const;
58 
59  virtual ucharArr loadUCharArray(
60  const std::string& group,
61  const std::string& container,
62  std::vector<size_t> &dims) const;
63 
64  virtual floatArr loadFloatArray(
65  const std::string& group,
66  const std::string& container,
67  std::vector<size_t> &dims) const;
68 
69  virtual doubleArr loadDoubleArray(
70  const std::string& group,
71  const std::string& container,
72  std::vector<size_t> &dims) const;
73 
74  virtual void saveFloatArray(
75  const std::string& groupName,
76  const std::string& datasetName,
77  const std::vector<size_t>& dimensions,
78  const boost::shared_array<float>& data) const;
79 
80  virtual void saveDoubleArray(
81  const std::string& groupName, const std::string& datasetName,
82  const std::vector<size_t>& dimensions,
83  const boost::shared_array<double>& data) const;
84 
85  virtual void saveUCharArray(
86  const std::string& groupName, const std::string& datasetName,
87  const std::vector<size_t>& dimensions,
88  const boost::shared_array<unsigned char>& data) const;
89 
90  virtual bool exists(const std::string& group) const;
91  virtual bool exists(const std::string& group, const std::string& container) const;
92 
93  virtual void subGroupNames(const std::string& group, std::vector<string>& subGroupNames) const;
94  virtual void subGroupNames(const std::string& group, const std::regex& filter, std::vector<string>& subGroupNames) const;
95 
96 protected:
97  template <typename T>
98  boost::shared_array<T> loadArray(const std::string &group, const std::string &constainer, std::vector<size_t> &dims) const
99  {
100  if (dims.size() > 0)
101  {
102  size_t length = dims[0];
103  for (size_t i = 1; i < dims.size(); i++)
104  {
105  if (dims[i] != 0)
106  {
107  length *= dims[i];
108  }
109  else
110  {
111  std::cout << timestamp << "Warning: DirectoryKernel::LoadArray(): Found zero dim: " << i << std::endl;
112  }
113  }
114  T *data = new T[length];
115  std::ifstream in;
116  for (size_t i = 0; i < length; i++)
117  {
118  in >> data[i];
119  }
120  return boost::shared_array<T>(data);
121  }
122  return boost::shared_array<T>(nullptr);
123  }
124 
125  template <typename T>
126  void saveArray(
127  const std::string &group, const std::string &container,
128  const std::vector<size_t> &dims, const boost::shared_array<T>& data) const
129  {
130  if (dims.size() > 0)
131  {
132  size_t length = dims[0];
133  for (size_t i = 1; i < dims.size(); i++)
134  {
135  if (dims[i] != 0)
136  {
137  length *= dims[i];
138  }
139  else
140  {
141  std::cout << timestamp << "Warning: DirectoryKernel::SaveArray(): Found zero dim: " << i << std::endl;
142  }
143  }
144 
145  std::ofstream out;
146  for (size_t i = 0; i < length; i++)
147  {
148  out << data[i];
149  }
150  }
151  }
152 
153  boost::filesystem::path getAbsolutePath(const std::string &group, const std::string &name) const;
154 };
155 
156 using DirectoryKernelPtr = std::shared_ptr<DirectoryKernel>;
157 
158 } // namespace lvr2
159 
160 #endif
virtual void saveFloatArray(const std::string &groupName, const std::string &datasetName, const std::vector< size_t > &dimensions, const boost::shared_array< float > &data) const
virtual ucharArr loadUCharArray(const std::string &group, const std::string &container, std::vector< size_t > &dims) const
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
virtual doubleArr loadDoubleArray(const std::string &group, const std::string &container, std::vector< size_t > &dims) const
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
boost::shared_array< double > doubleArr
Definition: DataStruct.hpp:134
boost::filesystem::path getAbsolutePath(const std::string &group, const std::string &name) const
boost::shared_array< T > loadArray(const std::string &group, const std::string &constainer, std::vector< size_t > &dims) const
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
virtual void savePointBuffer(const std::string &group, const std::string &container, const PointBufferPtr &buffer) const
std::shared_ptr< PointBuffer > PointBufferPtr
virtual void saveMeshBuffer(const std::string &group, const std::string &container, const MeshBufferPtr &buffer) const
virtual void saveMetaYAML(const std::string &group, const std::string &metaName, const YAML::Node &node) const
DirectoryKernel(const std::string &root)
virtual void subGroupNames(const std::string &group, std::vector< string > &subGroupNames) const
virtual void saveImage(const std::string &group, const std::string &container, const cv::Mat &image) const
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
virtual void loadMetaYAML(const std::string &group, const std::string &container, YAML::Node &node) const
virtual PointBufferPtr loadPointBuffer(const std::string &group, const std::string &container) const
void saveArray(const std::string &group, const std::string &container, const std::vector< size_t > &dims, const boost::shared_array< T > &data) const
void filter(lvr2::PointBufferPtr &cloud, lvr2::indexArray &inlier, size_t j)
virtual bool exists(const std::string &group) const
virtual void saveUCharArray(const std::string &groupName, const std::string &datasetName, const std::vector< size_t > &dimensions, const boost::shared_array< unsigned char > &data) const
virtual floatArr loadFloatArray(const std::string &group, const std::string &container, std::vector< size_t > &dims) const
std::shared_ptr< DirectoryKernel > DirectoryKernelPtr
virtual ~DirectoryKernel()=default
virtual void saveDoubleArray(const std::string &groupName, const std::string &datasetName, const std::vector< size_t > &dimensions, const boost::shared_array< double > &data) const
virtual MeshBufferPtr loadMeshBuffer(const std::string &group, const std::string container) const
virtual boost::optional< cv::Mat > loadImage(const std::string &group, const std::string &container) const


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:06