LVROptimizationPlanarOptimizationDialog.cpp
Go to the documentation of this file.
1 
28 #include <QFileDialog>
30 
36 
39 
40 #include "lvr2/io/Model.hpp"
41 
43 
44 namespace lvr2
45 {
46 
47 LVRPlanarOptimizationDialog::LVRPlanarOptimizationDialog(LVRMeshItem* mesh, LVRModelItem* parent, QTreeWidget* treeWidget, vtkRenderWindow* window) :
48  m_mesh(mesh), m_parent(parent), m_treeWidget(treeWidget), m_renderWindow(window)
49 {
50  // Setup DialogUI and events
51  QDialog* dialog = new QDialog(m_treeWidget);
52  m_dialog = new PlanarOptimizationDialog;
53  m_dialog->setupUi(dialog);
54 
56 
57  dialog->show();
58  dialog->raise();
59  dialog->activateWindow();
60 }
61 
63 {
64  // TODO Auto-generated destructor stub
65 }
66 
68 {
69  QObject::connect(m_dialog->buttonBox, SIGNAL(accepted()), this, SLOT(optimizeMesh()));
70  QObject::connect(m_dialog->checkBox_sr, SIGNAL(stateChanged(int)), this, SLOT(toggleSmallRegionRemoval(int)));
71  QObject::connect(m_dialog->checkBox_rt, SIGNAL(stateChanged(int)), this, SLOT(toggleRetesselation(int)));
72 }
73 
75 {
76  QSpinBox* smallRegionRemoval_box = m_dialog->spinBox_sr;
77  if(state == Qt::Checked)
78  {
79  smallRegionRemoval_box->setEnabled(true);
80  }
81  else
82  {
83  smallRegionRemoval_box->setEnabled(false);
84  }
85 }
86 
88 {
89  QCheckBox* generateTextures_box = m_dialog->checkBox_gt;
90  QDoubleSpinBox* lineSegmentThreshold_box = m_dialog->doubleSpinBox_ls;
91  if(state == Qt::Checked)
92  {
93  generateTextures_box->setEnabled(true);
94  lineSegmentThreshold_box->setEnabled(true);
95  }
96  else
97  {
98  generateTextures_box->setEnabled(false);
99  lineSegmentThreshold_box->setEnabled(false);
100  }
101 }
102 
104 {
105  QSpinBox* planeIterations_box = m_dialog->spinBox_pi;
106  int planeIterations = planeIterations_box->value();
107  QDoubleSpinBox* normalThreshold_box = m_dialog->doubleSpinBox_nt;
108  float normalThreshold = (float)normalThreshold_box->value();
109  QSpinBox* minimalPlaneSize_box = m_dialog->spinBox_mp;
110  int minimalPlaneSize = minimalPlaneSize_box->value();
111  QCheckBox* removeSmallRegions_box = m_dialog->checkBox_sr;
112  bool removeSmallRegions = removeSmallRegions_box->isChecked();
113  QSpinBox* removeSmallRegionThreshold_box = m_dialog->spinBox_sr;
114  int removeSmallRegionThreshold = (removeSmallRegions) ? removeSmallRegionThreshold_box->value() : 0;
115  QCheckBox* fillHoles_box = m_dialog->checkBox_fh;
116  bool fillHoles = fillHoles_box->isChecked();
117  QCheckBox* retesselate_box = m_dialog->checkBox_rt;
118  bool retesselate = retesselate_box->isChecked();
119  QCheckBox* generateTextures_box = m_dialog->checkBox_gt;
120  bool generateTextures = generateTextures_box->isChecked();
121  QDoubleSpinBox* lineSegmentThreshold_box = m_dialog->doubleSpinBox_ls;
122  float lineSegmentThreshold = (float)lineSegmentThreshold_box->value();
123 
124  using Vec = BaseVector<float>;
125 
127 
128  if (fillHoles)
129  {
130  // variable for max_size?
131  // TODO happended in old code right after deletesmallPlanarCluster.
132  //int res = naiveFillSmallHoles(mesh, 1);
133  }
134 
135  auto faceNormals = calcFaceNormals(mesh);
137  mesh,
138  faceNormals,
139  normalThreshold,
140  planeIterations,
141  minimalPlaneSize
142  );
143 
144  if (removeSmallRegions && removeSmallRegionThreshold > 0)
145  {
146  deleteSmallPlanarCluster(mesh, clusterBiMap, removeSmallRegionThreshold);
147  }
148 
149 
150  // TODO idk what the lvr2 equivalent to this is?
151  //mesh.restorePlanes(minimalPlaneSize);
152 
153  // Save triangle mesh
154  if(retesselate)
155  {
156  Tesselator<Vec>::apply(mesh, clusterBiMap, faceNormals, lineSegmentThreshold);
157  }
158 
159  MeshBufferPtr res;
160  if (generateTextures)
161  {
162  // TODO Use TextureFinalizer...
164  res = fin.apply(mesh);
165  }
166  else
167  {
169  res = fin.apply(mesh);
170  }
171 
172  ModelPtr model(new Model(res));
173  ModelBridgePtr bridge(new LVRModelBridge(model));
174  vtkSmartPointer<vtkRenderer> renderer = m_renderWindow->GetRenderers()->GetFirstRenderer();
175  bridge->addActors(renderer);
176 
177  QString base = m_parent->getName() + " (optimized)";
178  m_optimizedModel = new LVRModelItem(bridge, base);
179 
180  m_treeWidget->addTopLevelItem(m_optimizedModel);
181  m_optimizedModel->setExpanded(true);
182 }
183 
184 } // namespace lvr2
LVRPlanarOptimizationDialog(LVRMeshItem *mesh, LVRModelItem *parent, QTreeWidget *treeWidget, vtkRenderWindow *renderer)
ClusterBiMap< FaceHandle > iterativePlanarClusterGrowing(BaseMesh< BaseVecT > &mesh, FaceMap< Normal< typename BaseVecT::CoordType >> &normals, float minSinAngle, int numIterations, int minClusterSize)
Algorithm which generates planar clusters from the given mesh, drags points in clusters into regressi...
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
static void apply(BaseMesh< BaseVecT > &mesh, ClusterBiMap< FaceHandle > &clusters, DenseFaceMap< Normal< typename BaseVecT::CoordType >> &faceNormals, float lineFusionThreshold)
DenseFaceMap< Normal< typename BaseVecT::CoordType > > calcFaceNormals(const BaseMesh< BaseVecT > &mesh)
Calculates a normal for each face in the mesh.
MeshBufferPtr apply(const BaseMesh< BaseVecT > &mesh)
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.
boost::shared_ptr< LVRModelBridge > ModelBridgePtr
Half-edge data structure implementing the BaseMesh interface.
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
MeshBufferPtr getMeshBuffer()


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