40 #ifndef __usSequenceReader_h_
41 #define __usSequenceReader_h_
49 #include <visp3/core/vpConfig.h>
53 #include <visp3/core/vpException.h>
54 #include <visp3/core/vpImage.h>
55 #include <visp3/io/vpImageIo.h>
57 #include <visp3/ustk_core/usImageIo.h>
58 #include <visp3/ustk_core/usImageSettingsXmlParser.h>
78 bool m_firstFrameIsSet;
82 bool m_lastFrameIsSet;
90 std::string m_sequenceFileName;
91 std::string m_genericImageFileName;
98 bool m_enableLoopCycling;
105 std::vector<uint64_t> m_timestamps;
114 void acquire(ImageType &image, uint64_t ×tamp);
126 if (m_enableLoopCycling) {
127 if (loopIncrement == 1) {
128 if (m_frameCount > m_lastFrame) {
134 else if (loopIncrement == -1) {
135 if (m_frameCount < m_firstFrame) {
142 else if (m_frameCount > m_lastFrame || m_frameCount < m_firstFrame)
166 void open(ImageType &image, uint64_t ×tamp);
182 template <
class ImageType>
184 : m_frame(), m_frameRate(0.0), m_firstFrame(0), m_firstFrameIsSet(false), m_lastFrame(0), m_lastFrameIsSet(false),
185 m_frameCount(0), m_sequenceFileName(
""), m_genericImageFileName(
""), m_fileNameIsSet(false), is_open(false),
186 m_enableLoopCycling(false), loopIncrement(1)
200 m_sequenceFileName = sequenceFileName;
201 m_fileNameIsSet =
true;
210 m_firstFrame = firstIndex;
211 m_firstFrameIsSet =
true;
220 m_lastFrame = lastIndex;
221 m_lastFrameIsSet =
true;
231 throw(vpException(vpException::notImplementedError));
243 throw(vpException(vpException::notImplementedError));
248 if (!m_fileNameIsSet) {
249 throw(vpException(vpException::badValue,
"Sequence settings file name not set"));
252 m_xmlParser.parse(m_sequenceFileName);
254 throw(vpException(vpException::badValue),
"trying to open a non-usImagePreScan2D image !");
256 setFirstFrameIndex(m_xmlParser.getSequenceStartNumber());
257 setLastFrameIndex(m_xmlParser.getSequenceStopNumber());
258 m_frameRate = m_xmlParser.getSequenceFrameRate();
259 m_genericImageFileName = m_xmlParser.getImageFileName();
262 m_frame.setTransducerRadius(m_xmlParser.getTransducerSettings().getTransducerRadius());
263 m_frame.setScanLinePitch(m_xmlParser.getTransducerSettings().getScanLinePitch());
264 m_frame.setScanLineNumber(m_xmlParser.getTransducerSettings().getScanLineNumber());
265 m_frame.setTransducerConvexity(m_xmlParser.getTransducerSettings().isTransducerConvex());
266 m_frame.setAxialResolution(m_xmlParser.getAxialResolution());
267 m_frame.setSamplingFrequency(m_xmlParser.getTransducerSettings().getSamplingFrequency());
268 m_frame.setTransmitFrequency(m_xmlParser.getTransducerSettings().getTransmitFrequency());
271 char buffer[FILENAME_MAX];
272 snprintf(buffer, FILENAME_MAX, m_genericImageFileName.c_str(), m_firstFrame);
273 std::string imageFileName;
275 std::vector<std::string> splitName =
276 vpIoTools::splitChain(vpIoTools::splitChain(m_genericImageFileName, std::string(
"/")).back(), std::string(
"."));
278 std::string parentName = vpIoTools::getParent(m_sequenceFileName);
279 if (!parentName.empty()) {
280 parentName = parentName + vpIoTools::path(
"/");
282 std::vector<std::string> splitNameDirs = vpIoTools::splitChain(m_genericImageFileName, std::string(
"/"));
283 if (splitNameDirs.size() > 1) {
284 for (
unsigned int i = 0; i < splitNameDirs.size() - 1; i++)
285 parentName += (splitNameDirs.at(i) + vpIoTools::path(
"/"));
287 if (splitName.size() == 2) {
288 imageFileName = parentName + vpIoTools::splitChain(std::string(buffer), std::string(
"/")).back();
290 else if (splitName.size() == 3) {
291 std::vector<std::string> dirFiles;
293 if (vpIoTools::checkDirectory(vpIoTools::getParent(m_sequenceFileName))) {
294 dirFiles = vpIoTools::getDirFiles(parentName);
296 if (dirFiles.size() == (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() +
298 for (
unsigned int i = 0; i < dirFiles.size(); i++) {
299 if (vpIoTools::splitChain(dirFiles.at(i), std::string(
".")).at(1) == std::string(
"xml"))
300 dirFiles.erase(dirFiles.begin() + i);
303 if (dirFiles.size() !=
304 (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() + 1))
305 throw(vpException(vpException::fatalError,
"For imgage sequnces with timeStamps, the directory must contain "
306 "only the entire image sequence (no additionnal files allowed)"));
310 while (i < dirFiles.size()) {
311 uint64_t timestamp_temp;
312 std::istringstream(vpIoTools::splitChain(dirFiles.at(i), std::string(
".")).at(1)) >> timestamp_temp;
313 m_timestamps.push_back(timestamp_temp);
316 imageFileName = parentName + dirFiles.front();
319 throw(vpException(vpException::fatalError),
"Sequence filename incorrect !");
323 vpImageIo::read(image, imageFileName);
325 m_frame.setDepth((image.getHeight() - 1) * m_frame.getAxialResolution());
329 int scanlineNumber = image.getWidth();
333 m_frameCount = m_firstFrame + 1;
341 if (!m_fileNameIsSet) {
342 throw(vpException(vpException::badValue,
"Sequence settings file name not set"));
345 m_xmlParser.parse(m_sequenceFileName);
347 throw(vpException(vpException::badValue),
"trying to open a non-usImagePreScan2D image !");
349 setFirstFrameIndex(m_xmlParser.getSequenceStartNumber());
350 setLastFrameIndex(m_xmlParser.getSequenceStopNumber());
351 m_frameRate = m_xmlParser.getSequenceFrameRate();
352 m_genericImageFileName = m_xmlParser.getImageFileName();
355 m_frame.setTransducerRadius(m_xmlParser.getTransducerSettings().getTransducerRadius());
356 m_frame.setScanLinePitch(m_xmlParser.getTransducerSettings().getScanLinePitch());
357 m_frame.setScanLineNumber(m_xmlParser.getTransducerSettings().getScanLineNumber());
358 m_frame.setTransducerConvexity(m_xmlParser.getTransducerSettings().isTransducerConvex());
359 m_frame.setAxialResolution(m_xmlParser.getAxialResolution());
360 m_frame.setSamplingFrequency(m_xmlParser.getTransducerSettings().getSamplingFrequency());
361 m_frame.setTransmitFrequency(m_xmlParser.getTransducerSettings().getTransmitFrequency());
364 char buffer[FILENAME_MAX];
365 snprintf(buffer, FILENAME_MAX, m_genericImageFileName.c_str(), m_firstFrame);
366 std::string imageFileName;
368 std::vector<std::string> splitName =
369 vpIoTools::splitChain(vpIoTools::splitChain(m_genericImageFileName, std::string(
"/")).back(), std::string(
"."));
371 std::string parentName = vpIoTools::getParent(m_sequenceFileName);
372 if (!parentName.empty()) {
373 parentName = parentName + vpIoTools::path(
"/");
375 std::vector<std::string> splitNameDirs = vpIoTools::splitChain(m_genericImageFileName, std::string(
"/"));
376 if (splitNameDirs.size() > 1) {
377 for (
unsigned int i = 0; i < splitNameDirs.size() - 1; i++)
378 parentName += (splitNameDirs.at(i) + vpIoTools::path(
"/"));
380 if (splitName.size() == 2) {
381 imageFileName = parentName + vpIoTools::splitChain(std::string(buffer), std::string(
"/")).back();
383 m_timestamps.clear();
384 m_timestamps.push_back(timestamp);
386 else if (splitName.size() == 3) {
387 std::vector<std::string> dirFiles;
389 if (vpIoTools::checkDirectory(vpIoTools::getParent(m_sequenceFileName))) {
390 dirFiles = vpIoTools::getDirFiles(parentName);
392 if (dirFiles.size() == (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() +
394 for (
unsigned int i = 0; i < dirFiles.size(); i++) {
395 if (vpIoTools::splitChain(dirFiles.at(i), std::string(
".")).at(1) == std::string(
"xml"))
396 dirFiles.erase(dirFiles.begin() + i);
399 if (dirFiles.size() !=
400 (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() + 1))
401 throw(vpException(vpException::fatalError,
"For imgage sequnces with timeStamps, the directory must contain "
402 "only the entire image sequence (no additionnal files allowed)"));
406 while (i < dirFiles.size()) {
407 uint64_t timestamp_temp;
408 std::istringstream(vpIoTools::splitChain(dirFiles.at(i), std::string(
".")).at(1)) >> timestamp_temp;
409 m_timestamps.push_back(timestamp_temp);
412 std::istringstream(vpIoTools::splitChain(dirFiles.at(0), std::string(
".")).at(1)) >> timestamp;
414 imageFileName = parentName + dirFiles.front();
417 throw(vpException(vpException::fatalError),
"Sequence filename incorrect !");
421 vpImageIo::read(image, imageFileName);
423 m_frame.setDepth((image.getHeight() - 1) * m_frame.getAxialResolution());
427 int scanlineNumber = image.getWidth();
431 m_frameCount = m_firstFrame + 1;
438 if (!m_fileNameIsSet) {
439 throw(vpException(vpException::badValue,
"Sequence settings file name not set"));
442 m_xmlParser.parse(m_sequenceFileName);
444 throw(vpException(vpException::badValue),
"trying to open a non-usImagePostScan2D image !");
446 setFirstFrameIndex(m_xmlParser.getSequenceStartNumber());
447 setLastFrameIndex(m_xmlParser.getSequenceStopNumber());
448 m_frameRate = m_xmlParser.getSequenceFrameRate();
449 m_genericImageFileName = m_xmlParser.getImageFileName();
452 m_frame.setTransducerRadius(m_xmlParser.getTransducerSettings().getTransducerRadius());
453 m_frame.setScanLinePitch(m_xmlParser.getTransducerSettings().getScanLinePitch());
454 m_frame.setScanLineNumber(m_xmlParser.getTransducerSettings().getScanLineNumber());
455 m_frame.setTransducerConvexity(m_xmlParser.getTransducerSettings().isTransducerConvex());
456 m_frame.setWidthResolution(m_xmlParser.getWidthResolution());
457 m_frame.setHeightResolution(m_xmlParser.getHeightResolution());
458 m_frame.setSamplingFrequency(m_xmlParser.getTransducerSettings().getSamplingFrequency());
459 m_frame.setTransmitFrequency(m_xmlParser.getTransducerSettings().getTransmitFrequency());
462 char buffer[FILENAME_MAX];
463 snprintf(buffer, FILENAME_MAX, m_genericImageFileName.c_str(), m_firstFrame);
464 std::string imageFileName;
466 std::vector<std::string> splitName =
467 vpIoTools::splitChain(vpIoTools::splitChain(m_genericImageFileName, std::string(
"/")).back(), std::string(
"."));
469 std::string parentName = vpIoTools::getParent(m_sequenceFileName);
470 if (!parentName.empty()) {
471 parentName = parentName + vpIoTools::path(
"/");
473 std::vector<std::string> splitNameDirs = vpIoTools::splitChain(m_genericImageFileName, std::string(
"/"));
474 if (splitNameDirs.size() > 1) {
475 for (
unsigned int i = 0; i < splitNameDirs.size() - 1; i++)
476 parentName += (splitNameDirs.at(i) + vpIoTools::path(
"/"));
478 if (splitName.size() == 2) {
479 imageFileName = parentName + vpIoTools::splitChain(std::string(buffer), std::string(
"/")).back();
481 else if (splitName.size() == 3) {
482 std::vector<std::string> dirFiles;
484 if (vpIoTools::checkDirectory(vpIoTools::getParent(m_sequenceFileName))) {
485 dirFiles = vpIoTools::getDirFiles(parentName);
487 if (dirFiles.size() == (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() +
489 for (
unsigned int i = 0; i < dirFiles.size(); i++) {
490 if (vpIoTools::splitChain(dirFiles.at(i), std::string(
".")).at(1) == std::string(
"xml"))
491 dirFiles.erase(dirFiles.begin() + i);
495 if (dirFiles.size() !=
496 (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() + 1))
497 throw(vpException(vpException::fatalError,
"For imgage sequnces with timeStamps, the directory must contain "
498 "only the entire image sequence (no additionnal files allowed)"));
502 while (i < dirFiles.size()) {
503 uint64_t timestamp_temp;
504 std::istringstream(vpIoTools::splitChain(dirFiles.at(i), std::string(
".")).at(1)) >> timestamp_temp;
505 m_timestamps.push_back(timestamp_temp);
509 imageFileName = parentName + dirFiles.front();
512 throw(vpException(vpException::fatalError),
"Sequence filename incorrect !");
516 vpImageIo::read(image, imageFileName);
529 m_frameCount = m_firstFrame + 1;
537 if (!m_fileNameIsSet) {
538 throw(vpException(vpException::badValue,
"Sequence settings file name not set"));
541 m_xmlParser.parse(m_sequenceFileName);
543 throw(vpException(vpException::badValue),
"trying to open a non-usImagePostScan2D image !");
545 setFirstFrameIndex(m_xmlParser.getSequenceStartNumber());
546 setLastFrameIndex(m_xmlParser.getSequenceStopNumber());
547 m_frameRate = m_xmlParser.getSequenceFrameRate();
548 m_genericImageFileName = m_xmlParser.getImageFileName();
551 m_frame.setTransducerRadius(m_xmlParser.getTransducerSettings().getTransducerRadius());
552 m_frame.setScanLinePitch(m_xmlParser.getTransducerSettings().getScanLinePitch());
553 m_frame.setScanLineNumber(m_xmlParser.getTransducerSettings().getScanLineNumber());
554 m_frame.setTransducerConvexity(m_xmlParser.getTransducerSettings().isTransducerConvex());
555 m_frame.setWidthResolution(m_xmlParser.getWidthResolution());
556 m_frame.setHeightResolution(m_xmlParser.getHeightResolution());
557 m_frame.setSamplingFrequency(m_xmlParser.getTransducerSettings().getSamplingFrequency());
558 m_frame.setTransmitFrequency(m_xmlParser.getTransducerSettings().getTransmitFrequency());
561 char buffer[FILENAME_MAX];
562 snprintf(buffer, FILENAME_MAX, m_genericImageFileName.c_str(), m_firstFrame);
563 std::string imageFileName;
565 std::vector<std::string> splitName =
566 vpIoTools::splitChain(vpIoTools::splitChain(m_genericImageFileName, std::string(
"/")).back(), std::string(
"."));
568 std::string parentName = vpIoTools::getParent(m_sequenceFileName);
569 if (!parentName.empty()) {
570 parentName = parentName + vpIoTools::path(
"/");
572 std::vector<std::string> splitNameDirs = vpIoTools::splitChain(m_genericImageFileName, std::string(
"/"));
573 if (splitNameDirs.size() > 1) {
574 for (
unsigned int i = 0; i < splitNameDirs.size() - 1; i++)
575 parentName += (splitNameDirs.at(i) + vpIoTools::path(
"/"));
577 if (splitName.size() == 2) {
578 imageFileName = parentName + vpIoTools::splitChain(std::string(buffer), std::string(
"/")).back();
581 else if (splitName.size() == 3) {
582 std::istringstream(splitName.at(1)) >> timestamp;
583 std::vector<std::string> dirFiles;
585 if (vpIoTools::checkDirectory(vpIoTools::getParent(m_sequenceFileName))) {
586 dirFiles = vpIoTools::getDirFiles(parentName);
588 if (dirFiles.size() == (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() +
590 for (
unsigned int i = 0; i < dirFiles.size(); i++) {
591 if (vpIoTools::splitChain(dirFiles.at(i), std::string(
".")).at(1) == std::string(
"xml"))
592 dirFiles.erase(dirFiles.begin() + i);
596 std::istringstream(vpIoTools::splitChain(dirFiles.at(0), std::string(
".")).at(1)) >> timestamp;
598 if (dirFiles.size() !=
599 (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() + 1))
600 throw(vpException(vpException::fatalError,
"For imgage sequnces with timeStamps, the directory must contain "
601 "only the entire image sequence (no additionnal files allowed)"));
605 while (i < dirFiles.size()) {
606 uint64_t timestamp_temp;
607 std::istringstream(vpIoTools::splitChain(dirFiles.at(i), std::string(
".")).at(1)) >> timestamp_temp;
608 m_timestamps.push_back(timestamp_temp);
612 imageFileName = parentName + dirFiles.front();
615 throw(vpException(vpException::fatalError),
"Sequence filename incorrect !");
618 vpImageIo::read(image, imageFileName);
631 m_frameCount = m_firstFrame + 1;
647 char buffer[FILENAME_MAX];
648 snprintf(buffer, FILENAME_MAX, m_genericImageFileName.c_str(), m_frameCount);
649 std::string imageFileName;
651 std::vector<std::string> splitName =
652 vpIoTools::splitChain(vpIoTools::splitChain(m_genericImageFileName, std::string(
"/")).back(), std::string(
"."));
654 std::string parentName = vpIoTools::getParent(m_sequenceFileName);
655 if (!parentName.empty()) {
656 parentName = parentName + vpIoTools::path(
"/");
658 std::vector<std::string> splitNameDirs = vpIoTools::splitChain(m_genericImageFileName, std::string(
"/"));
659 if (splitNameDirs.size() > 1) {
660 for (
unsigned int i = 0; i < splitNameDirs.size() - 1; i++)
661 parentName += (splitNameDirs.at(i) + vpIoTools::path(
"/"));
663 if (splitName.size() == 2) {
664 imageFileName = parentName + vpIoTools::splitChain(std::string(buffer), std::string(
"/")).back();
666 else if (splitName.size() == 3) {
667 std::vector<std::string> dirFiles;
669 if (vpIoTools::checkDirectory(vpIoTools::getParent(m_sequenceFileName))) {
670 dirFiles = vpIoTools::getDirFiles(parentName);
672 if (dirFiles.size() == (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() +
674 for (
unsigned int i = 0; i < dirFiles.size(); i++) {
675 if (vpIoTools::splitChain(dirFiles.at(i), std::string(
".")).at(1) == std::string(
"xml"))
676 dirFiles.erase(dirFiles.begin() + i);
680 if (dirFiles.size() !=
681 (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() + 1))
682 throw(vpException(vpException::fatalError,
"For imgage sequnces with timeStamps, the directory must contain "
683 "only the entire image sequence (no additionnal files allowed)"));
685 imageFileName = parentName + dirFiles.at(m_frameCount);
688 throw(vpException(vpException::fatalError),
"Sequence filename incorrect !");
691 vpImageIo::read(image, imageFileName);
692 image.setTransducerSettings(m_frame);
693 image.setScanLineNumber(image.getWidth());
694 image.setDepth(m_frame.getDepth());
696 m_frameCount += loopIncrement;
707 this->open(image, timestamp);
711 char buffer[FILENAME_MAX];
712 snprintf(buffer, FILENAME_MAX, m_genericImageFileName.c_str(), m_frameCount);
713 std::string imageFileName;
715 std::vector<std::string> splitName =
716 vpIoTools::splitChain(vpIoTools::splitChain(m_genericImageFileName, std::string(
"/")).back(), std::string(
"."));
718 std::string parentName = vpIoTools::getParent(m_sequenceFileName);
719 if (!parentName.empty()) {
720 parentName = parentName + vpIoTools::path(
"/");
722 std::vector<std::string> splitNameDirs = vpIoTools::splitChain(m_genericImageFileName, std::string(
"/"));
723 if (splitNameDirs.size() > 1) {
724 for (
unsigned int i = 0; i < splitNameDirs.size() - 1; i++)
725 parentName += (splitNameDirs.at(i) + vpIoTools::path(
"/"));
727 if (splitName.size() == 2) {
728 imageFileName = parentName + vpIoTools::splitChain(std::string(buffer), std::string(
"/")).back();
731 else if (splitName.size() == 3) {
733 std::vector<std::string> dirFiles;
735 if (vpIoTools::checkDirectory(vpIoTools::getParent(m_sequenceFileName))) {
736 dirFiles = vpIoTools::getDirFiles(parentName);
738 if (dirFiles.size() == (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() +
740 for (
unsigned int i = 0; i < dirFiles.size(); i++) {
741 if (vpIoTools::splitChain(dirFiles.at(i), std::string(
".")).at(1) == std::string(
"xml"))
742 dirFiles.erase(dirFiles.begin() + i);
746 std::istringstream(vpIoTools::splitChain(dirFiles.at(m_frameCount), std::string(
".")).at(1)) >> timestamp;
748 if (dirFiles.size() !=
749 (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() + 1))
750 throw(vpException(vpException::fatalError,
"For imgage sequnces with timeStamps, the directory must contain "
751 "only the entire image sequence (no additionnal files allowed)"));
753 imageFileName = parentName + dirFiles.at(m_frameCount);
756 throw(vpException(vpException::fatalError),
"Sequence filename incorrect !");
760 vpImageIo::read(image, imageFileName);
761 image.setTransducerSettings(m_frame);
762 image.setScanLineNumber(image.getWidth());
763 image.setDepth(m_frame.getDepth());
765 m_frameCount += loopIncrement;
780 char buffer[FILENAME_MAX];
781 snprintf(buffer, FILENAME_MAX, m_genericImageFileName.c_str(), m_frameCount);
782 std::string imageFileName;
784 std::vector<std::string> splitName =
785 vpIoTools::splitChain(vpIoTools::splitChain(m_genericImageFileName, std::string(
"/")).back(), std::string(
"."));
787 std::string parentName = vpIoTools::getParent(m_sequenceFileName);
788 if (!parentName.empty()) {
789 parentName = parentName + vpIoTools::path(
"/");
791 std::vector<std::string> splitNameDirs = vpIoTools::splitChain(m_genericImageFileName, std::string(
"/"));
792 if (splitNameDirs.size() > 1) {
793 for (
unsigned int i = 0; i < splitNameDirs.size() - 1; i++)
794 parentName += (splitNameDirs.at(i) + vpIoTools::path(
"/"));
796 if (splitName.size() == 2) {
797 imageFileName = parentName + vpIoTools::splitChain(std::string(buffer), std::string(
"/")).back();
799 else if (splitName.size() == 3) {
800 std::vector<std::string> dirFiles;
802 if (vpIoTools::checkDirectory(vpIoTools::getParent(m_sequenceFileName))) {
803 dirFiles = vpIoTools::getDirFiles(parentName);
805 if (dirFiles.size() == (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() +
807 for (
unsigned int i = 0; i < dirFiles.size(); i++) {
808 if (vpIoTools::splitChain(dirFiles.at(i), std::string(
".")).at(1) == std::string(
"xml"))
809 dirFiles.erase(dirFiles.begin() + i);
813 if (dirFiles.size() !=
814 (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() + 1))
815 throw(vpException(vpException::fatalError,
"For imgage sequnces with timeStamps, the directory must contain "
816 "only the entire image sequence (no additionnal files allowed)"));
818 imageFileName = parentName + dirFiles.at(m_frameCount);
821 throw(vpException(vpException::fatalError),
"Sequence filename incorrect !");
825 vpImageIo::read(image, imageFileName);
833 m_frameCount += loopIncrement;
846 this->open(image, timestamp);
850 char buffer[FILENAME_MAX];
851 snprintf(buffer, FILENAME_MAX, m_genericImageFileName.c_str(), m_frameCount);
852 std::string imageFileName;
854 std::vector<std::string> splitName =
855 vpIoTools::splitChain(vpIoTools::splitChain(m_genericImageFileName, std::string(
"/")).back(), std::string(
"."));
857 std::string parentName = vpIoTools::getParent(m_sequenceFileName);
858 if (!parentName.empty()) {
859 parentName = parentName + vpIoTools::path(
"/");
861 std::vector<std::string> splitNameDirs = vpIoTools::splitChain(m_genericImageFileName, std::string(
"/"));
862 if (splitNameDirs.size() > 1) {
863 for (
unsigned int i = 0; i < splitNameDirs.size() - 1; i++)
864 parentName += (splitNameDirs.at(i) + vpIoTools::path(
"/"));
866 if (splitName.size() == 2) {
867 imageFileName = parentName + vpIoTools::splitChain(std::string(buffer), std::string(
"/")).back();
870 else if (splitName.size() == 3) {
871 std::vector<std::string> dirFiles;
873 if (vpIoTools::checkDirectory(vpIoTools::getParent(m_sequenceFileName))) {
874 dirFiles = vpIoTools::getDirFiles(parentName);
876 std::sort(dirFiles.begin(), dirFiles.end());
877 if (dirFiles.size() == (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() +
879 for (
unsigned int i = 0; i < dirFiles.size(); i++) {
880 if (vpIoTools::splitChain(dirFiles.at(i), std::string(
".")).at(1) == std::string(
"xml"))
881 dirFiles.erase(dirFiles.begin() + i);
884 std::istringstream(vpIoTools::splitChain(dirFiles.at(m_frameCount), std::string(
".")).at(1)) >> timestamp;
886 if (dirFiles.size() !=
887 (
unsigned int)(m_xmlParser.getSequenceStopNumber() - m_xmlParser.getSequenceStartNumber() + 1))
888 throw(vpException(vpException::fatalError,
"For imgage sequnces with timeStamps, the directory must contain "
889 "only the entire image sequence (no additionnal files allowed)"));
891 imageFileName = parentName + dirFiles.at(m_frameCount);
894 throw(vpException(vpException::fatalError),
"Sequence filename incorrect !");
898 vpImageIo::read(image, imageFileName);
906 m_frameCount += loopIncrement;
920 if (index < m_firstFrame || index > m_lastFrame) {
921 throw(vpException(vpException::badValue,
"position out of range"));
925 char buffer[FILENAME_MAX];
926 snprintf(buffer, FILENAME_MAX, m_genericImageFileName.c_str(), index);
927 std::string imageFileName = buffer;
929 vpImageIo::read(image, imageFileName);
930 image.setImageSettins(m_frame);
941 getFrame(image, index);
951 m_enableLoopCycling = activateLoopCycling;
961 return m_lastFrame - m_firstFrame + 1;
962 throw(vpException(vpException::fatalError,
"Cannot compute the frame number of the sequence before opening it !"));
973 throw(vpException(vpException::fatalError,
"Sequence not opened, xml parser is empty !"));
void setHeightResolution(double heightResolution)
double getHeightResolution() const
void setWidthResolution(double widthResolution)
void setScanLineNumber(unsigned int scanLineNumber)
void setImagePreScanSettings(const usImagePreScanSettings &preScanSettings)
void setAxialResolution(const double axialResolution)
Input/output operations between ultrasound image settings and the assiciated xml files.
Reading of sequences of ultrasound images.
virtual ~usSequenceReader()
void open(ImageType &image, uint64_t ×tamp)
void acquire(ImageType &image)
void setSequenceFileName(const std::string &sequenceFileName)
usImageSettingsXmlParser getXmlParser()
void setLastFrameIndex(long lastIndex)
std::vector< uint64_t > getSequenceTimestamps() const
long getImageNumber() const
void open(ImageType &image)
void setLoopCycling(bool activateLoopCycling)
ImageType & getFrame(int index)
double getFrameRate() const
void acquire(ImageType &image, uint64_t ×tamp)
void setFirstFrameIndex(long firstIndex)
void getFrame(ImageType &image, int index)
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 setTransducerSettings(const usTransducerSettings &other)
void setScanLineNumber(unsigned int scanLineNumber)