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
99  ModelPtr model = ModelFactory::readModel(options.getInputFileName());
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 }
lvr2::ModelFactory::saveModel
static void saveModel(ModelPtr m, std::string file)
Definition: ModelFactory.cpp:225
BaseVector.hpp
lvr2::GrowingCellStructure
Definition: GrowingCellStructure.hpp:19
PointsetSurface.hpp
lvr2::GrowingCellStructure::setNeighborLearningRate
void setNeighborLearningRate(float m_neighborLearningRate)
Definition: GrowingCellStructure.hpp:79
lvr2::BaseVector< float >
lvr2::GrowingCellStructure::setBasicSteps
void setBasicSteps(int m_basicSteps)
Definition: GrowingCellStructure.hpp:63
lvr2::GrowingCellStructure::getMesh
void getMesh(HalfEdgeMesh< BaseVecT > &mesh)
lvr2::PointBufferPtr
std::shared_ptr< PointBuffer > PointBufferPtr
Definition: PointBuffer.hpp:130
saveMesh
void saveMesh(int s=0)
Definition: src/tools/lvr2_gs_reconstruction/Main.cpp:69
lvr2::GrowingCellStructure::setFilterChain
void setFilterChain(bool m_filterChain)
Definition: GrowingCellStructure.hpp:96
gs_reconstruction::Options
Definition: OptionsGS.hpp:55
lvr2::PointBuffer
A class to handle point information with an arbitrarily large number of attribute channels....
Definition: PointBuffer.hpp:51
lvr2::GrowingCellStructure::setAllowMiss
void setAllowMiss(int m_allowMiss)
Definition: GrowingCellStructure.hpp:89
NULL
#define NULL
Definition: mydefs.hpp:141
lvr2::Model
Definition: Model.hpp:51
HalfEdgeMesh.hpp
AdaptiveKSearchSurface.hpp
loadPointCloud
PointsetSurfacePtr< BaseVecT > loadPointCloud(const gs_reconstruction::Options &options, PointBufferPtr buffer)
Definition: src/tools/lvr2_gs_reconstruction/Main.cpp:29
lvr2::SimpleFinalizer
Definition: FinalizeAlgorithms.hpp:68
lvr2::GrowingCellStructure::setDecreaseFactor
void setDecreaseFactor(float m_decreaseFactor)
Definition: GrowingCellStructure.hpp:84
lvr2::PointsetSurfacePtr
std::shared_ptr< PointsetSurface< BaseVecT > > PointsetSurfacePtr
Definition: PointsetSurface.hpp:161
lvr2::GrowingCellStructure::setNumBalances
void setNumBalances(int m_balances)
Definition: GrowingCellStructure.hpp:105
options
const kaboom::Options * options
Definition: src/tools/lvr2_kaboom/Main.cpp:45
lvr2::GrowingCellStructure::setWithCollapse
void setWithCollapse(bool m_withCollapse)
Definition: GrowingCellStructure.hpp:69
PointBuffer.hpp
lvr2::timestamp
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
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::GrowingCellStructure::setNumSplits
void setNumSplits(int m_numSplits)
Definition: GrowingCellStructure.hpp:65
lvr2::GrowingCellStructure::setRuntime
void setRuntime(int m_runtime)
Definition: GrowingCellStructure.hpp:61
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ModelPtr
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
GrowingCellStructure.hpp
lvr2::MeshBufferPtr
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
lvr2::GrowingCellStructure::setDeleteLongEdgesFactor
void setDeleteLongEdgesFactor(int m_deleteLongEdgesFactor)
Definition: GrowingCellStructure.hpp:98
main
int main(int argc, char **argv)
Definition: src/tools/lvr2_gs_reconstruction/Main.cpp:85
lvr2::GrowingCellStructure::setLearningRate
void setLearningRate(float m_learningRate)
Definition: GrowingCellStructure.hpp:74
lvr2::ModelFactory::readModel
static ModelPtr readModel(std::string filename)
Definition: ModelFactory.cpp:65
ModelFactory.hpp
lvr2::GrowingCellStructure::setBoxFactor
void setBoxFactor(float m_boxFactor)
Definition: GrowingCellStructure.hpp:67
lvr2::GrowingCellStructure::setInterior
void setInterior(bool m_interior)
Definition: GrowingCellStructure.hpp:103
lvr2::GrowingCellStructure::setCollapseThreshold
void setCollapseThreshold(float m_collapseThreshold)
Definition: GrowingCellStructure.hpp:91
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
OptionsGS.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