15 #include <QStringList> 16 #include <QDataStream> 19 #include <vtkImageData.h> 36 if (calFilesPath.isEmpty())
38 QStringList list = fileName.split(
"/");
39 list[list.size()-1] =
"";
40 calFilesPath = list.join(
"/")+
"/";
46 if (QFileInfo(fileName).suffix().isEmpty())
59 retval.
mUsRaw = this->readUsDataFile(fileName);
61 std::pair<QString, ProbeDefinition> probeDefinitionFull = this->readProbeDefinitionBackwardsCompatible(
changeExtension(fileName,
"mhd"), calFilesPath);
69 "Mismatch in spacing values from calibration and recorded image.\n" 70 "This might be valid if the sound speed was changed prior to recording.\n" 76 retval.
mProbeUid = probeDefinitionFull.first;
79 retval.
mPositions = this->readPositions(fileName);
81 if (!this->valid(retval))
89 double msecs = (retval.
mFrames.rbegin()->mTime - retval.
mFrames.begin()->mTime);
90 report(QString(
"Read %1 seconds of us data from %2.").arg(msecs/1000, 0,
'g', 3).arg(fileName));
100 reportError(
"Mismatch between number of images and number of image positions.\n" 112 std::pair<QString, ProbeDefinition> UsReconstructionFileReader::readProbeDefinitionBackwardsCompatible(QString mhdFileName, QString calFilesPath)
118 report(QString(
"Invalid probe in %1, falling back to old format").arg(retval.first));
119 QString caliFilename;
120 QStringList probeConfigPath;
121 this->readCustomMhdTags(mhdFileName, &probeConfigPath, &caliFilename);
131 Eigen::Array3i dim(data.
mUsRaw->getDimensions());
141 void UsReconstructionFileReader::readCustomMhdTags(QString mhdFileName, QStringList* probeConfigPath, QString* calFileName)
145 QFile file(mhdFileName);
146 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
148 reportWarning(
"Error in Reconstructer::readUsDataFile(): Can't open file: " 151 bool foundConfig =
false;
152 QStringList& configList = *probeConfigPath;
153 bool foundCalFile =
false;
154 while (!file.atEnd())
156 QString line = file.readLine();
157 if(line.startsWith(
"ConfigurationID", Qt::CaseInsensitive))
159 QStringList tempList = line.split(
"=", QString::SkipEmptyParts);
160 configList = tempList[1].trimmed().split(
":", QString::SkipEmptyParts);
161 if (configList.size()>=3)
162 configList[3] = configList[3].trimmed();
165 else if(line.startsWith(
"ProbeCalibration", Qt::CaseInsensitive))
167 QStringList list = line.split(
"=", QString::SkipEmptyParts);
168 *calFileName = list[1].trimmed();
175 reportWarning(QString(
"Error in Reconstructer::readUsDataFile(): ")
176 +
"Can't find ConfigurationID in file: " 181 reportWarning(QString(
"Error in Reconstructer::readUsDataFile(): ")
182 +
"Can't find ProbeCalibration in file: " 189 if (probeConfigPath.size()!=4)
192 QString xmlPath = calFilesPath+
"ProbeCalibConfigs.xml";
196 configuration = xmlConfigParser->getConfiguration(
202 return configuration;
207 std::pair<QString, ProbeDefinition> retval;
210 if (!QFileInfo(filename).exists())
212 reportWarning(
"File not found: " + filename +
", failed to load probe data.");
217 retval.second.parseXml(file.
getElement(
"configuration"));
219 retval.first = file.
getElement(
"tool").toElement().attribute(
"toolID");
224 USFrameDataPtr UsReconstructionFileReader::readUsDataFile(QString mhdFileName)
231 bool useOldFormat = !QFileInfo(
changeExtension(fileName,
"fts")).exists();
232 std::vector<TimedPosition> retval;
245 std::vector<TimedPosition> UsReconstructionFileReader::readPositions(QString fileName)
247 bool useOldFormat = !QFileInfo(
changeExtension(fileName,
"fts")).exists();
248 std::vector<TimedPosition> retval;
252 this->readPositionFile(
changeExtension(fileName,
"pos"),
true, &retval);
256 this->readPositionFile(
changeExtension(fileName,
"tp"),
false, &retval);
262 void UsReconstructionFileReader::readTimeStampsFile(QString fileName,
263 std::vector<TimedPosition>* timedPos)
265 QFile file(fileName);
266 if(!file.open(QIODevice::ReadOnly))
274 while (!file.atEnd())
276 if (i>=timedPos->size())
281 QByteArray array = file.readLine();
282 double time = QString(array).toDouble(&ok);
288 timedPos->at(i).mTime = time;
294 void UsReconstructionFileReader::readPositionFile(QString posFile,
bool alsoReadTimestamps, std::vector<TimedPosition>* timedPos)
297 if(!file.open(QIODevice::ReadOnly))
306 while (!file.atEnd())
308 if (i>=timedPos->size())
315 if (alsoReadTimestamps)
318 QByteArray array = file.readLine();
319 position.
mTime = QString(array).toDouble(&ok);
328 QString positionString = file.readLine();
329 positionString +=
" " + file.readLine();
330 positionString +=
" " + file.readLine();
331 positionString +=
" 0 0 0 1";
332 position.
mPos = Transform3D::fromString(positionString, &ok);
343 timedPos->at(i) = position;
350 bool UsReconstructionFileReader::readMaskFile(QString mhdFileName,
ImagePtr mask)
354 if (!QFileInfo(fileName).exists())
360 QFile file(fileName);
361 file.open(QIODevice::ReadOnly);
362 QDataStream stream(&file);
364 unsigned char* dataPtr =
static_cast<unsigned char*
>(data->GetScalarPointer());
365 char *rawchars =
reinterpret_cast<char*
>(dataPtr);
367 stream.readRawData(rawchars, file.size());
QString qstring_cast(const T &val)
< a easy-to-work-with struct for a specific xml configuration
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
UsReconstructionFileReader()
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)
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.