NorMIT-nav  18.04
An IGT application
cxProbeAdapterRTSource.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 
12 
13 #include "cxProbeAdapterRTSource.h"
14 #include <vtkImageChangeInformation.h>
15 #include <vtkImageData.h>
16 
17 #include "cxTool.h"
18 #include "cxTypeConversions.h"
19 #include "cxLogger.h"
20 #include "cxData.h"
21 
22 
23 namespace cx
24 {
25 
27  mUid(uid), mBase(source), mProbe(probe)
28 {
29  connect(probe.get(), &Probe::sectorChanged, this, &ProbeAdapterRTSource::probeChangedSlot);
30 
31  connect(mBase.get(), &VideoSource::streaming, this, &VideoSource::streaming);
32  connect(mBase.get(), &VideoSource::connected, this, &VideoSource::connected);
33  connect(mBase.get(), &VideoSource::newFrame, this, &VideoSource::newFrame);
34  connect(mBase.get(), &VideoSource::newFrame, this, &ProbeAdapterRTSource::newFrameSlot);
35 
36  mRedirecter = vtkImageChangeInformationPtr::New();
37  mRedirecter->SetInputData(mBase->getVtkImageData());
38  this->probeChangedSlot();
39 }
40 
42 {
43  disconnect(mBase.get(), &VideoSource::streaming, this, &VideoSource::streaming);
44  disconnect(mBase.get(), &VideoSource::connected, this, &VideoSource::connected);
45  disconnect(mBase.get(), &VideoSource::newFrame, this, &VideoSource::newFrame);
46  disconnect(mBase.get(), &VideoSource::newFrame, this, &ProbeAdapterRTSource::newFrameSlot);
47 }
48 
50 {
51  return mUid;
52 }
53 
55 {
56  return mBase->getName();
57 }
58 
60 {
61  return mRedirecter->GetOutput();
62 }
63 
65 {
66  QString uid = mBase->getUid();
67  ProbePtr probe = mProbe.lock();
68  if (probe)
69  return mBase->getTimestamp() - probe->getProbeDefinition(uid).getTemporalCalibration();
70  else
71  return mBase->getTimestamp();
72 }
73 
75 {
76  TimeInfo retval;
77  retval.mAcquisitionTime.setMSecsSinceEpoch(this->getTimestamp());
78  return retval;
79 }
80 
82 {
83  return mBase->getInfoString();
84 }
85 
87 {
88  return mBase->getStatusString();
89 }
90 
92 {
93  mBase->start();
94 }
95 
97 {
98  mBase->stop();
99 }
100 
102 {
103  return mBase->validData();
104 }
105 
107 {
108  return mBase->isConnected();
109 }
110 
112 {
113  return mBase->isStreaming();
114 }
115 
117 {
118  return mBase;
119 }
120 
121 void ProbeAdapterRTSource::newFrameSlot()
122 {
123  ProbePtr probe = mProbe.lock();
124  if (!probe)
125  return;
126  if (!this->validData())
127  return;
128 
129  mRedirecter->Update();
130 
131  QString uid = mBase->getUid();
132  ProbeDefinition data = probe->getProbeDefinition(uid);
133  QSize dimProbe = data.getSize();
134  QSize dimImage(mRedirecter->GetOutput()->GetDimensions()[0], mRedirecter->GetOutput()->GetDimensions()[1]);
135 
136  if (dimProbe!=dimImage)
137  {
138  report(
139  QString("Resampling probe calibration. Calibration:[%1,%2], Image:[%3,%4], uid=%5")
140  .arg(dimProbe.width())
141  .arg(dimProbe.height())
142  .arg(dimImage.width())
143  .arg(dimImage.height())
144  .arg(uid));
145 
146  data.resample(dimImage);
147  probe->setProbeDefinition(data);
148  }
149 
150 }
151 
152 void ProbeAdapterRTSource::probeChangedSlot()
153 {
154  ProbePtr probe = mProbe.lock();
155  if (!probe)
156  return;
157 
158  mRedirecter->Update();
159 
160  QString uid = mBase->getUid();
161  mRedirecter->SetOutputSpacing(probe->getProbeDefinition(uid).getSpacing().begin());
162 
163  mRedirecter->Update();
164 }
165 
166 }
void connected(bool on)
emitted when source is connected/disconnected
virtual QString getInfoString() const
an information text intended to be visible along with the data stream at all times ...
void streaming(bool on)
emitted when streaming started/stopped
virtual bool validData() const
return true is data stream is ok to display. This is a heuristic based on the data rate...
virtual void stop()
stop streaming
void resample(QSize mSize)
Set a new image size. Resample all other parameters to match this new image size, keeping sizes in mi...
boost::shared_ptr< Probe > ProbePtr
Definition: cxProbe.h:72
virtual void start()
start streaming
virtual bool isConnected() const
return true when a connection to the data source is established.
virtual TimeInfo getAdvancedTimeInfo()
virtual QString getStatusString() const
status text describing the stream state, display instead of stream when the stream is invalid...
ProbeAdapterRTSource(QString uid, ProbePtr probe, VideoSourcePtr source)
boost::shared_ptr< class VideoSource > VideoSourcePtr
void sectorChanged()
< Return a ProbeSectorPtr for the given uid. Use &#39;active&#39; to get the default.
Definition of characteristics for an Ultrasound Probe Sector.
QDateTime mAcquisitionTime
Possibly modified time stamp.
Definition: cxData.h:44
virtual vtkImageDataPtr getVtkImageData()
void report(QString msg)
Definition: cxLogger.cpp:69
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
void newFrame()
emitted when a new frame has arrived (getVtkImageData() returns something new). info/status/name/vali...
virtual bool isStreaming() const
return true when the source is streaming data.
Namespace for all CustusX production code.