34 #include <QStringList>
37 #include <boost/bind.hpp>
38 #include "vtkImageImport.h"
39 #include "vtkImageData.h"
54 #include <QtConcurrent>
62 mVideoSourceUid(
"playback " + type)
67 mVideoSource->setStatusString(QString(
"No US Acquisition"));
69 connect(&mUSImageDataFutureWatcher, SIGNAL(finished()),
this, SLOT(usDataLoadFinishedSlot()));
84 return mTimer ?
true :
false;
90 disconnect(mTimer.get(), SIGNAL(changed()),
this, SLOT(timerChangedSlot()));
93 connect(mTimer.get(), SIGNAL(changed()),
this, SLOT(timerChangedSlot()));
97 mVideoSource->start();
101 mVideoSource->deconfigure();
113 std::vector<TimelineEvent> events;
115 QStringList allFiles = this->getAbsolutePathToFtsFiles(mRoot);
116 for (
int i=0; i<allFiles.size(); ++i)
121 if (timestamps.empty())
125 QString(
"Acquisition %1").arg(QFileInfo(allFiles[i]).fileName()),
126 timestamps.front().mTime,
127 timestamps.back().mTime);
128 current.
mUid = allFiles[i];
129 current.mGroup =
"acquisition";
130 current.mColor = QColor::fromHsv(36, 255, 222);
132 events.push_back(current);
141 QStringList USAcquisitionVideoPlayback::getAbsolutePathToFtsFiles(QString folder)
151 void USAcquisitionVideoPlayback::timerChangedSlot()
154 for (
unsigned i=0; i<mEvents.size(); ++i)
156 if (mEvents[i].isInside(mTimer->getTime().toMSecsSinceEpoch()))
163 this->loadFullData(event.
mUid);
164 this->updateFrame(event.
mUid);
167 void USAcquisitionVideoPlayback::loadFullData(QString filename)
173 mVideoSource->setInfoString(QString(
""));
174 mVideoSource->setStatusString(QString(
"No US Acquisition"));
175 mVideoSource->deconfigure();
178 if (filename.isEmpty())
182 mCurrentData = USReconstructInputData();
185 if (filename.isEmpty())
190 if (!mUSImageDataReader)
192 mUSImageDataReader.reset(
new UsReconstructionFileReader());
194 mUSImageDataFutureWatcher.setFuture(mUSImageDataFutureResult);
198 void USAcquisitionVideoPlayback::usDataLoadFinishedSlot()
201 mCurrentData = mUSImageDataFutureResult.result();
204 mUSImageDataReader.reset();
206 mVideoSource->start();
209 ToolPtr tool = mBackend->tracking()->getFirstProbe();
218 mCurrentTimestamps.clear();
219 for (
unsigned i=0; i<mCurrentData.
mFrames.size(); ++i)
220 mCurrentTimestamps.push_back(mCurrentData.
mFrames[i].mTime);
222 this->updateFrame(mCurrentData.
mFilename);
225 void USAcquisitionVideoPlayback::updateFrame(QString filename)
227 if (mUSImageDataReader)
229 mVideoSource->setInfoString(QString(
"Loading US Data..."));
230 mVideoSource->setStatusString(QString(
"Loading US Data..."));
237 mVideoSource->setInfoString(QString(
""));
238 mVideoSource->setStatusString(QString(
"No US Acquisition"));
244 mVideoSource->start();
246 double timestamp = mTimer->getTime().toMSecsSinceEpoch();
249 std::vector<double>::iterator iter = std::lower_bound(mCurrentTimestamps.begin(), mCurrentTimestamps.end(), timestamp);
250 if (iter==mCurrentTimestamps.begin())
253 int index = std::distance(mCurrentTimestamps.begin(), iter);
256 mVideoSource->overrideTimeout(fabs(timestamp-*iter)>timeout);
258 ImagePtr image(
new Image(mVideoSourceUid, mCurrentData.
mUsRaw->getImageContainer()->get(index)));
259 image->setAcquisitionTime(QDateTime::fromMSecsSinceEpoch(timestamp));
261 mVideoSource->setInfoString(QString(
"%1 - Frame %2").arg(mCurrentData.
mUsRaw->getName()).arg(index));
262 if (mVideoSource->validData())
263 mVideoSource->setStatusString(QString(
""));
265 mVideoSource->setStatusString(QString(
"Timeout"));
267 mVideoSource->setInput(image);
Reader class for the US Acquisition files.
void setTime(PlaybackTimePtr controller)
Description of one event in time.
boost::shared_ptr< class Image > ImagePtr
std::vector< TimedPosition > readFrameTimestamps(QString fileName)
VideoSourcePtr getVideoSource()
boost::shared_ptr< class VideoServiceBackend > VideoServiceBackendPtr
void setRoot(const QString path)
boost::shared_ptr< class PlaybackTime > PlaybackTimePtr
boost::shared_ptr< Probe > ProbePtr
USReconstructInputData readAllFiles(QString fileName, QString calFilesPath="")
boost::shared_ptr< class VideoSource > VideoSourcePtr
USAcquisitionVideoPlayback(VideoServiceBackendPtr backend, QString type)
VideoSource controlled by a vtkImageData.
std::vector< TimelineEvent > getEvents()
QStringList getAbsolutePathToFiles(QString path, QStringList nameFilters, bool includeSubDirs)
virtual ~USAcquisitionVideoPlayback()
boost::shared_ptr< class Tool > ToolPtr