15 #include <QStringList> 16 #include <QDataStream> 19 #include <vtkImageData.h> 30 mFileManagerService(fileManager)
37 if (calFilesPath.isEmpty())
39 QStringList list = fileName.split(
"/");
40 list[list.size()-1] =
"";
41 calFilesPath = list.join(
"/")+
"/";
47 if (QFileInfo(fileName).suffix().isEmpty())
60 retval.
mUsRaw = this->readUsDataFile(fileName);
62 std::pair<QString, ProbeDefinition> probeDefinitionFull = this->readProbeDefinitionBackwardsCompatible(
changeExtension(fileName,
"mhd"), calFilesPath);
70 "Mismatch in spacing values from calibration and recorded image.\n" 71 "This might be valid if the sound speed was changed prior to recording.\n" 77 retval.
mProbeUid = probeDefinitionFull.first;
80 retval.
mPositions = this->readPositions(fileName);
82 if (!this->valid(retval))
90 double msecs = (retval.
mFrames.rbegin()->mTime - retval.
mFrames.begin()->mTime);
91 report(QString(
"Read %1 seconds of us data from %2.").arg(msecs/1000, 0,
'g', 3).arg(fileName));
101 reportError(
"Mismatch between number of images and number of image positions.\n" 113 std::pair<QString, ProbeDefinition> UsReconstructionFileReader::readProbeDefinitionBackwardsCompatible(QString mhdFileName, QString calFilesPath)
119 report(QString(
"Invalid probe in %1, falling back to old format").arg(retval.first));
120 QString caliFilename;
121 QStringList probeConfigPath;
122 this->readCustomMhdTags(mhdFileName, &probeConfigPath, &caliFilename);
132 Eigen::Array3i dim(data.
mUsRaw->getDimensions());
142 void UsReconstructionFileReader::readCustomMhdTags(QString mhdFileName, QStringList* probeConfigPath, QString* calFileName)
146 QFile file(mhdFileName);
147 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
149 reportWarning(
"Error in Reconstructer::readUsDataFile(): Can't open file: " 152 bool foundConfig =
false;
153 QStringList& configList = *probeConfigPath;
154 bool foundCalFile =
false;
155 while (!file.atEnd())
157 QString line = file.readLine();
158 if(line.startsWith(
"ConfigurationID", Qt::CaseInsensitive))
160 QStringList tempList = line.split(
"=", QString::SkipEmptyParts);
161 configList = tempList[1].trimmed().split(
":", QString::SkipEmptyParts);
162 if (configList.size()>=3)
163 configList[3] = configList[3].trimmed();
166 else if(line.startsWith(
"ProbeCalibration", Qt::CaseInsensitive))
168 QStringList list = line.split(
"=", QString::SkipEmptyParts);
169 *calFileName = list[1].trimmed();
176 reportWarning(QString(
"Error in Reconstructer::readUsDataFile(): ")
177 +
"Can't find ConfigurationID in file: " 182 reportWarning(QString(
"Error in Reconstructer::readUsDataFile(): ")
183 +
"Can't find ProbeCalibration in file: " 190 if (probeConfigPath.size()!=4)
193 QString xmlPath = calFilesPath+
"ProbeCalibConfigs.xml";
197 configuration = xmlConfigParser->getConfiguration(
203 return configuration;
208 std::pair<QString, ProbeDefinition> retval;
211 if (!QFileInfo(filename).exists())
213 reportWarning(
"File not found: " + filename +
", failed to load probe data.");
218 retval.second.parseXml(file.
getElement(
"configuration"));
220 retval.first = file.
getElement(
"tool").toElement().attribute(
"toolID");
225 USFrameDataPtr UsReconstructionFileReader::readUsDataFile(QString mhdFileName)
232 bool useOldFormat = !QFileInfo(
changeExtension(fileName,
"fts")).exists();
233 std::vector<TimedPosition> retval;
246 std::vector<TimedPosition> UsReconstructionFileReader::readPositions(QString fileName)
248 bool useOldFormat = !QFileInfo(
changeExtension(fileName,
"fts")).exists();
249 std::vector<TimedPosition> retval;
253 this->readPositionFile(
changeExtension(fileName,
"pos"),
true, &retval);
257 this->readPositionFile(
changeExtension(fileName,
"tp"),
false, &retval);
263 void UsReconstructionFileReader::readTimeStampsFile(QString fileName,
264 std::vector<TimedPosition>* timedPos)
266 QFile file(fileName);
267 if(!file.open(QIODevice::ReadOnly))
275 while (!file.atEnd())
277 if (i>=timedPos->size())
282 QByteArray array = file.readLine();
283 double time = QString(array).toDouble(&ok);
289 timedPos->at(i).mTime = time;
295 void UsReconstructionFileReader::readPositionFile(QString posFile,
bool alsoReadTimestamps, std::vector<TimedPosition>* timedPos)
298 if(!file.open(QIODevice::ReadOnly))
307 while (!file.atEnd())
309 if (i>=timedPos->size())
316 if (alsoReadTimestamps)
319 QByteArray array = file.readLine();
320 position.
mTime = QString(array).toDouble(&ok);
329 QString positionString = file.readLine();
330 positionString +=
" " + file.readLine();
331 positionString +=
" " + file.readLine();
332 positionString +=
" 0 0 0 1";
333 position.
mPos = Transform3D::fromString(positionString, &ok);
344 timedPos->at(i) = position;
351 bool UsReconstructionFileReader::readMaskFile(QString mhdFileName,
ImagePtr mask)
355 if (!QFileInfo(fileName).exists())
361 QFile file(fileName);
362 file.open(QIODevice::ReadOnly);
363 QDataStream stream(&file);
365 unsigned char* dataPtr =
static_cast<unsigned char*
>(data->GetScalarPointer());
366 char *rawchars =
reinterpret_cast<char*
>(dataPtr);
368 stream.readRawData(rawchars, file.size());
QString qstring_cast(const T &val)
< a easy-to-work-with struct for a specific xml configuration
boost::shared_ptr< class FileManagerService > FileManagerServicePtr
void reportError(QString msg)
void setSpacing(Vector3D spacing)
One position with timestamp.
static std::pair< QString, ProbeDefinition > readProbeDefinitionFromFile(QString mhdFileName)
boost::shared_ptr< class Image > ImagePtr
boost::shared_ptr< class USFrameData > USFrameDataPtr
std::vector< TimedPosition > readFrameTimestamps(QString fileName)
QDomElement getElement()
return the current element
USReconstructInputData readAllFiles(QString fileName, QString calFilesPath="")
void reportWarning(QString msg)
Implementation of abstract interface ProbeXmlConfigParser Interface to ProbeCalibConfigs.xml.
boost::shared_ptr< ProbeXmlConfigParser > ProbeXmlConfigParserPtr
vtkImageDataPtr generateVtkImageData(Eigen::Array3i dim, Vector3D spacing, const unsigned char initValue, int components)
UsReconstructionFileReader(FileManagerServicePtr fileManager)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition of characteristics for an Ultrasound Probe Sector.
Vector3D getSpacing() const
QString changeExtension(QString name, QString ext)
void setDeepModified(vtkImageDataPtr image)
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
static USFrameDataPtr create(ImagePtr inputFrameData)
Helper class for xml files used to store ssc/cx data.
ProbeDefinition createProbeDefinitionFromConfiguration(ProbeXmlConfigParser::Configuration config)
void setData(ProbeDefinition data)
Namespace for all CustusX production code.