36 #include <QStringList> 37 #include <QDataStream> 40 #include <vtkImageData.h> 57 if (calFilesPath.isEmpty())
59 QStringList list = fileName.split(
"/");
60 list[list.size()-1] =
"";
61 calFilesPath = list.join(
"/")+
"/";
67 if (QFileInfo(fileName).suffix().isEmpty())
80 retval.
mUsRaw = this->readUsDataFile(fileName);
82 std::pair<QString, ProbeDefinition> probeDefinitionFull = this->readProbeDefinitionBackwardsCompatible(
changeExtension(fileName,
"mhd"), calFilesPath);
90 "Mismatch in spacing values from calibration and recorded image.\n" 91 "This might be valid if the sound speed was changed prior to recording.\n" 97 retval.
mProbeUid = probeDefinitionFull.first;
100 retval.
mPositions = this->readPositions(fileName);
102 if (!this->valid(retval))
110 double msecs = (retval.
mFrames.rbegin()->mTime - retval.
mFrames.begin()->mTime);
111 report(QString(
"Read %1 seconds of us data from %2.").arg(msecs/1000, 0,
'g', 3).arg(fileName));
121 reportError(
"Mismatch between number of images and number of image positions.\n" 133 std::pair<QString, ProbeDefinition> UsReconstructionFileReader::readProbeDefinitionBackwardsCompatible(QString mhdFileName, QString calFilesPath)
139 report(QString(
"Invalid probe in %1, falling back to old format").arg(retval.first));
140 QString caliFilename;
141 QStringList probeConfigPath;
142 this->readCustomMhdTags(mhdFileName, &probeConfigPath, &caliFilename);
152 Eigen::Array3i dim(data.
mUsRaw->getDimensions());
162 void UsReconstructionFileReader::readCustomMhdTags(QString mhdFileName, QStringList* probeConfigPath, QString* calFileName)
166 QFile file(mhdFileName);
167 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
169 reportWarning(
"Error in Reconstructer::readUsDataFile(): Can't open file: " 172 bool foundConfig =
false;
173 QStringList& configList = *probeConfigPath;
174 bool foundCalFile =
false;
175 while (!file.atEnd())
177 QString line = file.readLine();
178 if(line.startsWith(
"ConfigurationID", Qt::CaseInsensitive))
180 QStringList tempList = line.split(
"=", QString::SkipEmptyParts);
181 configList = tempList[1].trimmed().split(
":", QString::SkipEmptyParts);
182 if (configList.size()>=3)
183 configList[3] = configList[3].trimmed();
186 else if(line.startsWith(
"ProbeCalibration", Qt::CaseInsensitive))
188 QStringList list = line.split(
"=", QString::SkipEmptyParts);
189 *calFileName = list[1].trimmed();
196 reportWarning(QString(
"Error in Reconstructer::readUsDataFile(): ")
197 +
"Can't find ConfigurationID in file: " 202 reportWarning(QString(
"Error in Reconstructer::readUsDataFile(): ")
203 +
"Can't find ProbeCalibration in file: " 210 if (probeConfigPath.size()!=4)
213 QString xmlPath = calFilesPath+
"ProbeCalibConfigs.xml";
217 configuration = xmlConfigParser->getConfiguration(
223 return configuration;
228 std::pair<QString, ProbeDefinition> retval;
231 if (!QFileInfo(filename).exists())
233 reportWarning(
"File not found: " + filename +
", failed to load probe data.");
238 retval.second.parseXml(file.
getElement(
"configuration"));
240 retval.first = file.
getElement(
"tool").toElement().attribute(
"toolID");
245 USFrameDataPtr UsReconstructionFileReader::readUsDataFile(QString mhdFileName)
252 bool useOldFormat = !QFileInfo(
changeExtension(fileName,
"fts")).exists();
253 std::vector<TimedPosition> retval;
266 std::vector<TimedPosition> UsReconstructionFileReader::readPositions(QString fileName)
268 bool useOldFormat = !QFileInfo(
changeExtension(fileName,
"fts")).exists();
269 std::vector<TimedPosition> retval;
273 this->readPositionFile(
changeExtension(fileName,
"pos"),
true, &retval);
277 this->readPositionFile(
changeExtension(fileName,
"tp"),
false, &retval);
283 void UsReconstructionFileReader::readTimeStampsFile(QString fileName,
284 std::vector<TimedPosition>* timedPos)
286 QFile file(fileName);
287 if(!file.open(QIODevice::ReadOnly))
295 while (!file.atEnd())
297 if (i>=timedPos->size())
302 QByteArray array = file.readLine();
303 double time = QString(array).toDouble(&ok);
309 timedPos->at(i).mTime = time;
315 void UsReconstructionFileReader::readPositionFile(QString posFile,
bool alsoReadTimestamps, std::vector<TimedPosition>* timedPos)
318 if(!file.open(QIODevice::ReadOnly))
327 while (!file.atEnd())
329 if (i>=timedPos->size())
336 if (alsoReadTimestamps)
339 QByteArray array = file.readLine();
340 position.
mTime = QString(array).toDouble(&ok);
349 QString positionString = file.readLine();
350 positionString +=
" " + file.readLine();
351 positionString +=
" " + file.readLine();
352 positionString +=
" 0 0 0 1";
353 position.
mPos = Transform3D::fromString(positionString, &ok);
364 timedPos->at(i) = position;
371 bool UsReconstructionFileReader::readMaskFile(QString mhdFileName,
ImagePtr mask)
375 if (!QFileInfo(fileName).exists())
381 QFile file(fileName);
382 file.open(QIODevice::ReadOnly);
383 QDataStream stream(&file);
385 unsigned char* dataPtr =
static_cast<unsigned char*
>(data->GetScalarPointer());
386 char *rawchars =
reinterpret_cast<char*
>(dataPtr);
388 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.