40 #ifndef __usSequenceReader3D_h_
41 #define __usSequenceReader3D_h_
48 #include <visp3/core/vpDebug.h>
49 #include <visp3/core/vpException.h>
51 #include <visp3/ustk_core/usImageIo.h>
66 void open(ImageType &image);
74 std::string m_fileName;
81 usImageIo::VolHeader m_volHeader;
84 std::ifstream m_volFile;
107 if (m_frameCount > m_volHeader.volumes)
124 template <
class ImageType>
126 : m_frameCount(0), m_fileName(
""), m_fileNameIsSet(false), is_open(false), m_volHeader()
141 m_fileName = fileName;
142 m_fileNameIsSet =
true;
152 throw(vpException(vpException::notImplementedError));
192 if (!m_fileNameIsSet) {
193 throw(vpException(vpException::badValue,
"Sequence file name not set"));
197 throw(vpException(vpException::ioError,
"only .vol files are supported for 3D sequence reading"));
200 int szHeader =
sizeof(usImageIo::VolHeader);
205 m_volFile.open(m_fileName.c_str(), std::ios::in | std::ios::binary);
208 while (n < szHeader) {
209 m_volFile.read(&
byte, 1);
210 ((
char *)&m_volHeader)[n] = byte;
213 std::cout <<
"fpv " << m_volHeader.fpv << std::endl;
214 std::cout <<
"w " << m_volHeader.w << std::endl;
215 std::cout <<
"h " << m_volHeader.h << std::endl;
218 if (m_volHeader.type != 0)
219 throw(vpException(vpException::badValue,
"trying to read non-prescan in .vol file"));
222 if (m_volHeader.ss != 8)
223 throw(vpException(vpException::badValue,
".vol file doesn't contain unsigned char data"));
226 image.
resize(m_volHeader.h, m_volHeader.w, m_volHeader.fpv);
229 for (
int k = 0; k < m_volHeader.fpv; k++) {
230 for (
int j = 0; j < m_volHeader.w; j++) {
231 for (
int i = 0; i < m_volHeader.h; i++) {
232 m_volFile.read((
char *)&voxel, 1);
233 image(j, i, k, voxel);
244 if (!m_fileNameIsSet) {
245 throw(vpException(vpException::badValue,
"Sequence file name not set"));
249 throw(vpException(vpException::ioError,
"only .vol files are supported for 3D sequence reading"));
252 int szHeader =
sizeof(usImageIo::VolHeader);
257 m_volFile.open(m_fileName.c_str(), std::ios::in | std::ios::binary);
260 while (n < szHeader) {
261 m_volFile.read(&
byte, 1);
262 ((
char *)&m_volHeader)[n] = byte;
265 std::cout <<
"fpv " << m_volHeader.fpv << std::endl;
266 std::cout <<
"w " << m_volHeader.w << std::endl;
267 std::cout <<
"h " << m_volHeader.h << std::endl;
270 if (m_volHeader.type != 1)
271 throw(vpException(vpException::badValue,
"trying to read non-postscan in .vol file"));
274 if (m_volHeader.ss != 8)
275 throw(vpException(vpException::badValue,
".vol file doesn't contain unsigned char data"));
278 image.
resize(m_volHeader.h, m_volHeader.w, m_volHeader.fpv);
281 for (
int k = 0; k < m_volHeader.fpv; k++) {
282 for (
int i = 0; i < m_volHeader.h; i++) {
283 for (
int j = 0; j < m_volHeader.w; j++) {
284 m_volFile.read((
char *)&voxel, 1);
285 image(j, i, k, voxel);
305 image.
resize(m_volHeader.h, m_volHeader.w, m_volHeader.fpv);
307 for (
int k = 0; k < m_volHeader.fpv; k++) {
308 for (
int j = 0; j < m_volHeader.w; j++) {
309 for (
int i = 0; i < m_volHeader.h; i++) {
310 m_volFile.read((
char *)&voxel, 1);
311 image(j, i, k, voxel);
330 image.
resize(m_volHeader.h, m_volHeader.w, m_volHeader.fpv);
332 for (
int k = 0; k < m_volHeader.fpv; k++) {
333 for (
int i = 0; i < m_volHeader.h; i++) {
334 for (
int j = 0; j < m_volHeader.w; j++) {
335 m_volFile.read((
char *)&voxel, 1);
336 image(j, i, k, voxel);
355 int volumeNumberInSequence)
358 this->open(preScanImage);
363 if (m_volHeader.type != 0)
364 throw(vpException(vpException::badValue,
"trying to read non-prescan in .vol file"));
367 if (m_volHeader.ss != 8)
368 throw(vpException(vpException::badValue,
".vol file doesn't contain unsigned char data"));
372 int szHeader =
sizeof(usImageIo::VolHeader);
373 int offset = szHeader + volumeNumberInSequence * m_volHeader.fpv * m_volHeader.w * m_volHeader.h;
374 m_volFile.seekg(offset);
377 preScanImage.
resize(m_volHeader.h, m_volHeader.w, m_volHeader.fpv);
379 for (
int k = 0; k < m_volHeader.fpv; k++) {
380 for (
int j = 0; j < m_volHeader.w; j++) {
381 for (
int i = 0; i < m_volHeader.h; i++) {
382 m_volFile.read((
char *)&voxel, 1);
383 preScanImage(j, i, k, voxel);
void resize(unsigned int height, unsigned int width, unsigned int numberOfFrames)
static usHeaderFormatType getHeaderFormat(const std::string &headerfilename)
void resize(unsigned int height, unsigned int width, unsigned int numberOfFrames)
Reading of sequences of ultrasound images.
void setSequenceFileName(const std::string &sequenceFileName)
long getImageNumber() const
void acquire(ImageType &image)
void getVolume(usImagePreScan3D< unsigned char > &preScanImage, int volumeNumberInSequence)
virtual ~usSequenceReader3D()