25 auto *timeGeomElem =
new TiXmlElement(
"ProportionalTimeGeometry");
26 timeGeomElem->SetAttribute(
"NumberOfTimeSteps", timeGeom->
CountTimeSteps());
32 timeGeomElem->SetAttribute(
"FirstTimePoint", boost::lexical_cast<std::string>(timeGeom->
GetFirstTimePoint()));
33 if (timeGeom->
GetStepDuration() != std::numeric_limits<TimePointType>::infinity())
34 timeGeomElem->SetAttribute(
"StepDuration", boost::lexical_cast<std::string>(timeGeom->
GetStepDuration()));
43 geom3DElement->SetAttribute(
"TimeStep", t);
44 timeGeomElem->LinkEndChild(geom3DElement);
48 MITK_WARN <<
"Serializing a ProportionalTimeGeometry that contains something other than Geometry3D!" 49 <<
" (in time step " << t <<
")" 50 <<
" File will miss information!";
59 if (!timeGeometryElement)
61 MITK_ERROR <<
"Cannot deserialize ProportionalTimeGeometry from nullptr.";
65 int numberOfTimeSteps = 0;
67 if (TIXML_SUCCESS != timeGeometryElement->QueryIntAttribute(
"NumberOfTimeSteps", &numberOfTimeSteps))
69 MITK_WARN <<
"<ProportionalTimeGeometry> found without NumberOfTimeSteps attribute. Counting...";
74 std::string firstTimePoint_s;
76 std::string stepDuration_s;
79 if (TIXML_SUCCESS == timeGeometryElement->QueryStringAttribute(
"FirstTimePoint", &firstTimePoint_s))
88 if (TIXML_SUCCESS == timeGeometryElement->QueryStringAttribute(
"StepDuration", &stepDuration_s))
94 stepDuration = std::numeric_limits<TimePointType>::infinity();
97 catch (
const boost::bad_lexical_cast &e )
99 MITK_ERROR <<
"Could not parse string as number: " << e.what();
104 std::multimap<TimeStepType, BaseGeometry::Pointer> allReadGeometries;
106 int indexForUnlabeledTimeStep(-1);
107 for (TiXmlElement *currentElement = timeGeometryElement->FirstChildElement(); currentElement !=
nullptr;
108 currentElement = currentElement->NextSiblingElement())
112 std::string tagName = currentElement->Value();
113 if (tagName ==
"Geometry3D")
116 if (restoredGeometry.IsNotNull())
119 if (TIXML_SUCCESS != currentElement->QueryIntAttribute(
"TimeStep", &timeStep))
121 timeStep = indexForUnlabeledTimeStep--;
122 MITK_WARN <<
"Found <Geometry3D> without 'TimeStep' attribute in <ProportionalTimeGeometry>. No guarantees " 126 if (allReadGeometries.count(static_cast<TimeStepType>(timeStep)) > 0)
128 MITK_WARN <<
"Found <Geometry3D> tags with identical 'TimeStep' attribute in <ProportionalTimeGeometry>. No " 129 "guarantees on order anymore.";
132 allReadGeometries.insert(std::make_pair(static_cast<TimeStepType>(timeStep), restoredGeometry.GetPointer()));
137 MITK_WARN <<
"Found unsupported tag <" << tagName <<
"> inside <ProportionalTimeGeometry>. Ignoring.";
144 newTimeGeometry->SetFirstTimePoint(firstTimePoint);
145 newTimeGeometry->SetStepDuration(stepDuration);
146 newTimeGeometry->ReserveSpaceForGeometries(allReadGeometries.size());
149 for (
auto entry : allReadGeometries)
154 newTimeGeometry->SetTimeStepGeometry(entry.second, t++);
159 newTimeGeometry->UpdateBoundingBox();
161 return newTimeGeometry;
TimeStepType CountTimeSteps() const override
Returns the number of time steps.
Standard implementation of BaseGeometry.
BaseGeometry::Pointer GetGeometryForTimeStep(TimeStepType timeStep) const override
Returns the geometry which corresponds to the given time step.
static TiXmlElement * ToXML(const ProportionalTimeGeometry *geometry)
Serialize given geometry to XML.
static Geometry3D::Pointer FromXML(TiXmlElement *node)
Create a Geometry3D from XML. Interprets only the format created by ToXML().
static TiXmlElement * ToXML(const Geometry3D *geometry)
Serialize given geometry to XML.
Target lexical_cast(const std::string &arg)
virtual TimePointType GetStepDuration() const
mitk::ScalarType TimePointType
std::vcl_size_t TimeStepType
virtual TimePointType GetFirstTimePoint() const
static ProportionalTimeGeometry::Pointer FromXML(TiXmlElement *node)
Create a ProportionalTimeGeometry from XML. Interprets only the format created by ToXML()...