UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-05-20)
usMetaHeaderParser.h
1 /****************************************************************************
2  *
3  * This file is part of the ustk software.
4  * Copyright (C) 2016 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ustk with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * This software was developed at:
17  * Inria Rennes - Bretagne Atlantique
18  * Campus Universitaire de Beaulieu
19  * 35042 Rennes Cedex
20  * France
21  *
22  * If you have questions regarding the use of this file, please contact
23  * Inria at ustk@inria.fr
24  *
25  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27  *
28  * Authors:
29  * Marc Pouliquen
30  *
31  *****************************************************************************/
32 
33 #ifndef DOXYGEN_SHOULD_SKIP_THIS
39 #ifndef __usMetaHeaderParser_h_
40 #define __usMetaHeaderParser_h_
41 
42 #include <cstdlib>
43 #include <fstream>
44 #include <ios>
45 #include <iostream>
46 #include <map>
47 #include <sstream>
48 #include <stdint.h>
49 #include <string>
50 
51 #include <visp3/core/vpConfig.h>
52 #include <visp3/ustk_core/us.h>
53 #include <visp3/ustk_core/usImagePostScan2D.h>
54 #include <visp3/ustk_core/usImagePostScan3D.h>
55 #include <visp3/ustk_core/usImagePreScan2D.h>
56 #include <visp3/ustk_core/usImagePreScan3D.h>
57 #include <visp3/ustk_core/usImageRF2D.h>
58 #include <visp3/ustk_core/usImageRF3D.h>
59 
65 class VISP_EXPORT usMetaHeaderParser
66 {
67 
68 public:
69  typedef enum {
70  MET_UNKNOWN = -1,
71  MET_UCHAR,
72  MET_SHORT,
73  MET_DOUBLE,
74  } ElementType;
75 
76 #ifndef DOXYGEN_SHOULD_SKIP_THIS
77  struct MHDHeader {
78  std::string MHDFileName;
79  std::string rawFileName;
80  unsigned int numberOfDimensions;
81  int numberOfChannels;
82  ElementType elementType;
83  int dim[4];
84  double elementSpacing[4];
85  double position[4];
86  int headerSize;
87  bool msb;
88  us::ImageType imageType;
89  bool isTransducerConvex;
91  double transducerRadius;
92  double scanLinePitch;
93  double motorRadius;
94  double framePitch;
95  unsigned int scanLineNumber; // for post-scan
96  unsigned int frameNumber; // for post-scan
97  int transmitFrequency;
98  int samplingFrequency;
99  std::vector<uint64_t> timestamp;
100  };
101 #endif // DOXYGEN_SHOULD_SKIP_THIS
102 
103  // Constructor
104  usMetaHeaderParser();
105  usMetaHeaderParser(const std::string &MHDFilename);
106  // Desctructor
107  virtual ~usMetaHeaderParser();
108 
109  // Data accessors.
110  double getAxialResolution() const { return m_axialResolution; }
111  ElementType getElementType() const { return header.elementType; }
112  double getHeightResolution() const { return m_heightResolution; }
113  us::ImageType getImageType() const { return header.imageType; }
114  MHDHeader getMHDHeader() const { return header; }
115  usMotorSettings getMotorSettings() const { return m_motorSettings; }
116  std::string getRawFileName() const { return header.rawFileName; }
117  usTransducerSettings getTransducerSettings() const { return m_transducerSettings; }
118  double getWidthResolution() const { return m_widthResolution; }
119 
120  // comparison
121  bool operator==(usMetaHeaderParser const &other);
122 
123  void parse();
124 
125  void read(const std::string &filename);
126  void readMHDHeader(const std::string &fileName);
127 
128  // Setters
129  void setAxialResolution(const double axialresolution);
130  void setHeightResolution(const double heightResolution);
131  void setImageFileName(const std::string &imageFileName);
132  void setImageTimestamp(const std::vector<uint64_t> timestamp);
133  void setMHDHeader(MHDHeader header);
134  void setMotorSettings(const usMotorSettings &motorSettings);
135  void setRawFileName(const std::string &rawFileName);
136  void setTransducerSettings(const usTransducerSettings &transducerSettings);
137  void setWidthResolution(const double widthResolution);
138 
139 private:
140  usTransducerSettings m_transducerSettings;
141  usMotorSettings m_motorSettings;
142  double m_axialResolution;
143  double m_heightResolution;
144  double m_widthResolution;
145 
146  MHDHeader header;
147  std::map<std::string, int> imageTypeMap;
148  std::map<std::string, int> elementTypeMap;
149  std::map<int, std::string> imageTypeReverseMap;
150  std::map<int, std::string> elementTypeReverseMap;
151 };
152 #endif // __usMetaHeaderParser_h_
153 #endif // DOXYGEN_SHOULD_SKIP_THIS
Generic class for 3D ultrasound motor settings associated to the 3D probe used during acquisition.
Generic class for 2D ultrasound data common settings associated to the type of probe transducer used ...
ImageType
Definition: us.h:65