def test_xml(self): """ Test conversion to and from xml. This is just a basic functionality test of a round trip from Pose3 to xml and back. """ pose = Pose3(t=Vector3(1.5, 2.6, 3.7), R=np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])) pose_xml = pose.to_xml() self.assertEqual(pose_xml.tag, 'pose') pose_rt = Pose3.from_xml(pose_xml) pose.assert_almost_equal(pose_rt)
def _parse_xml(base_elem): """ Parse the xml of an <element> tag, extracting the ProjectObject attributes. Inputs: base_elem (ET.Element) - An Element with tag "element" and appropriate sub-elements. Return: tuple (id, pose, category, bounds, symmetry, score, evaluated) ProjectObject attributes (see constructor for details). Exceptions: ValueError - If base_elem is not <element> or if none of its children is <id>. """ # verify base_elem tag is 'element' if base_elem.tag != "element": raise ValueError('Expected tag to be "element"') # defaults proxy = ProjectObject(1) category = proxy.category pose = proxy.pose symmetry = proxy.symmetry score = proxy.score evaluated = proxy.evaluated for elem in base_elem: if elem.tag == "id": id = elem.text elif elem.tag == "pose": pose = Pose3.from_xml(elem) elif elem.tag == "category": category = elem.text elif (elem.tag == "bounds"): # Note: Boxe3d.from_xml expects tag to be 'box3d' elem_temp = deepcopy(elem) elem_temp.tag = "box3d" bounds = Box3d.from_xml(elem_temp) elif elem.tag == "symmetry": symmetry = ObjectSymmetry.from_xml(elem) elif elem.tag == "detectionScore": score = float(elem.text) elif elem.tag == "evaluated": evaluated = bool(elem.text) if id is None: raise ValueError("XML is missing required <id> tag.") return (id, pose, category, bounds, symmetry, score, evaluated)