src/tools/lvr2_hdf5_builder_2/Main.cpp
Go to the documentation of this file.
1 #include "Options.hpp"
3 #include "lvr2/io/IOUtils.hpp"
5 #include "lvr2/io/Timestamp.hpp"
9 
10 #include <boost/filesystem.hpp>
11 
12 using namespace lvr2;
13 
15 
16 // Extend IO with features (dependencies are automatically fetched)
17 using HDF5IO =
19 
22 
23 template <typename T>
24 boost::shared_array<T> reduceData(boost::shared_array<T> data,
25  size_t dataCount,
26  size_t dataWidth,
27  unsigned int reductionFactor,
28  size_t* reducedDataCount)
29 {
30  *reducedDataCount = dataCount / reductionFactor + 1;
31 
32  boost::shared_array<T> reducedData =
33  boost::shared_array<T>(new T[(*reducedDataCount) * dataWidth]);
34 
35  size_t reducedDataIdx = 0;
36  for (size_t i = 0; i < dataCount; i++)
37  {
38  if (i % reductionFactor == 0)
39  {
40  std::copy(data.get() + i * dataWidth,
41  data.get() + (i + 1) * dataWidth,
42  reducedData.get() + reducedDataIdx * dataWidth);
43 
44  reducedDataIdx++;
45  }
46  }
47 
48  return reducedData;
49 }
50 
51 int main(int argc, char** argv)
52 {
53  hdf5tool2::Options options(argc, argv);
54  boost::filesystem::path inputDir(options.getInputDir());
55  boost::filesystem::path outputDir(options.getOutputDir());
56 
57  boost::filesystem::path outputPath(outputDir / options.getOutputFile());
58 
59  m_usePreviews = options.getPreview();
61 
62  HDF5IO hdf;
63  uint pos = 0;
64 
65  // check if input directory exists
66  if (!boost::filesystem::exists(inputDir))
67  {
68  std::cout << timestamp << "Error: Directory " << options.getInputDir() << " does not exist"
69  << std::endl;
70  exit(-1);
71  }
72 
73  // check if output directory exists
74  if (!boost::filesystem::exists(outputDir))
75  {
76  std::cout << timestamp << "Creating directory " << options.getOutputDir() << std::endl;
77  if (!boost::filesystem::create_directory(outputDir))
78  {
79  std::cout << timestamp << "Error: Unable to create " << options.getOutputDir()
80  << std::endl;
81  exit(-1);
82  }
83  }
84 
85  bool exitsts = false;
86  ScanProjectPtr existingScanProject;
87 
88  // check if HDF5 already exists
89  if (boost::filesystem::exists(outputPath))
90  {
91  std::cout << timestamp << "File already exists. Expanding File..." << std::endl;
92 
93  // get existing scans
94  hdf.open(outputPath.string());
95  existingScanProject = hdf.loadScanProject();
96  exitsts = true;
97  }
98  else
99  {
100  hdf.open(outputPath.string());
101  }
102 
103  ScanProjectPtr scanProject(new ScanProject());
104 
105  // reading scan project from given directory into ScanProject
106  std::cout << timestamp << "Reading ScanProject from directory" << std::endl;
107  loadScanProject(inputDir, *scanProject);
108 
109  // saving ScanProject into HDF5 file
110  std::cout << timestamp << "Writing ScanProject to HDF5" << std::endl;
111  if (exitsts)
112  {
113  for (ScanPositionPtr scanPosPtr : scanProject->positions)
114  {
115  existingScanProject->positions.push_back(scanPosPtr);
116  }
117  hdf.save(existingScanProject);
118  }
119  else
120  {
121  hdf.save(scanProject);
122  }
123 
124  if (m_usePreviews)
125  {
126  for (int i = 0; i < scanProject->positions.size(); i++)
127  {
128  char buffer[128];
129  sprintf(buffer, "%08d", i);
130  string nr_str(buffer);
131  std::string previewGroupName = "/preview/" + nr_str;
132 
133  std::cout << timestamp << "Generating preview for position " << nr_str << std::endl;
134 
135  ScanPositionPtr scanPositionPtr = scanProject->positions[i];
136 
137  ScanPtr scanPtr = scanPositionPtr->scans[0];
138  floatArr points = scanPtr->points->getPointArray();
139 
140  if (points)
141  {
142  size_t numPreview;
143  floatArr previewData = reduceData(points,
144  scanPtr->points->numPoints(),
145  3,
147  &numPreview);
148 
149  std::vector<size_t> previewDim = {numPreview, 3};
150  hdf.save<float>(previewGroupName, "points", previewDim, previewData);
151  }
152  }
153  }
154 
155  std::cout << timestamp << "Program finished" << std::endl;
156 }
virtual void save(std::string filename)
Save the loaded elements to the given file.
Definition: HDF5IO.cpp:282
const kaboom::Options * options
ScanProjectPtr loadScanProject()
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
typename add_features_with_deps< F... >::type AddFeatures
std::shared_ptr< Scan > ScanPtr
Shared pointer to scans.
Definition: ScanTypes.hpp:98
int main(int argc, char **argv)
Manager Class for all Hdf5IO components located in hdf5 directory.
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
std::shared_ptr< ScanProject > ScanProjectPtr
Definition: ScanTypes.hpp:344
A class to parse the program options for the reconstruction executable.
unsigned int uint
Definition: Model.hpp:46
bool loadScanProject(const boost::filesystem::path &root, ScanProject &scanProj)
bool open(std::string filename, int open_flag)
Definition: HDF5IO.cpp:232
boost::shared_array< T > reduceData(boost::shared_array< T > data, size_t dataCount, size_t dataWidth, unsigned int reductionFactor, size_t *reducedDataCount)
std::shared_ptr< ScanPosition > ScanPositionPtr
Definition: ScanTypes.hpp:311
char ** argv


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