ScanProjectSchemaHyperlib.cpp
Go to the documentation of this file.
1 #include <sstream>
2 #include <iomanip>
3 
6 #include "lvr2/io/IOUtils.hpp"
7 #include "lvr2/io/yaml/Scan.hpp"
13 
14 namespace lvr2
15 {
16 
18 {
19  Description d;
20  d.groupName = boost::none; // All scan related data is stored in the "raw" group
21  d.dataSetName = boost::none; // No dataset name for project root
22  d.metaName = "meta.yaml";
23  d.metaData = boost::none;
24 
25  boost::filesystem::path metaPath(*d.metaName);
26  try
27  {
28  d.metaData = YAML::LoadFile(metaPath.string());
29  }
30  catch(const YAML::BadFile& e)
31  {
32  // Nothing to do, meta node will contain default values
33  YAML::Node node;
34  node = ScanProject();
35  d.metaData = node;
36  }
37 
38  return d;
39 }
40 
41 Description ScanProjectSchemaHyperlib::position(const size_t &scanPosNo) const
42 {
43  Description d;
44 
45  // Save scan file name
46  std::stringstream sstr;
47  sstr << std::setfill('0') << std::setw(8) << scanPosNo;
48 
49  d.dataSetName = boost::none;
50  d.metaName = "meta.yaml";
51  d.metaData = boost::none;
52 
53  // Load meta data
54  boost::filesystem::path positionPath(sstr.str());
55  boost::filesystem::path metaPath(*d.metaName);
56 
57  d.groupName = (positionPath).string();
58 
59  try
60  {
61  d.metaData = YAML::LoadFile( (positionPath / metaPath).string());
62  }
63  catch(YAML::BadFile& e)
64  {
65  // Nothing to do, meta node will contail default values
66  YAML::Node node;
67  node = ScanPosition();
68  d.metaData = node;
69  }
70 
71  return d;
72 }
73 
74 Description ScanProjectSchemaHyperlib::scan(const size_t &scanPosNo, const size_t &scanNo) const
75 {
76  // Get information about scan the associated scan position
77  Description d = position(scanPosNo);
78  return scan(*d.groupName, scanNo);
79 }
80 
81 Description ScanProjectSchemaHyperlib::scan(const std::string &scanPositionPath, const size_t &scanNo) const
82 {
83 
84  Description d;
85  boost::filesystem::path groupPath(scanPositionPath);
86  boost::filesystem::path scansPath("scans");
87  boost::filesystem::path dataPath("data");
88  boost::filesystem::path totalGroupPath = groupPath / scansPath / dataPath;
89  d.groupName = totalGroupPath.string();
90 
91  // Create dataset path
92  std::stringstream sstr;
93  sstr << "scan" << std::setfill('0') << std::setw(8) << scanNo;
94  d.dataSetName = sstr.str() + std::string(".ply");
95 
96  // Load meta data for scan
97  boost::filesystem::path metaPath(sstr.str() + ".yaml");
98  d.metaData = boost::none;
99  try
100  {
101  d.metaData = YAML::LoadFile((totalGroupPath / metaPath).string());
102  }
103  catch(YAML::BadFile& e)
104  {
105  // Nothing to do, meta node will contail default values
106  YAML::Node node;
107  node = Scan();
108  d.metaData = node;
109  }
110 
111  d.metaName = metaPath.string();
112  d.groupName = totalGroupPath.string();
113  return d;
114 }
115 
116 Description ScanProjectSchemaHyperlib::scanCamera(const size_t &scanPositionNo, const size_t &camNo) const
117 {
118  Description g = position(scanPositionNo);
119  return scanCamera(*g.groupName, camNo);
120 }
121 
122 Description ScanProjectSchemaHyperlib::scanCamera(const std::string &scanPositionPath, const size_t &camNo) const
123 {
124  Description d;
125 
126  // Construct group path
127  std::stringstream sstr;
128  sstr << "cam_" << camNo;
129 
130  boost::filesystem::path groupPath(scanPositionPath);
131  boost::filesystem::path camPath(sstr.str());
132  d.groupName = (groupPath / camPath).string();
133 
134  // No data set information for camera position
135  d.dataSetName = boost::none;
136  d.metaName = "meta.yaml";
137 
138  boost::filesystem::path metaPath(*d.metaName);
139 
140  // Load camera information from yaml
141  d.metaData = boost::none;
142  try
143  {
144  d.metaData = YAML::LoadFile( (groupPath / camPath / metaPath).string());
145  }
146  catch(const YAML::BadFile& e)
147  {
148  // Nothing to do, meta node will contail default values
149  YAML::Node node;
150  node = ScanCamera();
151  d.metaData = node;
152  }
153 
154 
155 
156  return d;
157 }
158 
160  const size_t &scanPosNo, const size_t &scanNo,
161  const size_t &scanCameraNo, const size_t &scanImageNo) const
162 {
163  // Scan images are not supported
164  Description d_cam = scanCamera(scanPosNo, scanCameraNo);
165  return scanImage(*d_cam.groupName, scanImageNo);
166 }
167 
169  const std::string &scanImagePath, const size_t &scanImageNo) const
170 {
171  Description d;
172 
173  boost::filesystem::path siPath(scanImagePath);
174  boost::filesystem::path dPath("data");
175 
176  std::stringstream sstr;
177  sstr << std::setfill('0') << std::setw(8) << scanImageNo;
178 
179  std::string imgName(sstr.str() + std::string(".png"));
180  std::string yamlName(sstr.str() + std::string(".yaml"));
181 
182  boost::filesystem::path metaPath(yamlName);
183 
184  d.groupName = (siPath / dPath).string();
185  d.dataSetName = imgName;
186  d.metaName = yamlName;
187  d.metaData = boost::none;
188 
189  try
190  {
191  d.metaData = YAML::LoadFile((siPath / dPath / metaPath).string());
192  }
193  catch(YAML::BadFile& e)
194  {
195  // Nothing to do, meta node will contail default values
196  YAML::Node node;
197  node = ScanImage();
198  d.metaData = node;
199  }
200 
201 
202  return d;
203 }
204 
205 } // namespace lvr2
lvr2::Description::dataSetName
StringOptional dataSetName
Definition: ScanProjectSchema.hpp:19
ScanProject.hpp
ScanPosition.hpp
lvr2::ScanProjectSchemaHyperlib::scanProject
virtual Description scanProject() const
Definition: ScanProjectSchemaHyperlib.cpp:17
lvr2::ScanProjectSchemaHyperlib::scanCamera
virtual Description scanCamera(const size_t &scanPositionNo, const size_t &camNo) const
Definition: ScanProjectSchemaHyperlib.cpp:116
IOUtils.hpp
lvr2::ScanProjectSchemaHyperlib::position
virtual Description position(const size_t &scanPosNo) const
Definition: ScanProjectSchemaHyperlib.cpp:41
ScanImage.hpp
ScanTypes.hpp
lvr2::ScanProjectSchemaHyperlib::scan
virtual Description scan(const size_t &scanPosNo, const size_t &scanNo) const
Definition: ScanProjectSchemaHyperlib.cpp:74
lvr2::Scan
Definition: ScanTypes.hpp:24
lvr2::ScanPosition
Definition: ScanTypes.hpp:276
lvr2::ScanCamera
Definition: ScanTypes.hpp:138
lvr2::ScanImage
Definition: ScanTypes.hpp:107
lvr2::ScanProject
Definition: ScanTypes.hpp:322
ScanProjectSchemaHyperlib.hpp
MatrixIO.hpp
lvr2::Description::groupName
StringOptional groupName
Definition: ScanProjectSchema.hpp:18
lvr2
Definition: BaseBufferManipulators.hpp:39
Scan.hpp
ScanCamera.hpp
lvr2::Description
Definition: ScanProjectSchema.hpp:16
lvr2::ScanProjectSchemaHyperlib::scanImage
virtual Description scanImage(const size_t &scanPosNo, const size_t &scanNo, const size_t &scanCameraNo, const size_t &scanImageNo) const
Definition: ScanProjectSchemaHyperlib.cpp:159
lvr2::Description::metaData
NodeOptional metaData
Definition: ScanProjectSchema.hpp:21
lvr2::Description::metaName
StringOptional metaName
Definition: ScanProjectSchema.hpp:20


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