MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkUSDeviceWriterXML.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
13// MITK
16#include <mitkIGTMimeTypes.h>
17#include <mitkLocaleSwitch.h>
18#include <mitkUSDevice.h>
19
20// Third Party
21#include <tinyxml2.h>
22#include <itksys/SystemTools.hxx>
23#include <fstream>
24#include <iostream>
25
26mitk::USDeviceWriterXML::USDeviceWriterXML() : AbstractFileWriter(USDevice::GetStaticNameOfClass(),
27 mitk::IGTMimeTypes::USDEVICEINFORMATIONXML_MIMETYPE(),
28 "MITK USDevice Writer (XML)"), m_Filename("")
29{
30 RegisterService();
31}
32
34{
35}
36
40
45
47{
48 if (m_Filename == "")
49 {
50 MITK_WARN << "Cannot write to file - empty filename!";
51 return;
52 }
53}
54
55void mitk::USDeviceWriterXML::SetFilename(std::string filename)
56{
57 m_Filename = filename;
58}
59
61{
62 tinyxml2::XMLDocument document;
63 document.InsertEndChild(document.NewDeclaration());
64
65 //Create the xml information of the ULTRASOUNDDEVICE-Tag:
66 auto *ultrasoundDeviceTag = document.NewElement(USDeviceReaderWriterConstants::TAG_ULTRASOUNDDEVICE);
67 this->CreateXmlInformationOfUltrasoundDeviceTag(document, ultrasoundDeviceTag, config);
68
69
70 //Create the xml information of the GENERALSETTINGS-Tag:
71 auto *generalSettingsTag = document.NewElement(USDeviceReaderWriterConstants::TAG_GENERALSETTINGS);
72 this->CreateXmlInformationOfGeneralSettingsTag(ultrasoundDeviceTag, generalSettingsTag, config);
73
74 //Create the xml information of the PROBES-Tag:
75 this->CreateXmlInformationOfProbesTag(ultrasoundDeviceTag, config);
76
77 return document.SaveFile(m_Filename.c_str()) == tinyxml2::XML_SUCCESS;
78}
79
81 tinyxml2::XMLDocument &document, tinyxml2::XMLElement* ultrasoundDeviceTag,
83{
84 ultrasoundDeviceTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_FILEVERS, config.fileversion);
85 ultrasoundDeviceTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_TYPE, config.deviceType.c_str());
86 ultrasoundDeviceTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_NAME, config.deviceName.c_str());
87 ultrasoundDeviceTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_MANUFACTURER, config.manufacturer.c_str());
88 ultrasoundDeviceTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_MODEL, config.model.c_str());
89 ultrasoundDeviceTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_COMMENT, config.comment.c_str());
90 ultrasoundDeviceTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_IMAGESTREAMS, config.numberOfImageStreams);
91
92 if (config.deviceType.compare("oigtl") == 0)
93 {
94 ultrasoundDeviceTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_HOST, config.host.c_str());
95 ultrasoundDeviceTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_PORT, config.port);
96 ultrasoundDeviceTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_SERVER, config.server);
97 }
98
99 document.InsertEndChild(ultrasoundDeviceTag);
100}
101
102void mitk::USDeviceWriterXML::CreateXmlInformationOfGeneralSettingsTag(tinyxml2::XMLElement *parentTag, tinyxml2::XMLElement *generalSettingsTag, mitk::USDeviceReaderXML::USDeviceConfigData & config)
103{
104 generalSettingsTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_GREYSCALE, config.useGreyscale);
106 generalSettingsTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_RESOLUTIONWIDTH, config.resolutionWidth);
107 generalSettingsTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_RESOLUTIONHEIGHT, config.resolutionHeight);
108
109 generalSettingsTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_SOURCEID, config.sourceID);
110 generalSettingsTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_FILEPATH, config.filepathVideoSource.c_str());
111 generalSettingsTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_OPENCVPORT, config.opencvPort);
112
113 parentTag->InsertEndChild(generalSettingsTag);
114}
115
117{
118 if (config.probes.size() != 0)
119 {
120 auto* doc = parentTag->GetDocument();
121 auto *probesTag = doc->NewElement(USDeviceReaderWriterConstants::TAG_PROBES);
122 parentTag->InsertEndChild(probesTag);
123
124 for (size_t index = 0; index < config.probes.size(); ++index)
125 {
126 auto *probeTag = doc->NewElement(USDeviceReaderWriterConstants::TAG_PROBE);
127 probesTag->InsertEndChild(probeTag);
128
129 mitk::USProbe::Pointer probe = config.probes.at(index);
130 probeTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_NAME, probe->GetName().c_str());
131 std::map<int, mitk::Vector3D> depthsAndSpacing = probe->GetDepthsAndSpacing();
132 if (depthsAndSpacing.size() != 0)
133 {
134 auto *depthsTag = doc->NewElement(USDeviceReaderWriterConstants::TAG_DEPTHS);
135 probeTag->InsertEndChild(depthsTag);
136 for (std::map<int, mitk::Vector3D>::iterator it = depthsAndSpacing.begin(); it != depthsAndSpacing.end(); it++)
137 {
138 auto *depthTag = doc->NewElement(USDeviceReaderWriterConstants::TAG_DEPTH);
139 depthTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_DEPTH, it->first);
140 depthsTag->InsertEndChild(depthTag);
141
142 auto *spacingTag = doc->NewElement(USDeviceReaderWriterConstants::TAG_SPACING);
143 spacingTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_X, it->second[0]);
144 spacingTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_Y, it->second[1]);
145 depthTag->InsertEndChild(spacingTag);
146 }
147
148 auto *croppingTag = doc->NewElement(USDeviceReaderWriterConstants::TAG_CROPPING);
149 probeTag->InsertEndChild(croppingTag);
150 croppingTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_TOP, probe->GetProbeCropping().top);
151 croppingTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_BOTTOM, probe->GetProbeCropping().bottom);
152 croppingTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_LEFT, probe->GetProbeCropping().left);
153 croppingTag->SetAttribute(USDeviceReaderWriterConstants::ATTR_RIGHT, probe->GetProbeCropping().right);
154 }
155 }
156 }
157}
void CreateXmlInformationOfUltrasoundDeviceTag(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *ultrasoundDeviceTag, mitk::USDeviceReaderXML::USDeviceConfigData &config)
Creates the xml ULTRASOUNDDEVICE-Tag entry of the ultrasound video device configuration file.
void CreateXmlInformationOfGeneralSettingsTag(tinyxml2::XMLElement *parentTag, tinyxml2::XMLElement *generalSettingsTag, mitk::USDeviceReaderXML::USDeviceConfigData &config)
Creates the xml GENERALSETTINGS-Tag entry of the ultrasound video device configuration file.
bool WriteUltrasoundDeviceConfiguration(mitk::USDeviceReaderXML::USDeviceConfigData &config)
Writes the configuration settings of an ultrasound device to a xml-file.
void CreateXmlInformationOfProbesTag(tinyxml2::XMLElement *parentTag, mitk::USDeviceReaderXML::USDeviceConfigData &config)
Creates the xml PROBES-Tag entry of the ultrasound video device configuration file....
void SetFilename(std::string filename)
Sets the filename of the ultrasound device configuration file which should be created.
mitk::USDeviceWriterXML * Clone() const override
A device holds information about it's model, make and the connected probes. It is the common super cl...
IGT Exceptions.
std::vector< mitk::USProbe::Pointer > probes