CustusX  15.4.0-beta
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 
42 
43 namespace cx
44 {
45 
47  mUid(uid), mBase(source), mProbe(probe)
48 {
49  connect(probe.get(), &Probe::sectorChanged, this, &ProbeAdapterRTSource::probeChangedSlot);
50 
51  connect(mBase.get(), &VideoSource::streaming, this, &VideoSource::streaming);
52  connect(mBase.get(), &VideoSource::connected, this, &VideoSource::connected);
53  connect(mBase.get(), &VideoSource::newFrame, this, &VideoSource::newFrame);
54  connect(mBase.get(), &VideoSource::newFrame, this, &ProbeAdapterRTSource::newFrameSlot);
55 
56  mRedirecter = vtkImageChangeInformationPtr::New();
57  mRedirecter->SetInputData(mBase->getVtkImageData());
58  this->probeChangedSlot();
59 }
60 
62 {}
63 
65 {
66  return mUid;
67 }
68 
70 {
71  return mBase->getName();
72 }
73 
75 {
76  return mRedirecter->GetOutput();
77 }
78 
80 {
81  QString uid = mBase->getUid();
82  ProbePtr probe = mProbe.lock();
83  if (probe)
84  return mBase->getTimestamp() - probe->getProbeData(uid).getTemporalCalibration();
85  else
86  return mBase->getTimestamp();
87 }
88 
90 {
91  return mBase->getInfoString();
92 }
93 
95 {
96  return mBase->getStatusString();
97 }
98 
100 {
101  mBase->start();
102 }
103 
105 {
106  mBase->stop();
107 }
108 
110 {
111  return mBase->validData();
112 }
113 
115 {
116  return mBase->isConnected();
117 }
118 
120 {
121  return mBase->isStreaming();
122 }
123 
125 {
126  return mBase;
127 }
128 
129 void ProbeAdapterRTSource::newFrameSlot()
130 {
131  ProbePtr probe = mProbe.lock();
132  if (!probe)
133  return;
134  if (!this->validData())
135  return;
136 
137  mRedirecter->Update();
138 
139  QString uid = mBase->getUid();
140  ProbeDefinition data = probe->getProbeData(uid);
141  QSize dimProbe = data.getSize();
142  QSize dimImage(mRedirecter->GetOutput()->GetDimensions()[0], mRedirecter->GetOutput()->GetDimensions()[1]);
143 
144  if (dimProbe!=dimImage)
145  {
146  report(
147  QString("Resampling probe calibration. Calibration:[%1,%2], Image:[%3,%4], uid=%5")
148  .arg(dimProbe.width())
149  .arg(dimProbe.height())
150  .arg(dimImage.width())
151  .arg(dimImage.height())
152  .arg(uid));
153 
154  data.resample(dimImage);
155  probe->setProbeSector(data);
156  }
157 
158 }
159 
160 void ProbeAdapterRTSource::probeChangedSlot()
161 {
162  ProbePtr probe = mProbe.lock();
163  if (!probe)
164  return;
165 
166  mRedirecter->Update();
167 
168  QString uid = mBase->getUid();
169  mRedirecter->SetOutputSpacing(probe->getProbeData(uid).getSpacing().begin());
170 
171  mRedirecter->Update();
172 }
173 
174 }
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 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.
Definition: cxProbeData.h:118
virtual vtkImageDataPtr getVtkImageData()
void report(QString msg)
Definition: cxLogger.cpp:90
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
QSize getSize() const
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.