45 std::vector<itk::SmartPointer<mitk::BaseData>> result;
53 TiXmlHandle docHandle(&doc);
55 for (TiXmlElement *currentPointSetElement =
56 docHandle.FirstChildElement(
"point_set_file").FirstChildElement(
"point_set").ToElement();
57 currentPointSetElement != NULL;
58 currentPointSetElement = currentPointSetElement->NextSiblingElement())
66 if (currentPointSetElement->FirstChildElement(
"time_series") != NULL)
68 for (TiXmlElement *currentTimeSeries = currentPointSetElement->FirstChildElement(
"time_series")->ToElement();
69 currentTimeSeries != NULL;
70 currentTimeSeries = currentTimeSeries->NextSiblingElement())
72 unsigned int currentTimeStep(0);
73 TiXmlElement *currentTimeSeriesID = currentTimeSeries->FirstChildElement(
"time_series_id");
75 currentTimeStep = atoi(currentTimeSeriesID->GetText());
77 timeGeometry->Expand(currentTimeStep + 1);
78 TiXmlElement *geometryElem = currentTimeSeries->FirstChildElement(
"Geometry3D");
82 if (geometry.IsNotNull())
84 timeGeometry->SetTimeStepGeometry(geometry, currentTimeStep);
88 MITK_ERROR <<
"Could not deserialize Geometry3D element.";
93 MITK_WARN <<
"Fallback to legacy behavior: defining PointSet geometry as identity";
96 newPointSet = this->ReadPoints(newPointSet, currentTimeSeries, currentTimeStep);
101 newPointSet = this->ReadPoints(newPointSet, currentPointSetElement, 0);
104 newPointSet->SetTimeGeometry(timeGeometry);
106 result.push_back(newPointSet.GetPointer());
111 mitkThrow() <<
"Parsing error at line " << doc.ErrorRow() <<
", col " << doc.ErrorCol() <<
": " << doc.ErrorDesc();
119 TiXmlElement *geometryElem = parentElement->FirstChildElement(
"geometry3d");
124 AffineTransform3D::MatrixType matrix;
125 AffineTransform3D::OffsetType
offset;
126 bool isImageGeometry(
false);
127 unsigned int frameOfReferenceID(0);
130 bool somethingMissing(
false);
133 TiXmlElement *imageGeometryElem = geometryElem->FirstChildElement(
"image_geometry");
134 if (imageGeometryElem)
136 std::string igs = imageGeometryElem->GetText();
137 isImageGeometry = igs ==
"true" || igs ==
"TRUE" || igs ==
"1";
140 somethingMissing =
true;
142 TiXmlElement *frameOfReferenceElem = geometryElem->FirstChildElement(
"frame_of_reference_id");
143 if (frameOfReferenceElem)
145 frameOfReferenceID = atoi(frameOfReferenceElem->GetText());
148 somethingMissing =
true;
150 TiXmlElement *indexToWorldElem = geometryElem->FirstChildElement(
"index_to_world");
151 if (indexToWorldElem)
153 TiXmlElement *matrixElem = indexToWorldElem->FirstChildElement(
"matrix3x3");
154 TiXmlElement *offsetElem = indexToWorldElem->FirstChildElement(
"offset");
155 if (indexToWorldElem && offsetElem)
157 TiXmlElement *col0 = matrixElem->FirstChildElement(
"column_0");
158 TiXmlElement *col1 = matrixElem->FirstChildElement(
"column_1");
159 TiXmlElement *col2 = matrixElem->FirstChildElement(
"column_2");
161 if (col0 && col1 && col2)
163 somethingMissing |= TIXML_SUCCESS != col0->QueryDoubleAttribute(
"x", &matrix[0][0]);
164 somethingMissing |= TIXML_SUCCESS != col0->QueryDoubleAttribute(
"y", &matrix[1][0]);
165 somethingMissing |= TIXML_SUCCESS != col0->QueryDoubleAttribute(
"z", &matrix[2][0]);
167 somethingMissing |= TIXML_SUCCESS != col1->QueryDoubleAttribute(
"x", &matrix[0][1]);
168 somethingMissing |= TIXML_SUCCESS != col1->QueryDoubleAttribute(
"y", &matrix[1][1]);
169 somethingMissing |= TIXML_SUCCESS != col1->QueryDoubleAttribute(
"z", &matrix[2][1]);
171 somethingMissing |= TIXML_SUCCESS != col2->QueryDoubleAttribute(
"x", &matrix[0][2]);
172 somethingMissing |= TIXML_SUCCESS != col2->QueryDoubleAttribute(
"y", &matrix[1][2]);
173 somethingMissing |= TIXML_SUCCESS != col2->QueryDoubleAttribute(
"z", &matrix[2][2]);
176 somethingMissing =
true;
178 somethingMissing |= TIXML_SUCCESS != offsetElem->QueryDoubleAttribute(
"x", &offset[0]);
179 somethingMissing |= TIXML_SUCCESS != offsetElem->QueryDoubleAttribute(
"y", &offset[1]);
180 somethingMissing |= TIXML_SUCCESS != offsetElem->QueryDoubleAttribute(
"z", &offset[2]);
183 somethingMissing =
true;
185 TiXmlElement *boundsElem = geometryElem->FirstChildElement(
"bounds");
188 TiXmlElement *minBoundsElem = boundsElem->FirstChildElement(
"min");
189 TiXmlElement *maxBoundsElem = boundsElem->FirstChildElement(
"max");
191 if (minBoundsElem && maxBoundsElem)
193 somethingMissing |= TIXML_SUCCESS != minBoundsElem->QueryDoubleAttribute(
"x", &bounds[0]);
194 somethingMissing |= TIXML_SUCCESS != minBoundsElem->QueryDoubleAttribute(
"y", &bounds[2]);
195 somethingMissing |= TIXML_SUCCESS != minBoundsElem->QueryDoubleAttribute(
"z", &bounds[4]);
197 somethingMissing |= TIXML_SUCCESS != maxBoundsElem->QueryDoubleAttribute(
"x", &bounds[1]);
198 somethingMissing |= TIXML_SUCCESS != maxBoundsElem->QueryDoubleAttribute(
"y", &bounds[3]);
199 somethingMissing |= TIXML_SUCCESS != maxBoundsElem->QueryDoubleAttribute(
"z", &bounds[5]);
202 somethingMissing =
true;
205 somethingMissing =
true;
208 somethingMissing =
true;
210 if (somethingMissing)
212 MITK_ERROR <<
"XML structure of geometry inside a PointSet file broken. Refusing to build Geometry3D";
218 g->SetImageGeometry(isImageGeometry);
219 g->SetFrameOfReferenceID(frameOfReferenceID);
220 g->SetBounds(bounds);
223 transform->SetMatrix(matrix);
224 transform->SetOffset(offset);
226 g->SetIndexToWorldTransform(transform);
228 return g.GetPointer();
233 TiXmlElement *currentTimeSeries,
234 unsigned int currentTimeStep)
236 if (currentTimeSeries->FirstChildElement(
"point") != NULL)
238 for (TiXmlElement *currentPoint = currentTimeSeries->FirstChildElement(
"point")->ToElement(); currentPoint != NULL;
239 currentPoint = currentPoint->NextSiblingElement())
247 id = atoi(currentPoint->FirstChildElement(
"id")->GetText());
248 if (currentPoint->FirstChildElement(
"specification") != NULL)
252 x = atof(currentPoint->FirstChildElement(
"x")->GetText());
253 y = atof(currentPoint->FirstChildElement(
"y")->GetText());
254 z = atof(currentPoint->FirstChildElement(
"z")->GetText());
258 newPointSet->SetPoint(
id, point, spec, currentTimeStep);
263 if (currentTimeStep != newPointSet->GetTimeSteps() + 1)
265 newPointSet->Expand(currentTimeStep + 1);
272 :
mitk::AbstractFileReader(other)
itk::SmartPointer< Self > Pointer
BoundingBoxType::BoundsArrayType BoundsArrayType
static Geometry3D::Pointer FromXML(TiXmlElement *node)
Create a Geometry3D from XML. Interprets only the format created by ToXML().
DataCollection - Class to facilitate loading/accessing structured data.
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
itk::SmartPointer< Self > Pointer
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
Convenience class to temporarily change the current locale.
virtual std::vector< itk::SmartPointer< BaseData > > Read() override
Reads a path or stream and creates a list of BaseData objects.
Base class for creating mitk::BaseData objects from files or streams.
virtual ~PointSetReaderService()
PointSpecificationType
enumeration of the type a point can be
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.