23 #include <boost/lexical_cast.hpp>
29 TiXmlElement *timeGeomElem =
new TiXmlElement(
"ProportionalTimeGeometry");
30 timeGeomElem->SetAttribute(
"NumberOfTimeSteps", timeGeom->
CountTimeSteps());
36 timeGeomElem->SetAttribute(
"FirstTimePoint", boost::lexical_cast<std::string>(timeGeom->
GetFirstTimePoint()));
37 if (timeGeom->
GetStepDuration() != std::numeric_limits<TimePointType>::infinity())
38 timeGeomElem->SetAttribute(
"StepDuration", boost::lexical_cast<std::string>(timeGeom->
GetStepDuration()));
47 geom3DElement->SetAttribute(
"TimeStep", t);
48 timeGeomElem->LinkEndChild(geom3DElement);
52 MITK_WARN <<
"Serializing a ProportionalTimeGeometry that contains something other than Geometry3D!"
53 <<
" (in time step " << t <<
")"
54 <<
" File will miss information!";
63 if (!timeGeometryElement)
65 MITK_ERROR <<
"Cannot deserialize ProportionalTimeGeometry from nullptr.";
69 int numberOfTimeSteps = 0;
71 if (TIXML_SUCCESS != timeGeometryElement->QueryIntAttribute(
"NumberOfTimeSteps", &numberOfTimeSteps))
73 MITK_WARN <<
"<ProportionalTimeGeometry> found without NumberOfTimeSteps attribute. Counting...";
78 std::string firstTimePoint_s;
80 std::string stepDuration_s;
83 if (TIXML_SUCCESS == timeGeometryElement->QueryStringAttribute(
"FirstTimePoint", &firstTimePoint_s))
85 firstTimePoint = boost::lexical_cast<
double>(firstTimePoint_s);
92 if (TIXML_SUCCESS == timeGeometryElement->QueryStringAttribute(
"StepDuration", &stepDuration_s))
94 stepDuration = boost::lexical_cast<
double>(stepDuration_s);
98 stepDuration = std::numeric_limits<TimePointType>::infinity();
101 catch (boost::bad_lexical_cast &e)
103 MITK_ERROR <<
"Could not parse string as number: " << e.what();
108 std::multimap<TimeStepType, BaseGeometry::Pointer> allReadGeometries;
110 int indexForUnlabeledTimeStep(-1);
111 for (TiXmlElement *currentElement = timeGeometryElement->FirstChildElement(); currentElement !=
nullptr;
112 currentElement = currentElement->NextSiblingElement())
116 std::string tagName = currentElement->Value();
117 if (tagName ==
"Geometry3D")
120 if (restoredGeometry.IsNotNull())
123 if (TIXML_SUCCESS != currentElement->QueryIntAttribute(
"TimeStep", &timeStep))
125 timeStep = indexForUnlabeledTimeStep--;
126 MITK_WARN <<
"Found <Geometry3D> without 'TimeStep' attribute in <ProportionalTimeGeometry>. No guarantees "
130 if (allReadGeometries.count(static_cast<TimeStepType>(timeStep)) > 0)
132 MITK_WARN <<
"Found <Geometry3D> tags with identical 'TimeStep' attribute in <ProportionalTimeGeometry>. No "
133 "guarantees on order anymore.";
136 allReadGeometries.insert(std::make_pair(static_cast<TimeStepType>(timeStep), restoredGeometry.GetPointer()));
141 MITK_WARN <<
"Found unsupported tag <" << tagName <<
"> inside <ProportionalTimeGeometry>. Ignoring.";
148 newTimeGeometry->SetFirstTimePoint(firstTimePoint);
149 newTimeGeometry->SetStepDuration(stepDuration);
150 newTimeGeometry->ReserveSpaceForGeometries(allReadGeometries.size());
153 for (
auto entry : allReadGeometries)
158 newTimeGeometry->SetTimeStepGeometry(entry.second, t++);
163 newTimeGeometry->UpdateBoundingBox();
165 return newTimeGeometry;
virtual TimeStepType CountTimeSteps() const override
Returns the number of time steps.
Standard implementation of BaseGeometry.
virtual 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().
virtual TimePointType GetFirstTimePoint() const
static TiXmlElement * ToXML(const Geometry3D *geometry)
Serialize given geometry to XML.
virtual TimePointType GetStepDuration() const
mitk::ScalarType TimePointType
std::vcl_size_t TimeStepType
static ProportionalTimeGeometry::Pointer FromXML(TiXmlElement *node)
Create a ProportionalTimeGeometry from XML. Interprets only the format created by ToXML()...