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
33  ModelPtr model = ModelFactory::readModel(options.getInputFileName());
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  // =======================================================================
119  OpenMPConfig::setNumThreads(options.getNumThreads());
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 }
lvr2::OpenMPConfig::setNumThreads
static void setNumThreads(int n)
Sets the number of used threads if OpenMP is used for parallelization.
Definition: lvropenmp.cpp:56
lvr2::ModelFactory::saveModel
static void saveModel(ModelPtr m, std::string file)
Definition: ModelFactory.cpp:225
BaseVector.hpp
DMCReconstruction.hpp
dmc_reconstruction::Options
Definition: src/tools/lvr2_dmc_reconstruction/Options.hpp:56
PointsetSurface.hpp
lvr2::BaseVector< float >
Options.hpp
lvr2::PointBufferPtr
std::shared_ptr< PointBuffer > PointBufferPtr
Definition: PointBuffer.hpp:130
loadPointCloud
PointsetSurfacePtr< BaseVecT > loadPointCloud(const dmc_reconstruction::Options &options)
Definition: src/tools/lvr2_dmc_reconstruction/Main.cpp:30
lvr2::Model
Definition: Model.hpp:51
HalfEdgeMesh.hpp
AdaptiveKSearchSurface.hpp
lvr2::SimpleFinalizer
Definition: FinalizeAlgorithms.hpp:68
lvr2::PointsetSurfacePtr
std::shared_ptr< PointsetSurface< BaseVecT > > PointsetSurfacePtr
Definition: PointsetSurface.hpp:161
main
int main(int argc, char **argv)
Definition: src/tools/lvr2_dmc_reconstruction/Main.cpp:100
FastReconstruction.hpp
options
const kaboom::Options * options
Definition: src/tools/lvr2_kaboom/Main.cpp:45
lvropenmp.hpp
PointBuffer.hpp
lvr2::timestamp
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
lvr2::DMCReconstruction
A surface reconstruction object that implements the standard marching cubes algorithm using a octree ...
Definition: DMCReconstruction.hpp:67
lvr2::panic_unimplemented
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
MeshBuffer.hpp
argc
int argc
Definition: tests_high_five_parallel.cpp:27
lvr2::DMCReconstruction::getMesh
virtual void getMesh(BaseMesh< BaseVecT > &mesh)
Returns the surface reconstruction of the given point set.
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ModelPtr
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
lvr2::BaseOption::printLogo
void printLogo() const
Definition: BaseOption.cpp:110
lvr2::ModelFactory::readModel
static ModelPtr readModel(std::string filename)
Definition: ModelFactory.cpp:65
ModelFactory.hpp
mesh
HalfEdgeMesh< Vec > mesh
Definition: src/tools/lvr2_gs_reconstruction/Main.cpp:26
argv
char ** argv
Definition: tests_high_five_parallel.cpp:28
lvr2::SimpleFinalizer::apply
MeshBufferPtr apply(const BaseMesh< BaseVecT > &mesh)
CleanupAlgorithms.hpp
lvr2::HalfEdgeMesh
Half-edge data structure implementing the BaseMesh interface.
Definition: HalfEdgeMesh.hpp:70


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