DirectoryKernel.cpp
Go to the documentation of this file.
2 
3 namespace lvr2
4 {
5 
7  const std::string &group,
8  const std::string &container,
9  const MeshBufferPtr &buffer) const
10 {
11  boost::filesystem::path p = getAbsolutePath(group, container);
12  if(!boost::filesystem::exists(p.parent_path()))
13  {
14  boost::filesystem::create_directories(p.parent_path());
15  }
16 
17  ModelPtr model(new Model);
18  model->m_mesh = buffer;
19  std::cout << timestamp << "Directory Kernel::saveMeshBuffer(): " << p.string() << std::endl;
20  ModelFactory::saveModel(model, p.string());
21 }
22 
24  const std::string &group,
25  const std::string &container,
26  const PointBufferPtr &buffer) const
27 {
28  boost::filesystem::path p = getAbsolutePath(group, container);
29  if(!boost::filesystem::exists(p.parent_path()))
30  {
31  boost::filesystem::create_directories(p.parent_path());
32  }
33  ModelPtr model(new Model);
34  model->m_pointCloud = buffer;
35  std::cout << timestamp << "Directory Kernel::savePointBuffer(): " << p.string() << std::endl;
36  ModelFactory::saveModel(model, p.string());
37 }
38 
40  const std::string &group,
41  const std::string &container,
42  const cv::Mat &image) const
43 {
44  boost::filesystem::path p = getAbsolutePath(group, container);
45  if(!boost::filesystem::exists(p.parent_path()))
46  {
47  boost::filesystem::create_directories(p.parent_path());
48  }
49  std::cout << timestamp << "Directory Kernel::saveImage(): " << p.string() << std::endl;
50 
51  cv::imwrite(p.string(), image);
52 }
53 
55  const std::string &group,
56  const std::string &container,
57  const YAML::Node &node) const
58 {
59  boost::filesystem::path p = getAbsolutePath(group, container);
60  if(!boost::filesystem::exists(p.parent_path()))
61  {
62  boost::filesystem::create_directories(p.parent_path());
63  }
64  std::cout << timestamp << "Directory Kernel::saveMetaYAML(): " << p.string() << std::endl;
65  saveMetaInformation(p.string(), node);
66 }
67 
68 
69 
71  const std::string &group,
72  const std::string container) const
73 {
74  boost::filesystem::path p = getAbsolutePath(group, container);
75  std::cout << timestamp << "Directory Kernel::loadMeshBuffer(): " << p.string() << std::endl;
76  ModelPtr model = ModelFactory::readModel(p.string());
77  if (model)
78  {
79  return model->m_mesh;
80  }
81 }
82 
84  const std::string &group,
85  const std::string &container) const
86 {
87  boost::filesystem::path p = getAbsolutePath(group, container);
88  std::cout << timestamp << "Directory Kernel::loadPointBuffer(): " << p.string() << std::endl;
89  ModelPtr model = ModelFactory::readModel(p.string());
90  if (model)
91  {
92  std::cout << model->m_pointCloud << std::endl;
93  std::cout << model->m_pointCloud->numPoints() << std::endl;
94  return model->m_pointCloud;
95  }
96 }
97 
98 boost::optional<cv::Mat> DirectoryKernel::loadImage(
99  const std::string &group,
100  const std::string &container) const
101 {
102  boost::filesystem::path p = getAbsolutePath(group, container);
103  boost::optional<cv::Mat> opt;
104  std::cout << timestamp << "Directory Kernel::loadImage: " << p.string() << std::endl;
105  if(boost::filesystem::exists(p))
106  {
107  opt = cv::imread(p.string());
108 
109  }
110  else
111  {
112  opt = boost::none;
113  }
114  return opt;
115 }
116 
118  const std::string &group,
119  const std::string &container,
120  YAML::Node& n) const
121 {
122  boost::filesystem::path p = getAbsolutePath(group, container);
123  std::cout << timestamp << "Directory Kernel::loadMetaYAML: " << p.string() << std::endl;
124  YAML::Node node = loadMetaInformation(p.string());
125  n = node;
126 }
127 
128 bool DirectoryKernel::exists(const std::string &group) const
129 {
130  return boost::filesystem::exists(getAbsolutePath(group, ""));
131 }
132 bool DirectoryKernel::exists(const std::string &group, const std::string &container) const
133 {
134  // Check if container is not empty to prevent checking
135  // against the root itself
136  if(container != "")
137  {
138  return boost::filesystem::exists(getAbsolutePath(group, container));
139  }
140  return false;
141 }
142 
143 void DirectoryKernel::subGroupNames(const std::string &group, std::vector<string> &subGroupNames) const
144 {
145  boost::filesystem::path groupPath(getAbsolutePath(group, ""));
146  boost::filesystem::directory_iterator it(groupPath);
147  while (it != boost::filesystem::directory_iterator{})
148  {
149  if (boost::filesystem::is_directory(*it))
150  {
151  subGroupNames.push_back(it->path().string());
152  }
153  }
154 }
155 
156 void DirectoryKernel::subGroupNames(const std::string &group, const std::regex &filter, std::vector<string> &subGroupNames) const
157 {
158  boost::filesystem::path groupPath(getAbsolutePath(group, ""));
159  boost::filesystem::directory_iterator it(groupPath);
160  while (it != boost::filesystem::directory_iterator{})
161  {
162  if (boost::filesystem::is_directory(*it))
163  {
164  std::string currentName = it->path().string();
165  if (std::regex_match(currentName, filter))
166  {
167  subGroupNames.push_back(currentName);
168  }
169  }
170  }
171 }
172 
173 boost::filesystem::path DirectoryKernel::getAbsolutePath(const std::string &group, const std::string &name) const
174 {
175  boost::filesystem::path groupPath(group);
176  boost::filesystem::path namePath(name);
177  boost::filesystem::path rootPath(m_fileResourceName);
178  boost::filesystem::path ret = rootPath / groupPath / namePath;
179  return ret;
180 }
181 
182 
183 
184 ucharArr DirectoryKernel::loadUCharArray(const std::string& group, const std::string& container, std::vector<size_t>& dims) const
185 {
186  return loadArray<unsigned char>(group, container, dims);
187 }
188 
189 floatArr DirectoryKernel::loadFloatArray(const std::string& group, const std::string& container, std::vector<size_t>& dims) const
190 {
191  return loadArray<float>(group, container, dims);
192 }
193 
194 doubleArr DirectoryKernel::loadDoubleArray(const std::string& group, const std::string& container, std::vector<size_t>& dims) const
195 {
196  return loadArray<double>(group, container, dims);
197 }
198 
199 void DirectoryKernel::saveFloatArray(const std::string& groupName, const std::string& datasetName, const std::vector<size_t>& dimensions, const boost::shared_array<float>& data) const
200 {
201  saveArray<float>(groupName, datasetName, dimensions, data);
202 }
203 
204 void DirectoryKernel::saveDoubleArray(const std::string& groupName, const std::string& datasetName, const std::vector<size_t>& dimensions, const boost::shared_array<double>& data) const
205 {
206  saveArray<double>(groupName, datasetName, dimensions, data);
207 }
208 
209 void DirectoryKernel::saveUCharArray(const std::string& groupName, const std::string& datasetName, const std::vector<size_t>& dimensions, const boost::shared_array<unsigned char>& data) const
210 {
211  saveArray<unsigned char>(groupName, datasetName, dimensions, data);
212 }
213 
214 } // namespace lvr2
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
lvr2::ModelFactory::saveModel
static void saveModel(ModelPtr m, std::string file)
Definition: ModelFactory.cpp:225
lvr2::DirectoryKernel::loadMetaYAML
virtual void loadMetaYAML(const std::string &group, const std::string &container, YAML::Node &node) const
Definition: DirectoryKernel.cpp:117
lvr2::loadMetaInformation
YAML::Node loadMetaInformation(const std::string &in)
Definition: MetaFormatFactory.cpp:54
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::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
p
SharedPointer p
Definition: ConvertShared.hpp:42
DirectoryKernel.hpp
lvr2::Model
Definition: Model.hpp:51
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::saveMetaInformation
void saveMetaInformation(const std::string &outfile, const YAML::Node &node)
Definition: MetaFormatFactory.cpp:6
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
filter
void filter(lvr2::PointBufferPtr &cloud, lvr2::indexArray &inlier, size_t j)
Definition: src/tools/lvr2_cl_sor/Main.cpp:40
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::ModelPtr
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
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
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
lvr2::FileKernel::m_fileResourceName
std::string m_fileResourceName
Definition: FileKernel.hpp:107
lvr2::ModelFactory::readModel
static ModelPtr readModel(std::string filename)
Definition: ModelFactory.cpp:65
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
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