src/tools/lvr2_gs_reconstruction/Main.cpp
Go to the documentation of this file.
1 /*
2  * MainGS.cpp
3  *
4  * Created on: somewhen.02.2019
5  * Author: Patrick Hoffmann (pahoffmann@uos.de)
6  */
7 
9 
10 #include "OptionsGS.hpp"
14 #include "lvr2/io/MeshBuffer.hpp"
15 #include "lvr2/io/ModelFactory.hpp"
16 #include "lvr2/io/PointBuffer.hpp"
20 
21 #include <signal.h>
22 
23 using namespace lvr2;
24 
27 
28 template <typename BaseVecT>
30  PointBufferPtr buffer)
31 {
32  // Create a point cloud manager
33  string pcm_name = options.getPcm();
35 
36  // Create point set surface object
37  if (pcm_name == "PCL")
38  {
39  cout << timestamp << "Using PCL as point cloud manager is not implemented yet!" << endl;
40  panic_unimplemented("PCL as point cloud manager");
41  }
42  else if (pcm_name == "STANN" || pcm_name == "FLANN" || pcm_name == "NABO" ||
43  pcm_name == "NANOFLANN")
44  {
45  surface = make_shared<AdaptiveKSearchSurface<BaseVecT>>(
46  buffer, pcm_name, options.getKn(), options.getKi(), options.getKd(), 1, "");
47  }
48  else
49  {
50  cout << timestamp << "Unable to create PointCloudManager." << endl;
51  cout << timestamp << "Unknown option '" << pcm_name << "'." << endl;
52  return nullptr;
53  }
54 
55  // Set search options for normal estimation and distance evaluation
56  surface->setKd(options.getKd());
57  surface->setKi(options.getKi());
58  surface->setKn(options.getKn());
59 
60  // calc normals if there are none
61  if (!buffer->hasNormals() && buffer.get()->numPoints() < 1000000)
62  {
63  surface->calculateSurfaceNormals();
64  }
65 
66  return surface;
67 }
68 
69 void saveMesh(int s = 0)
70 {
71  if (s != 0)
72  {
73  std::cout << endl << "Received signal bit..." << endl;
74  }
76  MeshBufferPtr res = fin.apply(mesh);
77 
78  ModelPtr m(new Model(res));
79 
80  cout << timestamp << "Saving mesh." << endl;
81  ModelFactory::saveModel(m, "triangle_init_mesh.ply");
82  exit(0);
83 }
84 
85 int main(int argc, char** argv)
86 {
87 
89 
90  // if one of the needed parameters is missing,
91  if (options.printUsage())
92  {
93  return EXIT_SUCCESS;
94  }
95 
96  std::cout << options << std::endl;
97 
98  // try to parse the model
100 
101  // did model parse succeed
102  if (!model)
103  {
104  cout << timestamp << "IO Error: Unable to parse " << options.getInputFileName() << endl;
105  return EXIT_FAILURE;
106  }
107 
108  /* Catch ctr+c and save the Mesh.. */
109  struct sigaction sigIntHandler;
110 
111  sigIntHandler.sa_handler = saveMesh;
112  sigemptyset(&sigIntHandler.sa_mask);
113  sigIntHandler.sa_flags = 0;
114 
115  sigaction(SIGINT, &sigIntHandler, NULL);
116  PointBufferPtr buffer = model->m_pointCloud;
117 
118  if (!buffer)
119  {
120  cout << "Failed to create Buffer...exiting..." << endl;
121  PointBuffer* pointBuffer = new PointBuffer(model.get()->m_mesh.get()->getVertices(),
122  model.get()->m_mesh.get()->numVertices());
123  PointBufferPtr pointer(pointBuffer);
124  buffer = pointer;
125  }
126 
127  // Create a point cloud manager
128  string pcm_name = options.getPcm();
129  auto surface = loadPointCloud<Vec>(options, buffer);
130  if (!surface)
131  {
132  cout << "Failed to create pointcloud. Exiting." << endl;
133  return EXIT_FAILURE;
134  }
135 
137 
138  // set gcs variables
139  gcs.setRuntime(options.getRuntime());
140  gcs.setBasicSteps(options.getBasicSteps());
141  gcs.setBoxFactor(options.getBoxFactor());
142  gcs.setAllowMiss(options.getAllowMiss());
143  gcs.setCollapseThreshold(options.getCollapseThreshold());
144  gcs.setDecreaseFactor(options.getDecreaseFactor());
145  gcs.setDeleteLongEdgesFactor(options.getDeleteLongEdgesFactor());
146  gcs.setFilterChain(options.isFilterChain());
147  gcs.setLearningRate(options.getLearningRate());
148  gcs.setNeighborLearningRate(options.getNeighborLearningRate());
149  gcs.setNumSplits(options.getNumSplits());
150  gcs.setWithCollapse(options.getWithCollapse());
151  gcs.setInterior(options.isInterior());
152  gcs.setNumBalances(options.getNumBalances());
153 
154  gcs.getMesh(mesh);
155 
156  saveMesh();
157 
158  return 0;
159 }
A class to handle point information with an arbitrarily large number of attribute channels...
Definition: PointBuffer.hpp:51
void setNumBalances(int m_balances)
HalfEdgeMesh< Vec > mesh
const kaboom::Options * options
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
void setWithCollapse(bool m_withCollapse)
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
static ModelPtr readModel(std::string filename)
void setDeleteLongEdgesFactor(int m_deleteLongEdgesFactor)
void setBoxFactor(float m_boxFactor)
void setNumSplits(int m_numSplits)
MeshBufferPtr apply(const BaseMesh< BaseVecT > &mesh)
std::shared_ptr< PointBuffer > PointBufferPtr
void setCollapseThreshold(float m_collapseThreshold)
void setLearningRate(float m_learningRate)
PointsetSurfacePtr< BaseVecT > loadPointCloud(const gs_reconstruction::Options &options, PointBufferPtr buffer)
void setInterior(bool m_interior)
Half-edge data structure implementing the BaseMesh interface.
void setBasicSteps(int m_basicSteps)
void getMesh(HalfEdgeMesh< BaseVecT > &mesh)
void setFilterChain(bool m_filterChain)
int main(int argc, char **argv)
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
void setNeighborLearningRate(float m_neighborLearningRate)
void setAllowMiss(int m_allowMiss)
std::shared_ptr< PointsetSurface< BaseVecT > > PointsetSurfacePtr
void setDecreaseFactor(float m_decreaseFactor)
string getInputFileName() const
Definition: OptionsGS.cpp:43
#define NULL
Definition: mydefs.hpp:141
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