Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkTubeGraphIO.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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkTubeGraphIO.h"
18 
21 #include "mitkTubeGraphProperty.h"
22 
23 #include <mitkIOMimeTypes.h>
24 
25 #include <tinyxml.h>
26 
27 #include <vtkMatrix4x4.h>
28 
29 #include <itksys/SystemTools.hxx>
30 
31 namespace mitk
32 {
33  TubeGraphIO::TubeGraphIO(const TubeGraphIO &other) : AbstractFileIO(other) {}
34  TubeGraphIO::TubeGraphIO()
36  mitk::TubeGraph::GetStaticNameOfClass(), mitk::TubeGraphIO::TUBEGRAPH_MIMETYPE(), "Tube Graph Structure File")
37  {
38  this->RegisterService();
39  }
40 
41  std::vector<BaseData::Pointer> TubeGraphIO::Read()
42  {
43  std::locale::global(std::locale("C"));
44 
45  std::vector<itk::SmartPointer<mitk::BaseData>> result;
46 
47  InputStream stream(this);
48 
49  TiXmlDocument doc;
50  stream >> doc;
51  if (!doc.Error())
52  {
53  TubeGraph::Pointer newTubeGraph = TubeGraph::New();
54 
55  TiXmlHandle hDoc(&doc);
56  TiXmlElement *pElem;
57  TiXmlHandle hRoot(0);
58 
59  pElem = hDoc.FirstChildElement().Element();
60 
61  // save this for later
62  hRoot = TiXmlHandle(pElem);
63 
64  pElem = hRoot.FirstChildElement(mitk::TubeGraphDefinitions::XML_GEOMETRY).Element();
65 
66  // read geometry
68  geometry->Initialize();
69 
70  // read origin
71  mitk::Point3D origin;
72  double temp = 0;
73  pElem->Attribute(mitk::TubeGraphDefinitions::XML_ORIGIN_X, &temp);
74  origin[0] = temp;
75  pElem->Attribute(mitk::TubeGraphDefinitions::XML_ORIGIN_Y, &temp);
76  origin[1] = temp;
77  pElem->Attribute(mitk::TubeGraphDefinitions::XML_ORIGIN_Z, &temp);
78  origin[2] = temp;
79  geometry->SetOrigin(origin);
80 
81  // read spacing
82  Vector3D spacing;
83  pElem->Attribute(mitk::TubeGraphDefinitions::XML_SPACING_X, &temp);
84  spacing.SetElement(0, temp);
85  pElem->Attribute(mitk::TubeGraphDefinitions::XML_SPACING_Y, &temp);
86  spacing.SetElement(1, temp);
87  pElem->Attribute(mitk::TubeGraphDefinitions::XML_SPACING_Z, &temp);
88  spacing.SetElement(2, temp);
89  geometry->SetSpacing(spacing);
90 
91  // read transform
92  vtkMatrix4x4 *m = vtkMatrix4x4::New();
93  pElem->Attribute(mitk::TubeGraphDefinitions::XML_MATRIX_XX, &temp);
94  m->SetElement(0, 0, temp);
95  pElem->Attribute(mitk::TubeGraphDefinitions::XML_MATRIX_XY, &temp);
96  m->SetElement(1, 0, temp);
97  pElem->Attribute(mitk::TubeGraphDefinitions::XML_MATRIX_XZ, &temp);
98  m->SetElement(2, 0, temp);
99  pElem->Attribute(mitk::TubeGraphDefinitions::XML_MATRIX_YX, &temp);
100  m->SetElement(0, 1, temp);
101  pElem->Attribute(mitk::TubeGraphDefinitions::XML_MATRIX_YY, &temp);
102  m->SetElement(1, 1, temp);
103  pElem->Attribute(mitk::TubeGraphDefinitions::XML_MATRIX_YZ, &temp);
104  m->SetElement(2, 1, temp);
105  pElem->Attribute(mitk::TubeGraphDefinitions::XML_MATRIX_ZX, &temp);
106  m->SetElement(0, 2, temp);
107  pElem->Attribute(mitk::TubeGraphDefinitions::XML_MATRIX_ZY, &temp);
108  m->SetElement(1, 2, temp);
109  pElem->Attribute(mitk::TubeGraphDefinitions::XML_MATRIX_ZZ, &temp);
110  m->SetElement(2, 2, temp);
111 
112  m->SetElement(0, 3, origin[0]);
113  m->SetElement(1, 3, origin[1]);
114  m->SetElement(2, 3, origin[2]);
115  m->SetElement(3, 3, 1);
116  geometry->SetIndexToWorldTransformByVtkMatrix(m);
117 
118  geometry->SetImageGeometry(false);
119 
120  // read tube graph
121 
122  // read vertices
123  pElem = hRoot.FirstChildElement(mitk::TubeGraphDefinitions::XML_VERTICES).Element();
124  if (pElem != 0)
125  {
126  // walk through the vertices
127  TiXmlElement *vertexElement = pElem->FirstChildElement();
128 
129  for (vertexElement; vertexElement; vertexElement = vertexElement->NextSiblingElement())
130  {
131  int vertexID(0);
132  mitk::Point3D coordinate;
133  coordinate.Fill(0.0);
134  double diameter(0);
135 
136  vertexElement->Attribute(mitk::TubeGraphDefinitions::XML_VERTEX_ID, &vertexID);
137 
138  TiXmlElement *tubeElement = vertexElement->FirstChildElement();
139 
140  tubeElement->Attribute(mitk::TubeGraphDefinitions::XML_ELEMENT_X, &temp);
141  coordinate[0] = temp;
142  tubeElement->Attribute(mitk::TubeGraphDefinitions::XML_ELEMENT_Y, &temp);
143  coordinate[1] = temp;
144  tubeElement->Attribute(mitk::TubeGraphDefinitions::XML_ELEMENT_Z, &temp);
145  coordinate[2] = temp;
146  tubeElement->Attribute(mitk::TubeGraphDefinitions::XML_ELEMENT_DIAMETER, &diameter);
147 
148  mitk::TubeGraphVertex vertexData;
149  mitk::CircularProfileTubeElement *newElement = new mitk::CircularProfileTubeElement(coordinate, diameter);
150  vertexData.SetTubeElement(newElement);
151 
152  mitk::TubeGraph::VertexDescriptorType newVertex = newTubeGraph->AddVertex(vertexData);
153  if (newVertex != vertexID)
154  {
155  MITK_ERROR << "Aborting tube graph creation, different vertex ids.";
156  return result;
157  ;
158  }
159  }
160  }
161 
162  // read edges
163  pElem = hRoot.FirstChildElement(mitk::TubeGraphDefinitions::XML_EDGES).Element();
164  if (pElem != 0)
165  {
166  // walk through the edges
167  TiXmlElement *edgeElement = pElem->FirstChildElement();
168 
169  for (edgeElement; edgeElement; edgeElement = edgeElement->NextSiblingElement())
170  {
171  int edgeID(0), edgeSourceID(0), edgeTargetID(0);
172  mitk::Point3D coordinate;
173  double diameter(0);
174 
175  edgeElement->Attribute(mitk::TubeGraphDefinitions::XML_EDGE_ID, &edgeID);
176  edgeElement->Attribute(mitk::TubeGraphDefinitions::XML_EDGE_SOURCE_ID, &edgeSourceID);
177  edgeElement->Attribute(mitk::TubeGraphDefinitions::XML_EDGE_TARGET_ID, &edgeTargetID);
178 
179  mitk::TubeGraphEdge edgeData;
180 
181  TiXmlElement *tubeElement = edgeElement->FirstChildElement(mitk::TubeGraphDefinitions::XML_ELEMENT);
182  for (tubeElement; tubeElement; tubeElement = tubeElement->NextSiblingElement())
183  {
184  tubeElement->Attribute(mitk::TubeGraphDefinitions::XML_ELEMENT_X, &temp);
185  coordinate[0] = temp;
186  tubeElement->Attribute(mitk::TubeGraphDefinitions::XML_ELEMENT_Y, &temp);
187  coordinate[1] = temp;
188  tubeElement->Attribute(mitk::TubeGraphDefinitions::XML_ELEMENT_Z, &temp);
189  coordinate[2] = temp;
190  tubeElement->Attribute(mitk::TubeGraphDefinitions::XML_ELEMENT_DIAMETER, &diameter);
191 
192  mitk::CircularProfileTubeElement *newElement = new mitk::CircularProfileTubeElement(coordinate, diameter);
193 
194  edgeData.AddTubeElement(newElement);
195  }
196  try
197  {
198  newTubeGraph->AddEdge(edgeSourceID, edgeTargetID, edgeData);
199  }
200  catch (const std::runtime_error &error)
201  {
202  MITK_ERROR << error.what();
203  return result;
204  }
205  }
206  }
207 
208  // Compute bounding box
209  BoundingBox::Pointer bb = this->ComputeBoundingBox(newTubeGraph);
210  geometry->SetBounds(bb->GetBounds());
211 
212  MITK_INFO << "Tube Graph read";
213  MITK_INFO << "Edge numb:" << newTubeGraph->GetNumberOfEdges()
214  << " Vertices: " << newTubeGraph->GetNumberOfVertices();
215 
216  MITK_INFO << "Reading tube graph property";
218 
219  // read label groups
220  pElem = hRoot.FirstChildElement(mitk::TubeGraphDefinitions::XML_LABELGROUPS).Element();
221  if (pElem != 0)
222  {
223  // walk through the label groups
224  TiXmlElement *labelGroupElement = pElem->FirstChildElement();
225 
226  for (labelGroupElement; labelGroupElement; labelGroupElement = labelGroupElement->NextSiblingElement())
227  {
229  const char *labelGroupName;
230 
231  labelGroupName =
232  labelGroupElement->Attribute((char *)mitk::TubeGraphDefinitions::XML_LABELGROUP_NAME.c_str());
233  if (labelGroupName)
234  newLabelGroup->labelGroupName = labelGroupName;
235 
236  // labelGroupElement->Attribute(mitk::TubeGraphDefinitions::XML_LABELGROUP_NAME, &labelGroupName);
237  // newLabelGroup.labeGroupName = labelGroupName;
238 
239  TiXmlElement *labelElement = labelGroupElement->FirstChildElement(mitk::TubeGraphDefinitions::XML_LABEL);
240  for (labelElement; labelElement; labelElement = labelElement->NextSiblingElement())
241  {
243  const char *labelName;
244  bool isVisible = true;
245  Color color;
246 
247  labelName = labelElement->Attribute((char *)mitk::TubeGraphDefinitions::XML_LABEL_NAME.c_str());
248  if (labelName)
249  newLabel->labelName = labelName;
250 
251  labelElement->Attribute(mitk::TubeGraphDefinitions::XML_LABEL_VISIBILITY, &temp);
252  if (temp == 0)
253  isVisible = false;
254  else
255  isVisible = true;
256  labelElement->Attribute(mitk::TubeGraphDefinitions::XML_LABEL_COLOR_R, &temp);
257  color[0] = temp;
258  labelElement->Attribute(mitk::TubeGraphDefinitions::XML_LABEL_COLOR_G, &temp);
259  color[1] = temp;
260  labelElement->Attribute(mitk::TubeGraphDefinitions::XML_LABEL_COLOR_B, &temp);
261  color[2] = temp;
262 
263  newLabel->isVisible = isVisible;
264  newLabel->labelColor = color;
265  newLabelGroup->labels.push_back(newLabel);
266  }
267  newProperty->AddLabelGroup(newLabelGroup, newProperty->GetLabelGroups().size());
268  }
269  }
270  // read attributations
271  pElem = hRoot.FirstChildElement(mitk::TubeGraphDefinitions::XML_ATTRIBUTIONS).Element();
272  if (pElem != 0)
273  {
274  TiXmlElement *tubeToLabelElement = pElem->FirstChildElement();
275  std::map<TubeGraphProperty::TubeToLabelGroupType, std::string> tubeToLabelsMap;
276  for (tubeToLabelElement; tubeToLabelElement; tubeToLabelElement = tubeToLabelElement->NextSiblingElement())
277  {
281 
282  tubeToLabelElement->Attribute(mitk::TubeGraphDefinitions::XML_TUBE_ID_1, &temp);
283  tube.first = temp;
284  tubeToLabelElement->Attribute(mitk::TubeGraphDefinitions::XML_TUBE_ID_2, &temp);
285  tube.second = temp;
286  const char *labelGroupName =
287  tubeToLabelElement->Attribute((char *)mitk::TubeGraphDefinitions::XML_LABELGROUP_NAME.c_str());
288  if (labelGroupName)
289  labelGroup = newProperty->GetLabelGroupByName(labelGroupName);
290 
291  const char *labelName =
292  tubeToLabelElement->Attribute((char *)mitk::TubeGraphDefinitions::XML_LABEL_NAME.c_str());
293  if (labelName)
294  label = newProperty->GetLabelByName(labelGroup, labelName);
295 
296  if (tube != TubeGraph::ErrorId && labelGroup != NULL && label != NULL)
297  {
298  TubeGraphProperty::TubeToLabelGroupType tubeToLabelGroup(tube, labelGroupName);
299  tubeToLabelsMap.insert(
300  std::pair<TubeGraphProperty::TubeToLabelGroupType, std::string>(tubeToLabelGroup, labelName));
301  }
302  }
303  if (tubeToLabelsMap.size() > 0)
304  newProperty->SetTubesToLabels(tubeToLabelsMap);
305  }
306  // read annotations
307  pElem = hRoot.FirstChildElement(mitk::TubeGraphDefinitions::XML_ANNOTATIONS).Element();
308  if (pElem != 0)
309  {
310  TiXmlElement *annotationElement = pElem->FirstChildElement();
311  for (annotationElement; annotationElement; annotationElement = annotationElement->NextSiblingElement())
312  {
314  std::string annotationName;
315  std::string annotationDescription;
317 
318  annotationName =
319  annotationElement->Attribute((char *)mitk::TubeGraphDefinitions::XML_ANNOTATION_NAME.c_str());
320  annotation->name = annotationName;
321 
322  annotationDescription =
323  annotationElement->Attribute((char *)mitk::TubeGraphDefinitions::XML_ANNOTATION_DESCRIPTION.c_str());
324  annotation->description = annotationDescription;
325 
326  annotationElement->Attribute(mitk::TubeGraphDefinitions::XML_TUBE_ID_1, &temp);
327  tube.first = temp;
328  annotationElement->Attribute(mitk::TubeGraphDefinitions::XML_TUBE_ID_2, &temp);
329  tube.second = temp;
330 
331  if (tube != TubeGraph::ErrorId)
332  {
333  annotation->tube = tube;
334  newProperty->AddAnnotation(annotation);
335  }
336  }
337  }
338 
339  MITK_INFO << "Tube Graph Property read";
340 
341  newTubeGraph->SetGeometry(geometry);
342  newTubeGraph->SetProperty("Tube Graph.Visualization Information", newProperty);
343  result.push_back(newTubeGraph.GetPointer());
344  }
345 
346  else
347  {
348  mitkThrow() << "Parsing error at line " << doc.ErrorRow() << ", col " << doc.ErrorCol() << ": "
349  << doc.ErrorDesc();
350  }
351  return result;
352  }
353 
355  {
357  return Unsupported;
358  return Supported;
359  }
360 
362  {
363  OutputStream out(this);
364 
365  if (!out.good())
366  {
367  mitkThrow() << "Stream not good.";
368  }
369 
370  std::locale previousLocale(out.getloc());
371  std::locale I("C");
372  out.imbue(I);
373 
374  const mitk::TubeGraph *tubeGraph = dynamic_cast<const mitk::TubeGraph *>(this->GetInput());
375  // Get geometry of the tube graph
376  mitk::Geometry3D::Pointer geometry = dynamic_cast<mitk::Geometry3D *>(tubeGraph->GetGeometry());
377  // Get property of the tube graph
378  mitk::TubeGraphProperty::Pointer tubeGraphProperty = dynamic_cast<mitk::TubeGraphProperty *>(
379  tubeGraph->GetProperty("Tube Graph.Visualization Information").GetPointer());
380  // Create XML document
381  TiXmlDocument documentXML;
382  { // Begin document
383  TiXmlDeclaration *declXML = new TiXmlDeclaration("1.0", "", "");
384  documentXML.LinkEndChild(declXML);
385 
386  TiXmlElement *mainXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_TUBEGRAPH_FILE);
388  documentXML.LinkEndChild(mainXML);
389 
390  TiXmlElement *geometryXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_GEOMETRY);
391  { // begin geometry
392  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_MATRIX_XX, geometry->GetMatrixColumn(0)[0]);
393  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_MATRIX_XY, geometry->GetMatrixColumn(0)[1]);
394  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_MATRIX_XZ, geometry->GetMatrixColumn(0)[2]);
395  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_MATRIX_YX, geometry->GetMatrixColumn(1)[0]);
396  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_MATRIX_YY, geometry->GetMatrixColumn(1)[1]);
397  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_MATRIX_YZ, geometry->GetMatrixColumn(1)[2]);
398  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_MATRIX_ZX, geometry->GetMatrixColumn(2)[0]);
399  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_MATRIX_ZY, geometry->GetMatrixColumn(2)[1]);
400  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_MATRIX_ZZ, geometry->GetMatrixColumn(2)[2]);
401 
402  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_ORIGIN_X, geometry->GetOrigin()[0]);
403  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_ORIGIN_Y, geometry->GetOrigin()[1]);
404  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_ORIGIN_Z, geometry->GetOrigin()[2]);
405 
406  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_SPACING_X, geometry->GetSpacing()[0]);
407  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_SPACING_Y, geometry->GetSpacing()[1]);
408  geometryXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_SPACING_Z, geometry->GetSpacing()[2]);
409 
410  } // end geometry
411  mainXML->LinkEndChild(geometryXML);
412 
413  TiXmlElement *verticesXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_VERTICES);
414  { // begin vertices section
415  std::vector<mitk::TubeGraphVertex> vertexVector = tubeGraph->GetVectorOfAllVertices();
416  for (unsigned int index = 0; index < vertexVector.size(); index++)
417  {
418  TiXmlElement *vertexXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_VERTEX);
419  vertexXML->SetAttribute(mitk::TubeGraphDefinitions::XML_VERTEX_ID,
420  tubeGraph->GetVertexDescriptor(vertexVector[index]));
421  // element of each vertex
422  const mitk::TubeElement *element = vertexVector[index].GetTubeElement();
423  TiXmlElement *elementXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_ELEMENT);
424  elementXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_ELEMENT_X,
425  element->GetCoordinates().GetElement(0));
426  elementXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_ELEMENT_Y,
427  element->GetCoordinates().GetElement(1));
428  elementXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_ELEMENT_Z,
429  element->GetCoordinates().GetElement(2));
430  if (dynamic_cast<const mitk::CircularProfileTubeElement *>(element))
431  elementXML->SetDoubleAttribute(
433  (dynamic_cast<const mitk::CircularProfileTubeElement *>(element))->GetDiameter());
434  else
435  elementXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_ELEMENT_DIAMETER, 2);
436 
437  vertexXML->LinkEndChild(elementXML);
438 
439  verticesXML->LinkEndChild(vertexXML);
440  }
441  } // end vertices section
442  mainXML->LinkEndChild(verticesXML);
443 
444  TiXmlElement *edgesXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_EDGES);
445  { // begin edges section
446  std::vector<mitk::TubeGraphEdge> edgeVector = tubeGraph->GetVectorOfAllEdges();
447  for (unsigned int index = 0; index < edgeVector.size(); index++)
448  {
449  TiXmlElement *edgeXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_EDGE);
450  edgeXML->SetAttribute(mitk::TubeGraphDefinitions::XML_EDGE_ID, index);
451  std::pair<mitk::TubeGraphVertex, mitk::TubeGraphVertex> soureTargetPair =
452  tubeGraph->GetVerticesOfAnEdge(tubeGraph->GetEdgeDescriptor(edgeVector[index]));
454  tubeGraph->GetVertexDescriptor(soureTargetPair.first));
456  tubeGraph->GetVertexDescriptor(soureTargetPair.second));
457 
458  // begin elements of the edge
459  std::vector<mitk::TubeElement *> elementVector = edgeVector[index].GetElementVector();
460  for (unsigned int elementIndex = 0; elementIndex < elementVector.size(); elementIndex++)
461  {
462  TiXmlElement *elementXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_ELEMENT);
463  elementXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_ELEMENT_X,
464  elementVector[elementIndex]->GetCoordinates().GetElement(0));
465  elementXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_ELEMENT_Y,
466  elementVector[elementIndex]->GetCoordinates().GetElement(1));
467  elementXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_ELEMENT_Z,
468  elementVector[elementIndex]->GetCoordinates().GetElement(2));
469  if (dynamic_cast<const mitk::CircularProfileTubeElement *>(elementVector[elementIndex]))
470  elementXML->SetDoubleAttribute(
472  (dynamic_cast<const mitk::CircularProfileTubeElement *>(elementVector[elementIndex]))->GetDiameter());
473  else
474  elementXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_ELEMENT_DIAMETER, 2);
475  edgeXML->LinkEndChild(elementXML);
476  // elementsXML->LinkEndChild(elementXML);
477  }
478  edgesXML->LinkEndChild(edgeXML);
479  }
480  } // end edges section
481  mainXML->LinkEndChild(edgesXML);
482 
483  TiXmlElement *labelGroupsXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_LABELGROUPS);
484  { // begin label group section
485  std::vector<TubeGraphProperty::LabelGroup *> labelGroupVector = tubeGraphProperty->GetLabelGroups();
486  for (unsigned int index = 0; index < labelGroupVector.size(); index++)
487  {
488  TiXmlElement *labelGroupXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_LABELGROUP);
489  labelGroupXML->SetAttribute(mitk::TubeGraphDefinitions::XML_LABELGROUP_NAME,
490  labelGroupVector[index]->labelGroupName);
491  // begin labels of the label group
492  std::vector<TubeGraphProperty::LabelGroup::Label *> labelVector = labelGroupVector[index]->labels;
493  for (unsigned int labelIndex = 0; labelIndex < labelVector.size(); labelIndex++)
494  {
495  TiXmlElement *labelXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_LABEL);
496  labelXML->SetAttribute(mitk::TubeGraphDefinitions::XML_LABEL_NAME, labelVector[labelIndex]->labelName);
498  labelVector[labelIndex]->isVisible);
499  labelXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_LABEL_COLOR_R,
500  labelVector[labelIndex]->labelColor[0]);
501  labelXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_LABEL_COLOR_G,
502  labelVector[labelIndex]->labelColor[1]);
503  labelXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_LABEL_COLOR_B,
504  labelVector[labelIndex]->labelColor[2]);
505  labelGroupXML->LinkEndChild(labelXML);
506  }
507  labelGroupsXML->LinkEndChild(labelGroupXML);
508  }
509  } // end labe group section
510  mainXML->LinkEndChild(labelGroupsXML);
511 
512  TiXmlElement *attributionsXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_ATTRIBUTIONS);
513  { // begin attributions section
514  std::map<mitk::TubeGraphProperty::TubeToLabelGroupType, std::string> tubeToLabelGroup =
515  tubeGraphProperty->GetTubesToLabels();
516  for (std::map<mitk::TubeGraphProperty::TubeToLabelGroupType, std::string>::iterator it =
517  tubeToLabelGroup.begin();
518  it != tubeToLabelGroup.end();
519  it++)
520  {
521  TiXmlElement *attributXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_ATTRIBUTION);
522  attributXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_TUBE_ID_1, it->first.first.first);
523  attributXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_TUBE_ID_2, it->first.first.second);
524  attributXML->SetAttribute(mitk::TubeGraphDefinitions::XML_LABELGROUP_NAME, it->first.second);
525  attributXML->SetAttribute(mitk::TubeGraphDefinitions::XML_LABEL_NAME, it->second);
526  attributionsXML->LinkEndChild(attributXML);
527  }
528 
529  } // end attributions section
530  mainXML->LinkEndChild(attributionsXML);
531 
532  TiXmlElement *annotationsXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_ANNOTATIONS);
533  { // begin annotations section
534  std::vector<mitk::TubeGraphProperty::Annotation *> annotations = tubeGraphProperty->GetAnnotations();
535  for (unsigned int index = 0; index < annotations.size(); index++)
536  {
537  TiXmlElement *annotationXML = new TiXmlElement(mitk::TubeGraphDefinitions::XML_ANNOTATION);
538  annotationXML->SetAttribute(mitk::TubeGraphDefinitions::XML_ANNOTATION_NAME, annotations[index]->name);
539  annotationXML->SetAttribute(mitk::TubeGraphDefinitions::XML_ANNOTATION_DESCRIPTION,
540  annotations[index]->description);
541  annotationXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_TUBE_ID_1, annotations[index]->tube.first);
542  annotationXML->SetDoubleAttribute(mitk::TubeGraphDefinitions::XML_TUBE_ID_2, annotations[index]->tube.second);
543 
544  annotationsXML->LinkEndChild(annotationXML);
545  }
546  } // end annotations section
547  mainXML->LinkEndChild(annotationsXML);
548  } // end document
549 
550  TiXmlPrinter printer;
551  printer.SetStreamPrinting();
552  documentXML.Accept(&printer);
553  out << printer.Str();
554  }
555 
557  {
559  return Unsupported;
560  return Supported;
561  }
562 
563  TubeGraphIO *TubeGraphIO::IOClone() const { return new TubeGraphIO(*this); }
564 }
565 
566 const mitk::BoundingBox::Pointer mitk::TubeGraphIO::ComputeBoundingBox(mitk::TubeGraph::Pointer graph) const
567 {
568  BoundingBox::Pointer boundingBox = BoundingBox::New();
569  BoundingBox::PointIdentifier pointid = 0;
571 
572  ScalarType nullpoint[] = {0, 0, 0};
573  BoundingBox::PointType p(nullpoint);
574 
575  // traverse the tree and add each point to the pointscontainer
576 
577  mitk::Point3D pos;
578 
579  std::vector<mitk::TubeGraphVertex> vertexVector = graph->GetVectorOfAllVertices();
580  for (std::vector<mitk::TubeGraphVertex>::iterator vertex = vertexVector.begin(); vertex != vertexVector.end();
581  ++vertex)
582  {
583  pos = vertex->GetTubeElement()->GetCoordinates();
584  p[0] = pos[0];
585  p[1] = pos[1];
586  p[2] = pos[2];
587  pointscontainer->InsertElement(pointid++, p);
588  }
589 
590  std::vector<mitk::TubeGraphEdge> edgeVector = graph->GetVectorOfAllEdges();
591 
592  for (std::vector<mitk::TubeGraphEdge>::iterator edge = edgeVector.begin(); edge != edgeVector.end(); ++edge)
593  {
594  std::vector<mitk::TubeElement *> allElements = edge->GetElementVector();
595  for (unsigned int index = 0; index < edge->GetNumberOfElements(); index++)
596  {
597  pos = allElements[index]->GetCoordinates();
598  p[0] = pos[0];
599  p[1] = pos[1];
600  p[2] = pos[2];
601  pointscontainer->InsertElement(pointid++, p);
602  }
603  }
604 
605  boundingBox->SetPoints(pointscontainer);
606  boundingBox->ComputeBoundingBox();
607 
608  return boundingBox;
609 }
static const std::string XML_ATTRIBUTIONS
static const std::string XML_SPACING_Y
mitk::Point3D PointType
itk::SmartPointer< Self > Pointer
Standard implementation of BaseGeometry.
static const std::string XML_EDGE_SOURCE_ID
static const std::string XML_ANNOTATION_DESCRIPTION
static const std::string XML_VERTEX_ID
static const std::string XML_LABELGROUP
virtual ConfidenceLevel GetWriterConfidenceLevel() const override
static const TubeDescriptorType ErrorId
Definition: mitkTubeGraph.h:55
#define MITK_INFO
Definition: mitkLogMacros.h:22
static const std::string XML_MATRIX_YX
virtual ConfidenceLevel GetReaderConfidenceLevel() const override
static const std::string XML_ELEMENT
#define MITK_ERROR
Definition: mitkLogMacros.h:24
Base Class for Tube Graphs.
Definition: mitkTubeGraph.h:37
static const std::string XML_LABEL
double ScalarType
virtual ConfidenceLevel GetReaderConfidenceLevel() const override
static const std::string XML_EDGE
static const std::string XML_ELEMENT_Y
Base Class for Tube Graph Vertices.
static const std::string XML_SPACING_Z
static const std::string XML_TUBEGRAPH_FILE
void AddTubeElement(TubeElement *element)
reader and writer for xml representations of mitk::TubeGraph
static const std::string XML_VERTEX
DataCollection - Class to facilitate loading/accessing structured data.
Abstract class for elements which describes tubular structur.
std::vector< EdgeType > GetVectorOfAllEdges() const
static Pointer New()
static const std::string XML_MATRIX_XY
static const std::string XML_ANNOTATION
static Pointer New()
std::pair< VertexType, VertexType > GetVerticesOfAnEdge(const EdgeDescriptorType &edge) const
static const std::string XML_FILE_VERSION
static const std::string XML_SPACING_X
VertexDescriptorType GetVertexDescriptor(const VertexType &vertexData) const
static const std::string XML_VERTICES
static const std::string XML_MATRIX_XZ
static const std::string XML_ATTRIBUTION
static Pointer New()
static const std::string VERSION_STRING
static const std::string XML_MATRIX_ZX
static const std::string XML_MATRIX_YY
static const std::string XML_MATRIX_ZZ
std::pair< TubeDescriptorType, std::string > TubeToLabelGroupType
static const std::string XML_TUBE_ID_1
std::pair< VertexDescriptorType, VertexDescriptorType > TubeDescriptorType
Definition: mitkTubeGraph.h:43
std::pair< us::ServiceRegistration< IFileReader >, us::ServiceRegistration< IFileWriter > > RegisterService(us::ModuleContext *context=us::GetModuleContext())
Property for tube graphs.
virtual std::vector< BaseData::Pointer > Read() override
Reads a path or stream and creates a list of BaseData objects.
static const std::string XML_LABEL_COLOR_B
#define mitkThrow()
static const std::string XML_LABELGROUP_NAME
virtual const BaseData * GetInput() const override
Get the input data set via SetInput().
static const std::string XML_LABEL_NAME
static const std::string XML_MATRIX_ZY
static const char * GetStaticNameOfClass()
Class for elements which describes tubular structur with a circular cross section.
static const std::string XML_LABEL_COLOR_R
static const std::string XML_EDGE_ID
static const std::string XML_ORIGIN_X
virtual void Write() override
Write the base data to the specified location or output stream.
Base Class for Tube Graph Edges.
static const std::string XML_EDGE_TARGET_ID
EdgeDescriptorType GetEdgeDescriptor(const EdgeType &edgeData) const
static const std::string XML_GEOMETRY
static const std::string XML_MATRIX_YZ
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
static const std::string XML_ELEMENT_Z
static const std::string XML_LABEL_COLOR_G
static const std::string XML_ORIGIN_Z
boost::graph_traits< GraphType >::vertex_descriptor VertexDescriptorType
static const std::string XML_LABELGROUPS
static const std::string XML_TUBE_ID_2
static const std::string XML_ELEMENT_DIAMETER
void SetTubeElement(TubeElement *element)
static const std::string XML_ANNOTATION_NAME
virtual const Point3D & GetCoordinates() const =0
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
Definition: mitkIFileIO.h:49
virtual ConfidenceLevel GetWriterConfidenceLevel() const override
mitk::BaseProperty::Pointer GetProperty(const char *propertyKey) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList, and set it to this, respectively;.
static const std::string XML_ANNOTATIONS
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
Definition: mitkBaseData.h:129
static const std::string XML_LABEL_VISIBILITY
Abstract class for implementing a reader and writer.
static const std::string XML_MATRIX_XX
static const std::string XML_EDGES
static const std::string XML_ORIGIN_Y
static const std::string XML_ELEMENT_X
std::vector< VertexType > GetVectorOfAllVertices() const
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.