LVRReconstructionMarchingCubesDialog.cpp
Go to the documentation of this file.
1 
28 #include <QFileDialog>
29 
30 #include <Eigen/Dense>
31 
33 #include "LVRItemTypes.hpp"
34 
44 #include "lvr2/io/PointBuffer.hpp"
45 #include "lvr2/io/Progress.hpp"
47 
48 namespace lvr2
49 {
50 
51 //QProgressDialog* LVRReconstructViaMarchingCubesDialog::m_progressBar = new QProgressDialog;
52 LVRReconstructViaMarchingCubesDialog* LVRReconstructViaMarchingCubesDialog::m_master;
54 {
56 }
57 
59 {
61 }
62 
63 
65 {
66  Q_EMIT(progressValueChanged(v));
67  QApplication::processEvents();
68 }
69 
71 {
72  Q_EMIT(progressTitleChanged(QString(t.c_str())));
73  QApplication::processEvents();
74 }
75 
76 LVRReconstructViaMarchingCubesDialog::LVRReconstructViaMarchingCubesDialog(string decomposition, LVRPointCloudItem* pc, QTreeWidgetItem* parent, QTreeWidget* treeWidget, vtkRenderWindow* window) :
77  m_decomposition(decomposition),
78  m_pc(pc), m_parent(parent),
79  m_treeWidget(treeWidget),
80  m_renderWindow(window)
81 {
82  m_master = this;
83 
84  // Setup DialogUI and events
85  QDialog* dialog = new QDialog(m_treeWidget);
86  m_dialog = new ReconstructViaMarchingCubesDialog;
87  m_dialog->setupUi(dialog);
88 
89  if(decomposition == "PMC")
90  {
91  dialog->setWindowTitle("Planar Marching Cubes");
92  }
93 
95 
96  m_progressDialog = new QProgressDialog;
97  m_progressDialog->setMinimum(0);
98  m_progressDialog->setMaximum(100);
99  m_progressDialog->setMinimumDuration(100);
100  m_progressDialog->setWindowTitle("Processing...");
101  m_progressDialog->setAutoClose(false);
102  m_progressDialog->reset();
103  m_progressDialog->hide();
104 
105  // Register LVR progress callbacks
108 
109  connect(this, SIGNAL(progressValueChanged(int)), m_progressDialog, SLOT(setValue(int)));
110  connect(this, SIGNAL(progressTitleChanged(const QString&)), m_progressDialog, SLOT(setLabelText(const QString&)));
111 
112  dialog->show();
113  dialog->raise();
114  dialog->activateWindow();
115 }
116 
118 {
119  m_master = 0;
122 }
123 
125 {
126  QObject::connect(m_dialog->comboBox_pcm, SIGNAL(currentIndexChanged(const QString)), this, SLOT(toggleRANSACcheckBox(const QString)));
127  QObject::connect(m_dialog->comboBox_gs, SIGNAL(currentIndexChanged(int)), this, SLOT(switchGridSizeDetermination(int)));
128  QObject::connect(m_dialog->buttonBox, SIGNAL(accepted()), this, SLOT(generateMesh()));
129 }
130 
132 {
133  QCheckBox* ransac_box = m_dialog->checkBox_RANSAC;
134  if(text == "PCL")
135  {
136  ransac_box->setChecked(false);
137  ransac_box->setCheckable(false);
138  }
139  else
140  {
141  ransac_box->setCheckable(true);
142  }
143 }
144 
146 {
147  QComboBox* gs_box = m_dialog->comboBox_gs;
148 
149  QLabel* label = m_dialog->label_below_gs;
150  QDoubleSpinBox* spinBox = m_dialog->spinBox_below_gs;
151 
152  // TODO: Add reasonable default values
153  if(index == 0)
154  {
155  label->setText("Voxel size");
156  spinBox->setMinimum(0);
157  spinBox->setMaximum(2000000);
158  spinBox->setSingleStep(1);
159  spinBox->setValue(10);
160  }
161  else
162  {
163  label->setText("Number of intersections");
164  spinBox->setMinimum(1);
165  spinBox->setMaximum(200000);
166  spinBox->setSingleStep(1);
167  spinBox->setValue(10);
168  }
169 }
170 
172 {
173  QComboBox* pcm_box = m_dialog->comboBox_pcm;
174  string pcm = pcm_box->currentText().toStdString();
175  QCheckBox* extrusion_box = m_dialog->checkBox_Extrusion;
176  bool extrusion = extrusion_box->isChecked();
177  QCheckBox* ransac_box = m_dialog->checkBox_RANSAC;
178  bool ransac = ransac_box->isChecked();
179  QSpinBox* kn_box = m_dialog->spinBox_kn;
180  int kn = kn_box->value();
181  QSpinBox* kd_box = m_dialog->spinBox_kd;
182  int kd = kd_box->value();
183  QSpinBox* ki_box = m_dialog->spinBox_ki;
184  int ki = ki_box->value();
185  QCheckBox* reNormals_box = m_dialog->checkBox_renormals;
186  bool reestimateNormals = reNormals_box->isChecked();
187  QComboBox* gridMode_box = m_dialog->comboBox_gs;
188  bool useVoxelsize = (gridMode_box->currentIndex() == 0) ? true : false;
189  QDoubleSpinBox* gridSize_box = m_dialog->spinBox_below_gs;
190  float resolution = (float)gridSize_box->value();
191 
192 
193  m_progressDialog->raise();
194  m_progressDialog->show();
195  m_progressDialog->activateWindow();
196 
197  using Vec = BaseVector<float>;
198 
199  QTreeWidgetItem* entry_point = m_parent;
200  if(m_parent)
201  {
202  if(m_parent->type() == LVRScanDataItemType)
203  {
204  entry_point = m_parent->parent();
205  }
206  }
207 
208  PointBufferPtr pc_buffer = m_pc->getPointBuffer();
209 
211  std::cout << T << std::endl;
212 
213  pc_buffer = qttf::transform(pc_buffer, T);
214 
215  PointsetSurfacePtr<Vec> surface;
216 
217  if(pcm == "STANN" || pcm == "FLANN" || pcm == "NABO" || pcm == "NANOFLANN")
218  {
219  surface = PointsetSurfacePtr<Vec>( new AdaptiveKSearchSurface<Vec>(pc_buffer, pcm, kn, ki, kd, (ransac ? 1 : 0)) );
220  }
221 
222  if(!surface->pointBuffer()->hasNormals() || reestimateNormals)
223  {
224  surface->calculateSurfaceNormals();
225  }
226 
228 
229  if(m_decomposition == "MC")
230  {
231  auto grid = std::make_shared<PointsetGrid<Vec, FastBox<Vec>>>(
232  resolution,
233  surface,
234  surface->getBoundingBox(),
235  useVoxelsize,
236  extrusion
237  );
238  grid->calcDistanceValues();
239  auto reconstruction = make_unique<FastReconstruction<Vec, FastBox<Vec>>>(grid);
240  reconstruction->getMesh(mesh);
241  }
242  else if(m_decomposition == "PMC")
243  {
245  auto grid = std::make_shared<PointsetGrid<Vec, BilinearFastBox<Vec>>>(
246  resolution,
247  surface,
248  surface->getBoundingBox(),
249  useVoxelsize,
250  extrusion
251  );
252  grid->calcDistanceValues();
253  auto reconstruction = make_unique<FastReconstruction<Vec, BilinearFastBox<Vec>>>(grid);
254  reconstruction->getMesh(mesh);
255  }
256  else if(m_decomposition == "MT")
257  {
258  auto grid = std::make_shared<PointsetGrid<Vec, TetraederBox<Vec>>>(
259  resolution,
260  surface,
261  surface->getBoundingBox(),
262  useVoxelsize,
263  extrusion
264  );
265  grid->calcDistanceValues();
266  auto reconstruction = make_unique<FastReconstruction<Vec, TetraederBox<Vec>>>(grid);
267  reconstruction->getMesh(mesh);
268  }
269  else if(m_decomposition == "SF")
270  {
271  SharpBox<Vec>::m_surface = surface;
272  auto grid = std::make_shared<PointsetGrid<Vec, SharpBox<Vec>>>(
273  resolution,
274  surface,
275  surface->getBoundingBox(),
276  useVoxelsize,
277  extrusion
278  );
279  grid->calcDistanceValues();
280  auto reconstruction = make_unique<FastReconstruction<Vec, SharpBox<Vec>>>(grid);
281  reconstruction->getMesh(mesh);
282  }
283 
284  auto faceNormals = calcFaceNormals(mesh);
285 
286  ClusterBiMap<FaceHandle> clusterBiMap = planarClusterGrowing(mesh, faceNormals, 0.85);
287  deleteSmallPlanarCluster(mesh, clusterBiMap, 10);
288 
289  ClusterPainter painter(clusterBiMap);
290  auto clusterColors = DenseClusterMap<Rgb8Color>(painter.simpsons(mesh));
291  auto vertexNormals = calcVertexNormals(mesh, faceNormals, *surface);
292 
293  TextureFinalizer<Vec> finalize(clusterBiMap);
294  finalize.setVertexNormals(vertexNormals);
295  finalize.setClusterColors(clusterColors);
296  Materializer<Vec> materializer(mesh, clusterBiMap, faceNormals, *surface);
297  MaterializerResult<Vec> matResult = materializer.generateMaterials();
298  finalize.setMaterializerResult(matResult);
299  MeshBufferPtr buffer = finalize.apply(mesh);
300 
301 
302  ModelPtr model(new Model(buffer));
303  ModelBridgePtr bridge(new LVRModelBridge(model));
304 
305  vtkSmartPointer<vtkRenderer> renderer = m_renderWindow->GetRenderers()->GetFirstRenderer();
306  bridge->addActors(renderer);
307 
308  QString base("mesh");
309 
310  if(m_parent)
311  {
312  base = m_parent->text(0) + " (mesh)";
313  }
314 
315  m_generatedModel = new LVRModelItem(bridge, base);
316 
317  if(entry_point)
318  {
319  entry_point->addChild(m_generatedModel);
320  } else {
321  m_treeWidget->addTopLevelItem(m_generatedModel);
322  }
323 
324 
325  m_generatedModel->setExpanded(true);
326 
327  m_progressDialog->hide();
328 
329 }
330 
331 } // namespace lvr2
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.
Transform< double > Transformd
4x4 double precision transformation matrix
Definition: MatrixTypes.hpp:71
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.
SharedPointer p
Half-edge data structure implementing the BaseMesh interface.
static void setProgressCallback(ProgressCallbackPtr)
Registers a callback that is called with the new value when the percentage of the progress changed...
Definition: Progress.cpp:73
A point cloud manager class that uses the STANN nearest neighbor search library to handle the data...
static LVRReconstructViaMarchingCubesDialog * m_master
static void setProgressTitleCallback(ProgressTitleCallbackPtr)
Registers a callback that is called when a new progress instance is created.
Definition: Progress.cpp:78
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.
Transformd getTransformation(QTreeWidgetItem *from, QTreeWidgetItem *to)
Definition: qttf.cpp:9
LVRReconstructViaMarchingCubesDialog(string decomposition, LVRPointCloudItem *pc, QTreeWidgetItem *parent, QTreeWidget *treeWidget, vtkRenderWindow *renderer)
std::shared_ptr< PointsetSurface< BaseVecT > > PointsetSurfacePtr
A map with constant lookup overhead using small-ish integer-keys.
Definition: VectorMap.hpp:60
#define NULL
Definition: mydefs.hpp:141
PointBufferPtr transform(PointBufferPtr pc_in, const Transformd &T)
Definition: qttf.cpp:32


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