38 #include <visp3/ustk_core/usImageSettingsXmlParser.h>
42 #include <libxml/parser.h>
48 : m_transducerSettings(
usTransducerSettings()), m_spacingX(0.0), m_spacingY(0.0), m_spacingZ(0.0),
49 m_motorSettings(
usMotorSettings()), m_imageFileName(std::string(
"")), m_image_type(
us::UNKNOWN), m_is_3D(false),
119 for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
120 if (dataNode->type == XML_ELEMENT_NODE) {
121 std::map<std::string, int>::iterator iter_data = this->nodeMap.find((
char *)dataNode->name);
122 if (iter_data != nodeMap.end()) {
123 switch (iter_data->second) {
125 value = xmlReadStringChild(doc, dataNode);
126 if (strcmp(value.c_str(),
"postscan") == 0) {
129 else if (strcmp(value.c_str(),
"prescan") == 0) {
132 else if (strcmp(value.c_str(),
"rf") == 0) {
136 throw(vpException(vpException::fatalError, std::string(
"unknown image type in xml file")));
140 this->m_axialResolution = xmlReadDoubleChild(doc, dataNode);
143 throw(vpException(vpException::fatalError,
144 std::string(
"Trying to assign an axial resolution to a post-scan image !")));
148 throw(vpException(vpException::fatalError,
149 std::string(
"Trying to assign an height resolution to a pre-scan image !")));
151 else if (this->m_is_3D) {
153 vpException::fatalError,
154 std::string(
"Trying to assign an height resolution to a 3D image ! Use spacing_y instead.")));
157 this->m_heightResolution = xmlReadDoubleChild(doc, dataNode);
161 throw(vpException(vpException::fatalError,
162 std::string(
"Trying to assign an width resolution to a pre-scan image !")));
164 else if (this->m_is_3D) {
166 vpException::fatalError,
167 std::string(
"Trying to assign an height resolution to a 3D image ! Use spacing_x instead.")));
170 this->m_widthResolution = xmlReadDoubleChild(doc, dataNode);
175 vpException(vpException::fatalError, std::string(
"Trying to assign a spacing to a pre-scan image !")));
177 else if (!this->m_is_3D) {
179 vpException::fatalError,
180 std::string(
"Trying to assign a spacing to a 2D image ! Use height/width resolutions instead.")));
183 this->m_widthResolution = xmlReadDoubleChild(doc, dataNode);
188 vpException(vpException::fatalError, std::string(
"Trying to assign a spacing to a pre-scan image !")));
190 else if (!this->m_is_3D) {
192 vpException::fatalError,
193 std::string(
"Trying to assign an spacing to a 2D image ! Use height/width resolutions instead.")));
196 this->m_widthResolution = xmlReadDoubleChild(doc, dataNode);
201 vpException(vpException::fatalError, std::string(
"Trying to assign a spacing to a pre-scan image !")));
203 else if (!this->m_is_3D) {
205 vpException::fatalError,
206 std::string(
"Trying to assign an spacing to a 2D image ! Use height/width resolutions instead.")));
209 this->m_widthResolution = xmlReadDoubleChild(doc, dataNode);
213 throw(vpException(vpException::fatalError,
214 std::string(
"Trying to assign a scan line number to a pre-scan image (for pre-scan "
215 "images scan line number is the image width) !")));
221 this->m_transducerSettings.
setScanLinePitch(xmlReadDoubleChild(doc, dataNode));
222 this->m_transducerSettings.
setScanLinePitch(xmlReadDoubleChild(doc, dataNode));
239 this->m_motorSettings.
setFramePitch(xmlReadDoubleChild(doc, dataNode));
242 this->m_motorSettings.
setMotorRadius(xmlReadDoubleChild(doc, dataNode));
245 value = xmlReadStringChild(doc, dataNode);
246 if (strcmp(value.c_str(),
"linear_motor") == 0) {
249 else if (strcmp(value.c_str(),
"tilting_motor") == 0) {
252 else if (strcmp(value.c_str(),
"rotational_motor") == 0) {
256 throw(vpException(vpException::fatalError, std::string(
"unknown image type in xml file")));
260 this->m_imageFileName = xmlReadStringChild(doc, dataNode);
263 this->m_sequence_frame_rate = xmlReadDoubleChild(doc, dataNode);
264 this->m_is_sequence =
true;
267 this->m_sequence_start = xmlReadIntChild(doc, dataNode);
268 this->m_is_sequence =
true;
271 this->m_sequence_stop = xmlReadIntChild(doc, dataNode);
272 this->m_is_sequence =
true;
275 vpTRACE(
"unknown tag in readConfigNode : %d, %s", iter_data->second, (iter_data->first).c_str());
289 std::string imageFileName = m_imageFileName;
290 xmlWriteStringChild(node,
"image_file_name", imageFileName);
292 xmlWriteStringChild(node,
"image_type", std::string(
"rf"));
293 xmlWriteDoubleChild(node,
"scanline_pitch", m_transducerSettings.
getScanLinePitch());
295 xmlWriteBoolChild(node,
"is_probe_convex", m_transducerSettings.
isTransducerConvex());
296 xmlWriteDoubleChild(node,
"axial_resolution", m_axialResolution);
301 xmlWriteStringChild(node,
"image_type", std::string(
"prescan"));
302 xmlWriteDoubleChild(node,
"scanline_pitch", m_transducerSettings.
getScanLinePitch());
304 xmlWriteBoolChild(node,
"is_probe_convex", m_transducerSettings.
isTransducerConvex());
305 xmlWriteDoubleChild(node,
"axial_resolution", m_axialResolution);
310 xmlWriteStringChild(node,
"image_type", std::string(
"postscan"));
311 xmlWriteDoubleChild(node,
"scanline_pitch", m_transducerSettings.
getScanLinePitch());
313 xmlWriteBoolChild(node,
"is_probe_convex", m_transducerSettings.
isTransducerConvex());
314 xmlWriteIntChild(node,
"scanline_number", m_transducerSettings.
getScanLineNumber());
318 xmlWriteIntChild(node,
"frame_number", m_motorSettings.
getFrameNumber());
319 xmlWriteDoubleChild(node,
"spacing_x", m_spacingX);
320 xmlWriteDoubleChild(node,
"spacing_y", m_spacingY);
321 xmlWriteDoubleChild(node,
"spacing_z", m_spacingZ);
324 xmlWriteDoubleChild(node,
"height_resolution", m_heightResolution);
325 xmlWriteDoubleChild(node,
"width_resolution", m_widthResolution);
329 xmlWriteDoubleChild(node,
"frame_pitch", m_motorSettings.
getFramePitch());
330 xmlWriteDoubleChild(node,
"motor_radius", m_motorSettings.
getMotorRadius());
332 xmlWriteStringChild(node,
"motor_type", std::string(
"linear_motor"));
335 xmlWriteStringChild(node,
"motor_type", std::string(
"tilting_motor"));
338 xmlWriteStringChild(node,
"motor_type", std::string(
"rotational_motor"));
342 std::cout <<
"writing sequence parameters" << std::endl;
344 xmlWriteDoubleChild(node,
"sequence_frame_rate", this->m_sequence_frame_rate);
345 xmlWriteIntChild(node,
"sequence_start_number", this->m_sequence_start);
346 xmlWriteIntChild(node,
"sequence_stop_number", this->m_sequence_stop);
361 double axialResolution,
us::ImageType image_type,
int samplingFrequency,
362 int transmitFrequency)
370 m_axialResolution = axialResolution;
371 m_image_type = image_type;
374 throw(vpException(vpException::fatalError,
"trying to write axial resolution in a image not rf nor pre-scan !"));
390 unsigned int scanLineNumber,
double widthResolution,
391 double heightResolution,
int samplingFrequency,
int transmitFrequency)
399 m_heightResolution = widthResolution;
400 m_widthResolution = heightResolution;
411 m_motorSettings = motorSettings;
Input/output operations between ultrasound image settings and the associated xml files.
double getSpacingX() const
void setMotorSettings(const usMotorSettings &motorSettings)
usImageSettingsXmlParser & operator=(const usImageSettingsXmlParser &twinparser)
double getWidthResolution() const
usMotorSettings getMotorSettings() const
double getSpacingY() const
void setImageFileName(const std::string &imageFileName)
us::ImageType getImageType() const
usImageSettingsXmlParser()
usTransducerSettings getTransducerSettings() const
void setImageSettings(double transducerRadius, double scanLinePitch, bool isTransducerConvex, double axialResolution, us::ImageType image_type, int samplingFrequency, int transmitFrequency)
std::string getImageFileName() const
virtual ~usImageSettingsXmlParser()
@ CODE_XML_HEIGHT_RESOLUTION
@ CODE_XML_SAMPLING_FREQUENCY
@ CODE_XML_SCANLINE_NUMBER
@ CODE_XML_SCANLINE_PITCH
@ CODE_XML_WIDTH_RESOLUTION
@ CODE_XML_TRANSDUCER_RADIUS
@ CODE_XML_SEQUENCE_FRAME_RATE
@ CODE_XML_AXIAL_RESOLUTION
@ CODE_XML_SEQUENCE_LAST_IMAGE_NUMBER
@ CODE_XML_IS_TRANSDUCER_CONVEX
@ CODE_XML_ASSOCIATED_IMAGE_FILE_NAME
@ CODE_XML_TRANSMIT_FREQUENCY
@ CODE_XML_SEQUENCE_FIRST_IMAGE_NUMBER
double getHeightResolution() const
double getAxialResolution() const
void writeMainClass(xmlNodePtr node)
double getSpacingZ() const
void readMainClass(xmlDocPtr doc, xmlNodePtr node)
Generic class for 3D ultrasound motor settings associated to the 3D probe used during acquisition.
unsigned int getFrameNumber() const
double getMotorRadius() const
void setMotorType(const usMotorType &motorType)
void setMotorRadius(double motorRadius)
double getFramePitch() const
usMotorType getMotorType() const
void setFramePitch(double framePitch)
Generic class for 2D ultrasound data common settings associated to the type of probe transducer used ...
void setTransducerConvexity(const bool isTransducerConvex)
int getTransmitFrequency() const
void setScanLinePitch(const double scanLinePitch)
void setTransmitFrequency(const int transmitFrequency)
double getScanLinePitch() const
void setSamplingFrequency(const int samplingFrequency)
void setTransducerRadius(const double transducerRadius)
bool isTransducerConvex() const
double getTransducerRadius() const
int getSamplingFrequency() const
unsigned int getScanLineNumber() const
void setScanLineNumber(unsigned int scanLineNumber)