NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxLayoutVideoSource.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #include "cxLayoutVideoSource.h"
13 #include "cxViewCollectionWidget.h"
14 #include "vtkImageData.h"
15 #include "cxLogger.h"
16 
17 namespace cx
18 {
19 
21  mWidget(widget),
22  mStreaming(false)
23 {
24  CX_ASSERT(widget);
25  connect(mWidget.data(), &ViewCollectionWidget::rendered, this, &LayoutVideoSource::onRendered);
26 }
27 
29 {
30  return QString("LayoutVideoSource%1").arg(reinterpret_cast<long>(this));
31 }
32 
34 {
35  return QString("LayoutVideoSource");
36 }
37 
39 {
40  return mTimestamp.toMSecsSinceEpoch();
41 }
42 
44 {
45  return TimeInfo(mTimestamp.toMSecsSinceEpoch());
46 }
47 
49 {
50  if (mStreaming)
51  return;
52 
53  mStreaming = true;
54  emit streaming(mStreaming);
55 }
56 
58 {
59  if (!mStreaming)
60  return;
61 
62  mGrabbed = vtkImageDataPtr();
63  mStreaming = false;
64  emit streaming(mStreaming);
65 }
66 
68 {
69  return mStreaming;
70 }
71 
73 {
74  return true;
75 }
76 
78 {
79  return mStreaming;
80 }
81 
82 void LayoutVideoSource::onRendered()
83 {
84  if (!mStreaming)
85  return;
86 
87  mGrabbed = vtkImageDataPtr();
88  mTimestamp = QDateTime::currentDateTime();
89  emit newFrame();
90 }
91 
93 {
94  if (!mStreaming)
95  return vtkImageDataPtr();
96 
97  if (!mGrabbed)
98  {
99  ViewCollectionImageWriter grabber(mWidget);
100  mGrabbed = grabber.grab();
101  }
102  return mGrabbed;
103 }
104 
105 } // namespace cx
cx::VideoSource::newFrame
void newFrame()
emitted when a new frame has arrived (getVtkImageData() returns something new). info/status/name/vali...
cxLogger.h
CX_ASSERT
#define CX_ASSERT(statement)
Definition: cxLogger.h:116
cx::LayoutVideoSource::getUid
virtual QString getUid()
Definition: cxLayoutVideoSource.cpp:28
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::LayoutVideoSource::start
virtual void start()
start streaming
Definition: cxLayoutVideoSource.cpp:48
cx::LayoutVideoSource::getAdvancedTimeInfo
virtual TimeInfo getAdvancedTimeInfo()
Definition: cxLayoutVideoSource.cpp:43
cx::LayoutVideoSource::getVtkImageData
virtual vtkImageDataPtr getVtkImageData()
Definition: cxLayoutVideoSource.cpp:92
cx::LayoutVideoSource::isConnected
virtual bool isConnected() const
return true when a connection to the data source is established.
Definition: cxLayoutVideoSource.cpp:72
vtkImageDataPtr
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
Definition: cxVideoConnectionWidget.h:30
cx::LayoutVideoSource::stop
virtual void stop()
stop streaming
Definition: cxLayoutVideoSource.cpp:57
cxViewCollectionWidget.h
cx::LayoutVideoSource::getName
virtual QString getName()
Definition: cxLayoutVideoSource.cpp:33
cx::LayoutVideoSource::LayoutVideoSource
LayoutVideoSource(ViewCollectionWidget *widget)
Definition: cxLayoutVideoSource.cpp:20
cxLayoutVideoSource.h
cx::TimeInfo
Definition: cxData.h:43
cx::LayoutVideoSource::validData
virtual bool validData() const
return true is data stream is ok to display. This is a heuristic based on the data rate.
Definition: cxLayoutVideoSource.cpp:67
cx::LayoutVideoSource::getTimestamp
virtual double getTimestamp()
Definition: cxLayoutVideoSource.cpp:38
cxViewCollectionImageWriter.h
cx::LayoutVideoSource::isStreaming
virtual bool isStreaming() const
return true when the source is streaming data.
Definition: cxLayoutVideoSource.cpp:77
cx::ViewCollectionImageWriter::grab
vtkImageDataPtr grab()
Definition: cxViewCollectionImageWriter.cpp:44
cx::ViewCollectionWidget::rendered
void rendered()
cx::VideoSource::streaming
void streaming(bool on)
emitted when streaming started/stopped
cx::ViewCollectionImageWriter
Definition: cxViewCollectionImageWriter.h:34
cx::ViewCollectionWidget
Definition: cxViewCollectionWidget.h:39