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
lvr2::LVRCvImageItem::reload
void reload(vtkSmartPointer< vtkRenderer > renderer)
Definition: LVRCvImageItem.cpp:22
lvr2::LVRCvImageItem::setVisibility
void setVisibility(bool visible)
Definition: LVRCvImageItem.cpp:27
lvr2::LVRCvImageItem::m_name
QString m_name
Definition: LVRCvImageItem.hpp:53
lvr2::LVRScanDataItem::getScanId
size_t getScanId()
Definition: LVRScanDataItem.hpp:42
lvr2::LVRCamDataItem::getCamId
size_t getCamId()
Definition: LVRCamDataItem.hpp:56
LVRItemTypes.hpp
lvr2::LVRCvImageItem::m_label
QLabel * m_label
Definition: LVRCvImageItem.hpp:57
NULL
#define NULL
Definition: mydefs.hpp:141
lvr2::LVRCamDataItemType
@ LVRCamDataItemType
Definition: LVRItemTypes.hpp:47
lvr2::LVRCvImageItem::LVRCvImageItem
LVRCvImageItem(std::shared_ptr< ScanDataManager > sdm, vtkSmartPointer< vtkRenderer > renderer, QString name="", QTreeWidgetItem *parent=NULL)
Definition: LVRCvImageItem.cpp:9
lvr2::LVRCvImageItem::openWindow
void openWindow()
Definition: LVRCvImageItem.cpp:38
lvr2::LVRGraphicsView
Definition: LVRGraphicsView.hpp:12
lvr2::LVRScanDataItem
Definition: LVRScanDataItem.hpp:25
lvr2::LVRCvImageItem::~LVRCvImageItem
~LVRCvImageItem()
Definition: LVRCvImageItem.cpp:132
LVRScanDataItem.hpp
lvr2::LVRCvImageItemType
@ LVRCvImageItemType
Definition: LVRItemTypes.hpp:50
lvr2::LVRScanDataItemType
@ LVRScanDataItemType
Definition: LVRItemTypes.hpp:46
lvr2::LVRCvImageItem::m_sdm
std::shared_ptr< ScanDataManager > m_sdm
Definition: LVRCvImageItem.hpp:54
lvr2::LVRGraphicsView::set_modifiers
void set_modifiers(Qt::KeyboardModifiers modifiers)
Definition: LVRGraphicsView.cpp:28
lvr2::LVRCvImageItem::convertCvImageToQt
QImage * convertCvImageToQt(cv::Mat &cv_img)
Definition: LVRCvImageItem.cpp:112
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::LVRCvImageItem::m_graphics_scene
QGraphicsScene * m_graphics_scene
Definition: LVRCvImageItem.hpp:58
LVRCamDataItem.hpp
lvr2::LVRGraphicsView::init
void init()
Definition: LVRGraphicsView.cpp:10
lvr2::LVRCvImageItem::m_renderer
vtkSmartPointer< vtkRenderer > m_renderer
Definition: LVRCvImageItem.hpp:56
lvr2::LVRCvImageItem::closeWindow
void closeWindow()
Definition: LVRCvImageItem.cpp:107
lvr2::LVRCvImageItem::graphicsViewClosed
void graphicsViewClosed()
Definition: LVRCvImageItem.cpp:127
lvr2::LVRCvImageItem::m_graphics_view
LVRGraphicsView * m_graphics_view
Definition: LVRCvImageItem.hpp:59
lvr2::LVRCamDataItem
Definition: LVRCamDataItem.hpp:36
lvr2::LVRGraphicsView::closed
void closed()


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