Medical Imaging Interaction Toolkit  2018.4.99-07c45cb1
Medical Imaging Interaction Toolkit
mitkUSDeviceWriterXML.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 // MITK
15 #include "mitkUSDeviceWriterXML.h"
16 #include <mitkIGTMimeTypes.h>
17 #include <mitkLocaleSwitch.h>
18 #include <mitkUSDevice.h>
19 
20 // Third Party
21 #include <tinyxml.h>
22 #include <itksys/SystemTools.hxx>
23 #include <fstream>
24 #include <iostream>
25 
27  mitk::IGTMimeTypes::USDEVICEINFORMATIONXML_MIMETYPE(),
28  "MITK USDevice Writer (XML)"), m_Filename("")
29 {
31 }
32 
34 {
35 }
36 
38 {
39 }
40 
42 {
43  return new USDeviceWriterXML(*this);
44 }
45 
47 {
48  if (m_Filename == "")
49  {
50  MITK_WARN << "Cannot write to file - empty filename!";
51  return;
52  }
53 }
54 
55 void mitk::USDeviceWriterXML::SetFilename(std::string filename)
56 {
57  m_Filename = filename;
58 }
59 
61 {
62  TiXmlDocument document;
63  TiXmlDeclaration* xmlDeclaration = new TiXmlDeclaration("1.0", "", "");
64  document.LinkEndChild(xmlDeclaration);
65 
66 
67  //Create the xml information of the ULTRASOUNDDEVICE-Tag:
68  TiXmlElement *ultrasoundDeviceTag = new TiXmlElement(TAG_ULTRASOUNDDEVICE);
69  this->CreateXmlInformationOfUltrasoundDeviceTag(document, ultrasoundDeviceTag, config);
70 
71 
72  //Create the xml information of the GENERALSETTINGS-Tag:
73  TiXmlElement *generalSettingsTag = new TiXmlElement(TAG_GENERALSETTINGS);
74  this->CreateXmlInformationOfGeneralSettingsTag(ultrasoundDeviceTag, generalSettingsTag, config);
75 
76  //Create the xml information of the PROBES-Tag:
77  this->CreateXmlInformationOfProbesTag(ultrasoundDeviceTag, config);
78 
79  return document.SaveFile(m_Filename);
80 }
81 
83  TiXmlDocument &document, TiXmlElement * ultrasoundDeviceTag,
85 {
86  ultrasoundDeviceTag->SetAttribute(ATTR_FILEVERS, config.fileversion);
87  ultrasoundDeviceTag->SetAttribute(ATTR_TYPE, config.deviceType);
88  ultrasoundDeviceTag->SetAttribute(ATTR_NAME, config.deviceName);
89  ultrasoundDeviceTag->SetAttribute(ATTR_MANUFACTURER, config.manufacturer);
90  ultrasoundDeviceTag->SetAttribute(ATTR_MODEL, config.model);
91  ultrasoundDeviceTag->SetAttribute(ATTR_COMMENT, config.comment);
92  ultrasoundDeviceTag->SetAttribute(ATTR_IMAGESTREAMS, config.numberOfImageStreams);
93 
94  if (config.deviceType.compare("oigtl") == 0)
95  {
96  ultrasoundDeviceTag->SetAttribute(ATTR_HOST, config.host);
97  ultrasoundDeviceTag->SetAttribute(ATTR_PORT, config.port);
98  std::string value = config.server ? "true" : "false";
99  ultrasoundDeviceTag->SetAttribute(ATTR_SERVER, value);
100  }
101 
102  document.LinkEndChild(ultrasoundDeviceTag);
103 }
104 
105 void mitk::USDeviceWriterXML::CreateXmlInformationOfGeneralSettingsTag(TiXmlElement *parentTag, TiXmlElement *generalSettingsTag, mitk::USDeviceReaderXML::USDeviceConfigData & config)
106 {
107  std::string value = config.useGreyscale ? "true" : "false";
108  generalSettingsTag->SetAttribute(ATTR_GREYSCALE, value);
109  value = config.useResolutionOverride ? "true" : "false";
110  generalSettingsTag->SetAttribute(ATTR_RESOLUTIONOVERRIDE, value);
111  generalSettingsTag->SetAttribute(ATTR_RESOLUTIONWIDTH, config.resolutionWidth);
112  generalSettingsTag->SetAttribute(ATTR_RESOLUTIONHEIGHT, config.resolutionHeight);
113 
114  generalSettingsTag->SetAttribute(ATTR_SOURCEID, config.sourceID);
115  generalSettingsTag->SetAttribute(ATTR_FILEPATH, config.filepathVideoSource);
116  generalSettingsTag->SetAttribute(ATTR_OPENCVPORT, config.opencvPort);
117 
118  parentTag->LinkEndChild(generalSettingsTag);
119 }
120 
122 {
123  if (config.probes.size() != 0)
124  {
125  TiXmlElement *probesTag = new TiXmlElement(TAG_PROBES);
126  parentTag->LinkEndChild(probesTag);
127 
128  for (size_t index = 0; index < config.probes.size(); ++index)
129  {
130  TiXmlElement *probeTag = new TiXmlElement(TAG_PROBE);
131  probesTag->LinkEndChild(probeTag);
132 
133  mitk::USProbe::Pointer probe = config.probes.at(index);
134  probeTag->SetAttribute(ATTR_NAME, probe->GetName());
135  std::map<int, mitk::Vector3D> depthsAndSpacing = probe->GetDepthsAndSpacing();
136  if (depthsAndSpacing.size() != 0)
137  {
138  TiXmlElement *depthsTag = new TiXmlElement(TAG_DEPTHS);
139  probeTag->LinkEndChild(depthsTag);
140  for (std::map<int, mitk::Vector3D>::iterator it = depthsAndSpacing.begin(); it != depthsAndSpacing.end(); it++)
141  {
142  TiXmlElement *depthTag = new TiXmlElement(TAG_DEPTH);
143  depthTag->SetAttribute(ATTR_DEPTH, it->first);
144  depthsTag->LinkEndChild(depthTag);
145 
146  TiXmlElement *spacingTag = new TiXmlElement(TAG_SPACING);
147  spacingTag->SetDoubleAttribute(ATTR_X, it->second[0], 6);
148  spacingTag->SetDoubleAttribute(ATTR_Y, it->second[1], 6);
149  depthTag->LinkEndChild(spacingTag);
150  }
151 
152  TiXmlElement *croppingTag = new TiXmlElement(TAG_CROPPING);
153  probeTag->LinkEndChild(croppingTag);
154  croppingTag->SetAttribute(ATTR_TOP, probe->GetProbeCropping().top);
155  croppingTag->SetAttribute(ATTR_BOTTOM, probe->GetProbeCropping().bottom);
156  croppingTag->SetAttribute(ATTR_LEFT, probe->GetProbeCropping().left);
157  croppingTag->SetAttribute(ATTR_RIGHT, probe->GetProbeCropping().right);
158  }
159  }
160  }
161 }
A device holds information about it&#39;s model, make and the connected probes. It is the common super cl...
Definition: mitkUSDevice.h:73
void CreateXmlInformationOfUltrasoundDeviceTag(TiXmlDocument &document, TiXmlElement *ultrasoundDeviceTag, mitk::USDeviceReaderXML::USDeviceConfigData &config)
Creates the xml ULTRASOUNDDEVICE-Tag entry of the ultrasound video device configuration file...
static const char * TAG_CROPPING
static const char * TAG_DEPTH
void CreateXmlInformationOfGeneralSettingsTag(TiXmlElement *parentTag, TiXmlElement *generalSettingsTag, mitk::USDeviceReaderXML::USDeviceConfigData &config)
Creates the xml GENERALSETTINGS-Tag entry of the ultrasound video device configuration file...
static const char * ATTR_OPENCVPORT
static const char * ATTR_SERVER
static const char * TAG_PROBE
static const char * ATTR_RIGHT
DataCollection - Class to facilitate loading/accessing structured data.
static const char * ATTR_GREYSCALE
static const char * ATTR_RESOLUTIONWIDTH
std::vector< mitk::USProbe::Pointer > probes
void Write() override
Write the base data to the specified location or output stream.
static const char * ATTR_TOP
static const char * ATTR_DEPTH
static const char * ATTR_Y
#define MITK_WARN
Definition: mitkLogMacros.h:19
static const char * ATTR_LEFT
static const char * ATTR_COMMENT
static const char * ATTR_X
static const char * ATTR_TYPE
void SetFilename(std::string filename)
Sets the filename of the ultrasound device configuration file which should be created.
static const char * ATTR_IMAGESTREAMS
static const char * ATTR_PORT
mitk::USDeviceWriterXML * Clone() const override
static const char * ATTR_FILEVERS
bool WriteUltrasoundDeviceConfiguration(mitk::USDeviceReaderXML::USDeviceConfigData &config)
Writes the configuration settings of an ultrasound device to a xml-file.
static const char * ATTR_FILEPATH
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
static const char * ATTR_RESOLUTIONHEIGHT
static const char * ATTR_MODEL
static const char * ATTR_BOTTOM
static const char * TAG_ULTRASOUNDDEVICE
static const char * TAG_SPACING
static const char * ATTR_NAME
static const char * ATTR_HOST
Base class for writing mitk::BaseData objects to files or streams.
static const char * TAG_GENERALSETTINGS
static const char * ATTR_RESOLUTIONOVERRIDE
static const char * ATTR_MANUFACTURER
void CreateXmlInformationOfProbesTag(TiXmlElement *parentTag, mitk::USDeviceReaderXML::USDeviceConfigData &config)
Creates the xml PROBES-Tag entry of the ultrasound video device configuration file. All information of all configured probes is extracted and then stored in the xml file.
static const char * TAG_PROBES
static const char * TAG_DEPTHS
static const char * ATTR_SOURCEID