src/tools/lvr2_dmc_reconstruction/Main.cpp
Go to the documentation of this file.
1 /*
2  * Main.cpp
3  *
4  * Created on: 16.05.2020
5  * Author: Benedikt Schumacher (bschumacher@uos.de)
6  */
7 
9 
10 #include "Options.hpp"
11 
15 #include "lvr2/io/MeshBuffer.hpp"
16 #include "lvr2/io/ModelFactory.hpp"
17 #include "lvr2/io/PointBuffer.hpp"
22 
24 
25 using namespace lvr2;
26 
28 
29 template <typename BaseVecT>
31 {
32  // Create a point loader object
34 
35  // Parse loaded data
36  if (!model)
37  {
38  cout << timestamp << "IO Error: Unable to parse " << options.getInputFileName() << endl;
39  return nullptr;
40  }
41 
42  PointBufferPtr buffer = model->m_pointCloud;
43 
44  // Create a point cloud manager
45  string pcm_name = options.getPCM();
47 
48  // Create point set surface object
49  if(pcm_name == "PCL")
50  {
51  cout << timestamp << "Using PCL as point cloud manager is not implemented yet!" << endl;
52  panic_unimplemented("PCL as point cloud manager");
53  }
54  else if(pcm_name == "STANN" || pcm_name == "FLANN" || pcm_name == "NABO" || pcm_name == "NANOFLANN")
55  {
56 
57  int plane_fit_method = 0;
58 
59  if(options.useRansac())
60  {
61  plane_fit_method = 1;
62  }
63 
64  // plane_fit_method
65  // - 0: PCA
66  // - 1: RANSAC
67  // - 2: Iterative
68 
69  surface = make_shared<AdaptiveKSearchSurface<BaseVecT>>(
70  buffer,
71  pcm_name,
72  options.getKn(),
73  options.getKi(),
74  options.getKd(),
75  plane_fit_method,
76  options.getScanPoseFile()
77  );
78  }
79  else
80  {
81  cout << timestamp << "Unable to create PointCloudManager." << endl;
82  cout << timestamp << "Unknown option '" << pcm_name << "'." << endl;
83  return nullptr;
84  }
85 
86  // Set search options for normal estimation and distance evaluation
87  surface->setKd(options.getKd());
88  surface->setKi(options.getKi());
89  surface->setKn(options.getKn());
90 
91  // calc normals if there are none
92  if (!buffer->hasNormals() && buffer.get()->numPoints() < 1000000)
93  {
94  surface->calculateSurfaceNormals();
95  }
96 
97  return surface;
98 }
99 
100 int main(int argc, char** argv)
101 {
102 
104 
105  options.printLogo();
106 
107  // if one of the needed parameters is missing,
108  if (options.printUsage())
109  {
110  return EXIT_SUCCESS;
111  }
112 
113  std::cout << options << std::endl;
114 
115 
116  // =======================================================================
117  // Set number of threads
118  // =======================================================================
120 
121  // Create a point cloud manager
122  string pcm_name = options.getPCM();
123  auto surface = loadPointCloud<Vec>(options);
124  if (!surface)
125  {
126  cout << "Failed to create pointcloud. Exiting." << endl;
127  return EXIT_FAILURE;
128  }
129 
131 
132  DMCReconstruction<Vec, FastBox<Vec>> dmc(surface, surface->getBoundingBox(), true, options.getMaxLevel(), options.getMaxError());
133 
134  dmc.getMesh(mesh);
135 
136  // Finalize mesh
138  auto meshBuffer = finalize.apply(mesh);
139 
140  auto m = ModelPtr(new Model(meshBuffer));
141  ModelFactory::saveModel(m, "triangle_mesh.ply");
142 
143  cout << timestamp << "Finished reconstruction" << endl;
144 
145  return 0;
146 }
HalfEdgeMesh< Vec > mesh
const kaboom::Options * options
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
static ModelPtr readModel(std::string filename)
static void setNumThreads(int n)
Sets the number of used threads if OpenMP is used for parallelization.
Definition: lvropenmp.cpp:56
MeshBufferPtr apply(const BaseMesh< BaseVecT > &mesh)
A surface reconstruction object that implements the standard marching cubes algorithm using a octree ...
std::shared_ptr< PointBuffer > PointBufferPtr
void printLogo() const
Definition: BaseOption.cpp:110
Half-edge data structure implementing the BaseMesh interface.
virtual void getMesh(BaseMesh< BaseVecT > &mesh)
Returns the surface reconstruction of the given point set.
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
void panic_unimplemented(std::string msg)
Throws a panic exception with the given error message and denotes that the exception was thrown due t...
Definition: Panic.hpp:84
int main(int argc, char **argv)
std::shared_ptr< PointsetSurface< BaseVecT > > PointsetSurfacePtr
PointsetSurfacePtr< BaseVecT > loadPointCloud(const dmc_reconstruction::Options &options)
static void saveModel(ModelPtr m, std::string file)
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