...
 
Commits (2)
# -*- coding: utf-8 -*-
"""Functions to load MITK's mps point set file. """
import xml.etree.ElementTree as ET
import numpy as np
def load_mps(file_name):
"""
Load a pointset from a .mps file. For now, just loads points,
without geometry information.
:param file_name: string representing file path.
:return: ids (length N), points (Nx3)
"""
tree = ET.parse(file_name)
root = tree.getroot()
points = root[1]
time_series = points[0]
tmp = {}
for point in time_series.findall('point'):
i = point.find('id').text
x_c = point.find('x').text
y_c = point.find('y').text
z_c = point.find('z').text
tmp[int(i)] = (float(x_c), float(y_c), float(z_c))
ids = np.zeros(len(tmp.keys()), dtype=int)
result = np.zeros((len(tmp.keys()), 3))
counter = 0
for k in tmp:
ids[counter] = k
result[counter][0] = tmp[k][0]
result[counter][1] = tmp[k][1]
result[counter][2] = tmp[k][2]
counter = counter + 1
return ids, result
<?xml version="1.0" encoding="UTF-8" ?>
<point_set_file>
<file_version>0.1</file_version>
<point_set>
<time_series>
<time_series_id>0</time_series_id>
<Geometry3D ImageGeometry="false" FrameOfReferenceID="0">
<IndexToWorld type="Matrix3x3" m_0_0="1" m_0_1="0" m_0_2="0" m_1_0="0" m_1_1="1" m_1_2="0" m_2_0="0" m_2_1="0" m_2_2="1" />
<Offset type="Vector3D" x="0" y="0" z="0" />
<Bounds>
<Min type="Vector3D" x="-134.87921472311" y="-87.0495708179474" z="1570.031022310257" />
<Max type="Vector3D" x="111.4532385277748" y="-19.0247973632812" z="1773.7020261287689" />
</Bounds>
</Geometry3D>
<point>
<id>0</id>
<specification>0</specification>
<x>10.2352026367</x>
<y>-87.0495708179</y>
<z>1773.70202613</z>
</point>
<point>
<id>1</id>
<specification>0</specification>
<x>-134.879214723</x>
<y>-19.0247973633</y>
<z>1574.53710377</z>
</point>
<point>
<id>2</id>
<specification>0</specification>
<x>111.453238528</x>
<y>-22.3497973633</y>
<z>1570.03102231</z>
</point>
</time_series>
</point_set>
</point_set_file>
# coding=utf-8
"""Tests for load_mps"""
import six
import pytest
import sksurgerycore.io.load_mps as lmps
def test_load_mps():
ids, points = lmps.load_mps('tests/data/pointset.mps')
assert points.shape[0] == 3
assert points.shape[1] == 3
assert ids.shape[0] == 3