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
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
lvr2::DirectoryKernel::loadMetaYAML
virtual void loadMetaYAML(const std::string &group, const std::string &container, YAML::Node &node) const
Definition: DirectoryKernel.cpp:117
lvr2::DirectoryKernel::loadUCharArray
virtual ucharArr loadUCharArray(const std::string &group, const std::string &container, std::vector< size_t > &dims) const
Definition: DirectoryKernel.cpp:184
lvr2::DirectoryKernel::~DirectoryKernel
virtual ~DirectoryKernel()=default
lvr2::DirectoryKernel::DirectoryKernel
DirectoryKernel(const std::string &root)
Definition: DirectoryKernel.hpp:19
lvr2::DirectoryKernel::subGroupNames
virtual void subGroupNames(const std::string &group, std::vector< string > &subGroupNames) const
Definition: DirectoryKernel.cpp:143
lvr2::PointBufferPtr
std::shared_ptr< PointBuffer > PointBufferPtr
Definition: PointBuffer.hpp:130
lvr2::DirectoryKernel::saveMeshBuffer
virtual void saveMeshBuffer(const std::string &group, const std::string &container, const MeshBufferPtr &buffer) const
Definition: DirectoryKernel.cpp:6
lvr2::DirectoryKernel::saveDoubleArray
virtual void saveDoubleArray(const std::string &groupName, const std::string &datasetName, const std::vector< size_t > &dimensions, const boost::shared_array< double > &data) const
Definition: DirectoryKernel.cpp:204
lvr2::DirectoryKernel::saveUCharArray
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
Definition: DirectoryKernel.cpp:209
lvr2::DirectoryKernel::exists
virtual bool exists(const std::string &group) const
Definition: DirectoryKernel.cpp:128
lvr2::DirectoryKernel::loadImage
virtual boost::optional< cv::Mat > loadImage(const std::string &group, const std::string &container) const
Definition: DirectoryKernel.cpp:98
lvr2::DirectoryKernel::saveImage
virtual void saveImage(const std::string &group, const std::string &container, const cv::Mat &image) const
Definition: DirectoryKernel.cpp:39
lvr2::timestamp
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
lvr2::DirectoryKernel::getAbsolutePath
boost::filesystem::path getAbsolutePath(const std::string &group, const std::string &name) const
Definition: DirectoryKernel.cpp:173
lvr2::DirectoryKernel::saveMetaYAML
virtual void saveMetaYAML(const std::string &group, const std::string &metaName, const YAML::Node &node) const
Definition: DirectoryKernel.cpp:54
lvr2::DirectoryKernel::loadMeshBuffer
virtual MeshBufferPtr loadMeshBuffer(const std::string &group, const std::string container) const
Definition: DirectoryKernel.cpp:70
FileKernel.hpp
lvr2::DirectoryKernel
Definition: DirectoryKernel.hpp:16
lvr2::DirectoryKernel::saveArray
void saveArray(const std::string &group, const std::string &container, const std::vector< size_t > &dims, const boost::shared_array< T > &data) const
Definition: DirectoryKernel.hpp:126
MetaFormatFactory.hpp
filter
void filter(lvr2::PointBufferPtr &cloud, lvr2::indexArray &inlier, size_t j)
Definition: src/tools/lvr2_cl_sor/Main.cpp:40
lvr2::DirectoryKernel::loadArray
boost::shared_array< T > loadArray(const std::string &group, const std::string &constainer, std::vector< size_t > &dims) const
Definition: DirectoryKernel.hpp:98
lvr2::DirectoryKernel::loadFloatArray
virtual floatArr loadFloatArray(const std::string &group, const std::string &container, std::vector< size_t > &dims) const
Definition: DirectoryKernel.cpp:189
lvr2::ucharArr
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::DirectoryKernel::loadPointBuffer
virtual PointBufferPtr loadPointBuffer(const std::string &group, const std::string &container) const
Definition: DirectoryKernel.cpp:83
lvr2::MeshBufferPtr
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
Timestamp.hpp
lvr2::DirectoryKernel::loadDoubleArray
virtual doubleArr loadDoubleArray(const std::string &group, const std::string &container, std::vector< size_t > &dims) const
Definition: DirectoryKernel.cpp:194
lvr2::DirectoryKernel::savePointBuffer
virtual void savePointBuffer(const std::string &group, const std::string &container, const PointBufferPtr &buffer) const
Definition: DirectoryKernel.cpp:23
ModelFactory.hpp
lvr2::doubleArr
boost::shared_array< double > doubleArr
Definition: DataStruct.hpp:134
lvr2::DirectoryKernel::saveFloatArray
virtual void saveFloatArray(const std::string &groupName, const std::string &datasetName, const std::vector< size_t > &dimensions, const boost::shared_array< float > &data) const
Definition: DirectoryKernel.cpp:199
lvr2::FileKernel
Definition: FileKernel.hpp:20
lvr2::DirectoryKernelPtr
std::shared_ptr< DirectoryKernel > DirectoryKernelPtr
Definition: DirectoryKernel.hpp:156


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 Wed Mar 2 2022 00:37:23