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
57  meshreduce::Options options(argc, argv);
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;
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 }
size_t simpleMeshReduction(BaseMesh< BaseVecT > &mesh, const size_t count, FaceMap< Normal< typename BaseVecT::CoordType >> &faceNormals)
Like iterativeEdgeCollapse but with a fixed cost function.
HalfEdgeMesh< Vec > mesh
int main(int argc, char **argv)
const kaboom::Options * options
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
string getInputFileName() const
Returns the output file name.
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
static ModelPtr readModel(std::string filename)
DenseFaceMap< Normal< typename BaseVecT::CoordType > > calcFaceNormals(const BaseMesh< BaseVecT > &mesh)
Calculates a normal for each face in the mesh.
MeshBufferPtr apply(const BaseMesh< BaseVecT > &mesh)
A class to parse the program options for the reconstruction executable.
Half-edge data structure implementing the BaseMesh interface.
size_t numFaces() const final
Returns the number of faces in the mesh.
float getEdgeCollapseReductionRatio() const
Reduction ratio for mesh reduction via edge collapse.
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
BaseVector< float > Vec
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