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
lvr2::LVRReconstructViaMarchingCubesDialog::m_parent
QTreeWidgetItem * m_parent
Definition: LVRReconstructionMarchingCubesDialog.hpp:99
lvr2::planarClusterGrowing
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.
lvr2::LVRReconstructViaMarchingCubesDialog::setProgressTitle
void setProgressTitle(string)
Definition: LVRReconstructionMarchingCubesDialog.cpp:70
NormalAlgorithms.hpp
lvr2::BaseVector< float >
lvr2::LVRReconstructViaMarchingCubesDialog::LVRReconstructViaMarchingCubesDialog
LVRReconstructViaMarchingCubesDialog(string decomposition, LVRPointCloudItem *pc, QTreeWidgetItem *parent, QTreeWidget *treeWidget, vtkRenderWindow *renderer)
Definition: LVRReconstructionMarchingCubesDialog.cpp:76
LVRReconstructionMarchingCubesDialog.hpp
lvr2::ClusterPainter
Algorithm which generates the same color for all vertices, which are in the same cluster.
Definition: ClusterPainter.hpp:55
FastBox.hpp
lvr2::LVRReconstructViaMarchingCubesDialog::generateMesh
void generateMesh()
Definition: LVRReconstructionMarchingCubesDialog.cpp:171
lvr2::Transformd
Transform< double > Transformd
4x4 double precision transformation matrix
Definition: MatrixTypes.hpp:71
lvr2::PointBufferPtr
std::shared_ptr< PointBuffer > PointBufferPtr
Definition: PointBuffer.hpp:130
lvr2::LVRReconstructViaMarchingCubesDialog::switchGridSizeDetermination
void switchGridSizeDetermination(int index)
Definition: LVRReconstructionMarchingCubesDialog.cpp:145
lvr2::LVRReconstructViaMarchingCubesDialog::m_pc
LVRPointCloudItem * m_pc
Definition: LVRReconstructionMarchingCubesDialog.hpp:98
lvr2::calcVertexNormals
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.
LVRItemTypes.hpp
lvr2::ProgressBar::setProgressTitleCallback
static void setProgressTitleCallback(ProgressTitleCallbackPtr)
Registers a callback that is called when a new progress instance is created.
Definition: Progress.cpp:78
lvr2::TextureFinalizer::setClusterColors
void setClusterColors(const ClusterMap< Rgb8Color > &colors)
p
SharedPointer p
Definition: ConvertShared.hpp:42
lvr2::TextureFinalizer
Definition: FinalizeAlgorithms.hpp:105
TetraederBox.hpp
lvr2::TextureFinalizer::setVertexNormals
void setVertexNormals(const VertexMap< Normal< typename BaseVecT::CoordType >> &normals)
lvr2::LVRPointCloudItem
Definition: LVRPointCloudItem.hpp:45
lvr2::MaterializerResult
Result struct for the materializer.
Definition: FinalizeAlgorithms.hpp:61
NULL
#define NULL
Definition: mydefs.hpp:141
lvr2::LVRReconstructViaMarchingCubesDialog::setProgressValue
void setProgressValue(int v)
Definition: LVRReconstructionMarchingCubesDialog.cpp:64
lvr2::Model
Definition: Model.hpp:51
HalfEdgeMesh.hpp
AdaptiveKSearchSurface.hpp
lvr2::PointsetSurfacePtr
std::shared_ptr< PointsetSurface< BaseVecT > > PointsetSurfacePtr
Definition: PointsetSurface.hpp:161
lvr2::VectorMap
A map with constant lookup overhead using small-ish integer-keys.
Definition: VectorMap.hpp:60
lvr2::ModelBridgePtr
boost::shared_ptr< LVRModelBridge > ModelBridgePtr
Definition: LVRModelBridge.hpp:120
FastReconstruction.hpp
lvr2::LVRReconstructViaMarchingCubesDialog::~LVRReconstructViaMarchingCubesDialog
virtual ~LVRReconstructViaMarchingCubesDialog()
Definition: LVRReconstructionMarchingCubesDialog.cpp:117
lvr2::ProgressBar::setProgressCallback
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
lvr2::LVRReconstructViaMarchingCubesDialog::updateProgressbar
static void updateProgressbar(int p)
Definition: LVRReconstructionMarchingCubesDialog.cpp:53
lvr2::AdaptiveKSearchSurface
A point cloud manager class that uses the STANN nearest neighbor search library to handle the data....
Definition: AdaptiveKSearchSurface.hpp:98
PointBuffer.hpp
BilinearFastBox.hpp
lvr2::LVRReconstructViaMarchingCubesDialog::progressValueChanged
void progressValueChanged(int)
lvr2::LVRReconstructViaMarchingCubesDialog::updateProgressbarTitle
static void updateProgressbarTitle(string t)
Definition: LVRReconstructionMarchingCubesDialog.cpp:58
MatrixTypes.hpp
Progress.hpp
lvr2::LVRReconstructViaMarchingCubesDialog::toggleRANSACcheckBox
void toggleRANSACcheckBox(const QString &text)
Definition: LVRReconstructionMarchingCubesDialog.cpp:131
PointsetGrid.hpp
lvr2::qttf::transform
PointBufferPtr transform(PointBufferPtr pc_in, const Transformd &T)
Definition: qttf.cpp:32
lvr2::LVRScanDataItemType
@ LVRScanDataItemType
Definition: LVRItemTypes.hpp:46
lvr2::LVRPointCloudItem::getPointBuffer
PointBufferPtr getPointBuffer()
Definition: LVRPointCloudItem.cpp:190
lvr2::LVRReconstructViaMarchingCubesDialog::m_treeWidget
QTreeWidget * m_treeWidget
Definition: LVRReconstructionMarchingCubesDialog.hpp:100
lvr2::LVRReconstructViaMarchingCubesDialog::m_generatedModel
LVRModelItem * m_generatedModel
Definition: LVRReconstructionMarchingCubesDialog.hpp:101
lvr2::LVRModelBridge
Main class for conversion of LVR model instances to vtk actors. This class parses the internal model ...
Definition: LVRModelBridge.hpp:61
lvr2::LVRReconstructViaMarchingCubesDialog::m_dialog
ReconstructViaMarchingCubesDialog * m_dialog
Definition: LVRReconstructionMarchingCubesDialog.hpp:97
lvr2::Materializer::generateMaterials
MaterializerResult< BaseVecT > generateMaterials()
Generates materials.
lvr2::LVRModelItem
Definition: LVRModelItem.hpp:47
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ModelPtr
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
lvr2::LVRReconstructViaMarchingCubesDialog::connectSignalsAndSlots
void connectSignalsAndSlots()
Definition: LVRReconstructionMarchingCubesDialog.cpp:124
lvr2::LVRReconstructViaMarchingCubesDialog::m_renderWindow
vtkRenderWindow * m_renderWindow
Definition: LVRReconstructionMarchingCubesDialog.hpp:102
lvr2::MeshBufferPtr
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
lvr2::LVRReconstructViaMarchingCubesDialog::m_progressDialog
QProgressDialog * m_progressDialog
Definition: LVRReconstructionMarchingCubesDialog.hpp:103
lvr2::qttf::getTransformation
Transformd getTransformation(QTreeWidgetItem *from, QTreeWidgetItem *to)
Definition: qttf.cpp:9
lvr2::LVRReconstructViaMarchingCubesDialog::m_decomposition
string m_decomposition
Definition: LVRReconstructionMarchingCubesDialog.hpp:96
lvr2::deleteSmallPlanarCluster
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...
lvr2::LVRReconstructViaMarchingCubesDialog::progressTitleChanged
void progressTitleChanged(const QString &)
lvr2::SharpBox
Used for extended marching cubes Reconstruction.
Definition: SharpBox.hpp:53
lvr2::TextureFinalizer::apply
MeshBufferPtr apply(const BaseMesh< BaseVecT > &mesh)
lvr2::ClusterPainter::simpsons
DenseClusterMap< Rgb8Color > simpsons(const BaseMesh< BaseVecT > &mesh) const
Assign a pseudo-color to each cluster.
lvr2::LVRReconstructViaMarchingCubesDialog::m_master
static LVRReconstructViaMarchingCubesDialog * m_master
Definition: LVRReconstructionMarchingCubesDialog.hpp:104
lvr2::TextureFinalizer::setMaterializerResult
void setMaterializerResult(const MaterializerResult< BaseVecT > &materializerResult)
mesh
HalfEdgeMesh< Vec > mesh
Definition: src/tools/lvr2_gs_reconstruction/Main.cpp:26
lvr2::ClusterBiMap
A map of clusters, which also saves a back-reference from handle to cluster.
Definition: ClusterBiMap.hpp:72
lvr2::Materializer
Class for calculating materials for each cluster of a given mesh.
Definition: Materializer.hpp:131
lvr2::calcFaceNormals
DenseFaceMap< Normal< typename BaseVecT::CoordType > > calcFaceNormals(const BaseMesh< BaseVecT > &mesh)
Calculates a normal for each face in the mesh.
lvr2::HalfEdgeMesh
Half-edge data structure implementing the BaseMesh interface.
Definition: HalfEdgeMesh.hpp:70
lvr2::BilinearFastBox
Definition: BilinearFastBox.hpp:45


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