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 {
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();
60  m_previewReductionFactor = options.getPreviewReductionRatio();
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 }
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
lvr2::Hdf5IO
Manager Class for all Hdf5IO components located in hdf5 directory.
Definition: HDF5FeatureBase.hpp:38
m_usePreviews
bool m_usePreviews
Definition: src/tools/lvr2_hdf5_builder_2/Main.cpp:20
m_previewReductionFactor
int m_previewReductionFactor
Definition: src/tools/lvr2_hdf5_builder_2/Main.cpp:21
kaboom::Options::getInputDir
string getInputDir() const
Definition: src/tools/lvr2_kaboom/Options.cpp:98
main
int main(int argc, char **argv)
Definition: src/tools/lvr2_hdf5_builder_2/Main.cpp:51
lvr2::ScanProjectPtr
std::shared_ptr< ScanProject > ScanProjectPtr
Definition: ScanTypes.hpp:344
ScanProjectIO.hpp
IOUtils.hpp
hdf5tool2::Options
A class to parse the program options for the reconstruction executable.
Definition: src/tools/lvr2_hdf5_builder_2/Options.hpp:58
ScanIOUtils.hpp
ScanTypes.hpp
options
const kaboom::Options * options
Definition: src/tools/lvr2_kaboom/Main.cpp:45
Options.hpp
kaboom::Options::getOutputFile
string getOutputFile() const
Definition: src/tools/lvr2_kaboom/Options.cpp:88
lvr2::ScanPositionPtr
std::shared_ptr< ScanPosition > ScanPositionPtr
Definition: ScanTypes.hpp:311
lvr2::HDF5IO::open
bool open(std::string filename, int open_flag)
Definition: HDF5IO.cpp:232
lvr2::timestamp
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
lvr2::ScanProject
Definition: ScanTypes.hpp:322
HDF5FeatureBase.hpp
argc
int argc
Definition: tests_high_five_parallel.cpp:27
lvr2::loadScanProject
bool loadScanProject(const boost::filesystem::path &root, ScanProject &scanProj)
Definition: ScanIOUtils.cpp:1083
reduceData
boost::shared_array< T > reduceData(boost::shared_array< T > data, size_t dataCount, size_t dataWidth, unsigned int reductionFactor, size_t *reducedDataCount)
Definition: src/tools/lvr2_hdf5_builder_2/Main.cpp:24
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::Hdf5IO::AddFeatures
typename add_features_with_deps< F... >::type AddFeatures
Definition: HDF5FeatureBase.hpp:120
lvr2::HDF5IO
Definition: descriptions/HDF5IO.hpp:13
Timestamp.hpp
uint
unsigned int uint
Definition: Model.hpp:46
kaboom::Options::getOutputDir
string getOutputDir() const
Definition: src/tools/lvr2_kaboom/Options.cpp:103
BoundingBox.hpp
lvr2::HDF5IO::save
virtual void save(std::string filename)
Save the loaded elements to the given file.
Definition: HDF5IO.cpp:282
argv
char ** argv
Definition: tests_high_five_parallel.cpp:28
lvr2::HDF5IO::loadScanProject
ScanProjectPtr loadScanProject()
Definition: descriptions/HDF5IO.cpp:21
lvr2::ScanPtr
std::shared_ptr< Scan > ScanPtr
Shared pointer to scans.
Definition: ScanTypes.hpp:98


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