27 #include <vtkMatrix4x4.h>
29 #include <itksys/SystemTools.hxx>
34 TubeGraphIO::TubeGraphIO()
43 std::locale::global(std::locale(
"C"));
45 std::vector<itk::SmartPointer<mitk::BaseData>> result;
55 TiXmlHandle hDoc(&doc);
59 pElem = hDoc.FirstChildElement().Element();
62 hRoot = TiXmlHandle(pElem);
68 geometry->Initialize();
79 geometry->SetOrigin(origin);
84 spacing.SetElement(0, temp);
86 spacing.SetElement(1, temp);
88 spacing.SetElement(2, temp);
89 geometry->SetSpacing(spacing);
94 m->SetElement(0, 0, temp);
96 m->SetElement(1, 0, temp);
98 m->SetElement(2, 0, temp);
100 m->SetElement(0, 1, temp);
102 m->SetElement(1, 1, temp);
104 m->SetElement(2, 1, temp);
106 m->SetElement(0, 2, temp);
108 m->SetElement(1, 2, temp);
110 m->SetElement(2, 2, temp);
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);
118 geometry->SetImageGeometry(
false);
127 TiXmlElement *vertexElement = pElem->FirstChildElement();
129 for (vertexElement; vertexElement; vertexElement = vertexElement->NextSiblingElement())
133 coordinate.Fill(0.0);
138 TiXmlElement *tubeElement = vertexElement->FirstChildElement();
141 coordinate[0] = temp;
143 coordinate[1] = temp;
145 coordinate[2] = temp;
153 if (newVertex != vertexID)
155 MITK_ERROR <<
"Aborting tube graph creation, different vertex ids.";
167 TiXmlElement *edgeElement = pElem->FirstChildElement();
169 for (edgeElement; edgeElement; edgeElement = edgeElement->NextSiblingElement())
171 int edgeID(0), edgeSourceID(0), edgeTargetID(0);
182 for (tubeElement; tubeElement; tubeElement = tubeElement->NextSiblingElement())
185 coordinate[0] = temp;
187 coordinate[1] = temp;
189 coordinate[2] = temp;
198 newTubeGraph->AddEdge(edgeSourceID, edgeTargetID, edgeData);
200 catch (
const std::runtime_error &error)
210 geometry->SetBounds(bb->GetBounds());
213 MITK_INFO <<
"Edge numb:" << newTubeGraph->GetNumberOfEdges()
214 <<
" Vertices: " << newTubeGraph->GetNumberOfVertices();
216 MITK_INFO <<
"Reading tube graph property";
224 TiXmlElement *labelGroupElement = pElem->FirstChildElement();
226 for (labelGroupElement; labelGroupElement; labelGroupElement = labelGroupElement->NextSiblingElement())
229 const char *labelGroupName;
240 for (labelElement; labelElement; labelElement = labelElement->NextSiblingElement())
243 const char *labelName;
244 bool isVisible =
true;
265 newLabelGroup->
labels.push_back(newLabel);
267 newProperty->AddLabelGroup(newLabelGroup, newProperty->GetLabelGroups().size());
274 TiXmlElement *tubeToLabelElement = pElem->FirstChildElement();
275 std::map<TubeGraphProperty::TubeToLabelGroupType, std::string> tubeToLabelsMap;
276 for (tubeToLabelElement; tubeToLabelElement; tubeToLabelElement = tubeToLabelElement->NextSiblingElement())
286 const char *labelGroupName =
289 labelGroup = newProperty->GetLabelGroupByName(labelGroupName);
291 const char *labelName =
294 label = newProperty->GetLabelByName(labelGroup, labelName);
299 tubeToLabelsMap.insert(
300 std::pair<TubeGraphProperty::TubeToLabelGroupType, std::string>(tubeToLabelGroup, labelName));
303 if (tubeToLabelsMap.size() > 0)
304 newProperty->SetTubesToLabels(tubeToLabelsMap);
310 TiXmlElement *annotationElement = pElem->FirstChildElement();
311 for (annotationElement; annotationElement; annotationElement = annotationElement->NextSiblingElement())
314 std::string annotationName;
315 std::string annotationDescription;
320 annotation->
name = annotationName;
322 annotationDescription =
333 annotation->
tube = tube;
334 newProperty->AddAnnotation(annotation);
341 newTubeGraph->SetGeometry(geometry);
342 newTubeGraph->SetProperty(
"Tube Graph.Visualization Information", newProperty);
343 result.push_back(newTubeGraph.GetPointer());
348 mitkThrow() <<
"Parsing error at line " << doc.ErrorRow() <<
", col " << doc.ErrorCol() <<
": "
370 std::locale previousLocale(out.getloc());
379 tubeGraph->
GetProperty(
"Tube Graph.Visualization Information").GetPointer());
381 TiXmlDocument documentXML;
383 TiXmlDeclaration *declXML =
new TiXmlDeclaration(
"1.0",
"",
"");
384 documentXML.LinkEndChild(declXML);
388 documentXML.LinkEndChild(mainXML);
411 mainXML->LinkEndChild(geometryXML);
416 for (
unsigned int index = 0; index < vertexVector.size(); index++)
430 if (dynamic_cast<const mitk::CircularProfileTubeElement *>(element))
431 elementXML->SetDoubleAttribute(
433 (dynamic_cast<const mitk::CircularProfileTubeElement *>(element))->GetDiameter());
437 vertexXML->LinkEndChild(elementXML);
439 verticesXML->LinkEndChild(vertexXML);
442 mainXML->LinkEndChild(verticesXML);
447 for (
unsigned int index = 0; index < edgeVector.size(); index++)
451 std::pair<mitk::TubeGraphVertex, mitk::TubeGraphVertex> soureTargetPair =
459 std::vector<mitk::TubeElement *> elementVector = edgeVector[index].GetElementVector();
460 for (
unsigned int elementIndex = 0; elementIndex < elementVector.size(); elementIndex++)
464 elementVector[elementIndex]->GetCoordinates().GetElement(0));
466 elementVector[elementIndex]->GetCoordinates().GetElement(1));
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());
475 edgeXML->LinkEndChild(elementXML);
478 edgesXML->LinkEndChild(edgeXML);
481 mainXML->LinkEndChild(edgesXML);
485 std::vector<TubeGraphProperty::LabelGroup *> labelGroupVector = tubeGraphProperty->GetLabelGroups();
486 for (
unsigned int index = 0; index < labelGroupVector.size(); index++)
490 labelGroupVector[index]->labelGroupName);
492 std::vector<TubeGraphProperty::LabelGroup::Label *> labelVector = labelGroupVector[index]->labels;
493 for (
unsigned int labelIndex = 0; labelIndex < labelVector.size(); labelIndex++)
498 labelVector[labelIndex]->isVisible);
500 labelVector[labelIndex]->labelColor[0]);
502 labelVector[labelIndex]->labelColor[1]);
504 labelVector[labelIndex]->labelColor[2]);
505 labelGroupXML->LinkEndChild(labelXML);
507 labelGroupsXML->LinkEndChild(labelGroupXML);
510 mainXML->LinkEndChild(labelGroupsXML);
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();
526 attributionsXML->LinkEndChild(attributXML);
530 mainXML->LinkEndChild(attributionsXML);
534 std::vector<mitk::TubeGraphProperty::Annotation *> annotations = tubeGraphProperty->GetAnnotations();
535 for (
unsigned int index = 0; index < annotations.size(); index++)
540 annotations[index]->description);
544 annotationsXML->LinkEndChild(annotationXML);
547 mainXML->LinkEndChild(annotationsXML);
550 TiXmlPrinter printer;
551 printer.SetStreamPrinting();
552 documentXML.Accept(&printer);
553 out << printer.Str();
569 BoundingBox::PointIdentifier pointid = 0;
579 std::vector<mitk::TubeGraphVertex> vertexVector = graph->GetVectorOfAllVertices();
580 for (std::vector<mitk::TubeGraphVertex>::iterator vertex = vertexVector.begin(); vertex != vertexVector.end();
583 pos = vertex->GetTubeElement()->GetCoordinates();
587 pointscontainer->InsertElement(pointid++, p);
590 std::vector<mitk::TubeGraphEdge> edgeVector = graph->GetVectorOfAllEdges();
592 for (std::vector<mitk::TubeGraphEdge>::iterator edge = edgeVector.begin(); edge != edgeVector.end(); ++edge)
594 std::vector<mitk::TubeElement *> allElements = edge->GetElementVector();
595 for (
unsigned int index = 0; index < edge->GetNumberOfElements(); index++)
597 pos = allElements[index]->GetCoordinates();
601 pointscontainer->InsertElement(pointid++, p);
605 boundingBox->SetPoints(pointscontainer);
606 boundingBox->ComputeBoundingBox();
static const std::string XML_ATTRIBUTIONS
static const std::string XML_SPACING_Y
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
static const std::string XML_MATRIX_YX
virtual ConfidenceLevel GetReaderConfidenceLevel() const override
static const std::string XML_ELEMENT
Base Class for Tube Graphs.
static const std::string XML_LABEL
virtual ConfidenceLevel GetReaderConfidenceLevel() const override
static const std::string XML_EDGE
static const std::string XML_ELEMENT_Y
An output stream wrapper.
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 const std::string XML_MATRIX_XY
static const std::string XML_ANNOTATION
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 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
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
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
std::string labelGroupName
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...
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.
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
std::vector< Label * > labels
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.