Fraxinus  18.10
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
virtual TimeInfo getAdvancedTimeInfo()
virtual void stop()
stop streaming
#define CX_ASSERT(statement)
Definition: cxLogger.h:116
virtual bool isConnected() const
return true when a connection to the data source is established.
void streaming(bool on)
emitted when streaming started/stopped
virtual vtkImageDataPtr getVtkImageData()
LayoutVideoSource(ViewCollectionWidget *widget)
virtual void start()
start streaming
virtual double getTimestamp()
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
virtual bool isStreaming() const
return true when the source is streaming data.
virtual bool validData() const
return true is data stream is ok to display. This is a heuristic based on the data rate...
void newFrame()
emitted when a new frame has arrived (getVtkImageData() returns something new). info/status/name/vali...
Namespace for all CustusX production code.