LVRScanDataItem.cpp
Go to the documentation of this file.
1 #include "LVRScanDataItem.hpp"
2 #include "LVRModelItem.hpp"
3 #include "LVRItemTypes.hpp"
4 
6 
7 namespace lvr2
8 {
9 
11  ScanPtr data, std::shared_ptr<ScanDataManager> sdm, size_t idx,
12  vtkSmartPointer<vtkRenderer> renderer,
13  QString name, QTreeWidgetItem *parent)
14  : QTreeWidgetItem(parent, LVRScanDataItemType) ,m_renderer(renderer)
15 {
16  m_showSpectralsItem = nullptr;
17  m_pcItem = nullptr;
18  m_pItem = nullptr;
19  m_bbItem = nullptr;
20  m_data = data;
21  m_name = name;
22  m_sdm = sdm;
23  m_idx = idx;
24 
25 
26  // init pose
27  double pose[6];
28  eigenToEuler<double>(m_data->registration, pose);
29 
30  m_matrix = m_data->registration;
31 
32  m_pose.x = pose[0];
33  m_pose.y = pose[1];
34  m_pose.z = pose[2];
35  m_pose.r = pose[3] * 57.295779513;
36  m_pose.t = pose[4] * 57.295779513;
37  m_pose.p = pose[5] * 57.295779513;
38 
40 
42 
43  // init bb
45  m_bbItem = new LVRBoundingBoxItem(m_bb, "Bounding Box", this);
46  renderer->AddActor(m_bb->getActor());
47  m_bb->setPose(m_pose);
48 
49  setTransform(m_matrix);
50 
51  // load data
52  reload();
53 
54  setText(0, m_name);
55  setCheckState(0, Qt::Checked);
56 }
57 
59 {
61 }
62 
63 void LVRScanDataItem::reload(vtkSmartPointer<vtkRenderer> renderer)
64 {
65  if (m_model)
66  {
67  m_model->removeActors(renderer);
68  }
69 
70  if (m_pcItem)
71  {
72  delete m_pcItem;
73  }
74 
76  {
77  delete m_showSpectralsItem;
78  m_showSpectralsItem = nullptr;
79  }
80 
81  if (m_data->points)
82  {
83  m_model = ModelBridgePtr(new LVRModelBridge( ModelPtr( new Model(m_data->points))));
84  m_pcItem = new LVRPointCloudItem(m_model->getPointBridge(), this);
85 
86  m_model->addActors(renderer);
87  m_model->setTransform(m_matrix);
88 
89  if (!isPointCloudLoaded())
90  {
91  setText(1, "(Preview)");
92  }
93 
94  if (m_data->points->getUCharChannel("spectral_channels"))
95  {
96  m_showSpectralsItem = new QTreeWidgetItem(this);
97  m_showSpectralsItem->setText(0, "Spectrals");
98  m_showSpectralsItem->setCheckState(0, Qt::Checked);
99  }
100  }
101 }
102 
104 {
105  return m_data->pointsLoaded;
106 }
107 
108 void LVRScanDataItem::loadPointCloudData(vtkSmartPointer<vtkRenderer> renderer)
109 {
110  m_sdm->loadPointCloudData(m_data);
111 
112  if (isPointCloudLoaded())
113  {
114  reload(renderer);
115 
116  setText(1, "");
117  }
118 }
119 
120 void LVRScanDataItem::unloadPointCloudData(vtkSmartPointer<vtkRenderer> renderer)
121 {
122  m_sdm->loadPointCloudData(m_data, true);
123 
124  reload(renderer);
125 }
126 
128 {
129  return m_model;
130 }
131 
132 void LVRScanDataItem::setVisibility(bool visible, bool pc_visible)
133 {
134  if (!this->checkState(0))
135  {
136  visible = false;
137  }
138 
139  for (int i = 0; i < childCount(); i++)
140  {
141  QTreeWidgetItem* item = child(i);
142 
143  if(item->type() == LVRCamerasItemType)
144  {
145  for(int j=0; j < item->childCount(); j++)
146  {
147  QTreeWidgetItem* cam_item = item->child(j);
148 
149  if(cam_item->type() == LVRCamDataItemType)
150  {
151  LVRCamDataItem* cam_item_c = static_cast<LVRCamDataItem*>(cam_item);
152  cam_item_c->setVisibility(visible);
153  }
154 
155  }
156  }
157 
158  item->setHidden(!visible);
159  }
160 
161  if (m_model)
162  {
163  m_model->setVisibility(pc_visible && visible);
164  }
165 
167  {
168  m_model->getPointBridge()->setColorsVisibility(m_showSpectralsItem->checkState(0));
169  }
170 
171  if (m_bbItem)
172  {
173  m_bbItem->setVisibility(visible);
174  }
175 
176 }
177 
179 {
180  // we don't want to do delete m_bbItem, m_pItem and m_pcItem here
181  // because QTreeWidgetItem deletes its childs automatically in its destructor.
182 }
183 
184 } // namespace lvr2
LVRScanDataItem(ScanPtr data, std::shared_ptr< ScanDataManager > sdm, size_t idx, vtkSmartPointer< vtkRenderer > renderer, QString name="", QTreeWidgetItem *parent=NULL)
ModelBridgePtr getModelBridgePtr()
std::shared_ptr< ScanDataManager > m_sdm
QTreeWidgetItem * m_showSpectralsItem
LVRBoundingBoxItem * m_bbItem
void setVisibility(bool visible)
std::shared_ptr< Scan > ScanPtr
Shared pointer to scans.
Definition: ScanTypes.hpp:98
Main class for conversion of LVR model instances to vtk actors. This class parses the internal model ...
void setTransform(Eigen::Matrix< T, 4, 4 > transform)
boost::shared_ptr< LVRModelBridge > ModelBridgePtr
void setVisibility(bool visible)
void loadPointCloudData(vtkSmartPointer< vtkRenderer > renderer)
void setPose(const Pose &pose)
Definition: LVRPoseItem.cpp:69
vtkSmartPointer< vtkRenderer > m_renderer
void setVisibility(bool visible, bool pc_visible)
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
BoundingBoxBridgePtr m_bb
LVRPointCloudItem * m_pcItem
boost::shared_ptr< LVRBoundingBoxBridge > BoundingBoxBridgePtr
void unloadPointCloudData(vtkSmartPointer< vtkRenderer > renderer)


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