LVRReconstructionExtendedMarchingCubesDialog.cpp
Go to the documentation of this file.
1 
28 #include <QFileDialog>
30 
32 
37 
40 
41 #include "lvr2/io/PointBuffer.hpp"
42 
43 namespace lvr2
44 {
45 
46 LVRReconstructViaExtendedMarchingCubesDialog::LVRReconstructViaExtendedMarchingCubesDialog(string decomposition, LVRPointCloudItem* pc, LVRModelItem* parent, QTreeWidget* treeWidget, vtkRenderWindow* window) :
47  m_decomposition(decomposition),
48  m_pc(pc), m_parent(parent),
49  m_treeWidget(treeWidget),
50  m_renderWindow(window)
51 {
52  // Setup DialogUI and events
53  QDialog* dialog = new QDialog(m_treeWidget);
54  m_dialog = new ReconstructViaExtendedMarchingCubesDialog;
55  m_dialog->setupUi(dialog);
56 
57 
58  dialog->setWindowTitle("Extended Marching Cubes");
59 
61 
62  dialog->show();
63  dialog->raise();
64  dialog->activateWindow();
65 }
66 
68 {
69  // TODO Auto-generated destructor stub
70 }
71 
73 {
74  QObject::connect(m_dialog->comboBox_pcm, SIGNAL(currentIndexChanged(const QString)), this, SLOT(toggleRANSACcheckBox(const QString)));
75  QObject::connect(m_dialog->comboBox_gs, SIGNAL(currentIndexChanged(int)), this, SLOT(switchGridSizeDetermination(int)));
76  QObject::connect(m_dialog->buttonBox, SIGNAL(accepted()), this, SLOT(generateMesh()));
77 }
78 
80 {
81  QCheckBox* ransac_box = m_dialog->checkBox_RANSAC;
82  if(text == "PCL")
83  {
84  ransac_box->setChecked(false);
85  ransac_box->setCheckable(false);
86  }
87  else
88  {
89  ransac_box->setCheckable(true);
90  }
91 }
92 
94 {
95  QComboBox* gs_box = m_dialog->comboBox_gs;
96 
97  QLabel* label = m_dialog->label_below_gs;
98  QDoubleSpinBox* spinBox = m_dialog->spinBox_below_gs;
99 
100  // TODO: Add reasonable default values
101  if(index == 0)
102  {
103  label->setText("Voxel size");
104  spinBox->setMinimum(0);
105  spinBox->setMaximum(2000000);
106  spinBox->setSingleStep(1);
107  spinBox->setValue(10);
108  }
109  else
110  {
111  label->setText("Number of intersections");
112  spinBox->setMinimum(1);
113  spinBox->setMaximum(200000);
114  spinBox->setSingleStep(1);
115  spinBox->setValue(10);
116  }
117 }
118 
120 {
121  using Vec = BaseVector<float>;
122 
123  QComboBox* pcm_box = m_dialog->comboBox_pcm;
124  string pcm = pcm_box->currentText().toStdString();
125  QCheckBox* extrusion_box = m_dialog->checkBox_Extrusion;
126  bool extrusion = extrusion_box->isChecked();
127  QCheckBox* ransac_box = m_dialog->checkBox_RANSAC;
128  bool ransac = ransac_box->isChecked();
129  QSpinBox* kn_box = m_dialog->spinBox_kn;
130  int kn = kn_box->value();
131  QSpinBox* kd_box = m_dialog->spinBox_kd;
132  int kd = kd_box->value();
133  QSpinBox* ki_box = m_dialog->spinBox_ki;
134  int ki = ki_box->value();
135  QCheckBox* reNormals_box = m_dialog->checkBox_renormals;
136  bool reestimateNormals = reNormals_box->isChecked();
137  QComboBox* gridMode_box = m_dialog->comboBox_gs;
138  bool useVoxelsize = (gridMode_box->currentIndex() == 0) ? true : false;
139  QDoubleSpinBox* gridSize_box = m_dialog->spinBox_below_gs;
140  float resolution = (float)gridSize_box->value();
141 
142  float sf = m_dialog->doubleSpinBox_sf->value();
143  float sc = m_dialog->doubleSpinBox_sc->value();
144 
145 
146  PointBufferPtr pc_buffer = m_pc->getPointBuffer();
147 
148  PointsetSurfacePtr<Vec> surface;
149 
150  if(pcm == "STANN" || pcm == "FLANN" || pcm == "NABO" || pcm == "NANOFLANN")
151  {
152  surface = PointsetSurfacePtr<Vec>( new AdaptiveKSearchSurface<Vec>(pc_buffer, pcm, kn, ki, kd, ransac ? 1 : 0) );
153  }
154 
155  if(!surface->pointBuffer()->hasNormals() || reestimateNormals)
156  {
157  surface->calculateSurfaceNormals();
158  }
159 
160  SharpBox<Vec>::m_surface = surface;
163 
164  auto grid = std::make_shared<PointsetGrid<Vec, SharpBox<Vec>>>(
165  resolution,
166  surface,
167  surface->getBoundingBox(),
168  useVoxelsize,
169  extrusion
170  );
171 
172  grid->calcDistanceValues();
173  auto reconstruction = make_unique<FastReconstruction<Vec, SharpBox<Vec>>>(grid);
174 
175  // Create an empty mesh
177  reconstruction->getMesh(mesh);
178 
179  auto faceNormals = calcFaceNormals(mesh);
180 
181  ClusterBiMap<FaceHandle> clusterBiMap = planarClusterGrowing(mesh, faceNormals, 0.85);
182  deleteSmallPlanarCluster(mesh, clusterBiMap, 10);
183 
184  ClusterPainter painter(clusterBiMap);
185  auto clusterColors = DenseClusterMap<Rgb8Color>(painter.simpsons(mesh));
186  auto vertexNormals = calcVertexNormals(mesh, faceNormals, *surface);
187 
188  TextureFinalizer<Vec> finalize(clusterBiMap);
189  finalize.setVertexNormals(vertexNormals);
190  finalize.setClusterColors(clusterColors);
191  Materializer<Vec> materializer(mesh, clusterBiMap, faceNormals, *surface);
192  MaterializerResult<Vec> matResult = materializer.generateMaterials();
193  finalize.setMaterializerResult(matResult);
194  MeshBufferPtr buffer = finalize.apply(mesh);
195 
196 
197  ModelPtr model(new Model(buffer));
198  ModelBridgePtr bridge(new LVRModelBridge(model));
199 
200  vtkSmartPointer<vtkRenderer> renderer = m_renderWindow->GetRenderers()->GetFirstRenderer();
201  bridge->addActors(renderer);
202 
203  QString base = m_parent->getName() + " (mesh)";
204  m_generatedModel = new LVRModelItem(bridge, base);
205 
206  m_treeWidget->addTopLevelItem(m_generatedModel);
207  m_generatedModel->setExpanded(true);
208 }
209 
210 } // namespace lvr2
LVRReconstructViaExtendedMarchingCubesDialog(string decomposition, LVRPointCloudItem *pc, LVRModelItem *parent, QTreeWidget *treeWidget, vtkRenderWindow *renderer)
void setClusterColors(const ClusterMap< Rgb8Color > &colors)
void deleteSmallPlanarCluster(BaseMesh< BaseVecT > &mesh, ClusterBiMap< FaceHandle > &clusters, size_t smallClusterThreshold)
Removes all clusters and their cotained faces from the given mesh which are smaller than the given sm...
HalfEdgeMesh< Vec > mesh
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
Algorithm which generates the same color for all vertices, which are in the same cluster.
DenseVertexMap< Normal< typename BaseVecT::CoordType > > calcVertexNormals(const BaseMesh< BaseVecT > &mesh, const FaceMap< Normal< typename BaseVecT::CoordType >> &normals, const PointsetSurface< BaseVecT > &surface)
Calculates a normal for each vertex in the mesh.
PointBufferPtr getPointBuffer()
DenseFaceMap< Normal< typename BaseVecT::CoordType > > calcFaceNormals(const BaseMesh< BaseVecT > &mesh)
Calculates a normal for each face in the mesh.
Class for calculating materials for each cluster of a given mesh.
void setVertexNormals(const VertexMap< Normal< typename BaseVecT::CoordType >> &normals)
std::shared_ptr< PointBuffer > PointBufferPtr
Main class for conversion of LVR model instances to vtk actors. This class parses the internal model ...
A map of clusters, which also saves a back-reference from handle to cluster.
DenseClusterMap< Rgb8Color > simpsons(const BaseMesh< BaseVecT > &mesh) const
Assign a pseudo-color to each cluster.
Used for extended marching cubes Reconstruction.
Definition: SharpBox.hpp:53
boost::shared_ptr< LVRModelBridge > ModelBridgePtr
void setMaterializerResult(const MaterializerResult< BaseVecT > &materializerResult)
MaterializerResult< BaseVecT > generateMaterials()
Generates materials.
Half-edge data structure implementing the BaseMesh interface.
A point cloud manager class that uses the STANN nearest neighbor search library to handle the data...
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
ClusterBiMap< FaceHandle > planarClusterGrowing(const BaseMesh< BaseVecT > &mesh, const FaceMap< Normal< typename BaseVecT::CoordType >> &normals, float minSinAngle)
Algorithm which generates plane clusters from the given mesh.
MeshBufferPtr apply(const BaseMesh< BaseVecT > &mesh)
Result struct for the materializer.
std::shared_ptr< PointsetSurface< BaseVecT > > PointsetSurfacePtr
A map with constant lookup overhead using small-ish integer-keys.
Definition: VectorMap.hpp:60


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