Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 #include "cxProbeAdapterRTSource.h"
35 #include <vtkImageChangeInformation.h>
36 #include <vtkImageData.h>
37 
38 #include "cxTool.h"
39 #include "cxTypeConversions.h"
40 #include "cxLogger.h"
41 #include "cxData.h"
42 
43 
44 namespace cx
45 {
46 
48  mUid(uid), mBase(source), mProbe(probe)
49 {
50  connect(probe.get(), &Probe::sectorChanged, this, &ProbeAdapterRTSource::probeChangedSlot);
51 
52  connect(mBase.get(), &VideoSource::streaming, this, &VideoSource::streaming);
53  connect(mBase.get(), &VideoSource::connected, this, &VideoSource::connected);
54  connect(mBase.get(), &VideoSource::newFrame, this, &VideoSource::newFrame);
55  connect(mBase.get(), &VideoSource::newFrame, this, &ProbeAdapterRTSource::newFrameSlot);
56 
57  mRedirecter = vtkImageChangeInformationPtr::New();
58  mRedirecter->SetInputData(mBase->getVtkImageData());
59  this->probeChangedSlot();
60 }
61 
63 {
64  disconnect(mBase.get(), &VideoSource::streaming, this, &VideoSource::streaming);
65  disconnect(mBase.get(), &VideoSource::connected, this, &VideoSource::connected);
66  disconnect(mBase.get(), &VideoSource::newFrame, this, &VideoSource::newFrame);
67  disconnect(mBase.get(), &VideoSource::newFrame, this, &ProbeAdapterRTSource::newFrameSlot);
68 }
69 
71 {
72  return mUid;
73 }
74 
76 {
77  return mBase->getName();
78 }
79 
81 {
82  return mRedirecter->GetOutput();
83 }
84 
86 {
87  QString uid = mBase->getUid();
88  ProbePtr probe = mProbe.lock();
89  if (probe)
90  return mBase->getTimestamp() - probe->getProbeDefinition(uid).getTemporalCalibration();
91  else
92  return mBase->getTimestamp();
93 }
94 
96 {
97  TimeInfo retval;
98  retval.mAcquisitionTime.setMSecsSinceEpoch(this->getTimestamp());
99  return retval;
100 }
101 
103 {
104  return mBase->getInfoString();
105 }
106 
108 {
109  return mBase->getStatusString();
110 }
111 
113 {
114  mBase->start();
115 }
116 
118 {
119  mBase->stop();
120 }
121 
123 {
124  return mBase->validData();
125 }
126 
128 {
129  return mBase->isConnected();
130 }
131 
133 {
134  return mBase->isStreaming();
135 }
136 
138 {
139  return mBase;
140 }
141 
142 void ProbeAdapterRTSource::newFrameSlot()
143 {
144  ProbePtr probe = mProbe.lock();
145  if (!probe)
146  return;
147  if (!this->validData())
148  return;
149 
150  mRedirecter->Update();
151 
152  QString uid = mBase->getUid();
153  ProbeDefinition data = probe->getProbeDefinition(uid);
154  QSize dimProbe = data.getSize();
155  QSize dimImage(mRedirecter->GetOutput()->GetDimensions()[0], mRedirecter->GetOutput()->GetDimensions()[1]);
156 
157  if (dimProbe!=dimImage)
158  {
159  report(
160  QString("Resampling probe calibration. Calibration:[%1,%2], Image:[%3,%4], uid=%5")
161  .arg(dimProbe.width())
162  .arg(dimProbe.height())
163  .arg(dimImage.width())
164  .arg(dimImage.height())
165  .arg(uid));
166 
167  data.resample(dimImage);
168  probe->setProbeDefinition(data);
169  }
170 
171 }
172 
173 void ProbeAdapterRTSource::probeChangedSlot()
174 {
175  ProbePtr probe = mProbe.lock();
176  if (!probe)
177  return;
178 
179  mRedirecter->Update();
180 
181  QString uid = mBase->getUid();
182  mRedirecter->SetOutputSpacing(probe->getProbeDefinition(uid).getSpacing().begin());
183 
184  mRedirecter->Update();
185 }
186 
187 }
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:93
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 'active' to get the default.
Definition of characteristics for an Ultrasound Probe Sector.
QDateTime mAcquisitionTime
Possibly modified time stamp.
Definition: cxData.h:65
virtual vtkImageDataPtr getVtkImageData()
void report(QString msg)
Definition: cxLogger.cpp:90
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.