34 #include <vtkDataSetMapper.h>
35 #include <vtkImageFlip.h>
44 #include <QApplication>
45 #include "boost/function.hpp"
46 #include "boost/bind.hpp"
57 mUnusedProbeDefinitionVector.clear();
60 connect(mBackend->tracking().get(), SIGNAL(activeToolChanged(QString)),
this, SLOT(connectVideoToProbe()));
66 this->waitForClientFinished();
69 void VideoConnection::waitForClientFinished()
85 void VideoConnection::fpsSlot(QString source,
double fpsNumber)
88 emit
fps(source, fpsNumber);
98 return mStreamerInterface;
104 class EventProcessingThread :
public QThread
109 qApp->processEvents();
119 CX_LOG_INFO() <<
"Video client already exists - cannot start";
125 CX_LOG_INFO() <<
"Video thread already exists (in shutdown?) - cannot start";
129 mStreamerInterface = service;
136 mThread =
new EventProcessingThread;
137 mThread->setObjectName(
"org.custusx.core.video.imagereceiver");
138 mClient->moveToThread(mThread);
140 connect(mThread.data(), &QThread::started,
this, &VideoConnection::onConnected);
145 connect(mThread.data(), &QThread::finished,
this, &VideoConnection::onDisconnected);
146 connect(mThread.data(), &QThread::finished, mThread.data(), &QThread::deleteLater);
151 void VideoConnection::imageReceivedSlot()
155 this->updateImage(mClient->getLastImageMessage());
158 void VideoConnection::statusReceivedSlot()
162 this->updateStatus(mClient->getLastSonixStatusMessage());
165 void VideoConnection::stopClient()
176 QMetaObject::invokeMethod(mClient,
"shutdown", Qt::QueuedConnection);
187 void VideoConnection::onConnected()
189 this->startAllSources();
193 void VideoConnection::onDisconnected()
200 this->stopAllSources();
202 for (
unsigned i=0; i<mSources.size(); ++i)
205 ToolPtr tool = mBackend->tracking()->getFirstProbe();
206 if (tool && tool->getProbe())
207 this->removeSourceFromProbe(tool);
210 mStreamerInterface.reset();
216 void VideoConnection::useUnusedProbeDefinitionSlot()
220 std::vector<ProbeDefinitionPtr> unusedProbeDefinitionVector = mUnusedProbeDefinitionVector;
221 mUnusedProbeDefinitionVector.clear();
223 for (
unsigned i = 0; i < unusedProbeDefinitionVector.size(); ++i)
224 this->updateStatus(unusedProbeDefinitionVector[i]);
227 void VideoConnection::resetProbe()
229 ToolPtr tool = mBackend->tracking()->getFirstProbe();
230 if (!tool || !tool->getProbe())
235 ProbeDefinition data = probe->getProbeDefinition();
236 data.setUseDigitalVideo(
false);
237 probe->setProbeDefinition(data);
247 ToolPtr tool = mBackend->tracking()->getFirstProbe();
248 if (!tool || !tool->getProbe())
251 if (mUnusedProbeDefinitionVector.empty())
253 mUnusedProbeDefinitionVector.push_back(msg);
261 ProbeDefinition data = probe->getProbeDefinition();
263 data.setUid(msg->getUid());
264 data.setType(msg->getType());
265 data.setSector(msg->getDepthStart(), msg->getDepthEnd(), msg->getWidth());
266 data.setOrigin_p(msg->getOrigin_p());
267 data.setSize(msg->getSize());
268 data.setSpacing(msg->getSpacing());
269 data.setClipRect_p(msg->getClipRect_p());
270 data.setUseDigitalVideo(
true);
272 probe->setProbeDefinition(data);
273 probe->setActiveStream(msg->getUid());
276 void VideoConnection::startAllSources()
278 for (
unsigned i=0; i<mSources.size(); ++i)
279 mSources[i]->start();
282 void VideoConnection::stopAllSources()
284 for (
unsigned i=0; i<mSources.size(); ++i)
288 void VideoConnection::removeSourceFromProbe(
ToolPtr tool)
291 for (
unsigned i=0; i<mSources.size(); ++i)
292 probe->removeRTSource(mSources[i]);
295 void VideoConnection::updateImage(
ImagePtr message)
300 for (
unsigned i=0; i<mSources.size(); ++i)
302 if (message && message->getUid() == mSources[i]->getUid())
303 source = mSources[i];
306 bool newSource =
false;
310 source.reset(
new BasicVideoSource());
311 mSources.push_back(source);
316 source->setInput(message);
318 QString info = mClient->hostDescription() +
" - " + QString::number(mFPS,
'f', 1) +
" fps";
319 source->setInfoString(info);
323 this->connectVideoToProbe();
330 std::vector<VideoSourcePtr> retval;
331 std::copy(mSources.begin(), mSources.end(), std::back_inserter(retval));
342 void VideoConnection::connectVideoToProbe()
344 ToolPtr tool = mBackend->tracking()->getFirstProbe();
352 for (
unsigned i=0; i<mSources.size(); ++i)
353 probe->setRTSource(mSources[i]);
void fps(QString, double)
boost::shared_ptr< class Image > ImagePtr
VideoConnection(VideoServiceBackendPtr backend)
void videoSourcesChanged()
std::vector< VideoSourcePtr > getVideoSources()
boost::shared_ptr< class VideoServiceBackend > VideoServiceBackendPtr
boost::shared_ptr< Probe > ProbePtr
void sonixStatusReceived()
Base class for receiving images from a video stream.
void runDirectLinkClient(StreamerServicePtr service)
virtual bool isConnected() const
vtkSmartPointer< vtkDataSetMapper > vtkDataSetMapperPtr
virtual ~VideoConnection()
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)
boost::shared_ptr< class Tool > ToolPtr