-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from DSD-DBS/loading_and_saving_redo
Loading and saving redo
- Loading branch information
Showing
98 changed files
with
2,190 additions
and
4,438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
from raillabel.json_format import ( | ||
JSONAttributes, | ||
JSONBooleanAttribute, | ||
JSONNumAttribute, | ||
JSONTextAttribute, | ||
JSONVecAttribute, | ||
) | ||
|
||
|
||
def _attributes_from_json(json: JSONAttributes | None) -> dict[str, float | bool | str | list]: | ||
"""Parse the annotation attributes from json.""" | ||
if json is None: | ||
return {} | ||
|
||
attributes: dict[str, float | bool | str | list] = {} | ||
|
||
if json.boolean is not None: | ||
for bool_attribute in json.boolean: | ||
attributes[bool_attribute.name] = bool_attribute.val | ||
|
||
if json.num is not None: | ||
for num_attribute in json.num: | ||
attributes[num_attribute.name] = num_attribute.val | ||
|
||
if json.text is not None: | ||
for text_attribute in json.text: | ||
attributes[text_attribute.name] = text_attribute.val | ||
|
||
if json.vec is not None: | ||
for vec_attribute in json.vec: | ||
attributes[vec_attribute.name] = vec_attribute.val | ||
|
||
return attributes | ||
|
||
|
||
def _attributes_to_json(attributes: dict[str, float | bool | str | list]) -> JSONAttributes | None: | ||
if len(attributes) == 0: | ||
return None | ||
|
||
boolean_attributes = [] | ||
num_attributes = [] | ||
text_attributes = [] | ||
vec_attributes = [] | ||
|
||
for name, value in attributes.items(): | ||
if isinstance(value, bool): | ||
boolean_attributes.append(JSONBooleanAttribute(name=name, val=value)) | ||
|
||
elif isinstance(value, (int, float)): | ||
num_attributes.append(JSONNumAttribute(name=name, val=value)) | ||
|
||
elif isinstance(value, str): | ||
text_attributes.append(JSONTextAttribute(name=name, val=value)) | ||
|
||
elif isinstance(value, list): | ||
vec_attributes.append(JSONVecAttribute(name=name, val=value)) | ||
|
||
else: | ||
raise UnsupportedAttributeTypeError(name, value) | ||
|
||
return JSONAttributes( | ||
boolean=boolean_attributes, num=num_attributes, text=text_attributes, vec=vec_attributes | ||
) | ||
|
||
|
||
class UnsupportedAttributeTypeError(TypeError): | ||
def __init__(self, attribute_name: str, attribute_value: object) -> None: | ||
super().__init__( | ||
f"{attribute_value.__class__.__name__} of attribute {attribute_name} " | ||
"is not a supported attribute type" | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
|
||
from raillabel.json_format import JSONTransformData | ||
|
||
from .transform import Transform | ||
|
||
|
||
@dataclass | ||
class _SensorWithoutIntrinsics: | ||
"""Parent class of all sensors, that do not have an intrinsic calibration.""" | ||
|
||
extrinsics: Transform | None = None | ||
"External calibration of the sensor defined by the 3D transform to the coordinate system origin." | ||
|
||
uri: str | None = None | ||
"Name of the subdirectory containing the sensor files." | ||
|
||
description: str | None = None | ||
"Additional information about the sensor." | ||
|
||
|
||
def _extrinsics_from_json(json_transform: JSONTransformData | None) -> Transform | None: | ||
if json_transform is None: | ||
return None | ||
return Transform.from_json(json_transform) |
Oops, something went wrong.