40 #ifndef __usSequenceWriter_h_
41 #define __usSequenceWriter_h_
48 #include <visp3/core/vpDebug.h>
49 #include <visp3/core/vpException.h>
50 #include <visp3/core/vpImage.h>
51 #include <visp3/io/vpImageIo.h>
53 #include <visp3/ustk_core/usImageIo.h>
54 #include <visp3/ustk_core/usImageSettingsXmlParser.h>
73 void saveImage(
const ImageType &image, uint64_t timestamp = 0);
89 bool m_firstFrameIsSet;
94 std::string m_sequenceFileName;
95 std::string m_genericImageFileName;
96 bool m_headerFileNameIsSet;
97 bool m_imageFileNameIsSet;
102 void open(
const ImageType &image, uint64_t timestamp = 0);
112 template <
class ImageType>
114 : m_frame(), m_frameRate(0.0), m_firstFrame(0), m_firstFrameIsSet(false), m_frameCount(0), m_sequenceFileName(
""),
115 m_genericImageFileName(
""), m_headerFileNameIsSet(false), m_imageFileNameIsSet(false), is_open(false)
141 m_sequenceFileName = sequenceFileName;
142 m_headerFileNameIsSet =
true;
155 if (m_headerFileNameIsSet) {
156 std::string relativePathToHeader = vpIoTools::getParent(imageFileName);
157 if (!relativePathToHeader.empty()) {
158 std::string fullDirName = vpIoTools::getParent(m_sequenceFileName) + vpIoTools::path(
"/") + relativePathToHeader;
159 vpIoTools::makeDirectory(fullDirName);
161 m_genericImageFileName = imageFileName;
162 m_imageFileNameIsSet =
true;
172 m_firstFrame = firstIndex;
173 m_firstFrameIsSet =
true;
182 if (!m_headerFileNameIsSet || !m_imageFileNameIsSet)
183 throw(vpException(vpException::badValue,
"file names not set"));
186 if (!m_firstFrameIsSet) {
189 m_firstFrameIsSet =
true;
196 char buffer[FILENAME_MAX];
197 snprintf(buffer, FILENAME_MAX, m_genericImageFileName.c_str(), m_frameCount);
200 if (timestamp != 0) {
201 std::vector<std::string> splitted = vpIoTools::splitChain(std::string(buffer), std::string(
"."));
202 std::string base = splitted.at(0);
203 base.append(std::string(
".%lld."));
204 base.append(splitted.at(1));
205 snprintf(buffer, FILENAME_MAX, base.c_str(), timestamp);
206 std::vector<std::string> splittedGeneric =
207 vpIoTools::splitChain(std::string(m_genericImageFileName), std::string(
"."));
208 m_genericImageFileName = splittedGeneric.at(0) + std::string(
".TIMESTAMP.") + splittedGeneric.at(1);
211 std::string imageFileName = vpIoTools::getParent(m_sequenceFileName) + vpIoTools::path(
"/") + buffer;
213 vpImageIo::write(image, imageFileName);
215 m_frameCount = m_firstFrame + 1;
226 throw(vpException(vpException::notImplementedError));
236 xmlParser.
setImageSettings(m_frame.getTransducerRadius(), m_frame.getScanLinePitch(), m_frame.isTransducerConvex(),
237 m_frame.getAxialResolution(),
us::RF_2D, m_frame.getSamplingFrequency(),
238 m_frame.getTransmitFrequency());
243 xmlParser.save(m_sequenceFileName);
244 vpXmlParser::cleanup();
254 xmlParser.
setImageSettings(m_frame.getTransducerRadius(), m_frame.getScanLinePitch(), m_frame.isTransducerConvex(),
255 m_frame.getAxialResolution(),
us::PRESCAN_2D, m_frame.getSamplingFrequency(),
256 m_frame.getTransmitFrequency());
262 xmlParser.save(m_sequenceFileName);
263 vpXmlParser::cleanup();
273 xmlParser.
setImageSettings(m_frame.getTransducerRadius(), m_frame.getScanLinePitch(), m_frame.isTransducerConvex(),
274 m_frame.getScanLineNumber(), m_frame.getWidthResolution(), m_frame.getHeightResolution(),
275 m_frame.getSamplingFrequency(), m_frame.getTransmitFrequency());
282 xmlParser.save(m_sequenceFileName);
283 vpXmlParser::cleanup();
294 open(image, timestamp);
299 char buffer[FILENAME_MAX];
300 snprintf(buffer, FILENAME_MAX, m_genericImageFileName.c_str(), m_frameCount);
303 if (timestamp != 0) {
304 std::vector<std::string> splitted = vpIoTools::splitChain(std::string(buffer), std::string(
"."));
305 std::string base = splitted.at(0);
306 base.append(std::string(
".%lld."));
307 base.append(splitted.at(2));
308 snprintf(buffer, FILENAME_MAX, base.c_str(), timestamp);
311 std::string imageFileName = vpIoTools::getParent(m_sequenceFileName) + vpIoTools::path(
"/") + buffer;
313 vpImageIo::write(image, imageFileName);
315 m_frameCount = m_frameCount + 1;
Input/output operations between ultrasound image settings and the associated xml files.
void setImageFileName(const std::string &imageFileName)
void setImageType(us::ImageType image_type)
void setImageSettings(double transducerRadius, double scanLinePitch, bool isTransducerConvex, double axialResolution, us::ImageType image_type, int samplingFrequency, int transmitFrequency)
void setSequenceStartNumber(int sequenceStartNumber)
void setSequenceStopNumber(int sequenceStopNumber)
void setSequenceFrameRate(double sequenceFrameRate)
Writing of sequences of ultrasound images.
void setFrameRate(double frameRate)
void setImageFileName(const std::string &imageFileName)
void setFirstFrameIndex(long firstIndex)
void saveImage(const ImageType &image, uint64_t timestamp=0)
double getFrameRate() const
virtual ~usSequenceWriter()
void setSequenceFileName(const std::string &sequenceFileName)