1 #include <visp3/ustk_core/usMHDSequenceReader.h>
7 : m_sequenceDirectory(), m_sequenceImageType(
us::NOT_SET), m_sequenceFiles(), m_totalImageNumber(0), m_imageCounter(0)
22 m_sequenceFiles = vpIoTools::getDirFiles(sequenceDirectory);
23 m_sequenceDirectory = sequenceDirectory;
24 m_totalImageNumber = (int)m_sequenceFiles.size() / 2;
36 if (m_imageCounter > m_totalImageNumber)
37 throw(vpException(vpException::fatalError,
"usMHDSequenceReader : end of sequence reached !"));
41 throw(vpException(vpException::fatalError,
"usMHDSequenceReader trying to open a non-mhd file !"));
43 usMetaHeaderParser mhdParser;
44 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") +
45 m_sequenceFiles.at(2 * m_imageCounter));
46 m_sequenceImageType = mhdParser.getImageType();
48 throw(vpException(vpException::badValue,
"Reading a non rf 2D image!"));
50 if (mhdParser.getElementType() != usMetaHeaderParser::MET_SHORT) {
51 throw(vpException(vpException::badValue,
"Reading a non short image!"));
54 usMetaHeaderParser::MHDHeader mhdHeader = mhdParser.getMHDHeader();
55 timestamp = mhdHeader.timestamp.at(0);
68 image.
resize(mhdHeader.dim[1], mhdHeader.dim[0]);
71 usRawFileParser rawParser;
72 rawParser.read(image, m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * m_imageCounter + 1));
84 if (m_imageCounter > m_totalImageNumber)
85 throw(vpException(vpException::fatalError,
"usMHDSequenceReader : end of sequence reached !"));
89 throw(vpException(vpException::fatalError,
"usMHDSequenceReader trying to open a non-mhd file !"));
91 usMetaHeaderParser mhdParser;
92 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") +
93 m_sequenceFiles.at(2 * m_imageCounter));
94 m_sequenceImageType = mhdParser.getImageType();
96 throw(vpException(vpException::badValue,
"Reading a non pre-scan 2D image!"));
98 if (mhdParser.getElementType() != usMetaHeaderParser::MET_UCHAR) {
99 throw(vpException(vpException::badValue,
"Reading a non unsigned char image!"));
102 usMetaHeaderParser::MHDHeader mhdHeader = mhdParser.getMHDHeader();
103 timestamp = mhdHeader.timestamp.at(0);
116 image.
resize(mhdHeader.dim[1], mhdHeader.dim[0]);
119 usRawFileParser rawParser;
120 rawParser.read(image, m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * m_imageCounter + 1));
132 if (m_imageCounter > m_totalImageNumber)
133 throw(vpException(vpException::fatalError,
"usMHDSequenceReader : end of sequence reached !"));
137 throw(vpException(vpException::fatalError,
"usMHDSequenceReader trying to open a non-mhd file !"));
139 usMetaHeaderParser mhdParser;
140 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") +
141 m_sequenceFiles.at(2 * m_imageCounter));
142 m_sequenceImageType = mhdParser.getImageType();
144 throw(vpException(vpException::badValue,
"Reading a non post-scan 2D image!"));
146 if (mhdParser.getElementType() != usMetaHeaderParser::MET_UCHAR) {
147 throw(vpException(vpException::badValue,
"Reading a non unsigned char image!"));
150 usMetaHeaderParser::MHDHeader mhdHeader = mhdParser.getMHDHeader();
151 timestamp = mhdHeader.timestamp.at(0);
159 if (mhdHeader.isTransducerConvex) {
161 double deltaDepthPostScan2D =
162 mhdHeader.transducerRadius *
163 (1 - std::cos((
double)((mhdHeader.scanLineNumber - 1) * mhdHeader.scanLinePitch / 2.0)));
164 image.
setDepth(mhdHeader.elementSpacing[1] * mhdHeader.dim[1] - deltaDepthPostScan2D);
166 image.
setDepth(mhdHeader.elementSpacing[1] * mhdHeader.dim[1]);
174 image.resize(mhdHeader.dim[1], mhdHeader.dim[0]);
177 usRawFileParser rawParser;
178 rawParser.read(image, m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * m_imageCounter + 1));
194 if (m_imageCounter > m_totalImageNumber)
195 throw(vpException(vpException::fatalError,
"usMHDSequenceReader : end of sequence reached !"));
199 throw(vpException(vpException::fatalError,
"usMHDSequenceReader trying to open a non-mhd file !"));
201 usMetaHeaderParser mhdParser;
202 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") +
203 m_sequenceFiles.at(2 * m_imageCounter));
204 m_sequenceImageType = mhdParser.getImageType();
206 throw(vpException(vpException::badValue,
"Reading a non rf 3D image!"));
208 if (mhdParser.getElementType() != usMetaHeaderParser::MET_SHORT) {
209 throw(vpException(vpException::badValue,
"Reading a non short image!"));
212 usMetaHeaderParser::MHDHeader mhdHeader = mhdParser.getMHDHeader();
213 timestamp = mhdHeader.timestamp;
214 if (m_imageCounter % 2 == 1)
215 std::reverse(timestamp.begin(), timestamp.end());
235 image.
resize(mhdHeader.dim[1], mhdHeader.dim[0], mhdHeader.dim[2]);
238 usRawFileParser rawParser;
239 rawParser.read(image, m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * m_imageCounter + 1));
255 if (m_imageCounter > m_totalImageNumber)
256 throw(vpException(vpException::fatalError,
"usMHDSequenceReader : end of sequence reached !"));
260 throw(vpException(vpException::fatalError,
"usMHDSequenceReader trying to open a non-mhd file !"));
262 usMetaHeaderParser mhdParser;
263 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") +
264 m_sequenceFiles.at(2 * m_imageCounter));
265 m_sequenceImageType = mhdParser.getImageType();
267 throw(vpException(vpException::badValue,
"Reading a non pre-scan 3D image!"));
269 if (mhdParser.getElementType() != usMetaHeaderParser::MET_UCHAR) {
270 throw(vpException(vpException::badValue,
"Reading a non unsigned char image!"));
273 usMetaHeaderParser::MHDHeader mhdHeader = mhdParser.getMHDHeader();
274 timestamp = mhdHeader.timestamp;
275 if (m_imageCounter % 2 == 1)
276 std::reverse(timestamp.begin(), timestamp.end());
296 image.
resize(mhdHeader.dim[1], mhdHeader.dim[0], mhdHeader.dim[2]);
299 usRawFileParser rawParser;
300 rawParser.read(image, m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * m_imageCounter + 1));
312 if (m_imageCounter > m_totalImageNumber)
313 throw(vpException(vpException::fatalError,
"usMHDSequenceReader : end of sequence reached !"));
317 throw(vpException(vpException::fatalError,
"usMHDSequenceReader trying to open a non-mhd file !"));
319 usMetaHeaderParser mhdParser;
320 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") +
321 m_sequenceFiles.at(2 * m_imageCounter));
322 m_sequenceImageType = mhdParser.getImageType();
324 throw(vpException(vpException::badValue,
"Reading a non post-scan 3D image!"));
326 if (mhdParser.getElementType() != usMetaHeaderParser::MET_UCHAR) {
327 throw(vpException(vpException::badValue,
"Reading a non unsigned char image!"));
330 usMetaHeaderParser::MHDHeader mhdHeader = mhdParser.getMHDHeader();
332 if (mhdHeader.timestamp.size() > 0)
333 timestamp = mhdHeader.timestamp.at(0);
336 image.
resize(mhdHeader.dim[1], mhdHeader.dim[0], mhdHeader.dim[2]);
353 usRawFileParser rawParser;
354 rawParser.read(image, m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * m_imageCounter + 1));
377 usMetaHeaderParser mhdParser;
378 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") +
379 m_sequenceFiles.at(2 * m_imageCounter));
380 return mhdParser.getMHDHeader().timestamp.at(0);
389 usMetaHeaderParser mhdParser;
390 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") +
391 m_sequenceFiles.at(2 * m_imageCounter));
392 std::vector<uint64_t> timestamps = mhdParser.getMHDHeader().timestamp;
393 if (m_imageCounter % 2 == 0)
394 std::reverse(timestamps.begin(), timestamps.end());
420 if (imageNumber > (
unsigned int)m_totalImageNumber)
421 throw(vpException(vpException::fatalError,
422 "usMHDSequenceReader : trying to acquire an image with an index out of sequence bounds !"));
425 throw(vpException(vpException::fatalError,
"usMHDSequenceReader trying to open a non-mhd file !"));
427 usMetaHeaderParser mhdParser;
428 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * imageNumber));
429 m_sequenceImageType = mhdParser.getImageType();
431 throw(vpException(vpException::badValue,
"Reading a non rf 2D image!"));
433 if (mhdParser.getElementType() != usMetaHeaderParser::MET_SHORT) {
434 throw(vpException(vpException::badValue,
"Reading a non short image!"));
437 usMetaHeaderParser::MHDHeader mhdHeader = mhdParser.getMHDHeader();
438 timestamp = mhdHeader.timestamp.at(0);
451 image.
resize(mhdHeader.dim[1], mhdHeader.dim[0]);
454 usRawFileParser rawParser;
455 rawParser.read(image, m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * imageNumber + 1));
469 if (imageNumber > (
unsigned int)m_totalImageNumber)
470 throw(vpException(vpException::fatalError,
471 "usMHDSequenceReader : trying to acquire an image with an index out of sequence bounds !"));
474 throw(vpException(vpException::fatalError,
"usMHDSequenceReader trying to open a non-mhd file !"));
476 usMetaHeaderParser mhdParser;
477 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * imageNumber));
478 m_sequenceImageType = mhdParser.getImageType();
480 throw(vpException(vpException::badValue,
"Reading a non pre-scan 2D image!"));
482 if (mhdParser.getElementType() != usMetaHeaderParser::MET_UCHAR) {
483 throw(vpException(vpException::badValue,
"Reading a non unsigned char image!"));
486 usMetaHeaderParser::MHDHeader mhdHeader = mhdParser.getMHDHeader();
487 timestamp = mhdHeader.timestamp.at(0);
500 image.
resize(mhdHeader.dim[1], mhdHeader.dim[0]);
503 usRawFileParser rawParser;
504 rawParser.read(image, m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * imageNumber + 1));
518 if (imageNumber > (
unsigned int)m_totalImageNumber)
519 throw(vpException(vpException::fatalError,
520 "usMHDSequenceReader : trying to acquire an image with an index out of sequence bounds !"));
523 throw(vpException(vpException::fatalError,
"usMHDSequenceReader trying to open a non-mhd file !"));
525 usMetaHeaderParser mhdParser;
526 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * imageNumber));
527 m_sequenceImageType = mhdParser.getImageType();
529 throw(vpException(vpException::badValue,
"Reading a non post-scan 2D image!"));
531 if (mhdParser.getElementType() != usMetaHeaderParser::MET_UCHAR) {
532 throw(vpException(vpException::badValue,
"Reading a non unsigned char image!"));
535 usMetaHeaderParser::MHDHeader mhdHeader = mhdParser.getMHDHeader();
536 timestamp = mhdHeader.timestamp.at(0);
544 if (mhdHeader.isTransducerConvex) {
546 double deltaDepthPostScan2D =
547 mhdHeader.transducerRadius *
548 (1 - std::cos((
double)((mhdHeader.scanLineNumber - 1) * mhdHeader.scanLinePitch / 2.0)));
549 image.
setDepth(mhdHeader.elementSpacing[1] * mhdHeader.dim[1] - deltaDepthPostScan2D);
551 image.
setDepth(mhdHeader.elementSpacing[1] * mhdHeader.dim[1]);
559 image.resize(mhdHeader.dim[1], mhdHeader.dim[0]);
562 usRawFileParser rawParser;
563 rawParser.read(image, m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * imageNumber + 1));
574 std::vector<uint64_t> ×tamp)
576 if (imageNumber > (
unsigned int)m_totalImageNumber)
577 throw(vpException(vpException::fatalError,
"usMHDSequenceReader : end of sequence reached !"));
580 throw(vpException(vpException::fatalError,
"usMHDSequenceReader trying to open a non-mhd file !"));
582 usMetaHeaderParser mhdParser;
583 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * imageNumber));
584 m_sequenceImageType = mhdParser.getImageType();
586 throw(vpException(vpException::badValue,
"Reading a non rf 3D image!"));
588 if (mhdParser.getElementType() != usMetaHeaderParser::MET_SHORT) {
589 throw(vpException(vpException::badValue,
"Reading a non short image!"));
592 usMetaHeaderParser::MHDHeader mhdHeader = mhdParser.getMHDHeader();
593 timestamp = mhdHeader.timestamp;
594 if (imageNumber % 2 == 1)
595 std::reverse(timestamp.begin(), timestamp.end());
615 image.
resize(mhdHeader.dim[1], mhdHeader.dim[0], mhdHeader.dim[2]);
618 usRawFileParser rawParser;
619 rawParser.read(image, m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * imageNumber + 1));
631 std::vector<uint64_t> ×tamp)
633 if (imageNumber > (
unsigned int)m_totalImageNumber)
634 throw(vpException(vpException::fatalError,
"usMHDSequenceReader : end of sequence reached !"));
637 throw(vpException(vpException::fatalError,
"usMHDSequenceReader trying to open a non-mhd file !"));
639 usMetaHeaderParser mhdParser;
640 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * imageNumber));
641 m_sequenceImageType = mhdParser.getImageType();
643 throw(vpException(vpException::badValue,
"Reading a non pre-scan 3D image!"));
645 if (mhdParser.getElementType() != usMetaHeaderParser::MET_UCHAR) {
646 throw(vpException(vpException::badValue,
"Reading a non unsigned char image!"));
649 usMetaHeaderParser::MHDHeader mhdHeader = mhdParser.getMHDHeader();
650 timestamp = mhdHeader.timestamp;
651 if (imageNumber % 2 == 1)
652 std::reverse(timestamp.begin(), timestamp.end());
672 image.
resize(mhdHeader.dim[1], mhdHeader.dim[0], mhdHeader.dim[2]);
675 usRawFileParser rawParser;
676 rawParser.read(image, m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * imageNumber + 1));
690 if (imageNumber > (
unsigned int)m_totalImageNumber)
691 throw(vpException(vpException::fatalError,
692 "usMHDSequenceReader : trying to acquire an image with an index out of sequence bounds !"));
695 throw(vpException(vpException::fatalError,
"usMHDSequenceReader trying to open a non-mhd file !"));
697 usMetaHeaderParser mhdParser;
698 mhdParser.read(m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * imageNumber));
699 m_sequenceImageType = mhdParser.getImageType();
701 throw(vpException(vpException::badValue,
"Reading a non post-scan 3D image!"));
703 if (mhdParser.getElementType() != usMetaHeaderParser::MET_UCHAR) {
704 throw(vpException(vpException::badValue,
"Reading a non unsigned char image!"));
707 usMetaHeaderParser::MHDHeader mhdHeader = mhdParser.getMHDHeader();
709 if (mhdHeader.timestamp.size() > 0)
710 timestamp = mhdHeader.timestamp.at(0);
713 image.
resize(mhdHeader.dim[1], mhdHeader.dim[0], mhdHeader.dim[2]);
730 usRawFileParser rawParser;
731 rawParser.read(image, m_sequenceDirectory + vpIoTools::path(
"/") + m_sequenceFiles.at(2 * imageNumber + 1));
void resize(unsigned int height, unsigned int width, unsigned int numberOfFrames)
static usHeaderFormatType getHeaderFormat(const std::string &headerfilename)
void setWidthResolution(double widthResolution)
void setElementSpacingZ(double elementSpacingZ)
void setElementSpacingX(double elementSpacingX)
void setElementSpacingY(double elementSpacingY)
void resize(const unsigned int h, const unsigned int w)
void resize(unsigned int height, unsigned int width, unsigned int numberOfFrames)
Settings associated to ultrasound pre-scan images implemented in usImageRF2D, usImageRF3D,...
void setImagePreScanSettings(const usImagePreScanSettings &preScanSettings)
double getAxialResolution() const
void setAxialResolution(const double axialResolution)
void resize(const unsigned int height, const unsigned int width)
void resize(unsigned int height, unsigned int width, unsigned int numberOfFrames)
int getImageNumber() const
void acquire(usImageRF2D< short int > &image, uint64_t ×tamp)
std::vector< uint64_t > getNextTimeStamps()
void getImage(unsigned int imageNumber, usImageRF2D< short int > &image, uint64_t ×tamp)
void setSequenceDirectory(const std::string sequenceDirectory)
us::ImageType getImageType() const
uint64_t getNextTimeStamp()
int getTotalImageNumber() const
Generic class for 3D ultrasound motor settings associated to the 3D probe used during acquisition.
void setMotorSettings(const usMotorSettings &other)
void setMotorType(const usMotorType &motorType)
void setMotorRadius(double motorRadius)
void setFrameNumber(unsigned int frameNumber)
void setFramePitch(double framePitch)
void setTransducerConvexity(const bool isTransducerConvex)
void setDepth(double depth)
void setScanLinePitch(const double scanLinePitch)
void setTransmitFrequency(const int transmitFrequency)
void setSamplingFrequency(const int samplingFrequency)
void setTransducerRadius(const double transducerRadius)
void setScanLineNumber(unsigned int scanLineNumber)