diff --git a/exp/annotations.py b/exp/annotations.py --- a/exp/annotations.py +++ b/exp/annotations.py @@ -6,10 +6,20 @@ import json from typing import MutableMapping from analyzer.epoint import EPoint +from analyzer.corners import Corners + + +class Board: + def __init__(self,**kwargs): + self.board=Corners(kwargs.get("board") or []) + self.grid=Corners(kwargs.get("grid") or []) + + def isEmpty(self): + return len(self.board)==0 and len(self.grid)==0 class DataFile(MutableMapping): - """self._data: {filename: [EPoint,EPoint,EPoint,EPoint]}""" + """self.data: {filename: [Board, ...}""" def __init__(self,filename): self.filename=filename try: @@ -25,11 +35,15 @@ class DataFile(MutableMapping): def serialize(self,obj): if isinstance(obj,EPoint): return {"type": "EPoint", "val": [obj.x,obj.y]} + elif isinstance(obj,Board): + return {"type": "Board", "val": {"board": list(obj.board), "grid": list(obj.grid)}} raise TypeError(obj) def deserialize(self,obj): - if obj.get("type")!="EPoint": return obj - return EPoint(*obj["val"]) + type=obj.get("type") + if type=="EPoint": return EPoint(*obj["val"]) + elif type=="Board": return Board(**obj["val"]) + return obj def __getitem__(self, key): return self._data[key] def __setitem__(self, key, val): self._data[key]=val