LVRReconstructionEstimateNormalsDialog.cpp
Go to the documentation of this file.
1 
28 #include <QFileDialog>
30 #include "LVRItemTypes.hpp"
31 
33 
34 #include "lvr2/io/DataStruct.hpp"
35 
38 
39 #if defined CUDA_FOUND
40  #define GPU_FOUND
41 
43 
45 #elif defined OPENCL_FOUND
46  #define GPU_FOUND
47 
50 #endif
51 
52 namespace lvr2
53 {
54 
55 // old
56 LVREstimateNormalsDialog::LVREstimateNormalsDialog(LVRPointCloudItem* pc, QTreeWidgetItem* parent, QTreeWidget* treeWidget, vtkRenderWindow* window) :
57  m_pc(pc), m_parent(parent), m_treeWidget(treeWidget), m_renderWindow(window)
58 {
59  m_pcs.append(pc);
60  m_parents.append(parent);
61  // Setup DialogUI and events
62  QDialog* dialog = new QDialog(m_treeWidget);
63  m_dialog = new EstimateNormalsDialog;
64  m_dialog->setupUi(dialog);
65 
67 
68  dialog->show();
69  dialog->raise();
70  dialog->activateWindow();
71 
72  // init defaults
73  toggleSpecialOptions(m_dialog->comboBox_algo_select->currentText());
74 }
75 
76 // new
78  QList<LVRPointCloudItem*> pc_items,
79  QList<QTreeWidgetItem*> parents,
80  QTreeWidget* treeWidget,
81  vtkRenderWindow* renderer
82  )
83 :m_pcs(pc_items)
84 ,m_parents(parents)
85 ,m_treeWidget(treeWidget)
86 ,m_renderWindow(renderer)
87 {
88  // Setup DialogUI and events
89  QDialog* dialog = new QDialog(m_treeWidget);
90  m_dialog = new EstimateNormalsDialog;
91  m_dialog->setupUi(dialog);
92 
94 
95  dialog->show();
96  dialog->raise();
97  dialog->activateWindow();
98 
99  // init defaults
100  toggleSpecialOptions(m_dialog->comboBox_algo_select->currentText());
101 }
102 
104 {
105  // TODO Auto-generated destructor stub
106 }
107 
109 {
110  QObject::connect(m_dialog->buttonBox, SIGNAL(accepted()), this, SLOT(estimateNormals()));
111  QObject::connect(m_dialog->checkBox_kn_auto, SIGNAL(stateChanged(int)), this, SLOT(toggleAutoNormalEstimation(int)));
112  QObject::connect(m_dialog->checkBox_ki_auto, SIGNAL(stateChanged(int)), this, SLOT(toggleAutoNormalInterpolation(int)));
113  QObject::connect(m_dialog->comboBox_algo_select, SIGNAL(currentTextChanged(QString)), this, SLOT(toggleSpecialOptions(QString)));
114 }
115 
117 {
118  QSpinBox* spinBox_kn = m_dialog->spinBox_kn;
119  if(state == Qt::Checked)
120  {
121  spinBox_kn->setEnabled(false);
122  }
123  else
124  {
125  spinBox_kn->setEnabled(true);
126  }
127 }
128 
130 {
131  QSpinBox* spinBox_ki = m_dialog->spinBox_ki;
132  if(state == Qt::Checked)
133  {
134  spinBox_ki->setEnabled(false);
135  }
136  else
137  {
138  spinBox_ki->setEnabled(true);
139  }
140 }
141 
143 {
144  std::string alog_str = current_text.toStdString();
145  if(alog_str == "GPU")
146  {
147  m_dialog->label_fp->setVisible(true);
148  m_dialog->doubleSpinBox_fp_x->setVisible(true);
149  m_dialog->doubleSpinBox_fp_y->setVisible(true);
150  m_dialog->doubleSpinBox_fp_z->setVisible(true);
151  } else {
152  m_dialog->label_fp->setVisible(false);
153  m_dialog->doubleSpinBox_fp_x->setVisible(false);
154  m_dialog->doubleSpinBox_fp_y->setVisible(false);
155  m_dialog->doubleSpinBox_fp_z->setVisible(false);
156  }
157 
158 }
159 
161 {
162  using Vec = BaseVector<float>;
163 
164  bool autoKn = m_dialog->checkBox_kn_auto->isChecked();
165  bool autoKi = m_dialog->checkBox_ki_auto->isChecked();
166  bool genNew = m_dialog->checkBox_new_item->isChecked();
167 
168  int kn = m_dialog->spinBox_kn->value();
169  int ki = m_dialog->spinBox_ki->value();
170 
171  QString algo = m_dialog->comboBox_algo_select->currentText();
172  std::string algo_str = algo.toStdString();
173 
174  // print stuff
175  std::cout << "NORMAL ESTIMATION SETTINGS: " << std::endl;
176  if(autoKn)
177  {
178  std::cout << "-- kn: auto" << std::endl;
179  } else {
180  std::cout << "-- kn: " << kn << std::endl;
181  }
182 
183  if(autoKi)
184  {
185  std::cout << "-- ki: auto" << std::endl;
186  } else {
187  std::cout << "-- ki: " << ki << std::endl;
188  }
189 
190  std::cout << "-- algo: " << algo_str << std::endl;
191 
192  for(int pc_id = 0; pc_id < m_pcs.size(); pc_id++)
193  {
194  LVRPointCloudItem* pc_item = m_pcs[pc_id];
195  QTreeWidgetItem* parent = m_parents[pc_id];
196  // create new point cloud
197  PointBufferPtr pc = pc_item->getPointBuffer();
198  size_t numPoints = pc_item->getNumPoints();
199 
200  if(genNew)
201  {
202  floatArr old_pts = pc->getPointArray();
203  // Create buffer arrays
204  floatArr points(new float[3 * numPoints]);
205 
206  // copy pts to new pointbuffer
207  std::copy(old_pts.get(), old_pts.get() + numPoints*3, points.get());
208 
209  pc.reset(new PointBuffer);
210  pc->setPointArray(points, numPoints);
211  }
212 
213  PointsetSurfacePtr<Vec> surface;
214 
215  if(algo_str == "STANN" || algo_str == "FLANN" || algo_str == "NABO" || algo_str == "NANOFLANN")
216  {
217  surface = std::make_shared<AdaptiveKSearchSurface<Vec> >(
218  pc, algo_str, kn, ki, 20, false
219  );
220  } else if(algo_str == "GPU") {
221  surface = std::make_shared<AdaptiveKSearchSurface<Vec> >(
222  pc, "FLANN", kn, ki, 20, false
223  );
224  }
225 
226  if(autoKn || autoKi)
227  {
228  const BoundingBox<Vec>& bb = surface->getBoundingBox();
229  double V = bb.getXSize() * bb.getYSize() * bb.getZSize();
230 
231  if(autoKn)
232  {
233  kn = static_cast<int>(
234  sqrt(static_cast<double>(numPoints)) / V * 400.0);
235  std::cout << "-- auto kn: " << kn << std::endl;
236  }
237 
238  if(autoKi)
239  {
240  ki = static_cast<int>(
241  sqrt(static_cast<double>(numPoints)) / V * 400.0);
242 
243  std::cout << "-- auto ki: " << ki << std::endl;
244  }
245 
246  }
247 
248  if(algo_str == "GPU")
249  {
250  #ifdef GPU_FOUND
251  // TODO
252  float fpx = static_cast<float>(m_dialog->doubleSpinBox_fp_x->value());
253  float fpy = static_cast<float>(m_dialog->doubleSpinBox_fp_y->value());
254  float fpz = static_cast<float>(m_dialog->doubleSpinBox_fp_z->value());
255 
256  std::vector<float> flipPoint = {fpx, fpy, fpz};
257  size_t num_points = pc->numPoints();
258  floatArr points = pc->getPointArray();
259  floatArr normals = floatArr(new float[ num_points * 3 ]);
260  std::cout << timestamp << "Generate GPU kd-tree..." << std::endl;
261  GpuSurface gpu_surface(points, num_points);
262 
263  gpu_surface.setKn(kn);
264  gpu_surface.setKi(ki);
265  gpu_surface.setFlippoint(flipPoint[0], flipPoint[1], flipPoint[2]);
266 
267  std::cout << timestamp << "Calculated normals..." << std::endl;
268  gpu_surface.calculateNormals();
269  gpu_surface.getNormals(normals);
270 
271  pc->setNormalArray(normals, num_points);
272  gpu_surface.freeGPU();
273 
274  #else
275  std::cout << "ERROR: GPU Driver not installed, using FLANN instead" << std::endl;
276  surface->calculateSurfaceNormals();
277  #endif
278  } else {
279  surface->calculateSurfaceNormals();
280  }
281 
282  if(genNew)
283  {
284  ModelPtr model(new Model(pc));
285 
286  ModelBridgePtr bridge(new LVRModelBridge(model));
287  vtkSmartPointer<vtkRenderer> renderer = m_renderWindow->GetRenderers()->GetFirstRenderer();
288  bridge->addActors(renderer);
289 
290  QString base;
291  if (parent->type() == LVRModelItemType)
292  {
293  LVRModelItem *model_item = static_cast<LVRModelItem *>(parent);
294  base = model_item->getName() + " (w. normals)";
295  m_pointCloudWithNormals = new LVRModelItem(bridge, base);
296  m_pointCloudWithNormals->setPose(model_item->getPose());
297  }
298  else if (parent->type() == LVRScanDataItemType)
299  {
300  LVRScanDataItem *sd_item = static_cast<LVRScanDataItem *>(parent);
301  base = sd_item->getName() + " (w. normals)";
302  m_pointCloudWithNormals = new LVRModelItem(bridge, base);
304  }
305 
306  m_treeWidget->addTopLevelItem(m_pointCloudWithNormals);
307  m_pointCloudWithNormals->setExpanded(true);
308 
309  } else {
310 
311  if(parent->type() == LVRScanDataItemType)
312  {
313  // pc_item->update();
314  LVRScanDataItem *sd_item = static_cast<LVRScanDataItem *>(parent);
315  sd_item->reload();
316  } else {
317  vtkSmartPointer<vtkRenderer> renderer = m_renderWindow->GetRenderers()->GetFirstRenderer();
318  renderer->RemoveActor(pc_item->getPointBufferBridge()->getPointCloudActor());
319  pc_item->update();
320  renderer->AddActor(pc_item->getPointBufferBridge()->getPointCloudActor());
321  }
322 
323  }
324 
325  m_renderWindow->Render();
326 
327  std::cout << timestamp << "Finished." << std::endl;
328 
329  // m_renderWindow->GetRenderers()->GetFirstRenderer()->render();
330 
331  }
332 }
333 
334 } // namespace lvr2
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
BaseVector.hpp
CudaSurface.hpp
lvr2::LVRPointCloudItem::getPointBufferBridge
PointBufferBridgePtr getPointBufferBridge()
Definition: LVRPointCloudItem.cpp:195
PointsetSurface.hpp
lvr2::BaseVector< float >
lvr2::LVRPointCloudItem::getNumPoints
size_t getNumPoints()
Definition: LVRPointCloudItem.cpp:185
lvr2::LVRModelItem::setPose
void setPose(const Pose &pose)
Definition: LVRModelItem.cpp:100
LVRReconstructionEstimateNormalsDialog.hpp
lvr2::PointBufferPtr
std::shared_ptr< PointBuffer > PointBufferPtr
Definition: PointBuffer.hpp:130
lvr2::LVREstimateNormalsDialog::m_pcs
QList< LVRPointCloudItem * > m_pcs
Definition: LVRReconstructionEstimateNormalsDialog.hpp:77
lvr2::LVRModelItemType
@ LVRModelItemType
Definition: LVRItemTypes.hpp:40
LVRItemTypes.hpp
lvr2::LVREstimateNormalsDialog::m_dialog
EstimateNormalsDialog * m_dialog
Definition: LVRReconstructionEstimateNormalsDialog.hpp:74
lvr2::PointBuffer
A class to handle point information with an arbitrarily large number of attribute channels....
Definition: PointBuffer.hpp:51
GpuSurface
CudaSurface GpuSurface
Definition: src/tools/lvr2_cuda_normals/Main.cpp:60
lvr2::LVRPointCloudItem
Definition: LVRPointCloudItem.hpp:45
lvr2::CudaSurface
Definition: CudaSurface.hpp:78
lvr2::Model
Definition: Model.hpp:51
ClSurface.hpp
lvr2::LVREstimateNormalsDialog::~LVREstimateNormalsDialog
virtual ~LVREstimateNormalsDialog()
Definition: LVRReconstructionEstimateNormalsDialog.cpp:103
lvr2::LVRScanDataItem::getPose
Pose getPose()
Definition: LVRScanDataItem.hpp:46
lvr2::BoundingBox::getXSize
BaseVecT::CoordType getXSize() const
Returns the x-size of the bounding box.
AdaptiveKSearchSurface.hpp
lvr2::PointsetSurfacePtr
std::shared_ptr< PointsetSurface< BaseVecT > > PointsetSurfacePtr
Definition: PointsetSurface.hpp:161
lvr2::LVREstimateNormalsDialog::toggleAutoNormalEstimation
void toggleAutoNormalEstimation(int state)
Definition: LVRReconstructionEstimateNormalsDialog.cpp:116
lvr2::ModelBridgePtr
boost::shared_ptr< LVRModelBridge > ModelBridgePtr
Definition: LVRModelBridge.hpp:120
lvr2::BoundingBox::getYSize
BaseVecT::CoordType getYSize() const
Returns the y-size of the bounding box.
lvr2::LVRPointCloudItem::update
void update()
Definition: LVRPointCloudItem.cpp:100
lvr2::ClSurface
Definition: ClSurface.hpp:63
lvr2::LVREstimateNormalsDialog::m_parents
QList< QTreeWidgetItem * > m_parents
Definition: LVRReconstructionEstimateNormalsDialog.hpp:79
lvr2::LVRScanDataItem
Definition: LVRScanDataItem.hpp:25
lvr2::LVREstimateNormalsDialog::connectSignalsAndSlots
void connectSignalsAndSlots()
Definition: LVRReconstructionEstimateNormalsDialog.cpp:108
lvr2::timestamp
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
DataStruct.hpp
Datastructures for holding loaded data.
lvr2::LVRScanDataItem::getName
QString getName()
Definition: LVRScanDataItem.hpp:44
lvr2::LVREstimateNormalsDialog::toggleSpecialOptions
void toggleSpecialOptions(QString current_text)
Definition: LVRReconstructionEstimateNormalsDialog.cpp:142
lvr2::LVREstimateNormalsDialog::toggleAutoNormalInterpolation
void toggleAutoNormalInterpolation(int state)
Definition: LVRReconstructionEstimateNormalsDialog.cpp:129
lvr2::LVREstimateNormalsDialog::LVREstimateNormalsDialog
LVREstimateNormalsDialog(LVRPointCloudItem *pc_item, QTreeWidgetItem *parent, QTreeWidget *treeWidget, vtkRenderWindow *renderer)
Definition: LVRReconstructionEstimateNormalsDialog.cpp:56
lvr2::LVRScanDataItemType
@ LVRScanDataItemType
Definition: LVRItemTypes.hpp:46
lvr2::BoundingBox
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
lvr2::LVRPointCloudItem::getPointBuffer
PointBufferPtr getPointBuffer()
Definition: LVRPointCloudItem.cpp:190
lvr2::LVREstimateNormalsDialog::m_treeWidget
QTreeWidget * m_treeWidget
Definition: LVRReconstructionEstimateNormalsDialog.hpp:85
lvr2::BoundingBox::getZSize
BaseVecT::CoordType getZSize() const
Returns the z-size of the bounding box.
lvr2::LVRModelItem::getPose
Pose getPose()
Definition: LVRModelItem.cpp:95
lvr2::LVRModelBridge
Main class for conversion of LVR model instances to vtk actors. This class parses the internal model ...
Definition: LVRModelBridge.hpp:61
lvr2::LVRModelItem
Definition: LVRModelItem.hpp:47
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ModelPtr
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
lvr2::LVREstimateNormalsDialog::m_renderWindow
vtkRenderWindow * m_renderWindow
Definition: LVRReconstructionEstimateNormalsDialog.hpp:86
lvr2::LVRScanDataItem::reload
void reload()
Definition: LVRScanDataItem.cpp:58
lvr2::LVRModelItem::getName
QString getName()
Definition: LVRModelItem.cpp:109
lvr2::LVREstimateNormalsDialog::m_pointCloudWithNormals
LVRModelItem * m_pointCloudWithNormals
Definition: LVRReconstructionEstimateNormalsDialog.hpp:83
lvr2::LVREstimateNormalsDialog::estimateNormals
void estimateNormals()
Definition: LVRReconstructionEstimateNormalsDialog.cpp:160


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