LVRCvImageItem.cpp
Go to the documentation of this file.
1 
2 #include "LVRItemTypes.hpp"
3 #include "LVRScanDataItem.hpp"
4 #include "LVRCamDataItem.hpp"
5 
6 namespace lvr2
7 {
8 
9 LVRCvImageItem::LVRCvImageItem(std::shared_ptr<ScanDataManager> sdm, vtkSmartPointer<vtkRenderer> renderer, QString name, QTreeWidgetItem *parent) : QTreeWidgetItem(parent, LVRCvImageItemType)
10 {
11  m_name = name;
12  m_sdm = sdm;
13  m_renderer = renderer;
14  m_label = nullptr;
15  m_graphics_scene = nullptr,
16  m_graphics_view = nullptr;
17 
18  reload(renderer);
19  setText(0, m_name);
20 }
21 
22 void LVRCvImageItem::reload(vtkSmartPointer<vtkRenderer> renderer)
23 {
24 
25 }
26 
28 {
29 
30  // if(checkState(0) && visible)
31  // {
32  // m_renderer->AddActor(m_frustrum_actor);
33  // } else {
34  // m_renderer->RemoveActor(m_frustrum_actor);
35  // }
36 }
37 
39 {
40  int scan_id = -1;
41  int cam_id = -1;
42 
43  QTreeWidgetItem* parent_it = parent();
44 
45  while(parent_it != NULL)
46  {
47 
48  if(parent_it->type() == LVRCamDataItemType)
49  {
50  LVRCamDataItem* item = static_cast<LVRCamDataItem*>(parent_it);
51  cam_id = item->getCamId();
52  }
53 
54  if(parent_it->type() == LVRScanDataItemType)
55  {
56  LVRScanDataItem* item = static_cast<LVRScanDataItem*>(parent_it);
57  scan_id = item->getScanId();
58  }
59 
60  parent_it = parent_it->parent();
61  }
62 
63  if(scan_id >= 0 && cam_id >= 0)
64  {
65  if(!m_graphics_view)
66  {
69 
70  cv::Mat image = m_sdm->loadImageData(scan_id, cam_id);
71  cv::Mat cv_rgb;
72  cv::cvtColor(image, cv_rgb, cv::COLOR_BGR2RGB);
73 
74  QImage* q_image = convertCvImageToQt(cv_rgb);
75 
76  QPixmap pixmap = QPixmap::fromImage(*q_image);
77 
78  QGraphicsScene* gs = new QGraphicsScene();
79  gs->addPixmap(pixmap);
80  gs->setSceneRect(pixmap.rect());
81 
82  m_graphics_view->setScene(gs);
83  m_graphics_view->set_modifiers(Qt::NoModifier);
84  m_graphics_view->fitInView(pixmap.rect(), Qt::KeepAspectRatio);
85 
86  // connect SLOT
87 
88  QObject::connect(
91  [=]() {
92  QObject::disconnect(m_graphics_view, &LVRGraphicsView::closed, 0, 0);
93  m_graphics_view->scene()->clear();
94  m_graphics_view = nullptr;
95  }
96  );
97 
98  m_graphics_view->show();
99 
100  delete q_image;
101  }
102  } else {
103  std::cout << "Couldnt find scan_id or cam_id. cant load Image from HDF5 file." << std::endl;
104  }
105 }
106 
108 {
109  delete m_graphics_view;
110 }
111 
112 QImage* LVRCvImageItem::convertCvImageToQt(cv::Mat& cv_rgb)
113 {
114  // QImage image(input->width, input->height, QImage::Format_RGB32);
115  QImage* ret = nullptr;
116  if(cv_rgb.type() == CV_8U)
117  {
118  ret = new QImage(cv_rgb.data, cv_rgb.rows, cv_rgb.cols, cv_rgb.step, QImage::Format_Indexed8);
119  } else if(cv_rgb.type() == CV_8UC3) {
120 
121  ret = new QImage(cv_rgb.data, cv_rgb.cols, cv_rgb.rows, cv_rgb.step, QImage::Format_RGB888);
122  }
123 
124  return ret;
125 }
126 
128 {
129 
130 }
131 
133 {
134 
135 }
136 
137 } // namespace lvr2
LVRGraphicsView * m_graphics_view
void reload(vtkSmartPointer< vtkRenderer > renderer)
std::shared_ptr< ScanDataManager > m_sdm
QGraphicsScene * m_graphics_scene
void setVisibility(bool visible)
void set_modifiers(Qt::KeyboardModifiers modifiers)
LVRCvImageItem(std::shared_ptr< ScanDataManager > sdm, vtkSmartPointer< vtkRenderer > renderer, QString name="", QTreeWidgetItem *parent=NULL)
vtkSmartPointer< vtkRenderer > m_renderer
QImage * convertCvImageToQt(cv::Mat &cv_img)
#define NULL
Definition: mydefs.hpp:141


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