13 #include <vtkDataSetMapper.h> 14 #include <vtkImageFlip.h> 23 #include <QApplication> 24 #include "boost/function.hpp" 25 #include "boost/bind.hpp" 36 mUnusedProbeDefinitionVector.clear();
39 connect(mBackend->tracking().get(), SIGNAL(activeToolChanged(QString)),
this, SLOT(connectVideoToProbe()));
45 this->waitForClientFinished();
48 void VideoConnection::waitForClientFinished()
64 void VideoConnection::fpsSlot(QString source,
double fpsNumber)
67 emit
fps(source, fpsNumber);
77 return mStreamerInterface;
83 class EventProcessingThread :
public QThread
88 qApp->processEvents();
98 CX_LOG_INFO() <<
"Video client already exists - cannot start";
104 CX_LOG_INFO() <<
"Video thread already exists (in shutdown?) - cannot start";
108 mStreamerInterface = service;
115 mThread =
new EventProcessingThread;
116 mThread->setObjectName(
"org.custusx.core.video.imagereceiver");
117 mClient->moveToThread(mThread);
119 connect(mThread.data(), &QThread::started,
this, &VideoConnection::onConnected);
124 connect(mThread.data(), &QThread::finished,
this, &VideoConnection::onDisconnected);
125 connect(mThread.data(), &QThread::finished, mThread.data(), &QThread::deleteLater);
130 void VideoConnection::imageReceivedSlot()
134 this->updateImage(mClient->getLastImageMessage());
137 void VideoConnection::statusReceivedSlot()
141 this->updateStatus(mClient->getLastSonixStatusMessage());
144 void VideoConnection::stopClient()
155 QMetaObject::invokeMethod(mClient,
"shutdown", Qt::QueuedConnection);
166 void VideoConnection::onConnected()
168 this->startAllSources();
172 void VideoConnection::onDisconnected()
179 this->stopAllSources();
181 for (
unsigned i=0; i<mSources.size(); ++i)
184 ToolPtr tool = mBackend->tracking()->getFirstProbe();
185 if (tool && tool->getProbe())
186 this->removeSourceFromProbe(tool);
189 mStreamerInterface.reset();
195 void VideoConnection::useUnusedProbeDefinitionSlot()
199 std::vector<ProbeDefinitionPtr> unusedProbeDefinitionVector = mUnusedProbeDefinitionVector;
200 mUnusedProbeDefinitionVector.clear();
202 for (
unsigned i = 0; i < unusedProbeDefinitionVector.size(); ++i)
203 this->updateStatus(unusedProbeDefinitionVector[i]);
206 void VideoConnection::resetProbe()
208 ToolPtr tool = mBackend->tracking()->getFirstProbe();
209 if (!tool || !tool->getProbe())
216 probe->setProbeDefinition(data);
226 ToolPtr tool = mBackend->tracking()->getFirstProbe();
227 if (!tool || !tool->getProbe())
230 if (mUnusedProbeDefinitionVector.empty())
232 mUnusedProbeDefinitionVector.push_back(msg);
242 data.
setUid(msg->getUid());
244 data.
setSector(msg->getDepthStart(), msg->getDepthEnd(), msg->getWidth());
251 probe->setProbeDefinition(data);
252 probe->setActiveStream(msg->getUid());
255 void VideoConnection::startAllSources()
257 for (
unsigned i=0; i<mSources.size(); ++i)
258 mSources[i]->start();
261 void VideoConnection::stopAllSources()
263 for (
unsigned i=0; i<mSources.size(); ++i)
267 void VideoConnection::removeSourceFromProbe(
ToolPtr tool)
270 for (
unsigned i=0; i<mSources.size(); ++i)
271 probe->removeRTSource(mSources[i]);
274 void VideoConnection::updateImage(
ImagePtr message)
279 for (
unsigned i=0; i<mSources.size(); ++i)
281 if (message && message->getUid() == mSources[i]->getUid())
282 source = mSources[i];
285 bool newSource =
false;
290 mSources.push_back(source);
295 source->setInput(message);
297 QString info = mClient->hostDescription() +
" - " + QString::number(mFPS,
'f', 1) +
" fps";
298 source->setInfoString(info);
302 this->connectVideoToProbe();
309 std::vector<VideoSourcePtr> retval;
310 std::copy(mSources.begin(), mSources.end(), std::back_inserter(retval));
321 void VideoConnection::connectVideoToProbe()
323 ToolPtr tool = mBackend->tracking()->getFirstProbe();
331 for (
unsigned i=0; i<mSources.size(); ++i)
332 probe->setRTSource(mSources[i]);
void setSpacing(Vector3D spacing)
void fps(QString, double)
boost::shared_ptr< class Image > ImagePtr
VideoConnection(VideoServiceBackendPtr backend)
void videoSourcesChanged()
std::vector< VideoSourcePtr > getVideoSources()
void setSector(double depthStart, double depthEnd, double width, double centerOffset=0)
boost::shared_ptr< class VideoServiceBackend > VideoServiceBackendPtr
boost::shared_ptr< Probe > ProbePtr
void setOrigin_p(Vector3D origin_p)
void sonixStatusReceived()
void setUseDigitalVideo(bool val)
RTSource is digital (eg. US sector is set digitally, not read from .xml file)
void setClipRect_p(DoubleBoundingBox3D clipRect_p)
Base class for receiving images from a video stream.
void runDirectLinkClient(StreamerServicePtr service)
virtual bool isConnected() const
VideoSource controlled by a vtkImageData.
vtkSmartPointer< vtkDataSetMapper > vtkDataSetMapperPtr
virtual ~VideoConnection()
Definition of characteristics for an Ultrasound Probe Sector.
vtkSmartPointer< vtkImageFlip > vtkImageFlipPtr
boost::shared_ptr< class StreamerService > StreamerServicePtr
boost::shared_ptr< class BasicVideoSource > BasicVideoSourcePtr
boost::shared_ptr< class ProbeDefinition > ProbeDefinitionPtr
void fps(QString source, int fps)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr