src/tools/lvr2_mesh_reducer/Main.cpp
Go to the documentation of this file.
1 
29 #include <iostream>
30 #include <memory>
31 #include <tuple>
32 #include <stdlib.h>
33 
34 #include <boost/optional.hpp>
35 #include "Options.hpp"
36 
37 
38 
39 using std::unique_ptr;
40 using std::make_unique;
41 
42 #include "lvr2/io/Progress.hpp"
43 #include "lvr2/io/Model.hpp"
48 
50 
51 int main(int argc, char** argv)
52 {
53  // =======================================================================
54  // Parse and print command line parameters
55  // =======================================================================
56  // Parse command line arguments
58 
59  // Exit if options had to generate a usage message
60  // (this means required parameters are missing)
61  if (options.printUsage())
62  {
63  return EXIT_SUCCESS;
64  }
65  std::cout << options << std::endl;
66  cout << "LOAD" << endl;
67  lvr2::ModelPtr model = lvr2::ModelFactory::readModel(options.getInputFileName());
68  cout << "MODEL" << endl;
69  cout << model << endl;
70  lvr2::MeshBufferPtr meshBuffer = model->m_mesh;
71  cout << meshBuffer << endl;
72  lvr2::HalfEdgeMesh<Vec> mesh(meshBuffer);
73 
74  std::cout << lvr2::timestamp << "Computing face normals..." << std::endl;
75 
76  // Calculate initial face normals
77  auto faceNormals = calcFaceNormals(mesh);
78 
79  // Reduce mesh complexity
80  const auto reductionRatio = options.getEdgeCollapseReductionRatio();
81  std::cout << lvr2::timestamp << "Collapsing faces..." << std::endl;
82 
83  if (reductionRatio > 0.0)
84  {
85  if (reductionRatio > 1.0)
86  {
87  throw "The reduction ratio needs to be between 0 and 1!";
88  }
89 
90  // Each edge collapse removes two faces in the general case.
91  // TODO: maybe we should calculate this differently...
92  const auto count = static_cast<size_t>((mesh.numFaces() / 2) * reductionRatio);
93  auto collapsedCount = simpleMeshReduction(mesh, count, faceNormals);
94  }
95 
96  // =======================================================================
97  // Finalize mesh
98  // =======================================================================
100  // Run finalize algorithm
101  auto buffer = finalizer.apply(mesh);
102 
103  // =======================================================================
104  // Write all results (including the mesh) to file
105  // =======================================================================
106  // Create output model and save to file
107  auto m = lvr2::ModelPtr( new lvr2::Model(buffer));
108 
109  lvr2::ModelFactory::saveModel(m, "reduced_mesh.ply");
110 
111  cout << lvr2::timestamp << "Program end." << endl;
112 
113  return 0;
114 }
lvr2::ModelFactory::saveModel
static void saveModel(ModelPtr m, std::string file)
Definition: ModelFactory.cpp:225
NormalAlgorithms.hpp
Options.hpp
lvr2::BaseVector< float >
meshreduce::Options
A class to parse the program options for the reconstruction executable.
Definition: src/tools/lvr2_mesh_reducer/Options.hpp:59
lvr2::Model
Definition: Model.hpp:51
HalfEdgeMesh.hpp
lvr2::SimpleFinalizer
Definition: FinalizeAlgorithms.hpp:68
options
const kaboom::Options * options
Definition: src/tools/lvr2_kaboom/Main.cpp:45
lvr2::simpleMeshReduction
size_t simpleMeshReduction(BaseMesh< BaseVecT > &mesh, const size_t count, FaceMap< Normal< typename BaseVecT::CoordType >> &faceNormals)
Like iterativeEdgeCollapse but with a fixed cost function.
main
int main(int argc, char **argv)
Definition: src/tools/lvr2_mesh_reducer/Main.cpp:51
lvr2::timestamp
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
Progress.hpp
Vec
BaseVector< float > Vec
Definition: src/tools/lvr2_cuda_normals/Main.cpp:57
FinalizeAlgorithms.hpp
Model.hpp
argc
int argc
Definition: tests_high_five_parallel.cpp:27
lvr2::ModelPtr
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
lvr2::MeshBufferPtr
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
lvr2::ModelFactory::readModel
static ModelPtr readModel(std::string filename)
Definition: ModelFactory.cpp:65
mesh
HalfEdgeMesh< Vec > mesh
Definition: src/tools/lvr2_gs_reconstruction/Main.cpp:26
argv
char ** argv
Definition: tests_high_five_parallel.cpp:28
lvr2::calcFaceNormals
DenseFaceMap< Normal< typename BaseVecT::CoordType > > calcFaceNormals(const BaseMesh< BaseVecT > &mesh)
Calculates a normal for each face in the mesh.
ReductionAlgorithms.hpp
lvr2::SimpleFinalizer::apply
MeshBufferPtr apply(const BaseMesh< BaseVecT > &mesh)
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