1 #include "vvReadState.h"
2 #include "vvMainWindow.h"
3 #include "vvSlicerManager.h"
5 #include <qtreewidget.h>
8 #include <QXmlStreamReader>
13 vvReadState::vvReadState() : m_XmlReader(new QXmlStreamReader), m_File(new QFile)
18 vvReadState::~vvReadState()
22 void vvReadState::Run(vvMainWindow* vvWindow, const std::string& file)
27 m_File->setFileName(file.c_str());
28 m_File->open(QIODevice::ReadOnly);
29 m_XmlReader->setDevice(m_File.get());
31 QTreeWidget* tree = m_Window->GetTree();
32 m_TreeItemCount = tree->topLevelItemCount();
38 void vvReadState::ReadTree()
42 while (!m_XmlReader->atEnd()) {
43 m_XmlReader->readNext();
44 value = m_XmlReader->qualifiedName().toString().toStdString();
45 if (m_XmlReader->isStartElement()) {
51 if (m_XmlReader->hasError())
52 std::cout << "Error " << m_XmlReader->error() << " XML " << std::endl;
55 std::string vvReadState::ReadImage()
58 int current_index = -1;
59 std::vector<std::string> files(1);
61 QXmlStreamAttributes attributes = m_XmlReader->attributes();
62 if (!m_XmlReader->hasError())
63 current_index = attributes.value("Index").toString().toInt();
65 current_index += m_TreeItemCount;
67 while (!m_XmlReader->isEndElement() || value != "Image") {
68 m_XmlReader->readNext();
69 value = m_XmlReader->qualifiedName().toString().toStdString();
70 //std::cout << "Value = " << value << std::endl;
71 if (m_XmlReader->isStartElement()) {
72 if (value == "FileName") {
73 files[0] = m_XmlReader->readElementText().toStdString();
74 if (!m_XmlReader->hasError()) {
75 m_Window->LoadImages(files, vvImageReader::IMAGE);
78 else if (current_index >= 0) {
79 if (value == "Fusion")
80 value = ReadFusion(current_index);
81 else if (value == "Overlay")
82 value = ReadOverlay(current_index);
83 else if (value == "Vector")
84 value = ReadVector(current_index);
89 if (!m_XmlReader->hasError())
95 std::string vvReadState::ReadFusion(int index)
97 std::string file, value;
100 vvSlicerManager* slicerManager = m_Window->GetSlicerManagers()[index];
101 while (!m_XmlReader->isEndElement() || value != "Fusion") {
102 m_XmlReader->readNext();
103 value = m_XmlReader->qualifiedName().toString().toStdString();
104 if (m_XmlReader->isStartElement()) {
105 if (value == "FileName") {
106 file = m_XmlReader->readElementText().toStdString();
107 if (!m_XmlReader->hasError())
108 m_Window->AddFusionImage(index, file.c_str());
110 if (value == "FusionOpacity") {
111 vali = m_XmlReader->readElementText().toInt();
112 if (!m_XmlReader->hasError())
113 slicerManager->SetFusionOpacity(vali);
115 if (value == "FusionThresholdOpacity") {
116 vali = m_XmlReader->readElementText().toInt();
117 if (!m_XmlReader->hasError())
118 slicerManager->SetFusionThresholdOpacity(vali);
120 if (value == "FusionColorMap") {
121 vali = m_XmlReader->readElementText().toInt();
122 if (!m_XmlReader->hasError())
123 slicerManager->SetFusionColorMap(vali);
125 if (value == "FusionWindow") {
126 vald = m_XmlReader->readElementText().toDouble();
127 if (!m_XmlReader->hasError())
128 slicerManager->SetFusionWindow(vald);
130 if (value == "FusionLevel") {
131 vald = m_XmlReader->readElementText().toDouble();
132 if (!m_XmlReader->hasError())
133 slicerManager->SetFusionLevel(vald);
137 m_Window->ImageInfoChanged();
141 std::string vvReadState::ReadOverlay(int index)
143 std::string file, value;
146 vvSlicerManager* slicerManager = m_Window->GetSlicerManagers()[index];
147 while (!m_XmlReader->isEndElement() || value != "Overlay") {
148 m_XmlReader->readNext();
149 value = m_XmlReader->qualifiedName().toString().toStdString();
150 if (m_XmlReader->isStartElement()) {
151 if (value == "FileName") {
152 file = m_XmlReader->readElementText().toStdString();
153 if (!m_XmlReader->hasError())
154 m_Window->AddOverlayImage(index, file.c_str());
156 if (value == "OverlayColorWindow") {
157 vald = m_XmlReader->readElementText().toDouble();
158 if (!m_XmlReader->hasError())
159 slicerManager->SetOverlayColorWindow(vald);
161 if (value == "OverlayColorLevel") {
162 vald = m_XmlReader->readElementText().toDouble();
163 if (!m_XmlReader->hasError())
164 slicerManager->SetOverlayColorLevel(vald);
166 if (value == "LinkOverlayWindowLevel") {
167 vali = m_XmlReader->readElementText().toInt();
168 if (!m_XmlReader->hasError())
169 slicerManager->SetLinkOverlayWindowLevel(vali);
171 if (value == "OverlayColor") {
172 vali = m_XmlReader->readElementText().toInt();
173 if (!m_XmlReader->hasError())
174 slicerManager->SetOverlayColor(vali);
178 m_Window->ImageInfoChanged();
182 std::string vvReadState::ReadVector(int index)
184 std::string file, value;
185 while (!m_XmlReader->isEndElement() || value != "Vector") {
186 m_XmlReader->readNext();
187 value = m_XmlReader->qualifiedName().toString().toStdString();
188 if (m_XmlReader->isStartElement()) {
189 if (value == "FileName") {
190 file = m_XmlReader->readElementText().toStdString();
191 if (!m_XmlReader->hasError())
192 m_Window->AddField(file.c_str(), index);
199 void vvReadState::ReadGUI()